From e3c02c03dd2de442bbced87236f60a13a1cd154e Mon Sep 17 00:00:00 2001
From: 高章伟 <gaozhangwei@prec-tech.com>
Date: 星期四, 02 三月 2023 17:51:57 +0800
Subject: [PATCH] gzw 正式环境最新代码更新
---
force-app/main/default/classes/PCLLostProduct2AssetHandler.cls | 428 +++++++++++++++++++++++++++--------------------------
1 files changed, 216 insertions(+), 212 deletions(-)
diff --git a/force-app/main/default/classes/PCLLostProduct2AssetHandler.cls b/force-app/main/default/classes/PCLLostProduct2AssetHandler.cls
index ef0d891..31594ae 100644
--- a/force-app/main/default/classes/PCLLostProduct2AssetHandler.cls
+++ b/force-app/main/default/classes/PCLLostProduct2AssetHandler.cls
@@ -1,229 +1,233 @@
/*
-* 杩欎釜瑙﹀彂鍣ㄩ渶瑕佹洿鏂板畬鍘嗗彶鏁版嵁鍚庢墠鑳介儴缃诧紝
-* 涓�銆佸垹闄ゆ椂璋冪敤鏂规硶锛屼紶鍏LD澶卞崟鍨嬪彿ID锛�
-* 1銆佹壘鍒版槸杩欎釜澶卞崟鍨嬪彿鐨勬墍鏈変繚鏈夎澶囷紝鍒犻櫎鎺夛紱
-* 2銆佽繖涓渶瑕佸仛鎴愬叡閫氭柟娉曪紝浼犺繘鏉ュけ鍗曟姤鍛婏紝鐒跺悗浠ヤ究涓夈��1浣跨敤锛�
-* 浜屻�佹彃鍏ユ椂璋冪敤鏂规硶锛屼紶鍏EW澶卞崟鍨嬪彿锛�
-* 杩欎釜涔熼渶瑕佸啓鎴愬叡閫氭柟娉曪紝浠ヤ緵涓夈��2浣跨敤锛�
-* 1銆佸墠鎻愶細
-* 1锛夊け鍗曞瀷鍙风殑鎶ュ憡鏄け鍗曟姤鍛婃垨鑰呴儴鍒嗗け鍗曟姤鍛婏紱
-* 2锛夊け鍗曞瀷鍙风殑璇环鎵�鍦ㄥ尰闄㈢殑璁板綍绫诲瀷鏄疕P锛�
-* 2銆佹壘鍒版彃鍏ユ墍鏈夊け鍗曞瀷鍙蜂腑鏈夊け鍗曚骇鍝佸瀷鍙风殑鏁版嵁锛�
-* 3銆佹牴鎹暟閲忕敓鎴愪繚鏈夎澶囷紝鎶婅繖涓繚鏈夎澶囩殑鍨嬪彿璁剧疆涓鸿繖涓繚鏈夎澶囷紱
-* 涓夈�佹洿鏂帮細
-* 1銆佸垹闄わ細
-* 1锛変粠鏈変骇鍝佸瀷鍙锋洿鏂颁负鏃犱骇鍝佸瀷鍙凤紱
-* 2锛夎皟鐢ㄤ竴鐨勬柟娉曪紝鍒犻櫎鎺変繚鏈夎澶囷紱
-* 2銆佹彃鍏ワ細
-* 1锛変粠鏃犱骇鍝佸瀷鍙锋洿鏂颁负鏈変骇鍝佸瀷鍙凤紱
-* 2锛夎皟鐢ㄤ簩鐨勬柟娉曟彃鍏ユ暟鎹紱
-* 3銆佹洿鏂帮細
-* 1锛夊鏋滀骇鍝佹垨鑰呮暟閲忓彂鐢熶簡鍙樺寲锛岃�屼笖绗﹀悎澶卞崟鍨嬪彿瀵规姤鍛婄殑闇�姹傦紱
-* 2锛夎皟鐢ㄥ洓鐨勬柟娉曟洿鏂颁繚鏈夎澶囷紱
-* 鍥涖�佹洿鏂拌皟鐢紝浼犲叆New澶卞崟鍨嬪彿 list浠ュ強map;
-* 1銆佹壘鍒拌繖涓け鍗曞瀷鍙稩D鐨勬墍鏈夊け鍗曚繚鏈夎澶囷紱
-* 2銆佸惊鐜瘡涓け鍗曚繚鏈夎澶囩殑澶卞崟鏁伴噺锛�
-* 1锛夊厛鐢ㄥ湪澶卞崟鏁伴噺涓嬬殑淇濇湁璁惧锛屽姣斾竴涓嬩骇鍝侊紝鏈夊彉鍖栧姞鍏ユ洿鏂版暟鎹鍒楋紱
-* 2锛夌敤瀹岃繖涓け鍗曚笅鐨勬墍鏈変繚鏈夎澶囷紝鎻掑叆澶卞崟璁惧锛�
-* 3銆佸惊鐜畬濡傛灉杩欎釜澶卞崟鎶ュ憡杩樻湁淇濇湁璁惧锛岃褰曚笅鏉ヤ互渚涘垹闄わ紱
-* 4銆佹彃鍏ュけ鍗曡澶囷紱
-* 5銆佹洿鏂拌澶囷紱
-* 6銆佸垹闄や繚鏈夎澶囷紱
-* */
+ * 杩欎釜瑙﹀彂鍣ㄩ渶瑕佹洿鏂板畬鍘嗗彶鏁版嵁鍚庢墠鑳介儴缃诧紝
+ * 涓�銆佸垹闄ゆ椂璋冪敤鏂规硶锛屼紶鍏LD澶卞崟鍨嬪彿ID锛�
+ * 1銆佹壘鍒版槸杩欎釜澶卞崟鍨嬪彿鐨勬墍鏈変繚鏈夎澶囷紝鍒犻櫎鎺夛紱
+ * 2銆佽繖涓渶瑕佸仛鎴愬叡閫氭柟娉曪紝浼犺繘鏉ュけ鍗曟姤鍛婏紝鐒跺悗浠ヤ究涓夈��1浣跨敤锛�
+ * 浜屻�佹彃鍏ユ椂璋冪敤鏂规硶锛屼紶鍏EW澶卞崟鍨嬪彿锛�
+ * 杩欎釜涔熼渶瑕佸啓鎴愬叡閫氭柟娉曪紝浠ヤ緵涓夈��2浣跨敤锛�
+ * 1銆佸墠鎻愶細
+ * 1锛夊け鍗曞瀷鍙风殑鎶ュ憡鏄け鍗曟姤鍛婃垨鑰呴儴鍒嗗け鍗曟姤鍛婏紱
+ * 2锛夊け鍗曞瀷鍙风殑璇环鎵�鍦ㄥ尰闄㈢殑璁板綍绫诲瀷鏄疕P锛�
+ * 2銆佹壘鍒版彃鍏ユ墍鏈夊け鍗曞瀷鍙蜂腑鏈夊け鍗曚骇鍝佸瀷鍙风殑鏁版嵁锛�
+ * 3銆佹牴鎹暟閲忕敓鎴愪繚鏈夎澶囷紝鎶婅繖涓繚鏈夎澶囩殑鍨嬪彿璁剧疆涓鸿繖涓繚鏈夎澶囷紱
+ * 涓夈�佹洿鏂帮細
+ * 1銆佸垹闄わ細
+ * 1锛変粠鏈変骇鍝佸瀷鍙锋洿鏂颁负鏃犱骇鍝佸瀷鍙凤紱
+ * 2锛夎皟鐢ㄤ竴鐨勬柟娉曪紝鍒犻櫎鎺変繚鏈夎澶囷紱
+ * 2銆佹彃鍏ワ細
+ * 1锛変粠鏃犱骇鍝佸瀷鍙锋洿鏂颁负鏈変骇鍝佸瀷鍙凤紱
+ * 2锛夎皟鐢ㄤ簩鐨勬柟娉曟彃鍏ユ暟鎹紱
+ * 3銆佹洿鏂帮細
+ * 1锛夊鏋滀骇鍝佹垨鑰呮暟閲忓彂鐢熶簡鍙樺寲锛岃�屼笖绗﹀悎澶卞崟鍨嬪彿瀵规姤鍛婄殑闇�姹傦紱
+ * 2锛夎皟鐢ㄥ洓鐨勬柟娉曟洿鏂颁繚鏈夎澶囷紱
+ * 鍥涖�佹洿鏂拌皟鐢紝浼犲叆New澶卞崟鍨嬪彿 list浠ュ強map;
+ * 1銆佹壘鍒拌繖涓け鍗曞瀷鍙稩D鐨勬墍鏈夊け鍗曚繚鏈夎澶囷紱
+ * 2銆佸惊鐜瘡涓け鍗曚繚鏈夎澶囩殑澶卞崟鏁伴噺锛�
+ * 1锛夊厛鐢ㄥ湪澶卞崟鏁伴噺涓嬬殑淇濇湁璁惧锛屽姣斾竴涓嬩骇鍝侊紝鏈夊彉鍖栧姞鍏ユ洿鏂版暟鎹鍒楋紱
+ * 2锛夌敤瀹岃繖涓け鍗曚笅鐨勬墍鏈変繚鏈夎澶囷紝鎻掑叆澶卞崟璁惧锛�
+ * 3銆佸惊鐜畬濡傛灉杩欎釜澶卞崟鎶ュ憡杩樻湁淇濇湁璁惧锛岃褰曚笅鏉ヤ互渚涘垹闄わ紱
+ * 4銆佹彃鍏ュけ鍗曡澶囷紱
+ * 5銆佹洿鏂拌澶囷紱
+ * 6銆佸垹闄や繚鏈夎澶囷紱
+ * */
public without sharing class PCLLostProduct2AssetHandler extends Oly_TriggerHandler {
- private Map<Id, PCLLostProduct__c> newMap;
- private Map<Id, PCLLostProduct__c> oldMap;
- private List<PCLLostProduct__c> newList;
- private List<PCLLostProduct__c> oldList;
- public PCLLostProduct2AssetHandler() {
- this.newMap = (Map<Id, PCLLostProduct__c>) Trigger.newMap;
- this.oldMap = (Map<Id, PCLLostProduct__c>) Trigger.oldMap;
- this.newList = (List<PCLLostProduct__c>) Trigger.new;
- this.oldList = (List<PCLLostProduct__c>) Trigger.old;
- }
- protected override void afterUpdate() {
- updateProduct2Asset(newList,oldMap);
- }
+ private Map<Id, PCLLostProduct__c> newMap;
+ private Map<Id, PCLLostProduct__c> oldMap;
+ private List<PCLLostProduct__c> newList;
+ private List<PCLLostProduct__c> oldList;
+ public PCLLostProduct2AssetHandler() {
+ this.newMap = (Map<Id, PCLLostProduct__c>) Trigger.newMap;
+ this.oldMap = (Map<Id, PCLLostProduct__c>) Trigger.oldMap;
+ this.newList = (List<PCLLostProduct__c>) Trigger.new;
+ this.oldList = (List<PCLLostProduct__c>) Trigger.old;
+ }
+ protected override void afterUpdate() {
+ updateProduct2Asset(newList,oldMap);
+ }
- protected override void afterInsert() {
- insertLostAsset(newList);
- }
- protected override void beforedelete() {
- deleteLostAsset(oldMap.keySet());
- }
+ protected override void afterInsert() {
+ insertLostAsset(newList);
+ }
+ protected override void beforedelete() {
+ deleteLostAsset(oldMap.keySet());
+ }
- private void deleteLostAsset( set<id> oldIDList){
- list<Asset> delAstList = new list<Asset>();
- if(oldIDList.size()> 0){
- delAstList =
- [select id
- from asset
- where LostProduct__c in: oldIDList];
- }
- if(delAstList.size() > 0){
- delete delAstList;
- }
- }
+ private void deleteLostAsset( set<id> oldIDList){
+ list<Asset> delAstList = new list<Asset>();
+ if(oldIDList.size()> 0) {
+ delAstList =
+ [select id
+ from asset
+ where LostProduct__c in: oldIDList];
+ }
+ if(delAstList.size() > 0) {
+ delete delAstList;
+ }
+ }
- private void insertLostAsset(List<PCLLostProduct__c> newList){
- list<asset> InsertAssetlist = new list<asset>();
- for (PCLLostProduct__c LostProduct : newList) {
- // 閮ㄥ垎澶卞崟鎴栧け鍗曟姤鍛婂瀷鍙疯�屼笖璇环涓婄殑鍖婚櫌鐪熸槸鍖婚櫌
- if ((LostProduct.lcrRecordType_DevName__c == 'PCL_Lost_report' ||
- LostProduct.lcrRecordType_DevName__c == 'PCL_PartLost_report'
- ) && LostProduct.HP_RecordType_DevName__c == 'HP'
- && string.isNotBlank(LostProduct.LostProduct__c))
- {
- for(integer i = 0;i <integer.valueof(lostProduct.Quantity__c);i++){
- InsertAssetlist.add(buildAsset (lostProduct));
- }
- }
- }
- if(InsertAssetlist.size() > 0){
- insert InsertAssetlist;
- }
- }
- private void updateProduct2Asset(List<PCLLostProduct__c> newList,
- Map<Id, PCLLostProduct__c> oldMap){
- // 瑕佽鍒犻櫎鏁版嵁鐨処D鐨剆et
- set<id> oldDelIDList = new set<id>();
- // 瑕佽鎻掑叆鐨勪繚鏈夎澶囩殑澶卞崟鍨嬪彿鐨刵ew鐨刲ist
- list<PCLLostProduct__c> newInsertList =
- new list<PCLLostProduct__c>();
- //闇�瑕佽蛋鏇存柊娴佺▼鐨勫け鍗曞瀷鍙�
- List<PCLLostProduct__c> newUpdateList =
- new List<PCLLostProduct__c>();
- //闇�瑕佽蛋鏇存柊娴佺▼鐨勫け鍗曞瀷鍙稩DSet
- set<ID> newUpIDSet = new set<ID>();
+ private void insertLostAsset(List<PCLLostProduct__c> newList){
+ list<asset> InsertAssetlist = new list<asset>();
+ for (PCLLostProduct__c LostProduct : newList) {
+ // 閮ㄥ垎澶卞崟鎴栧け鍗曟姤鍛婂瀷鍙疯�屼笖璇环涓婄殑鍖婚櫌鐪熸槸鍖婚櫌
+ if ((LostProduct.lcrRecordType_DevName__c == 'PCL_Lost_report' ||
+ LostProduct.lcrRecordType_DevName__c == 'PCL_PartLost_report'
+ ) && LostProduct.HP_RecordType_DevName__c == 'HP'
+ && string.isNotBlank(LostProduct.LostProduct__c))
+ {
+ for(integer i = 0; i <integer.valueof(lostProduct.Quantity__c); i++) {
+ InsertAssetlist.add(buildAsset (lostProduct));
+ }
+ }
+ }
- // for寰幆锛屽垽鏂摢浜涢渶瑕佸鍔犮�佸垹闄ゆ垨鏇存柊
- for( PCLLostProduct__c NewLsP : newList){
- PCLLostProduct__c oldLsP = oldMap.get(NewLsP.id);
- //1銆佷骇鍝佸瀷鍙锋湁鍊煎彉涓轰骇鍝佸瀷鍙蜂负绌猴紝闇�瑕佸垹闄わ紱
- if(string.isNotBlank(oldLsP.LostProduct__c) &&
- string.isBlank(NewLsP.LostProduct__c)){
- oldDelIDList.add(NewLsP.id);
- }
- //2銆佷骇鍝佸瀷鍙蜂负绌哄彉涓轰骇鍝佸瀷鍙锋湁鍊硷紝闇�瑕佹彃鍏ュけ鍗曚繚鏈夎澶囷紱
- if(string.isBlank(oldLsP.LostProduct__c) &&
- string.isNotBlank(NewLsP.LostProduct__c)){
- newInsertList.add(NewLsP);
- }
- // 3銆佸鏋�
- // 1锛夋柊澶卞崟鍨嬪彿鎵�鍦ㄧ殑鎶ュ憡鏄け鍗曟姤鍛婃垨鑰呴儴鍒嗗け鍗曟姤鍛婏紱
- // 2锛夋墍鍦ㄨ浠风殑鍖婚櫌鏄尰闄�
- // 3锛夊け鍗曞瀷鍙蜂骇鍝佷笉涓虹┖锛�
- // 4锛変骇鍝佹洿鏀规垨鑰呮暟閲忔洿鏀癸紱
- // 閭d箞鏄渶瑕佹洿鏂扮殑鏁版嵁
- if ((NewLsP.lcrRecordType_DevName__c == 'PCL_Lost_report'
- || NewLsP.lcrRecordType_DevName__c == 'PCL_PartLost_report'
- ) && NewLsP.HP_RecordType_DevName__c == 'HP'
- && string.isNotBlank(NewLsP.LostProduct__c)
- && ( NewLsP.LostProduct__c != oldLsP.LostProduct__c
- || NewLsP.Quantity__c != oldLsP.Quantity__c
- )
- )
- {
- newUpdateList.add(NewLsP);
- newUpIDSet.add(NewLsP.Id);
- }
+ if(InsertAssetlist.size() > 0) {
+ insert InsertAssetlist;
+ }
+ }
+ private void updateProduct2Asset(List<PCLLostProduct__c> newList,
+ Map<Id, PCLLostProduct__c> oldMap){
+ // 瑕佽鍒犻櫎鏁版嵁鐨処D鐨剆et
+ set<id> oldDelIDList = new set<id>();
+ // 瑕佽鎻掑叆鐨勪繚鏈夎澶囩殑澶卞崟鍨嬪彿鐨刵ew鐨刲ist
+ list<PCLLostProduct__c> newInsertList =
+ new list<PCLLostProduct__c>();
+ //闇�瑕佽蛋鏇存柊娴佺▼鐨勫け鍗曞瀷鍙�
+ List<PCLLostProduct__c> newUpdateList =
+ new List<PCLLostProduct__c>();
+ //闇�瑕佽蛋鏇存柊娴佺▼鐨勫け鍗曞瀷鍙稩DSet
+ set<ID> newUpIDSet = new set<ID>();
- }
+ // for寰幆锛屽垽鏂摢浜涢渶瑕佸鍔犮�佸垹闄ゆ垨鏇存柊
+ for( PCLLostProduct__c NewLsP : newList) {
+ PCLLostProduct__c oldLsP = oldMap.get(NewLsP.id);
+ //1銆佷骇鍝佸瀷鍙锋湁鍊煎彉涓轰骇鍝佸瀷鍙蜂负绌猴紝闇�瑕佸垹闄わ紱
+ if(string.isNotBlank(oldLsP.LostProduct__c) &&
+ string.isBlank(NewLsP.LostProduct__c)) {
+ oldDelIDList.add(NewLsP.id);
+ }
+ //2銆佷骇鍝佸瀷鍙蜂负绌哄彉涓轰骇鍝佸瀷鍙锋湁鍊硷紝闇�瑕佹彃鍏ュけ鍗曚繚鏈夎澶囷紱
+ if(string.isBlank(oldLsP.LostProduct__c) &&
+ string.isNotBlank(NewLsP.LostProduct__c)) {
+ newInsertList.add(NewLsP);
+ }
+ // 3銆佸鏋�
+ // 1锛夋柊澶卞崟鍨嬪彿鎵�鍦ㄧ殑鎶ュ憡鏄け鍗曟姤鍛婃垨鑰呴儴鍒嗗け鍗曟姤鍛婏紱
+ // 2锛夋墍鍦ㄨ浠风殑鍖婚櫌鏄尰闄�
+ // 3锛夊け鍗曞瀷鍙蜂骇鍝佷笉涓虹┖锛�
+ // 4锛変骇鍝佹洿鏀规垨鑰呮暟閲忔洿鏀癸紱
+ // 閭d箞鏄渶瑕佹洿鏂扮殑鏁版嵁
+ if ((NewLsP.lcrRecordType_DevName__c == 'PCL_Lost_report'
+ || NewLsP.lcrRecordType_DevName__c == 'PCL_PartLost_report'
+ ) && NewLsP.HP_RecordType_DevName__c == 'HP'
+ && string.isNotBlank(NewLsP.LostProduct__c)
+ && ( NewLsP.LostProduct__c != oldLsP.LostProduct__c
+ || NewLsP.Quantity__c != oldLsP.Quantity__c
+ )
+ )
+ {
+ newUpdateList.add(NewLsP);
+ newUpIDSet.add(NewLsP.Id);
+ }
- // 鍒犻櫎鏁版嵁
- if(oldDelIDList.size() > 0){
- deleteLostAsset(oldDelIDList);
- }
- // 鎻掑叆鏁版嵁
- if(newInsertList.size()>0){
- insertLostAsset(newInsertList);
- }
- // 鏇存柊鏁版嵁
- if(newUpdateList.size()>0){
- updateLsAHandler(newUpdateList,newUpIDSet);
- }
+ }
- }
+ // 鍒犻櫎鏁版嵁
+ if(oldDelIDList.size() > 0) {
+ deleteLostAsset(oldDelIDList);
+ }
+ // 鎻掑叆鏁版嵁
+ if(newInsertList.size()>0) {
+ insertLostAsset(newInsertList);
+ }
+ // 鏇存柊鏁版嵁
+ if(newUpdateList.size()>0) {
+ updateLsAHandler(newUpdateList,newUpIDSet);
+ }
- private void updateLsAHandler(List<PCLLostProduct__c> newList,set<Id> newIDSet) {
+ }
- //闇�瑕佹彃鍏ュ拰鏇存柊鐨勪繚鏈夎澶囨暟鎹�
- list<asset> upsertAstList = new List<asset>();
+ private void updateLsAHandler(List<PCLLostProduct__c> newList,set<Id> newIDSet) {
- //闇�瑕佸垹闄ょ殑淇濇湁璁惧鏁版嵁
- list<asset> delAstList = new List<asset>();
+ //闇�瑕佹彃鍏ュ拰鏇存柊鐨勪繚鏈夎澶囨暟鎹�
+ list<asset> upsertAstList = new List<asset>();
- // 鏋勫缓map锛屼互渚垮垽鏂槸鍚﹂渶瑕佸垹闄ゆ垨鑰呮洿鏂板凡鏈変繚鏈夎澶囷紱
- map<id, list<asset>> LsPID2Asset = new map<id, list<asset>>();
+ //闇�瑕佸垹闄ょ殑淇濇湁璁惧鏁版嵁
+ list<asset> delAstList = new List<asset>();
- // 妫�绱㈣繖涓け鍗曞瀷鍙蜂笅闈㈡墍鏈変繚鏈夐」鐩�
- list<asset> oldAssetList = [
- select id, LostProduct__c, Product2Id,
- Status, Asset_Owner__c, IsCompetitorProduct
- from asset
- where LostProduct__c in : newIDSet
- ];
+ // 鏋勫缓map锛屼互渚垮垽鏂槸鍚﹂渶瑕佸垹闄ゆ垨鑰呮洿鏂板凡鏈変繚鏈夎澶囷紱
+ map<id, list<asset> > LsPID2Asset = new map<id, list<asset> >();
- for(asset tempAst: oldAssetList){
- list<asset> tempAstList = new List<asset>();
- if(LsPID2Asset.containsKey(tempAst.LostProduct__c)){
- tempAstList = LsPID2Asset.get(tempAst.LostProduct__c);
- }
- tempAstList.add(tempAst);
- LsPID2Asset.put(tempAst.LostProduct__c, tempAstList);
- }
- // 寰幆鐜版湁澶卞崟鍨嬪彿锛�
- for(PCLLostProduct__c tempLsP : newList){
- // 鑾峰彇褰撳墠澶卞崟鍨嬪彿鐨勬墍鏈夊け鍗曚繚鏈夎澶�
- list<asset> tempAstList = LsPID2Asset.get( tempLsP.id );
- for(integer i = 0; i < integer.valueOf(tempLsP.Quantity__c); i++){
- asset tempAst = buildAsset(tempLsP);
- // 濡傛灉褰撳墠澶卞崟鍨嬪彿杩樻湁鍊硷紝閭d箞鑾峰彇涓�涓洿鏂帮紝鍚﹀垯灏辨彃鍏�
- if(tempAstList !=null && tempAstList.size() > 0){
- asset oldAst = tempAstList.remove(0);
- // 濡傛灉鍙戠敓鍙樺寲浠ュ悗锛屾墠闇�瑕佹洿鏂�
- if(tempAst.Product2Id != oldAst.Product2Id ||
- tempAst.Status != oldAst.Status ||
- tempAst.Asset_Owner__c != oldAst.Asset_Owner__c ||
- tempAst.IsCompetitorProduct != oldAst.IsCompetitorProduct
- ){
- tempAst.id = oldAst.id;
- upsertAstList.add(tempAst);
- }
- }
- else{
- upsertAstList.add(tempAst);
- }
- }
- // 濡傛灉杩樻湁澶氬嚭鏉ョ殑锛岄偅涔堣繖浜涘氨鏄渶瑕佸垹闄ょ殑澶卞崟淇濇湁璁惧
- if(tempAstList !=null && tempAstList.size()> 0){
- delAstList.addAll(tempAstList);
- }
- }
- // 鎻掑叆鎴栬�呮洿鏂板け鍗曚繚鏈夎澶�
- if(upsertAstList.size() > 0){
- upsert upsertAstList;
- }
- // 鍒犻櫎澶氱殑澶卞崟淇濇湁璁惧
- if(delAstList.size() > 0){
- delete delAstList;
- }
- }
+ // 妫�绱㈣繖涓け鍗曞瀷鍙蜂笅闈㈡墍鏈変繚鏈夐」鐩�
+ list<asset> oldAssetList = [
+ select id, LostProduct__c, Product2Id,
+ Status, Asset_Owner__c, IsCompetitorProduct
+ from asset
+ where LostProduct__c in : newIDSet
+ ];
- private asset buildAsset(PCLLostProduct__c LostProduct){
- Asset Ast = new Asset(
- Name = '*',
- Product2Id = LostProduct.LostProduct__c,
- Opportunity__c = LostProduct.Opportunity__c,
- InstallDate = LostProduct.Submit_Day__c,
- Hospital__c = LostProduct.LostHP__c,
- Department_Class__c = LostProduct.LostDepartment_Class__c,
- AccountId = LostProduct.LostAccount__c,
- Status = '浣跨敤涓�',
- Asset_Owner__c = '鐥呴櫌璩囩敚',
- IsCompetitorProduct = True,
- LostProduct__c = LostProduct.id
- );
- return ast;
- }
+ for(asset tempAst: oldAssetList) {
+ list<asset> tempAstList = new List<asset>();
+ if(LsPID2Asset.containsKey(tempAst.LostProduct__c)) {
+ tempAstList = LsPID2Asset.get(tempAst.LostProduct__c);
+ }
+ tempAstList.add(tempAst);
+ LsPID2Asset.put(tempAst.LostProduct__c, tempAstList);
+ }
+ // 寰幆鐜版湁澶卞崟鍨嬪彿锛�
+ for(PCLLostProduct__c tempLsP : newList) {
+ // 鑾峰彇褰撳墠澶卞崟鍨嬪彿鐨勬墍鏈夊け鍗曚繚鏈夎澶�
+ list<asset> tempAstList = LsPID2Asset.get( tempLsP.id );
+ for(integer i = 0; i < integer.valueOf(tempLsP.Quantity__c); i++) {
+ asset tempAst = buildAsset(tempLsP);
+ // 濡傛灉褰撳墠澶卞崟鍨嬪彿杩樻湁鍊硷紝閭d箞鑾峰彇涓�涓洿鏂帮紝鍚﹀垯灏辨彃鍏�
+ if(tempAstList !=null && tempAstList.size() > 0) {
+ asset oldAst = tempAstList.remove(0);
+ // 濡傛灉鍙戠敓鍙樺寲浠ュ悗锛屾墠闇�瑕佹洿鏂�
+ if(tempAst.Product2Id != oldAst.Product2Id ||
+ tempAst.Status != oldAst.Status ||
+ tempAst.Asset_Owner__c != oldAst.Asset_Owner__c ||
+ tempAst.IsCompetitorProduct != oldAst.IsCompetitorProduct
+ ) {
+ tempAst.id = oldAst.id;
+ upsertAstList.add(tempAst);
+ }
+ }
+ else{
+ upsertAstList.add(tempAst);
+ }
+ }
+ // 濡傛灉杩樻湁澶氬嚭鏉ョ殑锛岄偅涔堣繖浜涘氨鏄渶瑕佸垹闄ょ殑澶卞崟淇濇湁璁惧
+ if(tempAstList !=null && tempAstList.size()> 0) {
+ delAstList.addAll(tempAstList);
+ }
+ }
+ // 鎻掑叆鎴栬�呮洿鏂板け鍗曚繚鏈夎澶�
+ if(upsertAstList.size() > 0) {
+ upsert upsertAstList;
+ }
+ // 鍒犻櫎澶氱殑澶卞崟淇濇湁璁惧
+ if(delAstList.size() > 0) {
+ delete delAstList;
+ }
+ }
+
+ private asset buildAsset(PCLLostProduct__c LostProduct){
+ Asset Ast = new Asset(
+ Name = '*',
+ // CHAN-CCR6MW gzw 銆愬鎵樸�戙�愪繚鏈夎澶囥�戜繚鏈夎澶囧彂璐ф棩閫昏緫 start
+ Posting_Date__c = Date.today(),
+ // CHAN-CCR6MW gzw 銆愬鎵樸�戙�愪繚鏈夎澶囥�戜繚鏈夎澶囧彂璐ф棩閫昏緫 end
+ Product2Id = LostProduct.LostProduct__c,
+ Opportunity__c = LostProduct.Opportunity__c,
+ InstallDate = LostProduct.Submit_Day__c,
+ Hospital__c = LostProduct.LostHP__c,
+ Department_Class__c = LostProduct.LostDepartment_Class__c,
+ AccountId = LostProduct.LostAccount__c,
+ Status = '浣跨敤涓�',
+ Asset_Owner__c = '鐥呴櫌璩囩敚',
+ IsCompetitorProduct = True,
+ LostProduct__c = LostProduct.id
+ );
+ return ast;
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1