| | |
| | | import org.jeecg.modules.lsw.entity.LswMaterial; |
| | | import org.jeecg.modules.lsw.entity.LswMaterialInbound; |
| | | import org.jeecg.modules.lsw.enums.MaterialCategoryEnum; |
| | | import org.jeecg.modules.lsw.enums.MaterialInboundCategory; |
| | | import org.jeecg.modules.lsw.service.ILswMaterialInboundService; |
| | | import org.jeecg.modules.lsw.service.ILswMaterialService; |
| | | import org.jeecg.modules.mes.entity.MesMaterialLoading; |
| | | import org.jeecg.modules.mes.entity.MesProductionOrder; |
| | | import org.jeecg.modules.mes.entity.MesProductionWorkOrder; |
| | | import org.jeecg.modules.mes.entity.MesWorkReporting; |
| | | import org.jeecg.modules.mes.entity.*; |
| | | import org.jeecg.modules.mes.mapper.MesWorkReportingMapper; |
| | | import org.jeecg.modules.mes.service.IMesMaterialLoadingService; |
| | | import org.jeecg.modules.mes.service.IMesProductionOrderService; |
| | | import org.jeecg.modules.mes.service.IMesProductionWorkOrderService; |
| | | import org.jeecg.modules.mes.service.IMesWorkReportingService; |
| | | import org.jeecg.modules.mes.service.*; |
| | | import org.jeecg.modules.mes.utils.CommonUtils; |
| | | import org.jeecg.modules.pms.entity.PmsMaterialProcess; |
| | | import org.jeecg.modules.pms.service.IPmsMaterialProcessService; |
| | |
| | | private IInspectionPlanService inspectionPlanService; |
| | | @Autowired |
| | | private IInspectionPlanItemService inspectionPlanItemService; |
| | | @Autowired |
| | | private IMesMaterialConsumptionDetailService mesMaterialConsumptionDetailService; |
| | | |
| | | @Override |
| | | public List<MesWorkReporting> queryWorkReportingByWorkOrderId(String workOrderId) { |
| | |
| | | String date = today.format(DateTimeFormatter.ofPattern("yyMMdd")); |
| | | Factory factory = factoryService.getById(mesWorkReporting.getFactoryId()); |
| | | workOrder.setFactoryCode(factory.getFactoryCode()); |
| | | List<MesMaterialConsumptionDetail> consumptionDetailList = CollectionUtil.newArrayList(); |
| | | switch (materialCategory) { |
| | | case FINISHED_PRODUCT: |
| | | //成品报工 |
| | | productReport(mesWorkReporting, workOrder, lineSideWarehouse); |
| | | consumptionDetailList = productReport(mesWorkReporting, workOrder, lineSideWarehouse); |
| | | //生成检验工单 |
| | | generateInspectionOrder(mesWorkReporting, workOrder); |
| | | //generateInspectionOrder(mesWorkReporting, workOrder); |
| | | //拼接成品报工托号 |
| | | String palletNumber4 = sysBusinessCodeRuleService.generateBusinessCodeSeq("WorkReportingPalletNumber4"); |
| | | String finishedPalletNumber = material.getMaterialNumber() + date + palletNumber4; |
| | |
| | | case INNER_FLANGE: |
| | | case OUTER_FLANGE: |
| | | //半成品(内法兰、外法兰)报工 |
| | | productReport(mesWorkReporting, workOrder, lineSideWarehouse); |
| | | consumptionDetailList = productReport(mesWorkReporting, workOrder, lineSideWarehouse); |
| | | //拼接半成品报工托号 |
| | | Shift shift = shiftService.getById(workOrder.getShiftId()); |
| | | String palletNumber6 = sysBusinessCodeRuleService.generateBusinessCodeSeq("WorkReportingPalletNumber6"); |
| | |
| | | } |
| | | //新增报工记录 |
| | | save(mesWorkReporting); |
| | | consumptionDetailList.forEach(i -> i.setReportingId(mesWorkReporting.getId())); |
| | | //保存物料消耗明细 |
| | | mesMaterialConsumptionDetailService.saveBatch(consumptionDetailList); |
| | | //更新排产工单 |
| | | MesProductionWorkOrder productionWorkUpdateOrder = new MesProductionWorkOrder() |
| | | .setId(workOrder.getId()) |
| | |
| | | } |
| | | |
| | | //半成品(内法兰、外法兰)、成品报工 |
| | | private void productReport(MesWorkReporting mesWorkReporting, MesProductionWorkOrder workOrder, LineSideWarehouse lineSideWarehouse) { |
| | | private List<MesMaterialConsumptionDetail> productReport(MesWorkReporting mesWorkReporting, MesProductionWorkOrder workOrder, LineSideWarehouse lineSideWarehouse) { |
| | | //1、入库 半成品/成品 到对应线边库 |
| | | LswMaterialInbound materialInbound = new LswMaterialInbound() |
| | | .setFactoryId(workOrder.getFactoryId()) |
| | |
| | | .setMaterialNumber(workOrder.getMaterialNumber()) |
| | | .setMaterialName(workOrder.getMaterialName()) |
| | | .setBatchNumber(mesWorkReporting.getBatchNumber()) |
| | | .setQuantity(mesWorkReporting.getQuantity()); |
| | | lswMaterialInboundService.save(materialInbound); |
| | | //2、扣减使用毛坯库存(更新上料记录)或半成品物料库存(内法兰、外法兰、小内圈、配件等),按照 排产工单id、物料编码 查询上料记录,按照时间从早到晚排序,优先扣减早的上料记录(先进先出) |
| | | .setQuantity(mesWorkReporting.getQuantity()) |
| | | .setInboundCategory(MaterialInboundCategory.PRODUCTION_INBOUND.name())//生产下线 |
| | | .setOriginalCode(lineSideWarehouse.getWarehouseCode()) |
| | | .setOriginalName(lineSideWarehouse.getWarehouseName()); |
| | | lswMaterialInboundService.inboundMaterial(materialInbound); |
| | | //2、扣减使用毛坯库存(更新上料记录)或半成品物料库存(内法兰、外法兰、小内圈、配件等),按照 产线id、库存地id、物料编码 查询上料记录,按照时间从早到晚排序,优先扣减早的上料记录(先进先出) |
| | | //先查询物料 BOM |
| | | Map<String, ProcessBillMaterialsDetailVo> processBillMaterialsDetailMap = pmsProcessBillMaterialsService |
| | | .queryMaterialsDetailByOrderIdAndMaterialNumber(mesWorkReporting.getOrderId(), workOrder.getMaterialNumber()).stream() |
| | | .collect(Collectors.toMap(ProcessBillMaterialsDetailVo::getMaterialNumber, v1 -> v1, (v1, v2) -> v1)); |
| | | //查询上料记录 |
| | | Map<String, List<MesMaterialLoading>> materialLoadingRecordMap = mesMaterialLoadingService.list(new LambdaQueryWrapper<MesMaterialLoading>() |
| | | .eq(MesMaterialLoading::getWorkOrderId, workOrder.getId()) |
| | | .eq(MesMaterialLoading::getFactoryId, workOrder.getFactoryId()) |
| | | .eq(MesMaterialLoading::getWarehouseId, lineSideWarehouse.getId()) |
| | | .in(MesMaterialLoading::getMaterialNumber, processBillMaterialsDetailMap.keySet()) |
| | | .gt(MesMaterialLoading::getRemainingQuantity, BigDecimal.ZERO)).stream() |
| | | .sorted(Comparator.comparing(MesMaterialLoading::getCreateTime)) |
| | | .collect(Collectors.groupingBy(MesMaterialLoading::getMaterialNumber)); |
| | | List<MesMaterialLoading> materialLoadingRecordUpdateList = CollectionUtil.newArrayList(); |
| | | List<MesMaterialConsumptionDetail> consumptionDetailAddList = CollectionUtil.newArrayList(); |
| | | for (String materialNumber : processBillMaterialsDetailMap.keySet()) { |
| | | List<MesMaterialLoading> materialLoadingRecordList = materialLoadingRecordMap.get(materialNumber); |
| | | if (materialLoadingRecordList.isEmpty()) { |
| | |
| | | //计算物料扣减数量 |
| | | ProcessBillMaterialsDetailVo processBillMaterialsDetailVo = processBillMaterialsDetailMap.get(materialNumber); |
| | | BigDecimal quantity = processBillMaterialsDetailVo.getPerQuantity().multiply(mesWorkReporting.getQuantity()); |
| | | List<MesMaterialLoading> updateList = deductQuantity(materialLoadingRecordList, quantity); |
| | | materialLoadingRecordUpdateList.addAll(updateList); |
| | | //扣减上料数量并记录物料消耗明细 |
| | | for (MesMaterialLoading mesMaterialLoading : materialLoadingRecordList) { |
| | | //记录物料消耗明细 |
| | | MesMaterialConsumptionDetail materialConsumptionDetail = new MesMaterialConsumptionDetail() |
| | | .setOrderId(mesWorkReporting.getOrderId()) |
| | | .setWorkOrderId(workOrder.getId()) |
| | | .setFactoryId(workOrder.getFactoryId()) |
| | | .setLoadingId(mesMaterialLoading.getId()); |
| | | if (mesMaterialLoading.getRemainingQuantity().compareTo(quantity) >= 0) { |
| | | mesMaterialLoading.setRemainingQuantity(mesMaterialLoading.getRemainingQuantity().subtract(quantity)); |
| | | materialConsumptionDetail.setQuantity(quantity); |
| | | break; |
| | | } else { |
| | | quantity = quantity.subtract(mesMaterialLoading.getRemainingQuantity()); |
| | | materialConsumptionDetail.setQuantity(mesMaterialLoading.getRemainingQuantity()); |
| | | mesMaterialLoading.setRemainingQuantity(BigDecimal.ZERO); |
| | | } |
| | | consumptionDetailAddList.add(materialConsumptionDetail); |
| | | } |
| | | materialLoadingRecordUpdateList.addAll(materialLoadingRecordList); |
| | | } |
| | | //更新上料记录 |
| | | mesMaterialLoadingService.updateBatchById(materialLoadingRecordUpdateList); |
| | |
| | | log.error("SAP工序报工异常!", e); |
| | | } |
| | | } |
| | | return consumptionDetailAddList; |
| | | } |
| | | |
| | | //根据检验方案生成检验工单 |
| | |
| | | //todo 检验工单目前还没有生成代码,没有功能 |
| | | } |
| | | |
| | | private List<MesMaterialLoading> deductQuantity(List<MesMaterialLoading> materialLoadingRecordList, BigDecimal quantity) { |
| | | for (MesMaterialLoading mesMaterialLoading : materialLoadingRecordList) { |
| | | if (mesMaterialLoading.getRemainingQuantity().compareTo(quantity) >= 0) { |
| | | mesMaterialLoading.setRemainingQuantity(mesMaterialLoading.getRemainingQuantity().subtract(quantity)); |
| | | break; |
| | | } else { |
| | | quantity = quantity.subtract(mesMaterialLoading.getRemainingQuantity()); |
| | | mesMaterialLoading.setRemainingQuantity(BigDecimal.ZERO); |
| | | } |
| | | } |
| | | return materialLoadingRecordList; |
| | | } |
| | | } |