2026-06-05 d1fac30e634e33edd29e3440de1f91da84c150c1
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -4,6 +4,8 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.procurementrecord.utils.StockUtils;
import com.ruoyi.production.mapper.*;
@@ -86,6 +88,8 @@
    private StockUtils stockUtils;
    @Autowired
    private StockInventoryMapper stockInventoryMapper;
    @Autowired
    private ProductModelMapper productModelMapper;
    @Override
    public SalesLedgerProduct selectSalesLedgerProductById(Long id) {
@@ -225,12 +229,28 @@
            return;
        }
        SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerProduct.getSalesLedgerId());
        // 获取单位:优先使用前端传入的unit,否则从产品规格获取
        String unit = salesLedgerProduct.getUnit();
        if (unit == null || unit.isEmpty()) {
            ProductModel productModel = productModelMapper.selectById(salesLedgerProduct.getProductModelId());
            unit = productModel != null ? productModel.getUnit() : null;
        }
        ProductionPlan productionPlan = new ProductionPlan();
        productionPlan.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId());
        productionPlan.setSalesLedgerProductId(salesLedgerProduct.getId());
        productionPlan.setMpsNo(generateNextPlanNo(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))));
        productionPlan.setProductModelId(salesLedgerProduct.getProductModelId());
        productionPlan.setQtyRequired(normalizeTotalQuantity(
        // 需求数量 = 产品数量(不是总数)
        productionPlan.setQtyRequired(salesLedgerProduct.getQuantity());
        // 同步单位
        productionPlan.setUnit(unit);
        // 同步产品数量
        productionPlan.setQuantity(salesLedgerProduct.getQuantity());
        // 同步每件数量
        productionPlan.setSingleQuantity(normalizeSingleQuantity(salesLedgerProduct.getSingleQuantity()));
        // 同步总数
        productionPlan.setTotalQuantity(normalizeTotalQuantity(
                salesLedgerProduct.getTotalQuantity(),
                salesLedgerProduct.getQuantity(),
                salesLedgerProduct.getSingleQuantity()