Browse Source

定时任务初始化恢复

guarantee-lsq 2 years ago
parent
commit
4d7bab25f3

+ 12 - 0
platform-rest/src/main/java/com/platform/rest/config/init/ServletInit.java

@@ -4,6 +4,7 @@ package com.platform.rest.config.init;
 import com.platform.common.constant.UpmsRedisKeyConstants;
 import com.platform.common.util.BeanUtils;
 import com.platform.common.util.RedisUtils;
+import com.platform.service.upms.ScheduleJobService;
 import com.platform.service.upms.SysOauthClientDetailsService;
 import lombok.AllArgsConstructor;
 import org.springframework.context.annotation.DependsOn;
@@ -26,6 +27,8 @@ public class ServletInit {
 
     private final SysOauthClientDetailsService sysOauthClientDetailsService;
 
+    private final ScheduleJobService scheduleJobService;
+
     /**
      * 初始化客户端缓存
      */
@@ -41,4 +44,13 @@ public class ServletInit {
         sysOauthClientDetailsService.initCache();
     }
 
+
+    /**
+     * 初始化job
+     */
+    @PostConstruct
+    public void initJob() {
+        scheduleJobService.init();
+    }
+
 }

+ 5 - 0
platform-service/src/main/java/com/platform/service/upms/ScheduleJobService.java

@@ -45,4 +45,9 @@ public interface ScheduleJobService extends IBaseService<ScheduleJob, ScheduleJo
      * @param jobIds
      */
     void resume(Long[] jobIds);
+
+    /**
+     * 项目启动时,初始化定时器
+     */
+    void init();
 }

+ 2 - 2
platform-service/src/main/java/com/platform/service/upms/impl/ScheduleJobServiceImpl.java

@@ -38,7 +38,7 @@ public class ScheduleJobServiceImpl extends BaseServiceImpl<ScheduleJobMapper, S
      */
     @PostConstruct
     public void init() {
-        /*List<ScheduleJob> scheduleJobList = mapper.selectAll();
+        List<ScheduleJob> scheduleJobList = mapper.selectAll();
         for (ScheduleJob scheduleJob : scheduleJobList) {
             CronTrigger cronTrigger = ScheduleUtils.getCronTrigger(scheduler, scheduleJob.getJobId());
             //如果不存在,则创建
@@ -47,7 +47,7 @@ public class ScheduleJobServiceImpl extends BaseServiceImpl<ScheduleJobMapper, S
             } else {
                 ScheduleUtils.updateScheduleJob(scheduler, scheduleJob);
             }
-        }*/
+        }
     }
 
     @Override