2023年12月20日09:31:06

main
litao 2 years ago
parent b05a741798
commit 80a61baea9
  1. 19
      src/main/java/org/springblade/hospital/agent/service/HikAgentService.java
  2. 9
      src/main/java/org/springblade/hospital/agent/utils/QueueUtils.java
  3. 42
      src/main/java/org/springblade/hospital/controller/AIoTRequestDemo.java
  4. 8
      src/main/java/org/springblade/hospital/controller/AlarmInformationController.java
  5. 18
      src/main/java/org/springblade/hospital/controller/AppDataController.java
  6. 47
      src/main/java/org/springblade/hospital/hik/alarm/Alarm.java
  7. 6
      src/main/java/org/springblade/hospital/hik/alarm/AlarmDataParse.java
  8. 66
      src/main/java/org/springblade/hospital/newalarm/communicationCom/HTTPClientUtil.java
  9. 2
      src/main/java/org/springblade/hospital/service/impl/AppDataServiceImpl.java
  10. 17
      src/main/java/org/springblade/hospital/utils/CornJobUtil.java
  11. 192
      src/main/java/org/springblade/hospital/utils/ExternalUtils.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<Point> 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<Map> 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<CommonResult> responseObserver) {
log.info("HikAgentService_setDevice来到了grpc服务端{}", request);
// log.info("HikAgentService_setDevice来到了grpc服务端{}", request);
responseObserver.onNext(CommonResult.newBuilder().build());
responseObserver.onCompleted();
}

@ -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());
}

@ -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<String, List<String>> 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<String, List<String>> 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);
}
/* 封装逻辑

@ -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());
boolean xjcg = false;
boolean xiaojing = Alarm.xiaojing(alarmInformation.getHostSerialNumber(), alarmInformation.getSystemNum(), alarmInformation.getDeviceId());
if (xiaojing) {
alarmInformation.setIsClear(1);
return R.status(alarmInformationService.updateById(alarmInformation));
xjcg = alarmInformationService.updateById(alarmInformation);
}
return R.status(xjcg);
}
/**

@ -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();

@ -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<Map> 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<Thread> threadList = new ArrayList<>();
ScheduledFuture<?> scheduledFuture = scheduled.scheduleAtFixedRate(() -> {
// log.info("我执行了1");
List<Map> list = externalUtils.getList(0, 0, null, null, "105", null);
List<Map> 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);

@ -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<Map> hostList = externalUtils.getList(0, 0, null, null, "105", sSerialNumber);
List<Map> 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);

@ -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,25 +176,30 @@ public class HTTPClientUtil {
// system子系统号
int system = Integer.parseInt(cidMap.get("system").toString());
// zone防区号
List<Map> 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();
if (StringUtils.isNotBlank(alarmMessageType)) {
alarmInformation.setReportTime(new Date());
alarmInformation.setType(sCIDCode);
alarmInformation.setContent(DictBizCache.getValue("alarm_message_type", sCIDCode));
alarmInformation.setContent(alarmMessageType);
if (cidMap.get("system") != null) {
alarmInformation.setSystemNum(Integer.parseInt(cidMap.get("system").toString()));
}
@ -223,20 +225,23 @@ public class HTTPClientUtil {
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());
alarmInformation.setCameraCode(DictBizCache.getValue("hikvision_camera", map.get("name").toString()));
}
// 主动修改设备状态-物联网平台
if ("3973".equals(sCIDCode)) {
if ("3401".equals(sCIDCode)) {
// 布防
externalUtils.bizDevice(Integer.parseInt(String.valueOf(map.get("id"))), 5);
} else if ("1973".equals(sCIDCode) || "3570".equals(sCIDCode)) {
} 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);
}
}
boolean save = alarmInformationService.save(alarmInformation);
alarmInformationService.save(alarmInformation);
}
// 只保留“即时报警”、“设备防拆报警”
if ("1103".equals(sCIDCode) || "1137".equals(sCIDCode)) {
// 上报海信iot平台
@ -244,7 +249,8 @@ public class HTTPClientUtil {
queueUtils = SpringUtil.getBean(QueueUtils.class);
}
List<Map> hostList = externalUtils.getList(0, 0, null, null, "105", sSerialNumber);
List<Map> 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);
@ -261,33 +267,11 @@ public class HTTPClientUtil {
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<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);
}

@ -77,7 +77,7 @@ public class AppDataServiceImpl extends BaseServiceImpl<AppDataMapper, AppData>
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);

@ -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<CornJob> jobs = cornJobService.list(Wrappers.<CornJob>lambdaQuery().eq(CornJob::getStatus, 1).eq(CornJob::getIsRegular, 1));

@ -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<Map> hosts = new ArrayList<>();
private List<Map> mapList = new ArrayList<>();
public List<Map> getHosts() {
return hosts;
}
public List<Map> getMapList() {
return mapList;
}
/**
* 获取物联网平台token
*/
@ -143,20 +156,6 @@ public class ExternalUtils {
* 更新设备状态
*/
public void updateStatus() {
List<Map> hosts = null;
List<Map> 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<Map> 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<Map> subSyss = subSysList.stream().filter(sys -> Integer.parseInt(JSONObject.parseObject(sys.get("SubSys").toString(), Map.class).get("id").toString()) == sCIDCode).collect(Collectors.toList());
List<Map> 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<String, Object> 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<String> 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<String, Object> 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<String> httpEntity = new HttpEntity<>(content, headers);
//
// // 发送post请求,并输出结果
// R r = restTemplate.postForObject(url, httpEntity, R.class);
//// System.out.println("调用远程服务器接口成功!!:" + r);
// }
}

Loading…
Cancel
Save