|
@@ -0,0 +1,82 @@
|
|
|
+package com.xxl.job.admin.controller;
|
|
|
+
|
|
|
+import com.xxl.job.admin.core.model.XxlJobInfo;
|
|
|
+import com.xxl.job.admin.core.util.Base64Util;
|
|
|
+import com.xxl.job.admin.service.XxlJobService;
|
|
|
+import com.xxl.job.core.biz.model.ReturnT;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: Crown
|
|
|
+ * @Date 2020/12/9 17:02
|
|
|
+ * @Version 1.1
|
|
|
+ */
|
|
|
+@Controller
|
|
|
+@RequestMapping("/longChi")
|
|
|
+public class LongChiController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private XxlJobService xxlJobService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增定时任务,并启动
|
|
|
+ *
|
|
|
+ * @param executeName 任务别名(英文)
|
|
|
+ * @param executorParam 任务执行参数
|
|
|
+ * @param cron cron
|
|
|
+ * @param author 作者
|
|
|
+ * @param jobGroupId 定时任务执行器ID
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("/only_one_add")
|
|
|
+ public ReturnT<String> onlyOneAdd(String executeName, String executorParam, String cron, String author,
|
|
|
+ int jobGroupId) {
|
|
|
+ System.err.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
|
|
+ System.err.println("定时任务开始执行!");
|
|
|
+// System.err.println("executorParam==" + executorParam);
|
|
|
+// System.err.println("cron==" + cron);
|
|
|
+// System.err.println("executeName==" + executeName);
|
|
|
+// System.err.println("author==" + author);
|
|
|
+ System.err.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
|
|
+
|
|
|
+ boolean isProgram = executeName.indexOf("program") >= 0;
|
|
|
+ executeName = executeName.substring(executeName.indexOf("_") + 1, executeName.length());
|
|
|
+ executeName = executeName.replaceAll(" ", "+");
|
|
|
+
|
|
|
+ if (isProgram) {
|
|
|
+ executeName = "【节目】" + Base64Util.decodeReplace(executeName);
|
|
|
+ } else {
|
|
|
+ executeName = "【照明策略】" + Base64Util.decodeReplace(executeName);
|
|
|
+ }
|
|
|
+
|
|
|
+ XxlJobInfo xxlJobInfo = new XxlJobInfo();
|
|
|
+ xxlJobInfo.setJobGroup(jobGroupId);
|
|
|
+ xxlJobInfo.setJobDesc(executeName);
|
|
|
+ xxlJobInfo.setExecutorRouteStrategy("FIRST");
|
|
|
+ xxlJobInfo.setJobCron(cron);
|
|
|
+ xxlJobInfo.setGlueType("BEAN");
|
|
|
+ xxlJobInfo.setExecutorHandler("executeJob");//调用本地方法运行
|
|
|
+ xxlJobInfo.setExecutorBlockStrategy("SERIAL_EXECUTION");
|
|
|
+ xxlJobInfo.setAuthor(author);
|
|
|
+ xxlJobInfo.setExecutorParam(executorParam);
|
|
|
+ xxlJobInfo.setGlueRemark("创建定时任务结束");
|
|
|
+ xxlJobInfo.setExecutorTimeout(5);
|
|
|
+ xxlJobInfo.setExecutorFailRetryCount(10); // 失败重试次数
|
|
|
+ //xxlJobInfo.setAlarmEmail();
|
|
|
+
|
|
|
+ ReturnT<String> addT = xxlJobService.add(xxlJobInfo);
|
|
|
+
|
|
|
+ xxlJobInfo.setExecutorParam(xxlJobInfo.getExecutorParam() + ",executeId:" + xxlJobInfo.getId());
|
|
|
+ addT = xxlJobService.update(xxlJobInfo);
|
|
|
+ // add SUCCESS
|
|
|
+ if (addT.getCode() == 200) {
|
|
|
+ ReturnT<String> addB = xxlJobService.start(xxlJobInfo.getId());
|
|
|
+ return addB;
|
|
|
+ }
|
|
|
+ return addT;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|