From 5835379ec30b1667c4e522db9d294c9b7bb8633a Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期二, 26 四月 2022 12:00:31 +0800
Subject: [PATCH] SSBG Back up
---
force-app/main/default/classes/Product2TriggerHandler.cls | 233 ++++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 169 insertions(+), 64 deletions(-)
diff --git a/force-app/main/default/classes/Product2TriggerHandler.cls b/force-app/main/default/classes/Product2TriggerHandler.cls
index eb132ba..56fff4f 100644
--- a/force-app/main/default/classes/Product2TriggerHandler.cls
+++ b/force-app/main/default/classes/Product2TriggerHandler.cls
@@ -46,77 +46,182 @@
}
}
+ //鐢ㄤ簬闄嶇被
public static void checkProduct2Level(List<Product2> newList, Map<Id, Product2> newMap, List<Product2> oldList, Map<Id, Product2> oldMap) {
- if(Trigger.isBefore && (Trigger.isInsert || Trigger.isUpdate)){
- List<String> p2ids = new List<String>();
- for(Product2 p2 : newList)
- {
- p2ids.add(p2.id);
- }
+ //鍙栦骇鍝乮d
+ List<String> p2ids = new List<String>();
+ for(Product2 p2 : newList)
+ {
+ p2ids.add(p2.id);
+ }
- //瀛樻斁鏌ユ壘鐨剆oql鏂�
- List<Product_Register_Link__c> pro2List = new List<Product_Register_Link__c>();
- pro2List = [select Product2__r.id,Product2__r.demoteer_Sap__c,Product_Register__r.MedPrdClass__c,Product_Register__r.ValidTo__c,Product_Register__r.ValidFrom__c
- from Product_Register_Link__c
- where Product2__r.Id in : p2ids];
- System.debug('pro2List='+pro2List);
- //瀛樻斁浜у搧鐨刬d鍜岀瓑绾х被鍒瓧娈电殑鍊肩殑闆嗗悎
- Map<Id,List<String>> pro2Map = new Map<Id,List<String>>();
- if (pro2List.size()>0) {
- for (Product_Register_Link__c prl: pro2List) {
- if (pro2Map.containsKey(prl.Product2__r.Id)) {
- pro2Map.get(prl.Product2__r.Id).add(prl.Product_Register__r.MedPrdClass__c);
- }else {
- pro2Map.put(prl.Product2__r.Id, new List<String>());
- pro2Map.get(prl.Product2__r.Id).add(prl.Product_Register__r.MedPrdClass__c);
- }
+ //瀛樻斁鏌ユ壘鐨剆oql鏂�,鍏崇郴琛ㄩ噷鐨勪骇鍝佸拰娉ㄥ唽璇佺浉鍏冲瓧娈�
+ List<Product_Register_Link__c> pro2List = new List<Product_Register_Link__c>();
+ pro2List = [select Product2__r.id,Product2__r.demoteer_Sap__c,Product2__r.Diedatvanink__c,Product_Register__r.Stelsedag__c,Product_Register__r.MedPrdClass__c,Product_Register__r.ValidTo__c,Product_Register__r.ValidFrom__c,Product_Register__c,Product2__c
+ from Product_Register_Link__c
+ where Product2__r.Id in : p2ids];
+ System.debug('pro2List='+pro2List);
+ //瀛樻斁浜у搧鐨刬d鍜屾敞鍐岃瘉鍖荤枟鍣ㄦ鍒嗙被鐨勫�肩殑闆嗗悎
+ Map<Id,List<String>> pro2Map = new Map<Id,List<String>>();
+ //瀛樻斁娉ㄥ唽璇佷笂鏈�鍓嶇殑缁存姢鏃�,涓�绫昏瘉浼樺厛,鍚﹀垯浜岀被璇併��
+ Map<Id,Date> prSteMap = new Map<Id,Date>();//瀛樹竴绫荤淮鎶ゆ棩
+ //Map<Id,Date> prSte1Map = new Map<Id,Date>();//瀛樹簩绫荤淮鎶ゆ棩
+ if (pro2List.size()>0) {
+ for (Product_Register_Link__c prl: pro2List) {
+ //鏈夊尰鐤楀櫒姊板垎绫诲氨澧炲姞,娌℃湁灏辨斁杩涘幓
+ if (pro2Map.containsKey(prl.Product2__r.Id)) {
+ pro2Map.get(prl.Product2__r.Id).add(prl.Product_Register__r.MedPrdClass__c);
+ }else {
+ pro2Map.put(prl.Product2__r.Id, new List<String>());
+ pro2Map.get(prl.Product2__r.Id).add(prl.Product_Register__r.MedPrdClass__c);
}
- }
-
- //瀛樻斁浜у搧id鍜屽瓧绗︿覆鍊�
- Map<Id,String> prlMap = new Map<Id,String>();
- System.debug('pro2Map='+pro2Map);
-
- //閫氳繃涓婇潰鐨勫惊鐜紝鎶婂叧绯昏〃杩囪幏鍙栫殑鏁版嵁璇诲嚭鏉ワ紝浼犵粰map
- if (pro2Map.size()>0) {
- for (Product_Register_Link__c pr: pro2List) {
- if (pro2Map.containsKey(pr.Product2__r.Id)) {
- if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <> null) {
- //鐢熶骇鏃ユ湡鍦ㄦ敞鍐岃瘉鏈夋晥鏈熷唴鐨勬槸浜岀被锛岀敓浜ф棩鏈熷湪澶囨璇佹湁鏁堟湡鐨勬槸涓�绫伙紝鍓嶆彁涓烘湁鏁堟湡
- //System.debug('pr.Product_Register__r.ValidTo__c='+ pr.Product_Register__r.ValidTo__c);
- //System.debug('pr.Product_Register__r.MedPrdClass__c='+pr.Product_Register__r.MedPrdClass__c);
- if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c
- && (pr.Product_Register__r.MedPrdClass__c == '1')) {
- prlMap.put(pr.Product2__r.Id, '涓�绫�');
- }
- else if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c
- && pr.Product_Register__r.MedPrdClass__c == '2' || pr.Product_Register__r.MedPrdClass__c == '3') {
- if (!'涓�绫�'.equals(prlMap.get(pr.Product2__r.Id))){
- prlMap.put(pr.Product2__r.Id, '浜岀被');
- }
- }
+ //涓�绫昏瘉.缁存姢鏃ヤ笉涓虹┖.浜у搧鐢熶骇鏃ユ湡鍦ㄦ敞鍐岃瘉鏈夋晥鏈熶箣鍐�,涓嬮潰鐨勬槸浜岀被
+ if (prl.Product_Register__r.MedPrdClass__c == '1' && prl.Product_Register__r.Stelsedag__c <> null &&
+ (newMap.get(prl.Product2__r.Id).demoteer_Sap__c <= prl.Product_Register__r.ValidTo__c && newMap.get(prl.Product2__r.Id).demoteer_Sap__c >= prl.Product_Register__r.ValidFrom__c)) {
+ if (prSteMap.containsKey(prl.Product2__r.Id)) {
+ //杩欎竴姝�,map鍙兘鏈塱d,浣嗘槸鍊兼槸null,鎵�浠ユ槸null鏃朵篃缁欎粬璧嬪��
+ if (prSteMap.get(prl.Product2__r.Id) > prl.Product_Register__r.Stelsedag__c || prSteMap.get(prl.Product2__r.Id) == null) {
+ prSteMap.put(prl.Product2__r.Id,prl.Product_Register__r.Stelsedag__c);
}
+ }else {
+ prSteMap.put(prl.Product2__r.Id,prl.Product_Register__r.Stelsedag__c);
}
- System.debug('prlMap='+prlMap);
+ }else {
+ //涓嶇鍚堝氨璧嬬┖,鍜屼笂闈㈢殑鍒ゆ柇鏉′欢鏈夊叧鑱�***
+ if (!prSteMap.containsKey(prl.Product2__r.Id) || prSteMap.get(prl.Product2__r.Id) == null) {
+ prSteMap.put(prl.Product2__r.Id,null);
+ }
}
- }
-
- //缁欎骇鍝佷笂鐨勭瓑绾х被鍒瓧娈佃祴鍊�
- for (Product2 pr2: newList) {
- System.debug('pr2.demoteer_Sap__c='+pr2.demoteer_Sap__c);
- if (!pro2Map.containsKey(pr2.Id)) {
- //閬垮厤浠巗ap浼犳潵鐨勬椂闂村彇娑堜簡锛岀瓑绾х被鍒瓧娈典笂杩樻湁鍊艰繖涓�璇�
- if (pr2.demoteer_Sap__c == null) {
- pr2.Level_Category__c = null;
- }else{
- pr2.Level_Category__c = '闈炵洃绠�';
+ /*//鍜屼笂闈竴鏍�
+ if ((prl.Product_Register__r.MedPrdClass__c == '2' || prl.Product_Register__r.MedPrdClass__c == '3') && prl.Product_Register__r.Stelsedag__c <> null &&
+ (newMap.get(prl.Product2__r.Id).demoteer_Sap__c <= prl.Product_Register__r.ValidTo__c && newMap.get(prl.Product2__r.Id).demoteer_Sap__c >= prl.Product_Register__r.ValidFrom__c)) {
+ System.debug(prSte1Map.containsKey(prl.Product2__r.Id));
+ System.debug(prSte1Map);
+ if (prSte1Map.containsKey(prl.Product2__r.Id)) {
+ System.debug(prSte1Map.get(prl.Product2__r.Id) > prl.Product_Register__r.Stelsedag__c);
+ if (prSte1Map.get(prl.Product2__r.Id) > prl.Product_Register__r.Stelsedag__c || prSte1Map.get(prl.Product2__r.Id) == null) {
+ prSte1Map.put(prl.Product2__r.Id,prl.Product_Register__r.Stelsedag__c);
+ }
+ }else {
+ prSte1Map.put(prl.Product2__r.Id,prl.Product_Register__r.Stelsedag__c);
}
- }else{
- //else if (prlMap.containsKey(pr2.Id)) {
- pr2.Level_Category__c = prlMap.get(pr2.Id);
- }
- System.debug('pr2.Level_Category__c='+pr2.Level_Category__c);
+ }else {
+ if (!prSte1Map.containsKey(prl.Product2__r.Id) || prSte1Map.get(prl.Product2__r.Id) == null) {
+ prSte1Map.put(prl.Product2__r.Id,null);
+ }
+ }*/
}
}
- }
+
+ //瀛樻斁浜у搧id鍜屽瓧绗︿覆鍊�
+ Map<Id,String> prlMap = new Map<Id,String>();
+ Map<Id,String> prl1Map = new Map<Id,String>();
+ Map<Id,String> prl2Map = new Map<Id,String>();
+ Map<Id,String> prl3Map = new Map<Id,String>();
+ System.debug('pro2Map='+pro2Map);
+ System.debug('prSteMap='+prSteMap);
+ /*System.debug('prSte1Map='+prSte1Map);*/
+ Date stedate;
+
+ //閫氳繃涓婇潰鐨勫惊鐜紝鎶婂叧绯昏〃杩囪幏鍙栫殑鏁版嵁璇诲嚭鏉ワ紝浼犵粰map锛屼竴鍏卞垎涓�3涓猰ap锛岃娉ㄦ剰
+ if (pro2Map.size()>0) {
+ for (Product_Register_Link__c pr: pro2List) {
+ //淇濊瘉id鍦ㄤ笂闈㈢殑map閲屽瓨鍦�,浣嗘槸杩欎竴姝ユ湁娌℃湁濂藉儚娌″暐鍖哄埆,鍙堟病閿欒,绱㈡�т笉鍒犳帀
+ //&& (prSteMap.containsKey(pr.Product2__r.Id)) || prSte1Map.containsKey(pr.Product2__r.Id)
+ if (pro2Map.containsKey(pr.Product2__r.Id)) {
+ //鍙栧緱鏄骇鍝佺殑鐢熶骇鏃ユ湡鍦ㄦ敞鍐岃瘉鐨勬湁鏁堟湡鍐呯殑娉ㄥ唽璇佷笂闈㈢殑缁存姢鏃�,涓�绫讳紭鍏�,鍏舵浜岀被
+ /*stedate = prSteMap.get(pr.Product2__r.Id)==null?(prSte1Map.get(pr.Product2__r.Id)==null?null:prSte1Map.get(pr.Product2__r.Id)):prSteMap.get(pr.Product2__r.Id);*/
+ stedate = prSteMap.get(pr.Product2__r.Id);
+ //淇濊瘉浜у搧涓婄殑鐢熶骇鏃ユ湁鍊�
+ if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <> null) {
+ //娉ㄥ唽璇佺淮鎶ゆ棩鏈夊��
+ if (stedate <> null) {
+ //鍏ュ簱鏃ュ皬浜庣瓑浜庣淮鎶ゆ棩,鍏ュ簱鏃ユ病鏈夋寜鐓у叆搴撴棩鍦ㄧ淮鎶ゆ棩涔嬪墠鍒ゆ柇
+ if (newMap.get(pr.Product2__r.Id).Diedatvanink__c == null || newMap.get(pr.Product2__r.Id).Diedatvanink__c <= stedate) {
+ if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c
+ && (pr.Product_Register__r.MedPrdClass__c == '2' || pr.Product_Register__r.MedPrdClass__c == '3')) {
+ System.debug('2');
+ if (prlMap.get(pr.Product2__r.Id) == null || !prlMap.containsKey(pr.Product2__r.Id)) {
+ prlMap.put(pr.Product2__r.Id, '浜岀被');
+ }else {
+ String Lins = prlMap.get(pr.Product2__r.Id);
+ Lins += '浜岀被';
+ prlMap.put(pr.Product2__r.Id, Lins);
+ }
+ }else if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c
+ && pr.Product_Register__r.MedPrdClass__c == '1') {
+ System.debug('1');
+ if (prlMap.get(pr.Product2__r.Id) == null || !prlMap.containsKey(pr.Product2__r.Id)) {
+ prlMap.put(pr.Product2__r.Id, '涓�绫�');
+ }else {
+ String Lins = prlMap.get(pr.Product2__r.Id);
+ Lins += '涓�绫�';
+ prlMap.put(pr.Product2__r.Id, Lins);
+ }
+ }
+ //鍏ュ簱鏃ュぇ浜庣淮鎶ゆ棩
+ }else if (newMap.get(pr.Product2__r.Id).Diedatvanink__c <> null && newMap.get(pr.Product2__r.Id).Diedatvanink__c > stedate) {
+ if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c
+ && pr.Product_Register__r.MedPrdClass__c == '1') {
+ if (prl1Map.get(pr.Product2__r.Id) == null || !prl1Map.containsKey(pr.Product2__r.Id)) {
+ prl1Map.put(pr.Product2__r.Id, '涓�绫�');
+ }else {
+ String Lins = prl1Map.get(pr.Product2__r.Id);
+ Lins += '涓�绫�';
+ prl1Map.put(pr.Product2__r.Id, Lins);
+ }
+ }else if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c
+ && pr.Product_Register__r.MedPrdClass__c == '2' || pr.Product_Register__r.MedPrdClass__c == '3') {
+ if (prl1Map.get(pr.Product2__r.Id) == null || !prl1Map.containsKey(pr.Product2__r.Id)) {
+ prl1Map.put(pr.Product2__r.Id, '浜岀被');
+ }else {
+ String Lins = prl1Map.get(pr.Product2__r.Id);
+ Lins += '浜岀被';
+ prl1Map.put(pr.Product2__r.Id, Lins);
+ }
+ }
+ }
+ }else if (stedate == null && newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c
+ && (pr.Product_Register__r.MedPrdClass__c == '2' || pr.Product_Register__r.MedPrdClass__c == '3')) {
+ prl3Map.put(pr.Product2__r.Id, '浜岀被');
+ }else {
+ //缁存姢鏃ョ┖锛屼篃娌℃湁浜岀被璇侊紝杩欎釜map缃┖
+ prl2Map.put(pr.Product2__r.Id, '绌�');
+ }
+ }
+ }
+ }
+ }
+
+ System.debug('prlMap='+prlMap);
+ System.debug('prl1Map='+prl1Map);
+ System.debug('prl2Map='+prl2Map);
+ //缁欎骇鍝佷笂鐨勭瓑绾х被鍒瓧娈佃祴鍊�
+ for (Product2 pr2: newList) {
+ if (prlMap.containsKey(pr2.Id)) {
+ if ((prlMap.get(pr2.Id).contains('浜岀被') && prlMap.get(pr2.Id).contains('涓�绫�')) ||
+ (!prlMap.get(pr2.Id).contains('涓�绫�') && prlMap.get(pr2.Id).contains('浜岀被'))){
+ pr2.Level_Category__c = '浜岀被';
+ }else if (prlMap.get(pr2.Id).contains('涓�绫�') && !prlMap.get(pr2.Id).contains('浜岀被')) {
+ pr2.Level_Category__c = '涓�绫�';
+ }
+ }else if (prl1Map.containsKey(pr2.Id)) {
+ if (prl1Map.get(pr2.Id).contains('涓�绫�')) {
+ pr2.Level_Category__c = '涓�绫�';
+ }else if (prl1Map.get(pr2.Id).contains('浜岀被') && !prl1Map.get(pr2.Id).contains('涓�绫�')) {
+ pr2.Level_Category__c = '浜岀被';
+ }
+ }else if (prl3Map.containsKey(pr2.Id)) {
+ pr2.Level_Category__c = '浜岀被';
+ }else if (prl2Map.containsKey(pr2.Id)) {
+ //涓轰簡閬垮厤楹荤儲涓庡悗缁慨鏀癸紝缁熶竴闈炵洃绠′簡銆�
+ pr2.Level_Category__c = '闈炵洃绠�';
+ }
+ //鐢熶骇鏃ユ棤鍊硷紝绛夌骇绫诲埆缃┖
+ if (pr2.demoteer_Sap__c == null) {
+ pr2.Level_Category__c = null;
+ }
+ System.debug('pr2.Level_Category__c='+pr2.Level_Category__c);
+ }
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1