Commit e7d0d0ea authored by duanruiming's avatar duanruiming

[update] 优化海信发送http灯态,通过方案倒计时计算灯态,通过时段切换方案

parent b13b8f7b
......@@ -78,11 +78,12 @@ public class CrossPhaseDirTurnCache implements CommandLineRunner {
List<CrossLightsPO> crossLightsPOS = crossLightsMapper.selectByCrossId(crossId);
Map<Integer, List<CrossLightsPO>> phaseDirMap = crossLightsPOS.stream().filter(po -> phaseLightsList.contains(po.getId())).collect(Collectors.groupingBy(CrossLightsPO::getDir));
Map<Integer, List<Integer>> dirTurnMap = new HashMap<>();
Map<Integer, List<CrossLightsPO>> dirTurnMap = new HashMap<>();
for (Map.Entry<Integer, List<CrossLightsPO>> entry : phaseDirMap.entrySet()) {
Integer dir = entry.getKey();
List<Integer> turnList = entry.getValue().stream().map(CrossLightsPO::getTurn).sorted().collect(Collectors.toList());
dirTurnMap.put(dir, turnList);
// List<Integer> turnList = entry.getValue().stream().map(CrossLightsPO::getTurn).sorted().collect(Collectors.toList());
// dirTurnMap.put(dir, turnList);
dirTurnMap.put(dir, entry.getValue());
crossPhaseDirTurnPojo.setDirTurnMap(dirTurnMap);
}
results.add(crossPhaseDirTurnPojo);
......
package net.wanji.utc.hisense.cache;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.Constants;
import net.wanji.common.utils.tool.DateUtil;
import net.wanji.common.utils.tool.StringUtils;
import net.wanji.databus.dao.entity.CrossSchedulesPO;
import net.wanji.databus.dao.entity.CrossSchemePO;
import net.wanji.databus.dao.entity.CrossSectionPO;
import net.wanji.databus.dao.mapper.CrossSchedulesMapper;
import net.wanji.databus.dao.mapper.CrossSchemeMapper;
import net.wanji.databus.dao.mapper.CrossSectionMapper;
import net.wanji.databus.po.CrossInfoPO;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author duanruiming
* @date 2023/09/23 17:26
*/
@Slf4j
@Component
@SuppressWarnings("unchecked")
@RequiredArgsConstructor
public class CrossRunSchemeCache implements CommandLineRunner {
public static final Map<String, String> currentRunSchemeNoCache = new HashMap<>();
@Resource
private CrossSchedulesMapper crossSchedulesMapper;
@Resource
private CrossSectionMapper crossSectionMapper;
@Resource
private CrossSchemeMapper crossSchemeMapper;
@Override
public void run(String... args) throws Exception {
init();
}
private void init() throws Exception {
Map<String, CrossInfoPO> crossInfoCache = CrossInfoCache.getCrossInfoCache();
if (!crossInfoCache.isEmpty()) {
for (Map.Entry<String, CrossInfoPO> entry : crossInfoCache.entrySet()) {
String crossId = entry.getKey();
List<CrossSectionPO> crossSectionPOS = crossSectionMapper.selectByCrossId(crossId);
List<CrossSchedulesPO> crossSchedulesPOS = crossSchedulesMapper.selectByCrossIds(Arrays.asList(crossId));
if (!CollectionUtils.isEmpty(crossSchedulesPOS)) {
Map<Integer, List<CrossSchedulesPO>> schedulesMap = crossSchedulesPOS.stream().collect(Collectors.groupingBy(CrossSchedulesPO::getPlanId));
// 判断当前执行的调度,获取日计划号
Date date = new Date();
LocalTime currentTime = LocalTime.parse(DateUtil.getTime());
Integer currentPlanId = getCurrentPlanId(schedulesMap, date);
Integer schemeId = getCurrentSchemeId(crossSectionPOS, currentTime, currentPlanId);
CrossSchemePO crossSchemePO = crossSchemeMapper.selectSchemePOById(schemeId);
currentRunSchemeNoCache.put(crossId, crossSchemePO.getSchemeNo());
}
}
}
}
private static Integer getCurrentSchemeId(List<CrossSectionPO> crossSectionPOS, LocalTime currentTime, Integer currentPlanId) {
if (!CollectionUtils.isEmpty(crossSectionPOS)) {
List<CrossSectionPO> currentPlanIdSectionList = crossSectionPOS.stream().filter(po -> Objects.equals(currentPlanId, po.getPlanId())).collect(Collectors.toList());
for (CrossSectionPO crossSectionPO : currentPlanIdSectionList) {
Integer schemeId = crossSectionPO.getSchemeId();
LocalTime startTime = LocalTime.parse(crossSectionPO.getStartTime());
LocalTime endTime = LocalTime.parse(crossSectionPO.getEndTime());
// 过滤非当前时段数据
if (currentTime.isAfter(startTime) && currentTime.isBefore(endTime)) {
return schemeId;
}
}
}
return 0;
}
private static Integer getCurrentPlanId(Map<Integer, List<CrossSchedulesPO>> schedulesMap, Date currentDate) {
for (Map.Entry<Integer, List<CrossSchedulesPO>> entry : schedulesMap.entrySet()) {
Integer planId = entry.getKey();
List<CrossSchedulesPO> schedulesPOS = entry.getValue();
if (!CollectionUtils.isEmpty(schedulesPOS)) {
for (CrossSchedulesPO schedulesPO : schedulesPOS) {
Integer isSpectialDay = schedulesPO.getWeek(); // 0 为特殊日期
Date specialDate = schedulesPO.getSpecialDate();
String specialDate4DB = DateUtil.format(specialDate, Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND);
String currentDateStr = DateUtil.format(currentDate, Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND);
if (Objects.equals(0, isSpectialDay)) {
if (StringUtils.equalsIgnoreCase(currentDateStr.substring(0, 10), specialDate4DB.substring(0, 10))) {
return planId;
}
}
Integer week4DB = schedulesPO.getWeek();
int weekCurrent = DateUtil.getWeek(currentDate);
if (week4DB == weekCurrent) {
return planId;
}
}
}
}
return 0;
}
}
package net.wanji.utc.hisense.pojo;
import lombok.Data;
import net.wanji.databus.dao.entity.CrossLightsPO;
import java.util.List;
import java.util.Map;
......@@ -14,5 +15,5 @@ public class CrossPhaseDirTurnPojo {
private String crossId;
private Integer phaseNo;
private Integer schemeNo;
private Map<Integer, List<Integer>> dirTurnMap;
private Map<Integer, List<CrossLightsPO>> dirTurnMap;
}
......@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.common.utils.tool.StringUtils;
import net.wanji.databus.dao.entity.CrossLightsPO;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.databus.po.SignalStatusLogPO;
import net.wanji.databus.vo.LightsStatusVO;
......@@ -138,14 +139,16 @@ public class SignalStatusServiceImpl implements SignalStatusService {
if (!CollectionUtils.isEmpty(crossPhaseDirTurnList)) {
List<CrossPhaseDirTurnPojo> schemeNoList = crossPhaseDirTurnList.stream().filter(po -> Objects.equals(po.getSchemeNo(), planId)).collect(Collectors.toList());
for (CrossPhaseDirTurnPojo crossPhaseDirTurnPojo : schemeNoList) {
Map<Integer, List<Integer>> dirTurnCache = crossPhaseDirTurnPojo.getDirTurnMap();
for (Map.Entry<Integer, List<Integer>> dirTurnCacheEntry : dirTurnCache.entrySet()) {
// Map<Integer, List<Integer>> dirTurnCache = crossPhaseDirTurnPojo.getDirTurnMap();
Map<Integer, List<CrossLightsPO>> dirTurnMap = crossPhaseDirTurnPojo.getDirTurnMap();
for (Map.Entry<Integer, List<CrossLightsPO>> dirTurnCacheEntry : dirTurnMap.entrySet()) {
Integer dirCache = dirTurnCacheEntry.getKey();
for (Map.Entry<Integer, List<Integer>> hisEntry : hisDirTurnMap.entrySet()) {
Integer hisDir = hisEntry.getKey();
if (Objects.equals(dirCache, CrossLisghtsLaneDirEnum.getLightsDirByLaneDir(hisDir))) {
List<Integer> turnListCache = dirTurnCacheEntry.getValue();
if (hisEntry.getValue().stream().allMatch(turnListCache::contains)) {
List<CrossLightsPO> turnListCache = dirTurnCacheEntry.getValue();
List<Integer> turnList = turnListCache.stream().map(CrossLightsPO::getTurn).sorted().collect(Collectors.toList());
if (hisEntry.getValue().stream().allMatch(turnList::contains)) {
phaseNo = crossPhaseDirTurnPojo.getPhaseNo();
}
}
......
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