Quellcode durchsuchen

2023-3-21 创建定时任务收集当天的所有需要执行风扇的实验室,存入到redis里面。

chaiyunlong vor 2 Jahren
Ursprung
Commit
d9671e0036

+ 6 - 0
zd-api/zd-laboratory-api/src/main/java/com/zd/laboratory/api/feign/RemoteLaboratoryService.java

@@ -446,6 +446,12 @@ public interface RemoteLaboratoryService {
     public void checkSendMsgBeOverdue();
 
     /**
+     * 定时器定时每天 00:00 开始执行,把一天的排风任务全部存入redis里面去
+     */
+    @GetMapping("/timed/exhaust/automaticExhaust")
+    public AjaxResult timedExhaustTask();
+
+    /**
      * 一体机logo修改通知
      */
     @ApiOperation(value = "一体机logo修改通知")

+ 8 - 0
zd-api/zd-laboratory-api/src/main/java/com/zd/laboratory/api/feign/fallback/RemoteLaboratoryFallbackFactory.java

@@ -408,6 +408,14 @@ public class RemoteLaboratoryFallbackFactory implements FallbackFactory<RemoteLa
                 throw new RuntimeException("安全检查隐患项未整改逾期通知" + cause.getMessage());
             }
 
+            /**
+             * 定时器定时每天 00:00 开始执行,把一天的排风任务全部存入redis里面去
+             */
+            @Override
+            public AjaxResult timedExhaustTask() {
+                throw new RuntimeException("定时排风执行失败:" + cause.getMessage());
+            }
+
             @Override
             public void logoNotice() {
                 throw new RuntimeException("logo通知失败" + cause.getMessage());

+ 8 - 0
zd-modules/zd-base/src/main/java/com/zd/base/job/task/LabTask.java

@@ -62,4 +62,12 @@ public class LabTask {
      * 安全检查隐患项未整改逾期通知
      */
     public  void checkSendMsgBeOverdue(){remoteLaboratoryService.checkSendMsgBeOverdue();}
+
+
+    /**
+     * 定时器定时每天 00:00 开始执行,把一天的排风任务全部存入redis里面去
+     */
+    public void timedExhaustTask() {
+        remoteLaboratoryService.timedExhaustTask();
+    }
 }

+ 8 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/event/RedisExpiredAndWorkListener.java

@@ -15,6 +15,8 @@ import com.zd.model.constant.BaseConstants;
 import com.zd.model.constant.HttpStatus;
 import com.zd.model.domain.ResultData;
 import com.zd.model.enums.HardwareTypeEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.connection.Message;
 import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
@@ -55,6 +57,8 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
     @Autowired
     private SocketService socketService;
 
+    private static final Logger log = LoggerFactory.getLogger(RedisExpiredAndWorkListener.class);
+
     public RedisExpiredAndWorkListener(RedisMessageListenerContainer listenerContainer)
     {
         super(listenerContainer);
@@ -62,9 +66,9 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
 
     @Override
     public void onMessage(Message message, byte[] bytes) {
-//        String topic = new String(bytes);
         String expiredKey = new String(message.getBody());
         if(expiredKey.indexOf(BaseConstants.DELAY_QUEUE)!=-1){
+            log.info("定时排风key失效后,需要执行对应的任务------------------"+expiredKey);
             String[] delayStr = expiredKey.split(BaseConstants.DELAY_QUEUE+"~");
             JSONObject jsonObj = (JSONObject) JSONObject.parseObject(delayStr[1], Object.class, Feature.OrderedField);
             LabDealyNotifyVo dealyNotifyVo = jsonObj.getObject(BaseConstants.DELAY_QUEUE, new TypeReference <LabDealyNotifyVo>(){});
@@ -76,6 +80,7 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
             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->{
@@ -98,10 +103,12 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
 
     public Boolean relayControl(LabHardware labHardwareVO,Symbol.command command){
         if (labHardwareVO.getHardwareType() == 2) {
+            log.info("定时排风执行对应的继电器------------------RelayCode="+labHardwareVO.getRelayCode()+",Bit="+labHardwareVO.getBit()+",HardwareId="+labHardwareVO.getId()+",SubjectId="+labHardwareVO.getSubjectId());
             ResultData ResultData = socketService.sendMqttCommand(labHardwareVO.getId(), labHardwareVO.getRelayCode(), command, labHardwareVO.getBit(),labHardwareVO.getSubjectId());
             boolean equals = ResultData.getCode().equals(HttpStatus.SUCCESS);
             return equals;
         }else{
+            log.info("定时排风执行对应的继电器------------------RelayCode="+labHardwareVO.getRelayCode()+",Bit="+labHardwareVO.getBit());
             ResultData ResultData = socketService.sendCommand(Symbol.order.control, labHardwareVO.getRelayCode(), command, labHardwareVO.getBit());
             boolean equals = ResultData.getCode().equals(HttpStatus.SUCCESS);
             return equals;

+ 10 - 2
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabTimedExhaustServiceImpl.java

@@ -14,6 +14,8 @@ import com.zd.laboratory.mapper.LabTimedExhaustJoinsubMapper;
 import com.zd.laboratory.mapper.LabTimedExhaustMapper;
 import com.zd.laboratory.service.ILabTimedExhaustService;
 import com.zd.model.constant.BaseConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -47,6 +49,8 @@ public class LabTimedExhaustServiceImpl implements ILabTimedExhaustService {
     @Autowired
     private RedisService redisService;
 
+    private static final Logger log = LoggerFactory.getLogger(LabTimedExhaustServiceImpl.class);
+
     /**
      * 查询定时排风列表
      *
@@ -144,6 +148,7 @@ public class LabTimedExhaustServiceImpl implements ILabTimedExhaustService {
         LabTimedExhaust labTimedExhaust = new LabTimedExhaust();
         labTimedExhaust.setExhaustType(1);
         List <LabTimedExhaust> timedExhaustList = labTimedExhaustMapper.selectLabTimedExhaustList(labTimedExhaust);
+        log.info("定时排风执行开始,查询执行任务为------------------"+timedExhaustList.size()+"条");
         List<LabTimedExhaustVo> timedExhaustVoList = Optional.ofNullable(timedExhaustList).orElseGet(Collections::emptyList)
                 .stream()
                 .map(a->getTimedExhaustVo(a)).collect(Collectors.toList());
@@ -170,7 +175,7 @@ public class LabTimedExhaustServiceImpl implements ILabTimedExhaustService {
             dateStr = ""+dateInt;
         }
         Integer newDateInt = Integer.parseInt(year+""+monthStr+""+""+dateStr);
-
+        log.info("定时排风日期转换,获取年月日------------------"+newDateInt);
         //todo 函数校验当日是否落选到时间区间   这里由于需求变动,在跳过节假日的时候,数据上报是不是节假日的日期时间段
         Predicate<List <LabExecutionDateVo>> predicate = a->a.stream()
                 .map(b->{
@@ -184,6 +189,7 @@ public class LabTimedExhaustServiceImpl implements ILabTimedExhaustService {
                 .filter(b-> StringUtils.isNotNull(b))
                 .collect(Collectors.toList()).size()>0;
 
+        log.info("定时排风过滤,把执行日期时间段匹配不到的数据过滤");
         Function <List<LabTimedExhaustVo>,List<LabTimedExhaustVo>> consumer = a->a.stream()
                 .filter(b->{
                     if(StringUtils.isNotNull(b.getExecutionDateVoList()) && b.getExecutionDateVoList().size()>0){
@@ -213,6 +219,7 @@ public class LabTimedExhaustServiceImpl implements ILabTimedExhaustService {
     }
 
     public void executionFun(final Long subId,List <LabExhaustPeriodVo> exhaustPeriodVoList,Calendar calendar){
+        log.info("执行过滤后的数据:"+JSON.toJSON(exhaustPeriodVoList)+"===实验室id:"+subId);
         Predicate<LabExhaustPeriodVo> predicate = a->{
 //            Integer[] weekDays = { 7, 1, 2, 3, 4, 5, 6 };
             int w = calendar.get(Calendar.DAY_OF_WEEK) - 1;
@@ -244,7 +251,7 @@ public class LabTimedExhaustServiceImpl implements ILabTimedExhaustService {
             return false;
         };
 
-
+        log.info("执行排风时段过滤");
         Optional.ofNullable(exhaustPeriodVoList).orElseGet(Collections::emptyList)
                 .stream()
                 .filter(a->predicate.test(a))
@@ -278,6 +285,7 @@ public class LabTimedExhaustServiceImpl implements ILabTimedExhaustService {
     }
 
     public void executionTimer(final Long newBeginTime,final Long subId,final Integer type){
+        log.info("将最后的匹配到的实验室存入redis   subId="+subId+",type="+type+",newBeginTime="+newBeginTime);
         LabDealyNotifyVo labDealyNotifyVo = new LabDealyNotifyVo();
         labDealyNotifyVo.setRandomNum(UUID.randomUUID().toString());
         labDealyNotifyVo.setSubId(subId);