liyong
18 小时以前 6b39b27a2807f4fb60e3b8ac12a1bb5deaad7775
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -13,6 +13,7 @@
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.procurementrecord.utils.StockUtils;
import com.ruoyi.production.controller.ProductWorkOrderController;
import com.ruoyi.production.dto.ProductStructureDto;
import com.ruoyi.production.dto.ProductionProductMainDto;
@@ -74,6 +75,8 @@
    private SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
    private StockUtils stockUtils;
    @Override
    public IPage<ProductionProductMainDto> listPageProductionProductMainDto(Page page, ProductionProductMainDto productionProductMainDto) {
@@ -89,34 +92,7 @@
        SysUser user = SecurityUtils.getLoginUser().getUser();
        if (dto.isReportWork()) {
            // 更新逻辑 - 只更新数量
            QueryWrapper<ProductionProductOutput> outputWrapper = new QueryWrapper<>();
            outputWrapper.eq("product_main_id", dto.getProductMainId());
            ProductionProductOutput output = productionProductOutputMapper.selectOne(outputWrapper);
            if (output == null) {
                throw new RuntimeException("产出记录不存在");
            }
            // 查询生产核算记录
            QueryWrapper<SalesLedgerProductionAccounting> accountingWrapper = new QueryWrapper<>();
            accountingWrapper.eq("sales_ledger_work_id", dto.getProductMainId());
            SalesLedgerProductionAccounting accounting = salesLedgerProductionAccountingMapper.selectOne(accountingWrapper);
            if (accounting == null) {
                throw new RuntimeException("生产核算记录不存在");
            }
            // 只更新数量
            if (dto.getQuantity() != null) {
                output.setQuantity(dto.getQuantity());
                productionProductOutputMapper.updateById(output);
                // 更新生产核算记录
                accounting.setFinishedNum(dto.getQuantity());
                salesLedgerProductionAccountingMapper.updateById(accounting);
            }
            return true;
        }
        // 新增逻辑
        ProductionProductMain productionProductMain = new ProductionProductMain();
@@ -193,6 +169,7 @@
            qualityInspect.setInspectState(0);
            qualityInspect.setInspectType(inspectType);
            qualityInspect.setProductMainId(productionProductMain.getId());
            qualityInspect.setProductModelId(productModel.getId());
            qualityInspectMapper.insert(qualityInspect);
            qualityTestStandardMapper.selectList(
@@ -210,9 +187,15 @@
        if (productModel != null) {
            List<ProductStructureDto> productStructureDtos = productStructureMapper.listByproductModelId(productModel.getId());
            for (ProductStructureDto productStructureDto : productStructureDtos) {
                ProductModel productModel1 = productModelMapper.selectById(productStructureDto.getProductModelId());
                BigDecimal stockQuantity = stockUtils.getStockQuantity(productModel1.getId());
                if (!(stockQuantity.compareTo(BigDecimal.ZERO) > 0)) {
                    throw new RuntimeException("库存不足");
                }
                ProductionProductInput productionProductInput = new ProductionProductInput();
                productionProductInput.setProductModelId(productStructureDto.getProductModelId());
                productionProductInput.setQuantity(productStructureDto.getUnitQuantity());
                productionProductInput.setQuantity(productStructureDto.getUnitQuantity().multiply(dto.getQuantity()));
                productionProductInput.setProductMainId(productionProductMain.getId());
                productionProductInputMapper.insert(productionProductInput);
            }