涂煌豪
2022-05-16 d075f9ef422d029599749fcf65c44740dbe4d8f9
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
global class NFM116Batch implements Database.Batchable<sObject>, Database.AllowsCallouts {
    // 设定发送指定签收单的ID
    public String setId;
    // 设定执行日期
    public Date setDate;
    // 是否发送指定日期30天之后的签收单
    public Boolean isAfterDate = false;
    // 是否发送指定的签收单
    public Boolean isAppoint = false;
    // 设定发送的签收单的IdList
    public List<String> setIdList;
 
    // Default 发送当日符合条件的签收单
    global NFM116Batch() {
        this.setDate = Date.today();
    }
    // 发送指定日期符合条件的签收单, eg: testDate = Date.newInstance(2022, 05, 02),发送20220501完成签收的签收单
    global NFM116Batch(Date testDate) {
        this.setDate = testDate;
    }
    // 发送在指定日期30天之后的所有符合条件的签收单(isAfterDate为true的时候)
    global NFM116Batch(Date testDate, Boolean isAfterDate) {
        this.setDate = testDate;
        this.isAppoint = true;
        this.isAfterDate = isAfterDate;
    }
    // 发送指定Id的签收单
    global NFM116Batch(String setId) {
        this.setId = setId;
        this.isAppoint = true;
    }
    // 发送指定IdList的签收单
    global NFM116Batch(List<String> setIdList) {
        this.setIdList = setIdList;
        this.isAppoint = true;
    }
 
    global Database.QueryLocator start(Database.BatchableContext bc) {
        String query = 'select Id from eSignForm__c where agencyAcceptSAPResult__c != null and HPAcceptSAPResult__c != null ';
        if(String.isNotBlank(setId)){
            query += ' and Id =: setId ';
        } else if (setIdList != null && setIdList.size() > 0) {
            query += ' and Id IN: setIdList ';
        } else if(!isAppoint){
            query += ' and SAPReportDate__c = ' + setDate.addDays(-1).format().replace('/', '-') ;
        } else if(isAfterDate){
            query += ' and SAPReportDate__c > ' + setDate.addDays(-30).format().replace('/', '-') ;
        }
        System.debug('thhquery:' + query);
        return Database.getQueryLocator(query);
    }
 
    global void execute(Database.BatchableContext BC, List<eSignForm__c> eSignFormList) {
        List<String> eSignFormIdList = new List<String>();
        if(eSignFormList.size() > 0){
            for(eSignForm__c es : eSignFormList){
                eSignFormIdList.add(es.Id);
            }
        }
        System.debug('eSignFormIdList1:' + eSignFormIdList);
        if(eSignFormIdList.size() > 0){
            NFM116Controller.executeNotFuture(null, eSignFormIdList);
        }
    }
 
    global void finish(Database.BatchableContext BC) {
        
    }
}