From d335d0f179612cbd68bfb48b8a91dc315f268752 Mon Sep 17 00:00:00 2001 From: gjh <1421wake> Date: Tue, 4 Mar 2025 14:15:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BA=E8=8C=83=E9=A1=B9=E7=9B=AE=E9=AA=8C?= =?UTF-8?q?=E6=94=B6=E6=97=B6=E9=97=B4=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../huzhou/controller/TestController.java | 106 ++++++++++++++++-- .../impl/HuzhouPlaninfoServiceImpl.java | 41 ++++--- 2 files changed, 127 insertions(+), 20 deletions(-) diff --git a/huzhou/src/main/java/com/easy/admin/modules/huzhou/controller/TestController.java b/huzhou/src/main/java/com/easy/admin/modules/huzhou/controller/TestController.java index 41e664f..64ddfb4 100644 --- a/huzhou/src/main/java/com/easy/admin/modules/huzhou/controller/TestController.java +++ b/huzhou/src/main/java/com/easy/admin/modules/huzhou/controller/TestController.java @@ -1,24 +1,38 @@ package com.easy.admin.modules.huzhou.controller; import cn.hutool.core.util.StrUtil; +import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.easy.admin.auth.model.SysUser; import com.easy.admin.common.api.vo.Result; import com.easy.admin.common.core.exception.EasyException; import com.easy.admin.modules.huzhou.dao.HuzhouProjectinfoMoneyMapper; import com.easy.admin.modules.huzhou.entity.HuzhouContractinfo; +import com.easy.admin.modules.huzhou.entity.HuzhouPlaninfo; import com.easy.admin.modules.huzhou.entity.HuzhouProjectinfoMoney; +import com.easy.admin.modules.huzhou.entity.ProjectManager; +import com.easy.admin.modules.huzhou.listener.ProjectManagerListener; import com.easy.admin.modules.huzhou.service.IHuzhouContractinfoService; +import com.easy.admin.modules.huzhou.service.IHuzhouPlaninfoHistoryService; +import com.easy.admin.modules.huzhou.service.IHuzhouPlaninfoService; +import com.easy.admin.modules.huzhou.service.IHuzhouProjectinfoService; import com.easy.admin.util.ShiroUtil; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.SerializationUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; -import java.util.List; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; /** * @Author gejunhao @@ -33,6 +47,12 @@ public class TestController { private IHuzhouContractinfoService contractinfoService; @Autowired private HuzhouProjectinfoMoneyMapper projectinfoMoneyMapper; + @Autowired + private IHuzhouPlaninfoService planinfoService; + @Autowired + private IHuzhouPlaninfoHistoryService planinfoHistoryService; + @Autowired + private IHuzhouProjectinfoService projectinfoService; @GetMapping("/getContractInfo") public Result getProjectContractInfo(String projectId,String taskName){ @@ -41,12 +61,6 @@ public class TestController { LambdaQueryWrapper qw = new LambdaQueryWrapper<>(); qw.eq(HuzhouContractinfo::getProjectId, projectId) .eq(HuzhouContractinfo::getFlag, taskName.equals("合同签订") ? "计划" : "实际"); - // 2.查询数据库中符合条件的合同信息 -// List dbList = contractinfoService.list(qw); -// boolean flag = contractinfoService.removeBatchByIds(dbList); -// if (flag){ -// log.info("删除原有数据成功!---{}",dbList); -// } SysUser currentUser = ShiroUtil.getCurrentUser(); currentUser.getId(); return Result.OK(currentUser.getId()); @@ -120,4 +134,82 @@ public class TestController { return Result.OK(flag); } + + + @PostMapping("/updatePlanByExcel") + public void upload(MultipartFile multipartFile, String projectId) throws Exception { + //解析项目计划文件 + HashMap hashMap = planinfoService.getPlanInfoListFromFile(multipartFile, projectId); + //res是true 表示项目计划文件没有问题,如果是false说明文件有问题,需要抛出异常 + boolean res = (boolean) hashMap.get("res"); + if (!res) { + throw new EasyException((String) hashMap.get("msg")); + } + List huzhouPlaninfoArrayList = (ArrayList) hashMap.get("arr"); + + HuzhouPlaninfo targetElement = huzhouPlaninfoArrayList.stream() + .filter(planInfo -> "示范项目验收阶段".equals(planInfo.getTaskName())) + .findFirst() + .orElse(null); // 如果没有找到符合条件的元素,则返回null + + if (targetElement != null) { + Date scheduledEndTime = targetElement.getScheduledEndTime(); + // 创建一个 Calendar 实例,并设置为 2025年12月31日 + Calendar calendar = Calendar.getInstance(); + // 设置时间为当天的最后一秒 + calendar.set(2025, Calendar.DECEMBER, 31, 23, 59, 59); + // 获取对应的时间 + Date deadline = calendar.getTime(); + + // 比较 scheduledEndTime 是否晚于 deadline + if (scheduledEndTime.after(deadline)) { + throw new EasyException("示范项目结束时间校验错误,请修改!"); + } else { + log.info("示范项目验收时间校验正确"); + } + } + + } + + private void updatePlanForShenPiAndFinished(List 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 大等于 1.7 的记录 + 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()); + } + } + } 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 6c4d270..a1e644a 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,14 +838,6 @@ 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); @@ -855,6 +847,10 @@ public class HuzhouPlaninfoServiceImpl extends ServiceImpl huzhouPlaninfoArrayList = (ArrayList) hashMap.get("arr"); + // 校验最后日期不能晚于25年底 + checkExcelPlanLastLevelTime(huzhouPlaninfoArrayList); + log.info("示范项目验收时间校验正确"); + // 深克隆备份Excel重点计划以供后续做差集操作 List excelList = SerializationUtils.clone((ArrayList) hashMap.get("arr")); // 未完成的项目则可以修改 @@ -877,12 +873,9 @@ public class HuzhouPlaninfoServiceImpl extends ServiceImpl "项目立项阶段".equals(item.getTaskName())); - - for (HuzhouPlaninfo huzhouPlaninfo : huzhouPlaninfoArrayList) { - log.info("待插入的计划信息为{}",huzhouPlaninfo.getTaskLevel()); - } + //批量新增 saveBatch(huzhouPlaninfoArrayList); //创建流程 @@ -926,6 +919,28 @@ public class HuzhouPlaninfoServiceImpl extends ServiceImpl huzhouPlaninfoArrayList) { + HuzhouPlaninfo targetElement = huzhouPlaninfoArrayList.stream() + .filter(planInfo -> "示范项目验收阶段".equals(planInfo.getTaskName())) + .findFirst() + .orElse(null); // 如果没有找到符合条件的元素,则返回null + + if (targetElement != null) { + Date scheduledEndTime = targetElement.getScheduledEndTime(); + // 创建一个 Calendar 实例,并设置为 2025年12月31日 + Calendar calendar = Calendar.getInstance(); + // 设置时间为当天的最后一秒 + calendar.set(2025, Calendar.DECEMBER, 31, 23, 59, 59); + // 获取对应的时间 + Date deadline = calendar.getTime(); + + // 比较 scheduledEndTime 是否晚于 deadline + if (scheduledEndTime.after(deadline)) { + throw new EasyException("示范项目结束时间校验错误,请修改!"); + } + } + } + private void updatePlanForShenPiAndFinished(List huzhouPlaninfoArrayList, List excelList, List planinfoHistory) { // 计算差集 Set keysFromHuzhouPlaninfoArrayList = huzhouPlaninfoArrayList.stream()