Commit b4ae70f9 by 潘诗林

fix:计算客户分类任务支持传参

1 parent 86ce670f
...@@ -4,33 +4,52 @@ import cn.com.glsx.dj.smartcarlife.service.CustomerInfoService; ...@@ -4,33 +4,52 @@ import cn.com.glsx.dj.smartcarlife.service.CustomerInfoService;
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 java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/** /**
* 客户分类每日刷新任务 * 客户分类刷新任务
* <p> * <p>
* 每天凌晨5点执行, 查询昨天有标签变动的客户, 重新计算客户分类(A/B/C)并更新到 customer_info 表 * 每天凌晨5点执行, 查询指定日期有标签变动的客户, 重新计算客户分类(A/B/C)并更新到 customer_info 表。
* <br>
* 支持传参: 传入日期 yyyy-MM-dd 查询该日期的变动数据, 不传则默认昨天。
* *
* @author yangwei_by_claude * @author yangwei_by_claude
* @version 1.0 * @version 1.0
* @since 2026/06/24 * @since 2026/06/24
*/ */
@Slf4j @Slf4j
@ElasticJobConf(name = "CustomerClassRefreshJob", cron = "0 0 5 * * ?", description = "客户分类每日刷新任务", overwrite = false) @ElasticJobConf(name = "CustomerClassRefreshJob", cron = "0 0 5 * * ?", description = "客户分类刷新任务", overwrite = false)
public class CustomerClassRefreshJob implements SimpleJob { public class CustomerClassRefreshJob implements SimpleJob {
@Autowired @Autowired
private CustomerInfoService customerInfoService; private CustomerInfoService customerInfoService;
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@Override @Override
public void execute(ShardingContext shardingContext) { public void execute(ShardingContext shardingContext) {
log.info("----------------客户分类每日刷新任务开始-----------------"); String date = resolveDate(shardingContext.getJobParameter());
log.info("----------------客户分类刷新任务开始, date={}-----------------", date);
try { try {
customerInfoService.refreshCustomerClassDaily(); customerInfoService.refreshCustomerClassDaily(date);
} catch (Exception e) { } catch (Exception e) {
log.error("客户分类每日刷新任务异常", e); log.error("客户分类刷新任务异常, date={}", date, e);
}
log.info("----------------客户分类刷新任务结束, date={}-----------------", date);
}
/**
* 解析日期参数: 有传参则使用, 否则默认昨天
*/
private String resolveDate(String jobParameter) {
if (StringUtils.isNotBlank(jobParameter)) {
return jobParameter.trim();
} }
log.info("----------------客户分类每日刷新任务结束-----------------"); return LocalDate.now().minusDays(1).format(FORMATTER);
} }
} }
...@@ -482,14 +482,14 @@ public class CustomerInfoService { ...@@ -482,14 +482,14 @@ public class CustomerInfoService {
* 3. 逐个计算客户分类 (A/B/C) * 3. 逐个计算客户分类 (A/B/C)
* 4. 批量更新 dj_car_life_customer_info.customer_class * 4. 批量更新 dj_car_life_customer_info.customer_class
*/ */
public void refreshCustomerClassDaily() { public void refreshCustomerClassDaily(String date) {
logger.info("每日刷新客户分类开始"); logger.info("刷新客户分类开始, date={}", date);
// 1. 合并查询昨天有变动的标签画像(含名称,一次RPC) // 1. 合并查询昨天有变动的标签画像(含名称,一次RPC)
RpcResponse<List<CustomerProfileRespDTO>> profileResp = RpcResponse<List<CustomerProfileRespDTO>> profileResp =
customerTagService.queryYesterdayChangedProfiles(); customerTagService.queryYesterdayChangedProfiles(date);
if (!profileResp.hasResult() || CollectionUtils.isEmpty(profileResp.getResult())) { if (!profileResp.hasResult() || CollectionUtils.isEmpty(profileResp.getResult())) {
logger.info("昨天无标签变动, 跳过刷新"); logger.info("{} 无标签变动, 跳过刷新", date);
return; return;
} }
List<CustomerProfileRespDTO> allProfiles = profileResp.getResult(); List<CustomerProfileRespDTO> allProfiles = profileResp.getResult();
...@@ -499,7 +499,7 @@ public class CustomerInfoService { ...@@ -499,7 +499,7 @@ public class CustomerInfoService {
.collect(Collectors.groupingBy(CustomerProfileRespDTO::getPhone)); .collect(Collectors.groupingBy(CustomerProfileRespDTO::getPhone));
List<String> changedPhones = new ArrayList<>(tagMap.keySet()); List<String> changedPhones = new ArrayList<>(tagMap.keySet());
logger.info("昨天有标签变动的手机号数量: {}", changedPhones.size()); logger.info("{} 有标签变动的手机号数量: {}", date, changedPhones.size());
// 3. 逐个计算并更新 // 3. 逐个计算并更新
int updatedCount = 0; int updatedCount = 0;
......
...@@ -58,8 +58,8 @@ public class CustomerTagService { ...@@ -58,8 +58,8 @@ public class CustomerTagService {
/** /**
* 查询昨天有变动的标签画像(含名称,合并查询) * 查询昨天有变动的标签画像(含名称,合并查询)
*/ */
public RpcResponse<List<CustomerProfileRespDTO>> queryYesterdayChangedProfiles() { public RpcResponse<List<CustomerProfileRespDTO>> queryYesterdayChangedProfiles(String date) {
return customerTagProfileRemote.queryYesterdayChangedProfiles(); return customerTagProfileRemote.queryYesterdayChangedProfiles(date);
} }
/** AI打标来源 */ /** AI打标来源 */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!