global class updateContectBatch implements Database.Batchable<sObject>,Database.AllowsCallouts, Database.Stateful {
|
// 如果批量执行失败,用于手动执行失败的数据
|
public String ConID;
|
global updateContectBatch(String ConID) {
|
this.ConID = ConID;
|
}
|
global updateContectBatch() {
|
|
}
|
|
global Database.QueryLocator start(Database.BatchableContext bc) {
|
// 检索点检计划(将数据库中的数据检索出来)
|
String query = ' select Id, TOOREND__c,TOOREND_txt__c,Maintenance_Contract__c, ' +
|
' Planned_End_Date__c, Planned_Start_Date__c,Need_copy__c,Implementation_Rates__c, ' +
|
' Timeliness_Rate__c, Implementation_Rate__c From Inspectup_Plan__c';
|
if (String.isNotBlank(ConID)) {
|
query += ' where Maintenance_Contract__c =: ConID';
|
}else{
|
// query += ' where Need_copy__c = true or Implementation_Rates__c = 100 ';
|
query += ' where Need_copy__c = true ';
|
}
|
return Database.getQueryLocator(query);
|
}
|
// Date nowDay = Date.today();
|
global void execute(Database.BatchableContext BC, list<Inspectup_Plan__c> IPlanList) {
|
// 维修合同下对应的多个点检计划
|
// Map<String, List<Inspectup_Plan__c>> ConToIPlanMap = new Map<String, List<Inspectup_Plan__c>>();
|
// System.debug('IPlanList:12345' + IPlanList);
|
// List<Inspectup_Plan__c> ConToIPlanList = new List<Inspectup_Plan__c>();
|
// Set<Id> conudList = new Set<Id>();
|
// List<Maintenance_Contract__c> ConList = new List<Maintenance_Contract__c>();
|
for (Inspectup_Plan__c IPInfo : IPlanList) {
|
// if (IPinfo.Need_copy__c == true) {
|
IPInfo.TOOREND_txt__c = IPInfo.TOOREND__c;
|
// ConToIPlanList.add(IPinfo);
|
// }
|
// if (IPinfo.Implementation_Rates__c == 100) {
|
// conudList.add(IPInfo.Maintenance_Contract__c);
|
// }
|
// String ConID = String.valueOf(IPInfo.Maintenance_Contract__c);
|
// List<Inspectup_Plan__c> IPInfoList = new List<Inspectup_Plan__c>();
|
// if (ConToIPlanMap.containsKey(ConID)) {
|
// IPInfoList = ConToIPlanMap.get(ConID);
|
// }
|
// if (nowDay >= IPInfo.Planned_Start_Date__c) {
|
// IPInfoList.add(IPInfo);
|
// ConToIPlanMap.put(ConID, IPInfoList);
|
// }
|
}
|
// List<AggregateResult> SecConList = [
|
// select Maintenance_Contract__c,sum(Ben_Actual_Times__c) Ben_Actual_Times,
|
// AVG(Maintenance_Contract__r.Actual_Times_txt__c) Actual_Times
|
// from Inspectup_Plan__c where Maintenance_Contract__c in :conudList
|
// group by Maintenance_Contract__c
|
// ];
|
// if (SecConList != null && SecConList.size() > 0) {
|
// for (AggregateResult Rpc : SecConList) {
|
// if (String.valueOf(Rpc.get('Ben_Actual_Times')) != String.valueOf(Rpc.get('Actual_Times')) ) {
|
// Maintenance_Contract__c con = new Maintenance_Contract__c();
|
// con.Id = String.valueOf(Rpc.get('Maintenance_Contract__c'));
|
// con.Actual_Times_txt__c = Integer.valueOf(Rpc.get('Ben_Actual_Times'));
|
// ConList.add(con);
|
// }
|
// }
|
// }
|
// System.debug('ConToIPlanMap:12345' + ConToIPlanMap);
|
// // 及时率 = 计划期内实际执行数/计划点检对象数*计划点检次数
|
// // 计划期内实际执行数 = 点检报告书日期在点检计划期间内(点检对象数)
|
// // 计划点检对象数 = 合同点检的总对象数
|
// // 计划点检次数 = 第几次点检计划(如何确定在第几次点检计划?)
|
// // 实施率 = 实际执行数/计划点检对象数*计划点检次数
|
// // 实际执行数 = 点检报告书日期在点检计划期间内和外(点检对象数)
|
// List<Maintenance_Contract__c> MCInfoList = new List<Maintenance_Contract__c>();
|
// for (String ConID : ConToIPlanMap.keySet()) {
|
// Maintenance_Contract__c MC = new Maintenance_Contract__c();
|
// MC.Id = ConID;
|
// // 到期点检次数
|
// MC.Due_Inspection_Times__c = ConToIPlanMap.get(ConID).size();
|
// MCInfoList.add(MC);
|
// }
|
// System.debug('MCInfoList:' + MCInfoList);
|
if (IPlanList.size() > 0) {
|
update IPlanList;
|
}
|
// if (ConList.size() > 0) {
|
// update ConList;
|
// }
|
}
|
|
global void finish(Database.BatchableContext BC) {
|
// 服务合同报告书任务ToAWS XHL Start
|
Id execBTId = Database.executebatch(new NFM605Batch (),1);
|
// 服务合同报告书任务ToAWS XHL End
|
}
|
}
|