global class SoakupHPDeptTeamSchedule implements Schedulable { global void execute(SchedulableContext SC) { List batchUser = [select Id, Name from User where Name = 'Batch']; if (batchUser.size() == 0) { return; } String[] recTypes = new String[] {'診療科 呼吸科', '診療科 婦人科', '診療科 普外科', '診療科 泌尿科', '診療科 消化科', '診療科 耳鼻喉科', '診療科 その他'}; List rects = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN :recTypes]; List deptRectIds = new List(); for (RecordType rect : rects) { deptRectIds.add(rect.Id); } // バッチ実行 // 10病院ずつ処理する Date toDate = Date.today(); Date yesterDate = toDate.addDays(-1); Date mon1stDate = Date.newInstance(toDate.year(), toDate.month(), 1); //每月到今天的工作日 Integer workdays = UpdateUserTextColBatch.getOlympusWorkDayCount(mon1stDate, toDate); //每月到昨天的工作日 Integer workdays1 = UpdateUserTextColBatch.getOlympusWorkDayCount(mon1stDate, yesterDate); //Integer Soakup_NotExecute_Day = Integer.valueOf(System.Label.Soakup_NotExecute_Day); Integer SSBacth_Execute_Day = Integer.valueOf(System.Label.SSBacth_Execute_Day); if (workdays1 == SSBacth_Execute_Day || workdays != SSBacth_Execute_Day) { Id execBTId = Database.executeBatch(new SoakupHPDeptTeamBatch(deptRectIds, batchUser[0].Id, '6.华南', '4.西南'), 10); execBTId = Database.executeBatch(new SoakupHPDeptTeamBatch(deptRectIds, batchUser[0].Id, '2.东北', '3.西北'), 10); execBTId = Database.executeBatch(new SoakupHPDeptTeamBatch(deptRectIds, batchUser[0].Id, '1.华北', null), 10); execBTId = Database.executeBatch(new SoakupHPDeptTeamBatch(deptRectIds, batchUser[0].Id, '5.华东', null), 10); } } }