| | |
| | | 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<>(); |
| | |
| | | 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()); |
| | | } |
| | | |
| | | // 验证库存 |
| | |
| | | input.setQuantity(reportQty); |
| | | input.setProductMainId(productionProductMain.getId()); |
| | | input.setRemark(drawMaterial.getRemark()); |
| | | input.setBatchNo(drawMaterial.getBatchNo()); |
| | | input.setCustomer(drawMaterial.getCustomer()); |
| | | inputList.add(input); |
| | | } |
| | | |
| | |
| | | for (ProductionProductInput productionProductInput : inputList) { |
| | | productionProductInputMapper.insert(productionProductInput); |
| | | } |
| | | productOrder.setDrawMaterials(JSON.toJSONString(existingMaterialList)); |
| | | productOrderMapper.updateById(productOrder); |
| | | order.setDrawMaterials(JSON.toJSONString(existingMaterialList)); |
| | | productOrderMapper.updateById(order); |
| | | } |
| | | } |
| | | /*新增报工产出表*/ |
| | |
| | | } |
| | | } else { |
| | | //直接入库 |
| | | stockUtils.addStock(productProcessRouteItem.getProductModelId(), productionProductOutput.getQuantity().subtract(productionProductOutput.getScrapQty()), 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()); |