| | |
| | | ApsPlateStandardRequireBomOrderDetailMapper plateBomOrderDetailMapper; |
| | | |
| | | @Autowired |
| | | private ApsPlatePlanMapper apsPlatePlanMapper; |
| | | private IApsPlatePlanService apsPlatePlanService; |
| | | |
| | | @Resource |
| | | IApsPlateStandardRequireBomOrderDetailService bomOrderDetailService; |
| | |
| | | /*获取钣金主单信息*/ |
| | | List<ApsPlatePlan> mainPlans = platePlanMapper.selectPlatePlanByPlantMajor(plantCode,mainOrderType); |
| | | Hashtable<String, ApsMaterialStorageManagement> usedStorage = new Hashtable<>(); |
| | | /*内存中存储子件工单*/ |
| | | Hashtable<String, List<ApsPlatePlan>> subPlans = new Hashtable<>(); |
| | | log.info("开始生成需求:"); |
| | | for (ApsPlatePlan mainPlan : mainPlans) { |
| | | String itemNumber = mainPlan.getItemNumber(); |
| | | /*根据料号 获取BOM Header */ |
| | | /*当前Bom节点处理完成后,处理下级BOM*/ |
| | | |
| | | |
| | | List<ApsPlateStandardRequire> requiresList=new ArrayList<>(); |
| | | List<ApsPlateStandardRequireBomStockDetail> stockDetailsList=new ArrayList<>(); |
| | | List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList=new ArrayList<>(); |
| | | |
| | | |
| | | log.info("开始生成需求:工单号:"+mainPlan.getDocumentNumber()); |
| | | /*当前Bom节点处理完成后,处理下级BOM*/ |
| | | getBomRequires(plantCode, "0","0",itemNumber,BigDecimal.ONE, batchNum, null |
| | | , mainPlan, requiresList, 0L,stockDetailsList,orderDetailsList,usedStorage |
| | | , mainPlan, requiresList, 0L,stockDetailsList,orderDetailsList,usedStorage,subPlans |
| | | ); |
| | | |
| | | // 批量插入以提高性能 |
| | |
| | | storageManagementService.updateRemainderStock(sm.getId(),sm.getRemainderStock(),sm.getVersion()); |
| | | }); |
| | | } |
| | | if(!subPlans.isEmpty()){ |
| | | subPlans.forEach((key, subPlansList) -> { |
| | | subPlansList.forEach(x->{ |
| | | if (!x.getUnmatchedQuantity().equals(x.getProductionQuantity())){ |
| | | platePlanMapper.updatePlanUnMatchQtyAndVersion(x); |
| | | } |
| | | }); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | List<ApsPlateStandardRequire> allRequires, |
| | | Long level,List<ApsPlateStandardRequireBomStockDetail> stockDetailsList, |
| | | List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList, |
| | | Hashtable<String, ApsMaterialStorageManagement> usedStorage |
| | | Hashtable<String, ApsMaterialStorageManagement> usedStorage, |
| | | Hashtable<String, List<ApsPlatePlan>> subPlans |
| | | ) { |
| | | /*构建需求信息*/ |
| | | ApsPlateStandardRequire require = new ApsPlateStandardRequire(); |
| | |
| | | if (require.getNetRequirement().compareTo(BigDecimal.ZERO) > 0) { |
| | | require.setMatchMode("工单匹配"); |
| | | /*使用子件工单进行需求匹配*/ |
| | | matchRequireAndSubPlan(require,orderDetailsList); |
| | | matchRequireAndSubPlan(require,orderDetailsList,subPlans); |
| | | } |
| | | allRequires.add(require); |
| | | log.info("已生成需求:"+plan.getDocumentNumber()+"bomHeaderCode:"+bomHeaderCode+"bomLineCode:"+itemCode+"bomLevel:"+level); |
| | |
| | | bomLineList.forEach(line -> { |
| | | getBomRequires(plant, itemCode, line.getBomLineId(),line.getItemCode() ,line.getNum() , batchNum |
| | | , require.getStartDate(), plan, allRequires, nextLevel,stockDetailsList |
| | | ,orderDetailsList,usedStorage |
| | | ,orderDetailsList,usedStorage,subPlans |
| | | ); |
| | | }); |
| | | } |
| | |
| | | * 使用子件工单匹配需求中的净需求 |
| | | * */ |
| | | |
| | | private void matchRequireAndSubPlan(ApsPlateStandardRequire require, List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList) { |
| | | private void matchRequireAndSubPlan(ApsPlateStandardRequire require, List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList,Hashtable<String, List<ApsPlatePlan>> subPlans) { |
| | | BigDecimal netRequirement = require.getNetRequirement(); |
| | | require.setMatchMode("工单匹配"); |
| | | require.setMatchState("已匹配"); |
| | | if (netRequirement.compareTo(BigDecimal.ZERO) > 0) { |
| | | ApsPlatePlan platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode()); |
| | | ApsPlatePlan platePlan = apsPlatePlanService.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode(),subPlans); |
| | | /*子件工单的未匹配数量 作为当前的库存*/ |
| | | while (platePlan != null && netRequirement.compareTo(BigDecimal.ZERO) > 0) { |
| | | BigDecimal stock = platePlan.getUnmatchedQuantity(); |
| | |
| | | /* 库存数量 大于 净需求数量*/ |
| | | /* 净需求数量=0 ,子件工单未匹配数量= 库存-净需求*/ |
| | | BigDecimal subtract = stock.subtract(netRequirement); |
| | | platePlan.setUnmatchedQuantity(subtract); |
| | | platePlan.setVersion(platePlan.getVersion() + 1); |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement,orderDetailsList); |
| | | netRequirement = BigDecimal.ZERO; |
| | | |
| | |
| | | /*净需求数量 == 库存数量*/ |
| | | |
| | | BigDecimal subtract = BigDecimal.ZERO; |
| | | platePlan.setUnmatchedQuantity(subtract); |
| | | platePlan.setVersion(platePlan.getVersion() + 1); |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement,orderDetailsList); |
| | | netRequirement = BigDecimal.ZERO; |
| | | |
| | |
| | | /*需求大于库存*/ |
| | | /*净需求 被部分满足 */ |
| | | BigDecimal rest = netRequirement.subtract(stock); |
| | | |
| | | platePlan.setUnmatchedQuantity(BigDecimal.ZERO); |
| | | platePlan.setVersion(platePlan.getVersion() + 1); |
| | | /*工单 未匹配数量为0 全部用于匹配需求*/ |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, BigDecimal.ZERO, stock, netRequirement,orderDetailsList); |
| | | /*净需求未被满足,需要继续匹配*/ |
| | | platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode()); |
| | | platePlan = apsPlatePlanService.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode(),subPlans); |
| | | /*剩余净需求*/ |
| | | netRequirement = rest; |
| | | require.setUnmatchedDemandAmount(rest); |