|
@@ -1,15 +1,17 @@
|
|
|
package com.zd.alg.fire.utils;
|
|
package com.zd.alg.fire.utils;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.zd.alg.fire.controller.FireDeviceController;
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.zd.alg.fire.service.IFireDeviceService;
|
|
import com.zd.alg.fire.service.IFireDeviceService;
|
|
|
import com.zd.alg.mqtt.MqttSend;
|
|
import com.zd.alg.mqtt.MqttSend;
|
|
|
import com.zd.algorithm.api.fire.entity.vo.HardwareFireDeviceVO;
|
|
import com.zd.algorithm.api.fire.entity.vo.HardwareFireDeviceVO;
|
|
|
import com.zd.common.core.redis.RedisService;
|
|
import com.zd.common.core.redis.RedisService;
|
|
|
import com.zd.common.core.utils.ReUtil;
|
|
import com.zd.common.core.utils.ReUtil;
|
|
|
import com.zd.common.core.utils.StringUtils;
|
|
import com.zd.common.core.utils.StringUtils;
|
|
|
|
|
+import com.zd.laboratory.api.entity.OneClickFireDTO;
|
|
|
import com.zd.laboratory.api.feign.RemoteLaboratoryService;
|
|
import com.zd.laboratory.api.feign.RemoteLaboratoryService;
|
|
|
import com.zd.model.constant.CacheConstants;
|
|
import com.zd.model.constant.CacheConstants;
|
|
|
|
|
+import com.zd.model.constant.CacheDevice;
|
|
|
import com.zd.model.constant.MqttConstants;
|
|
import com.zd.model.constant.MqttConstants;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -17,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
@@ -38,17 +39,15 @@ public class FireDeviceStatusTask {
|
|
|
private MqttSend mqttSend;
|
|
private MqttSend mqttSend;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisService redisService;
|
|
private RedisService redisService;
|
|
|
-
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private RemoteLaboratoryService laboratoryService;
|
|
|
|
|
|
|
+ RemoteLaboratoryService remoteLaboratoryService;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 定时更新灭火装置状态
|
|
* 定时更新灭火装置状态
|
|
|
- *
|
|
|
|
|
*/
|
|
*/
|
|
|
@Scheduled(cron = "0/20 * * * * ?")
|
|
@Scheduled(cron = "0/20 * * * * ?")
|
|
|
public void getFireDeviceStatus() {
|
|
public void getFireDeviceStatus() {
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
//redis取值
|
|
//redis取值
|
|
|
List<HardwareFireDeviceVO> list = JSON.parseArray(redisService.getCacheObject(CacheConstants.FIRE_DEVICE_LIST) + "", HardwareFireDeviceVO.class);
|
|
List<HardwareFireDeviceVO> list = JSON.parseArray(redisService.getCacheObject(CacheConstants.FIRE_DEVICE_LIST) + "", HardwareFireDeviceVO.class);
|
|
@@ -59,36 +58,49 @@ public class FireDeviceStatusTask {
|
|
|
redisService.setCacheObject(CacheConstants.FIRE_DEVICE_LIST, list, 60L, TimeUnit.MINUTES);
|
|
redisService.setCacheObject(CacheConstants.FIRE_DEVICE_LIST, list, 60L, TimeUnit.MINUTES);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (list != null && list.size()>0) {
|
|
|
|
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
for (HardwareFireDeviceVO vo : list) {
|
|
for (HardwareFireDeviceVO vo : list) {
|
|
|
//根据主机地址-位获取主机状态指令
|
|
//根据主机地址-位获取主机状态指令
|
|
|
String activeCode = FireLaborUtil.getFireActiveOrder(vo.getDeviceUrl());
|
|
String activeCode = FireLaborUtil.getFireActiveOrder(vo.getDeviceUrl());
|
|
|
//向mqtt发送状态信息
|
|
//向mqtt发送状态信息
|
|
|
//byte[] activeCodeByte=activeCode.getBytes(StandardCharsets.UTF_8);
|
|
//byte[] activeCodeByte=activeCode.getBytes(StandardCharsets.UTF_8);
|
|
|
- byte[] activeCodeByte =ReUtil.hexStringToByteArray(activeCode);
|
|
|
|
|
|
|
+ byte[] activeCodeByte = ReUtil.hexStringToByteArray(activeCode);
|
|
|
mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE + vo.getDeviceCode(), activeCodeByte);
|
|
mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE + vo.getDeviceCode(), activeCodeByte);
|
|
|
//兼容指令无反应问题
|
|
//兼容指令无反应问题
|
|
|
/*Thread.sleep(500);
|
|
/*Thread.sleep(500);
|
|
|
mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE + vo.getDeviceCode(), activeCodeByte);*/
|
|
mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE + vo.getDeviceCode(), activeCodeByte);*/
|
|
|
- logger.info("集合数量:" + list.size() + ",mqtt消息推送, 灭火装置状态请求,实验室id:" + vo.getSubjectId() + ",采集器编号:" + vo.getDeviceCode()+",继电器编号"+vo.getRelayCode());
|
|
|
|
|
|
|
+ logger.info("集合数量:" + list.size() + ",mqtt消息推送, 灭火装置状态请求,实验室id:" + vo.getSubjectId() + ",采集器编号:" + vo.getDeviceCode() + ",继电器编号" + vo.getRelayCode());
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取灭火主机最后一次响应时间,判断响应是否超时
|
|
//获取灭火主机最后一次响应时间,判断响应是否超时
|
|
|
- Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME+vo.getDeviceCode());
|
|
|
|
|
|
|
+ Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME + vo.getDeviceCode());
|
|
|
if (StringUtils.isNull(timeJson)) {
|
|
if (StringUtils.isNull(timeJson)) {
|
|
|
- logger.info("设备掉线,实验室id:"+vo.getSubjectId()+",采集器编号:"+vo.getDeviceCode());
|
|
|
|
|
|
|
+ logger.info("设备掉线,实验室id:" + vo.getSubjectId() + ",采集器编号:" + vo.getDeviceCode());
|
|
|
//离线
|
|
//离线
|
|
|
- mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE_ONLINE+vo.getDeviceCode(), "0");
|
|
|
|
|
- }else{
|
|
|
|
|
|
|
+ mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE_ONLINE + vo.getDeviceCode(), "0");
|
|
|
|
|
+ } else {
|
|
|
//在线
|
|
//在线
|
|
|
- mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE_ONLINE+vo.getDeviceCode(), "1");
|
|
|
|
|
|
|
+ mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE_ONLINE + vo.getDeviceCode(), "1");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //查询该实验室是否存在火焰摄像头报警
|
|
|
|
|
+ JSONObject fireJson = redisService.getCacheObject(CacheDevice.FIRE_CAMERA_KEY.getRedisKey() + vo.getSubjectId());
|
|
|
|
|
+ logger.info("火焰摄像头情况" + fireJson);
|
|
|
|
|
+ if (StringUtils.isNotNull(fireJson)) {
|
|
|
|
|
+ OneClickFireDTO dto = new OneClickFireDTO();
|
|
|
|
|
+ dto.setDeviceCode(vo.getDeviceCode());
|
|
|
|
|
+ dto.setIfFire(1);
|
|
|
|
|
+ dto.setAutomanual(2);
|
|
|
|
|
+ remoteLaboratoryService.oneClickFire(dto);
|
|
|
|
|
+ logger.info("火焰摄像头情况异常,通知预案。");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
logger.info("====暂未查询到灭火主机信息====");
|
|
logger.info("====暂未查询到灭火主机信息====");
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- logger.info("一键灭火定时任务异常"+e);
|
|
|
|
|
|
|
+ logger.info("一键灭火定时任务异常" + e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|