Commit a28ed26e authored by duanruiming's avatar duanruiming

[update] 优化海信灯态

parent 629c69ce
package net.wanji.utc.hisense;
import net.wanji.utc.hisense.netty.NettyClient;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
......@@ -29,6 +30,6 @@ public class HisenseApplication implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
// NettyClient.connection(localPort, remoteProt);
NettyClient.connection(localPort, remoteProt);
}
}
......@@ -63,11 +63,11 @@ public class SignalStatusController {
return jsonViewObject.success(lightsStatusVOList);
}
@AspectLog(description = "从滴滴数据大脑接收海信灯态", operationType = BaseEnum.OperationTypeEnum.QUERY)
@AspectLog(description = "接收海信灯态", operationType = BaseEnum.OperationTypeEnum.QUERY)
@PostMapping(value = "/receiveLightStatus", produces = MediaType.APPLICATION_JSON)
@ApiOperation(value = "接收海信灯态", notes = "接收海信灯态", response = LightsStatusVO.class, produces = MediaType.APPLICATION_JSON)
public JsonViewObject receiveLightStatus(@RequestBody HisenseLightStatusPojo hisenseLightStatusPojo) throws Exception{
signalStatusService.receiveLightStatus(hisenseLightStatusPojo);
public JsonViewObject receiveLightStatus(@RequestBody List<HisenseLightStatusPojo> hisenseLightStatusPojos) throws Exception{
signalStatusService.receiveLightStatus(hisenseLightStatusPojos);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success("海信灯态接收成功");
}
......
......@@ -6,7 +6,6 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.spring.ServiceBeanContext;
import net.wanji.databus.dao.mapper.CrossInfoMapper;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.utc.hisense.cache.CrossInfoCache;
import net.wanji.utc.hisense.cache.SignalDataCache;
......@@ -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.netty.MessageResultPojo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Slf4j
@Component
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
// 直接set灯态缓存
RunningLightsStatusPojo pojo = (RunningLightsStatusPojo) resultPojo;
String signalCode = pojo.getCID();
String crossId = signalMap.get(signalCode);
Map<String, RunningLightsStatusPojo> cache = SignalDataCache.runningStateInfoCacheUdp;
if (crossId != null) {
cache.put(crossId, pojo);
CrossInfoPO crossInfoPO = CrossInfoCache.getCrossInfoBySignalCode(signalCode);
if (Objects.nonNull(crossInfoPO)) {
Map<String, RunningLightsStatusPojo> cache = SignalDataCache.runningStateInfoCacheUdp;
cache.put(crossInfoPO.getId(), pojo);
}
return;
}
Object bean = 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);
Object hexResult = commandResponseFactory.getCommandResponse(commandPojo);
if (Objects.nonNull(hexResult)) {
......
......@@ -21,5 +21,5 @@ public interface SignalStatusService {
List<SignalStatusLogPO> runningStatusAlarm(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 {
Long lastPhaseTimeStamp = runningStatusStampMap.get(crossId);
String phaseId = lightsStatusVO.getPhaseId();
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));
// 通过时段表,切换方案 凌晨00:00 如果切换下一个日期方案,可能RefreshCacheTask还没执行
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));
executeNextSectionScheme(crossId, lightsStatusVO, "1", crossSchemePO);
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