|
|
|
@ -3,9 +3,9 @@ package org.springblade.hospital.newalarm.communicationCom; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
import com.google.protobuf.ByteString; |
|
|
|
import com.google.protobuf.ByteString; |
|
|
|
import com.hisense.device.agent.grpc.Point; |
|
|
|
import com.hisense.device.agent.grpc.Point; |
|
|
|
import lombok.extern.log4j.Log4j; |
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.httpclient.HttpClient; |
|
|
|
import org.apache.commons.httpclient.HttpClient; |
|
|
|
import org.apache.commons.httpclient.UsernamePasswordCredentials; |
|
|
|
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.GetMethod; |
|
|
|
import org.apache.commons.httpclient.methods.PostMethod; |
|
|
|
import org.apache.commons.httpclient.methods.PostMethod; |
|
|
|
import org.apache.commons.httpclient.methods.PutMethod; |
|
|
|
import org.apache.commons.httpclient.methods.PutMethod; |
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import org.springblade.common.cache.DictBizCache; |
|
|
|
import org.springblade.common.cache.DictBizCache; |
|
|
|
import org.springblade.core.tool.utils.SpringUtil; |
|
|
|
import org.springblade.core.tool.utils.SpringUtil; |
|
|
|
import org.springblade.hospital.agent.utils.DataTrans; |
|
|
|
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.service.IAlarmInformationService; |
|
|
|
import org.springblade.hospital.utils.ExternalUtils; |
|
|
|
import org.springblade.hospital.utils.ExternalUtils; |
|
|
|
import org.springblade.hospital.websocket.WebSocketServer; |
|
|
|
import org.springblade.hospital.websocket.WebSocketServer; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springblade.modules.system.service.IDictBizService; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class HTTPClientUtil { |
|
|
|
public class HTTPClientUtil { |
|
|
|
@ -49,7 +46,7 @@ public class HTTPClientUtil { |
|
|
|
|
|
|
|
|
|
|
|
public static String renzheng(String rzUrl, HttpClient client) { |
|
|
|
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); |
|
|
|
client.getState().setCredentials(AuthScope.ANY, creds); |
|
|
|
GetMethod method = new GetMethod(rzUrl); |
|
|
|
GetMethod method = new GetMethod(rzUrl); |
|
|
|
method.setDoAuthentication(true); |
|
|
|
method.setDoAuthentication(true); |
|
|
|
@ -77,7 +74,7 @@ public class HTTPClientUtil { |
|
|
|
|
|
|
|
|
|
|
|
public static String statusRz(String rzUrl, HttpClient client) throws IOException { |
|
|
|
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); |
|
|
|
client.getState().setCredentials(AuthScope.ANY, creds); |
|
|
|
GetMethod method = new GetMethod(rzUrl); |
|
|
|
GetMethod method = new GetMethod(rzUrl); |
|
|
|
method.setDoAuthentication(true); |
|
|
|
method.setDoAuthentication(true); |
|
|
|
@ -179,64 +176,72 @@ public class HTTPClientUtil { |
|
|
|
// system子系统号
|
|
|
|
// system子系统号
|
|
|
|
int system = Integer.parseInt(cidMap.get("system").toString()); |
|
|
|
int system = Integer.parseInt(cidMap.get("system").toString()); |
|
|
|
// zone防区号
|
|
|
|
// zone防区号
|
|
|
|
|
|
|
|
List<Map> mapList = externalUtils.getMapList(); |
|
|
|
if (cidMap.get("zone") != null) { |
|
|
|
if (cidMap.get("zone") != null) { |
|
|
|
zone = Integer.parseInt(cidMap.get("zone").toString()) + 1; |
|
|
|
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 { |
|
|
|
} 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) { |
|
|
|
if (alarmInformationService == null) { |
|
|
|
alarmInformationService = SpringUtil.getBean(IAlarmInformationService.class); |
|
|
|
alarmInformationService = SpringUtil.getBean(IAlarmInformationService.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String sCIDCode = cidMap.get("code").toString(); |
|
|
|
String sCIDCode = cidMap.get("code").toString(); |
|
|
|
|
|
|
|
String alarmMessageType = DictBizCache.getValue("alarm_message_type", sCIDCode); |
|
|
|
AlarmInformation alarmInformation = new AlarmInformation(); |
|
|
|
AlarmInformation alarmInformation = new AlarmInformation(); |
|
|
|
alarmInformation.setReportTime(new Date()); |
|
|
|
if (StringUtils.isNotBlank(alarmMessageType)) { |
|
|
|
alarmInformation.setType(sCIDCode); |
|
|
|
alarmInformation.setReportTime(new Date()); |
|
|
|
alarmInformation.setContent(DictBizCache.getValue("alarm_message_type", sCIDCode)); |
|
|
|
alarmInformation.setType(sCIDCode); |
|
|
|
if (cidMap.get("system") != null) { |
|
|
|
alarmInformation.setContent(alarmMessageType); |
|
|
|
alarmInformation.setSystemNum(Integer.parseInt(cidMap.get("system").toString())); |
|
|
|
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]); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
alarmInformation.setDeviceId(tagsMap.get("pmac").toString()); |
|
|
|
alarmInformation.setHostSerialNumber(sSerialNumber); |
|
|
|
Map bizProduct = JSONObject.parseObject(JSON.toJSONString(map.get("bizProduct")), Map.class); |
|
|
|
alarmInformation.setHostIp(resMap.get("ipAddress").toString()); |
|
|
|
alarmInformation.setProductName(bizProduct.get("name").toString()); |
|
|
|
alarmInformation.setAlarmType(1); |
|
|
|
if (tagsMap.get("cameraCode") != null) { |
|
|
|
|
|
|
|
alarmInformation.setCameraCode(tagsMap.get("cameraCode").toString()); |
|
|
|
if (CollectionUtils.isNotEmpty(list)) { |
|
|
|
} |
|
|
|
Map map = list.get(0); |
|
|
|
|
|
|
|
alarmInformation.setDeviceName(map.get("name").toString()); |
|
|
|
// 主动修改设备状态-物联网平台
|
|
|
|
alarmInformation.setDeviceType(Integer.parseInt(String.valueOf(map.get("pid")))); |
|
|
|
if ("3973".equals(sCIDCode)) { |
|
|
|
String s = JSON.toJSONString(map.get("tags")).replace("\\", ""); |
|
|
|
externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 5); |
|
|
|
s = s.substring(1, s.length() - 1); |
|
|
|
} else if ("1973".equals(sCIDCode) || "3570".equals(sCIDCode)) { |
|
|
|
Map tagsMap = JSONObject.parseObject(s, Map.class); |
|
|
|
externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 6); |
|
|
|
alarmInformation.setFloorNo(tagsMap.get("floorNo").toString()); |
|
|
|
} else if ("1570".equals(sCIDCode)) { |
|
|
|
alarmInformation.setBuildId(tagsMap.get("buildingNo").toString()); |
|
|
|
externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 7); |
|
|
|
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)) { |
|
|
|
if ("1103".equals(sCIDCode) || "1137".equals(sCIDCode)) { |
|
|
|
// 上报海信iot平台
|
|
|
|
// 上报海信iot平台
|
|
|
|
@ -244,50 +249,29 @@ public class HTTPClientUtil { |
|
|
|
queueUtils = SpringUtil.getBean(QueueUtils.class); |
|
|
|
queueUtils = SpringUtil.getBean(QueueUtils.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<Map> hostList = externalUtils.getList(0, 0, null, null, "105", sSerialNumber); |
|
|
|
List<Map> hostList = externalUtils.getHosts(); |
|
|
|
Map hostMap = hostList.get(0); |
|
|
|
if (CollectionUtils.isNotEmpty(hostList)) { |
|
|
|
String s = JSON.toJSONString(hostMap.get("tags")).replace("\\", ""); |
|
|
|
Map hostMap = hostList.get(0); |
|
|
|
s = s.substring(1, s.length() - 1); |
|
|
|
String s = JSON.toJSONString(hostMap.get("tags")).replace("\\", ""); |
|
|
|
Map tagsMap = JSONObject.parseObject(s, Map.class); |
|
|
|
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); |
|
|
|
byte[] byteValue = DataTrans.shortToBytesBigEndian((short) 1); |
|
|
|
Point point = Point.newBuilder() |
|
|
|
ByteString byteString = ByteString.copyFrom(byteValue); |
|
|
|
.setData(byteString) |
|
|
|
Point point = Point.newBuilder() |
|
|
|
.setId(tagsMap.get("mac").toString() + "_sector_" + zone) |
|
|
|
.setData(byteString) |
|
|
|
.setDevType(2) |
|
|
|
.setId(tagsMap.get("mac").toString() + "_sector_" + zone) |
|
|
|
.setPntType(7) |
|
|
|
.setDevType(2) |
|
|
|
.build(); |
|
|
|
.setPntType(7) |
|
|
|
boolean b = queueUtils.saveQueueDataStatus(point); |
|
|
|
.build(); |
|
|
|
System.out.println("===" + b); |
|
|
|
boolean b = queueUtils.saveQueueDataStatus(point); |
|
|
|
|
|
|
|
System.out.println("===" + b); |
|
|
|
// 报警信息发送到远程服务器
|
|
|
|
|
|
|
|
// if (restTemplate == null) {
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
// restTemplate = SpringUtil.getBean(RestTemplate.class);
|
|
|
|
jsonObject.put("message", JSONObject.toJSONString(alarmInformation)); |
|
|
|
// }
|
|
|
|
WebSocketServer.sendInfo(jsonObject); |
|
|
|
// String url = "http://152.136.119.150:81/alarmInformation/hikRemote";
|
|
|
|
} |
|
|
|
// HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
|
|
|
// headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Map<String, Object> 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<String> 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); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// System.out.println("接收到的数据:" + resMap);
|
|
|
|
// System.out.println("接收到的数据:" + resMap);
|
|
|
|
} |
|
|
|
} |
|
|
|
|