Commit 8e37a8a2 by 叶立庆

Merge remote-tracking branch 'origin/master' into v5.8.3.2

# Conflicts:
#	rpc-dj-smartcarlife-api/pom.xml
#	rpc-dj-smartcarlife/pom.xml
#	rpc-dj-smartcarlife/src/main/java/cn/com/glsx/dj/smartcarlife/job/CustomerClassRefreshJob.java
2 parents 539f0a46 76f98830
...@@ -495,7 +495,7 @@ public class GoodsSubOrder implements Serializable{ ...@@ -495,7 +495,7 @@ public class GoodsSubOrder implements Serializable{
*/ */
@ApiModelProperty(notes = "商品活动标识,0-否,1-是") @ApiModelProperty(notes = "商品活动标识,0-否,1-是")
@Column(name = "marketing_flag") @Column(name = "marketing_flag")
private Integer marketingFlag = 0; private Integer marketingFlag;
@ApiModelProperty(notes = "商品活动id") @ApiModelProperty(notes = "商品活动id")
@Column(name = "activity_id") @Column(name = "activity_id")
......
...@@ -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);
} }
...@@ -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!