From d8dc84a3d56df839895f1c417a4d9cbee763d262 Mon Sep 17 00:00:00 2001
From: 高章伟 <gaozhangwei@prec-tech.com>
Date: 星期五, 03 三月 2023 14:50:59 +0800
Subject: [PATCH] gzw 测试环境代码更新

---
 force-app/main/default/classes/LastbuyProductHandler.cls |   88 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 85 insertions(+), 3 deletions(-)

diff --git a/force-app/main/default/classes/LastbuyProductHandler.cls b/force-app/main/default/classes/LastbuyProductHandler.cls
index 0fb8f6f..f9ecba7 100644
--- a/force-app/main/default/classes/LastbuyProductHandler.cls
+++ b/force-app/main/default/classes/LastbuyProductHandler.cls
@@ -22,9 +22,16 @@
     }
     
     protected override void beforeInsert(){
-
+        //SWAG-CKADFQ 銆愬鎵樸�戙�怢ast Buy銆慙ast Buy棰勭暀绠$悊鏀瑰杽鏂伴渶姹� start
+        SetUniqueKey(null);
+        //SWAG-CKADFQ 銆愬鎵樸�戙�怢ast Buy銆慙ast Buy棰勭暀绠$悊鏀瑰杽鏂伴渶姹� end
     }
-
+    protected override void beforeUpdate(){
+        //SWAG-CKADFQ 銆愬鎵樸�戙�怢ast Buy銆慙ast Buy棰勭暀绠$悊鏀瑰杽鏂伴渶姹� start
+        CheckInquiryWinAboutupdate();
+        SetUniqueKeyOnUpdate();
+        //SWAG-CKADFQ 銆愬鎵樸�戙�怢ast Buy銆慙ast Buy棰勭暀绠$悊鏀瑰杽鏂伴渶姹� end
+    }
     protected override void afterInsert(){
         ReservedPro();
     }
@@ -36,7 +43,11 @@
     protected override void afterDelete(){
         ReservedPro();
     }
-
+    //SWAG-CKADFQ 銆愬鎵樸�戙�怢ast Buy銆慙ast Buy棰勭暀绠$悊鏀瑰杽鏂伴渶姹� start
+    protected override void beforeDelete(){
+        CheckInquiryWin();
+    }
+    //SWAG-CKADFQ 銆愬鎵樸�戙�怢ast Buy銆慙ast Buy棰勭暀绠$悊鏀瑰杽鏂伴渶姹� end
     private void ReservedPro(){
         //1.鏂板缓鎴栬�呮洿鏂颁骇鍝佸悗锛岃嫢棰勭暀浜у搧鏈夋晥锛屸�滈鐣欎骇鍝佲�濇爣璇嗕负true
         if(trigger.isInsert || trigger.isUpdate){
@@ -143,5 +154,76 @@
         }
 
     }
+    //SWAG-CKADFQ 銆愬鎵樸�戙�怢ast Buy銆慙ast Buy棰勭暀绠$悊鏀瑰杽鏂伴渶姹� start
+    private void SetUniqueKey(Set<Id> lbps){
+        if(trigger.isInsert) {
+            for (LastbuyProduct__c Lastbuyobj : this.newList){
+                Lastbuyobj.productInquiryOnly__c = Lastbuyobj.ProductName__c+'_'+Lastbuyobj.InquiryCode__c;
+            }
+        } else {
+            if(lbps!=null&&lbps.size() > 0){
+                for(String id : lbps){
+                    LastbuyProduct__c Lastbuyobj = this.newMap.get(id);
+                    Lastbuyobj.productInquiryOnly__c = Lastbuyobj.ProductName__c+'_'+Lastbuyobj.InquiryCode__c;
+                }
+            }
+        }
+        
+    }
+    private void CheckInquiryWin(){
+        if(trigger.isBefore && trigger.isDelete){
+            List<Id> InquiryId = new List<Id>();
+            List<Id> InquiryWinId = new List<Id>();
+            for(LastbuyProduct__c Lastbuyobj : oldList){
+                InquiryId.add(Lastbuyobj.InquiryCode__c);
+            }
+            List<Opportunity> OppList = [select Id,SAP_Send_OK__c from Opportunity where Id =:InquiryId];
+            System.debug('OppList++'+OppList);
+            for(Opportunity oppobj : OppList){
+                if(oppobj.SAP_Send_OK__c){
+                    // InquiryWinId.add(oppobj.Id);
+                    throw new ControllerUtil.myException('棰勭暀璇环宸茬粡WIN涓嶅厑璁稿垹闄�');   
+                }
+            }
+        }
+    }
+
+    // 璇环鍙戠敓鍙樺寲鏃堕獙璇�
+    private void CheckInquiryWinAboutupdate(){
+        if(trigger.isBefore && trigger.isUpdate){
+            List<Id> LastbuyId = new List<Id>();
+            List<Id> oppId = new List<Id>();
+            for(LastbuyProduct__c Lastbuyobj : newList){
+                // 鍙彇璇环鍙戠敓鍙樺寲鐨勬暟鎹�
+                if (Lastbuyobj.InquiryCode__c != oldMap.get(Lastbuyobj.Id).InquiryCode__c) {
+                    LastbuyId.add(Lastbuyobj.Id);
+                    oppId.add(oldMap.get(Lastbuyobj.Id).InquiryCode__c);
+                }
+            }
+            List<Opportunity> oppList = [select Id,SAP_Send_OK__c from Opportunity where Id =:oppId];
+            for(Opportunity opp : oppList){
+                if(opp.SAP_Send_OK__c){
+                    throw new ControllerUtil.myException('棰勭暀鐨勮浠峰凡缁廤IN锛屼笉鍏佽鏇挎崲锛岃鍙栨秷WIN鍚庡啀鏇挎崲');   
+                }
+            }
+
+        }
+    }
+
+    // 璇环鎴栦骇鍝佸彂鐢熷彉鍖栨椂鏇存柊鍞竴鏍囪瘑
+    private void SetUniqueKeyOnUpdate() {
+        Set<Id> updateUniKeys = new Set<Id>();
+        for(LastbuyProduct__c Lastbuyobj : this.newList){
+            LastbuyProduct__c old_Lastbuyobj = oldMap.get(Lastbuyobj.Id);
+            // 浜у搧鎴栬浠峰彉鍖栫殑鏃跺�欓兘鍔犺繘鏉�
+            if (Lastbuyobj.InquiryCode__c != old_Lastbuyobj.InquiryCode__c || 
+                Lastbuyobj.ProductName__c != old_Lastbuyobj.ProductName__c || 
+                String.isBlank(Lastbuyobj.productInquiryOnly__c)) {
+                updateUniKeys.add(Lastbuyobj.Id);
+            }
+        }
+        SetUniqueKey(updateUniKeys);
+    }
+    //SWAG-CKADFQ 銆愬鎵樸�戙�怢ast Buy銆慙ast Buy棰勭暀绠$悊鏀瑰杽鏂伴渶姹� end
 
 }
\ No newline at end of file

--
Gitblit v1.9.1