Pārlūkot izejas kodu

修改预警规则

shengyang000 3 gadi atpakaļ
vecāks
revīzija
5ca418e3d1

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

@@ -125,7 +125,7 @@ public class ToBeDoneJob implements Job, Serializable {
125 125
             startDate = DateUtil.getCurrMinute();
126 126
         } else if(timeType.equals(GrainConstant.STR_HOUR)) {
127 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 129
             startDate = DateUtil.getCurrDate();
130 130
         } else if(timeType.equals(GrainConstant.STR_WEEK)) {
131 131
             startDate = DateUtil.getCurrDate();
@@ -152,7 +152,7 @@ public class ToBeDoneJob implements Job, Serializable {
152 152
             date = DateUtils.addMinutes(baseDate, timeNum);
153 153
         } else if(timeType.equals(GrainConstant.STR_HOUR)) {
154 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 156
             date = DateUtils.addDays(baseDate, timeNum);
157 157
         } else if(timeType.equals(GrainConstant.STR_WEEK)) {
158 158
             date = DateUtils.addWeeks(baseDate, timeNum);
@@ -172,8 +172,8 @@ public class ToBeDoneJob implements Job, Serializable {
172 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 177
             //如果检查周期是 天、星期、月、季、年为单位,则计算为当天的工作时间8点整
178 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 13
 import org.apache.commons.lang.StringUtils;
14 14
 import org.json.JSONObject;
15 15
 import org.quartz.*;
16
+import org.quartz.impl.calendar.WeeklyCalendar;
16 17
 import org.springframework.beans.factory.annotation.Autowired;
17 18
 import org.springframework.stereotype.Service;
18 19
 
@@ -37,6 +38,9 @@ public class QuartzServiceImpl implements QuartzService {
37 38
     public void startScheduler() {
38 39
         try {
39 40
             scheduler.start();
41
+            //
42
+            WeeklyCalendar weeklyCalendar = new WeeklyCalendar();
43
+            scheduler.addCalendar("weekly", weeklyCalendar, false, false);
40 44
         } catch (SchedulerException e) {
41 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 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 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 356
         return toBeDoneCalendarTrigger;
352 357
     }
@@ -377,9 +382,9 @@ public class SysEarlyWarningServiceImpl extends ServiceImpl<SysEarlyWarningMappe
377 382
         String periodType = value[1];
378 383
 
379 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 405
             startAt = DateUtil.getCurrMinute();
401 406
         } else if(periodType.equals(GrainConstant.STR_HOUR)) {
402 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 409
             startAt = DateUtil.getCurrDate();
405 410
         } else if(periodType.equals(GrainConstant.STR_WEEK)) {
406 411
             startAt = DateUtil.getFirstDateOfCurrWeek();
@@ -486,7 +491,7 @@ public class SysEarlyWarningServiceImpl extends ServiceImpl<SysEarlyWarningMappe
486 491
             return calendarIntervalSchedule().withIntervalInMonths(periodNum);
487 492
         } else if(periodType.equals(GrainConstant.STR_WEEK)) {
488 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 495
             return calendarIntervalSchedule().withIntervalInDays(periodNum);
491 496
         } else if(periodType.equals(GrainConstant.STR_HOUR)) {
492 497
             return calendarIntervalSchedule().withIntervalInHours(periodNum);