From 96778f656fa80358c9d87e36a13e93fe994deadf Mon Sep 17 00:00:00 2001
From: yangjieke <yangjieke@prec-tech.com>
Date: 星期五, 18 三月 2022 19:41:26 +0800
Subject: [PATCH] 产品名称、型号的判断改为大小写敏感

---
 force-app/main/default/classes/SyncProduct2.trigger |  140 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 140 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/classes/SyncProduct2.trigger b/force-app/main/default/classes/SyncProduct2.trigger
new file mode 100644
index 0000000..f434683
--- /dev/null
+++ b/force-app/main/default/classes/SyncProduct2.trigger
@@ -0,0 +1,140 @@
+trigger SyncProduct2 on Product2 (after delete, after insert, after update) {
+    if (StaticParameter.EscapeSyncProduct2Trigger) {
+System.debug('Escape銆丒scapeSyncProduct2Trigger:::::' + StaticParameter.EscapeSyncProduct2Trigger);
+        return;
+    }
+    List<Product2> pr2s = new List<Product2>();
+    
+    if (Trigger.isDelete) {
+        for (Product2 pr2 : Trigger.old) {
+            pr2s.add(pr2);
+        }
+    } else {
+        for (Product2 pr2 : Trigger.new) {
+            if (Trigger.isInsert
+                    || Trigger.isUpdate
+                            && (pr2.Name.equals(Trigger.oldMap.get(pr2.Id).get('Name'))
+                                    || pr2.Asset_Model_No__c.equals(Trigger.oldMap.get(pr2.Id).get('Asset_Model_No__c'))
+                                    || pr2.IsActive != Trigger.oldMap.get(pr2.Id).get('IsActive')
+                                    || pr2.SFDA_Status__c != Trigger.oldMap.get(pr2.Id).get('SFDA_Status__c')))
+            pr2s.add(pr2);
+        }
+    }
+    
+    Map<String, Product2__c> pr2Map = new Map<String, Product2__c>();
+    if (pr2s.size() > 0) {
+        List<Product2__c> pr2Cs = ControllerUtil.pr2SelectForSync(pr2s);
+        for (Product2__c pr2 : pr2Cs) {
+            pr2Map.put(pr2.Product2__c, pr2);
+        }
+    }
+    
+    List<Product2__c> insPr2 = new List<Product2__c>();
+    List<Product2__c> updelPr2 = new List<Product2__c>();
+    List<Product2__c> delPr2 = new List<Product2__c>();
+    for (Product2 pr : pr2s) {
+        // 瑕嬩粯銇嬨仯銇熴倝鏇存柊锛忓墛闄�
+        if (pr2Map.containsKey(pr.Id)) {
+            Product2__c pr2 = pr2Map.get(pr.Id);
+            // 銆屾簴鍌欎腑銆嶃�屾柊瑁藉搧鐢宠珛涓�嶃伅瀵捐薄澶�
+            if (pr.IsActive
+                    && pr.SFDA_Status__c != '婧栧倷涓�' && pr.SFDA_Status__c != '鏂拌=鍝佺敵璜嬩腑') {
+                pr2.Name = pr.Asset_Model_No__c != null ? pr.Asset_Model_No__c.mid(0, 80) : pr.Name.mid(0, 80);
+                pr2.Name_Text__c = pr.Name;
+                pr2.OT_CODE_Text__c = pr.ProductCode;
+                pr2.CurrencyIsoCode = pr.CurrencyIsoCode;
+                if (Trigger.isDelete) {
+                    pr2.DeleteFlag__c = true;
+                } else {
+                    pr2.DeleteFlag__c = false;
+                }
+                updelPr2.add(pr2);
+            } else {
+                pr2.DeleteFlag__c = true;
+                delPr2.add(pr2);
+            }
+        // 鏂拌
+        } else {
+            if (pr.IsActive
+                    && pr.SFDA_Status__c != '婧栧倷涓�' && pr.SFDA_Status__c != '鏂拌=鍝佺敵璜嬩腑') {
+                Product2__c pr2 = new Product2__c(
+                    Product2__c = pr.Id,
+                    Name = pr.Asset_Model_No__c != null ? pr.Asset_Model_No__c.mid(0, 80) : pr.Name.mid(0, 80),
+                    Name_Text__c = pr.Name,
+                    OT_CODE_Text__c = pr.ProductCode,
+                    CurrencyIsoCode = pr.CurrencyIsoCode
+                );
+                insPr2.add(pr2);
+            }
+        }
+    }
+    
+    if (Trigger.isDelete) {
+        //ControllerUtil.delPr2List(updelPr2);
+        ControllerUtil.updelPr2List(updelPr2, null);
+    }
+    if (Trigger.isUpdate) {
+        ControllerUtil.updelPr2List(updelPr2, null);
+        ControllerUtil.updelPr2List(delPr2, null);
+    }
+    if (!Trigger.isDelete) ControllerUtil.insPr2List(insPr2);
+
+    // HWAG-AWLAU6 2018/3/7 "鏄惁澶氬勾淇濅慨"鐨勫�兼嫹璐濆埌"鏄惁澶氬勾淇濅慨锛堟枃鏈級"涓�
+    List<String> proId = new List<String>();
+    List<String> conformChangeProId = new List<String>();
+    if (Trigger.isInsert || Trigger.isUpdate) {
+        for (Product2 pro : Trigger.new) {
+            proId.add(pro.Id);
+            //XHL -----20190523----UpdateStart--
+            if (Trigger.isInsert){
+                conformChangeProId.add(pro.Id);
+            } else if (Trigger.isUpdate && (pro.Extend_new_product_gurantee__c != Trigger.oldMap.get(pro.Id).Extend_new_product_gurantee__c || 
+                        pro.Extend_Gurantee_Start__c != Trigger.oldMap.get(pro.Id).Extend_Gurantee_Start__c || 
+                        pro.Extend_Gurantee_End__c != Trigger.oldMap.get(pro.Id).Extend_Gurantee_End__c)){
+                conformChangeProId.add(pro.Id);    
+            }
+            //XHL -----20190523----UpdateEnd
+            
+        }
+    }
+    if (conformChangeProId.size() > 0) {
+        //List<Asset> assList = [select id, IS_Extend_Gurantee__c,GuaranteeFlag__c ,IS_Extend_Gurantee_Txt__c, Extend_Gurantee_Txt_Manual__c from Asset where Product2Id IN : proId AND GuaranteeFlag__c = true];
+        List<Asset> assList = [select id, IS_Extend_Gurantee__c,GuaranteeFlag__c ,
+                                    IS_Extend_Gurantee_Txt__c, Extend_Gurantee_Txt_Manual__c,
+                                    Product2Id 
+                                from Asset 
+                                where Product2Id IN : conformChangeProId];
+        if (assList != null && assList.size() > 0) {
+            List<Asset> updAsset = new List<Asset>();
+            for(Asset ass : assList) {
+                //XHL -------------20190118----UpdateStart----------鍦ㄤ繚鏈夎澶囦腑鍒涘缓GuaranteeFlag__c瀛楁----20190523灏嗗叾杩樺師
+                if (ass.IS_Extend_Gurantee__c != ass.IS_Extend_Gurantee_Txt__c && ass.Extend_Gurantee_Txt_Manual__c == false) {
+                    ass.IS_Extend_Gurantee_Txt__c = ass.IS_Extend_Gurantee__c;
+                    updAsset.add(ass);
+                }
+                //XHL -------------20190118----UpdateEnd----------20190523灏嗗叾杩樺師
+            }
+            if (updAsset.size() > 0) {
+                update updAsset;
+            }
+        }
+    }
+
+    // CHAN-AX9485 2018/3/27 鍏充簬浜у搧閰嶅鏈夋晥鏃犳晥鐨勫垽鏂�--浜у搧鍙樻洿鏃舵洿鏂颁骇鍝侀厤濂楁槸鍚︽湁鏁�
+    if (Trigger.isUpdate) {
+        List<Product_Set_Detail__c> psdList = [select Id, Effective_Product_detail__c, EffectiveNo_Product_detail__c, Total_price_RMB__c,
+                                            List_price_total_RMB_text__c from Product_Set_Detail__c where Product__c IN : proId];
+        List<Product_Set_Detail__c> updPsdList = new List<Product_Set_Detail__c>();
+        if (psdList != null && psdList.size() > 0) {
+            for(Product_Set_Detail__c psd : psdList) {
+                if (psd.Effective_Product_detail__c != psd.EffectiveNo_Product_detail__c
+                    || psd.Total_price_RMB__c != psd.List_price_total_RMB_text__c) {
+                    updPsdList.add(psd);
+                }
+            }
+        }
+        if (updPsdList.size() > 0) {
+            update updPsdList;
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.1