Explorar o código

修改预警规则

shengyang000 %!s(int64=3) %!d(string=hai) anos
pai
achega
5ca418e3d1

+ 4 - 4
src/main/java/com/unissoft/job/ToBeDoneJob.java

@@ -125,7 +125,7 @@ public class ToBeDoneJob implements Job, Serializable {
125
             startDate = DateUtil.getCurrMinute();
125
             startDate = DateUtil.getCurrMinute();
126
         } else if(timeType.equals(GrainConstant.STR_HOUR)) {
126
         } else if(timeType.equals(GrainConstant.STR_HOUR)) {
127
             startDate = DateUtil.getCurrHour();
127
             startDate = DateUtil.getCurrHour();
128
-        } else if(timeType.equals(GrainConstant.STR_DAY)) {
128
+        } else if(timeType.equals(GrainConstant.STR_DAY) || timeType.equals(GrainConstant.STR_WEEKDAY)) {
129
             startDate = DateUtil.getCurrDate();
129
             startDate = DateUtil.getCurrDate();
130
         } else if(timeType.equals(GrainConstant.STR_WEEK)) {
130
         } else if(timeType.equals(GrainConstant.STR_WEEK)) {
131
             startDate = DateUtil.getCurrDate();
131
             startDate = DateUtil.getCurrDate();
@@ -152,7 +152,7 @@ public class ToBeDoneJob implements Job, Serializable {
152
             date = DateUtils.addMinutes(baseDate, timeNum);
152
             date = DateUtils.addMinutes(baseDate, timeNum);
153
         } else if(timeType.equals(GrainConstant.STR_HOUR)) {
153
         } else if(timeType.equals(GrainConstant.STR_HOUR)) {
154
             date = DateUtils.addHours(baseDate, timeNum);
154
             date = DateUtils.addHours(baseDate, timeNum);
155
-        } else if(timeType.equals(GrainConstant.STR_DAY)) {
155
+        } else if(timeType.equals(GrainConstant.STR_DAY) || timeType.equals(GrainConstant.STR_WEEKDAY)) {
156
             date = DateUtils.addDays(baseDate, timeNum);
156
             date = DateUtils.addDays(baseDate, timeNum);
157
         } else if(timeType.equals(GrainConstant.STR_WEEK)) {
157
         } else if(timeType.equals(GrainConstant.STR_WEEK)) {
158
             date = DateUtils.addWeeks(baseDate, timeNum);
158
             date = DateUtils.addWeeks(baseDate, timeNum);
@@ -172,8 +172,8 @@ public class ToBeDoneJob implements Job, Serializable {
172
         Date warnDate = computeDate(endDate, timeType, 0 - timeNum);
172
         Date warnDate = computeDate(endDate, timeType, 0 - timeNum);
173
 
173
 
174
         //
174
         //
175
-        if(timeType.equals(GrainConstant.STR_DAY) || timeType.equals(GrainConstant.STR_WEEK) || timeType.equals(GrainConstant.STR_MONTH)
176
-                || timeType.equals(GrainConstant.STR_SEASON) || timeType.equals(GrainConstant.STR_YEAR)) {
175
+        if(timeType.equals(GrainConstant.STR_DAY) || timeType.equals(GrainConstant.STR_WEEKDAY) || timeType.equals(GrainConstant.STR_WEEK)
176
+                || timeType.equals(GrainConstant.STR_MONTH) || timeType.equals(GrainConstant.STR_SEASON) || timeType.equals(GrainConstant.STR_YEAR)) {
177
             //如果检查周期是 天、星期、月、季、年为单位,则计算为当天的工作时间8点整
177
             //如果检查周期是 天、星期、月、季、年为单位,则计算为当天的工作时间8点整
178
             warnDate = DateUtil.getSpecificDate(warnDate,8, 0, 0);
178
             warnDate = DateUtil.getSpecificDate(warnDate,8, 0, 0);
179
         }
179
         }

+ 4 - 0
src/main/java/com/unissoft/service/impl/QuartzServiceImpl.java

@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
13
 import org.apache.commons.lang.StringUtils;
13
 import org.apache.commons.lang.StringUtils;
14
 import org.json.JSONObject;
14
 import org.json.JSONObject;
15
 import org.quartz.*;
15
 import org.quartz.*;
16
+import org.quartz.impl.calendar.WeeklyCalendar;
16
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.beans.factory.annotation.Autowired;
17
 import org.springframework.stereotype.Service;
18
 import org.springframework.stereotype.Service;
18
 
19
 
@@ -37,6 +38,9 @@ public class QuartzServiceImpl implements QuartzService {
37
     public void startScheduler() {
38
     public void startScheduler() {
38
         try {
39
         try {
39
             scheduler.start();
40
             scheduler.start();
41
+            //
42
+            WeeklyCalendar weeklyCalendar = new WeeklyCalendar();
43
+            scheduler.addCalendar("weekly", weeklyCalendar, false, false);
40
         } catch (SchedulerException e) {
44
         } catch (SchedulerException e) {
41
             e.printStackTrace();
45
             e.printStackTrace();
42
         }
46
         }

+ 13 - 8
src/main/java/com/unissoft/service/impl/SysEarlyWarningServiceImpl.java

@@ -343,10 +343,15 @@ public class SysEarlyWarningServiceImpl extends ServiceImpl<SysEarlyWarningMappe
343
 
343
 
344
         CalendarIntervalScheduleBuilder calendarIntervalScheduleBuilder = getCalendarIntervalScheduleBuilder(timePeriodParam[1], Integer.parseInt(timePeriodParam[0]));
344
         CalendarIntervalScheduleBuilder calendarIntervalScheduleBuilder = getCalendarIntervalScheduleBuilder(timePeriodParam[1], Integer.parseInt(timePeriodParam[0]));
345
         //
345
         //
346
-        CalendarIntervalTrigger toBeDoneCalendarTrigger = newTrigger().withIdentity(triggerName, group)
346
+        TriggerBuilder<CalendarIntervalTrigger> calendarIntervalTriggerBuilder = newTrigger().withIdentity(triggerName, group)
347
                 .startAt(startAt)//设置开始调度时间
347
                 .startAt(startAt)//设置开始调度时间
348
-                .withSchedule(calendarIntervalScheduleBuilder)//设置调度频率
349
-                .build();
348
+                .withSchedule(calendarIntervalScheduleBuilder);//设置调度频率
349
+
350
+        if(timePeriodParam[1].equals(GrainConstant.STR_WEEKDAY)) {
351
+            calendarIntervalTriggerBuilder.modifiedByCalendar("weekly");//weekly在Scheduler初始化时,已注册
352
+        }
353
+
354
+        CalendarIntervalTrigger toBeDoneCalendarTrigger = calendarIntervalTriggerBuilder.build();
350
 
355
 
351
         return toBeDoneCalendarTrigger;
356
         return toBeDoneCalendarTrigger;
352
     }
357
     }
@@ -377,9 +382,9 @@ public class SysEarlyWarningServiceImpl extends ServiceImpl<SysEarlyWarningMappe
377
         String periodType = value[1];
382
         String periodType = value[1];
378
 
383
 
379
         if(! periodType.equals(GrainConstant.STR_SECOND) && ! periodType.equals(GrainConstant.STR_MINUTE) && ! periodType.equals(GrainConstant.STR_HOUR) &&
384
         if(! periodType.equals(GrainConstant.STR_SECOND) && ! periodType.equals(GrainConstant.STR_MINUTE) && ! periodType.equals(GrainConstant.STR_HOUR) &&
380
-                ! periodType.equals(GrainConstant.STR_DAY) && ! periodType.equals(GrainConstant.STR_WEEK) && ! periodType.equals(GrainConstant.STR_MONTH) &&
381
-                ! periodType.equals(GrainConstant.STR_SEASON) && ! periodType.equals(GrainConstant.STR_YEAR) ) {
382
-            throw new IllegalArgumentException(paramDesc + "值'_'后的值必须为second、minute、hour、day、week、month、season、year中的一种");
385
+                ! periodType.equals(GrainConstant.STR_DAY) && ! periodType.equals(GrainConstant.STR_WEEKDAY) && ! periodType.equals(GrainConstant.STR_WEEK) &&
386
+                ! periodType.equals(GrainConstant.STR_MONTH) && ! periodType.equals(GrainConstant.STR_SEASON) && ! periodType.equals(GrainConstant.STR_YEAR) ) {
387
+            throw new IllegalArgumentException(paramDesc + "值'_'后的值必须为second、minute、hour、day、weekday、week、month、season、year中的一种");
383
         }
388
         }
384
 
389
 
385
     }
390
     }
@@ -400,7 +405,7 @@ public class SysEarlyWarningServiceImpl extends ServiceImpl<SysEarlyWarningMappe
400
             startAt = DateUtil.getCurrMinute();
405
             startAt = DateUtil.getCurrMinute();
401
         } else if(periodType.equals(GrainConstant.STR_HOUR)) {
406
         } else if(periodType.equals(GrainConstant.STR_HOUR)) {
402
             startAt = DateUtil.getCurrHour();
407
             startAt = DateUtil.getCurrHour();
403
-        } else if(periodType.equals(GrainConstant.STR_DAY)) {
408
+        } else if(periodType.equals(GrainConstant.STR_DAY) || periodType.equals(GrainConstant.STR_WEEKDAY)) {
404
             startAt = DateUtil.getCurrDate();
409
             startAt = DateUtil.getCurrDate();
405
         } else if(periodType.equals(GrainConstant.STR_WEEK)) {
410
         } else if(periodType.equals(GrainConstant.STR_WEEK)) {
406
             startAt = DateUtil.getFirstDateOfCurrWeek();
411
             startAt = DateUtil.getFirstDateOfCurrWeek();
@@ -486,7 +491,7 @@ public class SysEarlyWarningServiceImpl extends ServiceImpl<SysEarlyWarningMappe
486
             return calendarIntervalSchedule().withIntervalInMonths(periodNum);
491
             return calendarIntervalSchedule().withIntervalInMonths(periodNum);
487
         } else if(periodType.equals(GrainConstant.STR_WEEK)) {
492
         } else if(periodType.equals(GrainConstant.STR_WEEK)) {
488
             return calendarIntervalSchedule().withIntervalInWeeks(periodNum);
493
             return calendarIntervalSchedule().withIntervalInWeeks(periodNum);
489
-        } else if(periodType.equals(GrainConstant.STR_DAY)) {
494
+        } else if(periodType.equals(GrainConstant.STR_DAY) || periodType.equals(GrainConstant.STR_WEEKDAY)) {
490
             return calendarIntervalSchedule().withIntervalInDays(periodNum);
495
             return calendarIntervalSchedule().withIntervalInDays(periodNum);
491
         } else if(periodType.equals(GrainConstant.STR_HOUR)) {
496
         } else if(periodType.equals(GrainConstant.STR_HOUR)) {
492
             return calendarIntervalSchedule().withIntervalInHours(periodNum);
497
             return calendarIntervalSchedule().withIntervalInHours(periodNum);