From 728621ba2f24bb9f41c7f2cd1c6cdc990247928c Mon Sep 17 00:00:00 2001
From: zhanghl <253316343@qq.com>
Date: 星期四, 15 五月 2025 16:58:36 +0800
Subject: [PATCH] 优化同步WorkOrder:先全部删除,再进行同步
---
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateStandardRequireServiceImpl.java | 113 ++++++++++++++++++++++++++++++--------------------------
1 files changed, 61 insertions(+), 52 deletions(-)
diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateStandardRequireServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateStandardRequireServiceImpl.java
index 2ab9146..e8178ce 100644
--- a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateStandardRequireServiceImpl.java
+++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateStandardRequireServiceImpl.java
@@ -64,7 +64,7 @@
ApsPlateStandardRequireBomOrderDetailMapper plateBomOrderDetailMapper;
@Autowired
- private ApsPlatePlanMapper apsPlatePlanMapper;
+ private IApsPlatePlanService apsPlatePlanService;
@Resource
IApsPlateStandardRequireBomOrderDetailService bomOrderDetailService;
@@ -175,20 +175,24 @@
String batchNum= requireBatchService.getNewBatchNumber();
/*鑾峰彇閽i噾涓诲崟淇℃伅*/
List<ApsPlatePlan> mainPlans = platePlanMapper.selectPlatePlanByPlantMajor(plantCode,mainOrderType);
- Hashtable<String, BigDecimal> usedStorage = new Hashtable<>();
+ 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
);
// 鎵归噺鎻掑叆浠ユ彁楂樻�ц兘
@@ -200,38 +204,40 @@
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());
+ });
+ }
+ if(!subPlans.isEmpty()){
+ subPlans.forEach((key, subPlansList) -> {
+ subPlansList.forEach(x->{
+ if (!x.getUnmatchedQuantity().equals(x.getProductionQuantity())){
+ platePlanMapper.updatePlanUnMatchQtyAndVersion(x);
+ }
+ });
+ });
+ }
}
/**
@@ -255,7 +261,8 @@
List<ApsPlateStandardRequire> allRequires,
Long level,List<ApsPlateStandardRequireBomStockDetail> stockDetailsList,
List<ApsPlateStandardRequireBomOrderDetail> orderDetailsList,
- Hashtable<String, BigDecimal> usedStorage
+ Hashtable<String, ApsMaterialStorageManagement> usedStorage,
+ Hashtable<String, List<ApsPlatePlan>> subPlans
) {
/*鏋勫缓闇�姹備俊鎭�*/
ApsPlateStandardRequire require = new ApsPlateStandardRequire();
@@ -285,17 +292,14 @@
/*榛樿鍑�闇�姹備负BOM鐢ㄩ噺*/
require.setNetRequirement(require.getRequireAmount());
+
/*璇诲彇搴撳瓨淇℃伅鐨勪紭鍏堢骇-> 鍐呭瓨銆乺edis銆乨b*/
- /* 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();
/*璁$畻鍑�闇�姹� 榛樿=闇�姹傛暟閲�*/
@@ -320,7 +324,7 @@
, afterStockAmount, require.getId(), stockDetailsList
);
/*鏇存柊鍐呭瓨涓殑搴撳瓨浣跨敤淇℃伅*/
- usedStorage.put(itemCode, afterStockAmount);
+ usedStorage.put(itemCode, itemStorage);
}
}
/*鏈尮閰嶆暟閲忥紝榛樿涓哄噣闇�姹�*/
@@ -377,7 +381,7 @@
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);
@@ -389,7 +393,7 @@
bomLineList.forEach(line -> {
getBomRequires(plant, itemCode, line.getBomLineId(),line.getItemCode() ,line.getNum() , batchNum
, require.getStartDate(), plan, allRequires, nextLevel,stockDetailsList
- ,orderDetailsList,usedStorage
+ ,orderDetailsList,usedStorage,subPlans
);
});
}
@@ -413,12 +417,12 @@
* 浣跨敤瀛愪欢宸ュ崟鍖归厤闇�姹備腑鐨勫噣闇�姹�
* */
- 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();
@@ -426,6 +430,8 @@
/* 搴撳瓨鏁伴噺 澶т簬 鍑�闇�姹傛暟閲�*/
/* 鍑�闇�姹傛暟閲�=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;
@@ -436,6 +442,8 @@
/*鍑�闇�姹傛暟閲� == 搴撳瓨鏁伴噺*/
BigDecimal subtract = BigDecimal.ZERO;
+ platePlan.setUnmatchedQuantity(subtract);
+ platePlan.setVersion(platePlan.getVersion() + 1);
bomOrderDetailService.savePlastPlanAndBomOrderDetail(require, platePlan, subtract, stock, netRequirement,orderDetailsList);
netRequirement = BigDecimal.ZERO;
@@ -446,11 +454,12 @@
/*闇�姹傚ぇ浜庡簱瀛�*/
/*鍑�闇�姹� 琚儴鍒嗘弧瓒� */
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);
--
Gitblit v1.9.3