1.编辑GLUE(Java)模式的定时任务
这里以传递json参数为例:
修改任务参数:{"startDate": "","endDate": "","desc": "入参日期格式:yyyyMMdd"}
保存。
2.编辑此定时任务的GLUE脚本
import添加:
import com.xxl.job.core.context.XxlJobHelper;
import cn.hutool.core.util.StrUtil;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
excute()方法里接收参数:
String jobParam = XxlJobHelper.getJobParam();
XxlJobHelper.log("自定义入参:"+jobParam);
String startDateStr = null;
String endDayStr = null;
if(!StrUtil.isEmptyIfStr(jobParam)){
JSONObject jsonObject = new JSONObject(jobParam);
startDayStr = jsonObject.getStr("startDate");
endDayStr = jsonObject.getStr("endDate");
}
if(StrUtil.isEmptyIfStr(startDateStr) || StrUtil.isEmptyIfStr(endDateStr)){
LocalDate todayDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMMdd");
startDateStr = todayDate.minusDays(2).format(formatter);
endDateStr = todayDate.format(formatter);
}
...省略
标签:传参,startDateStr,java,todayDate,StrUtil,---,jobParam,import
From: https://www.cnblogs.com/hujunwei/p/18657374