Commit bf0a2bf1 authored by duanruiming's avatar duanruiming

[update] 添加红灯倒计时

parent 728c8b9b
......@@ -135,10 +135,13 @@ public class DTSignalStatusServiceImpl implements SignalStatusService {
List<String> lightsStatus = SignalDataCache.realTimeLightCache.get(crossId);
List<PhaseStageStatusPojo> phaseStageStatusPojos = SignalDataCache.realTimePhaseStatusStageCache.get(crossId);
List<RunningStatusPojo> runningStatusPojos = SignalDataCache.realTimeRunStatusCache.get(crossId);
if (CollectionUtils.isEmpty(lightsStatus) || CollectionUtils.isEmpty(phaseStageStatusPojos) || CollectionUtils.isEmpty(runningStatusPojos)) {
throw new Exception("获取东土信号机实时数据为空");
}
return getLightsStatusVOs(crossId, lightsStatus, phaseStageStatusPojos, runningStatusPojos);
}
public static List<PhaseStageStatusPojo> getPhaseStageStatus(String crossId) throws Exception {
public static List<PhaseStageStatusPojo> getPhaseStageStatus(String crossId) throws Exception {
List<PhaseStageStatusPojo> phaseStageStatusPojos = new ArrayList<>();
CrossInfoPO crossInfoPO = DTControlCommandServiceImpl.checkCrossId(crossId);
String message = String.format(Constants.COMMAND_COMMON, Constants.COMMAND_QUERY, Constants.COMMAND_PHASE_STAGE_STATUS);
......@@ -179,6 +182,7 @@ public class DTSignalStatusServiceImpl implements SignalStatusService {
for (int j = 0; j < runningStatusPojos.size(); j++) {
RunningStatusPojo runningStatusPojo = runningStatusPojos.get(j);
LightsStatusVO lightsStatusVO = new LightsStatusVO();
Map<String, Object> phaseMap = new HashMap<>();
String controlModel = String.valueOf(ControlModelEnum.getWjControlMode(runningStatusPojo.getControlMode().substring(2, 4)));
lightsStatusVO.setCrossId(crossId);
lightsStatusVO.setRunMode(controlModel);
......@@ -191,6 +195,7 @@ public class DTSignalStatusServiceImpl implements SignalStatusService {
Integer currentSchemeId = runningStatusPojo.getSchemeId();
Integer currentPhaseStageId = runningStatusPojo.getPhaseStageId();
List<SchemeInfoPojo> schemeInfoPojos = SignalDataCache.schemeInfoCache.get(crossId);
if (!CollectionUtils.isEmpty(schemeInfoPojos)) {
for (SchemeInfoPojo schemeInfoPojo : schemeInfoPojos) {
if (Objects.equals(schemeInfoPojo.getSchemeId(), currentSchemeId)) {
......@@ -214,13 +219,24 @@ public class DTSignalStatusServiceImpl implements SignalStatusService {
List<PhaseInfoPojo> phaseInfoPojos = SignalDataCache.phaseInfoCache.get(crossId);
Integer redTime = 0;
for (PhaseInfoPojo phaseInfoPojo : phaseInfoPojos) {
Integer lightsId = phaseInfoPojo.getLightsId();
if (phaseInfoPojo.getPhaseId() == phaseList.get(0)) {
redTime = phaseInfoPojo.getRedTime();
}
List<LightsInfoPojo> lightsInfoPojos = SignalDataCache.lightInfoCache.get(crossId);
for (LightsInfoPojo lightsInfoPojo : lightsInfoPojos) {
if (Objects.equals(lightsInfoPojo.getLightId(), lightsId)) {
Integer lightsDir = lightsInfoPojo.getLightsDir(lightsId);
Integer type = lightsInfoPojo.getType();
Integer lightsTurn = lightsInfoPojo.getTurnDir(lightsDir, type);
phaseMap.put(String.join("-", String.valueOf(lightsDir), String.valueOf(lightsTurn)), phaseStageTime);
}
}
}
lightsStatusVO.setSchemeId(String.valueOf(currentSchemeId));
lightsStatusVO.setCycleLen(schemeInfoPojo.getCycle());
lightsStatusVO.setCycleCountDown(phaseStageStatusPojo.getRemainTime());
lightsStatusVO.setPhaseMap(phaseMap);
// 当运行时间小于过渡时,运行的时上一个阶段,
int realRemainTime = phaseStageStatusPojo.getRemainTime();
Integer runningTime = phaseStageStatusPojo.getRunningTime();
......
package net.wanji.utc.dt.task;
import net.wanji.databus.dto.PlanSectionDTO;
import net.wanji.databus.dto.SchemePhaseLightsDTO;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.utc.dt.cache.CrossInfoCache;
import net.wanji.utc.dt.cache.SignalDataCache;
import net.wanji.utc.dt.pojo.dtconvert.PhaseStageStatusPojo;
import net.wanji.utc.dt.pojo.dtconvert.RunningStatusPojo;
import net.wanji.utc.dt.service.StaticInfoService;
import net.wanji.utc.dt.service.impl.DTSignalStatusServiceImpl;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -24,11 +26,13 @@ public class RealTimeTask {
@Resource(name = "commonThreadPoolExecutor")
ThreadPoolTaskExecutor commonThreadPoolExecutor;
@Scheduled(initialDelay = 60 * 1000, fixedRate = 1000)
@Resource
StaticInfoService staticInfoService;
@Scheduled(initialDelay = 30 * 1000, fixedRate = 60 * 1000)
public void getRealTimeLightStatus() throws Exception {
Map<String, CrossInfoPO> crossInfoCache = CrossInfoCache.getCrossInfoCache();
if (!crossInfoCache.isEmpty()) {
System.err.println(new Date());
for (Map.Entry<String, CrossInfoPO> entry : crossInfoCache.entrySet()) {
String crossId = entry.getKey();
commonThreadPoolExecutor.execute(() -> {
......@@ -39,6 +43,15 @@ public class RealTimeTask {
SignalDataCache.realTimeRunStatusCache.put(crossId, runningStatusPojos);
List<PhaseStageStatusPojo> phaseStageStatus = DTSignalStatusServiceImpl.getPhaseStageStatus(crossId);
SignalDataCache.realTimePhaseStatusStageCache.put(crossId, phaseStageStatus);
// 静态数据
SchemePhaseLightsDTO schemePhaseLightsDTO = new SchemePhaseLightsDTO();
schemePhaseLightsDTO.setCrossId(crossId);
staticInfoService.schemePhaseLights(schemePhaseLightsDTO);
PlanSectionDTO planSectionDTO = new PlanSectionDTO();
planSectionDTO.setCrossId(crossId);
planSectionDTO.setPlanNo(-1);
staticInfoService.planSection(planSectionDTO);
staticInfoService.crossSchedules(crossId);
} catch (Exception e) {
throw new RuntimeException(e);
}
......
......@@ -25,7 +25,6 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StopWatch;
import javax.annotation.Resource;
import java.util.*;
......@@ -89,14 +88,8 @@ public class SignalStatusTask {
if (StringUtils.equals(BasicEnum.ManufacturerEnum.HK.getCode(), manufacturerInfoPO.getCode())) {
lightsStatusVOS = hkLightsStatusService.getHkLightsStatus(crossId);
} else if (StringUtils.equals(BasicEnum.ManufacturerEnum.DT.getCode(), manufacturerInfoPO.getCode())){
StopWatch stopWatch = new StopWatch();
stopWatch.start();
JsonViewObject jsonViewObject = utcDTFeignClients.lightStatus(crossId);
lightsStatusVOS = mapper.convertValue(jsonViewObject.getContent(), new TypeReference<List<LightsStatusVO>>() {});
stopWatch.stop();
log.error("运行时间:{}", stopWatch.getTotalTimeMillis());
log.error("dirLampGroupMap:{}", lightsStatusVOS.get(0).getDirLampGroupMap());
} else if (StringUtils.equals(BasicEnum.ManufacturerEnum.HISENSE.getCode(), manufacturerInfoPO.getCode())){
JsonViewObject jsonViewObject = utcHisenseFeignClients.lightStatus(crossId);
lightsStatusVOS = mapper.convertValue(jsonViewObject.getContent(), new TypeReference<List<LightsStatusVO>>() {});
......
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