buli
2023-05-23 07390e2fcb4adf27c928335bf27ae7939c5a80ad
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
global class OPDIsAccountBatch implements Database.Batchable<sObject> {
    public String query;
    public String Id;
    global OPDIsAccountBatch() {
       this.query = query;
    }
    global OPDIsAccountBatch(String Id) {
        this.query = query;
        this.Id = Id;
    }   
    global Database.QueryLocator start(Database.BatchableContext bc) {
        query = 'SELECT Id, Name,IsOPD_Account__c,Rental_Apply__c FROM Rental_Apply_Equipment_Set__c ';
        query +=  ' WHERE   (Bollow_Date__c > 2020-04-01 or createddate  > 2020-03-31T23:59:59.000+0000 ) '+
            ' and  IsOPD_Account__c = 1 and Cancel_Select__c = false ';
        if(String.isNotBlank(this.Id)){
            query += '  AND Rental_Apply__c = \''+this.Id+'\'';
        }
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, list<Sobject> scope) {
        List<Rental_Apply_Equipment_Set__c> RAES_objs = new List<Rental_Apply_Equipment_Set__c>();
        RAES_objs = scope;
        Map<String,Rental_Apply__c> raMap = new Map<String,Rental_Apply__c>();
        if(RAES_objs.size()>0){
            Boolean IsOPDAccountFlag = false;
            for (Rental_Apply_Equipment_Set__c rAES_obj: RAES_objs) {
                Rental_Apply__c ra= new Rental_Apply__c();
                ra.Id = rAES_obj.Rental_Apply__c;
                if(rAES_obj.IsOPD_Account__c !=null && rAES_obj.IsOPD_Account__c.intValue()==1){
                    ra.IsOPD_Account__c = 1;
                }
                if(!raMap.containsKey(rAES_obj.Rental_Apply__c)){
                       raMap.put(rAES_obj.Rental_Apply__c,ra); 
                }
            }
            if(raMap.size()>0){
                List<Rental_Apply__c> raList = (List<Rental_Apply__c>)raMap.values();
                update  raList;
            }
        }        
    }
    global void finish(Database.BatchableContext BC) {
    }
    public static void test1111111(){
        integer i =0;
        
    }
}