Bladeren bron

2022-12-9 添加疏散线路手动开关灯。

chaiyunlong 3 jaren geleden
bovenliggende
commit
89617c342d

+ 3 - 21
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/LabExitLineVertexController.java

@@ -100,9 +100,9 @@ public class LabExitLineVertexController extends BaseController {
     public ResultData executeEvacuation(@RequestBody LabExitLineEvacuationVo labExitLineEvacuationVo) {
         Map <String, Object> joinPointVOS = labExitLineVertexService.executeEvacuation(labExitLineEvacuationVo);
                 //todo redis把计算的逃生线路相关信息存储起来
-        redisService.setCacheObject("exitLineBy"+labExitLineEvacuationVo.getBuildId()+""+labExitLineEvacuationVo.getFloorId(), joinPointVOS, 1L, TimeUnit.HOURS);
+        redisService.setCacheObject("exitLineBy"+labExitLineEvacuationVo.getBuildId()+""+labExitLineEvacuationVo.getFloorId(), joinPointVOS, 3L, TimeUnit.HOURS);
         //todo 下发前端页面通知
-        messageSendService.exitLineToFloor(labExitLineEvacuationVo.getBuildId(),labExitLineEvacuationVo.getFloorId());
+        messageSendService.exitLineToFloor(labExitLineEvacuationVo.getFloorId());
         return ResultData.success(joinPointVOS);
     }
 
@@ -116,7 +116,7 @@ public class LabExitLineVertexController extends BaseController {
         //todo 结束疏散清空redis,以及下发通知
         redisService.deleteObject("exitLineBy"+labExitLineEvacuationVo.getBuildId()+""+labExitLineEvacuationVo.getFloorId());
         //todo 下发前端页面通知
-        messageSendService.exitLineToFloor(labExitLineEvacuationVo.getBuildId(),labExitLineEvacuationVo.getFloorId());
+        messageSendService.exitLineToFloor(labExitLineEvacuationVo.getFloorId());
         return ResultData.success();
     }
 
@@ -133,24 +133,6 @@ public class LabExitLineVertexController extends BaseController {
     }
 
     /**
-     * 手动执行开灯
-     */
-    @PostMapping("/openLight")
-    @ApiOperation(value = "手动执行开灯")
-    public ResultData openLight(@RequestBody LabExitPointRelay labExitPointRelay) {
-        return ResultData.success(labExitLineVertexService.openLight(labExitPointRelay));
-    }
-
-    /**
-     * 手动执行关灯
-     */
-    @PostMapping("/closeLight")
-    @ApiOperation(value = "手动执行开灯")
-    public ResultData closeLight(@RequestBody LabExitPointRelay labExitPointRelay) {
-        return ResultData.success(labExitLineVertexService.closeLight(labExitPointRelay));
-    }
-
-    /**
      * 修改逃生线路主
      */
     @ApiOperation(value = "修改逃生线路主")

+ 27 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/LabExitPointRelayController.java

@@ -45,7 +45,7 @@ public class LabExitPointRelayController extends BaseController{
 
 
     /**
-     * 新增逃生线路主
+     * 新增逃生灯关联的继电器
      */
     @ApiOperation(value = "新增逃生灯关联的继电器")
     @Log(title = "新增逃生灯关联的继电器", businessType = BusinessType.INSERT)
@@ -54,4 +54,30 @@ public class LabExitPointRelayController extends BaseController{
         return ResultData.result(labExitPointRelayService.insertLabExitPointRelay(labExitPointRelay));
     }
 
+    /**
+     * 手动执行开灯
+     */
+    @PostMapping("/openLight")
+    @ApiOperation(value = "手动执行开灯")
+    public ResultData openLight(@RequestBody LabExitPointRelay labExitPointRelay) {
+        return ResultData.success(labExitPointRelayService.openLight(labExitPointRelay));
+    }
+
+    /**
+     * 手动执行关灯
+     */
+    @PostMapping("/closeLight")
+    @ApiOperation(value = "手动执行开灯")
+    public ResultData closeLight(@RequestBody LabExitPointRelay labExitPointRelay) {
+        return ResultData.success(labExitPointRelayService.closeLight(labExitPointRelay));
+    }
+
+    /**
+     * 获取现有的redis存放已打开的灯
+     */
+    @GetMapping("/getOpenLight")
+    @ApiOperation(value = "获取现有的redis存放已打开的灯")
+    public ResultData getOpenLight(LabExitPointRelay labExitPointRelay) {
+        return ResultData.success(labExitPointRelayService.getOpenLight(labExitPointRelay));
+    }
 }

+ 3 - 3
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/mqtt/service/impl/SubMessageSendManager.java

@@ -245,17 +245,17 @@ public class SubMessageSendManager {
     /**
      * 新疏散下发通知
      *
-     * @param floorId
      */
-    public void exitLineToFloor(Long build,Long floorId) {
+    public void exitLineToFloor(Long floorId) {
         if (floorId == null) {
             return;
         }
         MessageBody messageBody = new MessageBody();
         messageBody.setData(BigViewDataType.FLOOR_EXITLINE);
-        commonSend.send(MqttConstants.TOPIC_LAB_NEWEXIT_LINE + build +""+ floorId, messageBody, SendMode.ONCE);
+        commonSend.send(MqttConstants.TOPIC_LAB_NEWEXIT_LINE + floorId , messageBody, SendMode.ONCE);
     }
 
+
     /**
      * 通知一体机logo查询
      *

+ 0 - 16
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/ILabExitLineVertexService.java

@@ -53,22 +53,6 @@ public interface ILabExitLineVertexService
     public Map<String,Object> executeEvacuation(LabExitLineEvacuationVo labExitLineEvacuationVo);
 
     /**
-     * 手动执行开灯
-     *
-     * @param labExitPointRelay 灯对象
-     * @return 结果
-     */
-    public int openLight(LabExitPointRelay labExitPointRelay);
-
-    /**
-     * 手动执行关灯
-     *
-     * @param labExitPointRelay 灯对象
-     * @return 结果
-     */
-    public int closeLight(LabExitPointRelay labExitPointRelay);
-
-    /**
      * 新增逃生线路主
      *
      * @param lineVertexVo 逃生线路主

+ 25 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/ILabExitPointRelayService.java

@@ -5,6 +5,7 @@ import com.zd.laboratory.domain.LabExitPointRelay;
 import com.zd.laboratory.domain.vo.LabExitLineVertexVo;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 逃生灯关联的继电器Service接口
@@ -39,4 +40,28 @@ public interface ILabExitPointRelayService {
      */
     public int updateLabExitPointRelay(LabExitPointRelay labExitPointRelay);
 
+
+    /**
+     * 手动执行开灯
+     *
+     * @param labExitPointRelay 灯对象
+     * @return 结果
+     */
+    public int openLight(LabExitPointRelay labExitPointRelay);
+
+    /**
+     * 手动执行关灯
+     *
+     * @param labExitPointRelay 灯对象
+     * @return 结果
+     */
+    public int closeLight(LabExitPointRelay labExitPointRelay);
+
+    /**
+     * 获取现有的redis存放已打开的灯
+     *
+     * @param labExitPointRelay 灯对象
+     * @return 结果
+     */
+    public Map <String,LabExitPointRelay> getOpenLight(LabExitPointRelay labExitPointRelay);
 }

+ 0 - 50
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabExitLineVertexServiceImpl.java

@@ -508,56 +508,6 @@ public class LabExitLineVertexServiceImpl implements ILabExitLineVertexService {
     }
 
 
-    @Override
-    public int openLight(LabExitPointRelay labExitPointRelay) {
-        List <LabExitPointRelay> labExitPointRelays = labExitPointRelayMapper.selectLabExitPointRelayList(labExitPointRelay);
-        //todo  开启继电器开关
-        Optional.ofNullable(labExitPointRelays).orElseGet(Collections::emptyList)
-                .stream()
-                .forEach(a->{
-                    try {
-                        if(a.getRelayType().intValue()==1){
-                            //这里打卡继电器的开关(老继电器)
-                            socketService.sendCommand(Symbol.order.control, a.getRelayCode(), Symbol.command.open, a.getRelayBit());
-                            Thread.sleep(timeWaitConfigUtils.getWaitTime());
-                        }else{
-                            //这里打卡继电器的开关(新继电器)
-                            socketService.sendMqttCommand(a.getRelayCode(), Symbol.command.open ,a.getRelayBit()+"");
-                            Thread.sleep(timeWaitConfigUtils.getWaitTime());
-                        }
-
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
-                    }
-                });
-        return 1;
-    }
-
-    @Override
-    public int closeLight(LabExitPointRelay labExitPointRelay) {
-        List <LabExitPointRelay> labExitPointRelays = labExitPointRelayMapper.selectLabExitPointRelayList(labExitPointRelay);
-        //todo  开启继电器开关
-        Optional.ofNullable(labExitPointRelays).orElseGet(Collections::emptyList)
-                .stream()
-                .forEach(a->{
-                    try {
-                        if(a.getRelayType().intValue()==1){
-                            //这里打卡继电器的开关(老继电器)
-                            socketService.sendCommand(Symbol.order.control, a.getRelayCode(), Symbol.command.close, a.getRelayBit());
-                            Thread.sleep(timeWaitConfigUtils.getWaitTime());
-                        }else{
-                            //这里打卡继电器的开关(新继电器)
-                            socketService.sendMqttCommand(a.getRelayCode(), Symbol.command.close ,a.getRelayBit()+"");
-                            Thread.sleep(timeWaitConfigUtils.getWaitTime());
-                        }
-
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
-                    }
-                });
-        return 1;
-    }
-
     /**
      * 新增逃生线路主
      *

+ 109 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabExitPointRelayServiceImpl.java

@@ -1,12 +1,19 @@
 package com.zd.laboratory.service.impl;
 
+import com.zd.common.core.redis.RedisService;
+import com.zd.laboratory.config.TimeWaitConfigUtils;
 import com.zd.laboratory.domain.LabExitPointRelay;
+import com.zd.laboratory.domain.vo.LabExitLineJoinPointVO;
 import com.zd.laboratory.mapper.LabExitPointRelayMapper;
+import com.zd.laboratory.mqtt.service.impl.SubMessageSendManager;
 import com.zd.laboratory.service.ILabExitPointRelayService;
+import com.zd.laboratory.socket.command.Symbol;
+import com.zd.laboratory.socket.service.SocketService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 /**
  * Controller
@@ -20,6 +27,18 @@ public class LabExitPointRelayServiceImpl implements ILabExitPointRelayService {
     @Autowired
     private LabExitPointRelayMapper labExitPointRelayMapper;
 
+    @Autowired
+    private SocketService socketService;
+
+    @Autowired
+    private TimeWaitConfigUtils timeWaitConfigUtils;
+
+    @Autowired
+    RedisService redisService;
+
+    @Autowired
+    private SubMessageSendManager messageSendService;
+
     @Override
     public List <LabExitPointRelay> selectLabExitPointRelayList(LabExitPointRelay labExitPointRelay) {
         return labExitPointRelayMapper.selectLabExitPointRelayList(labExitPointRelay);
@@ -42,5 +61,94 @@ public class LabExitPointRelayServiceImpl implements ILabExitPointRelayService {
         return labExitPointRelayMapper.updateLabExitPointRelay(labExitPointRelay);
     }
 
+    @Override
+    public int openLight(LabExitPointRelay labExitPointRelay) {
+        List <LabExitPointRelay> labExitPointRelays = labExitPointRelayMapper.selectLabExitPointRelayList(labExitPointRelay);
+
+        Map <String, Object> relayListMap = new HashMap <>();
+        Set <LabExitLineJoinPointVO> lightPointSet = new HashSet <>();
+        if(redisService.getCacheObject("exitLineBy"+labExitPointRelay.getBuildId()+""+labExitPointRelay.getFloorId())!=null){
+            relayListMap = redisService.getCacheObject("exitLineBy"+labExitPointRelay.getBuildId()+""+labExitPointRelay.getFloorId());
+            lightPointSet = (Set <LabExitLineJoinPointVO>) relayListMap.get("lightPointSet");
+        }
+        //todo  开启继电器开关
+        for(LabExitPointRelay relay : labExitPointRelays){
+            try {
+                if(relay.getRelayType().intValue()==1){
+                    //这里打卡继电器的开关(老继电器)
+                    socketService.sendCommand(Symbol.order.control, relay.getRelayCode(), Symbol.command.open, relay.getRelayBit());
+                    Thread.sleep(timeWaitConfigUtils.getWaitTime());
+                }else{
+                    //这里打卡继电器的开关(新继电器)
+                    socketService.sendMqttCommand(relay.getRelayCode(), Symbol.command.open ,relay.getRelayBit()+"");
+                    Thread.sleep(timeWaitConfigUtils.getWaitTime());
+                }
+
+                boolean flag = true;
+                for(LabExitLineJoinPointVO pointVO:lightPointSet){
+                    if(pointVO!=null && pointVO.getKey().equals(relay.getPointName())){
+                        flag = false;
+                    }
+                }
+                if(flag){
+                    LabExitLineJoinPointVO lineJoinPointVO = new LabExitLineJoinPointVO();
+                    lineJoinPointVO.setKey(relay.getPointName());
+                    lineJoinPointVO.setPointName(relay.getPointName());
+                    lineJoinPointVO.setBuildId(labExitPointRelay.getBuildId());
+                    lineJoinPointVO.setFloorId(labExitPointRelay.getFloorId());
+                    lightPointSet.add(lineJoinPointVO);
+                }
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+        relayListMap.put("lightPointSet",lightPointSet);
+        redisService.setCacheObject("exitLineBy"+labExitPointRelay.getBuildId()+""+labExitPointRelay.getFloorId(), relayListMap, 3L, TimeUnit.HOURS);
+        //todo  发送前端消息
+        messageSendService.exitLineToFloor(labExitPointRelay.getFloorId());
+        return 1;
+    }
+
+    @Override
+    public int closeLight(LabExitPointRelay labExitPointRelay) {
+        List <LabExitPointRelay> labExitPointRelays = labExitPointRelayMapper.selectLabExitPointRelayList(labExitPointRelay);
+
+        Map <String, Object> relayListMap = new HashMap <>();
+        Set <LabExitLineJoinPointVO> lightPointSet = new HashSet <>();
+        if(redisService.getCacheObject("exitLineBy"+labExitPointRelay.getBuildId()+""+labExitPointRelay.getFloorId())!=null){
+            relayListMap = redisService.getCacheObject("exitLineBy"+labExitPointRelay.getBuildId()+""+labExitPointRelay.getFloorId());
+            lightPointSet = (Set <LabExitLineJoinPointVO>) relayListMap.get("lightPointSet");
+        }
+        //todo  开启继电器开关
+        for(LabExitPointRelay relay : labExitPointRelays) {
+            try {
+                if (relay.getRelayType().intValue() == 1) {
+                    //这里打卡继电器的开关(老继电器)
+                    socketService.sendCommand(Symbol.order.control, relay.getRelayCode(), Symbol.command.close, relay.getRelayBit());
+                    Thread.sleep(timeWaitConfigUtils.getWaitTime());
+                } else {
+                    //这里打卡继电器的开关(新继电器)
+                    socketService.sendMqttCommand(relay.getRelayCode(), Symbol.command.close, relay.getRelayBit() + "");
+                    Thread.sleep(timeWaitConfigUtils.getWaitTime());
+                }
+                for(LabExitLineJoinPointVO pointVO:lightPointSet){
+                    if(pointVO!=null && pointVO.getKey().equals(relay.getPointName())){
+                        lightPointSet.remove(pointVO);
+                    }
+                }
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+        relayListMap.put("lightPointSet",lightPointSet);
+        redisService.setCacheObject("exitLineBy"+labExitPointRelay.getBuildId()+""+labExitPointRelay.getFloorId(), relayListMap, 3L, TimeUnit.HOURS);
+        //todo  发送前端消息
+        messageSendService.exitLineToFloor(labExitPointRelay.getFloorId());
+        return 1;
+    }
 
+    @Override
+    public Map <String, LabExitPointRelay> getOpenLight(LabExitPointRelay labExitPointRelay) {
+        return redisService.getCacheObject("pointRelayBy"+labExitPointRelay.getBuildId()+""+labExitPointRelay.getFloorId());
+    }
 }