global class RollupToUnprocessToMailBatch implements Database.Batchable { String query; global RollupToUnprocessToMailBatch() { } global Database.QueryLocator start(Database.BatchableContext BC) { query ='select id, status, createdby.name, createddate, targetObject.name '; query = query + 'from processinstance '; query = query + 'where status = \'Pending\' '; // 20210914 ljh SWAG-C6NAEV start query += ' and createddate > 2021-04-01T00:01:01.000+0000 '; // query += ' and Id in (\'04g1m000000G0KEAA0\',\'04g10000007rrRJAAY\') ';// 202100915 ljh 测试功能数据 // 20210914 ljh SWAG-C6NAEV end query = query + 'order by createdby.name '; system.debug(query); return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List scope) { List PiIdlist = new List(); List UserId = new List(); List TaskId = new List(); List toUpdateUser = new List(); List ScopeList = new List(); List getTaskDetails = new List(); Map userAndImf = new Map(); ScopeList = scope; for(processinstance pi : ScopeList){ PiIdlist.add(pi.Id); } getTaskDetails = [SELECT Id, ProcessInstanceId,ProcessInstance.status,ProcessInstance.targetObjectid, OriginalActorid, Actorid, IsDeleted, CreatedBy.name FROM ProcessInstanceWorkitem where ProcessInstanceId in:PiIdlist ]; for(ProcessInstanceWorkitem piw: getTaskDetails){ UserId.add(piw.OriginalActorid); if(userAndImf.containsKey(piw.OriginalActorid)){ String elseCache = userAndImf.get(piw.OriginalActorid); // 20210914 ljh 邮件换行 SWAG-C6NAEV start // elseCache = elseCache+ System.Label.Environment_Url+piw.ProcessInstance.targetObjectid +'
'; elseCache = elseCache+'\n'+ System.Label.Environment_Url+piw.ProcessInstance.targetObjectid; userAndImf.put(piw.OriginalActorid ,elseCache); }else{ // String InCache = System.Label.Environment_Url+piw.ProcessInstance.targetObjectid+'
'; String InCache = System.Label.Environment_Url+piw.ProcessInstance.targetObjectid; userAndImf.put(piw.OriginalActorid ,InCache); } // 20210914 ljh 邮件换行 SWAG-C6NAEV end } toUpdateUser = [select id,name,Unprocessed_Tack_Flag__c,Process_Task_List__c from user where id in:UserId]; //生成任务清单字段 //获取任务清单 for(User u:toUpdateUser){ if(userAndImf.containsKey(u.Id)){ if(u.Unprocessed_Tack_Flag__c==0||u.Unprocessed_Tack_Flag__c==233){ u.Process_Task_List__c = userAndImf.get(u.Id); u.Unprocessed_Tack_Flag__c =100; }else{ // 20210914 ljh 邮件换行 SWAG-C6NAEV start // u.Process_Task_List__c = u.Process_Task_List__c + userAndImf.get(u.Id); u.Process_Task_List__c = u.Process_Task_List__c +'\n'+ userAndImf.get(u.Id); // 20210914 ljh 邮件换行 SWAG-C6NAEV end } u.Unprocessed_Tack_Flag__c = u.Unprocessed_Tack_Flag__c+100; } } update toUpdateUser; } global void finish(Database.BatchableContext BC) { List toUpdateUser = [ select id, Send_Or_Not__c from user where Unprocessed_Tack_Flag__c!=0 ]; for(user u:toUpdateUser){ u.Send_Or_Not__c = true; } update toUpdateUser; } }