From e541fe63246e140b9e3c1e309ec7f7d6540f191b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 3 Dec 2023 18:11:45 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20job=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/job/JobController.java | 43 +++++------- .../admin/job/JobLogController.java | 35 ++++------ .../admin/job/vo/job/JobCreateReqVO.java | 20 ------ .../admin/job/vo/job/JobExcelVO.java | 56 --------------- .../admin/job/vo/job/JobExportReqVO.java | 19 ----- .../admin/job/vo/job/JobRespVO.java | 41 +++++++++-- .../job/{JobBaseVO.java => JobSaveReqVO.java} | 19 +++-- .../admin/job/vo/job/JobUpdateReqVO.java | 20 ------ .../admin/job/vo/log/JobLogBaseVO.java | 53 -------------- .../admin/job/vo/log/JobLogExcelVO.java | 53 -------------- .../admin/job/vo/log/JobLogExportReqVO.java | 32 --------- .../admin/job/vo/log/JobLogRespVO.java | 51 ++++++++++++-- .../module/infra/convert/job/JobConvert.java | 36 ---------- .../infra/convert/job/JobLogConvert.java | 30 -------- .../infra/dal/mysql/job/JobLogMapper.java | 13 ---- .../module/infra/dal/mysql/job/JobMapper.java | 15 +--- .../infra/service/job/JobLogService.java | 20 ------ .../infra/service/job/JobLogServiceImpl.java | 22 ++---- .../module/infra/service/job/JobService.java | 16 +---- .../infra/service/job/JobServiceImpl.java | 21 ++---- .../service/job/JobLogServiceImplTest.java | 57 --------------- .../infra/service/job/JobServiceImplTest.java | 70 +++---------------- 22 files changed, 151 insertions(+), 591 deletions(-) delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobCreateReqVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExcelVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExportReqVO.java rename yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/{JobBaseVO.java => JobSaveReqVO.java} (65%) delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobUpdateReqVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogBaseVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExcelVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExportReqVO.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobConvert.java delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobLogConvert.java diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java index 2574db968f..8261ecd65c 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobController.java @@ -1,18 +1,21 @@ package cn.iocoder.yudao.module.infra.controller.admin.job; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.quartz.core.util.CronUtils; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.*; -import cn.iocoder.yudao.module.infra.convert.job.JobConvert; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobPageReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobRespVO; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import cn.iocoder.yudao.module.infra.service.job.JobService; -import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; -import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.quartz.SchedulerException; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; @@ -23,7 +26,6 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; import java.time.LocalDateTime; -import java.util.Collection; import java.util.Collections; import java.util.List; @@ -42,7 +44,7 @@ public class JobController { @PostMapping("/create") @Operation(summary = "创建定时任务") @PreAuthorize("@ss.hasPermission('infra:job:create')") - public CommonResult createJob(@Valid @RequestBody JobCreateReqVO createReqVO) + public CommonResult createJob(@Valid @RequestBody JobSaveReqVO createReqVO) throws SchedulerException { return success(jobService.createJob(createReqVO)); } @@ -50,7 +52,7 @@ public class JobController { @PutMapping("/update") @Operation(summary = "更新定时任务") @PreAuthorize("@ss.hasPermission('infra:job:update')") - public CommonResult updateJob(@Valid @RequestBody JobUpdateReqVO updateReqVO) + public CommonResult updateJob(@Valid @RequestBody JobSaveReqVO updateReqVO) throws SchedulerException { jobService.updateJob(updateReqVO); return success(true); @@ -94,16 +96,7 @@ public class JobController { @PreAuthorize("@ss.hasPermission('infra:job:query')") public CommonResult getJob(@RequestParam("id") Long id) { JobDO job = jobService.getJob(id); - return success(JobConvert.INSTANCE.convert(job)); - } - - @GetMapping("/list") - @Operation(summary = "获得定时任务列表") - @Parameter(name = "ids", description = "编号列表", required = true) - @PreAuthorize("@ss.hasPermission('infra:job:query')") - public CommonResult> getJobList(@RequestParam("ids") Collection ids) { - List list = jobService.getJobList(ids); - return success(JobConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(job, JobRespVO.class)); } @GetMapping("/page") @@ -111,19 +104,20 @@ public class JobController { @PreAuthorize("@ss.hasPermission('infra:job:query')") public CommonResult> getJobPage(@Valid JobPageReqVO pageVO) { PageResult pageResult = jobService.getJobPage(pageVO); - return success(JobConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, JobRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出定时任务 Excel") @PreAuthorize("@ss.hasPermission('infra:job:export')") @OperateLog(type = EXPORT) - public void exportJobExcel(@Valid JobExportReqVO exportReqVO, + public void exportJobExcel(@Valid JobPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = jobService.getJobList(exportReqVO); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = jobService.getJobPage(exportReqVO).getList(); // 导出 Excel - List datas = JobConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "定时任务.xls", "数据", JobExcelVO.class, datas); + ExcelUtils.write(response, "定时任务.xls", "数据", JobRespVO.class, + BeanUtils.toBean(list, JobRespVO.class)); } @GetMapping("/get_next_times") @@ -133,8 +127,9 @@ public class JobController { @Parameter(name = "count", description = "数量", example = "5") }) @PreAuthorize("@ss.hasPermission('infra:job:query')") - public CommonResult> getJobNextTimes(@RequestParam("id") Long id, - @RequestParam(value = "count", required = false, defaultValue = "5") Integer count) { + public CommonResult> getJobNextTimes( + @RequestParam("id") Long id, + @RequestParam(value = "count", required = false, defaultValue = "5") Integer count) { JobDO job = jobService.getJob(id); if (job == null) { return success(Collections.emptyList()); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java index 1441f9cf6d..5797ff6e59 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/JobLogController.java @@ -1,20 +1,18 @@ package cn.iocoder.yudao.module.infra.controller.admin.job; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.framework.operatelog.core.util.OperateLogUtils; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExcelVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogPageReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogRespVO; -import cn.iocoder.yudao.module.infra.convert.job.JobLogConvert; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; import cn.iocoder.yudao.module.infra.service.job.JobLogService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -26,7 +24,6 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; -import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -47,16 +44,7 @@ public class JobLogController { @PreAuthorize("@ss.hasPermission('infra:job:query')") public CommonResult getJobLog(@RequestParam("id") Long id) { JobLogDO jobLog = jobLogService.getJobLog(id); - return success(JobLogConvert.INSTANCE.convert(jobLog)); - } - - @GetMapping("/list") - @Operation(summary = "获得定时任务日志列表") - @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") - @PreAuthorize("@ss.hasPermission('infra:job:query')") - public CommonResult> getJobLogList(@RequestParam("ids") Collection ids) { - List list = jobLogService.getJobLogList(ids); - return success(JobLogConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(jobLog, JobLogRespVO.class)); } @GetMapping("/page") @@ -64,19 +52,20 @@ public class JobLogController { @PreAuthorize("@ss.hasPermission('infra:job:query')") public CommonResult> getJobLogPage(@Valid JobLogPageReqVO pageVO) { PageResult pageResult = jobLogService.getJobLogPage(pageVO); - return success(JobLogConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, JobLogRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出定时任务日志 Excel") @PreAuthorize("@ss.hasPermission('infra:job:export')") @OperateLog(type = EXPORT) - public void exportJobLogExcel(@Valid JobLogExportReqVO exportReqVO, + public void exportJobLogExcel(@Valid JobLogPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - List list = jobLogService.getJobLogList(exportReqVO); + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = jobLogService.getJobLogPage(exportReqVO).getList(); // 导出 Excel - List datas = JobLogConvert.INSTANCE.convertList02(list); - ExcelUtils.write(response, "任务日志.xls", "数据", JobLogExcelVO.class, datas); + ExcelUtils.write(response, "任务日志.xls", "数据", JobLogRespVO.class, + BeanUtils.toBean(list, JobLogRespVO.class)); } -} +} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobCreateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobCreateReqVO.java deleted file mode 100644 index be99145325..0000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobCreateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 定时任务创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class JobCreateReqVO extends JobBaseVO { - - @Schema(description = "处理器的名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "sysUserSessionTimeoutJob") - @NotNull(message = "处理器的名字不能为空") - private String handlerName; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExcelVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExcelVO.java deleted file mode 100644 index 55811ecec3..0000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExcelVO.java +++ /dev/null @@ -1,56 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 定时任务 Excel VO - * - * @author 芋道源码 - */ -@Data -public class JobExcelVO { - - @ExcelProperty("任务编号") - private Long id; - - @ExcelProperty("任务名称") - private String name; - - @ExcelProperty(value = "任务状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.JOB_STATUS) - private Integer status; - - @ExcelProperty("处理器的名字") - private String handlerName; - - @ExcelProperty("处理器的参数") - private String handlerParam; - - @ExcelProperty("CRON 表达式") - private String cronExpression; - - @ExcelProperty("最后一次执行的开始时间") - private LocalDateTime executeBeginTime; - - @ExcelProperty("最后一次执行的结束时间") - private LocalDateTime executeEndTime; - - @ExcelProperty("上一次触发时间") - private LocalDateTime firePrevTime; - - @ExcelProperty("下一次触发时间") - private LocalDateTime fireNextTime; - - @ExcelProperty("监控超时时间") - private Integer monitorTimeout; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExportReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExportReqVO.java deleted file mode 100644 index 49b7e83d3e..0000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobExportReqVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - 定时任务 Excel 导出 Request VO-参数和 JobPageReqVO 是一致的") -@Data -public class JobExportReqVO { - - @Schema(description = "任务名称-模糊匹配", example = "测试任务") - private String name; - - @Schema(description = "任务状态-参见 JobStatusEnum 枚举", example = "1") - private Integer status; - - @Schema(description = "处理器的名字-模糊匹配", example = "UserSessionTimeoutJob") - private String handlerName; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobRespVO.java index b0e18a7965..25683f89c9 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobRespVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobRespVO.java @@ -1,30 +1,59 @@ package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @Schema(description = "管理后台 - 定时任务 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class JobRespVO extends JobBaseVO { +@ExcelIgnoreUnannotated +public class JobRespVO { @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("任务编号") private Long id; + @Schema(description = "任务名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试任务") + @ExcelProperty("任务名称") + private String name; + @Schema(description = "任务状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "任务状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.JOB_STATUS) private Integer status; @Schema(description = "处理器的名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "sysUserSessionTimeoutJob") - @NotNull(message = "处理器的名字不能为空") + @ExcelProperty("处理器的名字") private String handlerName; + @Schema(description = "处理器的参数", example = "yudao") + @ExcelProperty("处理器的参数") + private String handlerParam; + + @Schema(description = "CRON 表达式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0/10 * * * * ? *") + @ExcelProperty("CRON 表达式") + private String cronExpression; + + @Schema(description = "重试次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "3") + @NotNull(message = "重试次数不能为空") + private Integer retryCount; + + @Schema(description = "重试间隔", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + private Integer retryInterval; + + @Schema(description = "监控超时时间", example = "1000") + @ExcelProperty("监控超时时间") + private Integer monitorTimeout; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") private LocalDateTime createTime; } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobSaveReqVO.java similarity index 65% rename from yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobBaseVO.java rename to yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobSaveReqVO.java index 9d14846b23..0fb986e63a 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobBaseVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobSaveReqVO.java @@ -3,24 +3,29 @@ package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -/** -* 定时任务 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ +@Schema(description = "管理后台 - 定时任务创建/修改 Request VO") @Data -public class JobBaseVO { +public class JobSaveReqVO { + + @Schema(description = "任务编号", example = "1024") + private Long id; @Schema(description = "任务名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试任务") - @NotNull(message = "任务名称不能为空") + @NotEmpty(message = "任务名称不能为空") private String name; + @Schema(description = "处理器的名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "sysUserSessionTimeoutJob") + @NotEmpty(message = "处理器的名字不能为空") + private String handlerName; + @Schema(description = "处理器的参数", example = "yudao") private String handlerParam; @Schema(description = "CRON 表达式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0/10 * * * * ? *") - @NotNull(message = "CRON 表达式不能为空") + @NotEmpty(message = "CRON 表达式不能为空") private String cronExpression; @Schema(description = "重试次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "3") diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobUpdateReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobUpdateReqVO.java deleted file mode 100644 index df1435669d..0000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/job/JobUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.job; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 定时任务更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class JobUpdateReqVO extends JobBaseVO { - - @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "任务编号不能为空") - private Long id; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogBaseVO.java deleted file mode 100644 index 5a74d38dbd..0000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogBaseVO.java +++ /dev/null @@ -1,53 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.log; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -/** -* 定时任务日志 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ -@Data -public class JobLogBaseVO { - - @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "任务编号不能为空") - private Long jobId; - - @Schema(description = "处理器的名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "sysUserSessionTimeoutJob") - @NotNull(message = "处理器的名字不能为空") - private String handlerName; - - @Schema(description = "处理器的参数", example = "yudao") - private String handlerParam; - - @Schema(description = "第几次执行", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "第几次执行不能为空") - private Integer executeIndex; - - @Schema(description = "开始执行时间", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "开始执行时间不能为空") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime beginTime; - - @Schema(description = "结束执行时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime endTime; - - @Schema(description = "执行时长", example = "123") - private Integer duration; - - @Schema(description = "任务状态,参见 JobLogStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "任务状态不能为空") - private Integer status; - - @Schema(description = "结果数据", example = "执行成功") - private String result; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExcelVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExcelVO.java deleted file mode 100644 index e8619d42ae..0000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExcelVO.java +++ /dev/null @@ -1,53 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.log; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * 定时任务 Excel VO - * - * @author 芋艿 - */ -@Data -public class JobLogExcelVO { - - @ExcelProperty("日志编号") - private Long id; - - @ExcelProperty("任务编号") - private Long jobId; - - @ExcelProperty("处理器的名字") - private String handlerName; - - @ExcelProperty("处理器的参数") - private String handlerParam; - - @ExcelProperty("第几次执行") - private Integer executeIndex; - - @ExcelProperty("开始执行时间") - private LocalDateTime beginTime; - - @ExcelProperty("结束执行时间") - private LocalDateTime endTime; - - @ExcelProperty("执行时长") - private Integer duration; - - @ExcelProperty(value = "任务状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.JOB_STATUS) - private Integer status; - - @ExcelProperty("结果数据") - private String result; - - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExportReqVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExportReqVO.java deleted file mode 100644 index 3156e2bc35..0000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogExportReqVO.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.yudao.module.infra.controller.admin.job.vo.log; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 定时任务 Excel 导出 Request VO,参数和 JobLogPageReqVO 是一致的") -@Data -public class JobLogExportReqVO { - - @Schema(description = "任务编号", example = "10") - private Long jobId; - - @Schema(description = "处理器的名字,模糊匹配") - private String handlerName; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "开始执行时间") - private LocalDateTime beginTime; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "结束执行时间") - private LocalDateTime endTime; - - @Schema(description = "任务状态,参见 JobLogStatusEnum 枚举") - private Integer status; - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogRespVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogRespVO.java index 4da31956af..543339d695 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogRespVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/job/vo/log/JobLogRespVO.java @@ -1,22 +1,63 @@ package cn.iocoder.yudao.module.infra.controller.admin.job.vo.log; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; @Schema(description = "管理后台 - 定时任务日志 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class JobLogRespVO extends JobLogBaseVO { +@ExcelIgnoreUnannotated +public class JobLogRespVO { @Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("日志编号") private Long id; + @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("任务编号") + private Long jobId; + + @Schema(description = "处理器的名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "sysUserSessionTimeoutJob") + @ExcelProperty("处理器的名字") + private String handlerName; + + @Schema(description = "处理器的参数", example = "yudao") + @ExcelProperty("处理器的参数") + private String handlerParam; + + @Schema(description = "第几次执行", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty("第几次执行") + private Integer executeIndex; + + @Schema(description = "开始执行时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("开始执行时间") + private LocalDateTime beginTime; + + @Schema(description = "结束执行时间") + @ExcelProperty("结束执行时间") + private LocalDateTime endTime; + + @Schema(description = "执行时长", example = "123") + @ExcelProperty("执行时长") + private Integer duration; + + @Schema(description = "任务状态,参见 JobLogStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "任务状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.JOB_STATUS) + private Integer status; + + @Schema(description = "结果数据", example = "执行成功") + @ExcelProperty("结果数据") + private String result; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") private LocalDateTime createTime; } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobConvert.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobConvert.java deleted file mode 100644 index 2c7aa02973..0000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobConvert.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.yudao.module.infra.convert.job; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobExcelVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobRespVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobUpdateReqVO; -import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 定时任务 Convert - * - * @author 芋道源码 - */ -@Mapper -public interface JobConvert { - - JobConvert INSTANCE = Mappers.getMapper(JobConvert.class); - - JobDO convert(JobCreateReqVO bean); - - JobDO convert(JobUpdateReqVO bean); - - JobRespVO convert(JobDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobLogConvert.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobLogConvert.java deleted file mode 100644 index 3f32c526d6..0000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/job/JobLogConvert.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.infra.convert.job; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExcelVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogRespVO; -import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -/** - * 定时任务日志 Convert - * - * @author 芋艿 - */ -@Mapper -public interface JobLogConvert { - - JobLogConvert INSTANCE = Mappers.getMapper(JobLogConvert.class); - - JobLogRespVO convert(JobLogDO bean); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - -} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobLogMapper.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobLogMapper.java index 31280685bc..58ac6daf15 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobLogMapper.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobLogMapper.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.infra.dal.mysql.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; import org.apache.ibatis.annotations.Delete; @@ -11,7 +10,6 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.time.LocalDateTime; -import java.util.List; /** * 任务日志 Mapper @@ -32,17 +30,6 @@ public interface JobLogMapper extends BaseMapperX { ); } - default List selectList(JobLogExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(JobLogDO::getJobId, reqVO.getJobId()) - .likeIfPresent(JobLogDO::getHandlerName, reqVO.getHandlerName()) - .geIfPresent(JobLogDO::getBeginTime, reqVO.getBeginTime()) - .leIfPresent(JobLogDO::getEndTime, reqVO.getEndTime()) - .eqIfPresent(JobLogDO::getStatus, reqVO.getStatus()) - .orderByDesc(JobLogDO::getId) // ID 倒序 - ); - } - /** * 物理删除指定时间之前的日志 * diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobMapper.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobMapper.java index 883906a013..c585dbb14c 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobMapper.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/job/JobMapper.java @@ -1,15 +1,12 @@ package cn.iocoder.yudao.module.infra.dal.mysql.job; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobExportReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobPageReqVO; -import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobPageReqVO; +import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import org.apache.ibatis.annotations.Mapper; -import java.util.List; - /** * 定时任务 Mapper * @@ -30,12 +27,4 @@ public interface JobMapper extends BaseMapperX { ); } - default List selectList(JobExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(JobDO::getName, reqVO.getName()) - .eqIfPresent(JobDO::getStatus, reqVO.getStatus()) - .likeIfPresent(JobDO::getHandlerName, reqVO.getHandlerName()) - ); - } - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogService.java index 87be870b45..f1e7e7c67e 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogService.java @@ -2,13 +2,9 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.quartz.core.service.JobLogFrameworkService; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; -import java.util.Collection; -import java.util.List; - /** * Job 日志 Service 接口 * @@ -24,14 +20,6 @@ public interface JobLogService extends JobLogFrameworkService { */ JobLogDO getJobLog(Long id); - /** - * 获得定时任务列表 - * - * @param ids 编号 - * @return 定时任务列表 - */ - List getJobLogList(Collection ids); - /** * 获得定时任务分页 * @@ -40,14 +28,6 @@ public interface JobLogService extends JobLogFrameworkService { */ PageResult getJobLogPage(JobLogPageReqVO pageReqVO); - /** - * 获得定时任务列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 定时任务分页 - */ - List getJobLogList(JobLogExportReqVO exportReqVO); - /** * 清理 exceedDay 天前的任务日志 * diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImpl.java index cab33079d0..868fd1bb2f 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImpl.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; import cn.iocoder.yudao.module.infra.dal.mysql.job.JobLogMapper; @@ -13,8 +12,6 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; /** * Job 日志 Service 实现类 @@ -30,8 +27,10 @@ public class JobLogServiceImpl implements JobLogService { private JobLogMapper jobLogMapper; @Override - public Long createJobLog(Long jobId, LocalDateTime beginTime, String jobHandlerName, String jobHandlerParam, Integer executeIndex) { - JobLogDO log = JobLogDO.builder().jobId(jobId).handlerName(jobHandlerName).handlerParam(jobHandlerParam).executeIndex(executeIndex) + public Long createJobLog(Long jobId, LocalDateTime beginTime, + String jobHandlerName, String jobHandlerParam, Integer executeIndex) { + JobLogDO log = JobLogDO.builder().jobId(jobId).handlerName(jobHandlerName) + .handlerParam(jobHandlerParam).executeIndex(executeIndex) .beginTime(beginTime).status(JobLogStatusEnum.RUNNING.getStatus()).build(); jobLogMapper.insert(log); return log.getId(); @@ -42,7 +41,8 @@ public class JobLogServiceImpl implements JobLogService { public void updateJobLogResultAsync(Long logId, LocalDateTime endTime, Integer duration, boolean success, String result) { try { JobLogDO updateObj = JobLogDO.builder().id(logId).endTime(endTime).duration(duration) - .status(success ? JobLogStatusEnum.SUCCESS.getStatus() : JobLogStatusEnum.FAILURE.getStatus()).result(result).build(); + .status(success ? JobLogStatusEnum.SUCCESS.getStatus() : JobLogStatusEnum.FAILURE.getStatus()) + .result(result).build(); jobLogMapper.updateById(updateObj); } catch (Exception ex) { log.error("[updateJobLogResultAsync][logId({}) endTime({}) duration({}) success({}) result({})]", @@ -72,19 +72,9 @@ public class JobLogServiceImpl implements JobLogService { return jobLogMapper.selectById(id); } - @Override - public List getJobLogList(Collection ids) { - return jobLogMapper.selectBatchIds(ids); - } - @Override public PageResult getJobLogPage(JobLogPageReqVO pageReqVO) { return jobLogMapper.selectPage(pageReqVO); } - @Override - public List getJobLogList(JobLogExportReqVO exportReqVO) { - return jobLogMapper.selectList(exportReqVO); - } - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java index bd5dd646d6..81a9de9bab 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobService.java @@ -1,10 +1,8 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import org.quartz.SchedulerException; @@ -25,14 +23,14 @@ public interface JobService { * @param createReqVO 创建信息 * @return 编号 */ - Long createJob(@Valid JobCreateReqVO createReqVO) throws SchedulerException; + Long createJob(@Valid JobSaveReqVO createReqVO) throws SchedulerException; /** * 更新定时任务 * * @param updateReqVO 更新信息 */ - void updateJob(@Valid JobUpdateReqVO updateReqVO) throws SchedulerException; + void updateJob(@Valid JobSaveReqVO updateReqVO) throws SchedulerException; /** * 更新定时任务的状态 @@ -80,12 +78,4 @@ public interface JobService { */ PageResult getJobPage(JobPageReqVO pageReqVO); - /** - * 获得定时任务列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 定时任务分页 - */ - List getJobList(JobExportReqVO exportReqVO); - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java index 498d816b81..40fe982730 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java @@ -1,13 +1,11 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.quartz.core.scheduler.SchedulerManager; import cn.iocoder.yudao.framework.quartz.core.util.CronUtils; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobUpdateReqVO; -import cn.iocoder.yudao.module.infra.convert.job.JobConvert; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import cn.iocoder.yudao.module.infra.dal.mysql.job.JobMapper; import cn.iocoder.yudao.module.infra.enums.job.JobStatusEnum; @@ -21,8 +19,8 @@ import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.containsAny; +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; /** * 定时任务 Service 实现类 @@ -41,14 +39,14 @@ public class JobServiceImpl implements JobService { @Override @Transactional(rollbackFor = Exception.class) - public Long createJob(JobCreateReqVO createReqVO) throws SchedulerException { + public Long createJob(JobSaveReqVO createReqVO) throws SchedulerException { validateCronExpression(createReqVO.getCronExpression()); // 校验唯一性 if (jobMapper.selectByHandlerName(createReqVO.getHandlerName()) != null) { throw exception(JOB_HANDLER_EXISTS); } // 插入 - JobDO job = JobConvert.INSTANCE.convert(createReqVO); + JobDO job = BeanUtils.toBean(createReqVO, JobDO.class); job.setStatus(JobStatusEnum.INIT.getStatus()); fillJobMonitorTimeoutEmpty(job); jobMapper.insert(job); @@ -66,7 +64,7 @@ public class JobServiceImpl implements JobService { @Override @Transactional(rollbackFor = Exception.class) - public void updateJob(JobUpdateReqVO updateReqVO) throws SchedulerException { + public void updateJob(JobSaveReqVO updateReqVO) throws SchedulerException { validateCronExpression(updateReqVO.getCronExpression()); // 校验存在 JobDO job = validateJobExists(updateReqVO.getId()); @@ -75,7 +73,7 @@ public class JobServiceImpl implements JobService { throw exception(JOB_UPDATE_ONLY_NORMAL_STATUS); } // 更新 - JobDO updateObj = JobConvert.INSTANCE.convert(updateReqVO); + JobDO updateObj = BeanUtils.toBean(updateReqVO, JobDO.class); fillJobMonitorTimeoutEmpty(updateObj); jobMapper.updateById(updateObj); @@ -159,11 +157,6 @@ public class JobServiceImpl implements JobService { return jobMapper.selectPage(pageReqVO); } - @Override - public List getJobList(JobExportReqVO exportReqVO) { - return jobMapper.selectList(exportReqVO); - } - private static void fillJobMonitorTimeoutEmpty(JobDO job) { if (job.getMonitorTimeout() == null) { job.setMonitorTimeout(0); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImplTest.java index efba0c0cfd..9061297ec6 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImplTest.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.log.JobLogPageReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobLogDO; import cn.iocoder.yudao.module.infra.dal.mysql.job.JobLogMapper; @@ -12,14 +11,11 @@ import org.springframework.context.annotation.Import; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static java.util.Collections.singleton; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -110,23 +106,6 @@ public class JobLogServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbJobLog, jobLog); } - @Test - public void testGetJobLogList() { - // mock 数据 - JobLogDO dbJobLog = randomPojo(JobLogDO.class, o -> o.setExecuteIndex(1)); - jobLogMapper.insert(dbJobLog); - // 测试 handlerName 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> {})); - // 准备参数 - Collection ids = singleton(dbJobLog.getId()); - - // 调用 - List list = jobLogService.getJobLogList(ids); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbJobLog, list.get(0)); - } - @Test public void testGetJobPage() { // mock 数据 @@ -164,40 +143,4 @@ public class JobLogServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbJobLog, pageResult.getList().get(0)); } - @Test - public void testGetJobList_export() { - // mock 数据 - JobLogDO dbJobLog = randomPojo(JobLogDO.class, o -> { - o.setExecuteIndex(1); - o.setHandlerName("handlerName 单元测试"); - o.setStatus(JobLogStatusEnum.SUCCESS.getStatus()); - o.setBeginTime(buildTime(2021, 1, 8)); - o.setEndTime(buildTime(2021, 1, 8)); - }); - jobLogMapper.insert(dbJobLog); - // 测试 jobId 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> o.setJobId(randomLongId()))); - // 测试 handlerName 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> o.setHandlerName(randomString()))); - // 测试 beginTime 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> o.setBeginTime(buildTime(2021, 1, 7)))); - // 测试 endTime 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> o.setEndTime(buildTime(2021, 1, 9)))); - // 测试 status 不匹配 - jobLogMapper.insert(cloneIgnoreId(dbJobLog, o -> o.setStatus(JobLogStatusEnum.FAILURE.getStatus()))); - // 准备参数 - JobLogExportReqVO reqVo = new JobLogExportReqVO(); - reqVo.setJobId(dbJobLog.getJobId()); - reqVo.setHandlerName("单元"); - reqVo.setBeginTime(dbJobLog.getBeginTime()); - reqVo.setEndTime(dbJobLog.getEndTime()); - reqVo.setStatus(JobLogStatusEnum.SUCCESS.getStatus()); - - // 调用 - List list = jobLogService.getJobLogList(reqVo); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbJobLog, list.get(0)); - } - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImplTest.java index f10c40365c..fe673fec2a 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImplTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImplTest.java @@ -3,10 +3,8 @@ package cn.iocoder.yudao.module.infra.service.job; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.quartz.core.scheduler.SchedulerManager; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobCreateReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobExportReqVO; import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobPageReqVO; -import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobUpdateReqVO; +import cn.iocoder.yudao.module.infra.controller.admin.job.vo.job.JobSaveReqVO; import cn.iocoder.yudao.module.infra.dal.dataobject.job.JobDO; import cn.iocoder.yudao.module.infra.dal.mysql.job.JobMapper; import cn.iocoder.yudao.module.infra.enums.job.JobStatusEnum; @@ -16,17 +14,13 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import javax.annotation.Resource; -import java.util.Collection; -import java.util.List; -import static cn.hutool.core.util.RandomUtil.randomEle; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; -import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; @@ -44,7 +38,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { @Test public void testCreateJob_cronExpressionValid() { // 准备参数。Cron 表达式为 String 类型,默认随机字符串。 - JobCreateReqVO reqVO = randomPojo(JobCreateReqVO.class); + JobSaveReqVO reqVO = randomPojo(JobSaveReqVO.class); // 调用,并断言异常 assertServiceException(() -> jobService.createJob(reqVO), JOB_CRON_EXPRESSION_VALID); @@ -53,7 +47,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { @Test public void testCreateJob_jobHandlerExists() throws SchedulerException { // 准备参数 指定 Cron 表达式 - JobCreateReqVO reqVO = randomPojo(JobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")); + JobSaveReqVO reqVO = randomPojo(JobSaveReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")); // 调用 jobService.createJob(reqVO); @@ -64,7 +58,8 @@ public class JobServiceImplTest extends BaseDbUnitTest { @Test public void testCreateJob_success() throws SchedulerException { // 准备参数 指定 Cron 表达式 - JobCreateReqVO reqVO = randomPojo(JobCreateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")); + JobSaveReqVO reqVO = randomPojo(JobSaveReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")) + .setId(null); // 调用 Long jobId = jobService.createJob(reqVO); @@ -72,7 +67,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { assertNotNull(jobId); // 校验记录的属性是否正确 JobDO job = jobMapper.selectById(jobId); - assertPojoEquals(reqVO, job); + assertPojoEquals(reqVO, job, "id"); assertEquals(JobStatusEnum.NORMAL.getStatus(), job.getStatus()); // 校验调用 verify(schedulerManager).addJob(eq(job.getId()), eq(job.getHandlerName()), eq(job.getHandlerParam()), @@ -82,7 +77,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateJob_jobNotExists(){ // 准备参数 - JobUpdateReqVO reqVO = randomPojo(JobUpdateReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")); + JobSaveReqVO reqVO = randomPojo(JobSaveReqVO.class, o -> o.setCronExpression("0 0/1 * * * ? *")); // 调用,并断言异常 assertServiceException(() -> jobService.updateJob(reqVO), JOB_NOT_EXISTS); @@ -94,7 +89,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { JobDO job = randomPojo(JobDO.class, o -> o.setStatus(JobStatusEnum.INIT.getStatus())); jobMapper.insert(job); // 准备参数 - JobUpdateReqVO updateReqVO = randomPojo(JobUpdateReqVO.class, o -> { + JobSaveReqVO updateReqVO = randomPojo(JobSaveReqVO.class, o -> { o.setId(job.getId()); o.setCronExpression("0 0/1 * * * ? *"); }); @@ -110,7 +105,7 @@ public class JobServiceImplTest extends BaseDbUnitTest { JobDO job = randomPojo(JobDO.class, o -> o.setStatus(JobStatusEnum.NORMAL.getStatus())); jobMapper.insert(job); // 准备参数 - JobUpdateReqVO updateReqVO = randomPojo(JobUpdateReqVO.class, o -> { + JobSaveReqVO updateReqVO = randomPojo(JobSaveReqVO.class, o -> { o.setId(job.getId()); o.setCronExpression("0 0/1 * * * ? *"); }); @@ -200,25 +195,6 @@ public class JobServiceImplTest extends BaseDbUnitTest { verify(schedulerManager).deleteJob(eq(job.getHandlerName())); } - @Test - public void testGetJobList() { - // mock 数据 - JobDO dbJob = randomPojo(JobDO.class, o -> { - o.setStatus(randomEle(JobStatusEnum.values()).getStatus()); // 保证 status 的范围 - }); - jobMapper.insert(dbJob); - // 测试 id 不匹配 - jobMapper.insert(cloneIgnoreId(dbJob, o -> {})); - - // 准备参数 - Collection ids = singletonList(dbJob.getId()); - // 调用 - List list = jobService.getJobList(ids); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbJob, list.get(0)); - } - @Test public void testGetJobPage() { // mock 数据 @@ -248,34 +224,6 @@ public class JobServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbJob, pageResult.getList().get(0)); } - @Test - public void testGetJobList_export() { - // mock 数据 - JobDO dbJob = randomPojo(JobDO.class, o -> { - o.setName("定时任务测试"); - o.setHandlerName("handlerName 单元测试"); - o.setStatus(JobStatusEnum.INIT.getStatus()); - }); - jobMapper.insert(dbJob); - // 测试 name 不匹配 - jobMapper.insert(cloneIgnoreId(dbJob, o -> o.setName("土豆"))); - // 测试 status 不匹配 - jobMapper.insert(cloneIgnoreId(dbJob, o -> o.setStatus(JobStatusEnum.NORMAL.getStatus()))); - // 测试 handlerName 不匹配 - jobMapper.insert(cloneIgnoreId(dbJob, o -> o.setHandlerName(randomString()))); - // 准备参数 - JobExportReqVO reqVo = new JobExportReqVO(); - reqVo.setName("定时"); - reqVo.setStatus(JobStatusEnum.INIT.getStatus()); - reqVo.setHandlerName("单元"); - - // 调用 - List list = jobService.getJobList(reqVo); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(dbJob, list.get(0)); - } - @Test public void testGetJob() { // mock 数据