diff --git a/src/main/java/org/springblade/hospital/agent/service/HikAgentService.java b/src/main/java/org/springblade/hospital/agent/service/HikAgentService.java index 967c213..ef24db9 100644 --- a/src/main/java/org/springblade/hospital/agent/service/HikAgentService.java +++ b/src/main/java/org/springblade/hospital/agent/service/HikAgentService.java @@ -112,10 +112,11 @@ public class HikAgentService extends AgentGrpc.AgentImplBase { ChannStatus channStatus = ChannStatus.newBuilder().setId(80).setOnline(true).build(); initResponseObserver.onNext(Heartbeat.newBuilder().setAgentId(agentId) .setStatus("online").setCurrentTime(new Date().getTime()).addAllChannStatus(Arrays.asList(channStatus)).build()); - log.debug("sendHeartBeat 已发送"); +// log.debug("sendHeartBeat 已发送"); Thread.sleep(10000); } catch (Exception e) { - log.error("sendHeartBeat 异常:{}", e.getMessage()); + e.getMessage(); +// log.error("sendHeartBeat 异常:{}", e.getMessage()); } } } @@ -124,7 +125,6 @@ public class HikAgentService extends AgentGrpc.AgentImplBase { private void execGetDataFromDevice() { while (true) { try { - // Collection pointsAlarm = MemoryCache.POINT_MAP_SPF.values(); // log.info("execGetDataFromDevice pointsSPF.size()" + pointsAlarm.size() + "|||||当前线程:" + Thread.currentThread().getId()); // if (CollectionUtils.isNotEmpty(pointsAlarm)) { @@ -158,7 +158,7 @@ public class HikAgentService extends AgentGrpc.AgentImplBase { // queueUtils.saveQueueDataStatus(point); Thread.sleep(20000); } catch (Exception e) { - log.error("execGetDataFromDevice 从map获取数据异常:{}", e.getMessage()); +// log.error("execGetDataFromDevice 从map获取数据异常:{}", e.getMessage()); } } @@ -181,7 +181,12 @@ public class HikAgentService extends AgentGrpc.AgentImplBase { int page = request.getPage(); int pagesize = request.getPagesize(); int devType = request.getDevType(); - + int total = 0; + if (devType == 2) { + total = 61; + } else if (devType == 3) { + total = 19; + } List list = externalUtils.getList(page, pagesize, null, String.valueOf(devType), "100", null); log.info("list======" + list); @@ -204,7 +209,7 @@ public class HikAgentService extends AgentGrpc.AgentImplBase { }); log.info("total {}", list.size()); - responseObserver.onNext(ListResponse.newBuilder().setTotal(list.size()).setIsPointList(false).addAllItems(items).build()); + responseObserver.onNext(ListResponse.newBuilder().setTotal(total).setIsPointList(false).addAllItems(items).build()); responseObserver.onCompleted(); } else { responseObserver.onError(new Throwable("获取服务列表数据失败")); @@ -251,7 +256,7 @@ public class HikAgentService extends AgentGrpc.AgentImplBase { @Override public void setDevice(SetDeviceRequest request, StreamObserver responseObserver) { - log.info("HikAgentService_setDevice来到了grpc服务端{}", request); +// log.info("HikAgentService_setDevice来到了grpc服务端{}", request); responseObserver.onNext(CommonResult.newBuilder().build()); responseObserver.onCompleted(); } diff --git a/src/main/java/org/springblade/hospital/agent/utils/QueueUtils.java b/src/main/java/org/springblade/hospital/agent/utils/QueueUtils.java index 96640de..6e47bf3 100644 --- a/src/main/java/org/springblade/hospital/agent/utils/QueueUtils.java +++ b/src/main/java/org/springblade/hospital/agent/utils/QueueUtils.java @@ -5,9 +5,6 @@ import com.hisense.device.agent.grpc.DataResponse; import com.hisense.device.agent.grpc.Point; import io.grpc.stub.StreamObserver; import lombok.extern.slf4j.Slf4j; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springblade.hospital.agent.service.HikAgentService; import org.springframework.stereotype.Component; import java.util.Arrays; @@ -149,12 +146,10 @@ public class QueueUtils { sendMessage(list); // responseObserver.onNext(DataResponse.newBuilder().addAllPoints(list).build()); - log.info("消费到的状态数据是:{}", point); +// log.info("消费到的状态数据是:{}", point); } catch (Exception e) { - log.error("缓存队列单条消费异常:{}", e.getMessage()); - } } @@ -167,7 +162,7 @@ public class QueueUtils { /*注意:stream流 不能并行调用 ,否则前端解析错误*/ private synchronized void sendMessage(List list){ - log.info("sendMessage 当前线程:{}",Thread.currentThread().getName()); +// log.info("sendMessage 当前线程:{}",Thread.currentThread().getName()); responseObserver.onNext(DataResponse.newBuilder().addAllPoints(list).build()); } diff --git a/src/main/java/org/springblade/hospital/controller/AIoTRequestDemo.java b/src/main/java/org/springblade/hospital/controller/AIoTRequestDemo.java index 23d1df1..4432c6a 100644 --- a/src/main/java/org/springblade/hospital/controller/AIoTRequestDemo.java +++ b/src/main/java/org/springblade/hospital/controller/AIoTRequestDemo.java @@ -2,10 +2,12 @@ package org.springblade.hospital.controller; import com.google.common.collect.Lists; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.httpclient.HttpClient; import org.apache.commons.lang3.StringUtils; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springblade.hospital.newalarm.communicationCom.HTTPClientUtil; import javax.crypto.Mac; import javax.crypto.SecretKey; @@ -25,24 +27,28 @@ public class AIoTRequestDemo { Security.addProvider(new BouncyCastleProvider()); } - public static void main(String[] args) throws Exception { - LinkedHashMap> parameters = new LinkedHashMap<>(); - parameters.put("lang", Lists.newArrayList("zh_CN")); - String appKey = "9aON8USr"; - String appSecret = "VHc1CBWM0YS204rydm+wWxkQrqJSVyXAAgFRktVpOF4="; - String nonce = "123456"; - String timestampStr = "123456789"; - String correctSignature = "RdYq6cvBpeF84HO8iQErRF6Aq9XdE2fDx5w4qjDWfrg="; - String signature = renderSignature( - "/report/data/device", - parameters, - nonce, - timestampStr, - "", - appKey, - appSecret - ); - System.out.println(signature.equals(correctSignature)); + public static void main(String[] args) { +// LinkedHashMap> parameters = new LinkedHashMap<>(); +// parameters.put("lang", Lists.newArrayList("zh_CN")); +// String appKey = "9aON8USr"; +// String appSecret = "VHc1CBWM0YS204rydm+wWxkQrqJSVyXAAgFRktVpOF4="; +// String nonce = "123456"; +// String timestampStr = "123456789"; +// String correctSignature = "RdYq6cvBpeF84HO8iQErRF6Aq9XdE2fDx5w4qjDWfrg="; +// String signature = renderSignature( +// "/report/data/device", +// parameters, +// nonce, +// timestampStr, +// "", +// appKey, +// appSecret +// ); +// System.out.println(signature.equals(correctSignature)); + HttpClient client = new HttpClient(); + String rzUrl = "http://" + "171.16.170.81" + ":" + "80" + "/ISAPI/System/deviceInfo"; + String renzheng = HTTPClientUtil.renzheng(rzUrl, client); + log.info("登录信息:" + renzheng); } /* ———————————————————————————————————————— 封装逻辑 diff --git a/src/main/java/org/springblade/hospital/controller/AlarmInformationController.java b/src/main/java/org/springblade/hospital/controller/AlarmInformationController.java index 69f39bd..09c284a 100644 --- a/src/main/java/org/springblade/hospital/controller/AlarmInformationController.java +++ b/src/main/java/org/springblade/hospital/controller/AlarmInformationController.java @@ -139,9 +139,13 @@ public class AlarmInformationController extends BladeController { */ @PostMapping("/clear") public R clear(@RequestBody AlarmInformation alarmInformation) { - Alarm.xiaojing(alarmInformation.getHostSerialNumber(), alarmInformation.getSystemNum(), alarmInformation.getDeviceId()); - alarmInformation.setIsClear(1); - return R.status(alarmInformationService.updateById(alarmInformation)); + boolean xjcg = false; + boolean xiaojing = Alarm.xiaojing(alarmInformation.getHostSerialNumber(), alarmInformation.getSystemNum(), alarmInformation.getDeviceId()); + if (xiaojing) { + alarmInformation.setIsClear(1); + xjcg = alarmInformationService.updateById(alarmInformation); + } + return R.status(xjcg); } /** diff --git a/src/main/java/org/springblade/hospital/controller/AppDataController.java b/src/main/java/org/springblade/hospital/controller/AppDataController.java index b093c50..0ea27fe 100644 --- a/src/main/java/org/springblade/hospital/controller/AppDataController.java +++ b/src/main/java/org/springblade/hospital/controller/AppDataController.java @@ -151,7 +151,7 @@ public class AppDataController extends BladeController { sha256_HMAC.init(secret_key); String signature = Base64.encodeBase64String(sha256_HMAC.doFinal(message.getBytes())); String content = JSON.toJSONString(alarm); - System.out.println("body请求数据:" + content); + log.info("body请求数据:" + content); // 请求头参数 HttpHeaders headers = new HttpHeaders(); @@ -166,14 +166,14 @@ public class AppDataController extends BladeController { // 发送post请求,并输出结果 response = restTemplate.postForObject(url, httpEntity, String.class); - System.out.println("最终发送url:" + url); - System.out.println("鉴权url:" + message); - System.out.println("appKey:" + appKey); - System.out.println("appSecret:" + appSecret); - System.out.println("nonce:" + nonce); - System.out.println("timestamp:" + timestamp); - System.out.println("signature:" + signature); - System.out.println("fhxx:" + response); +// System.out.println("最终发送url:" + url); +// System.out.println("鉴权url:" + message); +// System.out.println("appKey:" + appKey); +// System.out.println("appSecret:" + appSecret); +// System.out.println("nonce:" + nonce); +// System.out.println("timestamp:" + timestamp); +// System.out.println("signature:" + signature); + log.info("fhxx:" + response); return R.data(response); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/org/springblade/hospital/hik/alarm/Alarm.java b/src/main/java/org/springblade/hospital/hik/alarm/Alarm.java index c4c0b48..886976f 100644 --- a/src/main/java/org/springblade/hospital/hik/alarm/Alarm.java +++ b/src/main/java/org/springblade/hospital/hik/alarm/Alarm.java @@ -46,7 +46,7 @@ public class Alarm implements CommandLineRunner { static FMSGCallBack_V31 fMSFCallBack_V31 = null; static FMSGCallBack fMSFCallBack; static Map numMap; -// static Map clientMap = new HashMap<>(); + // static Map clientMap = new HashMap<>(); public static Map ipMap; public static Map portMap; public static Map macMap; @@ -318,11 +318,9 @@ public class Alarm implements CommandLineRunner { .setPntType(11) .build(); queueUtils.saveQueueDataStatus(sysPoint); - // 获取该报警主机全部防区状态信息 String status = "http://" + ipMap.get(hostSerialNumber) + ":" + portMap.get(hostSerialNumber) + "/ISAPI/SecurityCP/status/zones?format=json"; String statusData = HTTPClientUtil.doGet(status, HTTPClientUtil.client); - System.out.println("statusData:" + statusData); // 解析状态信息 Map statusMap = JSONObject.parseObject(statusData, Map.class); @@ -332,7 +330,7 @@ public class Alarm implements CommandLineRunner { // 过滤只剩该子系统下正在报警的防区 List zones = zoneList.stream().filter(zone -> (boolean) JSONObject.parseObject(zone.get("Zone").toString(), Map.class).get("alarm") && String.valueOf(num).equals(JSONObject.parseObject(zone.get("Zone").toString(), Map.class).get("id").toString())).collect(Collectors.toList()); - System.out.println("zones数量:" + zones); + log.info("zones数量:" + zones); if (CollectionUtils.isNotEmpty(zones)) { for (Map zoneMap : zones) { Map zone = JSONObject.parseObject(zoneMap.get("Zone").toString(), Map.class); @@ -354,7 +352,7 @@ public class Alarm implements CommandLineRunner { // 下发消警指令 String xjUrl = "http://" + ipMap.get(hostSerialNumber) + ":" + portMap.get(hostSerialNumber) + "/ISAPI/SecurityCP/control/clearAlarm/" + num; String respx = HTTPClientUtil.doPut(xjUrl, "", HTTPClientUtil.client); - System.out.println("respx:" + respx); + log.info("respx:" + respx); return true; } } catch (Exception e) { @@ -381,7 +379,7 @@ public class Alarm implements CommandLineRunner { if (renzheng.contains(hostSerialNumber)) { String xjUrl = "http://" + ipMap.get(hostSerialNumber) + ":" + portMap.get(hostSerialNumber) + "/ISAPI/SecurityCP/control/arm/" + num + "?ways=away&format=json"; String respx = HTTPClientUtil.doPut(xjUrl, "", HTTPClientUtil.client); - System.out.println(respx); + log.info("respx:" + respx); return true; } } catch (Exception e) { @@ -408,7 +406,7 @@ public class Alarm implements CommandLineRunner { if (renzheng.contains(hostSerialNumber)) { String xjUrl = "http://" + ipMap.get(hostSerialNumber) + ":" + portMap.get(hostSerialNumber) + "/ISAPI/SecurityCP/control/disarm/" + num; String respx = HTTPClientUtil.doPut(xjUrl, "", HTTPClientUtil.client); - System.out.println(respx); + log.info("respx:" + respx); return true; } } catch (Exception e) { @@ -467,7 +465,7 @@ public class Alarm implements CommandLineRunner { if (renzheng.contains(hostSerialNumber)) { String xjUrl = "http://" + ipMap.get(hostSerialNumber) + ":" + portMap.get(hostSerialNumber) + "/ISAPI/SecurityCP/control/bypass/" + num; String respx = HTTPClientUtil.doPut(xjUrl, "", HTTPClientUtil.client); - System.out.println(respx); + log.info("respx:" + respx); return true; } } catch (Exception e) { @@ -497,7 +495,7 @@ public class Alarm implements CommandLineRunner { if (renzheng.contains(hostSerialNumber)) { String xjUrl = "http://" + ipMap.get(hostSerialNumber) + ":" + portMap.get(hostSerialNumber) + "/ISAPI/SecurityCP/control/bypassRecover/" + num; String respx = HTTPClientUtil.doPut(xjUrl, "", HTTPClientUtil.client); - System.out.println(respx); + log.info("respx:" + respx); return true; } } catch (Exception e) { @@ -535,7 +533,7 @@ public class Alarm implements CommandLineRunner { List threadList = new ArrayList<>(); ScheduledFuture scheduledFuture = scheduled.scheduleAtFixedRate(() -> { // log.info("我执行了1"); - List list = externalUtils.getList(0, 0, null, null, "105", null); + List list = externalUtils.getList(1, 20, null, null, "105", null); log.info("获取报警主机列表数量为:" + list.size()); if (list.size() != size.get()) { size.set(list.size()); @@ -546,23 +544,23 @@ public class Alarm implements CommandLineRunner { } threadList.clear(); // 51服务器使用:物联网平台获取的报警主机列表 -// getList(list, threadList); + getList(list, threadList); // 52服务器使用:不需要监听,只获取设备信息:ip、端口号、mac - for (Map map : list) { - String s = JSON.toJSONString(map.get("tags")).replace("\\", ""); - s = s.substring(1, s.length() - 1); - Map tagsMap = JSONObject.parseObject(s, Map.class); - - // 报警主机信息 - String number = tagsMap.get("hostNumber").toString();//序列号 - String ip = tagsMap.get("ip").toString(); - String port = tagsMap.get("port").toString(); - String mac = tagsMap.get("mac").toString(); - ipMap.put(number, ip); - portMap.put(number, port); - macMap.put(mac, number); - } +// for (Map map : list) { +// String s = JSON.toJSONString(map.get("tags")).replace("\\", ""); +// s = s.substring(1, s.length() - 1); +// Map tagsMap = JSONObject.parseObject(s, Map.class); +// +// // 报警主机信息 +// String number = tagsMap.get("hostNumber").toString();//序列号 +// String ip = tagsMap.get("ip").toString(); +// String port = tagsMap.get("port").toString(); +// String mac = tagsMap.get("mac").toString(); +// ipMap.put(number, ip); +// portMap.put(number, port); +// macMap.put(mac, number); +// } } }, 0, 1, TimeUnit.DAYS); } catch (Exception e) { @@ -690,6 +688,7 @@ public class Alarm implements CommandLineRunner { Thread thread = new Thread(() -> { // 登录认证 String rzUrl = "http://" + ip + ":" + port + "/ISAPI/System/deviceInfo"; + log.info("rzUrl:" + rzUrl); String renzheng = HTTPClientUtil.renzheng(rzUrl, client); log.info("登录信息:" + renzheng); diff --git a/src/main/java/org/springblade/hospital/hik/alarm/AlarmDataParse.java b/src/main/java/org/springblade/hospital/hik/alarm/AlarmDataParse.java index 62b1249..fe4c633 100644 --- a/src/main/java/org/springblade/hospital/hik/alarm/AlarmDataParse.java +++ b/src/main/java/org/springblade/hospital/hik/alarm/AlarmDataParse.java @@ -314,9 +314,9 @@ public class AlarmDataParse { externalUtils = SpringUtil.getBean(ExternalUtils.class); } if (sum > 0) { - list = externalUtils.getList(0, 0, "sector_" + sum, null, "100", sSerialNumber); + list = externalUtils.getList(1, 100, "sector_" + sum, null, "100", sSerialNumber); } else { - list = externalUtils.getList(0, 0, "sys_" + bySubSysNo, null, "100", sSerialNumber); + list = externalUtils.getList(1, 100, "sys_" + bySubSysNo, null, "100", sSerialNumber); } } System.out.println("【CID事件】" + "触发时间:" + TriggerTime + "CID事件号:" + sCIDCode + "CID事件名:" + sCIDDescribe + "子系统号:" + @@ -370,7 +370,7 @@ public class AlarmDataParse { queueUtils = SpringUtil.getBean(QueueUtils.class); } - List hostList = externalUtils.getList(0, 0, null, null, "105", sSerialNumber); + List hostList = externalUtils.getList(1, 20, null, null, "105", sSerialNumber); Map hostMap = hostList.get(0); String s = JSON.toJSONString(hostMap.get("tags")).replace("\\", ""); s = s.substring(1, s.length() - 1); diff --git a/src/main/java/org/springblade/hospital/newalarm/communicationCom/HTTPClientUtil.java b/src/main/java/org/springblade/hospital/newalarm/communicationCom/HTTPClientUtil.java index a303bd4..bdd0d6f 100644 --- a/src/main/java/org/springblade/hospital/newalarm/communicationCom/HTTPClientUtil.java +++ b/src/main/java/org/springblade/hospital/newalarm/communicationCom/HTTPClientUtil.java @@ -3,9 +3,9 @@ package org.springblade.hospital.newalarm.communicationCom; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.google.protobuf.ByteString; import com.hisense.device.agent.grpc.Point; -import lombok.extern.log4j.Log4j; import lombok.extern.slf4j.Slf4j; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.UsernamePasswordCredentials; @@ -14,8 +14,6 @@ import org.apache.commons.httpclient.methods.DeleteMethod; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PutMethod; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springblade.common.cache.DictBizCache; import org.springblade.core.tool.utils.SpringUtil; import org.springblade.hospital.agent.utils.DataTrans; @@ -24,18 +22,17 @@ import org.springblade.hospital.entity.AlarmInformation; import org.springblade.hospital.service.IAlarmInformationService; import org.springblade.hospital.utils.ExternalUtils; import org.springblade.hospital.websocket.WebSocketServer; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; +import org.springblade.modules.system.service.IDictBizService; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Slf4j public class HTTPClientUtil { @@ -49,7 +46,7 @@ public class HTTPClientUtil { public static String renzheng(String rzUrl, HttpClient client) { // 设置用户名和密码 - UsernamePasswordCredentials creds = new UsernamePasswordCredentials("admin", "hao12345"); + UsernamePasswordCredentials creds = new UsernamePasswordCredentials("admin", "qlyy123456"); client.getState().setCredentials(AuthScope.ANY, creds); GetMethod method = new GetMethod(rzUrl); method.setDoAuthentication(true); @@ -77,7 +74,7 @@ public class HTTPClientUtil { public static String statusRz(String rzUrl, HttpClient client) throws IOException { // 设置用户名和密码 - UsernamePasswordCredentials creds = new UsernamePasswordCredentials("admin", "hao12345"); + UsernamePasswordCredentials creds = new UsernamePasswordCredentials("admin", "qlyy123456"); client.getState().setCredentials(AuthScope.ANY, creds); GetMethod method = new GetMethod(rzUrl); method.setDoAuthentication(true); @@ -179,64 +176,72 @@ public class HTTPClientUtil { // system子系统号 int system = Integer.parseInt(cidMap.get("system").toString()); // zone防区号 + List mapList = externalUtils.getMapList(); if (cidMap.get("zone") != null) { zone = Integer.parseInt(cidMap.get("zone").toString()) + 1; - list = externalUtils.getList(0, 0, mac + "_sector_" + zone, null, "100", sSerialNumber); + int finalZone = zone; + list = mapList.stream().filter(map -> JSON.toJSONString(map.get("tags")).contains(mac + "_sector_" + finalZone)).collect(Collectors.toList()); +// list = externalUtils.getList(1, 100, mac + "_sector_" + zone, null, "100", sSerialNumber); } else { - list = externalUtils.getList(0, 0, mac + "_sys_" + system, null, "100", sSerialNumber); + list = mapList.stream().filter(map -> JSON.toJSONString(map.get("tags")).contains(mac + "_sys_" + system)).collect(Collectors.toList()); +// list = externalUtils.getList(1, 100, mac + "_sys_" + system, null, "100", sSerialNumber); } } // 事件信息入本地库 - //SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss+08:00"); if (alarmInformationService == null) { alarmInformationService = SpringUtil.getBean(IAlarmInformationService.class); } String sCIDCode = cidMap.get("code").toString(); + String alarmMessageType = DictBizCache.getValue("alarm_message_type", sCIDCode); AlarmInformation alarmInformation = new AlarmInformation(); - alarmInformation.setReportTime(new Date()); - alarmInformation.setType(sCIDCode); - alarmInformation.setContent(DictBizCache.getValue("alarm_message_type", sCIDCode)); - if (cidMap.get("system") != null) { - alarmInformation.setSystemNum(Integer.parseInt(cidMap.get("system").toString())); - } - alarmInformation.setHostSerialNumber(sSerialNumber); - alarmInformation.setHostIp(resMap.get("ipAddress").toString()); - alarmInformation.setAlarmType(1); - - if (CollectionUtils.isNotEmpty(list)) { - Map map = list.get(0); - alarmInformation.setDeviceName(map.get("name").toString()); - alarmInformation.setDeviceType(Integer.parseInt(String.valueOf(map.get("pid")))); - String s = JSON.toJSONString(map.get("tags")).replace("\\", ""); - s = s.substring(1, s.length() - 1); - Map tagsMap = JSONObject.parseObject(s, Map.class); - alarmInformation.setFloorNo(tagsMap.get("floorNo").toString()); - alarmInformation.setBuildId(tagsMap.get("buildingNo").toString()); - if (tagsMap.get("coordinate") != null) { - String coordinate = tagsMap.get("coordinate").toString(); - alarmInformation.setLatidute(coordinate.split("-")[0]); - alarmInformation.setLongidute(coordinate.split("-")[1]); + if (StringUtils.isNotBlank(alarmMessageType)) { + alarmInformation.setReportTime(new Date()); + alarmInformation.setType(sCIDCode); + alarmInformation.setContent(alarmMessageType); + if (cidMap.get("system") != null) { + alarmInformation.setSystemNum(Integer.parseInt(cidMap.get("system").toString())); } - alarmInformation.setDeviceId(tagsMap.get("pmac").toString()); - Map bizProduct = JSONObject.parseObject(JSON.toJSONString(map.get("bizProduct")), Map.class); - alarmInformation.setProductName(bizProduct.get("name").toString()); - if (tagsMap.get("cameraCode") != null) { - alarmInformation.setCameraCode(tagsMap.get("cameraCode").toString()); - } - - // 主动修改设备状态-物联网平台 - if ("3973".equals(sCIDCode)) { - externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 5); - } else if ("1973".equals(sCIDCode) || "3570".equals(sCIDCode)) { - externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 6); - } else if ("1570".equals(sCIDCode)) { - externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 7); + alarmInformation.setHostSerialNumber(sSerialNumber); + alarmInformation.setHostIp(resMap.get("ipAddress").toString()); + alarmInformation.setAlarmType(1); + + if (CollectionUtils.isNotEmpty(list)) { + Map map = list.get(0); + alarmInformation.setDeviceName(map.get("name").toString()); + alarmInformation.setDeviceType(Integer.parseInt(String.valueOf(map.get("pid")))); + String s = JSON.toJSONString(map.get("tags")).replace("\\", ""); + s = s.substring(1, s.length() - 1); + Map tagsMap = JSONObject.parseObject(s, Map.class); + alarmInformation.setFloorNo(tagsMap.get("floorNo").toString()); + alarmInformation.setBuildId(tagsMap.get("buildingNo").toString()); + if (tagsMap.get("coordinate") != null) { + String coordinate = tagsMap.get("coordinate").toString(); + alarmInformation.setLatidute(coordinate.split("-")[0]); + alarmInformation.setLongidute(coordinate.split("-")[1]); + } + alarmInformation.setDeviceId(tagsMap.get("pmac").toString()); + Map bizProduct = JSONObject.parseObject(JSON.toJSONString(map.get("bizProduct")), Map.class); + alarmInformation.setProductName(bizProduct.get("name").toString()); + if (tagsMap.get("cameraCode") != null) { + alarmInformation.setCameraCode(DictBizCache.getValue("hikvision_camera", map.get("name").toString())); + } + + // 主动修改设备状态-物联网平台 + if ("3401".equals(sCIDCode)) { + // 布防 + externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 5); + } else if ("1401".equals(sCIDCode) || "3570".equals(sCIDCode)) { + // 撤防 + externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 6); + } else if ("1570".equals(sCIDCode)) { + // 旁路 + externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 7); + } } + alarmInformationService.save(alarmInformation); } - boolean save = alarmInformationService.save(alarmInformation); - // 只保留“即时报警”、“设备防拆报警” if ("1103".equals(sCIDCode) || "1137".equals(sCIDCode)) { // 上报海信iot平台 @@ -244,50 +249,29 @@ public class HTTPClientUtil { queueUtils = SpringUtil.getBean(QueueUtils.class); } - List hostList = externalUtils.getList(0, 0, null, null, "105", sSerialNumber); - Map hostMap = hostList.get(0); - String s = JSON.toJSONString(hostMap.get("tags")).replace("\\", ""); - s = s.substring(1, s.length() - 1); - Map tagsMap = JSONObject.parseObject(s, Map.class); - - byte[] byteValue = DataTrans.shortToBytesBigEndian((short) 1); - ByteString byteString = ByteString.copyFrom(byteValue); - Point point = Point.newBuilder() - .setData(byteString) - .setId(tagsMap.get("mac").toString() + "_sector_" + zone) - .setDevType(2) - .setPntType(7) - .build(); - boolean b = queueUtils.saveQueueDataStatus(point); - System.out.println("===" + b); - - // 报警信息发送到远程服务器 - // if (restTemplate == null) { - // restTemplate = SpringUtil.getBean(RestTemplate.class); - // } - // String url = "http://152.136.119.150:81/alarmInformation/hikRemote"; - // HttpHeaders headers = new HttpHeaders(); - // headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); - // - // Map map = new HashMap<>(); - // map.put("id_", tagsMap.get("mac").toString() + "_sector_" + Integer.sum(strCIDalarm.wDefenceNo, 1)); - // map.put("devType_", 2); - // map.put("pntType_", 7); - // map.put("pntTypeValue_", 1); - // String content = JSON.toJSONString(map); - // - // HttpEntity httpEntity = new HttpEntity<>(content, headers); - // - // // 发送post请求,并输出结果 - // R r = restTemplate.postForObject(url, httpEntity, R.class); - // System.out.println("调用远程服务器接口成功!!:" + r); - - // webSocket推送给客户端消息 - JSONObject jsonObject = new JSONObject(); - jsonObject.put("message", JSONObject.toJSONString(alarmInformation)); - WebSocketServer.sendInfo(jsonObject); + List hostList = externalUtils.getHosts(); + if (CollectionUtils.isNotEmpty(hostList)) { + Map hostMap = hostList.get(0); + String s = JSON.toJSONString(hostMap.get("tags")).replace("\\", ""); + s = s.substring(1, s.length() - 1); + Map tagsMap = JSONObject.parseObject(s, Map.class); + + byte[] byteValue = DataTrans.shortToBytesBigEndian((short) 1); + ByteString byteString = ByteString.copyFrom(byteValue); + Point point = Point.newBuilder() + .setData(byteString) + .setId(tagsMap.get("mac").toString() + "_sector_" + zone) + .setDevType(2) + .setPntType(7) + .build(); + boolean b = queueUtils.saveQueueDataStatus(point); + System.out.println("===" + b); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("message", JSONObject.toJSONString(alarmInformation)); + WebSocketServer.sendInfo(jsonObject); + } } - } // System.out.println("接收到的数据:" + resMap); } diff --git a/src/main/java/org/springblade/hospital/service/impl/AppDataServiceImpl.java b/src/main/java/org/springblade/hospital/service/impl/AppDataServiceImpl.java index a40a914..c306674 100644 --- a/src/main/java/org/springblade/hospital/service/impl/AppDataServiceImpl.java +++ b/src/main/java/org/springblade/hospital/service/impl/AppDataServiceImpl.java @@ -77,7 +77,7 @@ public class AppDataServiceImpl extends BaseServiceImpl BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream()); String link = bladeFile.getLink(); Attach attach = new Attach(); - attach.setLink("http://192.169.9.252:1883/hospital/" + bladeFile.getName()); + attach.setLink("http://171.16.8.53:1883/hospital/" + bladeFile.getName()); attach.setOriginalName(file.getOriginalFilename()); attach.setName(bladeFile.getName()); attachService.save(attach); diff --git a/src/main/java/org/springblade/hospital/utils/CornJobUtil.java b/src/main/java/org/springblade/hospital/utils/CornJobUtil.java index 99a801f..7c26d01 100644 --- a/src/main/java/org/springblade/hospital/utils/CornJobUtil.java +++ b/src/main/java/org/springblade/hospital/utils/CornJobUtil.java @@ -37,18 +37,27 @@ public class CornJobUtil { /** * 定时更新设备状态,每1分钟执行一次 */ -// @Async -// @Scheduled(initialDelay = 5000, fixedRate = 60000) + @Async + @Scheduled(initialDelay = 5000, fixedRate = 60000) public void updateStatus() { log.info("定时1分钟获取1次设备状态"); externalUtils.updateStatus(); } + /** + * 每天凌晨1点执行任务,刷新内存设备信息 + */ + @Async + @Scheduled(cron = "0 0 1 * * ?") + public void refresh() { + externalUtils.refresh(); + } + /** * 定时布撤防,每3分钟执行一次 */ -// @Async -// @Scheduled(initialDelay = 6000, fixedRate = 180000) + @Async + @Scheduled(initialDelay = 6000, fixedRate = 180000) public void task() { // System.out.println("定时任务执行了2"); List jobs = cornJobService.list(Wrappers.lambdaQuery().eq(CornJob::getStatus, 1).eq(CornJob::getIsRegular, 1)); diff --git a/src/main/java/org/springblade/hospital/utils/ExternalUtils.java b/src/main/java/org/springblade/hospital/utils/ExternalUtils.java index 59fc22d..7bd480a 100644 --- a/src/main/java/org/springblade/hospital/utils/ExternalUtils.java +++ b/src/main/java/org/springblade/hospital/utils/ExternalUtils.java @@ -26,6 +26,7 @@ import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -45,6 +46,18 @@ public class ExternalUtils { @Autowired QueueUtils queueUtils; + private List hosts = new ArrayList<>(); + + private List mapList = new ArrayList<>(); + + public List getHosts() { + return hosts; + } + + public List getMapList() { + return mapList; + } + /** * 获取物联网平台token */ @@ -143,20 +156,6 @@ public class ExternalUtils { * 更新设备状态 */ public void updateStatus() { - List hosts = null; - List mapList = null; - try { - // 报警主机信息 - hosts = getList(0, 0, null, null, "105", null); - - // 子系统、防区信息 - mapList = getList(0, 0, null, null, "100", null); - } catch (Exception e) { - log.info("获取设备信息失败!"); - - } - - // 遍历设备列表更新设备状态信息 if (CollectionUtils.isNotEmpty(hosts)) { for (Map hostMap : hosts) { String tags = JSON.toJSONString(hostMap.get("tags")).replace("\\", ""); @@ -166,7 +165,7 @@ public class ExternalUtils { String mac = tagMap.get("mac").toString(); // 自定义mac // 认证 - String renzheng = null; + String renzheng = ""; try { String rzUrl = "http://" + Alarm.ipMap.get(number) + ":" + Alarm.portMap.get(number) + "/ISAPI/System/deviceInfo"; renzheng = HTTPClientUtil.statusRz(rzUrl, HTTPClientUtil.client); @@ -180,6 +179,7 @@ public class ExternalUtils { String status = "http://" + Alarm.ipMap.get(number) + ":" + Alarm.portMap.get(number) + "/ISAPI/SecurityCP/status/host?format=json"; String statusData = HTTPClientUtil.doGet(status, HTTPClientUtil.client); +// log.info("statusData" + status + "===" + statusData); Map statusMap = JSONObject.parseObject(statusData, Map.class); Map alarmHostStatus = JSONObject.parseObject(statusMap.get("AlarmHostStatus").toString(), Map.class); Map communiStatus = JSONObject.parseObject(alarmHostStatus.get("CommuniStatus").toString(), Map.class); @@ -210,7 +210,7 @@ public class ExternalUtils { String type = tagsMap.get("type").toString(); // 防区号/子系统号 - int sCIDCode = Integer.parseInt(tagsMap.get("buildingNo").toString()); +// log.info("该设备信息:" + tagsMap); // 设备真实状态 int fqStatus = 0; @@ -218,6 +218,7 @@ public class ExternalUtils { if ("2".equals(type)) { presence = 1; + int sCIDCode = Integer.parseInt(tagsMap.get("sectorNo").toString()); List zones = zoneList.stream().filter(zone -> Integer.parseInt(JSONObject.parseObject(zone.get("Zone").toString(), Map.class).get("id").toString()) == sCIDCode - 1).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(zones)) { @@ -247,11 +248,6 @@ public class ExternalUtils { byAlarmInStatus = 1; } - // 上报防区报警状态 -// updateById(id, 7, byAlarmInStatus, type); -// test1(id, 7, byAlarmInStatus, 2); -// test1(id, 7, 1, 2); - // 撤防-6 布防-5 旁路-7 if (byAlarmInFaultStatus == 0) { if (bySetupAlarmStatus == 1) { @@ -267,7 +263,7 @@ public class ExternalUtils { } } else if ("3".equals(type)) { presence = 2; - List subSyss = subSysList.stream().filter(sys -> Integer.parseInt(JSONObject.parseObject(sys.get("SubSys").toString(), Map.class).get("id").toString()) == sCIDCode).collect(Collectors.toList()); + List subSyss = subSysList.stream().filter(sys -> Integer.parseInt(JSONObject.parseObject(sys.get("SubSys").toString(), Map.class).get("id").toString()) == 1).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(subSyss)) { Map sysMap = subSyss.get(0); Map subSys = JSONObject.parseObject(sysMap.get("SubSys").toString(), Map.class); @@ -281,7 +277,6 @@ public class ExternalUtils { // 海信iot updateById(id, fqStatus, presence, type); -// test(id, fqStatus, presence, type); if (fqStatus == state) { continue; @@ -292,6 +287,9 @@ public class ExternalUtils { } } } + } else { + // 刷新内存数据 + refresh(); } } @@ -356,14 +354,13 @@ public class ExternalUtils { if (queueUtils == null) { queueUtils = SpringUtil.getBean(QueueUtils.class); } - byte[] byteValue = DataTrans.intToBytesBigEndian(pntTypeValue); + byte[] byteValue = DataTrans.shortToBytesBigEndian((short) pntTypeValue); ByteString byteString = ByteString.copyFrom(byteValue); Point point = Point.newBuilder() .setData(byteString) .setId(id) .setDevType(devType) .setPntType(pntType) -// .setPntTypeValue(pntTypeValue) .build(); boolean b = queueUtils.saveQueueDataStatus(point); } @@ -390,8 +387,6 @@ public class ExternalUtils { private Map device(String token, int id, int status) { String url = ParamCache.getValue(IOT_PLATFORM_URL) + "bizDevice"; -// String url = "http://171.16.8.58:8080/prod-api/api/bizDevice"; -// String url = "http://182.139.182.190:60032/prod-api/api/bizDevice"; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); headers.setBearerAuth(token); @@ -408,76 +403,87 @@ public class ExternalUtils { return JSONObject.parseObject(exchange.getBody(), Map.class); } + /** + * 刷新内存中报警主机、子系统、防区信息 + */ + public void refresh() { + // 报警主机信息 + hosts = getList(1, 20, null, null, "105", null); + + // 子系统、防区信息 + mapList = getList(1, 100, null, null, "100", null); + } + /** * 和iot联调测试专用接口 * * @param id * @param byBypassStatus */ - public void test(String id, int byBypassStatus, int presence, String type) { - - int pntType = 6; - int pntTypeValue = 0; - - // 离线状态 - if (presence == 0) { - int typeInt = "1".equals(type) ? 2 : 3; - test1(id, pntType, pntTypeValue, typeInt); - } - // 子系统 - else if (presence == 2) { - pntTypeValue = 1; - test1(id, pntType, pntTypeValue, 3); - - pntType = 10; - pntTypeValue = byBypassStatus == 5 ? 0 : 1; - test1(id, pntType, pntTypeValue, 3); - } - // 防区 撤防-6 布防-5 旁路-7 - else { - pntTypeValue = 1; - test1(id, pntType, pntTypeValue, 2); - - pntType = 9; - // 故障 - if (byBypassStatus == 4) { - pntTypeValue = 1; - test1(id, pntType, pntTypeValue, 2); - } - // 未故障 - else { - pntTypeValue = 0; - test1(id, pntType, pntTypeValue, 2); - - pntType = 8; - if (byBypassStatus == 5) { - pntTypeValue = 1; - } else if (byBypassStatus == 6) { - pntTypeValue = 0; - } else if (byBypassStatus == 7) { - pntTypeValue = 2; - } - test1(id, pntType, pntTypeValue, 2); - } - } - } - - public void test1(String id, int pntType, int pntTypeValue, int devType) { - String url = "http://152.136.119.150:81/alarmInformation/hikRemote"; - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); - - Map map = new HashMap<>(); - map.put("id_", id); - map.put("devType_", devType); - map.put("pntType_", pntType); - map.put("pntTypeValue_", pntTypeValue); - String content = JSON.toJSONString(map); - - HttpEntity httpEntity = new HttpEntity<>(content, headers); - - // 发送post请求,并输出结果 - R r = restTemplate.postForObject(url, httpEntity, R.class); -// System.out.println("调用远程服务器接口成功!!:" + r); - } +// public void test(String id, int byBypassStatus, int presence, String type) { +// +// int pntType = 6; +// int pntTypeValue = 0; +// +// // 离线状态 +// if (presence == 0) { +// int typeInt = "1".equals(type) ? 2 : 3; +// test1(id, pntType, pntTypeValue, typeInt); +// } +// // 子系统 +// else if (presence == 2) { +// pntTypeValue = 1; +// test1(id, pntType, pntTypeValue, 3); +// +// pntType = 10; +// pntTypeValue = byBypassStatus == 5 ? 0 : 1; +// test1(id, pntType, pntTypeValue, 3); +// } +// // 防区 撤防-6 布防-5 旁路-7 +// else { +// pntTypeValue = 1; +// test1(id, pntType, pntTypeValue, 2); +// +// pntType = 9; +// // 故障 +// if (byBypassStatus == 4) { +// pntTypeValue = 1; +// test1(id, pntType, pntTypeValue, 2); +// } +// // 未故障 +// else { +// pntTypeValue = 0; +// test1(id, pntType, pntTypeValue, 2); +// +// pntType = 8; +// if (byBypassStatus == 5) { +// pntTypeValue = 1; +// } else if (byBypassStatus == 6) { +// pntTypeValue = 0; +// } else if (byBypassStatus == 7) { +// pntTypeValue = 2; +// } +// test1(id, pntType, pntTypeValue, 2); +// } +// } +// } + +// public void test1(String id, int pntType, int pntTypeValue, int devType) { +// String url = "http://152.136.119.150:81/alarmInformation/hikRemote"; +// HttpHeaders headers = new HttpHeaders(); +// headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); +// +// Map map = new HashMap<>(); +// map.put("id_", id); +// map.put("devType_", devType); +// map.put("pntType_", pntType); +// map.put("pntTypeValue_", pntTypeValue); +// String content = JSON.toJSONString(map); +// +// HttpEntity httpEntity = new HttpEntity<>(content, headers); +// +// // 发送post请求,并输出结果 +// R r = restTemplate.postForObject(url, httpEntity, R.class); +//// System.out.println("调用远程服务器接口成功!!:" + r); +// } }