From ccf75464534965c47866449b2b4e457a6dadede9 Mon Sep 17 00:00:00 2001
From: liriming <1343021927@qq.com>
Date: 星期一, 14 十月 2024 14:13:00 +0800
Subject: [PATCH] 定时任务权限修改

---
 shasteel-biz/src/main/java/com/iailab/module/shasteel/job/init/JobCommandLineRunner.java |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/init/JobCommandLineRunner.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/init/JobCommandLineRunner.java
new file mode 100644
index 0000000..e9f61e8
--- /dev/null
+++ b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/init/JobCommandLineRunner.java
@@ -0,0 +1,38 @@
+package com.iailab.module.shasteel.job.init;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.iailab.module.shasteel.job.dao.ScheduleJobDao;
+import com.iailab.module.shasteel.job.entity.ScheduleJobEntity;
+import com.iailab.module.shasteel.job.utils.ScheduleUtils;
+import org.quartz.CronTrigger;
+import org.quartz.Scheduler;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * 初始化定时任务数据
+ */
+@Component
+public class JobCommandLineRunner implements CommandLineRunner {
+    @Resource
+    private Scheduler scheduler;
+    @Resource
+    private ScheduleJobDao scheduleJobDao;
+
+    @Override
+    public void run(String... args) {
+        List<ScheduleJobEntity> scheduleJobList = scheduleJobDao.selectList(new QueryWrapper<>());
+        for(ScheduleJobEntity scheduleJob : scheduleJobList){
+            CronTrigger cronTrigger = ScheduleUtils.getCronTrigger(scheduler, scheduleJob.getId());
+            //如果不存在,则创建
+            if(cronTrigger == null) {
+                ScheduleUtils.createScheduleJob(scheduler, scheduleJob);
+            }else {
+                ScheduleUtils.updateScheduleJob(scheduler, scheduleJob);
+            }
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3