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
/**
 * 20240106 sx add 处理OPD没有备品借出申请的batch
 *  */
 
global class exceteOPDHistoryNoRentalApplyBatch implements Database.Batchable<sObject>,Database.Stateful{
    public String query;
    public String aimDate = '';
 
    global exceteOPDHistoryNoRentalApplyBatch() {
        this.query = query;
    }
 
    global exceteOPDHistoryNoRentalApplyBatch(String tempdate) {
        this.aimDate = tempdate;
    }
 
    global Database.QueryLocator start(Database.BatchableContext bc) {
        String query = 'SELECT Id, OPDPlan_ImplementDate__c FROM OPDPlan__c where (Status__c = \'计划中\' OR Status__c = \'审批中\')  AND Rental_Apply2__c = null ';
        if(String.isNotBlank(aimDate)){
            query += 'AND OPDPlan_ImplementDate__c >=' + aimDate;
        }else{
            Date toDay = Date.today();
            query += 'AND OPDPlan_ImplementDate__c >= :toDay';
        }
        System.debug('query====' + query);
        return Database.getQueryLocator(query);
    }
 
    global void execute(Database.BatchableContext BC, List<sObject> scope) {
        
        List<OPDPlan__c> opdPlanList = scope;
        System.debug('opdPlanList====' + opdPlanList);
        if(opdPlanList.size() > 0){
            for(OPDPlan__c opd : opdPlanList){
                LexOPDSupplementaryController.newRentalApply(opd.Id);
            }
        }
    }
 
    global void finish(Database.BatchableContext BC) {
 
    }
}