彭锟
2022-03-29 1a846a596c87cf9674caff2c0571962b9909fb58
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
global class NFM601Batch implements Database.Batchable<sObject>, Database.AllowsCallouts {
    public String query;
    public List < String > accountIdList;
    global NFM601Batch() {
        this.query = query;
    }
    global NFM601Batch(List < String > accountIdList) {
        this.accountIdList = accountIdList;
    }
 
    global Database.QueryLocator start(Database.BatchableContext bc) {  
        return Database.getQueryLocator([select Id,NFM601Tag__c from Account where NFM601Tag__c = true]);
        //return null;
        // if (accountIdList != null && accountIdList.size() > 0) {
        //     return Database.getQueryLocator([SELECT Id, RecordTypeId, Is_Active_Formula__c,AwaitToSendAWS__c
                    
        //             FROM Account 
        //             WHERE Id IN:accountIdList
        //             ]);
        // } else {
        //     return Database.getQueryLocator(
        //          [SELECT Id, RecordTypeId,Is_Active_Formula__c,AwaitToSendAWS__c
                    
        //             FROM Account WHERE AwaitToSendAWS__c = true OR (RecordTypeId= '01210000000Qem1AAC' AND Ban_On_Use_Date__c = :Date.today()-1)
        //         ]);
                
        //         // 批量发送历史数据 Start
        //         // [SELECT Id, RecordType_DeveloperName__c, RecordTypeId,
        //         //     Sap2sfdcDealers_ModifycationLogo__c, Is_Active_Formula__c,
        //         //     ContractSfdc2SapLog__c
        //         //     FROM Account WHERE (RecordTypeId = '01210000000QemGAAS' OR RecordTypeId = '01210000000Qem1AAC') AND Is_Active_Formula__c = '有效'
        //         // ]);
        //         // 批量发送历史数据 End
               
        //        //临时 发送给 AWS
        //        // [SELECT Id, RecordType_DeveloperName__c, RecordTypeId,
        //        //      Sap2sfdcDealers_ModifycationLogo__c, Is_Active_Formula__c,
        //        //      ContractSfdc2SapLog__c
        //        //      FROM Account WHERE (RecordTypeId = '01210000000Qem1AAC') AND Is_Active_Formula__c = '有效'
        //        //  ]);
        // }
 
    }
 
    global void execute(Database.BatchableContext BC , List<Account> accList) {
        List<String> accIdList = new List<String>();
        if(accList.size()>0){
            for(Account temp : accList){
                accIdList.add(temp.Id);
            }
            NFM601Controller.executefuture('', accIdList);
            for(Account temp : accList){
                temp.NFM601Tag__c = false;
            }
        }
        update accList;
        // List < String > accIdList = new List < String > ();
        // for (Account account: accountList) {
        //     account.AwaitToSendAWS__c = false;
        //     accIdList.add(account.Id);
        // }
 
        // if (accIdList.size() > 0) {
        //     // Datetime nowDT = Datetime.now();
        //     // String nowStr = nowDT.format('yyyyMMddHHmm');
        //     // BatchIF_Log__c iflog = new BatchIF_Log__c();
        //     // iflog.Type__c = 'NFM601'
        //     // iflog.Log__c = 'execute NFM_601 batch \n';
        //     // iflog.Name = nowStr;
        //     // iflog.MessageGroupNumber = nowStr;
        //     NFM601Controller.executefuture(null, accIdList);
 
        //     update accountList;
 
        // }
        
    }
 
    global void finish(Database.BatchableContext BC) {
        if(!Test.isRunningTest()){
            Id execBTId = Database.executeBatch(new NFM606Batch(), 200);
        }
    }
}