From fbf3ce2885477fd0dfbd8ec6b490636dc0f680dc Mon Sep 17 00:00:00 2001
From: 涂煌豪 <997058689@qq.com>
Date: 星期五, 18 三月 2022 18:49:38 +0800
Subject: [PATCH] 先款后修-修理增加先款标识

---
 force-app/main/default/classes/RepairTrigger.cls |   58 ++++++++++++++++++++++++++++
 force-app/main/default/triggers/Repair.trigger   |    3 +
 2 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/force-app/main/default/classes/RepairTrigger.cls b/force-app/main/default/classes/RepairTrigger.cls
index 302018d..4d36d5f 100644
--- a/force-app/main/default/classes/RepairTrigger.cls
+++ b/force-app/main/default/classes/RepairTrigger.cls
@@ -696,7 +696,63 @@
         return repair;
     }
     //add        wangweipeng                 2021/12/09                     end
-
+    //鍏堟鍚庝慨-淇悊澧炲姞鍏堟鏍囪瘑 thh 20220318 start
+    public static void AdvancePaymentFlagUpsert(List<Repair__c> newList, Map<Id, Repair__c> newMap, List<Repair__c> oldList, Map<Id, Repair__c> oldMap) {
+        List<String> RepairQuotationIdList = new List<String>();
+        List<Repair__c> NoRepairQuotationList = new List<Repair__c>();
+        List<Repair_Quotation__c> RepairQuotationList = new List<Repair_Quotation__c>();
+        List<String> DealerIdList = new List<String>();
+        List<Account> DealerList = new List<Account>();
+        List<Repair__c> updateRepairList = new List<Repair__c>();
+        System.debug('newList1:' + newList);
+        for(Repair__c rep : newList){
+            Repair__c oldRep = oldMap.get(rep.Id);
+            if(rep.Repair_Quotation_Id__c != null){
+                RepairQuotationIdList.add(rep.Repair_Quotation_Id__c);
+            }else{
+                NoRepairQuotationList.add(rep);
+            }
+        }
+        //鍚屾湡涓殑淇悊淇悊鎶ヤ环鏈夊�兼椂锛岀湅鎶ヤ环涓婄殑鍏堟鏍囪瘑杩涜璧嬪��
+        if(RepairQuotationIdList.size() > 0){
+            RepairQuotationList = [select Id, Is_RecognitionModel__c from Repair_Quotation__c where Id IN :RepairQuotationIdList];
+        }
+        for(Repair_Quotation__c rq : RepairQuotationList){
+            for(Repair__c rep : newList){
+                if(rq.Id == rep.Repair_Quotation_Id__c){
+                    rep.Advance_Payment_Flag__c = rq.Is_RecognitionModel__c;
+                    updateRepairList.add(rep);
+                }
+            }
+        }
+        //鍚屾湡涓殑淇悊鎶ヤ环娌″�兼椂锛岀湅淇悊鍗曚笂鐨勭粡閿�鍟嗘槸涓嶆槸鍏堟瀵硅薄杩涜璧嬪��
+        if(NoRepairQuotationList.size() > 0){
+            for(Repair__c rep : NoRepairQuotationList){
+                DealerIdList.add(rep.Dealer__c);
+            }
+        }
+        if(DealerIdList.size() > 0 ){
+            DealerList = [select Id, FirstParagraphEnd__c from Account where Id IN : DealerIdList];
+        }
+        for(Account dealer : DealerList){
+            for(Repair__c rep : newList){
+                if(rep.Dealer__c == dealer.Id){
+                    rep.Advance_Payment_Flag__c = dealer.FirstParagraphEnd__c;
+                    updateRepairList.add(rep);
+                }
+            }
+        }
+        Savepoint sp = Database.setSavepoint();
+        try {
+            if(updateRepairList.size() > 0){
+                update updateRepairList;
+            }
+        } catch (System.Exception e) {
+            Database.rollback(sp);
+            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));
+        }
+    }
+    //鍏堟鍚庝慨-淇悊澧炲姞鍏堟鏍囪瘑 thh 20220318 end
 
     public static void CheckUpdate(List<Repair__c> oldList, Map<Id, Repair__c> newMap) {
         System.debug('===========> start');
diff --git a/force-app/main/default/triggers/Repair.trigger b/force-app/main/default/triggers/Repair.trigger
index 3de4a47..d520d7a 100644
--- a/force-app/main/default/triggers/Repair.trigger
+++ b/force-app/main/default/triggers/Repair.trigger
@@ -273,6 +273,9 @@
                 /****************************************************************************************************/
             }
         }
+        //鍏堟鍚庝慨-淇悊澧炲姞鍏堟鏍囪瘑 thh 20220318 start
+        RepairTrigger.AdvancePaymentFlagUpsert(Trigger.new, Trigger.newMap, Trigger.old, Trigger.oldMap);
+        //鍏堟鍚庝慨-淇悊澧炲姞鍏堟鏍囪瘑 thh 20220318 end
     }
     // ----------------------------------------------------------------------
     // 銇撱亾銇俱仹銆併偟銉笺儞銈广偝銉炽儓銉┿偗銉堥爡鐩倰鑷嫊鐨勩伀鏇存柊銇欍倠銉偢銉冦偗

--
Gitblit v1.9.1