Commit f2689c4a authored by duanruiming's avatar duanruiming

[add] 策略控制优化

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