|
@@ -47,43 +47,48 @@ public class FireDeviceStatusTask {
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
|
@Scheduled(cron = "0/20 * * * * ?")
|
|
@Scheduled(cron = "0/20 * * * * ?")
|
|
|
- public void getFireDeviceStatus() throws InterruptedException {
|
|
|
|
|
- //redis取值
|
|
|
|
|
- List<HardwareFireDeviceVO> list = JSON.parseArray(redisService.getCacheObject(CacheConstants.FIRE_DEVICE_LIST) + "", HardwareFireDeviceVO.class);
|
|
|
|
|
- if (list == null) {
|
|
|
|
|
- logger.info("====灭火设备集合,redis未取到值,数据库查询======");
|
|
|
|
|
- list = hardwareFireDeviceService.selectHardwareFireDeviceList(new HardwareFireDeviceVO());
|
|
|
|
|
- //redis存值,时效1分钟
|
|
|
|
|
- redisService.setCacheObject(CacheConstants.FIRE_DEVICE_LIST, list, 60L, TimeUnit.MINUTES);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public void getFireDeviceStatus() {
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ //redis取值
|
|
|
|
|
+ List<HardwareFireDeviceVO> list = JSON.parseArray(redisService.getCacheObject(CacheConstants.FIRE_DEVICE_LIST) + "", HardwareFireDeviceVO.class);
|
|
|
|
|
+ if (list == null) {
|
|
|
|
|
+ logger.info("====灭火设备集合,redis未取到值,数据库查询======");
|
|
|
|
|
+ list = hardwareFireDeviceService.selectHardwareFireDeviceList(new HardwareFireDeviceVO());
|
|
|
|
|
+ //redis存值,时效1分钟
|
|
|
|
|
+ redisService.setCacheObject(CacheConstants.FIRE_DEVICE_LIST, list, 60L, TimeUnit.MINUTES);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (list != null && list.size()>0) {
|
|
|
|
|
- for (HardwareFireDeviceVO vo : list) {
|
|
|
|
|
- //根据主机地址-位获取主机状态指令
|
|
|
|
|
- String activeCode = FireLaborUtil.getFireActiveOrder(vo.getDeviceUrl());
|
|
|
|
|
- //向mqtt发送状态信息
|
|
|
|
|
- //byte[] activeCodeByte=activeCode.getBytes(StandardCharsets.UTF_8);
|
|
|
|
|
- byte[] activeCodeByte =ReUtil.hexStringToByteArray(activeCode);
|
|
|
|
|
- mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE + vo.getDeviceCode(), activeCodeByte);
|
|
|
|
|
- //兼容指令无反应问题
|
|
|
|
|
- Thread.sleep(500);
|
|
|
|
|
- mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE + vo.getDeviceCode(), activeCodeByte);
|
|
|
|
|
- logger.info("集合数量:" + list.size() + ",mqtt消息推送, 灭火装置状态请求,实验室id:" + vo.getSubjectId() + ",采集器编号:" + vo.getDeviceCode()+",继电器编号"+vo.getRelayCode());
|
|
|
|
|
|
|
+ if (list != null && list.size()>0) {
|
|
|
|
|
+ for (HardwareFireDeviceVO vo : list) {
|
|
|
|
|
+ //根据主机地址-位获取主机状态指令
|
|
|
|
|
+ String activeCode = FireLaborUtil.getFireActiveOrder(vo.getDeviceUrl());
|
|
|
|
|
+ //向mqtt发送状态信息
|
|
|
|
|
+ //byte[] activeCodeByte=activeCode.getBytes(StandardCharsets.UTF_8);
|
|
|
|
|
+ byte[] activeCodeByte =ReUtil.hexStringToByteArray(activeCode);
|
|
|
|
|
+ mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE + vo.getDeviceCode(), activeCodeByte);
|
|
|
|
|
+ //兼容指令无反应问题
|
|
|
|
|
+ Thread.sleep(500);
|
|
|
|
|
+ mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE + vo.getDeviceCode(), activeCodeByte);
|
|
|
|
|
+ logger.info("集合数量:" + list.size() + ",mqtt消息推送, 灭火装置状态请求,实验室id:" + vo.getSubjectId() + ",采集器编号:" + vo.getDeviceCode()+",继电器编号"+vo.getRelayCode());
|
|
|
|
|
|
|
|
|
|
|
|
|
- //获取灭火主机最后一次响应时间,判断响应是否超时
|
|
|
|
|
- Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME+vo.getDeviceCode());
|
|
|
|
|
- if (StringUtils.isNull(timeJson)) {
|
|
|
|
|
- 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(), "1");
|
|
|
|
|
|
|
+ //获取灭火主机最后一次响应时间,判断响应是否超时
|
|
|
|
|
+ Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME+vo.getDeviceCode());
|
|
|
|
|
+ if (StringUtils.isNull(timeJson)) {
|
|
|
|
|
+ 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(), "1");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ logger.info("====暂未查询到灭火主机信息====");
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- logger.info("====暂未查询到灭火主机信息====");
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.info("一键灭火定时任务异常"+e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|