Commit 96e878b0 by 章家宝

feat:新增定时任务传参

1 parent eb7cf542
......@@ -21,6 +21,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
......@@ -175,29 +177,38 @@ public class InspectionCustomerTagService {
* 查询指定时间范围内未处理的批次,并提交客户标签分析任务
*
* @param jobParameter JSON格式参数,如:{"startDate":"2026-06-01","endDate":"2026-06-22"}
* 如果没有入参,则默认使用昨天的时间范围
* @return 处理的批次数量
*/
public int processHistoricalTags(String jobParameter) {
log.info("开始处理历史客户标签分析,参数:{}", jobParameter);
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String startTime;
String endTime;
// 解析JSON参数
String startTime = null;
String endTime = null;
if (StringUtils.isNotBlank(jobParameter)) {
try {
JSONObject jsonObject = JSONObject.parseObject(jobParameter);
startTime = jsonObject.getString("startDate");
endTime = jsonObject.getString("endDate");
String startDate = jsonObject.getString("startDate");
String endDate = jsonObject.getString("endDate");
// 开始时间从0点开始
startTime = LocalDate.parse(startDate, dateFormatter).atStartOfDay().format(dateTimeFormatter);
// 结束时间到23:59:59
endTime = LocalDate.parse(endDate, dateFormatter).atTime(23, 59, 59).format(dateTimeFormatter);
} catch (Exception e) {
log.error("解析任务参数失败:{}", jobParameter, e);
return 0;
}
}
// 检查时间范围参数
if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) {
log.warn("历史客户标签分析任务参数不完整,startDate={}, endDate={},跳过执行", startTime, endTime);
return 0;
} else {
// 没有入参,使用昨天的时间范围
LocalDate yesterday = LocalDate.now().minusDays(1);
startTime = yesterday.atStartOfDay().format(dateTimeFormatter);
endTime = yesterday.atTime(23, 59, 59).format(dateTimeFormatter);
}
log.info("历史客户标签分析时间范围:{} ~ {}", startTime, endTime);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!