Commit 35bb34be authored by zhouleilei's avatar zhouleilei

解决信号机同步时,车道数据重复问题

parent 8ebfab8f
...@@ -479,6 +479,8 @@ public class PlanSendServiceImpl implements PlanSendService { ...@@ -479,6 +479,8 @@ public class PlanSendServiceImpl implements PlanSendService {
} }
} }
} }
//解决车道重复问题
crossLaneLightsPOS = distinctLaneLights(crossLaneLightsPOS,crossLightsPOS);
baseCrossLaneLightsMapper.deleteByCrossId(crossId); baseCrossLaneLightsMapper.deleteByCrossId(crossId);
baseCrossLaneLightsMapper.insertBatch(crossLaneLightsPOS); baseCrossLaneLightsMapper.insertBatch(crossLaneLightsPOS);
...@@ -517,6 +519,73 @@ public class PlanSendServiceImpl implements PlanSendService { ...@@ -517,6 +519,73 @@ public class PlanSendServiceImpl implements PlanSendService {
return jsonViewObject.success(); return jsonViewObject.success();
} }
/**
* @Description 解决车道重复问题
* @Param [crossLaneLightsPOS, crossLightsPOS]
* @return java.util.List<net.wanji.databus.po.CrossLaneLightsPO>
**/
private List<CrossLaneLightsPO> distinctLaneLights(List<CrossLaneLightsPO> crossLaneLightsPOS,List<BaseCrossLightsPO> crossLightsPOS){
if (CollectionUtil.isEmpty(crossLightsPOS) || CollectionUtil.isEmpty(crossLaneLightsPOS)){
return crossLaneLightsPOS;
}
//存储灯组id和类型
Map<Integer, Integer> lightMap = new HashMap<>();
for (BaseCrossLightsPO crossLightsPO : crossLightsPOS) {
lightMap.put(crossLightsPO.getId(),crossLightsPO.getType());
}
List<CrossLaneLightsPO> resultList = new ArrayList<>();
//根据车道id分组
Map<String, List<CrossLaneLightsPO>> laneMap = crossLaneLightsPOS.stream().collect(Collectors.groupingBy(CrossLaneLightsPO::getLaneId));
Set<String> lineIds = laneMap.keySet();
for (String lineId : lineIds) {
List<CrossLaneLightsPO> laneList = laneMap.get(lineId);
//判断是否重复
if (laneList.size() > 1){
CrossLaneLightsPO result = null;
CrossLaneLightsPO type2Candidate = null;
CrossLaneLightsPO type5Candidate = null;
CrossLaneLightsPO minTypeCandidate = null;
for (CrossLaneLightsPO po : laneList) {
int type = lightMap.get(po.getLightsId());
if (type == 2) {
if (type2Candidate == null) {
type2Candidate = po;
}
} else if (type == 5) {
// 仅当type2不存在时,才考虑type5
if (type2Candidate == null && type5Candidate == null) {
type5Candidate = po;
}
} else {
// 仅当type2和type5都不存在时,才比较最小type
if (type2Candidate == null && type5Candidate == null) {
if (minTypeCandidate == null || type < lightMap.get(minTypeCandidate.getLightsId())) {
minTypeCandidate = po;
}
}
}
}
// 确定最终结果
if (type2Candidate != null) {
result = type2Candidate;
} else if (type5Candidate != null) {
result = type5Candidate;
} else {
result = minTypeCandidate;
}
resultList.add(result);
}else {
resultList.addAll(laneList);
}
}
resultList = resultList.stream().sorted(Comparator.comparing(CrossLaneLightsPO::getLaneId)).collect(Collectors.toList());
return resultList;
}
public void syncSchedules(String crossId, SchemePhaseLightsVO schemePhaseLightsVO) throws Exception { public void syncSchedules(String crossId, SchemePhaseLightsVO schemePhaseLightsVO) throws Exception {
ObjectMapper mapper = JacksonUtils.getInstance(); ObjectMapper mapper = JacksonUtils.getInstance();
// 计划信息 // 计划信息
......
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