| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.modules.base.entity.Factory; |
| | | import org.jeecg.modules.base.entity.LineSideWarehouse; |
| | | import org.jeecg.modules.base.entity.Shift; |
| | | import org.jeecg.modules.base.entity.ShiftGroup; |
| | | import org.jeecg.modules.base.service.IFactoryService; |
| | | import org.jeecg.modules.base.service.ILineSideWarehouseService; |
| | | import org.jeecg.modules.base.service.IShiftGroupService; |
| | | import org.jeecg.modules.base.service.IShiftService; |
| | | import org.jeecg.modules.lsw.entity.LswMaterialInventory; |
| | | import org.jeecg.modules.lsw.service.ILswMaterialInventoryService; |
| | | import org.jeecg.modules.lsw.vo.LswMaterialInventoryVo; |
| | | import org.jeecg.modules.mes.dto.MesProductionWorkScheduleRequest; |
| | | import org.jeecg.modules.mes.entity.MesKittingCompletenessCheck; |
| | | import org.jeecg.modules.mes.entity.MesProductionOrder; |
| | | import org.jeecg.modules.mes.enums.ProductionOrderStatus; |
| | | import org.jeecg.modules.mes.service.IMesProductionOrderService; |
| | | import org.jeecg.modules.mes.service.IMesProductionWorkOrderService; |
| | | import org.jeecg.modules.mes.entity.MesProductionWorkOrder; |
| | | import org.jeecg.modules.mes.mapper.MesProductionWorkOrderMapper; |
| | | import org.jeecg.modules.system.service.ISysDictService; |
| | | import org.jeecg.modules.pms.entity.PmsProcessBillMaterials; |
| | | import org.jeecg.modules.pms.entity.PmsProcessBillMaterialsDetail; |
| | | import org.jeecg.modules.pms.service.IPmsProcessBillMaterialsDetailService; |
| | | import org.jeecg.modules.pms.service.IPmsProcessBillMaterialsService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.ChronoUnit; |
| | |
| | | private IShiftGroupService shiftGroupService; |
| | | @Autowired |
| | | private IFactoryService factoryService; |
| | | @Autowired |
| | | private IMesProductionOrderService mesProductionOrderService; |
| | | @Autowired |
| | | private IPmsProcessBillMaterialsService pmsProcessBillMaterialsService; |
| | | @Autowired |
| | | private IPmsProcessBillMaterialsDetailService pmsProcessBillMaterialsDetailService; |
| | | @Autowired |
| | | private ILswMaterialInventoryService lswMaterialInventoryService; |
| | | @Autowired |
| | | private ILineSideWarehouseService lineSideWarehouseService; |
| | | |
| | | @Override |
| | | public List<MesProductionWorkOrder> schedule(MesProductionWorkScheduleRequest request) { |
| | |
| | | queryWrapper.orderByAsc("t1.work_order_date"); |
| | | return this.baseMapper.queryPageList(page, queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<MesKittingCompletenessCheck> workOrderCompletenessCheck(MesProductionWorkOrder workOrder) { |
| | | //根据当前排产工单确定生产订单 |
| | | List<MesProductionOrder> orderList = mesProductionOrderService.list(new LambdaQueryWrapper<MesProductionOrder>() |
| | | .eq(MesProductionOrder::getMaterialNumber, workOrder.getMaterialNumber()) |
| | | .eq(MesProductionOrder::getOrderStatus, ProductionOrderStatus.REL.name()) |
| | | .eq(MesProductionOrder::getDelFlag, CommonConstant.DEL_FLAG_0) |
| | | .orderByAsc(MesProductionOrder::getPlanStart)); |
| | | if (orderList.isEmpty()) { |
| | | throw new JeecgBootException("未找到该物料的关联生产订单!"); |
| | | } |
| | | //默认取时间最早未完成的订单,也就是第一项 |
| | | MesProductionOrder order = orderList.get(0); |
| | | //根据生产订单id和物料编码查询订单BOM |
| | | PmsProcessBillMaterials processBillMaterials = pmsProcessBillMaterialsService.list(new LambdaQueryWrapper<PmsProcessBillMaterials>() |
| | | .eq(PmsProcessBillMaterials::getOrderId, order.getId()) |
| | | .eq(PmsProcessBillMaterials::getMaterialNumber, workOrder.getMaterialNumber())) |
| | | .stream().findFirst().orElse(null); |
| | | if (processBillMaterials == null) { |
| | | throw new JeecgBootException("未找到与该物料关联的订单BOM!"); |
| | | } |
| | | //查询工单所属产线对应的线边仓 |
| | | LineSideWarehouse lineSideWarehouse = lineSideWarehouseService.list(new LambdaQueryWrapper<LineSideWarehouse>() |
| | | .eq(LineSideWarehouse::getFactoryId, workOrder.getFactoryId()) |
| | | .eq(LineSideWarehouse::getDelFlag, CommonConstant.DEL_FLAG_0) |
| | | .eq(LineSideWarehouse::getWarehouseStatus, CommonConstant.DEFAULT_1)) |
| | | .stream().findFirst().orElse(null); |
| | | if (lineSideWarehouse == null) { |
| | | throw new JeecgBootException("该产线未配置线边仓!"); |
| | | } |
| | | //订单BOM明细 |
| | | List<PmsProcessBillMaterialsDetail> processBillMaterialsDetails = pmsProcessBillMaterialsDetailService.queryByMaterialId(processBillMaterials.getId()); |
| | | //查询订单BOM明细中的物料在该产线线边仓中的库存 |
| | | List<String> bomMaterialNumberList = processBillMaterialsDetails.stream() |
| | | .map(PmsProcessBillMaterialsDetail::getMaterialNumber).collect(Collectors.toList()); |
| | | Map<String, LswMaterialInventoryVo> lswMaterialInventoryMap = lswMaterialInventoryService |
| | | .selectLineSideMaterialInventoryByMaterialNumber(bomMaterialNumberList, lineSideWarehouse.getId()).stream() |
| | | .collect(Collectors.toMap(LswMaterialInventoryVo::getMaterialNumber, v1 -> v1, (v1, v2) -> v1)); |
| | | List<MesKittingCompletenessCheck> completenessCheckResultList = CollectionUtil.newArrayList(); |
| | | //根据订单BOM明细列出齐套检查结果 |
| | | for (PmsProcessBillMaterialsDetail processBillMaterialsDetail : processBillMaterialsDetails) { |
| | | LswMaterialInventoryVo materialInventoryVo = lswMaterialInventoryMap.get(processBillMaterialsDetail.getMaterialNumber()); |
| | | MesKittingCompletenessCheck completenessCheckItem = new MesKittingCompletenessCheck() |
| | | .setMaterialNumber(processBillMaterialsDetail.getMaterialNumber()) |
| | | .setMaterialName(processBillMaterialsDetail.getMaterialName()) |
| | | //需求数量 = (bom明细的需求数量 / bom订单的数量) * 排产工单计划生产数量 |
| | | .setRequiredQuantity(processBillMaterialsDetail.getUsageQuantity() |
| | | .divide(processBillMaterials.getProductionQuantity(), 2, RoundingMode.HALF_UP) |
| | | .multiply(workOrder.getPlanQuantity())) |
| | | .setActualQuantity(materialInventoryVo == null ? BigDecimal.ZERO : materialInventoryVo.getStockQuantity()) |
| | | .setProductionUnit(processBillMaterialsDetail.getProductionUnit()); |
| | | completenessCheckResultList.add(completenessCheckItem); |
| | | } |
| | | completenessCheckResultList.forEach(item -> { |
| | | if (item.getRequiredQuantity().compareTo(item.getActualQuantity()) > 0) { |
| | | item.setCheckFlag(CommonConstant.DEFAULT_0); |
| | | } else { |
| | | item.setCheckFlag(CommonConstant.DEFAULT_1); |
| | | } |
| | | }); |
| | | return completenessCheckResultList; |
| | | } |
| | | } |