src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -143,28 +143,32 @@
        productionProductMain.setDeviceId(dto.getDeviceId());
        productionProductMainMapper.insert(productionProductMain);
        /* 新增报工投入表 */
        ProductWorkOrder WorkOrder = productWorkOrderMapper.selectById(dto.getWorkOrderId());
        if (WorkOrder == null) {
            throw new RuntimeException("工单不存在");
        }
        ProductOrder order = productOrderMapper.selectById(WorkOrder.getProductOrderId());
        if (order == null) {
            throw new RuntimeException("产品订单不存在");
        }
        List<DrawMaterialDto> drawMaterialList = dto.getDrawMaterialList();
        if (!CollectionUtils.isEmpty(drawMaterialList)) {
            // 1. 批量查询数据
            ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectById(dto.getWorkOrderId());
            if (productWorkOrder == null) {
                throw new RuntimeException("工单不存在");
            }
            ProductOrder productOrder = productOrderMapper.selectById(productWorkOrder.getProductOrderId());
            if (productOrder == null) {
                throw new RuntimeException("产品订单不存在");
            }
            // 2. 解析并构建物料Map
            List<DrawMaterialDto> existingMaterialList = JSON.parseArray(productOrder.getDrawMaterials(), DrawMaterialDto.class);
            // 物料Map
            List<DrawMaterialDto> existingMaterialList = JSON.parseArray(order.getDrawMaterials(), DrawMaterialDto.class);
            if (CollectionUtils.isEmpty(existingMaterialList)) {
                throw new RuntimeException("可领用物料列表为空");
            }
            Map<Long, DrawMaterialDto> materialMap = existingMaterialList.stream()
                    .collect(Collectors.toMap(DrawMaterialDto::getProductModelId,
                            Function.identity()));
            Map<String, DrawMaterialDto> materialMap = existingMaterialList.stream()
                    .collect(Collectors.toMap(
                            materialDto -> materialDto.getProductModelId() + "_" +
                                    (materialDto.getBatchNo() == null ? "" : materialDto.getBatchNo()) + "_" +
                                    (materialDto.getCustomer() == null ? "" : materialDto.getCustomer()),
                            Function.identity(),
                            (existing, replacement) -> existing
                    ));
            // 处理报工物料
            List<ProductionProductInput> inputList = new ArrayList<>();
@@ -173,9 +177,15 @@
                Long modelId = drawMaterial.getProductModelId();
                BigDecimal reportQty = drawMaterial.getReportQty();
                DrawMaterialDto material = materialMap.get(modelId);
                String key = drawMaterial.getProductModelId() + "_" +
                        (drawMaterial.getBatchNo() == null ? "" : drawMaterial.getBatchNo()) + "_" +
                        (drawMaterial.getCustomer() == null ? "" : drawMaterial.getCustomer());
                DrawMaterialDto material = materialMap.get(key);
                if (material == null) {
                    throw new RuntimeException("物料不存在: " + modelId);
                    throw new RuntimeException("物料不存在: 产品型号ID=" + modelId +
                            ", 批次号=" + drawMaterial.getBatchNo() +
                            ", 客户=" + drawMaterial.getCustomer());
                }
                // 验证库存
@@ -194,6 +204,8 @@
                input.setQuantity(reportQty);
                input.setProductMainId(productionProductMain.getId());
                input.setRemark(drawMaterial.getRemark());
                input.setBatchNo(drawMaterial.getBatchNo());
                input.setCustomer(drawMaterial.getCustomer());
                inputList.add(input);
            }
@@ -201,8 +213,8 @@
                for (ProductionProductInput productionProductInput : inputList) {
                    productionProductInputMapper.insert(productionProductInput);
                }
                productOrder.setDrawMaterials(JSON.toJSONString(existingMaterialList));
                productOrderMapper.updateById(productOrder);
                order.setDrawMaterials(JSON.toJSONString(existingMaterialList));
                productOrderMapper.updateById(order);
            }
        }
        /*新增报工产出表*/
@@ -241,14 +253,13 @@
                qualityInspect.setProductName(product.getProductName());
                qualityInspect.setModel(productModel.getModel());
                qualityInspect.setUnit(productModel.getUnit());
                qualityInspect.setQuantity(productQty);
                qualityInspect.setQuantity(productionProductOutput.getQuantity().subtract(productionProductOutput.getScrapQty()));
                qualityInspect.setProcess(process);
                qualityInspect.setInspectState(0);
                qualityInspect.setInspectType(inspectType);
                qualityInspect.setProductMainId(productionProductMain.getId());
                qualityInspect.setProductModelId(productModel.getId());
                qualityInspect.setBatchNo(productOrder.getBatchNo());
                qualityInspect.setInspectedQuantity(dto.getInspectedQuantity());
                qualityInspect.setManufacturingTeam(productOrder.getManufacturingTeam());
                qualityInspectMapper.insert(qualityInspect);
                List<QualityTestStandard> qualityTestStandard = qualityTestStandardMapper.getQualityTestStandardByProductId(product.getId(), inspectType, process);
@@ -267,7 +278,10 @@
                }
            } else {
                //直接入库
                stockUtils.addStock(productProcessRouteItem.getProductModelId(), productQty, StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode(), productionProductMain.getId());
                String customer = "长治市轴承制造有限公司";
                stockUtils.addStock(productProcessRouteItem.getProductModelId(), productionProductOutput.getQuantity().subtract(productionProductOutput.getScrapQty()),
                        StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode(), productionProductMain.getId(),order.getBatchNo(),customer
                );
            }
            /*更新工单和生产订单*/
            ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectById(dto.getWorkOrderId());