李彤
2022-11-18 9ae452e93335a603a4cb22b7314f633c5e0bce25
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
47
48
49
50
51
52
public with sharing class InquiryPredictsDateChangeHandler extends Oly_TriggerHandler{
 
    private List<InquiryPredictsDateChange__c> oldList;
    private List<InquiryPredictsDateChange__c> newList;
    private Map<Id,InquiryPredictsDateChange__c> oldMap;
    private Map<Id,InquiryPredictsDateChange__c> newMap;
 
    public InquiryPredictsDateChangeHandler() {
        this.oldList = (List<InquiryPredictsDateChange__c>) Trigger.old;
        this.newList = (List<InquiryPredictsDateChange__c>) Trigger.new;
        this.oldMap = (Map<Id,InquiryPredictsDateChange__c>) Trigger.oldMap;
        this.newMap = (Map<Id,InquiryPredictsDateChange__c>) Trigger.newMap;
    }
 
    protected override void afterUpdate() {
        addColumn();
    }
 
    //当审批流程走完时 更新 询价相关字段
    private void addColumn(){
        List<Opportunity> oppList = new List<Opportunity>();
        Map<Id,Opportunity> oppMap = new Map<Id,Opportunity>();
        List<Id> oppIdList = new List<Id>();
 
        for (InquiryPredictsDateChange__c ipd :newList ) {
            //判断更新前后的状态是否不同 若不同,则判断更新后的状态是否为'已批准'
            if ((ipd.Predicted_Date_Status__c != oldMap.get(ipd.Id).Predicted_Date_Status__c) && ipd.Predicted_Date_Status__c == '已批准' ) {
                String oppId = ipd.Opportunity__c  ;
                Opportunity opp = new Opportunity();
 
                opp.Id = oppId;
                // opp.Close_Forecasted_Assume_Date__c = ipd.Close_Forecasted_Assume_Date__c; //担当日
                opp.Close_Forecasted_Date__c        = ipd.Close_Forecasted_Date__c;        //KPI日
                opp.CloseDate                       = ipd.CloseDate__c;                    //结束日期/预测发货日
                opp.Date_InAdvance_Delay__c         = ipd.Date_InAdvance_Delay__c;         //日期提前/延后
                opp.Predicted_date_ChangeReason__c  = ipd.Predicted_date_ChangeReason__c;  //改变预测日期原因
                // opp.Opp_New_Mark__c                 = ipd.Opp_New_Mark__c;                 //询价新建标记
                opp.Opp_Delay_Mark__c               = ipd.Opp_Delay_Mark__c;               //询价延后标价
                opp.ForecastApprovalTime__c         = Datetime.now();
 
                oppList.add(opp);
 
            }
        }
 
        if (oppList.size() > 0) {
            System.debug('lt123oppList'+oppList);
            update oppList;
        }
    }
 
}