diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java index 9a714520..0ad7929f 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java @@ -519,6 +519,7 @@ public class SpringBootCallable implements Callable { File excelconverter = Tool.createPath(excel.getAbsolutePath(), "converter"); File exception = Tool.createPath(excel.getAbsolutePath(), "exception"); File excelstyle = Tool.createPath(excel.getAbsolutePath(), "style"); + File schedule = Tool.createPath(root.getAbsolutePath(), "schedule"); File utils = Tool.createPath(root.getAbsolutePath(), "utils"); File validation = Tool.createPath(root.getAbsolutePath(), "validation"); @@ -549,6 +550,10 @@ public class SpringBootCallable implements Callable { freeMarkerManager.outputTemp(Tool.createFile(excelstyle.getAbsolutePath(), name), option + "/java/frame/excel/style/" + name, ctx); } + //schedule + for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/schedule/")) { + freeMarkerManager.outputTemp(Tool.createFile(schedule.getAbsolutePath(), name), option + "/java/frame/schedule/" + name, ctx); + } //utils for (String name : ResourceUtil.getResourceFiles("/modules/SpringBoot/java/frame/utils/")) { freeMarkerManager.outputTemp(Tool.createFile(utils.getAbsolutePath(), name), option + "/java/frame/utils/" + name, ctx); diff --git a/src/main/resources/modules/SpringBoot/java/frame/schedule/RunCronTask.java b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunCronTask.java new file mode 100644 index 00000000..9c324a09 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunCronTask.java @@ -0,0 +1,14 @@ +package ${basePackage}.frame.schedule; + +import org.springframework.scheduling.config.CronTask; +import org.springframework.scheduling.config.Task; + +public abstract class RunCronTask extends RunTask { + + abstract String cron(); + + @Override + public Task build() { + return new CronTask(this, cron()); + } +} diff --git a/src/main/resources/modules/SpringBoot/java/frame/schedule/RunRepeatTask.java b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunRepeatTask.java new file mode 100644 index 00000000..d898ee83 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunRepeatTask.java @@ -0,0 +1,28 @@ +package ${basePackage}.frame.schedule; + +import org.springframework.scheduling.config.FixedDelayTask; +import org.springframework.scheduling.config.FixedRateTask; +import org.springframework.scheduling.config.Task; + +public abstract class RunRepeatTask extends RunTask { + + public abstract void config(Config config); + + public class Config { + int interval = 10 * 60 * 1000; + int initialDelay = 0; + boolean fix = false; + } + + @Override + public Task build() { + Config config = new Config(); + config(config); + + if (config.fix) { + return new FixedRateTask(this, config.interval, config.initialDelay); + } else { + return new FixedDelayTask(this, config.interval, config.initialDelay); + } + } +} diff --git a/src/main/resources/modules/SpringBoot/java/frame/schedule/RunSqlTask.java b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunSqlTask.java new file mode 100644 index 00000000..e6ccea67 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunSqlTask.java @@ -0,0 +1,16 @@ +package ${basePackage}.frame.schedule; + +public abstract class RunSqlTask extends RunRepeatTask { + + public abstract String getSql(); + + @Override + public void config(Config config) { + + } + + @Override + public void run() { + //exec sql + } +} diff --git a/src/main/resources/modules/SpringBoot/java/frame/schedule/RunTask.java b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunTask.java new file mode 100644 index 00000000..036e88f6 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/frame/schedule/RunTask.java @@ -0,0 +1,22 @@ +package ${basePackage}.frame.schedule; + + +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.scheduling.config.Task; + +import java.util.Date; +import java.util.concurrent.ScheduledFuture; + +public abstract class RunTask implements Runnable { + + public abstract String taskId(); + + public abstract Task build(); + + public void configChange(ThreadPoolTaskScheduler scheduler) { + ScheduledFuture schedule = scheduler.schedule(this, new Date()); + if (!schedule.cancel(true)) { + + } + } +}