global class OPDPlanSystemDelayBatch implements Database.Batchable { // SWAG-BXW4AH XHL 2021/02/27 【委托】 OPD计划再申请逻辑设置 public String query; List oPDPlanIdList = null; global OPDPlanSystemDelayBatch() { this.query = query; } global OPDPlanSystemDelayBatch(List oPDPlanIdList) { this.oPDPlanIdList = oPDPlanIdList; } global Database.QueryLocator start(Database.BatchableContext bc) { if (oPDPlanIdList <> null) { return Database.getQueryLocator([SELECT Id, Name, OPDPlan_ImplementDate__c, SystemDelayFlag__c, Status__c, SystemDelayMark__c FROM OPDPlan__c WHERE SystemDelayFlag__c = true AND Id In :oPDPlanIdList]); } else { return Database.getQueryLocator([SELECT Id, Name, OPDPlan_ImplementDate__c, SystemDelayFlag__c, Status__c, SystemDelayMark__c FROM OPDPlan__c WHERE SystemDelayFlag__c = true]); } } global void execute(Database.BatchableContext BC, List oPDPlanList) { List insertCancelPostponePlanList = new List (); for(OPDPlan__c opdp : oPDPlanList) { if (opdp.SystemDelayFlag__c) { CancelPostponePlan__c cpp = new CancelPostponePlan__c(); cpp.CancelOPDPlan__c = opdp.Id; cpp.cancelReasonCombobox__c = '系统自动延期'; cpp.NextPlanDate__c = opdp.OPDPlan_ImplementDate__c.addDays(30); cpp.Status__c = '延期成功'; cpp.RecordTypeId = '01210000000gQyM'; insertCancelPostponePlanList.add(cpp); } } if (insertCancelPostponePlanList.size() > 0) { insert insertCancelPostponePlanList; } } global void finish(Database.BatchableContext BC) { Id execBTId = Database.executebatch(new OPDPlanMarkBatch(), 100); } }