高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
force-app/main/default/classes/BatchEmailUtil.cls
@@ -189,4 +189,68 @@
        message.setUseSignature(false);
        addMessage(message);
    }
    //20230203 lt 计划的作业优化  一小时两次 start
    public Class ScBean {
        public String scName;
        public String scTime;
    }
    public static ScBean setSc1(String baseName, Integer minhour, Integer maxhour, Integer minMin, String spbefore, String spafter) {
        Datetime dt = Datetime.now();
        Integer year = Integer.valueOf(dt.format('yyyy'));//2021-12-29 you YYYY--->yyyy 是因为最后一周跨年了
        Integer month = Integer.valueOf(dt.format('MM'));
        Integer day = Integer.valueOf(dt.format('dd'));
        Integer hour = Integer.valueOf(dt.format('HH'));
        Integer min = Integer.valueOf(dt.format('mm'));
        ScBean b = new ScBean();
        if (hour == maxhour && min >= (minMin + 30)) {
            b.scName = baseName + '001';
            if (spafter != null && String.isNotBlank(spafter)) {
                b.scName = baseName + '005';
                b.scTime = spafter + ' ' + day + ' ' + month + ' ? ' + year;
                // system.schedule(sJobame,spafter + ' ' + day + ' ' + month + ' ? ' + year, new AgencyShareUpdateBatchSchedule());
                return b;
            }
            else {
                dt = Datetime.now().addDays(1);
                year = Integer.valueOf(dt.format('yyyy'));//2021-12-29 you YYYY--->yyyy 是因为最后一周跨年了
                month = Integer.valueOf(dt.format('MM'));
                day = Integer.valueOf(dt.format('dd'));
                hour = Integer.valueOf(dt.format('HH'));
                min = Integer.valueOf(dt.format('mm'));
                if (spbefore != null && String.isNotBlank(spbefore)) {
                    b.scName = baseName + '006';
                    b.scTime = spbefore + ' ' + day + ' ' + month + ' ? ' + year;
                }
                else {
                    b.scTime = '0 ' + minMin + ' ' + minhour + ' ' + day + ' ' + month + ' ? ' + year;
                }
            }
        }
        else if (min < minMin) {
            b.scName = baseName + '001';
            b.scTime = '0 ' + minMin + ' ' + hour + ' ' + day + ' ' + month + ' ? ' + year;
        }
        else if (min < minMin + 30) {
            b.scName = baseName + '002';
            b.scTime = '0 ' + (minMin + 30) + ' ' + hour + ' ' + day + ' ' + month + ' ? ' + year;
        }
        else {
            b.scName = baseName + '001';
            b.scTime = '0 ' + minMin + ' ' + (hour + 1) +' ' + day + ' ' + month + ' ? ' + year;
        }
        return b;
    }
    public static void removeOtherSc(String likeName, String needName) {
        String likeStr = likeName + '00%';
        for(CronTrigger ct : [SELECT Id,CronJobDetailId,CronExpression,CronJobDetail.Name
                                FROM CronTrigger
                               WHERE CronJobDetail.Name Like :likeStr
                                 AND CronJobDetail.Name != :needName]){
            System.abortJob(ct.Id);
        }
    }
    //20230203 lt 计划的作业优化  一小时两次 end
}