|
|
@@ -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());
|
|
|
+ }
|
|
|
}
|