diff --git a/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/impl/HuzhouPlaninfoServiceImpl.java b/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/impl/HuzhouPlaninfoServiceImpl.java index a9750d7..a7821f8 100644 --- a/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/impl/HuzhouPlaninfoServiceImpl.java +++ b/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/impl/HuzhouPlaninfoServiceImpl.java @@ -838,7 +838,16 @@ public class HuzhouPlaninfoServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(HuzhouPlaninfo::getProjectId,projectid); + queryWrapper.eq(HuzhouPlaninfo::getTaskName,"项目立项阶段"); + queryWrapper.eq(HuzhouPlaninfo::getIsfinish,"2"); + if ( this.list(queryWrapper).size()<1){ + throw new EasyException("项目立项阶段未完成,无法修改项目计划!"); + } + + //解析项目计划文件 HashMap hashMap = getPlanInfoListFromFile(multipartFile, projectid); //res是true 表示项目计划文件没有问题,如果是false说明文件有问题,需要抛出异常 boolean res = (boolean) hashMap.get("res"); @@ -847,6 +856,7 @@ public class HuzhouPlaninfoServiceImpl extends ServiceImpl excelList =(ArrayList) hashMap.get("arr"); List huzhouPlaninfoArrayList = (ArrayList) hashMap.get("arr"); + // 深克隆备份Excel重点计划以供后续做差集操作 List excelList = SerializationUtils.clone((ArrayList) hashMap.get("arr")); String isAllow = IsAllowModifyPlaninfo(projectid, huzhouPlaninfoArrayList); if (!"1".equals(isAllow)) { @@ -858,45 +868,9 @@ public class HuzhouPlaninfoServiceImpl extends ServiceImpl planinfoHistory = getListByProjectId(projectid); planinfoHistoryService.savePlanInfoToHistory(planinfoHistory); // 获取审批中和已完成的计划列表进行更新操作 - // 计算差集 - Set keysFromHuzhouPlaninfoArrayList = huzhouPlaninfoArrayList.stream() - .map(item ->item.getProjectId() + "-" + item.getTaskLevel()) - .collect(Collectors.toSet()); - - List tmpDifList = planinfoHistory.stream() - .filter(item -> !keysFromHuzhouPlaninfoArrayList.contains(item.getProjectId() + "-" + item.getTaskLevel())) - .filter(item -> { - try { - // 过滤条件:只保留 taskLevel 大于 2 的记录 - BigDecimal taskLevel = new BigDecimal(item.getTaskLevel()); - return taskLevel.compareTo(BigDecimal.valueOf(1.7)) >= 0; - } catch (NumberFormatException e) { - // 如果转换失败,可以选择处理异常或忽略这条记录 - throw new EasyException("无法将 taskLevel 转换为数字: " + item.getTaskLevel()); - } - }) - .collect(Collectors.toList()); - - // isFinish为0表示未开始,1审批中,2表示已完成 scheduledStartTime scheduledEndTime - Map excelMap = excelList.stream() - .collect(Collectors.toMap( - item -> item.getTaskLevel(), - item -> item - )); - // 遍历 tmpDifList,并根据 projectId 和 taskLevel 查找对应的 excelItem - tmpDifList.forEach(tmpItem -> { - String key = tmpItem.getTaskLevel(); - Optional.ofNullable(excelMap.get(key)).ifPresent(excelItem -> { - tmpItem.setScheduledEndTime(excelItem.getScheduledEndTime()); - tmpItem.setScheduledStartTime(excelItem.getScheduledStartTime()); - }); - }); + updatePlanForShenPiAndFinished(huzhouPlaninfoArrayList, excelList, planinfoHistory); - huzhouPlaninfoArrayList.addAll(tmpDifList); - for (HuzhouPlaninfo huzhouPlaninfo : huzhouPlaninfoArrayList) { - log.info("修改后的计划信息为{}",huzhouPlaninfo.getTaskLevel()); - } - //删除未开始 已完成 和审批中且taskLevel>2的项目 + //删除未开始 已完成 和审批中且taskLevel >= 1.7的项目 removeByProjectId(projectid); //将之前的分组id修改为最新的分组id LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); @@ -905,6 +879,7 @@ public class HuzhouPlaninfoServiceImpl extends ServiceImpl huzhouPlaninfoArrayList, List excelList, List planinfoHistory) { + // 计算差集 + Set keysFromHuzhouPlaninfoArrayList = huzhouPlaninfoArrayList.stream() + .map(item ->item.getProjectId() + "-" + item.getTaskLevel()) + .collect(Collectors.toSet()); + + List tmpDifList = planinfoHistory.stream() + .filter(item -> !keysFromHuzhouPlaninfoArrayList.contains(item.getProjectId() + "-" + item.getTaskLevel())) + .filter(item -> { + try { + // 过滤条件:只保留 taskLevel 大于 2 的记录 + BigDecimal taskLevel = new BigDecimal(item.getTaskLevel()); + return taskLevel.compareTo(BigDecimal.valueOf(1.7)) >= 0; + } catch (NumberFormatException e) { + // 如果转换失败,可以选择处理异常或忽略这条记录 + throw new EasyException("无法将 taskLevel 转换为数字: " + item.getTaskLevel()); + } + }) + .collect(Collectors.toList()); + + // isFinish为0表示未开始,1审批中,2表示已完成 scheduledStartTime scheduledEndTime + Map excelMap = excelList.stream() + .collect(Collectors.toMap( + item -> item.getTaskLevel(), + item -> item + )); + // 遍历 tmpDifList,并根据 projectId 和 taskLevel 查找对应的 excelItem + tmpDifList.forEach(tmpItem -> { + String key = tmpItem.getTaskLevel(); + Optional.ofNullable(excelMap.get(key)).ifPresent(excelItem -> { + tmpItem.setScheduledEndTime(excelItem.getScheduledEndTime()); + tmpItem.setScheduledStartTime(excelItem.getScheduledStartTime()); + }); + }); + + huzhouPlaninfoArrayList.addAll(tmpDifList); +// for (HuzhouPlaninfo huzhouPlaninfo : huzhouPlaninfoArrayList) { +// log.info("修改后的计划信息为{}",huzhouPlaninfo.getTaskLevel()); +// } + } + @Override public void downloadPlanInfo(HttpServletResponse response, String projectid) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();