9 小时以前 55d694aaae4e421b5e55cd941500e08f85cb5d4d
src/main/java/com/ruoyi/production/service/impl/ProductionPlanServiceImpl.java
@@ -24,6 +24,10 @@
import com.ruoyi.production.pojo.ProductionPlan;
import com.ruoyi.production.service.ProductionOrderService;
import com.ruoyi.production.service.ProductionPlanService;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -50,6 +54,8 @@
    private final ProductionOrderService productionOrderService;
    private final ProductModelMapper productModelMapper;
    private final ProductMapper productMapper;
    private final SalesLedgerMapper salesLedgerMapper;
    private final SalesLedgerProductMapper salesLedgerProductMapper;
    @Override
    public IPage<ProductionPlanVo> listPage(Page<ProductionPlanDto> page, ProductionPlanDto productionPlanDto) {
@@ -151,6 +157,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean add(ProductionPlanDto dto) {
        validateSalesSource(dto);
        // 新增主生产计划
        if (StringUtils.isBlank(dto.getMpsNo())) {
            String datePrefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
@@ -173,6 +180,7 @@
            throw new ServiceException("编辑失败,数据不能为空");
        }
        validateSalesSource(dto);
        ProductionPlan old = getById(dto.getId());
        if (old == null) {
            throw new ServiceException("编辑失败,生产计划不存在");
@@ -321,6 +329,32 @@
        util.exportExcel(response, exportList, "主生产计划");
    }
    private void validateSalesSource(ProductionPlanDto dto) {
        if (dto == null) {
            throw new ServiceException("生产计划不能为空");
        }
        if (dto.getSalesLedgerId() == null && dto.getSalesLedgerProductId() == null) {
            return;
        }
        if (dto.getSalesLedgerId() == null || dto.getSalesLedgerProductId() == null) {
            throw new ServiceException("销售台账和销售产品必须同时填写");
        }
        SalesLedgerProduct product = salesLedgerProductMapper.selectById(dto.getSalesLedgerProductId());
        if (product == null || !Objects.equals(product.getSalesLedgerId(), dto.getSalesLedgerId())) {
            throw new ServiceException("销售产品与销售台账不匹配");
        }
        SalesLedger ledger = salesLedgerMapper.selectById(dto.getSalesLedgerId());
        if (ledger == null || (!Objects.equals(ledger.getContractType(), 1)
                && !Objects.equals(ledger.getContractType(), 3))) {
            throw new ServiceException("生产计划只能关联普通销售产品或框架订单产品");
        }
        if (dto.getProductModelId() == null) {
            dto.setProductModelId(product.getProductModelId());
        } else if (!Objects.equals(dto.getProductModelId(), product.getProductModelId())) {
            throw new ServiceException("生产计划产品型号与销售产品不一致");
        }
    }
    /**
     * 校验主生产计划号唯一性,可通过 excludeId 排除当前记录。
     */