涂煌豪
2022-04-11 bae4d41e9e63cbeed024cf8209011dd9c854d54c
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
global class Sfdc2PoContactBatch implements Database.Batchable<sObject>, Database.AllowsCallouts {
    public String query;
 
    global Sfdc2PoContactBatch() {
        this.query = query;
    }
 
    global Database.QueryLocator start(Database.BatchableContext bc) {
        // return Database.getQueryLocator([SELECT id, Name, IsFromSPO__c, RecordTypeId, UnifiedI_Contact_ID__c, SendToComPlat__c,MobilePhone
        //     FROM Contact
        //     WHERE Id != null AND RecordTypeId = '01210000000QfWiAAK' AND Account.Is_Active_Formula__c = '有效' AND MobilePhone != '' AND  Isactive__c = '有效'
        // ]);
        // 发送指定数据
        // 经销商和医院客户人员数据都需要重新执行 thh 20220411 start
        return Database.getQueryLocator([SELECT id, Name, IsFromSPO__c, RecordTypeId, UnifiedI_Contact_ID__c, SendToComPlat__c,MobilePhone
            FROM Contact
            WHERE Id != null 
                AND (RecordTypeId = '01210000000QfWiAAK' OR RecordTypeId = '01210000000QfWdAAK')
                AND Account.Is_Active_Formula__c = '有效' 
                AND MobilePhone != '' 
                AND  ((Isactive__c = '有效' 
                AND SendToComPlat__c = true) OR SendToComPlat__c = true)
        ]);
        // 经销商和医院客户人员数据都需要重新执行 thh 20220411 end
 
    }
 
    global void execute(Database.BatchableContext BC, list < Contact > senContactList) {
        // 跳过ContactTriggerHandler,否则会报错 thh 20220411 start
        Oly_TriggerHandler.bypass('ContactTriggerHandler');
        // 跳过ContactTriggerHandler,否则会报错 thh 20220411 end
        List < String > conatctIdList = new List < String > ();
        for (Contact con: senContactList) {
            // 医院 客户人员 统一平台编码 发送 PO
            if ('01210000000QfWdAAK'.equals(con.RecordTypeId) && String.isNotBlank(con.UnifiedI_Contact_ID__c)) {
                conatctIdList.add(con.Id);
            }
            // 经销商 客户人员 手机号码不为空 发送 PO
            if ('01210000000QfWiAAK'.equals(con.RecordTypeId) && String.isNotBlank(con.MobilePhone)) {
                conatctIdList.add(con.Id);
            }
            
            con.SendToComPlat__c = false;
        }
        if (conatctIdList.size() > 0) {
            NFM606Controller.executeNotFuture(null, conatctIdList);
        }
        update senContactList;
    }
 
    global void finish(Database.BatchableContext BC) {
 
    }
}