jobid查询接口;
This commit is contained in:
+21
-2
@@ -58,6 +58,8 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -993,7 +995,9 @@ public class ContractManageApplicationService {
|
|||||||
public Integer addXxlJob(String shipperId) {
|
public Integer addXxlJob(String shipperId) {
|
||||||
XxlJobOpenApiUtil.JobInfoAddReq req = new XxlJobOpenApiUtil.JobInfoAddReq();
|
XxlJobOpenApiUtil.JobInfoAddReq req = new XxlJobOpenApiUtil.JobInfoAddReq();
|
||||||
req.setJobGroup(5);
|
req.setJobGroup(5);
|
||||||
req.setJobDesc("整租推送计费单据/流水任务,结算对象id:" + shipperId);
|
//生成唯一业务流水号拼接至JobDesc,保证本次新建任务的JobDesc唯一,据此查询jobId不会命中历史任务
|
||||||
|
String xxlJobBizNo = generateXxlJobBizNo();
|
||||||
|
req.setJobDesc("整租推送计费单据/流水任务,结算对象id:" + shipperId + ",业务流水号:" + xxlJobBizNo);
|
||||||
req.setAuthor("system");
|
req.setAuthor("system");
|
||||||
req.setAlarmEmail("");
|
req.setAlarmEmail("");
|
||||||
req.setScheduleType("CRON");
|
req.setScheduleType("CRON");
|
||||||
@@ -1015,7 +1019,7 @@ public class ContractManageApplicationService {
|
|||||||
if (!addOk) {
|
if (!addOk) {
|
||||||
throw new RuntimeException("创建夜间定时任务失败");
|
throw new RuntimeException("创建夜间定时任务失败");
|
||||||
}
|
}
|
||||||
Integer xxlJobId = apiUtil.queryJobIdByDescAndParam(req.getJobDesc(), shipperId);
|
Integer xxlJobId = apiUtil.queryJobIdByDescAndParam(req.getJobDesc(), shipperId,"5");
|
||||||
if (xxlJobId == null) {
|
if (xxlJobId == null) {
|
||||||
throw new RuntimeException("定时任务创建成功,但查询jobId失败");
|
throw new RuntimeException("定时任务创建成功,但查询jobId失败");
|
||||||
}
|
}
|
||||||
@@ -1030,6 +1034,21 @@ public class ContractManageApplicationService {
|
|||||||
apiUtil.pauseJob(shipperId);
|
apiUtil.pauseJob(shipperId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final DateTimeFormatter JOB_BIZ_NO_FORMATTER = DateTimeFormatter.ofPattern("yyMMddHHmmssSSS");
|
||||||
|
private static final Random RANDOM = new Random();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成xxl-job任务业务流水号:JOB + 当天yyMMddHHmmssSSS + 6位随机数字,保证每次创建的JobDesc唯一
|
||||||
|
* 示例:JOB260905102030123123456
|
||||||
|
* @return 业务流水号字符串
|
||||||
|
*/
|
||||||
|
private static String generateXxlJobBizNo() {
|
||||||
|
String dateTimeStr = LocalDateTime.now().format(JOB_BIZ_NO_FORMATTER);
|
||||||
|
int randomNum = RANDOM.nextInt(1_000_000);
|
||||||
|
String randomStr = String.format("%06d", randomNum);
|
||||||
|
return "JOB" + dateTimeStr + randomStr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改合同管理
|
* 修改合同管理
|
||||||
*/
|
*/
|
||||||
|
|||||||
+26
-7
@@ -58,19 +58,38 @@ public class XxlJobOpenApiUtil {
|
|||||||
* @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 jobGroup) {
|
||||||
// 手动拼接query参数
|
StringBuilder querySb = new StringBuilder();
|
||||||
String query = "jobGroup=&jobDesc="+cn.hutool.core.net.URLEncodeUtil.encode(jobDesc)
|
// start length必须
|
||||||
+"&executorHandler=&executorParam="+cn.hutool.core.net.URLEncodeUtil.encode(executorParam)
|
querySb.append("start=0&length=10");
|
||||||
+"&triggerStatus=-1&start=0&length=10";
|
|
||||||
|
|
||||||
String url = adminUrl + "/jobinfo/pageList?" + query;
|
// jobGroup:为空就不拼接这个参数!!不要 jobGroup=""
|
||||||
|
// 你们业务固定jobGroup=3,直接写死3,不用传空
|
||||||
|
if(StrUtil.isNotBlank(jobGroup)){
|
||||||
|
querySb.append("&jobGroup=").append(jobGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
// jobDesc
|
||||||
|
if(StrUtil.isNotBlank(jobDesc)){
|
||||||
|
querySb.append("&jobDesc=").append(cn.hutool.core.net.URLEncodeUtil.encode(jobDesc));
|
||||||
|
}
|
||||||
|
// executorParam
|
||||||
|
if(StrUtil.isNotBlank(executorParam)){
|
||||||
|
querySb.append("&executorParam=").append(cn.hutool.core.net.URLEncodeUtil.encode(executorParam));
|
||||||
|
}
|
||||||
|
// executorHandler为空,直接不携带
|
||||||
|
// triggerStatus=-1
|
||||||
|
querySb.append("&triggerStatus=-1");
|
||||||
|
|
||||||
|
String url = adminUrl + "/jobinfo/pageList?" + querySb;
|
||||||
|
log.info("[XxlJob] pageList请求url:{}",url);
|
||||||
try {
|
try {
|
||||||
HttpResponse response = HttpRequest.post(url)
|
HttpResponse response = HttpRequest.get(url)
|
||||||
.header("Authorization", cookie)
|
.header("Authorization", cookie)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
String jsonStr = response.body();
|
String jsonStr = response.body();
|
||||||
|
log.info("[XxlJob] pageList响应:{}",jsonStr);
|
||||||
if (StrUtil.isBlank(jsonStr)) {
|
if (StrUtil.isBlank(jsonStr)) {
|
||||||
log.warn("[XxlJob] pageList返回空响应");
|
log.warn("[XxlJob] pageList返回空响应");
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user