From b30f4c40c77a940a2a749a676e901787f55040b0 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期五, 06 十一月 2026 11:48:25 +0800
Subject: [PATCH] 流程优化

---
 src/main/java/com/ruoyi/projectManagement/service/impl/handle/InfoHandleService.java |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/ruoyi/projectManagement/service/impl/handle/InfoHandleService.java b/src/main/java/com/ruoyi/projectManagement/service/impl/handle/InfoHandleService.java
index a5f2ff4..4592366 100644
--- a/src/main/java/com/ruoyi/projectManagement/service/impl/handle/InfoHandleService.java
+++ b/src/main/java/com/ruoyi/projectManagement/service/impl/handle/InfoHandleService.java
@@ -9,6 +9,8 @@
 import com.ruoyi.basic.service.CustomerFollowUpFileService;
 import com.ruoyi.common.enums.PlanStageEnum;
 import com.ruoyi.common.enums.ReviewStatusEnum;
+import com.ruoyi.common.enums.IsDeleteEnum;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.projectManagement.dto.InfoStageDto;
 import com.ruoyi.projectManagement.dto.PlanStageDto;
 import com.ruoyi.projectManagement.dto.SaveInfoDto;
@@ -18,11 +20,13 @@
 import com.ruoyi.projectManagement.service.PlanService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Component;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
 import org.springframework.transaction.annotation.Transactional;
 
 import jakarta.validation.constraints.NotNull;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 import java.util.stream.Collectors;
 
@@ -44,9 +48,17 @@
 
     private final CustomerFollowUpFileService customerFollowUpFileService;
 
+    private final NamedParameterJdbcTemplate jdbc;
+
     @Transactional(rollbackFor = Exception.class)
     public Long save(@NotNull SaveInfoDto saveInfoDto) {
         Info info = BeanUtil.copyProperties(saveInfoDto, Info.class);
+
+        if (info.getPlanStartTime() != null && info.getPlanEndTime() != null
+                && info.getPlanEndTime().isBefore(info.getPlanStartTime())) {
+            throw new ServiceException("棰勮缁撴潫鏃堕棿涓嶈兘鏃╀簬棰勮寮�濮嬫椂闂�");
+        }
+        bindProjectCategory(info);
 
         // 闄勪欢鐗规畩澶勭悊
         String attachmentIds = StrUtil.join(",", Optional.ofNullable(saveInfoDto.getAttachmentIds()).orElse(Collections.emptyList()));
@@ -58,16 +70,45 @@
         }
         info.setTeam(saveInfoDto.getTeamList());
         if (info.getId() == null) {
-            // 鐢熸垚瀵瑰簲鐨勯樁娈靛叧绯绘暟鎹�
-            info.setPlanStage(getPlanStageList(info.getProjectManagementPlanId()));
+            // 鏂伴」鐩樁娈电敱 project_management_phase 鐙珛缁存姢锛屼笉鍐嶇敓鎴愭棫璁″垝妯℃澘闃舵銆�
+            info.setPlanStage(Collections.emptyList());
+            if (StrUtil.isBlank(info.getCurrentPhase())) {
+                info.setCurrentPhase("鏈紑濮�");
+            }
             // 鎻掑叆榛樿鐘舵��
             info.setStatus(PlanStageEnum.TO_BEGIN.getCode());
             info.setReviewStatus(ReviewStatusEnum.PENDING_REVIEW.getCode());
             infoMapper.insert(info);
         } else {
+            Info existing = infoMapper.selectById(info.getId());
+            if (existing == null || Integer.valueOf(IsDeleteEnum.DELETED.getCode()).equals(existing.getIsDelete())) {
+                throw new ServiceException("椤圭洰涓嶅瓨鍦ㄦ垨宸插垹闄�");
+            }
+            if (!StrUtil.isBlank(existing.getCurrentPhase()) && !"鏈紑濮�".equals(existing.getCurrentPhase())) {
+                throw new ServiceException("椤圭洰寮�濮嬪悗锛岄」鐩熀鏈俊鎭�佽礋璐d汉鍜岄」鐩粡鐞嗗潎涓嶅彲淇敼");
+            }
             infoMapper.updateById(info);
         }
         return info.getId();
+    }
+
+    private void bindProjectCategory(Info info) {
+        if (info.getProjectCategoryId() != null) {
+            List<String> names = jdbc.queryForList("""
+                    select category_name from project_management_category
+                    where id=:id and is_deleted=0
+                    """, Map.of("id", info.getProjectCategoryId()), String.class);
+            if (names.isEmpty()) throw new ServiceException("椤圭洰鍒嗙被涓嶅瓨鍦ㄦ垨宸插垹闄�");
+            info.setProjectClassification(names.getFirst());
+            return;
+        }
+        if (!StrUtil.isBlank(info.getProjectClassification())) {
+            List<Long> ids = jdbc.queryForList("""
+                    select id from project_management_category
+                    where category_name=:name and is_deleted=0 order by id
+                    """, Map.of("name", info.getProjectClassification().trim()), Long.class);
+            if (ids.size() == 1) info.setProjectCategoryId(ids.getFirst());
+        }
     }
 
     @Transactional
@@ -77,6 +118,9 @@
 
     public SaveInfoDto getInfoById(@NotNull Long id) {
         Info info = infoMapper.selectById(id);
+        if (info == null || Integer.valueOf(IsDeleteEnum.DELETED.getCode()).equals(info.getIsDelete())) {
+            throw new ServiceException("椤圭洰涓嶅瓨鍦ㄦ垨宸插垹闄�");
+        }
         return convert(info);
     }
 
@@ -98,6 +142,7 @@
     public List<SaveInfoDto> getSubordinateInfo(@NotNull Long id) {
         LambdaQueryWrapper<Info> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(Info::getProjectManagementInfoParentId, id);
+        queryWrapper.eq(Info::getIsDelete, IsDeleteEnum.NOT_DELETED.getCode());
         queryWrapper.orderByAsc(Info::getCreateTime);
         List<Info> infoList = infoMapper.selectList(queryWrapper);
         return infoList.stream().map(this::convert).collect(Collectors.toList());

--
Gitblit v1.9.3