From df483646c9416d7718a8d009201f7b12158725c3 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Tue, 09 Jun 2020 20:01:23 +0800 Subject: [PATCH] modify --- /dev/null | 16 ---------------- src/main/resources/templates/febs/views/index.html | 6 +++--- src/main/resources/application-dev.yml | 6 ------ src/main/resources/application-prod.yml | 6 ------ src/main/resources/application-test.yml | 6 ------ pom.xml | 6 ------ src/main/resources/templates/febs/views/layout.html | 4 +--- 7 files changed, 4 insertions(+), 46 deletions(-) diff --git a/pom.xml b/pom.xml index fc9df74..46f2f0f 100644 --- a/pom.xml +++ b/pom.xml @@ -65,12 +65,6 @@ <artifactId>commons-pool2</artifactId> </dependency> - <!-- 任务调度 --> - <dependency> - <groupId>org.quartz-scheduler</groupId> - <artifactId>quartz</artifactId> - </dependency> - <!-- MyBatis增强插件 --> <dependency> <groupId>com.baomidou</groupId> diff --git a/src/main/java/com/xcong/excoin/common/annotation/IsCron.java b/src/main/java/com/xcong/excoin/common/annotation/IsCron.java deleted file mode 100644 index 21cdb30..0000000 --- a/src/main/java/com/xcong/excoin/common/annotation/IsCron.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.xcong.excoin.common.annotation; - -import com.xcong.excoin.common.validator.CronValidator; - -import javax.validation.Constraint; -import javax.validation.Payload; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @author MrBird - */ -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@Constraint(validatedBy = CronValidator.class) -public @interface IsCron { - - String message(); - - Class<?>[] groups() default {}; - - Class<? extends Payload>[] payload() default {}; -} \ No newline at end of file diff --git a/src/main/java/com/xcong/excoin/common/validator/CronValidator.java b/src/main/java/com/xcong/excoin/common/validator/CronValidator.java deleted file mode 100644 index 9a51c40..0000000 --- a/src/main/java/com/xcong/excoin/common/validator/CronValidator.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.xcong.excoin.common.validator; - -import com.xcong.excoin.common.annotation.IsCron; -import org.quartz.CronExpression; - -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; - -/** - * 校验是否为合法的 Cron表达式 - * - * @author MrBird - */ -public class CronValidator implements ConstraintValidator<IsCron, String> { - - @Override - public void initialize(IsCron isCron) { - } - - @Override - public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { - try { - return CronExpression.isValidExpression(value); - } catch (Exception e) { - return false; - } - } -} \ No newline at end of file diff --git a/src/main/java/com/xcong/excoin/job/configure/ScheduleConfigure.java b/src/main/java/com/xcong/excoin/job/configure/ScheduleConfigure.java deleted file mode 100644 index 3fa8a05..0000000 --- a/src/main/java/com/xcong/excoin/job/configure/ScheduleConfigure.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.xcong.excoin.job.configure; - -import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; -import lombok.RequiredArgsConstructor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.scheduling.quartz.SchedulerFactoryBean; - -import javax.sql.DataSource; -import java.util.Properties; -import java.util.concurrent.ThreadPoolExecutor; - -/** - * 定时任务配置 - * - * @author MrBird - */ -@Configuration -@RequiredArgsConstructor -public class ScheduleConfigure { - - private final DynamicRoutingDataSource dynamicRoutingDataSource; - - @Bean - public ThreadPoolTaskExecutor scheduleJobExecutorService(){ - ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); - executor.setCorePoolSize(5); - executor.setMaxPoolSize(10); - executor.setQueueCapacity(20); - executor.setKeepAliveSeconds(30); - executor.setThreadNamePrefix("Febs-Job-Thread"); - executor.setWaitForTasksToCompleteOnShutdown(true); - executor.setAwaitTerminationSeconds(60); - executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); - executor.initialize(); - return executor; - } - - @Bean - public SchedulerFactoryBean schedulerFactoryBean() { - SchedulerFactoryBean factory = new SchedulerFactoryBean(); - // 手动从多数据源中获取 quartz数据源 - DataSource quartz = dynamicRoutingDataSource.getDataSource("quartz"); - factory.setDataSource(quartz); - - // quartz参数 - Properties prop = new Properties(); - prop.put("org.quartz.scheduler.instanceName", "MyScheduler"); - prop.put("org.quartz.scheduler.instanceId", "AUTO"); - // 线程池配置 - prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); - prop.put("org.quartz.threadPool.threadCount", "20"); - prop.put("org.quartz.threadPool.threadPriority", "5"); - // JobStore配置 - prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX"); - // 集群配置 - prop.put("org.quartz.jobStore.isClustered", "true"); - prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); - prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1"); - - prop.put("org.quartz.jobStore.misfireThreshold", "12000"); - prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); - factory.setQuartzProperties(prop); - - factory.setSchedulerName("FEBS_Scheduler"); - // 延时启动 - factory.setStartupDelay(1); - factory.setApplicationContextSchedulerContextKey("applicationContextKey"); - // 启动时更新己存在的 Job - factory.setOverwriteExistingJobs(true); - // 设置自动启动,默认为 true - factory.setAutoStartup(true); - - return factory; - } -} diff --git a/src/main/java/com/xcong/excoin/job/controller/JobController.java b/src/main/java/com/xcong/excoin/job/controller/JobController.java deleted file mode 100644 index d6d8e65..0000000 --- a/src/main/java/com/xcong/excoin/job/controller/JobController.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.xcong.excoin.job.controller; - -import com.xcong.excoin.common.annotation.ControllerEndpoint; -import com.xcong.excoin.common.controller.BaseController; -import com.xcong.excoin.common.entity.FebsResponse; -import com.xcong.excoin.common.entity.QueryRequest; -import com.xcong.excoin.job.entity.Job; -import com.xcong.excoin.job.service.IJobService; -import com.baomidou.mybatisplus.core.toolkit.StringPool; -import com.wuwenze.poi.ExcelKit; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.quartz.CronExpression; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletResponse; -import javax.validation.Valid; -import javax.validation.constraints.NotBlank; -import java.util.List; -import java.util.Map; - -/** - * @author MrBird - */ -@Slf4j -@Validated -@RestController -@RequestMapping("job") -@RequiredArgsConstructor -public class JobController extends BaseController { - - private final IJobService jobService; - - @GetMapping - @RequiresPermissions("job:view") - public FebsResponse jobList(QueryRequest request, Job job) { - Map<String, Object> dataTable = getDataTable(this.jobService.findJobs(request, job)); - return new FebsResponse().success().data(dataTable); - } - - @GetMapping("cron/check") - public boolean checkCron(String cron) { - try { - return CronExpression.isValidExpression(cron); - } catch (Exception e) { - return false; - } - } - - @PostMapping - @RequiresPermissions("job:add") - @ControllerEndpoint(operation = "新增定时任务", exceptionMessage = "新增定时任务失败") - public FebsResponse addJob(@Valid Job job) { - this.jobService.createJob(job); - return new FebsResponse().success(); - } - - @GetMapping("delete/{jobIds}") - @RequiresPermissions("job:delete") - @ControllerEndpoint(operation = "删除定时任务", exceptionMessage = "删除定时任务失败") - public FebsResponse deleteJob(@NotBlank(message = "{required}") @PathVariable String jobIds) { - String[] ids = jobIds.split(StringPool.COMMA); - this.jobService.deleteJobs(ids); - return new FebsResponse().success(); - } - - @PostMapping("update") - @ControllerEndpoint(operation = "修改定时任务", exceptionMessage = "修改定时任务失败") - public FebsResponse updateJob(@Valid Job job) { - this.jobService.updateJob(job); - return new FebsResponse().success(); - } - - @GetMapping("run/{jobIds}") - @RequiresPermissions("job:run") - @ControllerEndpoint(operation = "执行定时任务", exceptionMessage = "执行定时任务失败") - public FebsResponse runJob(@NotBlank(message = "{required}") @PathVariable String jobIds) { - this.jobService.run(jobIds); - return new FebsResponse().success(); - } - - @GetMapping("pause/{jobIds}") - @RequiresPermissions("job:pause") - @ControllerEndpoint(operation = "暂停定时任务", exceptionMessage = "暂停定时任务失败") - public FebsResponse pauseJob(@NotBlank(message = "{required}") @PathVariable String jobIds) { - this.jobService.pause(jobIds); - return new FebsResponse().success(); - } - - @GetMapping("resume/{jobIds}") - @RequiresPermissions("job:resume") - @ControllerEndpoint(operation = "恢复定时任务", exceptionMessage = "恢复定时任务失败") - public FebsResponse resumeJob(@NotBlank(message = "{required}") @PathVariable String jobIds) { - this.jobService.resume(jobIds); - return new FebsResponse().success(); - } - - @GetMapping("excel") - @RequiresPermissions("job:export") - @ControllerEndpoint(exceptionMessage = "导出Excel失败") - public void export(QueryRequest request, Job job, HttpServletResponse response) { - List<Job> jobs = this.jobService.findJobs(request, job).getRecords(); - ExcelKit.$Export(Job.class, response).downXlsx(jobs, false); - } -} diff --git a/src/main/java/com/xcong/excoin/job/controller/JobLogController.java b/src/main/java/com/xcong/excoin/job/controller/JobLogController.java deleted file mode 100644 index 8ea2be0..0000000 --- a/src/main/java/com/xcong/excoin/job/controller/JobLogController.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.xcong.excoin.job.controller; - -import com.xcong.excoin.common.annotation.ControllerEndpoint; -import com.xcong.excoin.common.controller.BaseController; -import com.xcong.excoin.common.entity.FebsResponse; -import com.xcong.excoin.common.entity.QueryRequest; -import com.xcong.excoin.job.entity.JobLog; -import com.xcong.excoin.job.service.IJobLogService; -import com.baomidou.mybatisplus.core.toolkit.StringPool; -import com.wuwenze.poi.ExcelKit; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.HttpServletResponse; -import javax.validation.constraints.NotBlank; -import java.util.List; -import java.util.Map; - -/** - * @author MrBird - */ -@Slf4j -@Validated -@RestController -@RequestMapping("jobLog") -@RequiredArgsConstructor -public class JobLogController extends BaseController { - - private final IJobLogService jobLogService; - - @GetMapping - @RequiresPermissions("job:log:view") - public FebsResponse jobLogList(QueryRequest request, JobLog log) { - Map<String, Object> dataTable = getDataTable(this.jobLogService.findJobLogs(request, log)); - return new FebsResponse().success().data(dataTable); - } - - @GetMapping("delete/{jobIds}") - @RequiresPermissions("job:log:delete") - @ControllerEndpoint(exceptionMessage = "删除调度日志失败") - public FebsResponse deleteJobLog(@NotBlank(message = "{required}") @PathVariable String jobIds) { - String[] ids = jobIds.split(StringPool.COMMA); - this.jobLogService.deleteJobLogs(ids); - return new FebsResponse().success(); - } - - @GetMapping("excel") - @RequiresPermissions("job:log:export") - @ControllerEndpoint(exceptionMessage = "导出Excel失败") - public void export(QueryRequest request, JobLog jobLog, HttpServletResponse response) { - List<JobLog> jobLogs = this.jobLogService.findJobLogs(request, jobLog).getRecords(); - ExcelKit.$Export(JobLog.class, response).downXlsx(jobLogs, false); - } -} diff --git a/src/main/java/com/xcong/excoin/job/controller/ViewController.java b/src/main/java/com/xcong/excoin/job/controller/ViewController.java deleted file mode 100644 index f7dff2c..0000000 --- a/src/main/java/com/xcong/excoin/job/controller/ViewController.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.xcong.excoin.job.controller; - -import com.xcong.excoin.common.entity.FebsConstant; -import com.xcong.excoin.common.utils.FebsUtil; -import com.xcong.excoin.job.entity.Job; -import com.xcong.excoin.job.service.IJobService; -import lombok.RequiredArgsConstructor; -import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; - -import javax.validation.constraints.NotBlank; - -/** - * @author MrBird - */ -@Controller("jobView") -@RequestMapping(FebsConstant.VIEW_PREFIX + "job") -@RequiredArgsConstructor -public class ViewController { - - private final IJobService jobService; - - @GetMapping("job") - @RequiresPermissions("job:view") - public String online() { - return FebsUtil.view("job/job"); - } - - @GetMapping("job/add") - @RequiresPermissions("job:add") - public String jobAdd() { - return FebsUtil.view("job/jobAdd"); - } - - @GetMapping("job/update/{jobId}") - @RequiresPermissions("job:update") - public String jobUpdate(@NotBlank(message = "{required}") @PathVariable Long jobId, Model model) { - Job job = jobService.findJob(jobId); - model.addAttribute("job", job); - return FebsUtil.view("job/jobUpdate"); - } - - @GetMapping("log") - @RequiresPermissions("job:log:view") - public String log() { - return FebsUtil.view("job/jobLog"); - } - -} diff --git a/src/main/java/com/xcong/excoin/job/entity/Job.java b/src/main/java/com/xcong/excoin/job/entity/Job.java deleted file mode 100644 index b9cba39..0000000 --- a/src/main/java/com/xcong/excoin/job/entity/Job.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.xcong.excoin.job.entity; - -import com.xcong.excoin.common.annotation.IsCron; -import com.xcong.excoin.common.converter.TimeConverter; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.wuwenze.poi.annotation.Excel; -import com.wuwenze.poi.annotation.ExcelField; -import lombok.Data; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; -import java.io.Serializable; -import java.util.Date; - -/** - * @author MrBird - */ -@Data -@TableName("t_job") -@Excel("定时任务信息表") -public class Job implements Serializable { - - private static final long serialVersionUID = 400066840871805700L; - - /** - * 任务调度参数 key - */ - public static final String JOB_PARAM_KEY = "JOB_PARAM_KEY"; - - public enum ScheduleStatus { - /** - * 正常 - */ - NORMAL("0"), - /** - * 暂停 - */ - PAUSE("1"); - - private String value; - - ScheduleStatus(String value) { - this.value = value; - } - - public String getValue() { - return value; - } - } - - @TableId(value = "JOB_ID", type = IdType.AUTO) - private Long jobId; - - @TableField("bean_name") - @NotBlank(message = "{required}") - @Size(max = 50, message = "{noMoreThan}") - @ExcelField(value = "Bean名称") - private String beanName; - - @TableField("method_name") - @NotBlank(message = "{required}") - @Size(max = 50, message = "{noMoreThan}") - @ExcelField(value = "方法名称") - private String methodName; - - @TableField("params") - @Size(max = 50, message = "{noMoreThan}") - @ExcelField(value = "方法参数") - private String params; - - @TableField("cron_expression") - @NotBlank(message = "{required}") - @IsCron(message = "{invalid}") - @ExcelField(value = "Cron表达式") - private String cronExpression; - - @TableField("status") - @ExcelField(value = "状态", writeConverterExp = "0=正常,1=暂停") - private String status; - - @TableField("remark") - @Size(max = 100, message = "{noMoreThan}") - @ExcelField(value = "备注") - private String remark; - - @TableField("create_time") - @ExcelField(value = "创建时间", writeConverter = TimeConverter.class) - private Date createTime; - - private transient String createTimeFrom; - private transient String createTimeTo; - -} diff --git a/src/main/java/com/xcong/excoin/job/entity/JobLog.java b/src/main/java/com/xcong/excoin/job/entity/JobLog.java deleted file mode 100644 index 75cca0f..0000000 --- a/src/main/java/com/xcong/excoin/job/entity/JobLog.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.xcong.excoin.job.entity; - - -import com.xcong.excoin.common.converter.TimeConverter; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.wuwenze.poi.annotation.Excel; -import com.wuwenze.poi.annotation.ExcelField; -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -/** - * @author MrBird - */ -@Data -@TableName("t_job_log") -@Excel("调度日志信息表") -public class JobLog implements Serializable { - - private static final long serialVersionUID = -7114915445674333148L; - /** - * 任务执行成功 - */ - public static final String JOB_SUCCESS = "0"; - /** - * 任务执行失败 - */ - public static final String JOB_FAIL = "1"; - - @TableId(value = "LOG_ID", type = IdType.AUTO) - private Long logId; - - @TableField("job_id") - private Long jobId; - - @TableField("bean_name") - @ExcelField(value = "Bean名称") - private String beanName; - - @TableField("method_name") - @ExcelField(value = "方法名称") - private String methodName; - - @TableField("params") - @ExcelField(value = "方法参数") - private String params; - - @TableField("status") - @ExcelField(value = "状态", writeConverterExp = "0=成功,1=失败") - private String status; - - @TableField("error") - @ExcelField(value = "异常信息") - private String error; - - @TableField("times") - @ExcelField(value = "耗时(毫秒)") - private Long times; - - @TableField("create_time") - @ExcelField(value = "执行时间", writeConverter = TimeConverter.class) - private Date createTime; - - private transient String createTimeFrom; - private transient String createTimeTo; - -} diff --git a/src/main/java/com/xcong/excoin/job/mapper/JobLogMapper.java b/src/main/java/com/xcong/excoin/job/mapper/JobLogMapper.java deleted file mode 100644 index e62a226..0000000 --- a/src/main/java/com/xcong/excoin/job/mapper/JobLogMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.xcong.excoin.job.mapper; - - -import com.xcong.excoin.job.entity.JobLog; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** - * @author MrBird - */ -public interface JobLogMapper extends BaseMapper<JobLog> { -} \ No newline at end of file diff --git a/src/main/java/com/xcong/excoin/job/mapper/JobMapper.java b/src/main/java/com/xcong/excoin/job/mapper/JobMapper.java deleted file mode 100644 index f782e8a..0000000 --- a/src/main/java/com/xcong/excoin/job/mapper/JobMapper.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.xcong.excoin.job.mapper; - - -import com.xcong.excoin.job.entity.Job; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -import java.util.List; - -/** - * @author MrBird - */ -public interface JobMapper extends BaseMapper<Job> { - - /** - * 获取定时任务列表 - * - * @return 定时任务列表 - */ - List<Job> queryList(); -} \ No newline at end of file diff --git a/src/main/java/com/xcong/excoin/job/service/IJobLogService.java b/src/main/java/com/xcong/excoin/job/service/IJobLogService.java deleted file mode 100644 index aa2de65..0000000 --- a/src/main/java/com/xcong/excoin/job/service/IJobLogService.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.xcong.excoin.job.service; - -import com.xcong.excoin.common.entity.FebsConstant; -import com.xcong.excoin.common.entity.QueryRequest; -import com.xcong.excoin.job.entity.JobLog; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.IService; -import org.springframework.scheduling.annotation.Async; - -/** - * @author MrBird - */ -public interface IJobLogService extends IService<JobLog> { - - /** - * 获取定时任务日志分页数据 - * - * @param request request - * @param jobLog jobLog - * @return 定时任务日志分页数据 - */ - IPage<JobLog> findJobLogs(QueryRequest request, JobLog jobLog); - - /** - * 保存定时任务日志 - * - * @param log 定时任务日志 - */ - @Async(FebsConstant.ASYNC_POOL) - void saveJobLog(JobLog log); - - /** - * 删除定时任务日志 - * - * @param jobLogIds 定时任务日志id数组 - */ - void deleteJobLogs(String[] jobLogIds); -} diff --git a/src/main/java/com/xcong/excoin/job/service/IJobService.java b/src/main/java/com/xcong/excoin/job/service/IJobService.java deleted file mode 100644 index 3639aa2..0000000 --- a/src/main/java/com/xcong/excoin/job/service/IJobService.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.xcong.excoin.job.service; - -import com.xcong.excoin.common.entity.QueryRequest; -import com.xcong.excoin.job.entity.Job; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.IService; - -/** - * @author MrBird - */ -public interface IJobService extends IService<Job> { - - /** - * 获取定时任务 - * - * @param jobId 任务id - * @return 定时任务 - */ - Job findJob(Long jobId); - - /** - * 获取定时任务分页数据 - * - * @param request request - * @param job job - * @return 定时任务分页数据 - */ - IPage<Job> findJobs(QueryRequest request, Job job); - - /** - * 创建定时任务 - * - * @param job job - */ - void createJob(Job job); - - /** - * 更新定时任务 - * - * @param job 定时任务 - */ - void updateJob(Job job); - - /** - * 删除定时任务 - * - * @param jobIds 定时任务id数组 - */ - void deleteJobs(String[] jobIds); - - /** - * 批量更新定时任务状态 - * - * @param jobIds 定时任务id - * @param status 待更新状态 - */ - void updateBatch(String jobIds, String status); - - /** - * 运行定时任务 - * - * @param jobIds 定时任务id - */ - void run(String jobIds); - - /** - * 暂停定时任务 - * - * @param jobIds 定时任务id - */ - void pause(String jobIds); - - /** - * 恢复定时任务 - * - * @param jobIds 定时任务id - */ - void resume(String jobIds); - -} diff --git a/src/main/java/com/xcong/excoin/job/service/impl/JobLogServiceImpl.java b/src/main/java/com/xcong/excoin/job/service/impl/JobLogServiceImpl.java deleted file mode 100644 index 6f956d6..0000000 --- a/src/main/java/com/xcong/excoin/job/service/impl/JobLogServiceImpl.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.xcong.excoin.job.service.impl; - -import com.xcong.excoin.common.entity.FebsConstant; -import com.xcong.excoin.common.entity.QueryRequest; -import com.xcong.excoin.common.utils.SortUtil; -import com.xcong.excoin.job.entity.JobLog; -import com.xcong.excoin.job.mapper.JobLogMapper; -import com.xcong.excoin.job.service.IJobLogService; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Service; - -import java.util.Arrays; -import java.util.List; - -/** - * @author MrBird - */ -@Slf4j -@Service("JobLogService") -public class JobLogServiceImpl extends ServiceImpl<JobLogMapper, JobLog> implements IJobLogService { - - @Override - public IPage<JobLog> findJobLogs(QueryRequest request, JobLog jobLog) { - LambdaQueryWrapper<JobLog> queryWrapper = new LambdaQueryWrapper<>(); - - if (StringUtils.isNotBlank(jobLog.getBeanName())) { - queryWrapper.eq(JobLog::getBeanName, jobLog.getBeanName()); - } - if (StringUtils.isNotBlank(jobLog.getMethodName())) { - queryWrapper.eq(JobLog::getMethodName, jobLog.getMethodName()); - } - if (StringUtils.isNotBlank(jobLog.getStatus())) { - queryWrapper.eq(JobLog::getStatus, jobLog.getStatus()); - } - Page<JobLog> page = new Page<>(request.getPageNum(), request.getPageSize()); - SortUtil.handlePageSort(request, page, "createTime", FebsConstant.ORDER_DESC, true); - return this.page(page, queryWrapper); - } - - @Override - public void saveJobLog(JobLog log) { - this.save(log); - } - - @Override - public void deleteJobLogs(String[] jobLogIds) { - List<String> list = Arrays.asList(jobLogIds); - this.baseMapper.deleteBatchIds(list); - } - -} diff --git a/src/main/java/com/xcong/excoin/job/service/impl/JobServiceImpl.java b/src/main/java/com/xcong/excoin/job/service/impl/JobServiceImpl.java deleted file mode 100644 index 3cc4745..0000000 --- a/src/main/java/com/xcong/excoin/job/service/impl/JobServiceImpl.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.xcong.excoin.job.service.impl; - -import com.xcong.excoin.common.entity.FebsConstant; -import com.xcong.excoin.common.entity.QueryRequest; -import com.xcong.excoin.common.utils.SortUtil; -import com.xcong.excoin.job.entity.Job; -import com.xcong.excoin.job.mapper.JobMapper; -import com.xcong.excoin.job.service.IJobService; -import com.xcong.excoin.job.util.ScheduleUtils; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.StringPool; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.quartz.CronTrigger; -import org.quartz.Scheduler; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.PostConstruct; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -/** - * @author MrBird - */ -@Slf4j -@Service("JobService") -@RequiredArgsConstructor -@Transactional(propagation = Propagation.SUPPORTS, readOnly = true) -public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements IJobService { - - private final Scheduler scheduler; - - - /** - * 项目启动时,初始化定时器 - */ - @PostConstruct - public void init() { - List<Job> scheduleJobList = this.baseMapper.queryList(); - // 如果不存在,则创建 - scheduleJobList.forEach(scheduleJob -> { - CronTrigger cronTrigger = ScheduleUtils.getCronTrigger(scheduler, scheduleJob.getJobId()); - if (cronTrigger == null) { - ScheduleUtils.createScheduleJob(scheduler, scheduleJob); - } else { - ScheduleUtils.updateScheduleJob(scheduler, scheduleJob); - } - }); - } - - @Override - public Job findJob(Long jobId) { - return this.getById(jobId); - } - - @Override - public IPage<Job> findJobs(QueryRequest request, Job job) { - LambdaQueryWrapper<Job> queryWrapper = new LambdaQueryWrapper<>(); - - if (StringUtils.isNotBlank(job.getBeanName())) { - queryWrapper.eq(Job::getBeanName, job.getBeanName()); - } - if (StringUtils.isNotBlank(job.getMethodName())) { - queryWrapper.eq(Job::getMethodName, job.getMethodName()); - } - if (StringUtils.isNotBlank(job.getParams())) { - queryWrapper.like(Job::getParams, job.getParams()); - } - if (StringUtils.isNotBlank(job.getRemark())) { - queryWrapper.like(Job::getRemark, job.getRemark()); - } - if (StringUtils.isNotBlank(job.getStatus())) { - queryWrapper.eq(Job::getStatus, job.getStatus()); - } - - if (StringUtils.isNotBlank(job.getCreateTimeFrom()) && StringUtils.isNotBlank(job.getCreateTimeTo())) { - queryWrapper - .ge(Job::getCreateTime, job.getCreateTimeFrom()) - .le(Job::getCreateTime, job.getCreateTimeTo()); - } - Page<Job> page = new Page<>(request.getPageNum(), request.getPageSize()); - SortUtil.handlePageSort(request, page, "createTime", FebsConstant.ORDER_DESC, true); - return this.page(page, queryWrapper); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void createJob(Job job) { - job.setCreateTime(new Date()); - job.setStatus(Job.ScheduleStatus.PAUSE.getValue()); - this.save(job); - ScheduleUtils.createScheduleJob(scheduler, job); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateJob(Job job) { - ScheduleUtils.updateScheduleJob(scheduler, job); - this.baseMapper.updateById(job); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteJobs(String[] jobIds) { - List<String> list = Arrays.asList(jobIds); - list.forEach(jobId -> ScheduleUtils.deleteScheduleJob(scheduler, Long.valueOf(jobId))); - this.baseMapper.deleteBatchIds(list); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateBatch(String jobIds, String status) { - List<String> list = Arrays.asList(jobIds.split(StringPool.COMMA)); - Job job = new Job(); - job.setStatus(status); - this.baseMapper.update(job, new LambdaQueryWrapper<Job>().in(Job::getJobId, list)); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void run(String jobIds) { - String[] list = jobIds.split(StringPool.COMMA); - Arrays.stream(list).forEach(jobId -> ScheduleUtils.run(scheduler, this.findJob(Long.valueOf(jobId)))); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void pause(String jobIds) { - String[] list = jobIds.split(StringPool.COMMA); - Arrays.stream(list).forEach(jobId -> ScheduleUtils.pauseJob(scheduler, Long.valueOf(jobId))); - this.updateBatch(jobIds, Job.ScheduleStatus.PAUSE.getValue()); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void resume(String jobIds) { - String[] list = jobIds.split(StringPool.COMMA); - Arrays.stream(list).forEach(jobId -> ScheduleUtils.resumeJob(scheduler, Long.valueOf(jobId))); - this.updateBatch(jobIds, Job.ScheduleStatus.NORMAL.getValue()); - } -} diff --git a/src/main/java/com/xcong/excoin/job/task/TestTask.java b/src/main/java/com/xcong/excoin/job/task/TestTask.java deleted file mode 100644 index b2ccd9b..0000000 --- a/src/main/java/com/xcong/excoin/job/task/TestTask.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.xcong.excoin.job.task; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -/** - * @author MrBird - */ -@Slf4j -@Component -public class TestTask { - - public void test(String params) { - log.info("我是带参数的test方法,正在被执行,参数为:{}" , params); - } - public void test1() { - log.info("我是不带参数的test1方法,正在被执行"); - } - -} diff --git a/src/main/java/com/xcong/excoin/job/util/ScheduleJob.java b/src/main/java/com/xcong/excoin/job/util/ScheduleJob.java deleted file mode 100644 index 14b682b..0000000 --- a/src/main/java/com/xcong/excoin/job/util/ScheduleJob.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.xcong.excoin.job.util; - -import com.xcong.excoin.common.utils.SpringContextUtil; -import com.xcong.excoin.job.entity.Job; -import com.xcong.excoin.job.entity.JobLog; -import com.xcong.excoin.job.service.IJobLogService; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.quartz.JobExecutionContext; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.scheduling.quartz.QuartzJobBean; - -import java.util.Date; -import java.util.concurrent.Future; - -/** - * 定时任务 - * - * @author MrBird - */ -@Slf4j -public class ScheduleJob extends QuartzJobBean { - - private ThreadPoolTaskExecutor scheduleJobExecutorService = SpringContextUtil.getBean("scheduleJobExecutorService", ThreadPoolTaskExecutor.class); - - @Override - protected void executeInternal(JobExecutionContext context) { - Job scheduleJob = (Job) context.getMergedJobDataMap().get(Job.JOB_PARAM_KEY); - - // 获取spring bean - IJobLogService scheduleJobLogService = SpringContextUtil.getBean(IJobLogService.class); - - JobLog jobLog = new JobLog(); - jobLog.setJobId(scheduleJob.getJobId()); - jobLog.setBeanName(scheduleJob.getBeanName()); - jobLog.setMethodName(scheduleJob.getMethodName()); - jobLog.setParams(scheduleJob.getParams()); - jobLog.setCreateTime(new Date()); - - long startTime = System.currentTimeMillis(); - - try { - // 执行任务 - log.info("任务准备执行,任务ID:{}", scheduleJob.getJobId()); - ScheduleRunnable task = new ScheduleRunnable(scheduleJob.getBeanName(), scheduleJob.getMethodName(), - scheduleJob.getParams()); - Future<?> future = scheduleJobExecutorService.submit(task); - future.get(); - long times = System.currentTimeMillis() - startTime; - jobLog.setTimes(times); - // 任务状态 0:成功 1:失败 - jobLog.setStatus(JobLog.JOB_SUCCESS); - - log.info("任务执行完毕,任务ID:{} 总共耗时:{} 毫秒", scheduleJob.getJobId(), times); - } catch (Exception e) { - log.error("任务执行失败,任务ID:" + scheduleJob.getJobId(), e); - long times = System.currentTimeMillis() - startTime; - jobLog.setTimes(times); - // 任务状态 0:成功 1:失败 - jobLog.setStatus(JobLog.JOB_FAIL); - jobLog.setError(StringUtils.substring(e.toString(), 0, 2000)); - } finally { - scheduleJobLogService.saveJobLog(jobLog); - } - } -} diff --git a/src/main/java/com/xcong/excoin/job/util/ScheduleRunnable.java b/src/main/java/com/xcong/excoin/job/util/ScheduleRunnable.java deleted file mode 100644 index 9a806a5..0000000 --- a/src/main/java/com/xcong/excoin/job/util/ScheduleRunnable.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.xcong.excoin.job.util; - -import com.xcong.excoin.common.utils.SpringContextUtil; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.util.ReflectionUtils; - -import java.lang.reflect.Method; - -/** - * 执行定时任务 - * - * @author MrBird - */ -@Slf4j -public class ScheduleRunnable implements Runnable { - - private Object target; - private Method method; - private String params; - - ScheduleRunnable(String beanName, String methodName, String params) throws NoSuchMethodException, SecurityException { - this.target = SpringContextUtil.getBean(beanName); - this.params = params; - - if (StringUtils.isNotBlank(params)) { - this.method = target.getClass().getDeclaredMethod(methodName, String.class); - } else { - this.method = target.getClass().getDeclaredMethod(methodName); - } - } - - @Override - public void run() { - try { - ReflectionUtils.makeAccessible(method); - if (StringUtils.isNotBlank(params)) { - method.invoke(target, params); - } else { - method.invoke(target); - } - } catch (Exception e) { - log.error("执行定时任务失败", e); - } - } - -} diff --git a/src/main/java/com/xcong/excoin/job/util/ScheduleUtils.java b/src/main/java/com/xcong/excoin/job/util/ScheduleUtils.java deleted file mode 100644 index 42007d7..0000000 --- a/src/main/java/com/xcong/excoin/job/util/ScheduleUtils.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.xcong.excoin.job.util; - -import com.xcong.excoin.job.entity.Job; -import lombok.extern.slf4j.Slf4j; -import org.quartz.*; - -/** - * 定时任务工具类 - * - * @author MrBird - */ -@Slf4j -public class ScheduleUtils { - - private static final String JOB_NAME_PREFIX = "TASK_"; - - /** - * 获取触发器 key - */ - private static TriggerKey getTriggerKey(Long jobId) { - return TriggerKey.triggerKey(JOB_NAME_PREFIX + jobId); - } - - /** - * 获取jobKey - */ - private static JobKey getJobKey(Long jobId) { - return JobKey.jobKey(JOB_NAME_PREFIX + jobId); - } - - /** - * 获取表达式触发器 - */ - public static CronTrigger getCronTrigger(Scheduler scheduler, Long jobId) { - try { - return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId)); - } catch (SchedulerException e) { - log.error("获取Cron表达式失败", e); - } - return null; - } - - /** - * 创建定时任务 - */ - public static void createScheduleJob(Scheduler scheduler, com.xcong.excoin.job.entity.Job scheduleJob) { - try { - // 构建job信息 - JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(getJobKey(scheduleJob.getJobId())) - .build(); - - // 表达式调度构建器 - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression()) - .withMisfireHandlingInstructionDoNothing(); - - // 按新的cronExpression表达式构建一个新的trigger - CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob.getJobId())) - .withSchedule(scheduleBuilder).build(); - - // 放入参数,运行时的方法可以获取 - jobDetail.getJobDataMap().put(com.xcong.excoin.job.entity.Job.JOB_PARAM_KEY, scheduleJob); - - scheduler.scheduleJob(jobDetail, trigger); - - // 暂停任务 - if (scheduleJob.getStatus().equals(com.xcong.excoin.job.entity.Job.ScheduleStatus.PAUSE.getValue())) { - pauseJob(scheduler, scheduleJob.getJobId()); - } - } catch (SchedulerException e) { - log.error("创建定时任务失败", e); - } - } - - /** - * 更新定时任务 - */ - public static void updateScheduleJob(Scheduler scheduler, com.xcong.excoin.job.entity.Job scheduleJob) { - try { - TriggerKey triggerKey = getTriggerKey(scheduleJob.getJobId()); - - // 表达式调度构建器 - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression()) - .withMisfireHandlingInstructionDoNothing(); - - CronTrigger trigger = getCronTrigger(scheduler, scheduleJob.getJobId()); - - if (trigger == null) { - throw new SchedulerException("获取Cron表达式失败"); - } else { - // 按新的 cronExpression表达式重新构建 trigger - trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); - // 参数 - trigger.getJobDataMap().put(com.xcong.excoin.job.entity.Job.JOB_PARAM_KEY, scheduleJob); - } - - scheduler.rescheduleJob(triggerKey, trigger); - - // 暂停任务 - if (scheduleJob.getStatus().equals(com.xcong.excoin.job.entity.Job.ScheduleStatus.PAUSE.getValue())) { - pauseJob(scheduler, scheduleJob.getJobId()); - } - - } catch (SchedulerException e) { - log.error("更新定时任务失败", e); - } - } - - /** - * 立即执行任务 - */ - public static void run(Scheduler scheduler, com.xcong.excoin.job.entity.Job scheduleJob) { - try { - // 参数 - JobDataMap dataMap = new JobDataMap(); - dataMap.put(Job.JOB_PARAM_KEY, scheduleJob); - - scheduler.triggerJob(getJobKey(scheduleJob.getJobId()), dataMap); - } catch (SchedulerException e) { - log.error("执行定时任务失败", e); - } - } - - /** - * 暂停任务 - */ - public static void pauseJob(Scheduler scheduler, Long jobId) { - try { - scheduler.pauseJob(getJobKey(jobId)); - } catch (SchedulerException e) { - log.error("暂停定时任务失败", e); - } - } - - /** - * 恢复任务 - */ - public static void resumeJob(Scheduler scheduler, Long jobId) { - try { - scheduler.resumeJob(getJobKey(jobId)); - } catch (SchedulerException e) { - log.error("恢复定时任务失败", e); - } - } - - /** - * 删除定时任务 - */ - public static void deleteScheduleJob(Scheduler scheduler, Long jobId) { - try { - scheduler.deleteJob(getJobKey(jobId)); - } catch (SchedulerException e) { - log.error("删除定时任务失败", e); - } - } -} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index a84924e..144ecf0 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -19,12 +19,6 @@ password: root driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/febs_base?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 - # 数据源-2,名称为 quartz - quartz: - username: root - password: root - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://127.0.0.1:3306/febs_quartz?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 redis: # Redis数据库索引(默认为 0) diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 04d0df9..6df33a3 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -19,12 +19,6 @@ password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/febs_base?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 - # 数据源-2,名称为 quartz - quartz: - username: root - password: 123456 - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://127.0.0.1:3306/febs_quartz?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 redis: # Redis数据库索引(默认为 0) diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 04d0df9..6df33a3 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -19,12 +19,6 @@ password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/febs_base?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 - # 数据源-2,名称为 quartz - quartz: - username: root - password: 123456 - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://127.0.0.1:3306/febs_quartz?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 redis: # Redis数据库索引(默认为 0) diff --git a/src/main/resources/mapper/job/JobMapper.xml b/src/main/resources/mapper/job/JobMapper.xml deleted file mode 100644 index 5b245b4..0000000 --- a/src/main/resources/mapper/job/JobMapper.xml +++ /dev/null @@ -1,16 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="com.xcong.excoin.job.mapper.JobMapper"> - <select id="queryList" resultType="job"> - select job_id jobId, - bean_name beanName, - method_name methodName, - params, - cron_expression cronExpression, - status, - remark, - create_time createTime - from t_job - order by job_id - </select> -</mapper> \ No newline at end of file diff --git a/src/main/resources/templates/febs/views/index.html b/src/main/resources/templates/febs/views/index.html index d27068d..a46deb5 100644 --- a/src/main/resources/templates/febs/views/index.html +++ b/src/main/resources/templates/febs/views/index.html @@ -99,9 +99,9 @@ <div class="layui-col-md-offset5"> <table class="login-count-table"> <tr> - <td>今日IP</td> - <td>今日访问</td> - <td>总访问量</td> + <td>注册用户数量</td> + <td>持仓用户数量</td> + <td>当前平台总金额</td> </tr> <tr> <td class="count" id="today-ip"> diff --git a/src/main/resources/templates/febs/views/layout.html b/src/main/resources/templates/febs/views/layout.html index 514ecb5..430a48e 100644 --- a/src/main/resources/templates/febs/views/layout.html +++ b/src/main/resources/templates/febs/views/layout.html @@ -26,8 +26,6 @@ <dl class="layui-nav-child"> <dd><a class="layui-nav-child-href" id="user-profile">个人中心</a></dd> <dd><a class="layui-nav-child-href" id="password-update">密码修改</a></dd> - <dd><a class="layui-nav-child-href" target="_blank" href="https://github.com/wuyouzhuguli/FEBS-Shiro">项目地址</a></dd> - <hr/> <dd><a class="layui-nav-child-href" data-th-href="@{logout}">退出登录</a></dd> </dl> </li> @@ -65,7 +63,7 @@ <div class="layui-side-scroll"> <div class="layui-logo" style="cursor: pointer"> <img data-th-src="@{febs/images/logo.png}"> - <span>FEBS 权限系统</span> + <span>ExCoin 管理系统</span> </div> <script type="text/html" -- Gitblit v1.9.1