|
|
@@ -1,31 +1,25 @@
|
|
|
package com.zd.laboratory.event;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
import com.alibaba.fastjson.parser.Feature;
|
|
|
-import com.zd.laboratory.domain.LabControl;
|
|
|
-import com.zd.laboratory.domain.LabHardware;
|
|
|
import com.zd.laboratory.domain.vo.LabDealyNotifyVo;
|
|
|
-import com.zd.laboratory.domain.vo.LabHardwareVO;
|
|
|
-import com.zd.laboratory.mapper.LabHardwareMapper;
|
|
|
-import com.zd.laboratory.service.ILabControlService;
|
|
|
-import com.zd.laboratory.socket.command.Symbol;
|
|
|
-import com.zd.laboratory.socket.service.SocketService;
|
|
|
+import com.zd.laboratory.domain.vo.LabExitLineJoinPointVO;
|
|
|
+import com.zd.laboratory.event.handle.EventHandler;
|
|
|
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.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.connection.Message;
|
|
|
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
|
|
+import org.springframework.data.redis.listener.PatternTopic;
|
|
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Optional;
|
|
|
-
|
|
|
+import java.util.Set;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 当前由于没有消息中间件,所以只能暂时采用此种方式直接消费数据
|
|
|
@@ -39,22 +33,13 @@ import java.util.Optional;
|
|
|
*
|
|
|
*
|
|
|
*
|
|
|
- * @Author: cyl
|
|
|
- * @Date: 2023/3/15/11:19
|
|
|
+ * @Author: zhoupan
|
|
|
+ * @Date: 2021/10/20/11:19
|
|
|
* @Description:
|
|
|
*/
|
|
|
@Component
|
|
|
public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListener {
|
|
|
|
|
|
- @Autowired
|
|
|
- private LabHardwareMapper labHardwareMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ILabControlService labControlService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SocketService socketService;
|
|
|
-
|
|
|
public RedisExpiredAndWorkListener(RedisMessageListenerContainer listenerContainer)
|
|
|
{
|
|
|
super(listenerContainer);
|
|
|
@@ -68,53 +53,11 @@ public class RedisExpiredAndWorkListener extends KeyExpirationEventMessageListen
|
|
|
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>(){});
|
|
|
-
|
|
|
- //这里类型固定写死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);
|
|
|
- Optional.ofNullable(hardwareList).orElseGet(Collections::emptyList)
|
|
|
- .stream()
|
|
|
- .forEach(a->{
|
|
|
- if(dealyNotifyVo.getOpenOrCloseType().intValue()==1){
|
|
|
- ResultData ResultData = socketService.sendMqttCommand(a.getId(), a.getRelayCode(), Symbol.command.open, a.getBit(),a.getSubjectId());
|
|
|
- boolean equals = ResultData.getCode().equals(HttpStatus.SUCCESS);
|
|
|
- //插入control 打开日志
|
|
|
- if (equals) {
|
|
|
- saveControl(a, 1);
|
|
|
- }
|
|
|
- }else{
|
|
|
- ResultData ResultData = socketService.sendMqttCommand(a.getId(), a.getRelayCode(), Symbol.command.close, a.getBit(),a.getSubjectId());
|
|
|
- boolean equals = ResultData.getCode().equals(HttpStatus.SUCCESS);
|
|
|
- //插入control 关闭日志
|
|
|
- if (equals) {
|
|
|
- saveControl(a,0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
+ System.out.println("测试继电器编号:"+dealyNotifyVo.getHardwareNum());
|
|
|
+ System.out.println("测试随机数:"+dealyNotifyVo.getRandomNum());
|
|
|
+ System.out.println("测试开启或关闭::::"+dealyNotifyVo.getOpenOrCloseType());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void saveControl(LabHardware labHardware,Integer controlType){
|
|
|
- LabControl control = new LabControl();
|
|
|
- control.setTriggerModes(1);
|
|
|
- control.setControlType(controlType);
|
|
|
- control.setUserName("定时排风自动执行");
|
|
|
- if(controlType.intValue()==1){
|
|
|
- control.setOperation("定时排风:打开");
|
|
|
- }else{
|
|
|
- control.setOperation("定时排风:关闭");
|
|
|
- }
|
|
|
- control.setHardwareType(HardwareTypeEnum.AI_VENTILATION);
|
|
|
- control.setHardwareId(labHardware.getId());
|
|
|
- control.setSubjectId(labHardware.getSubjectId());
|
|
|
- labControlService.insertLabControl(control);
|
|
|
- }
|
|
|
-
|
|
|
}
|