优化这段代码,将for/if的数量减少到三个,且逻辑不能改变 public List<IpmActPlanTable> queryYearPlanActList(String ogfId, String operationZone, String platformCode, String wellId, String startTime, String endTime) { // 查询年初作业计划数据 List<IpmActPlanTable> ipmActPlanTables1 = programmeManagementMapper.queryYearPlanActList(ogfId, operationZone, platformCode, wellId, startTime, endTime); // 查询预警信息 List<IpmActPlanTable> ipmActPlanTables = this.queryPlanVarInfo(startTime, endTime, platformCode); for (IpmActPlanTable item : ipmActPlanTables1) { // 格式化日期 item.setPlanStartDate(item.getPlanStartDate().substring(0, 10)); item.setPlanEffectDate(item.getPlanEffectDate().substring(0, 10)); item.setPlanEndDate(item.getPlanEndDate().substring(0, 10)); // 循环预警信息数据 如果年初计划中井数据在预警信息数据中存在 则设置label if (ipmActPlanTables.size() != 0) { for (IpmActPlanTable ita : ipmActPlanTables) { if (ita.getWellId().equals(item.getWellId())) { item.setLabel("1"); } } } } return ipmActPlanTables1; }
时间: 2024-02-14 09:27:38 浏览: 57
public List<IpmActPlanTable> queryYearPlanActList(String ogfId, String operationZone, String platformCode, String wellId, String startTime, String endTime) {
// 查询年初作业计划数据
List<IpmActPlanTable> ipmActPlanTables1 = programmeManagementMapper.queryYearPlanActList(ogfId, operationZone, platformCode, wellId, startTime, endTime);
// 查询预警信息
List<IpmActPlanTable> ipmActPlanTables = this.queryPlanVarInfo(startTime, endTime, platformCode);
// 格式化日期
for (IpmActPlanTable item : ipmActPlanTables1) {
item.setPlanStartDate(item.getPlanStartDate().substring(0, 10));
item.setPlanEffectDate(item.getPlanEffectDate().substring(0, 10));
item.setPlanEndDate(item.getPlanEndDate().substring(0, 10));
}
// 循环预警信息数据,如果年初计划中井数据在预警信息数据中存在,则设置label
if (!ipmActPlanTables.isEmpty()) {
Set<String> wellIds = new HashSet<>();
for (IpmActPlanTable ita : ipmActPlanTables) {
wellIds.add(ita.getWellId());
}
for (IpmActPlanTable item : ipmActPlanTables1) {
if (wellIds.contains(item.getWellId())) {
item.setLabel("1");
}
}
}
return ipmActPlanTables1;
}
阅读全文