jobid查询接口;
This commit is contained in:
+8
-10
@@ -59,21 +59,20 @@ public class XxlJobOpenApiUtil {
|
|||||||
* @return jobId,查不到返回null
|
* @return jobId,查不到返回null
|
||||||
*/
|
*/
|
||||||
public Integer queryJobIdByDescAndParam(String jobDesc, String executorParam) {
|
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 {
|
try {
|
||||||
HttpResponse response = HttpRequest.post(url)
|
HttpResponse response = HttpRequest.post(url)
|
||||||
.header("Cookie", cookie)
|
.header("Authorization", cookie)
|
||||||
.form("jobGroup", "")
|
|
||||||
.form("jobDesc", jobDesc)
|
|
||||||
.form("executorHandler", "")
|
|
||||||
.form("executorParam", executorParam)
|
|
||||||
.form("triggerStatus", "-1")
|
|
||||||
.form("start", 0)
|
|
||||||
.form("length", 10)
|
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
String jsonStr = response.body();
|
String jsonStr = response.body();
|
||||||
if (StrUtil.isBlank(jsonStr)) {
|
if (StrUtil.isBlank(jsonStr)) {
|
||||||
|
log.warn("[XxlJob] pageList返回空响应");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JSONObject jsonObj = JSON.parseObject(jsonStr);
|
JSONObject jsonObj = JSON.parseObject(jsonStr);
|
||||||
@@ -85,7 +84,6 @@ public class XxlJobOpenApiUtil {
|
|||||||
if (dataList == null || dataList.isEmpty()) {
|
if (dataList == null || dataList.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 精确匹配jobDesc和executorParam,返回第一条id
|
|
||||||
for (JobPageItem item : dataList) {
|
for (JobPageItem item : dataList) {
|
||||||
if (StrUtil.equals(item.jobDesc, jobDesc) && StrUtil.equals(item.executorParam, executorParam)) {
|
if (StrUtil.equals(item.jobDesc, jobDesc) && StrUtil.equals(item.executorParam, executorParam)) {
|
||||||
return item.id;
|
return item.id;
|
||||||
|
|||||||
+15
-15
@@ -38,7 +38,7 @@ public class XxlJobOpenApiUtil {
|
|||||||
try {
|
try {
|
||||||
Map<String, Object> formMap = BeanUtil.beanToMap(addReq);
|
Map<String, Object> formMap = BeanUtil.beanToMap(addReq);
|
||||||
HttpResponse response = HttpRequest.post(url)
|
HttpResponse response = HttpRequest.post(url)
|
||||||
.header("Cookie", cookie)
|
.header("Authorization", cookie)
|
||||||
.form(formMap)
|
.form(formMap)
|
||||||
.execute();
|
.execute();
|
||||||
int status = response.getStatus();
|
int status = response.getStatus();
|
||||||
@@ -52,28 +52,27 @@ public class XxlJobOpenApiUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据【任务描述+执行器参数】查询jobId
|
* 根据【执行器组+任务描述+执行器参数】查询jobId
|
||||||
* 适配返回JSON格式的pageList接口
|
* 适配返回JSON格式的pageList接口
|
||||||
* @param jobDesc 任务描述
|
* @param jobDesc 任务描述
|
||||||
* @param executorParam 任务参数(业务shipperId)
|
* @param executorParam 任务参数(业务shipperId)
|
||||||
* @return jobId,查不到返回null
|
* @return jobId,查不到返回null
|
||||||
*/
|
*/
|
||||||
public Integer queryJobIdByDescAndParam(String jobDesc, String executorParam) {
|
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 {
|
try {
|
||||||
HttpResponse response = HttpRequest.post(url)
|
HttpResponse response = HttpRequest.post(url)
|
||||||
.header("Cookie", cookie)
|
.header("Authorization", cookie)
|
||||||
.form("jobGroup", "")
|
|
||||||
.form("jobDesc", jobDesc)
|
|
||||||
.form("executorHandler", "")
|
|
||||||
.form("executorParam", executorParam)
|
|
||||||
.form("triggerStatus", "-1")
|
|
||||||
.form("start", 0)
|
|
||||||
.form("length", 10)
|
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
String jsonStr = response.body();
|
String jsonStr = response.body();
|
||||||
if (StrUtil.isBlank(jsonStr)) {
|
if (StrUtil.isBlank(jsonStr)) {
|
||||||
|
log.warn("[XxlJob] pageList返回空响应");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JSONObject jsonObj = JSON.parseObject(jsonStr);
|
JSONObject jsonObj = JSON.parseObject(jsonStr);
|
||||||
@@ -85,7 +84,6 @@ public class XxlJobOpenApiUtil {
|
|||||||
if (dataList == null || dataList.isEmpty()) {
|
if (dataList == null || dataList.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 精确匹配jobDesc和executorParam,返回第一条id
|
|
||||||
for (JobPageItem item : dataList) {
|
for (JobPageItem item : dataList) {
|
||||||
if (StrUtil.equals(item.jobDesc, jobDesc) && StrUtil.equals(item.executorParam, executorParam)) {
|
if (StrUtil.equals(item.jobDesc, jobDesc) && StrUtil.equals(item.executorParam, executorParam)) {
|
||||||
return item.id;
|
return item.id;
|
||||||
@@ -99,6 +97,8 @@ public class XxlJobOpenApiUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 暂停任务 POST /jobinfo/pause
|
* 暂停任务 POST /jobinfo/pause
|
||||||
* @param jobId xxl任务id
|
* @param jobId xxl任务id
|
||||||
@@ -111,7 +111,7 @@ public class XxlJobOpenApiUtil {
|
|||||||
String url = adminUrl + "/jobinfo/pause";
|
String url = adminUrl + "/jobinfo/pause";
|
||||||
try {
|
try {
|
||||||
HttpResponse response = HttpRequest.post(url)
|
HttpResponse response = HttpRequest.post(url)
|
||||||
.header("Cookie", cookie)
|
.header("Authorization", cookie)
|
||||||
.form("id", jobId)
|
.form("id", jobId)
|
||||||
.execute();
|
.execute();
|
||||||
return response.getStatus() == 302;
|
return response.getStatus() == 302;
|
||||||
@@ -133,7 +133,7 @@ public class XxlJobOpenApiUtil {
|
|||||||
String url = adminUrl + "/jobinfo/start";
|
String url = adminUrl + "/jobinfo/start";
|
||||||
try {
|
try {
|
||||||
HttpResponse response = HttpRequest.post(url)
|
HttpResponse response = HttpRequest.post(url)
|
||||||
.header("Cookie", cookie)
|
.header("Authorization", cookie)
|
||||||
.form("id", jobId)
|
.form("id", jobId)
|
||||||
.execute();
|
.execute();
|
||||||
return response.getStatus() == 302;
|
return response.getStatus() == 302;
|
||||||
@@ -155,7 +155,7 @@ public class XxlJobOpenApiUtil {
|
|||||||
String url = adminUrl + "/jobinfo/remove";
|
String url = adminUrl + "/jobinfo/remove";
|
||||||
try {
|
try {
|
||||||
HttpResponse response = HttpRequest.post(url)
|
HttpResponse response = HttpRequest.post(url)
|
||||||
.header("Cookie", cookie)
|
.header("Authorization", cookie)
|
||||||
.form("id", jobId)
|
.form("id", jobId)
|
||||||
.execute();
|
.execute();
|
||||||
return response.getStatus() == 302;
|
return response.getStatus() == 302;
|
||||||
|
|||||||
Reference in New Issue
Block a user