Selaa lähdekoodia

2023-3-21 添加一个预案避让功能,如果这个实验室发生了预案,将跳过当前需要执行的任务。

chaiyunlong 2 vuotta sitten
vanhempi
commit
a7500cbc2f

+ 30 - 24
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/event/RedisExpiredAndWorkListener.java

@@ -3,6 +3,7 @@ package com.zd.laboratory.event;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.alibaba.fastjson.parser.Feature;
+import com.zd.common.core.redis.RedisService;
 import com.zd.laboratory.domain.LabControl;
 import com.zd.laboratory.domain.LabHardware;
 import com.zd.laboratory.domain.vo.LabDealyNotifyVo;
@@ -57,6 +58,9 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
     @Autowired
     private SocketService socketService;
 
+    @Autowired
+    private RedisService redisService;
+
     private static final Logger log = LoggerFactory.getLogger(RedisExpiredAndWorkListener.class);
 
     public RedisExpiredAndWorkListener(RedisMessageListenerContainer listenerContainer)
@@ -73,30 +77,32 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
             JSONObject jsonObj = (JSONObject) JSONObject.parseObject(delayStr[1], Object.class, Feature.OrderedField);
             LabDealyNotifyVo dealyNotifyVo = jsonObj.getObject(BaseConstants.DELAY_QUEUE, new TypeReference <LabDealyNotifyVo>(){});
 
-            //这里类型固定写死2,智能通风
-            List <Long> ids = new ArrayList <>();
-            ids.add(2L);
-            LabHardwareVO labHardwareVO = new LabHardwareVO();
-            labHardwareVO.setIds(ids);
-            labHardwareVO.setSubjectId(dealyNotifyVo.getSubId());
-            List<LabHardware> hardwareList = labHardwareMapper.selectNewLabHardwareByTypes(labHardwareVO);
-            log.info("定时排风根据条件查询硬件列表数量------------------"+hardwareList.size());
-            Optional.ofNullable(hardwareList).orElseGet(Collections::emptyList)
-                    .stream()
-                    .forEach(a->{
-                        if(dealyNotifyVo.getOpenOrCloseType().intValue()==1){
-                            //插入control 打开日志
-                            if (relayControl(a,Symbol.command.open)) {
-                                saveControl(a, 1);
-                            }
-                        }else{
-                            //插入control 关闭日志
-                            if (relayControl(a,Symbol.command.close)) {
-                                saveControl(a,0);
+            if (redisService.getCacheObject("subjectByYa" + dealyNotifyVo.getSubId()) != null) {
+                //这里类型固定写死2,智能通风
+                List <Long> ids = new ArrayList <>();
+                ids.add(2L);
+                LabHardwareVO labHardwareVO = new LabHardwareVO();
+                labHardwareVO.setIds(ids);
+                labHardwareVO.setSubjectId(dealyNotifyVo.getSubId());
+                List<LabHardware> hardwareList = labHardwareMapper.selectNewLabHardwareByTypes(labHardwareVO);
+                log.info("定时排风根据条件查询硬件列表数量------------------"+hardwareList.size());
+                Optional.ofNullable(hardwareList).orElseGet(Collections::emptyList)
+                        .stream()
+                        .forEach(a->{
+                            if(dealyNotifyVo.getOpenOrCloseType().intValue()==1){
+                                //插入control 打开日志
+                                if (relayControl(a,Symbol.command.open)) {
+                                    saveControl(a, 1);
+                                }
+                            }else{
+                                //插入control 关闭日志
+                                if (relayControl(a,Symbol.command.close)) {
+                                    saveControl(a,0);
+                                }
                             }
-                        }
 
-                    });
+                        });
+            }
         }
 
     }
@@ -118,9 +124,9 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
 
     public void saveControl(LabHardware labHardware,Integer controlType){
         LabControl control = new LabControl();
-        control.setTriggerModes(1);
+        control.setTriggerModes(3);
         control.setControlType(controlType);
-        control.setUserName("定时排风自动执行");
+        control.setUserName("定时排风");
         if(controlType.intValue()==1){
             control.setOperation("定时排风:打开");
         }else{