jobid查询接口;

This commit is contained in:
王奎兴
2026-09-05 18:44:25 +08:00
parent cecfe3e777
commit 3abac7b3d6
2 changed files with 23 additions and 25 deletions
@@ -59,21 +59,20 @@ public class XxlJobOpenApiUtil {
* @return jobId,查不到返回null
*/
public Integer queryJobIdByDescAndParam(String jobDesc, String executorParam) {
String url = adminUrl + "/jobinfo/pageList";
// 手动拼接query参数
String query = "jobGroup=&jobDesc="+cn.hutool.core.net.URLEncodeUtil.encode(jobDesc)
+"&executorHandler=&executorParam="+cn.hutool.core.net.URLEncodeUtil.encode(executorParam)
+"&triggerStatus=-1&start=0&length=10";
String url = adminUrl + "/jobinfo/pageList?" + query;
try {
HttpResponse response = HttpRequest.post(url)
.header("Cookie", cookie)
.form("jobGroup", "")
.form("jobDesc", jobDesc)
.form("executorHandler", "")
.form("executorParam", executorParam)
.form("triggerStatus", "-1")
.form("start", 0)
.form("length", 10)
.header("Authorization", cookie)
.execute();
String jsonStr = response.body();
if (StrUtil.isBlank(jsonStr)) {
log.warn("[XxlJob] pageList返回空响应");
return null;
}
JSONObject jsonObj = JSON.parseObject(jsonStr);
@@ -85,7 +84,6 @@ public class XxlJobOpenApiUtil {
if (dataList == null || dataList.isEmpty()) {
return null;
}
// 精确匹配jobDesc和executorParam,返回第一条id
for (JobPageItem item : dataList) {
if (StrUtil.equals(item.jobDesc, jobDesc) && StrUtil.equals(item.executorParam, executorParam)) {
return item.id;
@@ -38,7 +38,7 @@ public class XxlJobOpenApiUtil {
try {
Map<String, Object> formMap = BeanUtil.beanToMap(addReq);
HttpResponse response = HttpRequest.post(url)
.header("Cookie", cookie)
.header("Authorization", cookie)
.form(formMap)
.execute();
int status = response.getStatus();
@@ -52,28 +52,27 @@ public class XxlJobOpenApiUtil {
}
/**
* 根据【任务描述+执行器参数】查询jobId
* 根据【执行器组+任务描述+执行器参数】查询jobId
* 适配返回JSON格式的pageList接口
* @param jobDesc 任务描述
* @param executorParam 任务参数(业务shipperId)
* @return jobId,查不到返回null
*/
public Integer queryJobIdByDescAndParam(String jobDesc, String executorParam) {
String url = adminUrl + "/jobinfo/pageList";
// 手动拼接query参数
String query = "jobGroup=&jobDesc="+cn.hutool.core.net.URLEncodeUtil.encode(jobDesc)
+"&executorHandler=&executorParam="+cn.hutool.core.net.URLEncodeUtil.encode(executorParam)
+"&triggerStatus=-1&start=0&length=10";
String url = adminUrl + "/jobinfo/pageList?" + query;
try {
HttpResponse response = HttpRequest.post(url)
.header("Cookie", cookie)
.form("jobGroup", "")
.form("jobDesc", jobDesc)
.form("executorHandler", "")
.form("executorParam", executorParam)
.form("triggerStatus", "-1")
.form("start", 0)
.form("length", 10)
.header("Authorization", cookie)
.execute();
String jsonStr = response.body();
if (StrUtil.isBlank(jsonStr)) {
log.warn("[XxlJob] pageList返回空响应");
return null;
}
JSONObject jsonObj = JSON.parseObject(jsonStr);
@@ -85,7 +84,6 @@ public class XxlJobOpenApiUtil {
if (dataList == null || dataList.isEmpty()) {
return null;
}
// 精确匹配jobDesc和executorParam,返回第一条id
for (JobPageItem item : dataList) {
if (StrUtil.equals(item.jobDesc, jobDesc) && StrUtil.equals(item.executorParam, executorParam)) {
return item.id;
@@ -99,6 +97,8 @@ public class XxlJobOpenApiUtil {
}
/**
* 暂停任务 POST /jobinfo/pause
* @param jobId xxl任务id
@@ -111,7 +111,7 @@ public class XxlJobOpenApiUtil {
String url = adminUrl + "/jobinfo/pause";
try {
HttpResponse response = HttpRequest.post(url)
.header("Cookie", cookie)
.header("Authorization", cookie)
.form("id", jobId)
.execute();
return response.getStatus() == 302;
@@ -133,7 +133,7 @@ public class XxlJobOpenApiUtil {
String url = adminUrl + "/jobinfo/start";
try {
HttpResponse response = HttpRequest.post(url)
.header("Cookie", cookie)
.header("Authorization", cookie)
.form("id", jobId)
.execute();
return response.getStatus() == 302;
@@ -155,7 +155,7 @@ public class XxlJobOpenApiUtil {
String url = adminUrl + "/jobinfo/remove";
try {
HttpResponse response = HttpRequest.post(url)
.header("Cookie", cookie)
.header("Authorization", cookie)
.form("id", jobId)
.execute();
return response.getStatus() == 302;