Commit 3030ff8f by 崔彦峰

feat(clues): 添加车辆品牌ID字段并优化线索跟进功能

- 在AddCluesFollowRecordReq中将customerIntentLevelChange重命名为customerIntentLevel
- 为AddCluesReq、CluesDetailResp和CluesInfo实体添加carBrandId字段
- 在CluesPageResp中添加failReason字段用于暂败原因显示
- 将updateFollowInfo方法重命名为updateCluesInfo并更新相关调用
- 优化线索跟进逻辑,支持根据不同跟进结果更新线索状态
- 添加对成功收车线索禁止新增跟进记录的验证
- 实现终端线索状态下清空下次跟进时间的功能
- 在分页查询中填充暂败原因信息
1 parent 4f751a22
...@@ -34,7 +34,7 @@ public interface CluesInfoMapper extends BaseMapper<CluesInfo> { ...@@ -34,7 +34,7 @@ public interface CluesInfoMapper extends BaseMapper<CluesInfo> {
CluesFollowTimeStatusCountResp followTimeStatusCount(); CluesFollowTimeStatusCountResp followTimeStatusCount();
int updateFollowInfo(@Param("id") Integer id, int updateCluesInfo(@Param("id") Integer id,
@Param("customerIntentLevel") String customerIntentLevel, @Param("customerIntentLevel") String customerIntentLevel,
@Param("latestFollowTime") Date latestFollowTime, @Param("latestFollowTime") Date latestFollowTime,
@Param("nextFollowTime") Date nextFollowTime, @Param("nextFollowTime") Date nextFollowTime,
......
...@@ -137,19 +137,33 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> { ...@@ -137,19 +137,33 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> {
throw new BusinessException("线索不存在"); throw new BusinessException("线索不存在");
} }
if (Objects.equals(cluesInfo.getCluesStatus(), CluesStatusEnum.SUCCESS.getCode())) {
throw new BusinessException("成功收车线索不能新增跟进记录");
}
Date now = new Date(); Date now = new Date();
CluesFollowRecord latestRecord = cluesFollowRecordMapper.selectLatestByCluesId(req.getCluesId()); CluesFollowRecord latestRecord = cluesFollowRecordMapper.selectLatestByCluesId(req.getCluesId());
int followRecordType = getFollowRecordType(latestRecord, now); int followRecordType = getFollowRecordType(latestRecord, now);
Integer originalCluesStatus = cluesInfo.getCluesStatus(); Integer originalCluesStatus = cluesInfo.getCluesStatus();
boolean statusChanged = Objects.equals(originalCluesStatus, CluesStatusEnum.PENDING_FOLLOW.getCode()); Integer targetCluesStatus = resolveTargetCluesStatus(originalCluesStatus, req.getFollowResult());
Integer targetCluesStatus = statusChanged ? CluesStatusEnum.FOLLOWING.getCode() : originalCluesStatus; boolean statusChanged = !Objects.equals(originalCluesStatus, targetCluesStatus);
String originalIntentLevel = cluesInfo.getCustomerIntentLevel(); String originalIntentLevel = cluesInfo.getCustomerIntentLevel();
CustomerIntentLevelEnum intentLevel = CustomerIntentLevelEnum.getByCode(req.getCustomerIntentLevelChange()); CustomerIntentLevelEnum intentLevel = CustomerIntentLevelEnum.getByCode(req.getCustomerIntentLevel());
boolean intentLevelChanged = !Objects.equals(req.getCustomerIntentLevelChange(), originalIntentLevel); boolean intentLevelChanged = !Objects.equals(req.getCustomerIntentLevel(), originalIntentLevel);
Date nextFollowTime = req.getNextFollowTime(); Date nextFollowTime;
if (intentLevelChanged) { if (isTerminalCluesStatus(targetCluesStatus)) {
nextFollowTime = DateUtil.offsetDay(now, intentLevel.getFollowDays()); nextFollowTime = null;
} else {
if (intentLevelChanged) {
assert intentLevel != null;
nextFollowTime = DateUtil.offsetDay(now, intentLevel.getFollowDays());
}
else {
CustomerIntentLevelEnum intentLevelEnum = CustomerIntentLevelEnum.getByCode(originalIntentLevel);
assert intentLevelEnum != null;
nextFollowTime = DateUtil.offsetDay(now, intentLevelEnum.getFollowDays());
}
} }
CluesFollowRecord followRecord = new CluesFollowRecord(); CluesFollowRecord followRecord = new CluesFollowRecord();
...@@ -167,10 +181,10 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> { ...@@ -167,10 +181,10 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> {
? req.getFailReason() : null); ? req.getFailReason() : null);
if (intentLevelChanged) { if (intentLevelChanged) {
followRecord.setCustomerIntentLevelChange(String.format("由%s级变更为%s级", originalIntentLevel, followRecord.setCustomerIntentLevelChange(String.format("由%s级变更为%s级", originalIntentLevel,
req.getCustomerIntentLevelChange())); req.getCustomerIntentLevel()));
} }
else { else {
followRecord.setCustomerIntentLevelChange(req.getCustomerIntentLevelChange()); followRecord.setCustomerIntentLevelChange(req.getCustomerIntentLevel());
} }
followRecord.setNextFollowTime(nextFollowTime); followRecord.setNextFollowTime(nextFollowTime);
followRecord.setFollowRemark(req.getFollowRemark()); followRecord.setFollowRemark(req.getFollowRemark());
...@@ -182,10 +196,9 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> { ...@@ -182,10 +196,9 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> {
if (cluesFollowRecordMapper.insert(followRecord) != 1) { if (cluesFollowRecordMapper.insert(followRecord) != 1) {
throw new BusinessException("新增线索跟进记录失败"); throw new BusinessException("新增线索跟进记录失败");
} }
if (baseMapper.updateCluesInfo(req.getCluesId(), req.getCustomerIntentLevel(),now,
if (baseMapper.updateFollowInfo(req.getCluesId(), req.getCustomerIntentLevelChange(),now,
nextFollowTime, targetCluesStatus, req.getOperatorName(), now) != 1) { nextFollowTime, targetCluesStatus, req.getOperatorName(), now) != 1) {
throw new BusinessException("更新线索跟进信息失败"); throw new BusinessException("更新线索信息失败");
} }
FollowStyleEnum followStyle = FollowStyleEnum.getByCode(req.getFollowStyle()); FollowStyleEnum followStyle = FollowStyleEnum.getByCode(req.getFollowStyle());
...@@ -194,17 +207,37 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> { ...@@ -194,17 +207,37 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> {
String.format("新增跟进记录,跟进方式:%s,跟进结果:%s", String.format("新增跟进记录,跟进方式:%s,跟进结果:%s",
followStyle.getDesc(), followResult.getDesc()), now, req.getOperatorId(), req.getOperatorName()); followStyle.getDesc(), followResult.getDesc()), now, req.getOperatorId(), req.getOperatorName());
if (statusChanged) { if (statusChanged) {
CluesStatusEnum targetStatus = CluesStatusEnum.getByCode(targetCluesStatus);
saveOperationLog(req.getCluesId(), CluesOpTypeEnum.STATUS_CHANGE, saveOperationLog(req.getCluesId(), CluesOpTypeEnum.STATUS_CHANGE,
"线索状态变更为:" + CluesStatusEnum.FOLLOWING.getDesc(), now, req.getOperatorId(), req.getOperatorName()); "线索状态变更为:" + targetStatus.getDesc(), now, req.getOperatorId(), req.getOperatorName());
} }
if (intentLevelChanged) { if (intentLevelChanged) {
saveOperationLog(req.getCluesId(), CluesOpTypeEnum.INTENT_LEVEL_CHANGE, saveOperationLog(req.getCluesId(), CluesOpTypeEnum.INTENT_LEVEL_CHANGE,
String.format("意向等级由 %s 变更为 %s", originalIntentLevel, String.format("意向等级由 %s 变更为 %s", originalIntentLevel,
req.getCustomerIntentLevelChange()), now, req.getOperatorId(), req.getOperatorName()); req.getCustomerIntentLevel()), now, req.getOperatorId(), req.getOperatorName());
} }
return followRecord.getId(); return followRecord.getId();
} }
private Integer resolveTargetCluesStatus(Integer currentStatus, Integer followResult) {
if (Objects.equals(followResult, FollowResultEnum.SUCCESS_RECEIVE.getCode())) {
return CluesStatusEnum.SUCCESS.getCode();
}
if (Objects.equals(followResult, FollowResultEnum.NO_SELL_OLD_CAR.getCode())) {
return CluesStatusEnum.TEMP_LOST.getCode();
}
if (Objects.equals(currentStatus, CluesStatusEnum.PENDING_FOLLOW.getCode())
|| Objects.equals(currentStatus, CluesStatusEnum.TEMP_LOST.getCode())) {
return CluesStatusEnum.FOLLOWING.getCode();
}
return currentStatus;
}
private boolean isTerminalCluesStatus(Integer cluesStatus) {
return Objects.equals(cluesStatus, CluesStatusEnum.TEMP_LOST.getCode())
|| Objects.equals(cluesStatus, CluesStatusEnum.SUCCESS.getCode());
}
private void saveOperationLog(Integer cluesId, private void saveOperationLog(Integer cluesId,
CluesOpTypeEnum opType, CluesOpTypeEnum opType,
String content, String content,
...@@ -248,7 +281,7 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> { ...@@ -248,7 +281,7 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> {
&& req.getFailReason() != null && FailReasonEnum.getByCode(req.getFailReason()) == null) { && req.getFailReason() != null && FailReasonEnum.getByCode(req.getFailReason()) == null) {
throw new BusinessException("暂败原因不合法"); throw new BusinessException("暂败原因不合法");
} }
if (CustomerIntentLevelEnum.getByCode(req.getCustomerIntentLevelChange()) == null) { if (CustomerIntentLevelEnum.getByCode(req.getCustomerIntentLevel()) == null) {
throw new BusinessException("客户意向等级不合法"); throw new BusinessException("客户意向等级不合法");
} }
} }
...@@ -301,6 +334,11 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> { ...@@ -301,6 +334,11 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> {
Date now = new Date(); Date now = new Date();
for (CluesPageResp clues : result.getRecords()) { for (CluesPageResp clues : result.getRecords()) {
fillFollowStatus(clues, now); fillFollowStatus(clues, now);
//填充暂败原因
if (clues.getCluesStatus().equals(CluesStatusEnum.TEMP_LOST.getCode())) {
CluesFollowRecord cluesFollowRecord = cluesFollowRecordMapper.selectLatestByCluesId(clues.getId());
clues.setFailReason(cluesFollowRecord == null ? null : cluesFollowRecord.getFailReason());
}
} }
return result; return result;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<result column="latest_follow_time" property="latestFollowTime" /> <result column="latest_follow_time" property="latestFollowTime" />
<result column="next_follow_time" property="nextFollowTime" /> <result column="next_follow_time" property="nextFollowTime" />
<result column="customer_intent_level" property="customerIntentLevel" /> <result column="customer_intent_level" property="customerIntentLevel" />
<result column="car_brand_id" property="carBrandId" />
<result column="car_brand" property="carBrand" /> <result column="car_brand" property="carBrand" />
<result column="car_childs_brand_id" property="carChildsBrandId" /> <result column="car_childs_brand_id" property="carChildsBrandId" />
<result column="car_childs_brand_name" property="carChildsBrandName" /> <result column="car_childs_brand_name" property="carChildsBrandName" />
...@@ -37,7 +38,7 @@ ...@@ -37,7 +38,7 @@
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, clues_no, clues_status, enter_type, car_owner_name, car_owner_phone, enter_time, latest_follow_time, next_follow_time, customer_intent_level, car_brand, car_childs_brand_id, car_childs_brand_name, car_series_id, car_series_name, car_type_id, car_type_name, seller_user_id, seller_name, seller_merchant_id, seller_merchant_name, conversion_user_id, conversion_name, conversion_merchant_id, conversion_merchant_name, remark, created_by, created_date, updated_by, updated_date, deleted_flag id, clues_no, clues_status, enter_type, car_owner_name, car_owner_phone, enter_time, latest_follow_time, next_follow_time, customer_intent_level, car_brand_id, car_brand, car_childs_brand_id, car_childs_brand_name, car_series_id, car_series_name, car_type_id, car_type_name, seller_user_id, seller_name, seller_merchant_id, seller_merchant_name, conversion_user_id, conversion_name, conversion_merchant_id, conversion_merchant_name, remark, created_by, created_date, updated_by, updated_date, deleted_flag
</sql> </sql>
<select id="detail" resultType="com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesDetailResp"> <select id="detail" resultType="com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesDetailResp">
...@@ -51,6 +52,7 @@ ...@@ -51,6 +52,7 @@
c.latest_follow_time AS latestFollowTime, c.latest_follow_time AS latestFollowTime,
c.next_follow_time AS nextFollowTime, c.next_follow_time AS nextFollowTime,
c.customer_intent_level AS customerIntentLevel, c.customer_intent_level AS customerIntentLevel,
c.car_brand_id AS carBrandId,
c.car_brand AS carBrand, c.car_brand AS carBrand,
c.car_childs_brand_id AS carChildsBrandId, c.car_childs_brand_id AS carChildsBrandId,
c.car_childs_brand_name AS carChildsBrandName, c.car_childs_brand_name AS carChildsBrandName,
...@@ -108,7 +110,7 @@ ...@@ -108,7 +110,7 @@
WHERE c.deleted_flag = 'N' WHERE c.deleted_flag = 'N'
</select> </select>
<update id="updateFollowInfo"> <update id="updateCluesInfo">
UPDATE vcp_clues_info UPDATE vcp_clues_info
SET customer_intent_level = #{customerIntentLevel}, SET customer_intent_level = #{customerIntentLevel},
latest_follow_time = #{latestFollowTime, jdbcType=TIMESTAMP}, latest_follow_time = #{latestFollowTime, jdbcType=TIMESTAMP},
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议(Top 3)

    1. 性能瓶颈:分页查询中存在经典的 N+1 查询问题

    • 问题描述:在 CluesInfoService.java 的分页处理逻辑(约第 338 行)中,在 for 循环内部调用了 cluesFollowRecordMapper.selectLatestByCluesId(clues.getId()) 查询数据库。
    • 影响分析:这是严重的性能隐患。如果一页返回 50 条线索,且都是暂败状态,系统将会额外发起 50 次数据库查询。在并发场景下会导致数据库连接池耗尽、接口响应极慢。
    • 优化建议:禁止在循环中查询数据库。建议收集符合条件的线索 ID,在循环外通过一次 IN 查询批量获取最新跟进记录,然后在内存中进行匹配;或者直接在分页查询的 MyBatis SQL 中通过 LEFT JOIN 关联取回暂败原因。
    • 代码示例(内存匹配方案): ```java // 1. 收集需要查询暂败原因的线索ID List tempLostCluesIds = result.getRecords().stream() .filter(c -> Objects.equals(c.getCluesStatus(), CluesStatusEnum.TEMP_LOST.getCode())) .map(CluesPageResp::getId) .collect(Collectors.toList());

    // 2. 批量查询并转换为 Map (需在 Mapper 中新增批量查询最新记录的方法) Map failReasonMap = new HashMap<>(); if (CollectionUtils.isNotEmpty(tempLostCluesIds)) { List records = cluesFollowRecordMapper.selectLatestByCluesIds(tempLostCluesIds); failReasonMap = records.stream().collect(Collectors.toMap( CluesFollowRecord::getCluesId, CluesFollowRecord::getFailReason, (v1, v2) -> v1 // 兜底防重 )); }

    // 3. 内存中回填 for (CluesPageResp clues : result.getRecords()) { fillFollowStatus(clues, now); if (Objects.equals(clues.getCluesStatus(), CluesStatusEnum.TEMP_LOST.getCode())) { clues.setFailReason(failReasonMap.get(clues.getId())); } }

    
    **2. 健壮性与最佳实践:生产代码中不应使用 `assert` 关键字**
    *   **问题描述**:在 `CluesInfoService.java` 的意向等级处理逻辑(约第 158 行)中,使用了 `assert intentLevel != null;` 和 `assert intentLevelEnum != null;` 进行非空断言。
    *   **影响分析**:Java 的 `assert` 关键字在 JVM 中默认是关闭的(除非启动时指定 `-ea` 参数),在生产环境中这行代码会被直接忽略。如果数据库中存在历史脏数据导致 `originalIntentLevel` 查出的枚举为空,下一行调用 `.getFollowDays()` 时将直接抛出 `NullPointerException`,导致核心业务流程中断。
    *   **优化建议**:使用标准的非空校验并抛出业务异常,或者进行防御性编程赋默认值。
    *   **代码示例**:
    ```java
    CustomerIntentLevelEnum intentLevelEnum = CustomerIntentLevelEnum.getByCode(originalIntentLevel);
    if (intentLevelEnum == null) {
        throw new BusinessException("未匹配到有效的历史客户意向等级");
    }
    nextFollowTime = DateUtil.offsetDay(now, intentLevelEnum.getFollowDays());
    

    3. 健壮性隐患:潜在的 NullPointerException (空指针异常)

    • 问题描述:在 CluesInfoService.java 的分页填充逻辑(约第 338 行)中,使用了 clues.getCluesStatus().equals(...)。
    • 影响分析:如果数据库中某条记录的 clues_status 字段由于异常情况为空,clues.getCluesStatus() 将返回 null,直接调用 .equals() 会触发 NullPointerException,导致整个分页查询接口崩溃。
    • 优化建议:在进行对象相等判断时,应始终将确定的常量或枚举值放在前面,或者使用 Objects.equals() 工具类。
    • 代码示例: ```java // 优化前: if (clues.getCluesStatus().equals(CluesStatusEnum.TEMP_LOST.getCode()))

    // 优化后(推荐): if (Objects.equals(clues.getCluesStatus(), CluesStatusEnum.TEMP_LOST.getCode())) // 或: if (CluesStatusEnum.TEMP_LOST.getCode().equals(clues.getCluesStatus()))

    
    ---
    
    #### 二、评分明细
    
    *   **功能实现的正确性与健壮性 (33/40)**:核心业务逻辑(状态流转、终端状态拦截)处理正确且清晰。扣分原因:存在引发 `NullPointerException` 的隐患(`assert` 失效风险及 `.equals` 调用风险)。
    *   **安全性与潜在风险 (30/30)**:MyBatis XML 中使用 `#{}` 预防了 SQL 注入,未发现越权、XSS 等明显安全漏洞。
    *   **最佳实践与可维护性 (15/20)**:代码结构较好,抽离了 `resolveTargetCluesStatus` 等私有方法,提高了可读性。扣分原因:在 Spring 业务代码中使用了不规范的 `assert` 断言。
    *   **性能与资源利用 (1/5)**:扣分原因:在分页列表的 `for` 循环中嵌套执行数据库查询,属于典型的 N+1 性能反模式,会对数据库造成不必要的压力。
    *   **提交信息质量 (5/5)**:Commit message 采用了符合 Angular 规范的格式(`feat(clues): ...`),且通过列表清晰详细地描述了变更点,非常优秀,便于追溯。
    
    总分:84分
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!