Commit a2daee72 by 叶立庆

Merge branch 'v5.8.3' into 'master'

上线合并

See merge request !41
2 parents 0d46dbee fd50d451
...@@ -137,4 +137,15 @@ public interface CustomerInfoRemote { ...@@ -137,4 +137,15 @@ public interface CustomerInfoRemote {
dataType=ApiParam.DataTypeEnum.INTEGER, required=true) dataType=ApiParam.DataTypeEnum.INTEGER, required=true)
@ApiResponse("群关联信息") @ApiResponse("群关联信息")
RpcResponse<GroupAssociationRespDTO> queryGroupAssociation(@NotNull Integer customerId); RpcResponse<GroupAssociationRespDTO> queryGroupAssociation(@NotNull Integer customerId);
/**
* 批量更新客户分类
*
* @param list 客户分类更新列表
* @return 更新结果
*/
@ApiMethod("批量更新客户分类")
@ApiParam(name="list", notes="客户分类更新列表", dataType=ApiParam.DataTypeEnum.OBJECT, required=true)
@ApiResponse("更新结果")
RpcResponse<Boolean> batchUpdateCustomerClass(List<CustomerInfoDTO> list);
} }
package cn.com.glsx.dj.smartcarlife.job;
import cn.com.glsx.dj.smartcarlife.service.CustomerInfoService;
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 java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* 客户分类刷新任务
* <p>
* 每天凌晨5点执行, 查询指定日期有标签变动的客户, 重新计算客户分类(A/B/C)并更新到 customer_info 表。
* <br>
* 支持传参: 传入日期 yyyy-MM-dd 查询该日期的变动数据, 不传则默认昨天。
*
* @author yangwei_by_claude
* @version 1.0
* @since 2026/06/24
*/
@Slf4j
@ElasticJobConf(name = "CustomerClassRefreshJob", cron = "0 0 5 * * ?", description = "客户分类刷新任务", overwrite = false)
public class CustomerClassRefreshJob implements SimpleJob {
@Autowired
private CustomerInfoService customerInfoService;
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@Override
public void execute(ShardingContext shardingContext) {
String date = resolveDate(shardingContext.getJobParameter());
log.info("----------------客户分类刷新任务开始, date={}-----------------", date);
try {
customerInfoService.refreshCustomerClassDaily(date);
} catch (Exception e) {
log.error("客户分类刷新任务异常, date={}", date, e);
}
log.info("----------------客户分类刷新任务结束, date={}-----------------", date);
}
/**
* 解析日期参数: 有传参则使用, 否则默认昨天
*/
private String resolveDate(String jobParameter) {
if (StringUtils.isNotBlank(jobParameter)) {
return jobParameter.trim();
}
return LocalDate.now().minusDays(1).format(FORMATTER);
}
}
...@@ -33,9 +33,9 @@ public interface CustomerInfoMapper extends OreMapper<CustomerInfo> { ...@@ -33,9 +33,9 @@ public interface CustomerInfoMapper extends OreMapper<CustomerInfo> {
List<CustomerProfileInfoDTO> pageCustomerProfileInfo(CustomerProfileInfoDTO dto); List<CustomerProfileInfoDTO> pageCustomerProfileInfo(CustomerProfileInfoDTO dto);
/** /**
* 根据手机号批量更新客户分类 (A/B/C) * 批量更新客户分类 (A/B/C)
*/ */
int batchUpdateCustomerClass(@Param("phone") String phone, @Param("customerClass") String customerClass); int batchUpdateCustomerClass(@Param("list") List<CustomerInfoDTO> list);
/** /**
* 分页查询客户简要信息 - 仅返回id、车系、手机号 * 分页查询客户简要信息 - 仅返回id、车系、手机号
......
...@@ -174,4 +174,15 @@ public class CustomerInfoRemoteImpl implements CustomerInfoRemote{ ...@@ -174,4 +174,15 @@ public class CustomerInfoRemoteImpl implements CustomerInfoRemote{
return RpcResponse.error(e); return RpcResponse.error(e);
} }
} }
@Override
public RpcResponse<Boolean> batchUpdateCustomerClass(List<CustomerInfoDTO> list) {
try {
customerInfoService.batchUpdateCustomerClass(list);
return RpcResponse.success(true);
} catch (RpcServiceException e) {
logger.error(e.getMessage(), e);
return RpcResponse.error(e);
}
}
} }
...@@ -472,52 +472,11 @@ public class CustomerInfoService { ...@@ -472,52 +472,11 @@ public class CustomerInfoService {
return resp; return resp;
} }
// ========== 定时任务: 每日刷新客户分类 ========== public void batchUpdateCustomerClass(List<CustomerInfoDTO> list) {
if(CollectionUtils.isEmpty(list)){
/** log.info("batchUpdateCustomerClass--更新集合为空");
* 每日刷新客户分类 (由定时任务调用)
* <p>
* 1. 查询昨天有标签变动的手机号
* 2. 按手机号批量查询标签画像 + 录音检测结果
* 3. 逐个计算客户分类 (A/B/C)
* 4. 批量更新 dj_car_life_customer_info.customer_class
*/
public void refreshCustomerClassDaily(String date) {
logger.info("刷新客户分类开始, date={}", date);
// 1. 合并查询昨天有变动的标签画像(含名称,一次RPC)
RpcResponse<List<CustomerProfileRespDTO>> profileResp =
customerTagService.queryYesterdayChangedProfiles(date);
if (!profileResp.hasResult() || CollectionUtils.isEmpty(profileResp.getResult())) {
logger.info("{} 无标签变动, 跳过刷新", date);
return; return;
} }
List<CustomerProfileRespDTO> allProfiles = profileResp.getResult(); customerInfoMapper.batchUpdateCustomerClass(list);
}
// 按手机号分组
Map<String, List<CustomerProfileRespDTO>> tagMap = allProfiles.stream()
.collect(Collectors.groupingBy(CustomerProfileRespDTO::getPhone));
List<String> changedPhones = new ArrayList<>(tagMap.keySet());
logger.info("{} 有标签变动的手机号数量: {}", date, changedPhones.size());
// 3. 逐个计算并更新
int updatedCount = 0;
for (String phone : changedPhones) {
List<CustomerProfileRespDTO> profiles =
tagMap.getOrDefault(phone, Collections.emptyList());
String customerClass = customerTagService.calcCustomerClass(profiles);
try {
customerInfoMapper.batchUpdateCustomerClass(phone, customerClass);
updatedCount++;
} catch (Exception e) {
logger.error("更新客户分类失败: phone={}", phone, e);
}
}
logger.info("每日刷新客户分类完成, 更新数量: {}", updatedCount);
}
} }
...@@ -296,11 +296,22 @@ ...@@ -296,11 +296,22 @@
</where> </where>
</update> </update>
<!-- 根据手机号批量更新客户分类 --> <!-- 批量更新客户分类 -->
<update id="batchUpdateCustomerClass"> <update id="batchUpdateCustomerClass">
UPDATE dj_car_life_customer_info UPDATE dj_car_life_customer_info
SET customer_class = #{customerClass}, updated_date = NOW() <trim prefix="SET" suffixOverrides=",">
WHERE customer_phone = #{phone} AND deleted_flag = 'N' <trim prefix="customer_class = CASE" suffix="END,">
<foreach collection="list" item="item">
WHEN customer_phone = #{item.customerPhone} THEN #{item.customerClass}
</foreach>
</trim>
updated_date = NOW()
</trim>
WHERE customer_phone IN
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item.customerPhone}
</foreach>
AND deleted_flag = 'N'
</update> </update>
<select id="countTodayPlanStore" parameterType="cn.com.glsx.dj.smartcarlife.dto.CustomerInfoDTO" resultType="java.lang.Integer"> <select id="countTodayPlanStore" parameterType="cn.com.glsx.dj.smartcarlife.dto.CustomerInfoDTO" resultType="java.lang.Integer">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!