|
@@ -2,8 +2,10 @@ package com.xxl.job.admin.controller.custom;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
@@ -12,12 +14,17 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.persagy.common.utils.StringUtil;
|
|
|
import com.xxl.job.admin.core.model.DictQuery;
|
|
|
+import com.xxl.job.admin.core.model.XxlJobGroup;
|
|
|
import com.xxl.job.admin.core.model.XxlJobInfo;
|
|
|
+import com.xxl.job.admin.core.model.XxlJobInfoIdValid;
|
|
|
+import com.xxl.job.admin.core.model.XxlJobInfoValid;
|
|
|
import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
|
|
|
import com.xxl.job.admin.core.scheduler.MisfireStrategyEnum;
|
|
|
import com.xxl.job.admin.core.scheduler.ScheduleTypeEnum;
|
|
|
import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
|
|
|
import com.xxl.job.admin.core.trigger.TriggerTypeEnum;
|
|
|
+import com.xxl.job.admin.dao.XxlJobGroupDao;
|
|
|
+import com.xxl.job.admin.dao.XxlJobInfoDao;
|
|
|
import com.xxl.job.admin.service.XxlJobService;
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
import com.xxl.job.core.constant.CommonConstant;
|
|
@@ -25,7 +32,6 @@ import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
|
|
|
|
|
/**
|
|
|
* 暴露接口
|
|
@@ -42,17 +48,32 @@ public class CustomInfoController {
|
|
|
@Resource
|
|
|
private XxlJobService xxlJobService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private XxlJobInfoDao xxlJobInfoDao;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private XxlJobGroupDao xxlJobGroupDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
private CustomInfoHandler customInfoHandler;
|
|
|
|
|
|
+ /**
|
|
|
+ * 旧数据转移
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@RequestMapping(value = "/transfer")
|
|
|
public ReturnT<String> transfer() {
|
|
|
return customInfoHandler.transfer();
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/addOrUpdateAndStart")
|
|
|
- public ReturnT<String> addOrUpdateAndStart(@RequestBody XxlJobInfo jobInfo) {
|
|
|
- if (jobInfo.getId() == null) {
|
|
|
+ public ReturnT<String> addOrUpdateAndStart(@RequestBody @Validated XxlJobInfoValid valid) {
|
|
|
+ XxlJobInfo jobInfo = new XxlJobInfo();
|
|
|
+ BeanUtils.copyProperties(valid, jobInfo);
|
|
|
+ jobInfo.setExecutorParam(valid.getExecutorParam().toJSONString());
|
|
|
+
|
|
|
+ if (valid.getId() == null) {
|
|
|
xxlJobService.add(jobInfo);
|
|
|
} else {
|
|
|
xxlJobService.update(jobInfo);
|
|
@@ -62,38 +83,50 @@ public class CustomInfoController {
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/add")
|
|
|
- public ReturnT<String> add(@RequestBody XxlJobInfo jobInfo) {
|
|
|
+ public ReturnT<String> add(@RequestBody @Validated XxlJobInfoValid valid) {
|
|
|
+ XxlJobInfo jobInfo = new XxlJobInfo();
|
|
|
+ BeanUtils.copyProperties(valid, jobInfo);
|
|
|
+ jobInfo.setExecutorParam(valid.getExecutorParam().toJSONString());
|
|
|
return xxlJobService.add(jobInfo);
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/update")
|
|
|
- public ReturnT<String> update(@RequestBody XxlJobInfo jobInfo) {
|
|
|
+ public ReturnT<String> update(@RequestBody @Validated XxlJobInfoValid valid) {
|
|
|
+ XxlJobInfo jobInfo = new XxlJobInfo();
|
|
|
+ BeanUtils.copyProperties(valid, jobInfo);
|
|
|
+
|
|
|
+ jobInfo.setExecutorParam(valid.getExecutorParam().toJSONString());
|
|
|
return xxlJobService.update(jobInfo);
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/remove")
|
|
|
- public ReturnT<String> remove(@RequestBody XxlJobInfo jobInfo) {
|
|
|
- return xxlJobService.remove(jobInfo.getId());
|
|
|
+ public ReturnT<String> remove(@RequestBody @Validated XxlJobInfoIdValid valid) {
|
|
|
+ return xxlJobService.remove(valid.getId());
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/stop")
|
|
|
- public ReturnT<String> pause(@RequestBody XxlJobInfo jobInfo) {
|
|
|
- return xxlJobService.stop(jobInfo.getId());
|
|
|
+ public ReturnT<String> pause(@RequestBody @Validated XxlJobInfoIdValid valid) {
|
|
|
+ return xxlJobService.stop(valid.getId());
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/start")
|
|
|
- public ReturnT<String> start(@RequestBody XxlJobInfo jobInfo) {
|
|
|
- return xxlJobService.start(jobInfo.getId());
|
|
|
+ public ReturnT<String> start(@RequestBody @Validated XxlJobInfoIdValid valid) {
|
|
|
+ return xxlJobService.start(valid.getId());
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/trigger")
|
|
|
- public ReturnT<String> triggerJob(@RequestBody XxlJobInfo jobInfo) {
|
|
|
- String executorParam = jobInfo.getExecutorParam();
|
|
|
- if (StringUtil.isBlank(executorParam)) {
|
|
|
- executorParam = StringUtil.EMPTY;
|
|
|
+ public ReturnT<String> triggerJob(@RequestBody @Validated XxlJobInfoIdValid valid) {
|
|
|
+ XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(valid.getId());
|
|
|
+ if (xxlJobInfo == null || StringUtil.isBlank(xxlJobInfo.getExecutorParam())) {
|
|
|
+ throw new IllegalArgumentException("非法请求,任务参数不存在");
|
|
|
}
|
|
|
-
|
|
|
- JobTriggerPoolHelper.trigger(jobInfo.getId(), TriggerTypeEnum.MANUAL, -1, null, executorParam, jobInfo.getAddressList());
|
|
|
+
|
|
|
+ XxlJobGroup xxlJobGroup = xxlJobGroupDao.load(xxlJobInfo.getJobGroup());
|
|
|
+ if (xxlJobGroup == null) {
|
|
|
+ throw new IllegalArgumentException("非法请求,执行器不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ JobTriggerPoolHelper.trigger(xxlJobInfo.getId(), TriggerTypeEnum.MANUAL, -1, null, xxlJobInfo.getExecutorParam(), xxlJobGroup.getAddressList());
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
|