| | |
| | | String itemNumber = mainPlan.getItemNumber(); |
| | | /*根据料号 获取BOM Header */ |
| | | /*当前Bom节点处理完成后,处理下级BOM*/ |
| | | List<ApsBom> bomLineList = bomLineService.selectApsBomLineList(plantCode, itemNumber); |
| | | |
| | | List<ApsPlateStandardRequire> requiresList=new ArrayList<>(); |
| | | if(!bomLineList.isEmpty()){ |
| | | bomLineList.forEach(line -> { |
| | | getBomRequires(plantCode, line, batchNum, null, mainPlan, requiresList, 0L); |
| | | }); |
| | | } |
| | | |
| | | getBomRequires(plantCode, "0","0",itemNumber,BigDecimal.ONE, batchNum, null, mainPlan, requiresList, 0L); |
| | | |
| | | // 批量插入以提高性能 |
| | | if (!requiresList.isEmpty()) { |
| | | int batchSize = 1000; |
| | |
| | | |
| | | /** |
| | | * 构建需求信息 |
| | | * */ |
| | | private void getBomRequires(String plant, ApsBom bomLine, String batchNum, Date upLevelStartDate, ApsPlatePlan plan, List<ApsPlateStandardRequire> allRequires, Long level) { |
| | | |
| | | String itemNumber = bomLine.getItemCode(); |
| | | * |
| | | * @param plant 工厂代码 |
| | | * @param bomHeaderCode BOM上级物料编码 |
| | | * @param bomLineId BOM行ID |
| | | * @param itemCode 物料代码 |
| | | * @param itemNum 物料数量 |
| | | * @param batchNum 批次号 |
| | | * @param upLevelStartDate 上级工序的开始日期 |
| | | * @param plan 计划对象 |
| | | * @param allRequires 所有需求的列表 |
| | | * @param level 层级 |
| | | */ |
| | | private void getBomRequires(String plant, String bomHeaderCode, String bomLineId,String itemCode,BigDecimal itemNum, String batchNum, Date upLevelStartDate, ApsPlatePlan plan, List<ApsPlateStandardRequire> allRequires, Long level) { |
| | | /*构建需求信息*/ |
| | | ApsPlateStandardRequire require = new ApsPlateStandardRequire(); |
| | | require.setId(IdUtil.getSnowflakeNextId()); |
| | |
| | | require.setBatchNumber(batchNum); |
| | | require.setDocNum(plan.getDocumentNumber()); |
| | | require.setOrgCode(plant); |
| | | require.setBomLineCode(itemNumber); |
| | | require.setBomHeaderCode(bomHeaderCode); |
| | | require.setBomLineId(bomLineId); |
| | | require.setBomLineCode(itemCode); |
| | | require.setBomLineLevel(level); |
| | | require.setBomUseAmount(bomLine.getNum()); |
| | | require.setBomUseAmount(itemNum); |
| | | require.setCreateTime(DateUtils.getNowDate()); |
| | | require.setCreateBy(SecurityUtils.getUsername()); |
| | | require.setDelFlag("0"); |
| | | require.setProductionBase(plan.getProductionBase()); |
| | | /*计算需求数量*/ |
| | | if (level == 0) { |
| | | require.setBomUseAmount(BigDecimal.ONE); |
| | | require.setCompleteDate(plan.getPlanEndDay()); |
| | | require.setDemandDate(plan.getPlanEndDay()); |
| | | } else { |
| | | require.setBomUseAmount(bomLine.getNum().multiply(plan.getProductionQuantity())); |
| | | require.setBomUseAmount(itemNum.multiply(plan.getProductionQuantity())); |
| | | } |
| | | /*查找库存,计算净需求,保存剩余库存,保存库存扣减明细*/ |
| | | BigDecimal remainderStock = BigDecimal.ZERO; |
| | | /*默认净需求为BOM用量*/ |
| | | require.setNetRequirement(require.getBomUseAmount()); |
| | | Optional<ApsMaterialStorageManagement> itemStorage = getItemStorage(plant, itemNumber); |
| | | Optional<ApsMaterialStorageManagement> itemStorage = getItemStorage(plant, itemCode); |
| | | if (itemStorage.isPresent()) { |
| | | ApsMaterialStorageManagement storage = itemStorage.get(); |
| | | /*剩余库存*/ |
| | |
| | | afterStockAmount = remainderStock.subtract(deductionAmount); |
| | | require.setNetRequirement(BigDecimal.ZERO); |
| | | } |
| | | bomStockDetailService.saveStorageAndDetail(storage, plan, bomLine, batchNum, deductionAmount, afterStockAmount,require.getId()); |
| | | /*记录库存剩余数量,记录库存使用记录*/ |
| | | bomStockDetailService.saveStorageAndDetail(storage, plan, bomLineId,itemCode, batchNum, deductionAmount, afterStockAmount,require.getId()); |
| | | } |
| | | } |
| | | |
| | | /*未匹配数量,默认为净需求*/ |
| | | require.setUnmatchedDemandAmount(require.getNetRequirement()); |
| | | /*工艺路线总需求*/ |
| | | ApsStandardProcessRouteLine routeHeader = routeLineService.getRouteLineTotalTime(require); |
| | | String routeId = routeHeader.getRouteId(); |
| | |
| | | allRequires.add(require); |
| | | if (require.getNetRequirement().compareTo(BigDecimal.ZERO) > 0) { |
| | | /*当前Bom节点处理完成后,处理下级BOM*/ |
| | | List<ApsBom> bomLineList = bomLineService.selectApsBomLineList(plant, itemNumber); |
| | | long nextLevel=level+1; |
| | | List<ApsBom> bomLineList = bomLineService.selectApsBomLineList(plant, itemCode); |
| | | if (!bomLineList.isEmpty()) { |
| | | bomLineList.forEach(line -> { |
| | | getBomRequires(plant, line, batchNum, require.getStartDate(), plan, allRequires, level + 1); |
| | | getBomRequires(plant, itemCode, line.getBomLineId(),line.getItemCode() ,line.getNum() , batchNum, require.getStartDate(), plan, allRequires, nextLevel); |
| | | }); |
| | | } |
| | | } |
| | |
| | | |
| | | private void matchRequireAndSubPlan(ApsPlateStandardRequire require) { |
| | | BigDecimal netRequirement = require.getNetRequirement(); |
| | | require.setMatchMode("工单匹配"); |
| | | if (netRequirement.compareTo(BigDecimal.ZERO) > 0) { |
| | | ApsPlatePlan platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode()); |
| | | ApsPlatePlan platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode()); |
| | | /*子件工单的未匹配数量 作为当前的库存*/ |
| | | while (platePlan != null && netRequirement.compareTo(BigDecimal.ZERO) > 0) { |
| | | BigDecimal stock = platePlan.getUnmatchedQuantity(); |
| | | if (netRequirement.compareTo(stock) < 0) { |
| | | /* 库存数量 大于 净需求数量*/ |
| | | /* 净需求数量=0 ,子件工单未匹配数量= 库存-净需求*/ |
| | | netRequirement = BigDecimal.ZERO; |
| | | require.setNetRequirement(netRequirement); |
| | | BigDecimal subtract = stock.subtract(netRequirement); |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement); |
| | | netRequirement = BigDecimal.ZERO; |
| | | require.setMatchState("已匹配"); |
| | | require.setUnmatchedDemandAmount(netRequirement); |
| | | /*净需求已经被满足,不需要继续匹配*/ |
| | | |
| | | } else if (netRequirement.compareTo(stock) == 0) { |
| | | /*净需求数量 == 库存数量*/ |
| | | netRequirement = BigDecimal.ZERO; |
| | | require.setNetRequirement(netRequirement); |
| | | |
| | | BigDecimal subtract = BigDecimal.ZERO; |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement); |
| | | netRequirement = BigDecimal.ZERO; |
| | | require.setMatchState("已匹配"); |
| | | require.setUnmatchedDemandAmount(netRequirement); |
| | | /*净需求已经被满足,不需要继续匹配*/ |
| | | } |
| | | if (netRequirement.compareTo(stock) > 0) { |
| | | /*需求大于库存*/ |
| | | /*净需求 被部分满足 */ |
| | | BigDecimal rest = netRequirement.subtract(stock); |
| | | require.setNetRequirement(rest); |
| | | require.setMatchState("匹配中"); |
| | | /*工单 未匹配数量为0 全部用于匹配需求*/ |
| | | bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, BigDecimal.ZERO, stock, netRequirement); |
| | | /*净需求未被满足,需要继续匹配*/ |
| | | platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode()); |
| | | platePlan = apsPlatePlanMapper.selectUnMatchPlateSubPlan(require.getOrgCode(), require.getBomLineCode()); |
| | | /*剩余净需求*/ |
| | | netRequirement = rest; |
| | | require.setUnmatchedDemandAmount(netRequirement); |
| | | } |
| | | } |
| | | } |