zss
2026-04-25 d34a44a1ffa778c0a95027f67d56544b0faa4930
src/main/java/com/ruoyi/projectManagement/service/impl/PlanServiceImpl.java
@@ -6,7 +6,10 @@
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.dto.StorageBlobVO;
import com.ruoyi.basic.enums.RecordTypeEnum;
import com.ruoyi.basic.service.CustomerFollowUpFileService;
import com.ruoyi.basic.utils.FileUtil;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.projectManagement.mapper.PlanMapper;
import com.ruoyi.projectManagement.mapper.PlanNodeMapper;
@@ -21,10 +24,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -43,6 +43,7 @@
    private final CustomerFollowUpFileService customerFollowUpFileService;
    private final PlanNodeMapper planNodeMapper;
    private final FileUtil fileUtil;
    @Lazy
    @Autowired
@@ -52,9 +53,8 @@
    @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);
        // 附件处理
        fileUtil.saveStorageAttachmentByRecordTypeAndRecordId("", RecordTypeEnum.PLAN, savePlanVo.getId(), savePlanVo.getStorageBlobDTOs());
        if (savePlanVo.getId() == null) {
            planMapper.insert(plan);
        } else {
@@ -72,11 +72,15 @@
        }
        // 删除多余节点
        List<PlanNode> needDeleteNode = planNodeMapper.selectList(new LambdaQueryWrapper<PlanNode>()
        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)
                .ne(PlanNode::getId, savePlanNodeVos.get(0).getId())
                .notIn(PlanNode::getId, savePlanNodeVos.stream().map(SavePlanNodeVo::getId).collect(Collectors.toList())));
                .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);
@@ -92,16 +96,20 @@
        });
    }
    private List<PlanNode> getPlanNodeByPlanId(Long planId) {
    @Override
    public List<PlanNode> getPlanNodeByPlanId(Long planId) {
        return planNodeMapper.selectList(new LambdaQueryWrapper<PlanNode>()
                .eq(PlanNode::getIsDelete, 0)
                .eq(PlanNode::getProjectManagementPlanId, planId));
                .eq(PlanNode::getProjectManagementPlanId, planId).orderByAsc(PlanNode::getSort));
    }
    private List<PlanNode> getPlanNodeByPlanIds(List<Long> planIds) {
        if(CollUtil.isEmpty(planIds)){
            return Collections.emptyList();
        }
        return planNodeMapper.selectList(new LambdaQueryWrapper<PlanNode>()
                .eq(PlanNode::getIsDelete, 0)
                .in(PlanNode::getProjectManagementPlanId, planIds));
                .in(PlanNode::getProjectManagementPlanId, planIds).orderByAsc(PlanNode::getSort));
    }
@@ -131,12 +139,14 @@
        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())));
        resultPage.getRecords().forEach(planVo -> {
            planVo.setPlanNodeList(collect.getOrDefault(planVo.getId(), Collections.emptyList()));
            planVo.setStorageBlobVOs(fileUtil.getStorageBlobVOsByRecordTypeAndRecordId(RecordTypeEnum.PLAN, planVo.getId()));
        });
        return resultPage;
    }