Browse Source

调整定时任务

wangq 4 years ago
parent
commit
aaded86699

+ 0 - 57
xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java

@@ -108,63 +108,6 @@ public class JobInfoController {
         return xxlJobService.add(jobInfo);
     }
 
-    /**
-     * 新增定时任务,并启动
-     *
-     * @param executeName   任务别名(英文)
-     * @param executorParam 任务执行参数
-     * @param cron          cron
-     * @param author        作者
-     * @param jobGroupId    定时任务执行器ID
-     * @return
-     */
-    //@GetMapping("/onlyoneadd")
-    @RequestMapping("/onlyoneadd")
-    public ReturnT<String> onlyOneAdd(String executeName, String executorParam, String cron, String author,
-                                      int jobGroupId) {
-//        System.err.println("executorParam==" + executorParam);
-//        System.err.println("cron==" + cron);
-//        System.err.println("executeName==" + executeName);
-//        System.err.println("author==" + author);
-        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 = update(xxlJobInfo);
-        // add SUCCESS
-        if (addT.getCode() == 200) {
-            ReturnT<String> addB = xxlJobService.start(xxlJobInfo.getId());
-            return addB;
-        }
-        return addT;
-    }
-
-
     @RequestMapping("/update")
     @ResponseBody
     public ReturnT<String> update(XxlJobInfo jobInfo) {

+ 82 - 0
xxl-job-admin/src/main/java/com/xxl/job/admin/controller/LongChiController.java

@@ -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;
+    }
+
+}

+ 6 - 2
xxl-job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/WebMvcConfig.java

@@ -21,8 +21,12 @@ public class WebMvcConfig implements WebMvcConfigurer {
 
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
-        registry.addInterceptor(permissionInterceptor).addPathPatterns("/**");
-        registry.addInterceptor(cookieInterceptor).addPathPatterns("/**");
+        registry.addInterceptor(permissionInterceptor).addPathPatterns("/**")
+                .excludePathPatterns("/longChi/**")
+        ;
+        registry.addInterceptor(cookieInterceptor).addPathPatterns("/**")
+                .excludePathPatterns("/longChi/**")
+        ;
     }
 
 }