| | |
| | | String batchNum= requireBatchService.getNewBatchNumber(); |
| | | /*获取钣金主单信息*/ |
| | | List<ApsPlatePlan> mainPlans = platePlanMapper.selectPlatePlanByPlantMajor(plantCode,mainOrderType); |
| | | Hashtable<String, BigDecimal> usedStorage = new Hashtable<>(); |
| | | Hashtable<String, ApsMaterialStorageManagement> usedStorage = new Hashtable<>(); |
| | | log.info("开始生成需求:"); |
| | | for (ApsPlatePlan mainPlan : mainPlans) { |
| | | String itemNumber = mainPlan.getItemNumber(); |
| | |
| | | apsPlateStandardRequireMapper.batchInsert(batch); |
| | | } |
| | | } |
| | | log.info("生成完成"); |
| | | // if(!stockDetailsList.isEmpty()){ |
| | | // int batchSize = 1000; |
| | | // stockDetailsList.forEach(x->x.setId(IdUtil.getSnowflakeNextId())); |
| | | // for (int i = 0; i < stockDetailsList.size(); i += batchSize) { |
| | | // int end = Math.min(i + batchSize, stockDetailsList.size()); |
| | | // List<ApsPlateStandardRequireBomStockDetail> batch = stockDetailsList.subList(i, end); |
| | | // plateBomStockDetailMapper.batchInsert(batch); |
| | | // } |
| | | // } |
| | | // |
| | | // if(!orderDetailsList.isEmpty()){ |
| | | // int batchSize = 1000; |
| | | // orderDetailsList.forEach(x->x.setId(IdUtil.getSnowflakeNextId())); |
| | | // for (int i = 0; i < orderDetailsList.size(); i += batchSize) { |
| | | // int end = Math.min(i + batchSize, orderDetailsList.size()); |
| | | // List<ApsPlateStandardRequireBomOrderDetail> batch = orderDetailsList.subList(i, end); |
| | | // plateBomOrderDetailMapper.batchInsert(batch); |
| | | // } |
| | | // } |
| | | /*集中保存库存信息*/ |
| | | /* if(!usedStorage.isEmpty()){ |
| | | usedStorage.forEach((key, sm) -> { |
| | | storageManagementService.updateRemainderStock(sm.getId(),sm.getRemainderStock(),sm.getVersion()); |
| | | }); |
| | | }*/ |
| | | |
| | | if(!stockDetailsList.isEmpty()){ |
| | | int batchSize = 1000; |
| | | stockDetailsList.forEach(x->x.setId(IdUtil.getSnowflakeNextId())); |
| | | for (int i = 0; i < stockDetailsList.size(); i += batchSize) { |
| | | int end = Math.min(i + batchSize, stockDetailsList.size()); |
| | | List<ApsPlateStandardRequireBomStockDetail> batch = stockDetailsList.subList(i, end); |
| | | plateBomStockDetailMapper.batchInsert(batch); |
| | | } |
| | | } |
| | | if(!orderDetailsList.isEmpty()){ |
| | | int batchSize = 1000; |
| | | orderDetailsList.forEach(x->x.setId(IdUtil.getSnowflakeNextId())); |
| | | for (int i = 0; i < orderDetailsList.size(); i += batchSize) { |
| | | int end = Math.min(i + batchSize, orderDetailsList.size()); |
| | | List<ApsPlateStandardRequireBomOrderDetail> batch = orderDetailsList.subList(i, end); |
| | | plateBomOrderDetailMapper.batchInsert(batch); |
| | | } |
| | | } |
| | | } |
| | | usedStorage.forEach((key,value)->{ |
| | | log.info("料号:"+key+",库存:"+value); |
| | | }); |
| | | |
| | | /*集中保存库存信息*/ |
| | | if(!usedStorage.isEmpty()){ |
| | | usedStorage.forEach((key, sm) -> { |
| | | storageManagementService.updateRemainderStock(sm.getId(),sm.getRemainderStock(),sm.getVersion()); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | List<ApsPlateStandardRequire> allRequires, |
| | | Long level,List<ApsPlateStandardRequireBomStockDetail> stockDetailsList, |
| | | List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList, |
| | | Hashtable<String, BigDecimal> usedStorage |
| | | Hashtable<String, ApsMaterialStorageManagement> usedStorage |
| | | ) { |
| | | /*构建需求信息*/ |
| | | ApsPlateStandardRequire require = new ApsPlateStandardRequire(); |
| | |
| | | /*默认净需求为BOM用量*/ |
| | | require.setNetRequirement(require.getRequireAmount()); |
| | | |
| | | |
| | | /*读取库存信息的优先级-> 内存、redis、db*/ |
| | | /* ApsMaterialStorageManagement storage = usedStorage.get(itemCode); |
| | | if(storage==null){ |
| | | storage = storageManagementService.getRdsStorage(plant, itemCode); |
| | | if(storage!=null){ |
| | | *//*剩余库存*//* |
| | | remainderStock = storage.getRemainderStock(); |
| | | } |
| | | }*/ |
| | | Optional<ApsMaterialStorageManagement> itemStorageOpt = storageManagementService.getItemStorage(plant, itemCode); |
| | | Optional<ApsMaterialStorageManagement> itemStorageOpt = Optional.ofNullable(usedStorage.get(itemCode)) ; |
| | | if(itemStorageOpt.isEmpty()){ |
| | | itemStorageOpt = storageManagementService.getRdsStorage(plant, itemCode); |
| | | } |
| | | if (itemStorageOpt.isPresent()) { |
| | | |
| | | ApsMaterialStorageManagement itemStorage=itemStorageOpt.get(); |
| | | BigDecimal remainderStock =itemStorage.getRemainderStock(); |
| | | /*计算净需求 默认=需求数量*/ |
| | |
| | | , afterStockAmount, require.getId(), stockDetailsList |
| | | ); |
| | | /*更新内存中的库存使用信息*/ |
| | | usedStorage.put(itemCode, afterStockAmount); |
| | | usedStorage.put(itemCode, itemStorage); |
| | | } |
| | | } |
| | | /*未匹配数量,默认为净需求*/ |