8 changed files with 129 additions and 10 deletions
Unified View
Diff Options
-
2src/main/java/com/qniao/zsh/api/command/paddle/admin/PaddleAdminCommandController.java
-
14src/main/java/com/qniao/zsh/api/command/xxljob/admin/XxlJobAdminCommandController.java
-
7src/main/java/com/qniao/zsh/application/service/createspider/CreateSpiderApplicationService.java
-
4src/main/java/com/qniao/zsh/application/service/paddle/PaddleApplicationService.java
-
91src/main/java/com/qniao/zsh/application/service/xxljob/XxlJobApplicationService.java
-
12src/main/java/com/qniao/zsh/infrastructure/util/LinuxCommandUtil.java
-
7src/main/java/com/qniao/zsh/infrastructure/util/xxl/XxlJobDemo.java
-
2src/main/resources/application-local.yml
@ -0,0 +1,14 @@ |
|||||
|
package com.qniao.zsh.api.command.xxljob.admin; |
||||
|
|
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
/** |
||||
|
* @author wh |
||||
|
* @date 2023/4/23 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("admin/xxl-job") |
||||
|
public class XxlJobAdminCommandController { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,91 @@ |
|||||
|
package com.qniao.zsh.application.service.xxljob; |
||||
|
|
||||
|
import cn.hutool.http.HttpRequest; |
||||
|
import cn.hutool.http.HttpResponse; |
||||
|
import cn.hutool.http.HttpStatus; |
||||
|
import cn.hutool.json.JSONObject; |
||||
|
import cn.hutool.json.JSONUtil; |
||||
|
import com.qniao.zsh.infrastructure.config.LoginRequestConfig; |
||||
|
import com.xxl.job.core.biz.AdminBiz; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @author wh |
||||
|
* @date 2023/4/23 |
||||
|
*/ |
||||
|
|
||||
|
@Service |
||||
|
public class XxlJobApplicationService { |
||||
|
public int login() { |
||||
|
Map<String, Object> paramMap = new HashMap<>(2); |
||||
|
paramMap.put("userName", "admin"); |
||||
|
paramMap.put("password", "123456"); |
||||
|
paramMap.put("ifRemember", "on"); |
||||
|
HttpResponse response = HttpRequest.post("http://localhost:8080/xxl-job-admin/login/") |
||||
|
.form(paramMap) |
||||
|
.timeout(20000) |
||||
|
.execute(); |
||||
|
|
||||
|
|
||||
|
String body = response.body(); |
||||
|
JSONObject jsonInfo = JSONUtil.parseObj(body); |
||||
|
|
||||
|
return Integer.parseInt(jsonInfo.getStr("code")); |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
public int add(String jobDesc) { |
||||
|
login(); |
||||
|
String cron = "* 0/15 * * * ?"; |
||||
|
Map<String, Object> paramMap = new HashMap<>(2); |
||||
|
paramMap.put("jobGroup", 2); |
||||
|
paramMap.put("jobDesc", jobDesc); |
||||
|
paramMap.put("author", "wh"); |
||||
|
paramMap.put("scheduleType", "CRON"); |
||||
|
paramMap.put("scheduleConf", cron); |
||||
|
paramMap.put("misfireStrategy", "DO_NOTHING"); |
||||
|
paramMap.put("executorRouteStrategy", "FIRST"); |
||||
|
paramMap.put("executorHandler", "spiderTest"); |
||||
|
paramMap.put("executorBlockStrategy", "SERIAL_EXECUTION"); |
||||
|
paramMap.put("glueType", "BEAN"); |
||||
|
HttpResponse response = HttpRequest.post("http://localhost:8080/xxl-job-admin/jobinfo/add") |
||||
|
.form(paramMap) |
||||
|
.timeout(20000) |
||||
|
.execute(); |
||||
|
String body = response.body(); |
||||
|
JSONObject jsonInfo = JSONUtil.parseObj(body); |
||||
|
|
||||
|
return Integer.parseInt(jsonInfo.getStr("code")); |
||||
|
} |
||||
|
|
||||
|
public int update(String jobDesc) { |
||||
|
login(); |
||||
|
String cron = "* 0/20 * * * ?"; |
||||
|
Map<String, Object> paramMap = new HashMap<>(2); |
||||
|
paramMap.put("jobGroup", 2); |
||||
|
paramMap.put("jobDesc", jobDesc); |
||||
|
paramMap.put("author", "wh"); |
||||
|
paramMap.put("scheduleType", "CRON"); |
||||
|
paramMap.put("scheduleConf", cron); |
||||
|
paramMap.put("misfireStrategy", "DO_NOTHING"); |
||||
|
paramMap.put("executorRouteStrategy", "FIRST"); |
||||
|
paramMap.put("executorHandler", "spiderTest"); |
||||
|
paramMap.put("executorBlockStrategy", "SERIAL_EXECUTION"); |
||||
|
paramMap.put("glueType", "BEAN"); |
||||
|
HttpResponse response = HttpRequest.post("http://localhost:8080/xxl-job-admin/jobinfo/add") |
||||
|
.form(paramMap) |
||||
|
.timeout(20000) |
||||
|
.execute(); |
||||
|
String body = response.body(); |
||||
|
JSONObject jsonInfo = JSONUtil.parseObj(body); |
||||
|
|
||||
|
return Integer.parseInt(jsonInfo.getStr("code")); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save