global class AssetUseInfoBatch implements Database.Batchable { 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 sList) { List updateList = new List(); 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) { } }