global class OPDPlanMarkBatchSchedule implements Schedulable { //SWAG-BA65JL 2019/03/22 XHL AddStart global void execute(SchedulableContext sc) { 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 OSFBacth_Execute_Day = Integer.valueOf(System.Label.OSFBacth_Execute_Day); //以下为每个季度的第一个工作日执行,分别为4月、7月、10月、1月的第一个工作日执行, //OPD计划的特别执行,季度计划不参与执行,若需要执行,请调OPDQuarterPlanPhotographBatch里面的方法去执行,特此说明 //获取这个月的月份 Integer executeMonth = toDate.month(); if (workdays1 != OSFBacth_Execute_Day && workdays == OSFBacth_Execute_Day) { if ( executeMonth == 1 || executeMonth == 4 || executeMonth == 7 || executeMonth == 10) { Database.executebatch(new OPDQuarterPlanPhotographBatch(), 100); } } // 2020-11-6 mzy update //if (workdays1 != OSFBacth_Execute_Day && workdays == OSFBacth_Execute_Day) { // Id execBTId = database.executebatch(new OPDPlanMarkBatch(),100); //} 2020-11-6 mzy update // 2020-11-6 mzy SWAG-BSC5WP add start //每个月的倒数第二个工作日需要进行执行 //获取这个月的最后一天 Date days = Date.newInstance(toDate.year(), toDate.month() + 1, 0); Integer monDays = days.day(); Date dayEnd = Date.newInstance(toDate.year(), toDate.month(), monDays); //获取这个月有多少个工作日 Integer monWorkDays = UpdateUserTextColBatch.getOlympusWorkDayCount(mon1stDate, dayEnd); //获取判断今天是否是工作日 List ssDay = [Select IsWorkDay__c From OlympusCalendar__c Where Date__c = :toDate]; //如果 这个月的工作日天数 - 每个月开始到今天的工作日天数 = 1 并且 今天是工作日 , 则说明今天是倒数第二个工作日 if (monWorkDays - workdays == 1 && ssDay != null && ssDay.size() > 0 && ssDay.get(0).IsWorkDay__c == 1 ) { // 将此执行语句转移至OPDPlanSystemDelayBatch finish内 SWAG-BXW4AH 【委托】 OPD计划再申请逻辑设置 // Id execBTId = Database.executebatch(new OPDPlanMarkBatch(), 100); // SWAG-C8U67Z 【委托】OPD计划页面TAT字段添加 2022/01/04 start // 备品审批优先度和出库优先度 // 时间节点:上月拍照日期-本月拍照日期 // 注意时间节点重叠产生的数据交叉的问题 // 取得上个月的拍照日 Date date_1mon_ago = toDate.addMonths(-1); Date first_1mon_ago = Date.newInstance(date_1mon_ago.year(), date_1mon_ago.month(), 1); Date last_1mon_ago = Date.newInstance(toDate.year(), toDate.month(), 0); // 上个月的所有工作日 List workdays_1mon_ago = [SELECT Date__c FROM OlympusCalendar__c WHERE Date__c >= :first_1mon_ago AND Date__c <= :last_1mon_ago AND IsWorkDay__c = 1]; if (workdays_1mon_ago != null && workdays_1mon_ago.size() > 2) { Date last2toend_1mon_ago = workdays_1mon_ago[workdays_1mon_ago.size() - 2].Date__c; Id execBTId = Database.executeBatch(new SparePartsSequencingBatch(last2toend_1mon_ago, toDate), 5); } // 挪到SparePartsSequencingBatch去执行 // Id execBTId = Database.executebatch(new OPDPlanSystemDelayBatch(), 100); // SWAG-C8U67Z 【委托】OPD计划页面TAT字段添加 2022/01/04 end } // 2020-11-6 mzy SWAG-BSC5WP add end // ========================================================================================== // 2021-02-19 XHL SWAG-BYD6DD Start // 这个月的工作日天数 - 每个月开始到今天的工作日天数 = 3 并且 今天是工作日 , 则说明今天是倒数第4个工作日 if (monWorkDays - workdays == 3 && ssDay != null && ssDay.size() > 0 && ssDay.get(0).IsWorkDay__c == 1) { Id execBTId = Database.executebatch(new OPDLendSortCopyToSortBeforeBatch(), 100); } // 2021-02-19 XHL SWAG-BYD6DD End // ========================================================================================== } }