彭锟
2022-03-28 a081dacbea1e46a9d3f4d77057da7923e9f59d99
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
global class NFM606Batch implements Database.Batchable < sObject > , Database.AllowsCallouts {
    // public String query;
    // public List < String > IdList;
    // public String executeType;
    // public String idStr;
 
    // Boolean IsNeedExecute = false; // 2021-03-03  mzy  WLIG-BYHD79  SFDC环境batch合并调查  是否符合执行条件
 
    // public SubAuthorizedBatch(Boolean NeedExecute) {
    //     this.IsNeedExecute = NeedExecute;
    // }
 
    public ID recordTypeId;
    global NFM606Batch() {
        ID recordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('社内员工').getRecordTypeId();
    }
    // global NFM606Batch(String executeType) {
    //     this.executeType = executeType;
    // }
    // global NFM606Batch(String executeType, List < String > IdList) {
    //     this.IdList = IdList;
    //     this.executeType = executeType;
    // }
    // global NFM606Batch(String executeType, String idStr) {
    //     this.idStr = idStr;
    //     this.executeType = executeType;
    // }
 
    global Database.QueryLocator start(Database.BatchableContext bc) {
        // if ('User'.equals(executeType)) {
        //     // 用户接口
        //     return Database.getQueryLocator([
        //         SELECT Id, IsActive, Employee_No__c FROM User WHERE IsActive = true AND Employee_No__c != '' AND Stay_or_not__c = '在职'
        //     ]);
        // } else if ('Contact'.equals(executeType)) {
        //     // 联系人接口
        
        return Database.getQueryLocator([
            select Id, trigger606Flag__c from Contact where Isactive__c = '有效' AND RecordTypeId != :recordTypeId 
                AND MobilePhone != '' AND trigger606Flag__c = true
        ]);
        // } else if ('Inspection_Report'.equals(executeType)) {
        //     // 点检报告接口
        //     return Database.getQueryLocator([
        //         select Id, Name, Status__c from Inspection_Report__c where Status__c = '批准'
        //         AND RecordtypeId = '0121m000000m3Bi'
        //     ]);
        // } else if ('NewMaintenanceReport_Task'.equals(executeType) && IdList != null && IdList.size() > 0) {
        //     // 维修合同接口
        //     return Database.getQueryLocator([
        //         select Id, Name from NewMaintenanceReport_Task__c where Id IN: IdList
        //     ]);
        // } else if ('NewMaintenanceReport_Task'.equals(executeType)) {
        //     return Database.getQueryLocator([
        //         select Id, Name from NewMaintenanceReport_Task__c
        //     ]);
        // } else if ('Repair'.equals(executeType) && IdList != null && IdList.size() > 0) {
        //     // 修理接口
        //     return Database.getQueryLocator([
        //         select Id, Name from Repair__c where Id IN: IdList
        //     ]);
        // } else if ('Repair'.equals(executeType) && String.isNotBlank(idStr)) {
        //     // 修理接口
        //     return Database.getQueryLocator([
        //         select Id, Name from Repair__c where Id = :idStr
        //     ]);
        // } else if ('Repair'.equals(executeType)) {
        //     return Database.getQueryLocator([
        //         select Id, Name from Repair__c
        //     ]);
        // }
        // // NewMaintenanceReport_Task__c
        // return Database.getQueryLocator(query);
 
    }
 
    global void execute(Database.BatchableContext BC, List<Contact> contactList) {
        List<String> IdList = new List<String>();
        List<Contact> trigger606List = new List<Contact>();
        List<Contact> updateContactList = new List<Contact>();
        if (contactList != null && contactList.size() > 0) {
            for (Contact con : contactList) {
                if(con.trigger606Flag__c){
                    IdList.add(con.Id);
                    trigger606List.add(con);
                }
            }
        }
        if(IdList.size() > 0){
            NFM606Controller.executeNotFuture(null, IdList);
            for(Contact con : trigger606List){
                con.trigger606Flag__c = false;
                updateContactList.add(con);
            }
        }
        if(updateContactList.size() > 0){
            update updateContactList;
        }
        // List < String > sobjectList = new List < String > ();
        // for (Sobject sobj: scope) {
        //     sobjectList.add(sobj.Id);
 
        // }
        // if (sobjectList.size() > 0) {
        //     if ('User'.equals(executeType)) {
        //         // List < String > employeeNoList = new List < String > ();
        //         // List < User > getUserList = [SELECT Id, IsActive, Employee_No__c FROM User WHERE Id In: sobjectList];
        //         // for (User user: getUserList) {
        //         //     employeeNoList.add(user.Employee_No__c);
        //         // }
        //         // if (employeeNoList.size() > 0) {
        //         //     NFM621Controller.executefuture('', employeeNoList);
        //         // }
        //         NFM621Controller.executefuture('', sobjectList);
        //     } else if ('Contact'.equals(executeType)) {
        //         NFM606Controller.executeNotFuture(null, sobjectList);
        //     } else if ('Inspection_Report'.equals(executeType)) {
        //         NFM602Controller.executeNotFuture(null, sobjectList);
        //     } else if ('NewMaintenanceReport_Task'.equals(executeType)) {
        //         NFM605Controller.executeNotFuture(null, sobjectList);
        //     } else if ('Repair'.equals(executeType)) {
        //         NFM603Controller.executefuture(null, sobjectList);
        //     }
        // }
    }
 
    global void finish(Database.BatchableContext BC) {
 
    }
}