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,6 +7,8 @@ import org.quartz.SchedulerException; | ||
7 | import org.springframework.security.access.prepost.PreAuthorize; | 7 | import org.springframework.security.access.prepost.PreAuthorize; |
8 | import org.springframework.web.bind.annotation.*; | 8 | import org.springframework.web.bind.annotation.*; |
9 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 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 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | 12 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
11 | import org.thingsboard.server.common.data.yunteng.dto.SysJobLogDTO; | 13 | import org.thingsboard.server.common.data.yunteng.dto.SysJobLogDTO; |
12 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | 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,15 +17,13 @@ import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | ||
15 | import org.thingsboard.server.controller.BaseController; | 17 | import org.thingsboard.server.controller.BaseController; |
16 | import org.thingsboard.server.dao.yunteng.service.TkSysJobLogService; | 18 | import org.thingsboard.server.dao.yunteng.service.TkSysJobLogService; |
17 | 19 | ||
20 | +import java.sql.Timestamp; | ||
18 | import java.util.HashMap; | 21 | import java.util.HashMap; |
19 | 22 | ||
20 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | 23 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
21 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE; | 24 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE; |
22 | 25 | ||
23 | -/** | ||
24 | - * 调度日志操作处理 | ||
25 | - * | ||
26 | - */ | 26 | +/** 调度日志操作处理 */ |
27 | @RestController | 27 | @RestController |
28 | @RequestMapping("api/yt/monitor/job_log") | 28 | @RequestMapping("api/yt/monitor/job_log") |
29 | @RequiredArgsConstructor | 29 | @RequiredArgsConstructor |
@@ -44,6 +44,8 @@ public class SysJobLogController extends BaseController { | @@ -44,6 +44,8 @@ public class SysJobLogController extends BaseController { | ||
44 | @RequestParam(value = "jobGroup", required = false) String jobGroup, | 44 | @RequestParam(value = "jobGroup", required = false) String jobGroup, |
45 | @RequestParam(value = "status", required = false) Integer status, | 45 | @RequestParam(value = "status", required = false) Integer status, |
46 | @RequestParam(value = "jobId", required = false) String jobId, | 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 | @RequestParam(value = ORDER_FILED, required = false) String orderBy, | 49 | @RequestParam(value = ORDER_FILED, required = false) String orderBy, |
48 | @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | 50 | @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) |
49 | throws ThingsboardException { | 51 | throws ThingsboardException { |
@@ -58,6 +60,15 @@ public class SysJobLogController extends BaseController { | @@ -58,6 +60,15 @@ public class SysJobLogController extends BaseController { | ||
58 | if (orderType != null) { | 60 | if (orderType != null) { |
59 | queryMap.put(ORDER_TYPE, orderType.name()); | 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 | return tkSysJobLogService.sysJobLogPageByJobId(queryMap); | 72 | return tkSysJobLogService.sysJobLogPageByJobId(queryMap); |
62 | } | 73 | } |
63 | 74 | ||
@@ -70,9 +81,10 @@ public class SysJobLogController extends BaseController { | @@ -70,9 +81,10 @@ public class SysJobLogController extends BaseController { | ||
70 | 81 | ||
71 | @GetMapping("/get/{jobId}/{id}") | 82 | @GetMapping("/get/{jobId}/{id}") |
72 | @ApiOperation(value = "获取详情") | 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 | @PostMapping("/clean") | 90 | @PostMapping("/clean") |
@@ -19,6 +19,8 @@ import org.thingsboard.server.dao.yunteng.entities.SysJobLogEntity; | @@ -19,6 +19,8 @@ import org.thingsboard.server.dao.yunteng.entities.SysJobLogEntity; | ||
19 | import org.thingsboard.server.dao.yunteng.mapper.SysJobLogMapper; | 19 | import org.thingsboard.server.dao.yunteng.mapper.SysJobLogMapper; |
20 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | 20 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
21 | import org.thingsboard.server.dao.yunteng.service.TkSysJobLogService; | 21 | import org.thingsboard.server.dao.yunteng.service.TkSysJobLogService; |
22 | + | ||
23 | +import java.time.LocalDateTime; | ||
22 | import java.time.ZoneOffset; | 24 | import java.time.ZoneOffset; |
23 | import java.util.Map; | 25 | import java.util.Map; |
24 | import java.util.Optional; | 26 | import java.util.Optional; |
@@ -37,6 +39,8 @@ public class SysJobLogServiceImpl extends AbstractBaseService<SysJobLogMapper, S | @@ -37,6 +39,8 @@ public class SysJobLogServiceImpl extends AbstractBaseService<SysJobLogMapper, S | ||
37 | String jobId = queryMap.get("jobId") != null ? queryMap.get("jobId").toString() : null; | 39 | String jobId = queryMap.get("jobId") != null ? queryMap.get("jobId").toString() : null; |
38 | Integer status = | 40 | Integer status = |
39 | queryMap.get("status") != null ? Integer.valueOf(queryMap.get("status").toString()) : null; | 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 | IPage<SysJobLogEntity> sysJobLogIPage = | 44 | IPage<SysJobLogEntity> sysJobLogIPage = |
41 | baseMapper.selectPage( | 45 | baseMapper.selectPage( |
42 | getPage(queryMap, "start_time", false), | 46 | getPage(queryMap, "start_time", false), |
@@ -44,7 +48,12 @@ public class SysJobLogServiceImpl extends AbstractBaseService<SysJobLogMapper, S | @@ -44,7 +48,12 @@ public class SysJobLogServiceImpl extends AbstractBaseService<SysJobLogMapper, S | ||
44 | .eq(StringUtils.isNotEmpty(jobId), SysJobLogEntity::getJobId, jobId) | 48 | .eq(StringUtils.isNotEmpty(jobId), SysJobLogEntity::getJobId, jobId) |
45 | .like(StringUtils.isNotEmpty(jobName), SysJobLogEntity::getJobName, jobName) | 49 | .like(StringUtils.isNotEmpty(jobName), SysJobLogEntity::getJobName, jobName) |
46 | .eq(StringUtils.isNotEmpty(jobGroup), SysJobLogEntity::getJobGroup, jobGroup) | 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 | return getPageData(sysJobLogIPage, SysJobLogDTO.class); | 57 | return getPageData(sysJobLogIPage, SysJobLogDTO.class); |
49 | } | 58 | } |
50 | 59 |