|
|
@ -21,6 +21,7 @@ import com.yxt.supervise.monitor.biz.devicelog.YDeviceLogMapper; |
|
|
|
import com.yxt.supervise.monitor.biz.scheduled.SyncService; |
|
|
|
import com.yxt.supervise.monitor.biz.util.HttpUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.messaging.simp.SimpMessagingTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
@ -44,6 +45,9 @@ public class YMessageInfoService extends ServiceImpl<YMessageInfoMapper, Message |
|
|
|
@Resource |
|
|
|
YMessageInfoMapper yMessageInfoMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SimpMessagingTemplate messagingTemplate; |
|
|
|
|
|
|
|
|
|
|
|
public List<CallPolice> saveMessageInfo() { |
|
|
|
String url = "https://api2.hik-cloud.com/api/v1/mq/consumer/messages"; |
|
|
@ -65,6 +69,7 @@ public class YMessageInfoService extends ServiceImpl<YMessageInfoMapper, Message |
|
|
|
for (MessageVo messageVo : messageList) { |
|
|
|
// 根据设备序列号查找本地数据库里面的设备ID
|
|
|
|
String deviceId = ""; |
|
|
|
String deviceName = ""; |
|
|
|
JSONObject deviceIdJson = JSONObject.parseObject(messageVo.getContent()); |
|
|
|
String devSerial = deviceIdJson.get("devSerial").toString(); |
|
|
|
QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>(); |
|
|
@ -72,6 +77,7 @@ public class YMessageInfoService extends ServiceImpl<YMessageInfoMapper, Message |
|
|
|
List<Device> devices = yDeviceMapper.selectList(deviceQueryWrapper); |
|
|
|
if (devices.size() > 0) { |
|
|
|
deviceId = devices.get(0).getId().toString(); |
|
|
|
deviceName = devices.get(0).getName(); |
|
|
|
} |
|
|
|
|
|
|
|
QueryWrapper<MessageInfo> wrapper = new QueryWrapper<>(); |
|
|
@ -109,6 +115,9 @@ public class YMessageInfoService extends ServiceImpl<YMessageInfoMapper, Message |
|
|
|
callPolice.setContent(messageVo.getContent()); |
|
|
|
callPolice.setCreateTime(new Date()); |
|
|
|
callPolice.setDeviceId(deviceId); |
|
|
|
callPolice.setCallType(deviceName + "设备报警信息"); |
|
|
|
|
|
|
|
messagingTemplate.convertAndSend("/topic/subscribe", callPolice); |
|
|
|
yCallPoliceMapper.insert(callPolice); |
|
|
|
} |
|
|
|
} |
|
|
@ -151,42 +160,86 @@ public class YMessageInfoService extends ServiceImpl<YMessageInfoMapper, Message |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void getCallMessage() { |
|
|
|
String url = "https://api2.hik-cloud.com/api/v1/open/basic/devices/list?groupNo=A1181&pageNo=1&pageSize=500"; |
|
|
|
public void refreshDeviceStatus() { |
|
|
|
String result = ""; |
|
|
|
try { |
|
|
|
result = HttpUtils.sendGet(url, SyncService.haiKangToken); |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result); |
|
|
|
JSONObject dataJson = (JSONObject) jsonObject.get("data"); |
|
|
|
JSONArray jsonArray = (JSONArray) dataJson.get("rows"); |
|
|
|
String deviceSerial = ""; |
|
|
|
String deviceStatus = ""; |
|
|
|
IPage<Device> iPage = new Page<>(); |
|
|
|
List<CallPolice> list = new ArrayList<>(); |
|
|
|
for (Object obj : jsonArray) { |
|
|
|
JSONObject objJson = (JSONObject) obj; |
|
|
|
deviceSerial = objJson.get("deviceSerial").toString(); |
|
|
|
deviceStatus = objJson.get("deviceStatus").toString(); |
|
|
|
if ("0".equals(deviceStatus)) { // 报警
|
|
|
|
CallPolice callPolice = new CallPolice(); |
|
|
|
callPolice.setCreateTime(new Date()); |
|
|
|
callPolice.setMsgType("handAdd"); |
|
|
|
callPolice.setContent("设备离线报警"); |
|
|
|
QueryWrapper<Device> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq("serialNumber", deviceSerial); |
|
|
|
List<Device> listSmall = yDeviceService.list(wrapper); |
|
|
|
if (listSmall.size() > 0) { |
|
|
|
callPolice.setDeviceId(listSmall.get(0).getId().toString()); |
|
|
|
list.add(callPolice); |
|
|
|
// 刷新设备状态
|
|
|
|
// 刷新nvr下的设备状态(摄像头类)
|
|
|
|
List<Device> sxtDevices = yDeviceService.getOtherList("5", null); |
|
|
|
for (Device device : sxtDevices) { |
|
|
|
String url = "https://api2.hik-cloud.com/api/v1/open/basic/channels/list?deviceSerial=" + device.getSerialNumber() + "&pageNo=1&pageSize=50"; |
|
|
|
try { |
|
|
|
result = HttpUtils.sendGet(url, SyncService.haiKangToken); |
|
|
|
JSONObject resJson = JSONObject.parseObject(result); |
|
|
|
JSONObject dataJson = (JSONObject) resJson.get("data"); |
|
|
|
JSONArray rowsJsonArr = (JSONArray) dataJson.get("rows"); |
|
|
|
for (Object obj : rowsJsonArr) { |
|
|
|
JSONObject jsonObject = (JSONObject) obj; |
|
|
|
// 只看正在使用的通道。
|
|
|
|
if ("1".equals(jsonObject.get("isUse").toString())) { |
|
|
|
QueryWrapper<Device> wrapper = new QueryWrapper<>(); |
|
|
|
int channelNo = Integer.valueOf(jsonObject.get("channelNo").toString()) + 1; |
|
|
|
wrapper.eq("channelNo", channelNo); |
|
|
|
wrapper.eq("nvrSerial", device.getSerialNumber()); |
|
|
|
List<Device> devices = yDeviceService.list(wrapper); |
|
|
|
// 通道状态,0:离线,1:在线,-1:设备未上报。
|
|
|
|
if (devices.size() > 0) { |
|
|
|
Device deviceTemp = devices.get(0); |
|
|
|
if ("0".equals(jsonObject.get("channelStatus").toString())) { |
|
|
|
if (!deviceTemp.getStatus().equals("0")) { |
|
|
|
deviceTemp.setStatus("0"); |
|
|
|
yDeviceService.updateById(deviceTemp); |
|
|
|
} |
|
|
|
} else if ("1".equals(jsonObject.get("channelStatus").toString())) { |
|
|
|
if (!deviceTemp.getStatus().equals("1")) { |
|
|
|
deviceTemp.setStatus("1"); |
|
|
|
yDeviceService.updateById(deviceTemp); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (CallPolice cl : list) { |
|
|
|
yCallPoliceMapper.insert(cl); |
|
|
|
// 刷新nvr下的设备状态(电子围栏类)
|
|
|
|
List<Device> dzwlDevices = yDeviceService.getOtherList("4", null); |
|
|
|
for (Device device : dzwlDevices) { |
|
|
|
String url = "https://api2.hik-cloud.com/api/v1/open/basic/channels/list?deviceSerial=" + device.getSerialNumber() + "&pageNo=1&pageSize=50"; |
|
|
|
try { |
|
|
|
result = HttpUtils.sendGet(url, SyncService.haiKangToken); |
|
|
|
JSONObject resJson = JSONObject.parseObject(result); |
|
|
|
JSONObject dataJson = (JSONObject) resJson.get("data"); |
|
|
|
JSONArray rowsJsonArr = (JSONArray) dataJson.get("rows"); |
|
|
|
for (Object obj : rowsJsonArr) { |
|
|
|
JSONObject jsonObject = (JSONObject) obj; |
|
|
|
// 只看正在使用的通道。
|
|
|
|
if ("1".equals(jsonObject.get("isUse").toString())) { |
|
|
|
// 通道状态,0:离线,1:在线,-1:设备未上报。
|
|
|
|
QueryWrapper<Device> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq("channelNo", jsonObject.get("channelNo").toString()); |
|
|
|
wrapper.eq("bjzjId", device.getId()); |
|
|
|
List<Device> devices = yDeviceService.list(wrapper); |
|
|
|
if (devices.size() > 0) { |
|
|
|
Device deviceTemp = devices.get(0); |
|
|
|
if ("0".equals(jsonObject.get("channelStatus").toString())) { |
|
|
|
if (!deviceTemp.getStatus().equals("0")) { |
|
|
|
deviceTemp.setStatus("0"); |
|
|
|
yDeviceService.updateById(deviceTemp); |
|
|
|
} |
|
|
|
} else if ("1".equals(jsonObject.get("channelStatus").toString())) { |
|
|
|
if (!deviceTemp.getStatus().equals("1")) { |
|
|
|
deviceTemp.setStatus("1"); |
|
|
|
yDeviceService.updateById(deviceTemp); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|