global class OPDLendSortCopyToSortBeforeBatch implements Database.Batchable { // SWAG-BYD6DD XHL 2021/02/20 public String query; List oPDPlanIdList = null; global OPDLendSortCopyToSortBeforeBatch() { this.query = query; } global OPDLendSortCopyToSortBeforeBatch(List oPDPlanIdList) { this.oPDPlanIdList = oPDPlanIdList; } global Database.QueryLocator start(Database.BatchableContext bc) { if (oPDPlanIdList <> null) { return Database.getQueryLocator([SELECT Id, Name, OPDPlan_ImplementDate__c,OPDLendSort__c,OPDLendSortDraft__c,OPDLendSortBefore__c,Status__c FROM OPDPlan__c WHERE (OPDLendSort__c != null OR OPDLendSortDraft__c != null OR OPDLendSortBefore__c != null) AND Status__c = '计划中' AND Id In :oPDPlanIdList]); } else { return Database.getQueryLocator([SELECT Id, Name, OPDPlan_ImplementDate__c,OPDLendSort__c,OPDLendSortDraft__c,OPDLendSortBefore__c,Status__c FROM OPDPlan__c WHERE Status__c = '计划中' AND (OPDLendSort__c != null OR OPDLendSortDraft__c != null OR OPDLendSortBefore__c != null)]); } } global void execute(Database.BatchableContext BC, List oPDPlanList) { for(OPDPlan__c opdp : oPDPlanList) { opdp.OPDLendSortBefore__c = null;//备品出借优先度(上月)置空 opdp.OPDLendSortBefore__c = opdp.OPDLendSort__c;//备品出借优先度 赋值给 备品出借优先度(上月) opdp.OPDLendSort__c = null;//备品出借优先度 置空 opdp.OPDLendSortDraft__c = null;//备品出借优先度草案中 置空 opdp.SortDate__c = null; //排序日期 置空 } if (oPDPlanList != null && oPDPlanList.size() > 0) { update oPDPlanList; } } global void finish(Database.BatchableContext BC) { } }