|
|
@@ -1,9 +1,10 @@
|
|
|
package com.zd.alg.fire.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.zd.alg.fire.service.IFireDeviceLogService;
|
|
|
import com.zd.alg.fire.service.IFireDeviceService;
|
|
|
-import com.zd.alg.fire.utils.FireDeviceStatusTask;
|
|
|
+import com.zd.alg.mqtt.MqttSend;
|
|
|
import com.zd.algorithm.api.fire.entity.HardwareFireDevice;
|
|
|
import com.zd.algorithm.api.fire.entity.HardwareFireDeviceLog;
|
|
|
import com.zd.algorithm.api.fire.entity.vo.HardwareFireDeviceVO;
|
|
|
@@ -16,6 +17,7 @@ import com.zd.common.core.web.controller.BaseController;
|
|
|
import com.zd.laboratory.api.feign.RemoteLaboratoryService;
|
|
|
import com.zd.model.constant.CacheConstants;
|
|
|
import com.zd.model.constant.CacheDevice;
|
|
|
+import com.zd.model.constant.MqttConstants;
|
|
|
import com.zd.model.domain.ResultData;
|
|
|
import com.zd.model.domain.per.PerFun;
|
|
|
import com.zd.model.domain.per.PerPrefix;
|
|
|
@@ -27,6 +29,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@@ -54,12 +57,42 @@ public class FireDeviceController extends BaseController {
|
|
|
@Autowired
|
|
|
private RemoteLaboratoryService remoteLaboratoryService;
|
|
|
|
|
|
+ /***
|
|
|
+ * 固定30s
|
|
|
+ */
|
|
|
+ @Value("${time.direTime}")
|
|
|
+ private Long direTime;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MqttSend mqttSend;
|
|
|
+
|
|
|
+ /***
|
|
|
+ * 是否取消灭火
|
|
|
+ */
|
|
|
+ private String CANCEL_OUTFILE="cancel_outFile";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手动灭火时间
|
|
|
+ */
|
|
|
+ private String ARTIFICIAL_OUT_FILE="artificial_out_file";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 继电器等待时间
|
|
|
+ */
|
|
|
@Value("${time.waitTime}")
|
|
|
private Long waitTime;
|
|
|
|
|
|
+ /***
|
|
|
+ * 灭火主机掉线时间
|
|
|
+ */
|
|
|
@Value("${time.onlineTime}")
|
|
|
- private Long onlineTime;
|
|
|
+ public Long onlineTime;
|
|
|
|
|
|
+ /***
|
|
|
+ * 灭火倒计时时间
|
|
|
+ */
|
|
|
+ @Value("${time.countDown}")
|
|
|
+ public Long countDown;
|
|
|
|
|
|
/**
|
|
|
* 获取主机状态(首次加载)
|
|
|
@@ -81,7 +114,8 @@ public class FireDeviceController extends BaseController {
|
|
|
boolean isexist = false;
|
|
|
//是否灭火中
|
|
|
boolean outfireing =false;
|
|
|
-
|
|
|
+ //时间差
|
|
|
+ long timeDifference=-1;
|
|
|
if (StringUtils.isNull(subjectId)) {
|
|
|
return ResultData.fail("实验室id参数为空");
|
|
|
}
|
|
|
@@ -125,7 +159,12 @@ public class FireDeviceController extends BaseController {
|
|
|
outfireing = startSpray==1?true:false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ //手动灭火和当前时差
|
|
|
+ Long outfireTime = redisService.getCacheObject(ARTIFICIAL_OUT_FILE+list.get(0).getDeviceCode());
|
|
|
+ if(StringUtils.isNotNull(outfireTime)){
|
|
|
+ timeDifference = System.currentTimeMillis()-outfireTime;
|
|
|
+ timeDifference = timeDifference/1000;
|
|
|
+ }
|
|
|
//查询该实验室是否存在火焰摄像头报警
|
|
|
JSONObject fireJson = redisService.getCacheObject(CacheDevice.FIRE_CAMERA_KEY.getRedisKey()+subjectId);
|
|
|
if (StringUtils.isNotNull(fireJson)) {
|
|
|
@@ -139,6 +178,8 @@ public class FireDeviceController extends BaseController {
|
|
|
map.put("isexist", isexist);
|
|
|
map.put("outfireing", outfireing);
|
|
|
map.put("fireDevice", list.get(0));
|
|
|
+ map.put("newTime", System.currentTimeMillis());
|
|
|
+ map.put("timeDifference", timeDifference);
|
|
|
return ResultData.success(map);
|
|
|
}
|
|
|
|
|
|
@@ -228,39 +269,129 @@ public class FireDeviceController extends BaseController {
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping(value = "/outfireapp")
|
|
|
- public ResultData outFire(Long subjectId) throws InterruptedException {
|
|
|
+ public ResultData outFire(Long subjectId,String deviceCode) throws InterruptedException {
|
|
|
logger.info("=========小程序端开始一键灭火=======");
|
|
|
- Map<String, Object> map = outFireCom(subjectId);
|
|
|
- if(StringUtils.isNotNull(map.get("check"))){
|
|
|
- return ResultData.fail(map.get("check").toString());
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ //设备是否在线
|
|
|
+ boolean online=false;
|
|
|
+ //获取灭火主机最后一次响应时间,判断响应是否超时
|
|
|
+ Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME+deviceCode);
|
|
|
+ if (StringUtils.isNotNull(timeJson)) {
|
|
|
+ Long timeDiff = (System.currentTimeMillis() - timeJson) / 1000;
|
|
|
+ //时间差 在设置时间内
|
|
|
+ if (timeDiff < onlineTime) {
|
|
|
+ online = true;
|
|
|
+ }
|
|
|
}
|
|
|
+ //int waitTime = 5;//倒计时等待时间(秒)
|
|
|
+ map.put("online", online);
|
|
|
+ map.put("waitTime", countDown);
|
|
|
+ map.put("direTime", direTime);
|
|
|
+ new Thread(()->startTT(subjectId,deviceCode,countDown)).start();
|
|
|
return ResultData.success(map);
|
|
|
}
|
|
|
|
|
|
/***
|
|
|
+ * 确定执行一键灭火
|
|
|
+ * 缓存10秒
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+/* @GetMapping(value = "/isConfirmlOutFile")
|
|
|
+ public ResultData isConfirmlOutFile(Long subjectId){
|
|
|
+ redisService.setCacheObject(CANCEL_OUTFILE+subjectId,"1",6L, TimeUnit.SECONDS);
|
|
|
+ return ResultData.success(1);
|
|
|
+ }*/
|
|
|
+
|
|
|
+ /***
|
|
|
+ * 取消执行一键灭火
|
|
|
+ * 缓存10秒
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/isCancelOutFile")
|
|
|
+ public ResultData isCancelOutFile(Long subjectId){
|
|
|
+ redisService.setCacheObject(CANCEL_OUTFILE+subjectId,"0",countDown, TimeUnit.SECONDS);
|
|
|
+ return ResultData.success(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /***
|
|
|
*发送灭火请求-PC
|
|
|
* @param subjectId
|
|
|
* @return
|
|
|
* @throws InterruptedException
|
|
|
*/
|
|
|
@GetMapping(value = "/outfirepc")
|
|
|
- public ResultData outFirePc(Long subjectId) throws InterruptedException {
|
|
|
- logger.info("=========PC端开始一键灭火=======");
|
|
|
- //执行灭火指令
|
|
|
- Map<String, Object> map = outFireCom(subjectId);
|
|
|
- if(StringUtils.isNotNull(map.get("check"))){
|
|
|
- return ResultData.fail(map.get("check").toString());
|
|
|
+ public ResultData outFirePc(Long subjectId,String deviceCode) throws InterruptedException {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ //设备是否在线
|
|
|
+ boolean online=false;
|
|
|
+ //获取灭火主机最后一次响应时间,判断响应是否超时
|
|
|
+ Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME+deviceCode);
|
|
|
+ if (StringUtils.isNotNull(timeJson)) {
|
|
|
+ Long timeDiff = (System.currentTimeMillis() - timeJson) / 1000;
|
|
|
+ //时间差 在设置时间内
|
|
|
+ if (timeDiff < onlineTime) {
|
|
|
+ online = true;
|
|
|
+ }
|
|
|
}
|
|
|
+ //int waitTime = 5;//倒计时等待时间(秒)
|
|
|
+ map.put("online", online);
|
|
|
+ map.put("waitTime", countDown);
|
|
|
+ map.put("direTime", direTime);
|
|
|
+ new Thread(()->startTT(subjectId,deviceCode,countDown)).start();
|
|
|
return ResultData.success(map);
|
|
|
}
|
|
|
|
|
|
+ public void startTT(Long subjectId,String deviceCode,Long waitTime){
|
|
|
+ //休眠5秒等待前端响应是否取消操作结果
|
|
|
+ try {
|
|
|
+ Thread.sleep(waitTime*1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ //设备是否在线
|
|
|
+ boolean online=false;
|
|
|
+
|
|
|
+ //是否取消灭火
|
|
|
+ String isflg= redisService.getCacheObject(CANCEL_OUTFILE+subjectId);
|
|
|
+ if(StringUtils.isNotNull(isflg)){
|
|
|
+ map.put("isCancel",true);
|
|
|
+ }else{
|
|
|
+ map.put("isCancel",false);
|
|
|
+
|
|
|
+ //获取灭火主机最后一次响应时间,判断响应是否超时
|
|
|
+ Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME+deviceCode);
|
|
|
+ if (StringUtils.isNotNull(timeJson)) {
|
|
|
+ Long timeDiff = (System.currentTimeMillis() - timeJson) / 1000;
|
|
|
+ //时间差 在设置时间内
|
|
|
+ if (timeDiff < onlineTime) {
|
|
|
+ online = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("online", online);
|
|
|
+
|
|
|
+ logger.info("=========PC端开始一键灭火=======");
|
|
|
+ //执行灭火指令
|
|
|
+ try {
|
|
|
+ map = outFireCom(subjectId,map);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*if(StringUtils.isNotNull(map.get("check"))){
|
|
|
+ return ResultData.fail(map.get("check").toString());
|
|
|
+ }*/
|
|
|
+
|
|
|
+ }
|
|
|
/***
|
|
|
*灭火指令发送方法
|
|
|
* @param subjectId
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String,Object> outFireCom(Long subjectId) throws InterruptedException {
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
+ public Map<String,Object> outFireCom(Long subjectId,Map<String, Object> map) throws InterruptedException {
|
|
|
+ //Map<String, Object> map = new HashMap<>();
|
|
|
map.put("check","");
|
|
|
//查询实验室下的硬件
|
|
|
RemoteLabHardware hd = new RemoteLabHardware();
|
|
|
@@ -279,6 +410,7 @@ public class FireDeviceController extends BaseController {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//获取当前实验室下灭火设备状态
|
|
|
HardwareFireDeviceVO fireDeviceVO = new HardwareFireDeviceVO();
|
|
|
fireDeviceVO.setSubjectId(subjectId);
|
|
|
@@ -286,6 +418,9 @@ public class FireDeviceController extends BaseController {
|
|
|
JSONObject object = redisService.getCacheObject(list.get(0).getDeviceCode());
|
|
|
logger.info("灭火设备状态:" + object);
|
|
|
|
|
|
+ //手动灭火时间
|
|
|
+ redisService.setCacheObject(ARTIFICIAL_OUT_FILE+list.get(0).getDeviceCode(),System.currentTimeMillis(),Long.valueOf(list.get(0).getDeviceCountDown()+direTime),TimeUnit.SECONDS);
|
|
|
+
|
|
|
if (StringUtils.isNotNull(object)) {
|
|
|
//异常传感器数量
|
|
|
Integer fireNumber = (Integer) object.get("fireNumber");
|
|
|
@@ -294,14 +429,14 @@ public class FireDeviceController extends BaseController {
|
|
|
//随机补充一路信号 触发灭火
|
|
|
List<RemoteLabHardware> li = new ArrayList<>();
|
|
|
li.add(hdlist.get(0));
|
|
|
- map = sendOutFireMsg(li);
|
|
|
+ map = sendOutFireMsg(li,map,list.get(0).getDeviceCode());
|
|
|
} else if (fireNumber == 0) {
|
|
|
logger.info("手动灭火,灭火设备2路信号正常,发送两路电信号,触发灭火!");
|
|
|
- map = sendOutFireMsg(hdlist);
|
|
|
+ map = sendOutFireMsg(hdlist,map,list.get(0).getDeviceCode());
|
|
|
}
|
|
|
} else {
|
|
|
logger.info("手动灭火,redis中没有获取到信息,但是仍然需要执行灭火流程,发送两路电信号,触发灭火");
|
|
|
- map = sendOutFireMsg(hdlist);
|
|
|
+ map = sendOutFireMsg(hdlist,map,list.get(0).getDeviceCode());
|
|
|
}
|
|
|
|
|
|
//灭火日志添加
|
|
|
@@ -322,8 +457,8 @@ public class FireDeviceController extends BaseController {
|
|
|
* @return
|
|
|
* @throws InterruptedException
|
|
|
*/
|
|
|
- private Map<String, Object> sendOutFireMsg(List<RemoteLabHardware> hdlist) throws InterruptedException {
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
+ private Map<String, Object> sendOutFireMsg(List<RemoteLabHardware> hdlist,Map<String, Object> map,String deviceCode) throws InterruptedException {
|
|
|
+ //Map<String, Object> map = new HashMap<>();
|
|
|
StringBuilder msg = new StringBuilder();
|
|
|
//执行动作结果
|
|
|
boolean flg = true;
|
|
|
@@ -345,6 +480,12 @@ public class FireDeviceController extends BaseController {
|
|
|
Thread.sleep(waitTime);
|
|
|
}
|
|
|
|
|
|
+ //通知前端一键灭火正在执行
|
|
|
+ Map<String,Object> mapstatus = new HashMap<>();
|
|
|
+ mapstatus.put("fireStatus",1);//1成功 0失败
|
|
|
+ mapstatus.put("direTime",direTime);
|
|
|
+ mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE_EXECUTING+deviceCode,JSON.toJSONString(mapstatus));
|
|
|
+
|
|
|
//关闭继电器
|
|
|
for (RemoteLabHardware hardware : hdlist) {
|
|
|
Thread.sleep(waitTime);
|
|
|
@@ -353,7 +494,7 @@ public class FireDeviceController extends BaseController {
|
|
|
logger.info("关闭继电器,执行结果:" + o);
|
|
|
}
|
|
|
map.put("msg", msg);
|
|
|
- map.put("flg", flg);
|
|
|
+ map.put("flg", true);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
@@ -446,4 +587,9 @@ public class FireDeviceController extends BaseController {
|
|
|
return ResultData.success(fireDeviceLogService.insertFireAutomatic(code));
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("fireStatus",1);
|
|
|
+ System.out.println(JSON.toJSONString(map));
|
|
|
+ }
|
|
|
}
|