高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
public with sharing class RepairQuoteTrigger {
 
    public static void ChangeRepair(List<Repair_Quotation__c> newList, Map<Id, Repair_Quotation__c> newMap, List<Repair_Quotation__c> oldList, Map<Id, Repair_Quotation__c> oldMap) {
        System.debug('===========> start');
        List<String> rqIds = new List<String>(); 
        Map<id,Repair_Quotation__c> RqMap = new Map<id,Repair_Quotation__c>();
        if (Trigger.isUpdate) {
            Boolean flag = false;
            for(Repair_Quotation__c rq : newList){
                if(Trigger.isUpdate && rq.ListPrice__c != oldMap.get(rq.id).ListPrice__c){
                    //rqIds.add(rq.id);
                    flag = true;
                }
            }
            if(flag == false){
                return;
            }
            for(Repair_Quotation__c rq : newList){
                if(Trigger.isUpdate && rq.ListPrice__c != oldMap.get(rq.id).ListPrice__c){
                    rqIds.add(rq.id);
                    RqMap.put(rq.id, rq);
                }
            }
        }else if(Trigger.isInsert){
            for(Repair_Quotation__c rq : newList){
                rqIds.add(rq.id);
                RqMap.put(rq.id, rq);
            }
        }
 
        List<Repair__c> RepairUpdateList = new List<Repair__c>();
        if(rqIds.size() > 0){
            //修理的同期中的修理报价de报价金额改变的修理
            List<Repair__c> RpList = [select id,Repair_Quotation_Id__c from Repair__c where Repair_Quotation_Id__c in :rqIds];
            if(RpList.size() > 0){
                for(Repair__c rp : RpList){
                    Repair_Quotation__c Rqa = RqMap.get(rp.Repair_Quotation_Id__c);
                    rp.Repair_Quotation_Price__c = Rqa.ListPrice__c;
                    RepairUpdateList.add(rp);
                }
                update RepairUpdateList;
            }
        }
        System.debug('===========> end');
    }
}