Commit 4b0f54cf authored by duanruiming's avatar duanruiming

[add] 优化绿波干线优化时间

parent fecb00e9
...@@ -461,25 +461,51 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -461,25 +461,51 @@ public class StrategyControlServiceImpl implements StrategyControlService {
} }
} }
// 绿波优化次数 // 绿波优化次数
long current = System.currentTimeMillis();
int greenOptCount = 0; int greenOptCount = 0;
int greenOptTime = 0; int greenOptTime = 0;
long endTime = current;
LambdaQueryWrapper<StrategyGreenOptHistEntity> greenQuery = new LambdaQueryWrapper<>(); LambdaQueryWrapper<StrategyGreenOptHistEntity> greenQuery = new LambdaQueryWrapper<>();
greenQuery.ge(StrategyGreenOptHistEntity::getControlTime, midNight); greenQuery.ge(StrategyGreenOptHistEntity::getControlTime, midNight);
greenQuery.ge(StrategyGreenOptHistEntity::getResponseCode, 200); greenQuery.eq(StrategyGreenOptHistEntity::getResponseCode, 200);
greenQuery.orderByDesc(StrategyGreenOptHistEntity::getControlTime);
List<StrategyGreenOptHistEntity> entities = strategyGreenOptHistMapper.selectList(greenQuery); List<StrategyGreenOptHistEntity> entities = strategyGreenOptHistMapper.selectList(greenQuery);
if (!CollectionUtils.isEmpty(entities)) { if (!CollectionUtils.isEmpty(entities)) {
for (StrategyGreenOptHistEntity entity : entities) { Map<Integer, List<StrategyGreenOptHistEntity>> listMap = entities.stream().collect(Collectors.groupingBy(StrategyGreenOptHistEntity::getGreenId));
String controlTime = entity.getControlTime(); for (Map.Entry<Integer, List<StrategyGreenOptHistEntity>> entry : listMap.entrySet()) {
Integer controlMethod = entity.getControlMethod(); Integer greenId = entry.getKey();
if (!Objects.equals(-1, controlMethod)) { List<StrategyGreenOptHistEntity> value = entry.getValue();
for (StrategyGreenOptHistEntity entity : value) {
if (Objects.equals(0 , entity.getDirType())) {
continue;
}
String controlTime = entity.getControlTime();
Integer controlMethod = entity.getControlMethod();
Date parse = DateUtil.parse(controlTime, "yyyy-MM-dd HH:mm:ss"); Date parse = DateUtil.parse(controlTime, "yyyy-MM-dd HH:mm:ss");
greenOptTime += entity.getControlDuration(); long controlLong = parse.getTime();
greenOptCount += 1; // 优化次数:去掉-1, 剩余记录总数
long temp = endTime;
if (Objects.equals(-1, controlMethod)) {
endTime = parse.getTime();
continue;
} else {
greenOptCount += 1;
// 最新数据与当前数据比较,小于30min
if (endTime - controlLong < 30 * 60 * 1000) {
temp = endTime;
endTime = current;
} else {
temp = endTime;
endTime = controlLong;
}
}
int offset = (int) ((temp - controlLong) / 1000);
greenOptTime += offset;
} }
} }
} }
strategyOptTimesVO.setCount(optCount + greenOptCount / 2); strategyOptTimesVO.setCount(optCount + greenOptCount);
strategyOptTimesVO.setTimes(optTime + greenOptTime / 2); strategyOptTimesVO.setTimes(optTime + greenOptTime);
return JsonViewObject.newInstance().success(strategyOptTimesVO); return JsonViewObject.newInstance().success(strategyOptTimesVO);
} }
......
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