Commit 17871725 by 章家宝

feat:新增定时任务传参

1 parent 323670b1
...@@ -4,10 +4,8 @@ import cn.com.glsx.dj.mindworkplate.service.InspectionCustomerTagService; ...@@ -4,10 +4,8 @@ import cn.com.glsx.dj.mindworkplate.service.InspectionCustomerTagService;
import com.dangdang.ddframe.job.api.ShardingContext; import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob; import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf; import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
/** /**
* 历史客户标签分析定时任务 * 历史客户标签分析定时任务
...@@ -18,36 +16,18 @@ import org.springframework.core.env.Environment; ...@@ -18,36 +16,18 @@ import org.springframework.core.env.Environment;
public class HistoricalCustomerTagJob implements SimpleJob { public class HistoricalCustomerTagJob implements SimpleJob {
@Autowired @Autowired
private Environment environment;
@Autowired
private InspectionCustomerTagService inspectionCustomerTagService; private InspectionCustomerTagService inspectionCustomerTagService;
@Override @Override
public void execute(ShardingContext shardingContext) { public void execute(ShardingContext shardingContext) {
log.info("----------历史客户标签分析任务开始----------"); log.info("----------历史客户标签分析任务开始----------");
// 读取配置参数
String enabled = environment.getProperty("historical.customer.tag.job.enabled");
String startTime = environment.getProperty("historical.customer.tag.job.startTime");
String endTime = environment.getProperty("historical.customer.tag.job.endTime");
// 检查是否启用
if (!"true".equalsIgnoreCase(enabled)) {
log.info("历史客户标签分析任务未启用,跳过执行。配置项:historical.customer.tag.job.enabled={}", enabled);
return;
}
// 检查时间范围参数
if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) {
log.warn("历史客户标签分析任务配置不完整,startTime={}, endTime={},跳过执行", startTime, endTime);
return;
}
log.info("历史客户标签分析任务配置:startTime={}, endTime={}", startTime, endTime);
try { try {
int processedCount = inspectionCustomerTagService.processHistoricalTags(startTime, endTime); // 自定义参数如:指定开始、截止日期范围{"startDate":"2026-06-01","endDate":"2026-06-22"}
String jobParameter = shardingContext.getJobParameter();
log.info("历史客户标签分析任务参数:{}", jobParameter);
int processedCount = inspectionCustomerTagService.processHistoricalTags(jobParameter);
log.info("----------历史客户标签分析任务结束,处理批次数量:{}----------", processedCount); log.info("----------历史客户标签分析任务结束,处理批次数量:{}----------", processedCount);
} catch (Exception e) { } catch (Exception e) {
log.error("历史客户标签分析任务执行异常", e); log.error("历史客户标签分析任务执行异常", e);
......
...@@ -11,9 +11,11 @@ import cn.com.glsx.dj.mindworkplate.model.ConversationDetail; ...@@ -11,9 +11,11 @@ import cn.com.glsx.dj.mindworkplate.model.ConversationDetail;
import cn.com.glsx.dj.mindworkplate.model.InspectionCustomerTag; import cn.com.glsx.dj.mindworkplate.model.InspectionCustomerTag;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination; import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.scrm.equity.enums.DeleteFlagEnum; import cn.com.glsx.scrm.equity.enums.DeleteFlagEnum;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -172,12 +174,33 @@ public class InspectionCustomerTagService { ...@@ -172,12 +174,33 @@ public class InspectionCustomerTagService {
* 处理历史客户标签分析 * 处理历史客户标签分析
* 查询指定时间范围内未处理的批次,并提交客户标签分析任务 * 查询指定时间范围内未处理的批次,并提交客户标签分析任务
* *
* @param startTime 开始时间(格式:yyyy-MM-dd HH:mm:ss) * @param jobParameter JSON格式参数,如:{"startDate":"2026-06-01","endDate":"2026-06-22"}
* @param endTime 结束时间(格式:yyyy-MM-dd HH:mm:ss)
* @return 处理的批次数量 * @return 处理的批次数量
*/ */
public int processHistoricalTags(String startTime, String endTime) { public int processHistoricalTags(String jobParameter) {
log.info("开始处理历史客户标签分析,时间范围:{} ~ {}", startTime, endTime); log.info("开始处理历史客户标签分析,参数:{}", jobParameter);
// 解析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");
} catch (Exception e) {
log.error("解析任务参数失败:{}", jobParameter, e);
return 0;
}
}
// 检查时间范围参数
if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) {
log.warn("历史客户标签分析任务参数不完整,startDate={}, endDate={},跳过执行", startTime, endTime);
return 0;
}
log.info("历史客户标签分析时间范围:{} ~ {}", startTime, endTime);
// 查询未处理的批次 // 查询未处理的批次
List<ConversationBatch> unprocessedBatches = inspectionCustomerTagMapper.findUnprocessedBatchesByTimeRange(startTime, endTime); List<ConversationBatch> unprocessedBatches = inspectionCustomerTagMapper.findUnprocessedBatchesByTimeRange(startTime, endTime);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!