liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
global class ASOTDeleteRealBatch implements Database.Batchable<sObject>,Database.Stateful {
    public String query;
    private BatchIF_Log__c iflog;
    global ASOTDeleteRealBatch() {
        this.query = query;
    }
 
    global Database.QueryLocator start(Database.BatchableContext bc) {
        system.debug('执行start');
        iflog = new BatchIF_Log__c();
        iflog.Type__c = 'PushNotification';
        iflog.Log__c  = 'CoverageTargetHPBatch start\n';
        iflog.ErrorLog__c = '';
        insert iflog;
 
        query = 'select id,Renew_Finish_Else__c,Renew_Finish_Correlation_Lightsource__c,Renew_Finish_Rigid_Mirror_3__c,Renew_Finish_Rigid_Mirror_1__c,'
                   +' Finish_Correlation_Lightsource__c,Finish_Rigid_Mirror_2__c,Finish_Rigid_Mirror_1__c '
                   +' from Account_Service_Of_Target__c '
                   +' where (Finish_Asset__c!=0 and Finish_Asset__c!=null) or (Finish_Coverage_Asset__c != 0 and Finish_Coverage_Asset__c!=null)';
        return Database.getQueryLocator(query);
    }
 
    global void execute(Database.BatchableContext BC, list<Account_Service_Of_Target__c> asotList) {
        List<Account_Service_Of_Target__c> asotL = new  List<Account_Service_Of_Target__c>();
        // 清空客户-目标的实际设备数
        for (Account_Service_Of_Target__c  asot : asotList) {
         asot.Renew_Finish_Else__c = 0;
         asot.Renew_Finish_Correlation_Lightsource__c = 0;
         asot.Renew_Finish_Rigid_Mirror_3__c = 0;
         asot.Renew_Finish_Rigid_Mirror_1__c = 0;
         asot.Finish_Correlation_Lightsource__c = 0;
         asot.Finish_Rigid_Mirror_2__c = 0;
         asot.Finish_Rigid_Mirror_1__c = 0;
         asotL.add(asot);
      }
      update asotL;
    }
 
    global void finish(Database.BatchableContext BC) {
        iflog.Log__c += '\nASOTDeleteRealBatch end';
        String tmp = iflog.ErrorLog__c;
        if (tmp.length() > 65000) {
            tmp = tmp.substring(0, 65000);
            tmp += ' ...have more lines...';
            iflog.ErrorLog__c = tmp;
        }
        update iflog;
      EquipmentRealCoverageRealBatch batch1 = new EquipmentRealCoverageRealBatch();
      Database.executeBatch(batch1);
      EquipmentRenewMoleculeBatch  batch2 = new EquipmentRenewMoleculeBatch();
      Database.executeBatch(batch2);
    }
}