zhangwencui
2026-11-03 f76bf27bf93e523ae4572d9e10e9ca541c324185
src/main/java/com/ruoyi/sales/service/BusinessApprovalService.java
@@ -1,17 +1,11 @@
package com.ruoyi.sales.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.enums.PlanStageEnum;
import com.ruoyi.common.enums.ReviewStatusEnum;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.projectManagement.dto.PlanStageDto;
import com.ruoyi.projectManagement.mapper.InfoMapper;
import com.ruoyi.projectManagement.mapper.PlanMapper;
import com.ruoyi.projectManagement.mapper.PlanNodeMapper;
import com.ruoyi.projectManagement.pojo.Info;
import com.ruoyi.projectManagement.pojo.Plan;
import com.ruoyi.projectManagement.pojo.PlanNode;
import com.ruoyi.sales.dto.BusinessReviewDto;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.pojo.SalesLedger;
@@ -22,15 +16,12 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Service
@RequiredArgsConstructor
public class BusinessApprovalService {
    private final SalesLedgerMapper salesLedgerMapper;
    private final InfoMapper infoMapper;
    private final PlanMapper planMapper;
    private final PlanNodeMapper planNodeMapper;
    @Transactional(rollbackFor = Exception.class)
    public void submit(Long id) {
@@ -74,18 +65,6 @@
    }
    private Long createProject(SalesLedger ledger, Long selectedPlanId) {
        Plan plan = selectedPlanId == null ? planMapper.selectOne(new LambdaQueryWrapper<Plan>()
                .eq(Plan::getName, "项目申报六阶段")
                .eq(Plan::getIsDelete, 0).last("limit 1")) : planMapper.selectById(selectedPlanId);
        if (plan == null) {
            throw new ServiceException("未找到“项目申报六阶段”计划,请先执行升级SQL");
        }
        List<PlanNode> nodes = planNodeMapper.selectList(new LambdaQueryWrapper<PlanNode>()
                .eq(PlanNode::getProjectManagementPlanId, plan.getId())
                .eq(PlanNode::getIsDelete, 0).orderByAsc(PlanNode::getSort));
        if (nodes.isEmpty()) {
            throw new ServiceException("项目六阶段尚未配置");
        }
        Info info = new Info();
        info.setNo("XM" + LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)
                + String.format("%06d", ledger.getId()));
@@ -94,22 +73,16 @@
        info.setClientId(ledger.getCustomerId());
        info.setClientName(ledger.getCustomerName());
        info.setEstablishTime(LocalDate.now());
        info.setProjectManagementPlanId(plan.getId());
        info.setSource("业务审批");
        info.setManagerId(SecurityUtils.getUserId());
        info.setManagerName(SecurityUtils.getLoginUser().getNickName());
        info.setSource("业务生成");
        info.setSourceBusinessId(ledger.getId());
        info.setCurrentPhase("未开始");
        info.setSalesmanName(ledger.getSalesman());
        info.setIsDelete(0);
        info.setPlanStartTime(LocalDate.now());
        info.setReviewStatus(ReviewStatusEnum.APPROVED.getCode());
        info.setStatus(PlanStageEnum.TO_BEGIN.getCode());
        info.setOrderDate(ledger.getExecutionDate());
        info.setOrderAmount(ledger.getContractAmount() == null ? null : ledger.getContractAmount().toPlainString());
        info.setRemark(ledger.getRemarks());
        info.setAttachment(ledger.getAttachmentMaterials());
        info.setDeptId(ledger.getDeptId());
        info.setPlanStage(nodes.stream().map(node -> new PlanStageDto(node.getId(), node.getName(),
                PlanStageEnum.TO_BEGIN, node.getSort(), node.getEstimatedDuration())).toList());
        infoMapper.insert(info);
        return info.getId();
    }