Commit 702b03ce authored by hanbing's avatar hanbing

[update] 诊断优化,优化日志根据相位号去重

parent fad4219a
......@@ -44,11 +44,14 @@ import net.wanji.opt.vo.SchemeOptVO;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeSet;
import java.util.stream.Collectors;
/**
......@@ -159,6 +162,10 @@ public class DiagnoServiceImpl implements DiagnoService {
schemeOptVO.setCrossId(crossId);
// 选择数据批次时间最大的记录
List<CrossSchemeOptLogPO> maxList = crossSchemeOptLogMapper.selectMaxByCrossId(crossId);
// 根据相位去重
TreeSet<CrossSchemeOptLogPO> collect = maxList.stream()
.collect(Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing(CrossSchemeOptLogPO::getPhaseNo))));
CrossSchemeOptLogPO crossSchemeOptLogPO = maxList.get(0);
String optType = crossSchemeOptLogPO.getOptType();
schemeOptVO.setOptType(Integer.parseInt(optType));
......@@ -168,7 +175,7 @@ public class DiagnoServiceImpl implements DiagnoService {
schemeOptVO.setSchemeId(crossSchemePO.getId());
schemeOptVO.setOffset(crossSchemeOptLogPO.getOffset());
// 构造调整时间列表
List<SchemeOptVO.PhaseOptTime> phaseOptTimeList = buildPhaseOptTimeList(maxList);
List<SchemeOptVO.PhaseOptTime> phaseOptTimeList = buildPhaseOptTimeList(collect);
schemeOptVO.setPhaseOptTimeList(phaseOptTimeList);
return schemeOptVO;
}
......@@ -315,7 +322,7 @@ public class DiagnoServiceImpl implements DiagnoService {
try {
crossSchemeOptLogPO = maxList.get(0);
} catch (IndexOutOfBoundsException e) {
throw new RuntimeException("优化日志数据库中无此路口记录");
throw new RuntimeException("没有该路口优化日志数据");
}
String dataExtend = crossSchemeOptLogPO.getDataExtend();
OptDataExtend optDataExtend = gson.fromJson(dataExtend, OptDataExtend.class);
......@@ -428,7 +435,8 @@ public class DiagnoServiceImpl implements DiagnoService {
}
private List<SchemeOptVO.PhaseOptTime> buildPhaseOptTimeList(List<CrossSchemeOptLogPO> crossSchemeOptLogPOList) {
private List<SchemeOptVO.PhaseOptTime> buildPhaseOptTimeList(
Collection<CrossSchemeOptLogPO> crossSchemeOptLogPOList) {
List<SchemeOptVO.PhaseOptTime> phaseOptTimeList = new ArrayList<>();
for (CrossSchemeOptLogPO crossSchemeOptLogPO : crossSchemeOptLogPOList) {
SchemeOptVO.PhaseOptTime phaseOptTime = new SchemeOptVO.PhaseOptTime();
......
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