Commit a38fb65a authored by duanruiming's avatar duanruiming

[update] 优化海信灯态倒计时

parent 97d6a8db
......@@ -14,14 +14,14 @@ import java.util.Objects;
@AllArgsConstructor
@RequiredArgsConstructor
public enum DataBrainDirEnum {
ZERO(0, 5),
ONE(1, 6),
TWO(2, 7),
THREE(3, 8),
FOUR(4, 1),
FIVE(5, 2),
SIX(6, 3),
SEVEN(7, 4);
ZERO(0, 1),
ONE(1, 2),
TWO(2, 3),
THREE(3, 4),
FOUR(4, 5),
FIVE(5, 6),
SIX(6, 7),
SEVEN(7, 8);
private Integer hisenseDir;
private Integer wjLightsDir;
......
package net.wanji.utc.hisense.task;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.StringUtils;
import net.wanji.databus.dao.entity.CrossPhasePO;
import net.wanji.databus.dao.entity.CrossSchemePO;
import net.wanji.databus.dao.mapper.CrossPhaseMapper;
import net.wanji.databus.dao.mapper.CrossSchemeMapper;
import net.wanji.databus.vo.LightsStatusVO;
import net.wanji.utc.hisense.cache.SignalDataCache;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;
......@@ -14,8 +22,14 @@ import java.util.Objects;
* @date 2023/09/20 14:25
*/
@Component
@Slf4j
public class HisensePhaseCountDownTask {
@Resource
private CrossPhaseMapper crossPhaseMapper;
@Resource
private CrossSchemeMapper crossSchemeMapper;
@Scheduled(fixedRate = 1000, initialDelay = 1000)
public void phaseTimeCountDown() {
Map<String, LightsStatusVO> runningStateInfoCache4DataBrain = SignalDataCache.runningStateInfoCache4DataBrain;
......@@ -26,8 +40,34 @@ public class HisensePhaseCountDownTask {
LightsStatusVO lightsStatusVO = entry.getValue();
String schemeStartTime = lightsStatusVO.getSchemeStartTime();
Long lastPhaseTimeStamp = runningStatusStampMap.get(crossId);
String phaseId = lightsStatusVO.getPhaseId();
String schemeId = lightsStatusVO.getSchemeId();
// log.error("当前相位号:{},上一时间戳:{},当前时间时间戳:{}", crossId, lastPhaseTimeStamp, schemeStartTime);
// log.error("当前路口参数:{}", entry);
if (Objects.nonNull(lastPhaseTimeStamp) && StringUtils.equalsIgnoreCase(schemeStartTime, String.valueOf(lastPhaseTimeStamp))) {
lightsStatusVO.setCycleCountDown(lightsStatusVO.getCycleCountDown() - 1);
CrossSchemePO crossSchemePO = crossSchemeMapper.selectByCrossIdAndSchemeNo(crossId, Integer.valueOf(schemeId));
if (lightsStatusVO.getCyclePhaseCountDown() == 0 && Objects.nonNull(crossSchemePO)) {
List<CrossPhasePO> crossPhasePOS = crossPhaseMapper.selectByCrossIdAndPlanId(crossId, String.valueOf(crossSchemePO.getId()));
Integer nextPhaseTime = 0;
String nextPhaseId = "0";
if (!CollectionUtils.isEmpty(crossPhasePOS)) {
for (int i = 0; i < crossPhasePOS.size(); i++) {
if (StringUtils.equalsIgnoreCase(phaseId, crossPhasePOS.get(i).getPhaseNo())) {
if (i == crossPhasePOS.size() - 1) {
nextPhaseTime = crossPhasePOS.get(0).getPhaseTime();
nextPhaseId = "1";
} else {
nextPhaseTime = crossPhasePOS.get(i + 1).getPhaseTime();
nextPhaseId = crossPhasePOS.get(i + 1).getPhaseNo();
}
}
}
}
lightsStatusVO.setPhaseId(nextPhaseId);
lightsStatusVO.setCyclePhaseCountDown(nextPhaseTime);
} else {
lightsStatusVO.setCyclePhaseCountDown(lightsStatusVO.getCyclePhaseCountDown() - 1);
}
runningStateInfoCache4DataBrain.put(crossId, 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