From f50da3afc73bc458640677c198bb7c99de5b2fe5 Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期一, 09 三月 2026 17:33:45 +0800
Subject: [PATCH] fix(mybatis): 修正createUser和updateUser填充值类型空值处理

---
 src/main/java/com/ruoyi/projectManagement/service/impl/PlanServiceImpl.java |  149 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 149 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/ruoyi/projectManagement/service/impl/PlanServiceImpl.java b/src/main/java/com/ruoyi/projectManagement/service/impl/PlanServiceImpl.java
new file mode 100644
index 0000000..fd5f028
--- /dev/null
+++ b/src/main/java/com/ruoyi/projectManagement/service/impl/PlanServiceImpl.java
@@ -0,0 +1,149 @@
+package com.ruoyi.projectManagement.service.impl;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Assert;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.ruoyi.basic.service.CustomerFollowUpFileService;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.projectManagement.mapper.PlanMapper;
+import com.ruoyi.projectManagement.mapper.PlanNodeMapper;
+import com.ruoyi.projectManagement.pojo.Plan;
+import com.ruoyi.projectManagement.pojo.PlanNode;
+import com.ruoyi.projectManagement.service.PlanService;
+import com.ruoyi.projectManagement.vo.*;
+import lombok.RequiredArgsConstructor;
+import org.jetbrains.annotations.Nullable;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+/**
+ * @author buhuazhen
+ * @description 椤圭洰绠$悊璁″垝鐨勫疄鐜�
+ * @createDate 2026-03-06 15:29:26
+ */
+@Service
+@RequiredArgsConstructor
+@Transactional(readOnly = true)
+public class PlanServiceImpl implements PlanService {
+
+    private final PlanMapper planMapper;
+
+    private final CustomerFollowUpFileService customerFollowUpFileService;
+
+    private final PlanNodeMapper planNodeMapper;
+
+    @Lazy
+    @Autowired
+    private PlanService planService;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void savePlan(SavePlanVo savePlanVo) {
+        Plan plan = BeanUtil.copyProperties(savePlanVo, Plan.class);
+        // 闄勪欢澶勭悊 , 鎷兼帴
+        String attachments = String.join(",", Optional.ofNullable(savePlanVo.getAttachmentIds()).orElse(Collections.emptyList()));
+        plan.setAttachment(attachments);
+        if (savePlanVo.getId() == null) {
+            planMapper.insert(plan);
+        } else {
+            planMapper.updateById(plan);
+        }
+        planService.savePlanNode(plan.getId(), savePlanVo.getSavePlanNodeList());
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void savePlanNode(Long planId, @Nullable List<SavePlanNodeVo> savePlanNodeVos) {
+        Assert.notNull(planId, () -> new ServiceException("璁″垝ID涓嶈兘涓虹┖"));
+        if (CollUtil.isEmpty(savePlanNodeVos)) {
+            return;
+        }
+
+        // 鍒犻櫎澶氫綑鑺傜偣
+        List<Long> existNodeIds = savePlanNodeVos.stream().map(SavePlanNodeVo::getId).filter(Objects::nonNull).collect(Collectors.toList());
+        LambdaQueryWrapper<PlanNode> planNodeLambdaQueryWrapper = new LambdaQueryWrapper<PlanNode>()
+                .select(PlanNode::getId)
+                .eq(PlanNode::getProjectManagementPlanId, planId);
+        if(CollUtil.isNotEmpty(existNodeIds)){
+            planNodeLambdaQueryWrapper.notIn(PlanNode::getId, existNodeIds);
+        }
+        List<PlanNode> needDeleteNode = planNodeMapper.selectList(planNodeLambdaQueryWrapper);
+
+        deletePlanNode(needDeleteNode.stream().map(PlanNode::getId).collect(Collectors.toList()));
+
+        List<PlanNode> planNodes = BeanUtil.copyToList(savePlanNodeVos, PlanNode.class);
+        // 璁剧疆鎺掑簭绱㈠紩
+        IntStream.range(0, savePlanNodeVos.size()).forEach(i -> {
+            planNodes.get(i).setSort(i);
+            planNodes.get(i).setProjectManagementPlanId(planId);
+            if (planNodes.get(i).getId() == null) {
+                planNodeMapper.insert(planNodes.get(i));
+            } else {
+                planNodeMapper.updateById(planNodes.get(i));
+            }
+        });
+    }
+
+    @Override
+    public List<PlanNode> getPlanNodeByPlanId(Long planId) {
+        return planNodeMapper.selectList(new LambdaQueryWrapper<PlanNode>()
+                .eq(PlanNode::getIsDelete, 0)
+                .eq(PlanNode::getProjectManagementPlanId, planId).orderByAsc(PlanNode::getSort));
+    }
+
+    private List<PlanNode> getPlanNodeByPlanIds(List<Long> planIds) {
+        return planNodeMapper.selectList(new LambdaQueryWrapper<PlanNode>()
+                .eq(PlanNode::getIsDelete, 0)
+                .in(PlanNode::getProjectManagementPlanId, planIds).orderByAsc(PlanNode::getSort));
+    }
+
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deletePlan(Long id) {
+        planMapper.update(null,
+                new LambdaUpdateWrapper<Plan>()
+                        .eq(Plan::getId, id)
+                        .set(Plan::getIsDelete, 1));
+        planService.deletePlanNode(getPlanNodeByPlanId(id).stream().map(PlanNode::getId).collect(Collectors.toList()));
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deletePlanNode(List<Long> ids) {
+        if (CollUtil.isNotEmpty(ids)) {
+            planNodeMapper.update(null,
+                    new LambdaUpdateWrapper<PlanNode>()
+                            .in(PlanNode::getId, ids)
+                            .set(PlanNode::getIsDelete, 1));
+        }
+    }
+
+    @Override
+    public IPage<PlanVo> searchPlan(SearchPlanVo searchPlanVo) {
+        IPage<Plan> planIPage = planMapper.selectPlanPage(searchPlanVo);
+        IPage<PlanVo> resultPage = planIPage.convert(plan -> BeanUtil.copyProperties(plan, PlanVo.class));
+        // 鏂囦欢鑾峰彇
+        customerFollowUpFileService.fillAttachment(resultPage.getRecords(), PlanVo::getAttachment, PlanVo::setAttachmentList);
+        Map<Long, List<PlanNodeVo>> collect = getPlanNodeByPlanIds(resultPage.getRecords().stream().map(PlanVo::getId).collect(Collectors.toList()))
+                .stream()
+                .map(it -> BeanUtil.copyProperties(it, PlanNodeVo.class))
+                .collect(Collectors.groupingBy(PlanNodeVo::getProjectManagementPlanId, Collectors.toList()));
+        resultPage.getRecords().forEach(planVo -> planVo.setPlanNodeList(collect.getOrDefault(planVo.getId(), Collections.emptyList())));
+        return resultPage;
+    }
+
+}
+
+
+
+

--
Gitblit v1.9.3