global class CheckPlanHistory implements Database.Batchable, Database.AllowsCallouts, Database.Stateful { public List IPIdList; global CheckPlanHistory(List IPIdList) { this.IPIdList = IPIdList; } global CheckPlanHistory() { } global Database.QueryLocator start(Database.BatchableContext bc) { String query = ' select Id, name, AssetId__c, Failourassetnumber__c, Inspection_ReportId__c, Inspection_ReportId__r.Inspectup_Plan__c, '; query += ' Inspection_ReportId__r.Inspection_Date__c, Inspection_ReportId__r.Failourassetnumber__c, '; query += ' Inspection_ReportId__r.Inspectup_Plan__r.Planned_Start_Date__c, Inspection_ReportId__r.Inspectup_Plan__r.Planned_End_Date__c, '; query += ' Inspection_ReportId__r.Inspectup_Plan__r.Check_Object_Quantity__c, Inspection_ReportId__r.Start_Date__c, '; query += ' Inspection_ReportId__r.Inspection_asset_number__c, ItemStatus__c,Inspection_ReportId__r.Inspectup_Plan__r.Execution_End_Date__c, '; query += ' Inspection_ReportId__r.Abandonment_Num__c, Inspection_ReportId__r.Status__c from Inspection_Item__c '; query += ' where Inspection_ReportId__r.Inspectup_Plan__c in: IPIdList AND Inspection_ReportId__r.Status__c = \'批准\' '; System.debug('1234567890'+query); return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, list ItemInfoList) { System.debug('1234567890'); BatchIF_Log__c iflog = new BatchIF_Log__c(); iflog.Type__c = 'checkMaplog'; iflog.RowDataFlg__c = false; iflog.Log__c = '1234567890'; iflog.ErrorLog__c = ''; insert iflog; Map> iplanMap = new Map>(); Map SumNumMap = new Map(); Map IDateMap = new Map(); if (ItemInfoList.size() > 0) { for (Inspection_Item__c items : ItemInfoList) { Decimal aEQs = 0;//实际执行数(季度):没去重 计划内外 String planId = items.Inspection_ReportId__r.Inspectup_Plan__c; if (iplanMap.containsKey(planId)) { SumNumMap = iplanMap.get(planId); } if (items.Inspection_ReportId__r.Inspection_Date__c >= items.Inspection_ReportId__r.Inspectup_Plan__r.Planned_Start_Date__c) { // 实际执行数(季度):没去重 计划内外 String aEQsKeyRepeat = planId + 'num'; if (SumNumMap.containsKey(aEQsKeyRepeat)) { aEQs = SumNumMap.get(aEQsKeyRepeat); } aEQs++; SumNumMap.put(aEQsKeyRepeat, aEQs); System.debug('-------7------' + SumNumMap ); } // 报告书 执行日 IDateMap.put(items.Inspection_ReportId__r.Inspectup_Plan__c + 'Start', items.Inspection_ReportId__r.Start_Date__c); // 点检计划 完成日 IDateMap.put(items.Inspection_ReportId__r.Inspectup_Plan__c + 'End', items.Inspection_ReportId__r.Inspectup_Plan__r.Execution_End_Date__c); } } List updateIPInfoList = new List(); if (IPIdList.size() > 0) { // 点检计划赋值 for (String iPId : IPIdList) { Inspectup_Plan__c IPlanInfo = new Inspectup_Plan__c(); IPlanInfo.Id = iPId; SumNumMap = iplanMap.get(iPId); System.debug('-------4------' + iplanMap); System.debug('-------2------' + SumNumMap); // BatchIF_Log__c checkMaplog = new BatchIF_Log__c(); // 20210911 gzw bug fix start // if (SumNumMap.size() > 0) { if (SumNumMap != null && SumNumMap.size() > 0 ) { IPlanInfo.Actual_Execute_Num__c = SumNumMap.get(iPId + 'num'); } updateIPInfoList.add(IPlanInfo); } } if (updateIPInfoList.size() > 0) { update updateIPInfoList; } } global void finish(Database.BatchableContext BC) { } }