|
|
@@ -69,12 +69,12 @@ public class FireDeviceController extends BaseController {
|
|
|
/***
|
|
|
* 是否取消灭火
|
|
|
*/
|
|
|
- private String CANCEL_OUTFILE = "cancel_outFile";
|
|
|
+ private String CANCEL_OUTFILE="cancel_outFile";
|
|
|
|
|
|
/**
|
|
|
* 手动灭火时间
|
|
|
*/
|
|
|
- private String ARTIFICIAL_OUT_FILE = "artificial_out_file";
|
|
|
+ private String ARTIFICIAL_OUT_FILE="artificial_out_file";
|
|
|
|
|
|
/**
|
|
|
* 继电器等待时间
|
|
|
@@ -113,9 +113,9 @@ public class FireDeviceController extends BaseController {
|
|
|
//是否配置灭火设备
|
|
|
boolean isexist = false;
|
|
|
//是否灭火中
|
|
|
- boolean outfireing = false;
|
|
|
+ boolean outfireing =false;
|
|
|
//时间差
|
|
|
- long timeDifference = -1;
|
|
|
+ long timeDifference=-1;
|
|
|
if (StringUtils.isNull(subjectId)) {
|
|
|
return ResultData.fail("实验室id参数为空");
|
|
|
}
|
|
|
@@ -133,7 +133,7 @@ public class FireDeviceController extends BaseController {
|
|
|
} else {
|
|
|
isexist = true;
|
|
|
//获取灭火主机最后一次响应时间,判断响应是否超时
|
|
|
- Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME + list.get(0).getRelayCode());
|
|
|
+ Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME+list.get(0).getDeviceCode());
|
|
|
if (StringUtils.isNotNull(timeJson)) {
|
|
|
Long timeDiff = (System.currentTimeMillis() - timeJson) / 1000;
|
|
|
//时间差 在设置时间内
|
|
|
@@ -145,7 +145,7 @@ public class FireDeviceController extends BaseController {
|
|
|
//根据编码从redis获取该设备状态
|
|
|
//String str = "{\"msg\":\"NO:5号设备故障 NO:10号设备火警 \",\"fireNumber\":1,\"fireStatus\":true,\"startSpray\":\"0\",\"gasSpray\":\"0\"}";
|
|
|
//JSONObject strJson = JSONObject.parseObject(str);
|
|
|
- JSONObject strJson = redisService.getCacheObject(list.get(0).getRelayCode());
|
|
|
+ JSONObject strJson = redisService.getCacheObject(list.get(0).getDeviceCode());
|
|
|
if (StringUtils.isNotNull(strJson)) {
|
|
|
Integer fireNumber = (Integer) strJson.get("fireNumber");
|
|
|
if (fireNumber == 1) {
|
|
|
@@ -156,17 +156,17 @@ public class FireDeviceController extends BaseController {
|
|
|
}
|
|
|
//启动喷洒状态 :1是启动 0未启动
|
|
|
Integer startSpray = Integer.valueOf(strJson.get("startSpray").toString());
|
|
|
- outfireing = startSpray == 1 ? true : false;
|
|
|
+ outfireing = startSpray==1?true:false;
|
|
|
}
|
|
|
|
|
|
//手动灭火和当前时差
|
|
|
- Long outfireTime = redisService.getCacheObject(ARTIFICIAL_OUT_FILE + list.get(0).getRelayCode());
|
|
|
- if (StringUtils.isNotNull(outfireTime)) {
|
|
|
- timeDifference = System.currentTimeMillis() - outfireTime;
|
|
|
- timeDifference = timeDifference / 1000;
|
|
|
+ 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);
|
|
|
+ JSONObject fireJson = redisService.getCacheObject(CacheDevice.FIRE_CAMERA_KEY.getRedisKey()+subjectId);
|
|
|
if (StringUtils.isNotNull(fireJson)) {
|
|
|
fire = true;
|
|
|
}
|
|
|
@@ -186,11 +186,11 @@ public class FireDeviceController extends BaseController {
|
|
|
/**
|
|
|
* 定时状态请求
|
|
|
*
|
|
|
- * @param relayCode
|
|
|
+ * @param deviceCode
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping(value = "/getStatusDetails")
|
|
|
- public ResultData getStatus(String relayCode) {
|
|
|
+ public ResultData getStatus(String deviceCode) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
//烟雾
|
|
|
boolean smoke = false;
|
|
|
@@ -201,14 +201,14 @@ public class FireDeviceController extends BaseController {
|
|
|
//是否在线
|
|
|
boolean online = false;
|
|
|
//是否灭火中
|
|
|
- boolean outfireing = false;
|
|
|
+ boolean outfireing =false;
|
|
|
|
|
|
- if (StringUtils.isNull(relayCode)) {
|
|
|
+ if (StringUtils.isNull(deviceCode)) {
|
|
|
ResultData.fail("设备编号参数为空");
|
|
|
}
|
|
|
|
|
|
//获取灭火主机最后一次响应时间,判断响应是否超时
|
|
|
- Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME + relayCode);
|
|
|
+ Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME+deviceCode);
|
|
|
if (StringUtils.isNotNull(timeJson)) {
|
|
|
Long timeDiff = (System.currentTimeMillis() - timeJson) / 1000;
|
|
|
//时间差 在设置时间内
|
|
|
@@ -220,7 +220,7 @@ public class FireDeviceController extends BaseController {
|
|
|
//根据编码从redis获取该设备状态
|
|
|
/*String str = "{\"msg\":\"NO:5号设备故障 NO:10号设备火警 \",\"fireNumber\":1,\"fireStatus\":true,\"startSpray\":\"0\",\"gasSpray\":\"0\"}";
|
|
|
JSONObject strJson = JSONObject.parseObject(str);*/
|
|
|
- JSONObject strJson = redisService.getCacheObject(relayCode);
|
|
|
+ JSONObject strJson = redisService.getCacheObject(deviceCode);
|
|
|
if (StringUtils.isNotNull(strJson)) {
|
|
|
Integer fireNumber = (Integer) strJson.get("fireNumber");
|
|
|
if (fireNumber == 1) {
|
|
|
@@ -231,28 +231,28 @@ public class FireDeviceController extends BaseController {
|
|
|
}
|
|
|
//启动喷洒状态 :1是启动 0未启动
|
|
|
Integer startSpray = Integer.valueOf(strJson.get("startSpray").toString());
|
|
|
- outfireing = startSpray == 1 ? true : false;
|
|
|
+ outfireing = startSpray==1?true:false;
|
|
|
}
|
|
|
|
|
|
//根据采集器编号获取灭火主机详情
|
|
|
- HardwareFireDeviceVO fireDeviceVo = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_DETAILS + relayCode);
|
|
|
- Long subjectId = 0L;
|
|
|
- if (StringUtils.isNull(fireDeviceVo)) {
|
|
|
+ HardwareFireDeviceVO fireDeviceVo = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_DETAILS+deviceCode) ;
|
|
|
+ Long subjectId=0L;
|
|
|
+ if(StringUtils.isNull(fireDeviceVo)){
|
|
|
HardwareFireDeviceVO vo = new HardwareFireDeviceVO();
|
|
|
- vo.setDeviceCode(relayCode);
|
|
|
+ vo.setDeviceCode(deviceCode);
|
|
|
List<HardwareFireDeviceVO> list = fireDeviceService.selectHardwareFireDeviceList(vo);
|
|
|
- if (list.size() > 0) {
|
|
|
+ if(list.size()>0){
|
|
|
subjectId = list.get(0).getSubjectId();
|
|
|
- redisService.setCacheObject(CacheConstants.FIRE_DEVICE_DETAILS + list.get(0).getDeviceCode(), list.get(0), 300L, TimeUnit.MINUTES);
|
|
|
- } else {
|
|
|
+ redisService.setCacheObject(CacheConstants.FIRE_DEVICE_DETAILS+list.get(0).getDeviceCode(),list.get(0),300L, TimeUnit.MINUTES);
|
|
|
+ }else{
|
|
|
logger.info("====定时请求状态时,根据code没有查询到灭火主机详情=====");
|
|
|
}
|
|
|
- } else {
|
|
|
- subjectId = fireDeviceVo.getSubjectId();
|
|
|
+ }else{
|
|
|
+ subjectId=fireDeviceVo.getSubjectId();
|
|
|
}
|
|
|
|
|
|
//查询该实验室是否存在火焰摄像头报警
|
|
|
- JSONObject fireJson = redisService.getCacheObject(CacheDevice.FIRE_CAMERA_KEY.getRedisKey() + subjectId);
|
|
|
+ JSONObject fireJson = redisService.getCacheObject(CacheDevice.FIRE_CAMERA_KEY.getRedisKey()+subjectId);
|
|
|
if (StringUtils.isNotNull(fireJson)) {
|
|
|
fire = true;
|
|
|
}
|
|
|
@@ -269,13 +269,13 @@ public class FireDeviceController extends BaseController {
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping(value = "/outfireapp")
|
|
|
- public ResultData outFire(Long subjectId, String relayCode) throws InterruptedException {
|
|
|
+ public ResultData outFire(Long subjectId,String deviceCode) throws InterruptedException {
|
|
|
logger.info("=========小程序端开始一键灭火=======");
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
//设备是否在线
|
|
|
- boolean online = false;
|
|
|
+ boolean online=false;
|
|
|
//获取灭火主机最后一次响应时间,判断响应是否超时
|
|
|
- Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME + relayCode);
|
|
|
+ Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME+deviceCode);
|
|
|
if (StringUtils.isNotNull(timeJson)) {
|
|
|
Long timeDiff = (System.currentTimeMillis() - timeJson) / 1000;
|
|
|
//时间差 在设置时间内
|
|
|
@@ -287,18 +287,29 @@ public class FireDeviceController extends BaseController {
|
|
|
map.put("online", online);
|
|
|
map.put("waitTime", countDown);
|
|
|
map.put("direTime", direTime);
|
|
|
- new Thread(() -> startTT(subjectId, relayCode, countDown)).start();
|
|
|
+ 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);
|
|
|
+ public ResultData isCancelOutFile(Long subjectId){
|
|
|
+ redisService.setCacheObject(CANCEL_OUTFILE+subjectId,"0",countDown, TimeUnit.SECONDS);
|
|
|
return ResultData.success(1);
|
|
|
}
|
|
|
|
|
|
@@ -309,12 +320,12 @@ public class FireDeviceController extends BaseController {
|
|
|
* @throws InterruptedException
|
|
|
*/
|
|
|
@GetMapping(value = "/outfirepc")
|
|
|
- public ResultData outFirePc(Long subjectId, String relayCode){
|
|
|
+ public ResultData outFirePc(Long subjectId,String deviceCode) throws InterruptedException {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
//设备是否在线
|
|
|
- boolean online = false;
|
|
|
+ boolean online=false;
|
|
|
//获取灭火主机最后一次响应时间,判断响应是否超时
|
|
|
- Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME + relayCode);
|
|
|
+ Long timeJson = redisService.getCacheObject(CacheConstants.FIRE_DEVICE_RESPOND_TIME+deviceCode);
|
|
|
if (StringUtils.isNotNull(timeJson)) {
|
|
|
Long timeDiff = (System.currentTimeMillis() - timeJson) / 1000;
|
|
|
//时间差 在设置时间内
|
|
|
@@ -326,55 +337,70 @@ public class FireDeviceController extends BaseController {
|
|
|
map.put("online", online);
|
|
|
map.put("waitTime", countDown);
|
|
|
map.put("direTime", direTime);
|
|
|
- new Thread(() -> startTT(subjectId, relayCode, countDown)).start();
|
|
|
+ new Thread(()->startTT(subjectId,deviceCode,countDown)).start();
|
|
|
return ResultData.success(map);
|
|
|
}
|
|
|
|
|
|
- public void startTT(Long subjectId, String relayCode, Long waitTime) {
|
|
|
+ public void startTT(Long subjectId,String deviceCode,Long waitTime){
|
|
|
//休眠5秒等待前端响应是否取消操作结果
|
|
|
try {
|
|
|
- Thread.sleep(waitTime * 1000);
|
|
|
+ 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)) {
|
|
|
+ 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);
|
|
|
|
|
|
- } else {
|
|
|
logger.info("=========PC端开始一键灭火=======");
|
|
|
//执行灭火指令
|
|
|
try {
|
|
|
- map = outFireCom(subjectId, map);
|
|
|
+ map = outFireCom(subjectId,map);
|
|
|
} catch (InterruptedException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
/***
|
|
|
*灭火指令发送方法
|
|
|
* @param subjectId
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String, Object> outFireCom(Long subjectId, Map<String, Object> map) throws InterruptedException {
|
|
|
+ public Map<String,Object> outFireCom(Long subjectId,Map<String, Object> map) throws InterruptedException {
|
|
|
//Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("check", "");
|
|
|
+ map.put("check","");
|
|
|
//查询实验室下的硬件
|
|
|
RemoteLabHardware hd = new RemoteLabHardware();
|
|
|
//实验室id
|
|
|
hd.setSubjectId(subjectId);
|
|
|
//灭火设备类型
|
|
|
- hd.setType(10);
|
|
|
+ hd.setIsPcfire(1);
|
|
|
List<RemoteLabHardware> hdlist = remoteLaboratoryService.remoteList(hd).getData();
|
|
|
if (hdlist.size() == 0) {
|
|
|
//return ResultData.fail("该实验室尚未配置关联硬件!");
|
|
|
- map.put("check", "该实验室尚未配置关联硬件!");
|
|
|
- return map;
|
|
|
+ map.put("check","该实验室尚未配置关联硬件!");
|
|
|
+ return map;
|
|
|
} else if (hdlist.size() != 2) {
|
|
|
//return ResultData.fail("该实验室尚未配置2路控制器!");
|
|
|
- map.put("check", "该实验室尚未配置2路控制器!");
|
|
|
+ map.put("check","该实验室尚未配置2路控制器!");
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
@@ -383,11 +409,11 @@ public class FireDeviceController extends BaseController {
|
|
|
HardwareFireDeviceVO fireDeviceVO = new HardwareFireDeviceVO();
|
|
|
fireDeviceVO.setSubjectId(subjectId);
|
|
|
List<HardwareFireDeviceVO> list = fireDeviceService.selectHardwareFireDeviceList(fireDeviceVO);
|
|
|
- JSONObject object = redisService.getCacheObject(list.get(0).getRelayCode());
|
|
|
+ JSONObject object = redisService.getCacheObject(list.get(0).getDeviceCode());
|
|
|
logger.info("灭火设备状态:" + object);
|
|
|
|
|
|
//手动灭火时间
|
|
|
- redisService.setCacheObject(ARTIFICIAL_OUT_FILE + list.get(0).getRelayCode(), System.currentTimeMillis(), Long.valueOf(list.get(0).getDeviceCountDown() + direTime), TimeUnit.SECONDS);
|
|
|
+ redisService.setCacheObject(ARTIFICIAL_OUT_FILE+list.get(0).getDeviceCode(),System.currentTimeMillis(),Long.valueOf(list.get(0).getDeviceCountDown()+direTime),TimeUnit.SECONDS);
|
|
|
|
|
|
if (StringUtils.isNotNull(object)) {
|
|
|
//异常传感器数量
|
|
|
@@ -397,14 +423,14 @@ public class FireDeviceController extends BaseController {
|
|
|
//随机补充一路信号 触发灭火
|
|
|
List<RemoteLabHardware> li = new ArrayList<>();
|
|
|
li.add(hdlist.get(0));
|
|
|
- map = sendOutFireMsg(li, map, list.get(0).getRelayCode());
|
|
|
+ map = sendOutFireMsg(li,map,list.get(0).getDeviceCode());
|
|
|
} else if (fireNumber == 0) {
|
|
|
logger.info("手动灭火,灭火设备2路信号正常,发送两路电信号,触发灭火!");
|
|
|
- map = sendOutFireMsg(hdlist, map, list.get(0).getRelayCode());
|
|
|
+ map = sendOutFireMsg(hdlist,map,list.get(0).getDeviceCode());
|
|
|
}
|
|
|
} else {
|
|
|
logger.info("手动灭火,redis中没有获取到信息,但是仍然需要执行灭火流程,发送两路电信号,触发灭火");
|
|
|
- map = sendOutFireMsg(hdlist, map, list.get(0).getRelayCode());
|
|
|
+ map = sendOutFireMsg(hdlist,map,list.get(0).getDeviceCode());
|
|
|
}
|
|
|
|
|
|
//灭火日志添加
|
|
|
@@ -425,7 +451,7 @@ public class FireDeviceController extends BaseController {
|
|
|
* @return
|
|
|
* @throws InterruptedException
|
|
|
*/
|
|
|
- private Map<String, Object> sendOutFireMsg(List<RemoteLabHardware> hdlist, Map<String, Object> map, String relayCode) throws InterruptedException {
|
|
|
+ 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();
|
|
|
//执行动作结果
|
|
|
@@ -449,10 +475,10 @@ public class FireDeviceController extends BaseController {
|
|
|
}
|
|
|
|
|
|
//通知前端一键灭火正在执行
|
|
|
- Map<String, Object> mapstatus = new HashMap<>();
|
|
|
- mapstatus.put("fireStatus", 1);
|
|
|
- mapstatus.put("direTime", direTime);
|
|
|
- mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE_EXECUTING + relayCode, JSON.toJSONString(mapstatus));
|
|
|
+ Map<String,Object> mapstatus = new HashMap<>();
|
|
|
+ mapstatus.put("fireStatus",1);
|
|
|
+ mapstatus.put("direTime",direTime);
|
|
|
+ mqttSend.send(MqttConstants.TOPIC_FIRE_DEVICE_EXECUTING+deviceCode,JSON.toJSONString(mapstatus));
|
|
|
|
|
|
//关闭继电器
|
|
|
for (RemoteLabHardware hardware : hdlist) {
|
|
|
@@ -556,8 +582,8 @@ public class FireDeviceController extends BaseController {
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("fireStatus", 1);
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("fireStatus",1);
|
|
|
System.out.println(JSON.toJSONString(map));
|
|
|
}
|
|
|
}
|