Commit f2689c4a authored by duanruiming's avatar duanruiming

[add] 策略控制优化

parent 5f9303d4
......@@ -331,7 +331,12 @@ public class StrategyControlServiceImpl implements StrategyControlService {
List<StrategyControlDataEntity> results = new ArrayList<>();
List<StrategyControlDataEntity> entities = getCurrentStrateInfoList(type);
List<StrategyControlDataEntity> runList = entities.stream().filter(entity -> Objects.equals(1, entity.getStatus())).collect(Collectors.toList());
Map<String, StrategyControlDataEntity> map = runList.stream().collect(Collectors.toMap(StrategyControlDataEntity::getBizId, entity -> entity));
Map<String, StrategyControlDataEntity> map = runList.stream()
.collect(Collectors.toMap(
StrategyControlDataEntity::getBizId,
entity -> entity,
(existing, replacement) -> existing.getId() > replacement.getId() ? existing : replacement
));
// 路口
if (Objects.equals(0, type)) {
List<AbnormalCrossListVO> abnormalCrossListVOS = crossDataRealtimeMapper.selectAbnormalCross(null, null, null);
......@@ -461,8 +466,9 @@ public class StrategyControlServiceImpl implements StrategyControlService {
LambdaQueryWrapper<StrategyControlDataEntity> queryWrapper = new LambdaQueryWrapper<>();
Date current = new Date();
queryWrapper.eq(StrategyControlDataEntity::getBizType, type);
queryWrapper.ge(StrategyControlDataEntity::getScheduleStart, current);
queryWrapper.le(StrategyControlDataEntity::getScheduleEnd, current);
queryWrapper.le(StrategyControlDataEntity::getScheduleStart, current);
queryWrapper.ge(StrategyControlDataEntity::getScheduleEnd, current);
queryWrapper.orderByAsc(StrategyControlDataEntity::getId);
List<StrategyControlDataEntity> entities = strategyControlInfoMapper.selectList(queryWrapper);
List<StrategyControlDataEntity> results = new ArrayList<>(entities.size());
for (StrategyControlDataEntity entity : entities) {
......@@ -587,7 +593,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
}
}
results.sort(Comparator.comparing(StrategyControlDataExt::getStatus).reversed());
results.stream().distinct().sorted(Comparator.comparing(StrategyControlDataExt::getStatus).reversed()).collect(Collectors.toList());
return results;
}
......@@ -755,6 +761,9 @@ public class StrategyControlServiceImpl implements StrategyControlService {
ObjectMapper mapper = JacksonUtils.getInstance();
List<StrategyControlDetailList.ExecutePlan> plans = list.getPlans();
if (!CollectionUtils.isEmpty(plans)) {
StrategyControlDetailList.ExecutePlan executePlan = plans.get(0);
LambdaQueryWrapper<StrategyPlanInfoEntity> planDel = new LambdaQueryWrapper<>();
planDel.eq(StrategyPlanInfoEntity::getCrossId, executePlan.getCrossId());
for (StrategyControlDetailList.ExecutePlan plan : plans) {
StrategyPlanInfoEntity planInfoEntity = new StrategyPlanInfoEntity();
planInfoEntity.setPlanId(plan.getPlanId());
......@@ -765,30 +774,29 @@ public class StrategyControlServiceImpl implements StrategyControlService {
planInfoEntity.setCompany(plan.getCompany());
planInfoEntity.setName(plan.getName());
planInfoEntity.setPlanDetails(mapper.writeValueAsString(plan.getPlanDetails()));
LambdaQueryWrapper<StrategyPlanInfoEntity> planDel = new LambdaQueryWrapper<>();
planDel.eq(StrategyPlanInfoEntity::getCrossId, plan.getCrossId());
planDel.eq(StrategyPlanInfoEntity::getPlanId, plan.getPlanId());
strategyPlanInfoMapper.delete(planDel);
strategyPlanInfoMapper.insert(planInfoEntity);
}
}
List<StrategyControlDetailList.DailyPlan> dailyPlans = list.getDailyPlans();
for (StrategyControlDetailList.DailyPlan dailyPlan : dailyPlans) {
Integer dailyPlanId = dailyPlan.getDailyPlanId();
String crossId = dailyPlan.getCrossId();
List<StrategyControlDetailList.DailyPlan.DailyPlanDetail> dailyPlanDetails = dailyPlan.getDailyPlanDetails();
StrategyDailyPlanInfoEntity dailyPlanInfoEntity = new StrategyDailyPlanInfoEntity();
dailyPlanInfoEntity.setCrossId(crossId);
dailyPlanInfoEntity.setDailyPlanId(dailyPlanId);
dailyPlanInfoEntity.setName(dailyPlan.getName());
LambdaQueryWrapper<StrategyDailyPlanInfoEntity> delete = new LambdaQueryWrapper<>();
delete.eq(StrategyDailyPlanInfoEntity::getCrossId, crossId);
delete.eq(StrategyDailyPlanInfoEntity::getDailyPlanId, dailyPlanId);
strategyDailyPlanInfoMapper.delete(delete);
dailyPlanInfoEntity.setDailyPlanDetails(mapper.writeValueAsString(dailyPlanDetails));
strategyDailyPlanInfoMapper.insert(dailyPlanInfoEntity);
}
if (!CollectionUtils.isEmpty(dailyPlans)) {
StrategyControlDetailList.DailyPlan dailyPlan1 = dailyPlans.get(0);
LambdaQueryWrapper<StrategyDailyPlanInfoEntity> delete = new LambdaQueryWrapper<>();
delete.eq(StrategyDailyPlanInfoEntity::getCrossId, dailyPlan1.getCrossId());
strategyDailyPlanInfoMapper.delete(delete);
for (StrategyControlDetailList.DailyPlan dailyPlan : dailyPlans) {
Integer dailyPlanId = dailyPlan.getDailyPlanId();
String crossId = dailyPlan.getCrossId();
List<StrategyControlDetailList.DailyPlan.DailyPlanDetail> dailyPlanDetails = dailyPlan.getDailyPlanDetails();
StrategyDailyPlanInfoEntity dailyPlanInfoEntity = new StrategyDailyPlanInfoEntity();
dailyPlanInfoEntity.setCrossId(crossId);
dailyPlanInfoEntity.setDailyPlanId(dailyPlanId);
dailyPlanInfoEntity.setName(dailyPlan.getName());
dailyPlanInfoEntity.setDailyPlanDetails(mapper.writeValueAsString(dailyPlanDetails));
strategyDailyPlanInfoMapper.insert(dailyPlanInfoEntity);
}
}
}
StrategyControlVO strategyControlVO = convertDataList(list);
StrategyControlReq req = convertReq(strategyControlVO);
......
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