Commit a28ed26e authored by duanruiming's avatar duanruiming

[update] 优化海信灯态

parent 629c69ce
package net.wanji.utc.hisense; package net.wanji.utc.hisense;
import net.wanji.utc.hisense.netty.NettyClient;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
...@@ -29,6 +30,6 @@ public class HisenseApplication implements CommandLineRunner { ...@@ -29,6 +30,6 @@ public class HisenseApplication implements CommandLineRunner {
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
// NettyClient.connection(localPort, remoteProt); NettyClient.connection(localPort, remoteProt);
} }
} }
...@@ -63,11 +63,11 @@ public class SignalStatusController { ...@@ -63,11 +63,11 @@ public class SignalStatusController {
return jsonViewObject.success(lightsStatusVOList); return jsonViewObject.success(lightsStatusVOList);
} }
@AspectLog(description = "从滴滴数据大脑接收海信灯态", operationType = BaseEnum.OperationTypeEnum.QUERY) @AspectLog(description = "接收海信灯态", operationType = BaseEnum.OperationTypeEnum.QUERY)
@PostMapping(value = "/receiveLightStatus", produces = MediaType.APPLICATION_JSON) @PostMapping(value = "/receiveLightStatus", produces = MediaType.APPLICATION_JSON)
@ApiOperation(value = "接收海信灯态", notes = "接收海信灯态", response = LightsStatusVO.class, produces = MediaType.APPLICATION_JSON) @ApiOperation(value = "接收海信灯态", notes = "接收海信灯态", response = LightsStatusVO.class, produces = MediaType.APPLICATION_JSON)
public JsonViewObject receiveLightStatus(@RequestBody HisenseLightStatusPojo hisenseLightStatusPojo) throws Exception{ public JsonViewObject receiveLightStatus(@RequestBody List<HisenseLightStatusPojo> hisenseLightStatusPojos) throws Exception{
signalStatusService.receiveLightStatus(hisenseLightStatusPojo); signalStatusService.receiveLightStatus(hisenseLightStatusPojos);
JsonViewObject jsonViewObject = JsonViewObject.newInstance(); JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success("海信灯态接收成功"); return jsonViewObject.success("海信灯态接收成功");
} }
......
...@@ -6,7 +6,6 @@ import io.netty.channel.SimpleChannelInboundHandler; ...@@ -6,7 +6,6 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.DatagramPacket;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.spring.ServiceBeanContext; import net.wanji.common.framework.spring.ServiceBeanContext;
import net.wanji.databus.dao.mapper.CrossInfoMapper;
import net.wanji.databus.po.CrossInfoPO; import net.wanji.databus.po.CrossInfoPO;
import net.wanji.utc.hisense.cache.CrossInfoCache; import net.wanji.utc.hisense.cache.CrossInfoCache;
import net.wanji.utc.hisense.cache.SignalDataCache; import net.wanji.utc.hisense.cache.SignalDataCache;
...@@ -18,38 +17,16 @@ import net.wanji.utc.hisense.netty.response.CommandResponseFactory; ...@@ -18,38 +17,16 @@ import net.wanji.utc.hisense.netty.response.CommandResponseFactory;
import net.wanji.utc.hisense.pojo.convert.RunningLightsStatusPojo; import net.wanji.utc.hisense.pojo.convert.RunningLightsStatusPojo;
import net.wanji.utc.hisense.pojo.netty.MessageResultPojo; import net.wanji.utc.hisense.pojo.netty.MessageResultPojo;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@Slf4j @Slf4j
@Component @Component
public class NettyServerHandler extends SimpleChannelInboundHandler<DatagramPacket> { public class NettyServerHandler extends SimpleChannelInboundHandler<DatagramPacket> {
// 信号机ID和路口ID映射
private static final Map<String, String> signalMap = new HashMap<>();
@Autowired
private CrossInfoMapper crossInfoMapper;
@PostConstruct
public void init() {
List<CrossInfoPO> crossInfoPOList = crossInfoMapper.selectAll();
for (CrossInfoPO crossInfoPO : crossInfoPOList) {
String crossId = crossInfoPO.getId();
String signalCode = crossInfoPO.getCode();
signalMap.put(signalCode, crossId);
}
}
@Resource
private CrossInfoCache crossInfoCache;
/** /**
* 读取消息 * 读取消息
...@@ -74,20 +51,16 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<DatagramPack ...@@ -74,20 +51,16 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<DatagramPack
// 直接set灯态缓存 // 直接set灯态缓存
RunningLightsStatusPojo pojo = (RunningLightsStatusPojo) resultPojo; RunningLightsStatusPojo pojo = (RunningLightsStatusPojo) resultPojo;
String signalCode = pojo.getCID(); String signalCode = pojo.getCID();
String crossId = signalMap.get(signalCode); CrossInfoPO crossInfoPO = CrossInfoCache.getCrossInfoBySignalCode(signalCode);
Map<String, RunningLightsStatusPojo> cache = SignalDataCache.runningStateInfoCacheUdp; if (Objects.nonNull(crossInfoPO)) {
if (crossId != null) { Map<String, RunningLightsStatusPojo> cache = SignalDataCache.runningStateInfoCacheUdp;
cache.put(crossId, pojo); cache.put(crossInfoPO.getId(), pojo);
} }
return; return;
} }
Object bean = ServiceBeanContext.getBean(className);
CommandResponseFactory commandResponseFactory = ServiceBeanContext.getBean(className); CommandResponseFactory commandResponseFactory = ServiceBeanContext.getBean(className);
String key = StringUtils.join("/", remote.getHostString(), ":", remote.getPort(), "/", resultPojo.getClass().getSimpleName());
String key = StringUtils.join("/", remote.getHostString(), ":", remote.getPort(), "/",
resultPojo.getClass().getSimpleName());
CommandPojo commandPojo = getCommandPojo(key, resultPojo); CommandPojo commandPojo = getCommandPojo(key, resultPojo);
Object hexResult = commandResponseFactory.getCommandResponse(commandPojo); Object hexResult = commandResponseFactory.getCommandResponse(commandPojo);
if (Objects.nonNull(hexResult)) { if (Objects.nonNull(hexResult)) {
......
...@@ -21,5 +21,5 @@ public interface SignalStatusService { ...@@ -21,5 +21,5 @@ public interface SignalStatusService {
List<SignalStatusLogPO> runningStatusAlarm(String crossId); List<SignalStatusLogPO> runningStatusAlarm(String crossId);
List<LightsStatusVO> lightStatus(String crossId); List<LightsStatusVO> lightStatus(String crossId);
void receiveLightStatus(HisenseLightStatusPojo hisenseLightStatusPojo) throws Exception; void receiveLightStatus(List<HisenseLightStatusPojo> hisenseLightStatusPojos) throws Exception;
} }
...@@ -47,11 +47,12 @@ public class HisensePhaseCountDownTask { ...@@ -47,11 +47,12 @@ public class HisensePhaseCountDownTask {
Long lastPhaseTimeStamp = runningStatusStampMap.get(crossId); Long lastPhaseTimeStamp = runningStatusStampMap.get(crossId);
String phaseId = lightsStatusVO.getPhaseId(); String phaseId = lightsStatusVO.getPhaseId();
String schemeId = lightsStatusVO.getSchemeId(); String schemeId = lightsStatusVO.getSchemeId();
if (Objects.nonNull(lastPhaseTimeStamp) && StringUtils.equalsIgnoreCase(schemeStartTime, String.valueOf(lastPhaseTimeStamp))) { if (Objects.nonNull(lastPhaseTimeStamp) && !StringUtils.equalsIgnoreCase(schemeStartTime, String.valueOf(lastPhaseTimeStamp))) {
CrossSchemePO crossSchemePO = crossSchemeMapper.selectByCrossIdAndSchemeNo(crossId, Integer.valueOf(schemeId)); CrossSchemePO crossSchemePO = crossSchemeMapper.selectByCrossIdAndSchemeNo(crossId, Integer.valueOf(schemeId));
// 通过时段表,切换方案 凌晨00:00 如果切换下一个日期方案,可能RefreshCacheTask还没执行 // 通过时段表,切换方案 凌晨00:00 如果切换下一个日期方案,可能RefreshCacheTask还没执行
String nextSectionSchemeNo = CrossRunSchemeCache.currentRunSchemeNoCache.get(crossId); String nextSectionSchemeNo = CrossRunSchemeCache.currentRunSchemeNoCache.get(crossId);
if (!StringUtils.equalsIgnoreCase(nextSectionSchemeNo, schemeId)) { String currentTime = String.valueOf(new Date().getTime());
if (StringUtils.equalsIgnoreCase(schemeStartTime, currentTime)) {
crossSchemePO = crossSchemeMapper.selectByCrossIdAndSchemeNo(crossId, Integer.valueOf(nextSectionSchemeNo)); crossSchemePO = crossSchemeMapper.selectByCrossIdAndSchemeNo(crossId, Integer.valueOf(nextSectionSchemeNo));
executeNextSectionScheme(crossId, lightsStatusVO, "1", crossSchemePO); executeNextSectionScheme(crossId, lightsStatusVO, "1", crossSchemePO);
lightsStatusVO.setCycleLen(crossSchemePO.getCycle()); lightsStatusVO.setCycleLen(crossSchemePO.getCycle());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment