高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
global class AssetUseInfoBatch implements Database.Batchable<sObject> {
    
    private Integer dt;
 
    global AssetUseInfoBatch() {
        
    }
    // 测试用
    global AssetUseInfoBatch(Integer intDate) {
        dt = intDate;
    }
 
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator([
            select Id, Use_Info__c from Asset
            ]);
    }
 
       global void execute(Database.BatchableContext BC, List<sObject> sList) {
        List<Asset> updateList = new List<Asset>();
        Integer year = 0;
        if (dt == null) {
            year = Date.today().year();
        } else {
            year = dt;
        }
 
        for (sObject sobj : sList) {
            Asset ast = (Asset) sobj;
            if (year == 2018) {
                ast.Use_Info_2018__c = ast.Use_Info__c;
            } else if (year == 2019) {
                ast.Use_Info_2019__c = ast.Use_Info__c;
            } else if (year == 2020) {
                ast.Use_Info_2020__c = ast.Use_Info__c;
            } else if (year == 2021) {
                ast.Use_Info_2021__c = ast.Use_Info__c;
            } else if (year == 2022) {
                ast.Use_Info_2022__c = ast.Use_Info__c;
            } else if (year == 2023) {
                ast.Use_Info_2023__c = ast.Use_Info__c;
            } else if (year == 2024) {
                ast.Use_Info_2024__c = ast.Use_Info__c;
            } else if (year == 2025) {
                ast.Use_Info_2025__c = ast.Use_Info__c;
            } else {
                break;
            }
            updateList.add(ast);
        }
 
        if (updateList.size() > 0) {
            update updateList;
        }
    }
    
    global void finish(Database.BatchableContext BC) {
        
    }
    
}