Commit a8950a44 authored by duanruiming's avatar duanruiming

[update] 优化日计划缓存,每日凌晨更新

parent e7d0d0ea
...@@ -44,7 +44,7 @@ public class CrossRunSchemeCache implements CommandLineRunner { ...@@ -44,7 +44,7 @@ public class CrossRunSchemeCache implements CommandLineRunner {
init(); init();
} }
private void init() throws Exception { public void init() throws Exception {
Map<String, CrossInfoPO> crossInfoCache = CrossInfoCache.getCrossInfoCache(); Map<String, CrossInfoPO> crossInfoCache = CrossInfoCache.getCrossInfoCache();
if (!crossInfoCache.isEmpty()) { if (!crossInfoCache.isEmpty()) {
......
...@@ -49,15 +49,16 @@ public class HisensePhaseCountDownTask { ...@@ -49,15 +49,16 @@ public class HisensePhaseCountDownTask {
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还没执行
String nextSectionSchemeNo = CrossRunSchemeCache.currentRunSchemeNoCache.get(crossId); String nextSectionSchemeNo = CrossRunSchemeCache.currentRunSchemeNoCache.get(crossId);
if (!StringUtils.equalsIgnoreCase(nextSectionSchemeNo, schemeId)) { if (!StringUtils.equalsIgnoreCase(nextSectionSchemeNo, schemeId)) {
executeNextSectionScheme(); crossSchemePO = crossSchemeMapper.selectByCrossIdAndSchemeNo(crossId, Integer.valueOf(nextSectionSchemeNo));
executeNextSectionScheme(crossId, lightsStatusVO, "1", crossSchemePO);
lightsStatusVO.setCycleLen(crossSchemePO.getCycle());
} else { } else {
executeNextPeriod(crossId, lightsStatusVO, phaseId, crossSchemePO);
} }
// 当前方案下一周期 // 当前方案下一周期
executeNextPeriod(crossId, lightsStatusVO, phaseId, crossSchemePO);
setDirLampGroupMap(lightsStatusVO); setDirLampGroupMap(lightsStatusVO);
runningStateInfoCache.put(crossId, lightsStatusVO); runningStateInfoCache.put(crossId, lightsStatusVO);
} }
...@@ -65,9 +66,36 @@ public class HisensePhaseCountDownTask { ...@@ -65,9 +66,36 @@ public class HisensePhaseCountDownTask {
} }
} }
private void executeNextSectionScheme() { /**
* @description 通过日计划缓存,切换下一个时段方案
* @param crossId
* @param lightsStatusVO
* @param phaseId
* @param crossSchemePO
*/
private void executeNextSectionScheme(String crossId, LightsStatusVO lightsStatusVO, String phaseId, CrossSchemePO crossSchemePO) {
if (Objects.nonNull(crossSchemePO)) {
List<CrossPhasePO> nextSchemePhaseList = crossPhaseMapper.selectByCrossIdAndPlanId(crossId, String.valueOf(crossSchemePO.getId()));
Integer phaseTime = 0;
if (!CollectionUtils.isEmpty(nextSchemePhaseList)) {
for (CrossPhasePO crossPhasePO : nextSchemePhaseList) {
if (StringUtils.equalsIgnoreCase(phaseId, crossPhasePO.getPhaseNo())) {
phaseTime = crossPhasePO.getPhaseTime();
}
}
}
lightsStatusVO.setPhaseId(phaseId);
lightsStatusVO.setCyclePhaseCountDown(phaseTime);
}
} }
/**
* @description 切换下一方案周期
* @param crossId
* @param lightsStatusVO
* @param phaseId
* @param crossSchemePO
*/
private void executeNextPeriod(String crossId, LightsStatusVO lightsStatusVO, String phaseId, CrossSchemePO crossSchemePO) { private void executeNextPeriod(String crossId, LightsStatusVO lightsStatusVO, String phaseId, CrossSchemePO crossSchemePO) {
if (lightsStatusVO.getCyclePhaseCountDown() == 0 && Objects.nonNull(crossSchemePO)) { if (lightsStatusVO.getCyclePhaseCountDown() == 0 && Objects.nonNull(crossSchemePO)) {
List<CrossPhasePO> crossPhasePOS = crossPhaseMapper.selectByCrossIdAndPlanId(crossId, String.valueOf(crossSchemePO.getId())); List<CrossPhasePO> crossPhasePOS = crossPhaseMapper.selectByCrossIdAndPlanId(crossId, String.valueOf(crossSchemePO.getId()));
...@@ -93,6 +121,10 @@ public class HisensePhaseCountDownTask { ...@@ -93,6 +121,10 @@ public class HisensePhaseCountDownTask {
} }
} }
/**
* @description 通过当前周期倒计时方案相位灯态
* @param lightsStatusVO
*/
public void setDirLampGroupMap(LightsStatusVO lightsStatusVO) { public void setDirLampGroupMap(LightsStatusVO lightsStatusVO) {
String crossId = lightsStatusVO.getCrossId(); String crossId = lightsStatusVO.getCrossId();
String currentSchemeNo = lightsStatusVO.getSchemeId(); String currentSchemeNo = lightsStatusVO.getSchemeId();
...@@ -170,6 +202,13 @@ public class HisensePhaseCountDownTask { ...@@ -170,6 +202,13 @@ public class HisensePhaseCountDownTask {
} }
} }
/**
* @description 获取路口方案相位倒计时
* @param crossId
* @param schemeNo
* @param phaseNo
* @return
*/
private PhaseCountDownDTO getPhaseCountDownDTO(String crossId, String schemeNo, String phaseNo) { private PhaseCountDownDTO getPhaseCountDownDTO(String crossId, String schemeNo, String phaseNo) {
List<CrossSchemePhaseCountDownDTO> crossSchemePhaseCountDownList = CrossSchemePhaseTimeCountCache.crossSchemePhaseCountDownList; List<CrossSchemePhaseCountDownDTO> crossSchemePhaseCountDownList = CrossSchemePhaseTimeCountCache.crossSchemePhaseCountDownList;
if (!CollectionUtils.isEmpty(crossSchemePhaseCountDownList)) { if (!CollectionUtils.isEmpty(crossSchemePhaseCountDownList)) {
......
package net.wanji.utc.hisense.task;
import lombok.extern.slf4j.Slf4j;
import net.wanji.utc.hisense.cache.CrossRunSchemeCache;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author duanruiming
* @date 2023/09/25 10:15
*/
@Component
@Slf4j
public class RefreshCacheTask {
@Resource
private CrossRunSchemeCache crossRunSchemeCache;
@Scheduled(cron = "0 0 * * * ?")
public void refresh() throws Exception {
try {
crossRunSchemeCache.init();
} catch (Exception e) {
throw new Exception("每天刷新路口日计划缓存失败", e);
}
}
}
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