Commit ada82b8f authored by duanruiming's avatar duanruiming

[add] 通过方案自动加载灯态接口

parent 04a76264
......@@ -26,7 +26,7 @@ public class CrossInfoCache implements CommandLineRunner {
@Resource
private ManufacturerInfoMapper manufacturerInfoMapper;
private static List<CrossInfoPO> crossInfoList = new ArrayList<>();
public static List<CrossInfoPO> crossInfoList = new ArrayList<>();
/**
* 通过路口编号获取厂商编码
......
package net.wanji.utc.cache;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.wanji.databus.dao.entity.CrossLightsPO;
import net.wanji.databus.dao.entity.CrossPhaseLightsPO;
import net.wanji.databus.dao.entity.CrossPhasePO;
import net.wanji.databus.dao.entity.CrossSchemePO;
import net.wanji.databus.dao.mapper.*;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.utc.po.hk.CrossPhaseDirTurnPojo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author duanruiming
* @date 2023/09/11 17:42
*/
@Slf4j
@Component
@SuppressWarnings("unchecked")
@RequiredArgsConstructor
public class CrossPhaseDirTurnCache implements CommandLineRunner {
private final CrossInfoMapper crossInfoMapper;
private final CrossPhaseMapper crossPhaseMapper;
private final CrossSchemeMapper crossSchemeMapper;
private final CrossPhaseLightsMapper crossPhaseLightsMapper;
private final CrossLightsMapper crossLightsMapper;
private static final Map<String, List<CrossPhaseDirTurnPojo>> crossInfoMap = new HashMap<>();
public static List<CrossPhaseDirTurnPojo> getCrossPhaseDirTurnCache(String crossId) {
if (!crossInfoMap.isEmpty()) {
return crossInfoMap.get(crossId);
}
return null;
}
@Override
public void run(String... args) throws Exception {
init();
}
public void init() {
List<CrossInfoPO> crossInfoPOList = crossInfoMapper.selectAll();
if (!CollectionUtils.isEmpty(crossInfoPOList)) {
for (CrossInfoPO crossInfoPO : crossInfoPOList) {
String crossId = crossInfoPO.getId();
List<CrossSchemePO> crossSchemePOS = crossSchemeMapper.selectByCrossId(crossId);
Map<Integer, String> schemeIdNoMap = crossSchemePOS.stream().collect(Collectors.toMap(CrossSchemePO::getId, CrossSchemePO::getSchemeNo));
List<CrossPhasePO> crossPhasePOS = crossPhaseMapper.selectByCrossId(crossId);
if (!CollectionUtils.isEmpty(crossPhasePOS)) {
List<CrossPhaseDirTurnPojo> results = new ArrayList<>();
for (CrossPhasePO crossPhasePO : crossPhasePOS) {
CrossPhaseDirTurnPojo crossPhaseDirTurnPojo = new CrossPhaseDirTurnPojo();
String phaseNo = crossPhasePO.getPhaseNo();
crossPhaseDirTurnPojo.setCrossId(crossId);
crossPhaseDirTurnPojo.setPhaseNo(Integer.valueOf(phaseNo));
Integer planId = crossPhasePO.getPlanId();
String schemeNo = schemeIdNoMap.get(planId);
if (StringUtils.isNotBlank(schemeNo)) {
crossPhaseDirTurnPojo.setSchemeNo(Integer.valueOf(schemeNo));
} else {
crossPhaseDirTurnPojo.setSchemeNo(-1);
}
Integer phaseId = crossPhasePO.getId();
List<CrossPhaseLightsPO> crossPhaseLightsPOList = crossPhaseLightsMapper.selectByCrossId(crossId);
List<Integer> phaseLightsList = crossPhaseLightsPOList.stream()
.filter(po -> Objects.equals(po.getPhaseId(), phaseId))
.map(CrossPhaseLightsPO::getLightsId).collect(Collectors.toList());
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<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);
dirTurnMap.put(dir, entry.getValue());
crossPhaseDirTurnPojo.setDirTurnMap(dirTurnMap);
}
results.add(crossPhaseDirTurnPojo);
}
crossInfoMap.put(crossId, results);
}
}
}
}
}
package net.wanji.utc.cache;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.wanji.databus.dao.entity.CrossPhasePO;
import net.wanji.databus.dao.entity.CrossSchemePO;
import net.wanji.databus.dao.mapper.CrossInfoMapper;
import net.wanji.databus.dao.mapper.CrossPhaseMapper;
import net.wanji.databus.dao.mapper.CrossSchemeMapper;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.utc.dto.CrossSchemePhaseCountDownDTO;
import net.wanji.utc.dto.PhaseCountDownDTO;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author duanruiming
* @date 2023/09/22 14:19
*/
@Slf4j
@Component
@SuppressWarnings("unchecked")
@RequiredArgsConstructor
public class CrossSchemePhaseTimeCountCache implements CommandLineRunner {
public static final List<CrossSchemePhaseCountDownDTO> crossSchemePhaseCountDownList = new ArrayList<>();
@Resource
private CrossPhaseMapper crossPhaseMapper;
@Resource
private CrossSchemeMapper crossSchemeMapper;
@Resource
private CrossInfoMapper crossInfoMapper;
@Override
public void run(String... args) throws Exception {
try {
init();
} catch (Exception e) {
log.error("路口方案相位倒计时缓存加载失败", e);
throw new Exception(e);
}
}
public void init() throws Exception {
List<CrossInfoPO> crossInfoPOList = crossInfoMapper.selectAll();
if (!CollectionUtils.isEmpty(crossInfoPOList)) {
for (CrossInfoPO crossInfoPO : crossInfoPOList) {
String crossId = crossInfoPO.getId();
List<CrossPhasePO> crossPhasePOS = crossPhaseMapper.selectByCrossId(crossId);
if (!CollectionUtils.isEmpty(crossPhasePOS)) {
Map<Integer, List<CrossPhasePO>> schemeIdListMap = crossPhasePOS.stream().collect(Collectors.groupingBy(CrossPhasePO::getPlanId));
for (Map.Entry<Integer, List<CrossPhasePO>> entry : schemeIdListMap.entrySet()) {
Integer schemeId = entry.getKey();
CrossSchemePhaseCountDownDTO crossSchemePhaseCountDownDTO = new CrossSchemePhaseCountDownDTO();
CrossSchemePO crossSchemePO = crossSchemeMapper.selectSchemePOById(schemeId);
if (Objects.isNull(crossSchemePO)) {
continue;
}
Integer cycle = crossSchemePO.getCycle();
String schemeNo = crossSchemePO.getSchemeNo();
List<CrossPhasePO> schemeNoList = entry.getValue();
if (!CollectionUtils.isEmpty(schemeNoList)) {
List<CrossPhasePO> phaseSortList = schemeNoList.stream().sorted(Comparator.comparingInt(CrossPhasePO::getSort)).collect(Collectors.toList());
Integer changePhaseTime = 0;
List<PhaseCountDownDTO> phaseCountDownDTOS = new ArrayList<>(phaseSortList.size());
for (CrossPhasePO crossPhasePO : phaseSortList) {
String phaseNo = crossPhasePO.getPhaseNo();
Integer phaseTime = crossPhasePO.getPhaseTime();
Integer yellowTime = crossPhasePO.getYellowTime();
Integer redTime = crossPhasePO.getRedTime();
changePhaseTime += phaseTime;
PhaseCountDownDTO phaseCountDownDTO = new PhaseCountDownDTO();
phaseCountDownDTO.setPhaseNo(phaseNo);
phaseCountDownDTO.setPhaseTime(phaseTime);
phaseCountDownDTO.setChangePhaseTime(changePhaseTime);
phaseCountDownDTO.setYellowTime(yellowTime);
phaseCountDownDTO.setRedTime(redTime);
phaseCountDownDTOS.add(phaseCountDownDTO);
}
crossSchemePhaseCountDownDTO.setPhaseCountDownDTOList(phaseCountDownDTOS);
}
crossSchemePhaseCountDownDTO.setCrossId(crossId);
crossSchemePhaseCountDownDTO.setSchemeNo(schemeNo);
crossSchemePhaseCountDownList.add(crossSchemePhaseCountDownDTO);
}
}
}
}
}
}
......@@ -74,7 +74,7 @@ public class SignalStatusController {
@ApiResponse(code = 200, message = "OK", response = LightsStatusVO.class)
})
public JsonViewObject lightStatusV2() throws Exception {
List<LightsStatusVO> lightsStatusVOList = signalStatusService.lightStatus();
List<LightsStatusVO> lightsStatusVOList = signalStatusService.lightStatus4StaticScheme();
List<LightsStatusVO2> listResult = new ArrayList<>(lightsStatusVOList.size());
for (LightsStatusVO lightsStatusVO : lightsStatusVOList) {
......@@ -87,13 +87,13 @@ public class SignalStatusController {
LightsStatusVO2.DirInfo dirInfo = new LightsStatusVO2.DirInfo();
String dir = groupEntry.getKey();
Map<String, Integer> turnDountMap = (Map<String, Integer>) phaseMap.get(dir);
Map<String, String> turnColorMap = (Map<String, String>)groupEntry.getValue();
Map<Integer, String> turnColorMap = (Map<Integer, String>) groupEntry.getValue();
List<LightsStatusVO2.TurnInfo> turnList = new ArrayList<>();
for (Map.Entry<String, String> turnEntry : turnColorMap.entrySet()) {
String turn = turnEntry.getKey();
for (Map.Entry<Integer, String> turnEntry : turnColorMap.entrySet()) {
Integer turn = turnEntry.getKey();
String color = turnEntry.getValue();
LightsStatusVO2.TurnInfo turnInfo = new LightsStatusVO2.TurnInfo();
turnInfo.setTurn(turn);
turnInfo.setTurn(String.valueOf(turn));
turnInfo.setColor(color);
Integer countDown = turnDountMap.get(turn);
turnInfo.setCountDown(countDown);
......
package net.wanji.utc.dto;
import lombok.Data;
import java.util.List;
/**
* @author duanruiming
* @date 2023/09/22 14:26
*/
@Data
public class CrossSchemePhaseCountDownDTO {
private String crossId;
private String schemeNo;
private List<PhaseCountDownDTO> phaseCountDownDTOList;
}
package net.wanji.utc.dto;
import lombok.Data;
/**
* @author duanruiming
* @date 2023/09/22 14:23
*/
@Data
public class PhaseCountDownDTO {
private String phaseNo;
private Integer changePhaseTime;
private Integer phaseTime;
private Integer yellowTime;
private Integer redTime;
}
package net.wanji.utc.po.hk;
import lombok.Data;
import net.wanji.databus.dao.entity.CrossLightsPO;
import java.util.List;
import java.util.Map;
/**
* @author duanruiming
* @date 2023/09/12 10:24
*/
@Data
public class CrossPhaseDirTurnPojo {
private String crossId;
private Integer phaseNo;
private Integer schemeNo;
private Map<Integer, List<CrossLightsPO>> dirTurnMap;
}
......@@ -21,9 +21,8 @@ public interface SignalStatusService {
List<SignalStatusLogPO> runningStatusAlarm(String crossId);
List<LightsStatusVO> lightStatus() throws Exception;
List<LightsStatusVO> lightStatus4StaticScheme() throws Exception;
List<LightsStatusVO> lightStatus(String crossId) throws Exception;
List<LightsStatusVO> lightStatusHist(String crossId, Integer batchTime, Integer endBatchTime) throws Exception;
}
......@@ -22,16 +22,14 @@ import net.wanji.utc.service.runninginfo.HkLightsStatusService;
import net.wanji.utc.service.runninginfo.HkRunningStatusService;
import net.wanji.utc.service.runninginfo.SignalStatusService;
import net.wanji.utc.service.runninginfo.WanJiCommonRunningStatusService;
import net.wanji.utc.task.SignalStatus4StaticSchemeTask;
import net.wanji.utc.util.ListUtil;
import net.wanji.utc.util.RedisUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -153,6 +151,16 @@ public class SignalStatusServiceImpl implements SignalStatusService {
return resList;
}
@Override
public List<LightsStatusVO> lightStatus4StaticScheme() throws Exception {
Map<String, LightsStatusVO> runningStateInfoCache = SignalStatus4StaticSchemeTask.runningStateInfoCache;
List<LightsStatusVO> result = new ArrayList<>();
for (Map.Entry<String, LightsStatusVO> entry : runningStateInfoCache.entrySet()) {
result.add(entry.getValue());
}
return result;
}
private List<BaseCrossInfo> getBaseCrossInfoList(BasicEnum.ManufacturerEnum manufacturerEnum) {
// 查询路口信息
ManufacturerInfoPO manufacturerInfoPO = manufacturerInfoMapper.selectByCode(manufacturerEnum.getCode());
......@@ -181,7 +189,8 @@ public class SignalStatusServiceImpl implements SignalStatusService {
for (CrossLightsStatusHistPO crossLightsStatusHistPO : crossLightsStatusHistPOS) {
String lightsStatusJson = crossLightsStatusHistPO.getLightsStatusJson();
ObjectMapper instance = JacksonUtils.getInstance();
List<LightsStatusVO> lightsStatusVOS = instance.readValue(lightsStatusJson, new TypeReference<List<LightsStatusVO>>() {});
List<LightsStatusVO> lightsStatusVOS = instance.readValue(lightsStatusJson, new TypeReference<List<LightsStatusVO>>() {
});
if (!CollectionUtils.isEmpty(lightsStatusVOS)) {
LightsStatusVO lightsStatusVO = lightsStatusVOS.get(0);
result.add(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