Commit 9365b0f067641b5422c890ffb96f588db63427bc
1 parent
fbcfb3e1
fix: [DEFECT-1168]定时任务调度日志里面,增加时间过滤条件
Showing
2 changed files
with
29 additions
and
8 deletions
... | ... | @@ -7,6 +7,8 @@ import org.quartz.SchedulerException; |
7 | 7 | import org.springframework.security.access.prepost.PreAuthorize; |
8 | 8 | import org.springframework.web.bind.annotation.*; |
9 | 9 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
10 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
10 | 12 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
11 | 13 | import org.thingsboard.server.common.data.yunteng.dto.SysJobLogDTO; |
12 | 14 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
... | ... | @@ -15,15 +17,13 @@ import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
15 | 17 | import org.thingsboard.server.controller.BaseController; |
16 | 18 | import org.thingsboard.server.dao.yunteng.service.TkSysJobLogService; |
17 | 19 | |
20 | +import java.sql.Timestamp; | |
18 | 21 | import java.util.HashMap; |
19 | 22 | |
20 | 23 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
21 | 24 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE; |
22 | 25 | |
23 | -/** | |
24 | - * 调度日志操作处理 | |
25 | - * | |
26 | - */ | |
26 | +/** 调度日志操作处理 */ | |
27 | 27 | @RestController |
28 | 28 | @RequestMapping("api/yt/monitor/job_log") |
29 | 29 | @RequiredArgsConstructor |
... | ... | @@ -44,6 +44,8 @@ public class SysJobLogController extends BaseController { |
44 | 44 | @RequestParam(value = "jobGroup", required = false) String jobGroup, |
45 | 45 | @RequestParam(value = "status", required = false) Integer status, |
46 | 46 | @RequestParam(value = "jobId", required = false) String jobId, |
47 | + @RequestParam(value = "startTime", required = false) Long startTime, | |
48 | + @RequestParam(value = "endTime", required = false) Long endTime, | |
47 | 49 | @RequestParam(value = ORDER_FILED, required = false) String orderBy, |
48 | 50 | @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) |
49 | 51 | throws ThingsboardException { |
... | ... | @@ -58,6 +60,15 @@ public class SysJobLogController extends BaseController { |
58 | 60 | if (orderType != null) { |
59 | 61 | queryMap.put(ORDER_TYPE, orderType.name()); |
60 | 62 | } |
63 | + | |
64 | + if (null != startTime && null != endTime) { | |
65 | + if (startTime > endTime) { | |
66 | + throw new TkDataValidationException( | |
67 | + ErrorMessage.START_TIME_NOT_MORE_THAN_END_TIME.getMessage()); | |
68 | + } | |
69 | + queryMap.put("startTime", new Timestamp(startTime).toLocalDateTime()); | |
70 | + queryMap.put("endTime", new Timestamp(endTime).toLocalDateTime()); | |
71 | + } | |
61 | 72 | return tkSysJobLogService.sysJobLogPageByJobId(queryMap); |
62 | 73 | } |
63 | 74 | |
... | ... | @@ -70,9 +81,10 @@ public class SysJobLogController extends BaseController { |
70 | 81 | |
71 | 82 | @GetMapping("/get/{jobId}/{id}") |
72 | 83 | @ApiOperation(value = "获取详情") |
73 | - public ResponseResult<SysJobLogDTO> getSysJobLog(@PathVariable("jobId") String jobId,@PathVariable("id") String id) | |
74 | - throws SchedulerException { | |
75 | - return ResponseResult.success(tkSysJobLogService.findSysJobLogById(jobId,id)); | |
84 | + public ResponseResult<SysJobLogDTO> getSysJobLog( | |
85 | + @PathVariable("jobId") String jobId, @PathVariable("id") String id) | |
86 | + throws SchedulerException { | |
87 | + return ResponseResult.success(tkSysJobLogService.findSysJobLogById(jobId, id)); | |
76 | 88 | } |
77 | 89 | |
78 | 90 | @PostMapping("/clean") | ... | ... |
... | ... | @@ -19,6 +19,8 @@ import org.thingsboard.server.dao.yunteng.entities.SysJobLogEntity; |
19 | 19 | import org.thingsboard.server.dao.yunteng.mapper.SysJobLogMapper; |
20 | 20 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
21 | 21 | import org.thingsboard.server.dao.yunteng.service.TkSysJobLogService; |
22 | + | |
23 | +import java.time.LocalDateTime; | |
22 | 24 | import java.time.ZoneOffset; |
23 | 25 | import java.util.Map; |
24 | 26 | import java.util.Optional; |
... | ... | @@ -37,6 +39,8 @@ public class SysJobLogServiceImpl extends AbstractBaseService<SysJobLogMapper, S |
37 | 39 | String jobId = queryMap.get("jobId") != null ? queryMap.get("jobId").toString() : null; |
38 | 40 | Integer status = |
39 | 41 | queryMap.get("status") != null ? Integer.valueOf(queryMap.get("status").toString()) : null; |
42 | + LocalDateTime startTime = (LocalDateTime) queryMap.get("startTime"); | |
43 | + LocalDateTime endTime = (LocalDateTime) queryMap.get("endTime"); | |
40 | 44 | IPage<SysJobLogEntity> sysJobLogIPage = |
41 | 45 | baseMapper.selectPage( |
42 | 46 | getPage(queryMap, "start_time", false), |
... | ... | @@ -44,7 +48,12 @@ public class SysJobLogServiceImpl extends AbstractBaseService<SysJobLogMapper, S |
44 | 48 | .eq(StringUtils.isNotEmpty(jobId), SysJobLogEntity::getJobId, jobId) |
45 | 49 | .like(StringUtils.isNotEmpty(jobName), SysJobLogEntity::getJobName, jobName) |
46 | 50 | .eq(StringUtils.isNotEmpty(jobGroup), SysJobLogEntity::getJobGroup, jobGroup) |
47 | - .eq(null != status, SysJobLogEntity::getStatus, status)); | |
51 | + .eq(null != status, SysJobLogEntity::getStatus, status) | |
52 | + .and( | |
53 | + null != startTime && null != endTime, | |
54 | + qr -> | |
55 | + qr.ge(SysJobLogEntity::getStartTime, startTime) | |
56 | + .le(SysJobLogEntity::getStartTime, endTime))); | |
48 | 57 | return getPageData(sysJobLogIPage, SysJobLogDTO.class); |
49 | 58 | } |
50 | 59 | ... | ... |