| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean addProductMain(ProductionProductMainDto dto) { |
| | | SysUser user = userMapper.selectUserById(dto.getUserId()); |
| | | ProductionProductMain productionProductMain = new ProductionProductMain(); |
| | |
| | | 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); |
| | | if (reportQty != null && reportQty.compareTo(new BigDecimal(0)) == 0) { |
| | | throw new RuntimeException("产品" + drawMaterial.getProductName() + "- 型号" + drawMaterial.getModel() + |
| | | "- 批次号=" + drawMaterial.getBatchNo() + "的料已用完,请重新领料"); |
| | | |
| | | } |
| | | |
| | | 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 { |
| | | throw new RuntimeException("请领取投入材料"); |
| | | } |
| | | /*新增报工产出表*/ |
| | | ProductionProductOutput productionProductOutput = new ProductionProductOutput(); |
| | |
| | | //合格数量=报工数量 |
| | | BigDecimal productQty = productionProductOutput.getQuantity(); |
| | | //只有合格数量>0才能增加相应数据 |
| | | ProductWorkOrder pwo = productWorkOrderMapper.selectById(productionProductMain.getWorkOrderId()); |
| | | String customer = "长治市轴承制造有限公司"; |
| | | if (productQty.compareTo(BigDecimal.ZERO) > 0) { |
| | | /*新增质检*/ |
| | | List<ProductProcessRouteItem> productProcessRouteItems = productProcessRouteItemMapper.selectList(Wrappers.<ProductProcessRouteItem>lambdaQuery().eq(ProductProcessRouteItem::getProductRouteId, productProcessRouteItem.getProductRouteId())); |
| | |
| | | inspectType = 2; |
| | | process = null; |
| | | } |
| | | ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectById(productionProductMain.getWorkOrderId()); |
| | | ProductOrder productOrder = productOrderMapper.selectById(productWorkOrder.getProductOrderId()); |
| | | ProductOrder productOrder = productOrderMapper.selectById(pwo.getProductOrderId()); |
| | | if (productOrder == null) { |
| | | throw new RuntimeException("生产订单不存在"); |
| | | } |
| | | |
| | | |
| | | Product product = productMapper.selectById(productModel.getProductId()); |
| | | QualityInspect qualityInspect = new QualityInspect(); |
| | |
| | | qualityInspect.setProductModelId(productModel.getId()); |
| | | qualityInspect.setBatchNo(productOrder.getBatchNo()); |
| | | qualityInspect.setManufacturingTeam(productOrder.getManufacturingTeam()); |
| | | qualityInspect.setProductionDate(pwo.getActualStartTime() != null ? pwo.getActualStartTime() : LocalDate.now()); |
| | | qualityInspectMapper.insert(qualityInspect); |
| | | List<QualityTestStandard> qualityTestStandard = qualityTestStandardMapper.getQualityTestStandardByProductId(product.getId(), inspectType, process); |
| | | if (qualityTestStandard.size() > 0) { |
| | |
| | | } |
| | | } else { |
| | | //直接入库 |
| | | stockUtils.addStock(productProcessRouteItem.getProductModelId(), productionProductOutput.getQuantity().subtract(productionProductOutput.getScrapQty()), StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode(), productionProductMain.getId()); |
| | | stockUtils.addStock(productProcessRouteItem.getProductModelId(), productionProductOutput.getQuantity().subtract(productionProductOutput.getScrapQty()), |
| | | StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode(), productionProductMain.getId(), order.getBatchNo(), customer, pwo.getActualStartTime() != null ? pwo.getActualStartTime() : LocalDate.now() |
| | | ); |
| | | } |
| | | /*更新工单和生产订单*/ |
| | | ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectById(dto.getWorkOrderId()); |
| | |
| | | } |
| | | } |
| | | productOrderMapper.updateById(productOrder); |
| | | /*添加生产核算 区分工序是计件还是计时*/ |
| | | BigDecimal workHours = (productProcess.getType() == 1) |
| | | ? productProcess.getSalaryQuota().multiply(productQty) |
| | | : productProcess.getSalaryQuota(); |
| | | /*添加生产核算*/ |
| | | BigDecimal workHours = productProcess.getSalaryQuota(); |
| | | |
| | | SalesLedgerProductionAccounting salesLedgerProductionAccounting = SalesLedgerProductionAccounting.builder() |
| | | .productMainId(productionProductMain.getId()) |
| | |
| | | //如果报废数量>0,需要进入报废的库存 |
| | | if (ObjectUtils.isNotEmpty(dto.getScrapQty())) { |
| | | if (dto.getScrapQty().compareTo(BigDecimal.ZERO) > 0) { |
| | | stockUtils.addUnStock(productModel.getId(), dto.getScrapQty(), StockInUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode(), productionProductMain.getId()); |
| | | stockUtils.addUnStock(productModel.getId(), dto.getScrapQty(), StockInUnQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode(), productionProductMain.getId(), |
| | | order.getBatchNo(), customer, pwo.getActualStartTime() != null ? pwo.getActualStartTime() : LocalDate.now()); |
| | | } |
| | | } |
| | | return true; |
| | |
| | | public Boolean removeProductMain(Long id) { |
| | | //判断该条报工是否不合格处理,如果不合格处理了,则不允许删除 |
| | | List<QualityInspect> qualityInspects = qualityInspectMapper.selectList(Wrappers.<QualityInspect>lambdaQuery().eq(QualityInspect::getProductMainId, id)); |
| | | if (qualityInspects.size() > 0) { |
| | | if (!qualityInspects.isEmpty()) { |
| | | List<QualityUnqualified> qualityUnqualifieds = qualityUnqualifiedMapper.selectList(Wrappers.<QualityUnqualified>lambdaQuery() |
| | | .in(QualityUnqualified::getInspectId, qualityInspects.stream().map(QualityInspect::getId).collect(Collectors.toList()))); |
| | | if (qualityUnqualifieds.size() > 0 && qualityUnqualifieds.get(0).getInspectState() == 1) { |