Commit 9f3641bc authored by duanruiming's avatar duanruiming

[update] 优化海信程序

parent f53a45fa
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;
......@@ -30,6 +29,6 @@ public class HisenseApplication implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
NettyClient.connection(localPort, remoteProt);
// NettyClient.connection(localPort, remoteProt);
}
}
......@@ -10,6 +10,7 @@ import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
/**
* @author duanruiming
......@@ -23,4 +24,5 @@ public class SignalDataCache {
// 海信推送灯态数据
public static final Map<String, RunningLightsStatusPojo> runningStateInfoCache = new HashMap<>();
public static final Map<String, LightsStatusVO> runningStateInfoCache4DataBrain = new HashMap<>();
public static final Map<String, PriorityQueue<LightsStatusVO>> crossPriority = new HashMap<>();
}
......@@ -47,7 +47,8 @@ public class SignalStatusServiceImpl implements SignalStatusService {
public void receiveLightStatus(HisenseLightStatusPojo hisenseLightStatusPojo) throws Exception {
ObjectMapper jackson = JacksonUtils.getInstance();
String bodyStr = hisenseLightStatusPojo.getBody();
List<HisenseLightStatusPojo.Body> bodies = jackson.readValue(bodyStr, new TypeReference<List<HisenseLightStatusPojo.Body>>() {});
List<HisenseLightStatusPojo.Body> bodies = jackson.readValue(bodyStr, new TypeReference<List<HisenseLightStatusPojo.Body>>() {
});
if (!CollectionUtils.isEmpty(bodies)) {
for (HisenseLightStatusPojo.Body body : bodies) {
HisenseLightStatusPojo.ContentBody content = body.getContent();
......@@ -55,19 +56,49 @@ public class SignalStatusServiceImpl implements SignalStatusService {
String hiCrossId = content.getCrossId();
CrossInfoPO crossInfo = CrossInfoCache.getCrossInfoBySignalCode(hiCrossId);
if (Objects.isNull(crossInfo)) {
log.error("接收滴滴数据大脑海信灯态数据,当前路口编码不存在:{}", hiCrossId);
continue;
}
String crossId = crossInfo.getId();
int cycleCountDown = content.getCycleCountDown();
PriorityQueue<LightsStatusVO> crossPriority = SignalDataCache.crossPriority.get(crossId);
if (Objects.isNull(crossPriority)) {
crossPriority = new PriorityQueue<>((o1, o2) -> {
long l = Long.parseLong(o1.getSchemeStartTime()) - Long.parseLong(o2.getSchemeStartTime());
return (int) l;
});
} else {
if (crossPriority.size() > 0) {
LightsStatusVO lightsStatusVOCache = crossPriority.peek();
if (Objects.nonNull(lightsStatusVOCache)) {
if (lightsStatusVOCache.getCycleCountDown() <= cycleCountDown) {
continue;
}
}
}
}
int hiControlMode = content.getControlMode();
int period = content.getPeriod();
int planId = content.getPlanId();
int cycleCountDown = content.getCycleCountDown();
lightsStatusVO.setCrossId(hiCrossId);
Long signalMachineStamp = content.getSignalMachineStamp();
if (StringUtils.equals(crossId, "13NF80B5QN0")) {
log.error("当前路口编号:{}, 周期倒计时:{},周期时间:{}", crossId, cycleCountDown, period);
}
lightsStatusVO.setCrossId(crossId);
lightsStatusVO.setSchemeId(String.valueOf(planId));
lightsStatusVO.setRunMode(String.valueOf(DataBrainControlModeEnum.getWjControlMode(hiControlMode)));
String runMode = String.valueOf(DataBrainControlModeEnum.getWjControlMode(hiControlMode));
lightsStatusVO.setRunMode(runMode);
lightsStatusVO.setCycleCountDown(cycleCountDown);
lightsStatusVO.setCycleLen(period);
lightsStatusVO.setSchemeStartTime(String.valueOf(signalMachineStamp));
// 保证不为空值
lightsStatusVO.setPhaseMap(Collections.emptyMap());
lightsStatusVO.setControlMode(runMode);
lightsStatusVO.setCode(hiCrossId);
lightsStatusVO.setManufacturerCode("hisense");
lightsStatusVO.setPhasePlanId(String.valueOf(planId));
List<HisenseLightStatusPojo.ContentBody.LampRealInfos> lampRealInfos = content.getLampRealInfos();
if (!CollectionUtils.isEmpty(lampRealInfos)) {
......@@ -87,16 +118,23 @@ public class SignalStatusServiceImpl implements SignalStatusService {
if (StringUtils.endsWithIgnoreCase(lampStatus, "23")) {
lightsStatusVO.setPhaseId("0");
lightsStatusVO.setCyclePhaseCountDown(countDown);
break;
}
turnMap.put(String.valueOf(DataBrainTurnEnum.getWjTurn(roadFlowDirection)), DataBrainLampStatusEnum.getWjLampStatus(lampStatus));
}
dirMap.put(String.valueOf(DataBrainDirEnum.getWjLightsDir(roadDirection)), turnMap);
}
lightsStatusVO.setDirLampGroupMap(dirMap);
crossPriority.offer(lightsStatusVO);
if (crossPriority.size() > 100) {
crossPriority.clear();
}
SignalDataCache.runningStateInfoCache4DataBrain.put(crossId, lightsStatusVO);
log.error("接收滴滴数据大脑后缓存路口灯态:{}", SignalDataCache.runningStateInfoCache4DataBrain);
SignalDataCache.crossPriority.put(crossId, crossPriority);
}
}
}
}
}
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