Commit 0a4f0e7b by 章家宝

feat:全量同步客户标签需要定时任务传入参数

1 parent 36b10e41
package cn.com.glsx.dj.strategy.job;
import cn.com.glsx.dj.strategy.service.CustomerTagProfileService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 客户标签画像全量同步定时任务
* 每天凌晨2点执行,从 smartcarlife 项目同步客户画像信息
* 从 smartcarlife 项目同步客户画像信息
* <p>
* 执行规则:
* - 只有参数中 isRunning = true 时才执行
* - 其他情况均跳过(用于手动触发控制)
* <p>
* 参数示例:{"isRunning": true}
*
* @version 1.0
* @since 2026/06/22
......@@ -26,6 +35,14 @@ public class CustomerTagProfileSyncJob implements SimpleJob {
@Override
public void execute(ShardingContext shardingContext) {
String jobParameter = shardingContext.getJobParameter();
// 检查参数是否允许执行
if (!isRunning(jobParameter)) {
log.info("客户标签画像全量同步任务未启用,跳过执行。如需执行,请传递参数 {\"isRunning\": true}");
return;
}
log.info("客户标签画像全量同步定时任务开始执行");
try {
CustomerTagProfileService.SyncResult result = customerTagProfileService.syncCustomerTagProfile();
......@@ -35,4 +52,23 @@ public class CustomerTagProfileSyncJob implements SimpleJob {
log.error("客户标签画像全量同步定时任务执行异常", e);
}
}
/**
* 判断是否允许执行
*
* @param jobParameter 任务参数
* @return true-允许执行,false-不允许执行
*/
private boolean isRunning(String jobParameter) {
if (StringUtils.isBlank(jobParameter)) {
return false;
}
try {
JSONObject jsonObject = JSON.parseObject(jobParameter);
return jsonObject.getBooleanValue("isRunning");
} catch (Exception e) {
log.warn("解析任务参数失败: {}", jobParameter, e);
return false;
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!