高章伟
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
public class Opponent_Bid_InformationHandler extends Oly_TriggerHandler  {
 
    private Map<Id, Opponent_Bid_Information__c> newMap;
    private Map<Id, Opponent_Bid_Information__c> oldMap;
    private List<Opponent_Bid_Information__c> newList;
    private List<Opponent_Bid_Information__c> oldList;
 
 
    public Opponent_Bid_InformationHandler() {
        this.newMap = (Map<Id, Opponent_Bid_Information__c>) Trigger.newMap;
        this.oldMap = (Map<Id, Opponent_Bid_Information__c>) Trigger.oldMap;
        this.newList = (List<Opponent_Bid_Information__c>) Trigger.new;
        this.oldList = (List<Opponent_Bid_Information__c>) Trigger.old;
    }
 
    protected override void afterUpdate() {
        // 更新询价的部分失单信息
        updateOpponentInfo();
    }
    private void updateOpponentInfo() {
        List<Opportunity> oppList = new List<Opportunity>();
        // 因为没法跨表,所以进行select,如果使用那些字段,需要手动添加
        List<Opponent_Bid_Information__c> temOBIList = 
            [select id,Opportunity__c,Report_Status__c,
            Lost_By_Company__c,Lost_reason_main__c , of_lost_system_processor__c,
            Lost_Reason_Sub__c, Lost_By_Product__c,
            CompetitorProduct1__r.id, CompetitorProduct1__r.Name,
            CompetitorProduct2__r.id, CompetitorProduct2__r.Name,
            CompetitorProduct3__r.id, CompetitorProduct3__r.Name,
            CompetitorProduct4__r.id, CompetitorProduct4__r.Name
            from Opponent_Bid_Information__c 
            where id in: newList];
        for (Opponent_Bid_Information__c n : temOBIList) {
            if (n.Report_Status__c  == '批准' ) {
                Opportunity opp = new Opportunity();
                opp.id = n.Opportunity__c;
                
                opp.Lost_By_Company_part__c                = n.Lost_By_Company__c;
                opp.Lost_reason_main_part__c             = n.Lost_reason_main__c;
                opp.of_lost_system_processor_part__c     = n.of_lost_system_processor__c;
                if(n.Lost_Reason_Sub__c!=null){
                    opp.Lost_Reason_Sub_part__c                = n.Lost_Reason_Sub__c+';';
                }else{
                    opp.Lost_Reason_Sub_part__c             = n.Lost_Reason_Sub__c;
                }
                opp.Lost_By_Product_part__c                = n.Lost_By_Product__c;
 
                if (n.CompetitorProduct1__r.id == '01t10000000Tqam') {
                    opp.CompetitorProduct1_part__c = n.Lost_By_Product__c;
                } else {
                    opp.CompetitorProduct1_part__c = n.CompetitorProduct1__r.Name;
                }
                if (n.CompetitorProduct2__r.id == '01t10000000Tqam') {
                    opp.CompetitorProduct2_part__c = n.Lost_By_Product__c;
                } else {
                    opp.CompetitorProduct2_part__c = n.CompetitorProduct2__r.Name;
                }
                if (n.CompetitorProduct3__r.id == '01t10000000Tqam') {
                    opp.CompetitorProduct3_part__c = n.Lost_By_Product__c;
                } else {
                    opp.CompetitorProduct3_part__c = n.CompetitorProduct3__r.Name;
                }
                if (n.CompetitorProduct4__r.id == '01t10000000Tqam') {
                    opp.CompetitorProduct4_part__c = n.Lost_By_Product__c;
                } else {
                    opp.CompetitorProduct4_part__c = n.CompetitorProduct4__r.Name;
                }
                oppList.add(opp);
            }
        }
        if (oppList.size() > 0) update oppList;
    }
 
}