//20230203 lt 计划的作业优化 --- 继承加“, Database.Stateful”,不然removeOtherSc方法空指针
|
global class NFM402Batch implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful {
|
public String query;
|
|
//20230203 lt 计划的作业优化 一小时两次 start
|
private BatchEmailUtil.ScBean scB1;
|
//20230203 lt 计划的作业优化 一小时两次 end
|
|
global NFM402Batch() {
|
this.query = query;
|
}
|
|
global Database.QueryLocator start(Database.BatchableContext bc) {
|
|
//20230203 lt 计划的作业优化 一小时两次 start
|
scB1 = BatchEmailUtil.setSc1('NFM402Schedule', 0, 23, 0, '0 30 *', null);
|
if (System.Test.isRunningTest() == false) {
|
for(CronTrigger ct : [SELECT Id FROM CronTrigger WHERE CronJobDetail.Name =: scB1.scName]) {
|
System.abortJob(ct.Id);
|
}
|
system.schedule(scB1.scName, scB1.scTime, new NFM402Schedule());
|
}
|
//20230203 lt 计划的作业优化 一小时两次 end
|
|
query = 'select id from Repair__c where AsyncData__c = true and (Complaint_Number__c = null or Complaint_Number__c = \'\')';
|
return Database.getQueryLocator(query);
|
}
|
|
global void execute(Database.BatchableContext BC, list<Repair__c> scope) {
|
List<QIS_Report__c> qisList = [
|
select id from QIS_Report__c where AsyncData__c = true and (Complaint_Number__c = null or Complaint_Number__c = '')
|
];
|
Set<String> tempids = new Set<String>();
|
if (scope.size() > 0) {
|
for(Repair__c rep : scope){
|
tempids.add(rep.Id);
|
}
|
}
|
if (qisList.size() > 0) {
|
for (QIS_Report__c qis : qisList) {
|
tempids.add(qis.Id);
|
}
|
}
|
List<String> ids = new List<String>();
|
for (String id : tempids ) {
|
ids.add(id);
|
}
|
|
try {
|
if (ids.size()>0) {
|
NFM402Controller.sendRequest(ids);
|
}
|
}
|
catch (Exception e) {
|
System.debug(e.getStackTraceString());
|
}
|
|
}
|
|
global void finish(Database.BatchableContext BC) {
|
BatchEmailUtil.removeOtherSc('NFM402Schedule', scB1.scName); //20230203 lt 计划的作业优化
|
// if (Test.isRunningTest() == false) {
|
//update by rentongxiao 生成PDF
|
// Database.executeBatch(new RepairToPDFBatch(), 100);
|
// Database.executeBatch(new RepairToPDFBatch(), 50);
|
// }
|
|
}
|
}
|