1
|
1
|
package org.thingsboard.server.controller.yunteng;
|
2
|
2
|
|
|
3
|
+import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*;
|
|
4
|
+import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE;
|
|
5
|
+
|
3
|
6
|
import io.swagger.annotations.Api;
|
4
|
7
|
import io.swagger.annotations.ApiOperation;
|
|
8
|
+import java.util.HashMap;
|
|
9
|
+import java.util.List;
|
|
10
|
+import javax.annotation.PostConstruct;
|
5
|
11
|
import lombok.RequiredArgsConstructor;
|
6
|
12
|
import org.apache.commons.lang3.StringUtils;
|
7
|
13
|
import org.quartz.SchedulerException;
|
...
|
...
|
@@ -19,16 +25,12 @@ import org.thingsboard.server.common.data.yunteng.dto.SysJobDTO; |
19
|
25
|
import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum;
|
20
|
26
|
import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult;
|
21
|
27
|
import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
|
|
28
|
+import org.thingsboard.server.common.msg.queue.ServiceType;
|
22
|
29
|
import org.thingsboard.server.controller.BaseController;
|
23
|
30
|
import org.thingsboard.server.dao.util.yunteng.CronUtils;
|
24
|
31
|
import org.thingsboard.server.dao.util.yunteng.ScheduleUtils;
|
25
|
32
|
import org.thingsboard.server.dao.yunteng.service.TkSysJobService;
|
26
|
|
-
|
27
|
|
-import java.util.HashMap;
|
28
|
|
-import java.util.List;
|
29
|
|
-
|
30
|
|
-import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*;
|
31
|
|
-import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE;
|
|
33
|
+import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
|
32
|
34
|
|
33
|
35
|
/** 调度任务信息操作处理 */
|
34
|
36
|
@RestController
|
...
|
...
|
@@ -38,6 +40,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. |
38
|
40
|
@PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{})")
|
39
|
41
|
public class SysJobController extends BaseController {
|
40
|
42
|
private final TkSysJobService jobService;
|
|
43
|
+ private final TbServiceInfoProvider serviceInfoProvider;
|
41
|
44
|
|
42
|
45
|
@GetMapping(
|
43
|
46
|
path = "/page",
|
...
|
...
|
@@ -90,7 +93,7 @@ public class SysJobController extends BaseController { |
90
|
93
|
@ApiOperation(value = "任务调度立即执行一次")
|
91
|
94
|
public ResponseResult<Boolean> run(@PathVariable("id") String id) throws SchedulerException {
|
92
|
95
|
SysJobDTO jobDTO = jobService.selectJobById(id);
|
93
|
|
- if(null == jobDTO){
|
|
96
|
+ if (null == jobDTO) {
|
94
|
97
|
throw new TkDataValidationException(ErrorMessage.INTERNAL_ERROR.getMessage());
|
95
|
98
|
}
|
96
|
99
|
boolean result = jobService.run(jobDTO);
|
...
|
...
|
@@ -142,8 +145,7 @@ public class SysJobController extends BaseController { |
142
|
145
|
return ResponseResult.success(dateList);
|
143
|
146
|
}
|
144
|
147
|
|
145
|
|
- private ResponseResult<SysJobDTO> saveOrUpdate(SysJobDTO job)
|
146
|
|
- throws SchedulerException{
|
|
148
|
+ private ResponseResult<SysJobDTO> saveOrUpdate(SysJobDTO job) throws SchedulerException {
|
147
|
149
|
String message = StringUtils.isEmpty(job.getId()) ? "新增任务'" : "修改任务'";
|
148
|
150
|
if (!CronUtils.isValid(job.getCronExpression())) {
|
149
|
151
|
throw new TkDataValidationException(message + job.getJobName() + "'失败,Cron表达式不正确");
|
...
|
...
|
@@ -171,4 +173,13 @@ public class SysJobController extends BaseController { |
171
|
173
|
}
|
172
|
174
|
return ResponseResult.success(jobService.saveOrUpdateJob(job));
|
173
|
175
|
}
|
|
176
|
+
|
|
177
|
+ /** 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据) */
|
|
178
|
+ @PostConstruct
|
|
179
|
+ public void init() throws SchedulerException {
|
|
180
|
+ if (!serviceInfoProvider.isService(ServiceType.TB_CORE)) {
|
|
181
|
+ return;
|
|
182
|
+ }
|
|
183
|
+ jobService.init();
|
|
184
|
+ }
|
174
|
185
|
} |
...
|
...
|
|