🔧 简化 job 模块的 VO
This commit is contained in:
parent
35d171b1d9
commit
e541fe6324
|
@ -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<Long> createJob(@Valid @RequestBody JobCreateReqVO createReqVO)
|
||||
public CommonResult<Long> 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<Boolean> updateJob(@Valid @RequestBody JobUpdateReqVO updateReqVO)
|
||||
public CommonResult<Boolean> 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<JobRespVO> 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<List<JobRespVO>> getJobList(@RequestParam("ids") Collection<Long> ids) {
|
||||
List<JobDO> 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<PageResult<JobRespVO>> getJobPage(@Valid JobPageReqVO pageVO) {
|
||||
PageResult<JobDO> 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<JobDO> list = jobService.getJobList(exportReqVO);
|
||||
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<JobDO> list = jobService.getJobPage(exportReqVO).getList();
|
||||
// 导出 Excel
|
||||
List<JobExcelVO> 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<List<LocalDateTime>> getJobNextTimes(@RequestParam("id") Long id,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "5") Integer count) {
|
||||
public CommonResult<List<LocalDateTime>> 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());
|
||||
|
|
|
@ -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<JobLogRespVO> 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<List<JobLogRespVO>> getJobLogList(@RequestParam("ids") Collection<Long> ids) {
|
||||
List<JobLogDO> 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<PageResult<JobLogRespVO>> getJobLogPage(@Valid JobLogPageReqVO pageVO) {
|
||||
PageResult<JobLogDO> 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<JobLogDO> list = jobLogService.getJobLogList(exportReqVO);
|
||||
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<JobLogDO> list = jobLogService.getJobLogPage(exportReqVO).getList();
|
||||
// 导出 Excel
|
||||
List<JobLogExcelVO> datas = JobLogConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "任务日志.xls", "数据", JobLogExcelVO.class, datas);
|
||||
ExcelUtils.write(response, "任务日志.xls", "数据", JobLogRespVO.class,
|
||||
BeanUtils.toBean(list, JobLogRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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")
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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<JobRespVO> convertList(List<JobDO> list);
|
||||
|
||||
PageResult<JobRespVO> convertPage(PageResult<JobDO> page);
|
||||
|
||||
List<JobExcelVO> convertList02(List<JobDO> list);
|
||||
|
||||
}
|
|
@ -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<JobLogRespVO> convertList(List<JobLogDO> list);
|
||||
|
||||
PageResult<JobLogRespVO> convertPage(PageResult<JobLogDO> page);
|
||||
|
||||
List<JobLogExcelVO> convertList02(List<JobLogDO> list);
|
||||
|
||||
}
|
|
@ -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<JobLogDO> {
|
|||
);
|
||||
}
|
||||
|
||||
default List<JobLogDO> selectList(JobLogExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<JobLogDO>()
|
||||
.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 倒序
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 物理删除指定时间之前的日志
|
||||
*
|
||||
|
|
|
@ -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<JobDO> {
|
|||
);
|
||||
}
|
||||
|
||||
default List<JobDO> selectList(JobExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<JobDO>()
|
||||
.likeIfPresent(JobDO::getName, reqVO.getName())
|
||||
.eqIfPresent(JobDO::getStatus, reqVO.getStatus())
|
||||
.likeIfPresent(JobDO::getHandlerName, reqVO.getHandlerName())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<JobLogDO> getJobLogList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得定时任务分页
|
||||
*
|
||||
|
@ -40,14 +28,6 @@ public interface JobLogService extends JobLogFrameworkService {
|
|||
*/
|
||||
PageResult<JobLogDO> getJobLogPage(JobLogPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得定时任务列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 定时任务分页
|
||||
*/
|
||||
List<JobLogDO> getJobLogList(JobLogExportReqVO exportReqVO);
|
||||
|
||||
/**
|
||||
* 清理 exceedDay 天前的任务日志
|
||||
*
|
||||
|
|
|
@ -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<JobLogDO> getJobLogList(Collection<Long> ids) {
|
||||
return jobLogMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<JobLogDO> getJobLogPage(JobLogPageReqVO pageReqVO) {
|
||||
return jobLogMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JobLogDO> getJobLogList(JobLogExportReqVO exportReqVO) {
|
||||
return jobLogMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<JobDO> getJobPage(JobPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得定时任务列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 定时任务分页
|
||||
*/
|
||||
List<JobDO> getJobList(JobExportReqVO exportReqVO);
|
||||
|
||||
}
|
||||
|
|
|
@ -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<JobDO> getJobList(JobExportReqVO exportReqVO) {
|
||||
return jobMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
private static void fillJobMonitorTimeoutEmpty(JobDO job) {
|
||||
if (job.getMonitorTimeout() == null) {
|
||||
job.setMonitorTimeout(0);
|
||||
|
|
|
@ -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<Long> ids = singleton(dbJobLog.getId());
|
||||
|
||||
// 调用
|
||||
List<JobLogDO> 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<JobLogDO> list = jobLogService.getJobLogList(reqVo);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbJobLog, list.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Long> ids = singletonList(dbJob.getId());
|
||||
// 调用
|
||||
List<JobDO> 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<JobDO> list = jobService.getJobList(reqVo);
|
||||
// 断言
|
||||
assertEquals(1, list.size());
|
||||
assertPojoEquals(dbJob, list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJob() {
|
||||
// mock 数据
|
||||
|
|
Loading…
Reference in New Issue