Commit d232126b by 杨卫

feat(strategy): 新增督导带教功能并优化预警汇总查询

- 新增督导带教人员下拉列表查询接口及实现
- 添加学习记录请求参数支持模糊搜索字段
- 优化预警汇总查询逻辑,切换门店数据源为商户关系表
- 新增商户关系表查询服务及相应映射器
- 添加策略检查响应DTO的最大订单数阈值字段
- 更新RPC依赖版本至5.8.5-SNAPSHOT
- 重构策略分发处理器减少不必要的导入
- 修复商户过滤工具中的渠道类型设置问题
1 parent 9428d184
...@@ -123,4 +123,10 @@ public class ConversationBatchDTO extends ConversationBatch implements Serializa ...@@ -123,4 +123,10 @@ public class ConversationBatchDTO extends ConversationBatch implements Serializa
*/ */
@ApiModelProperty(notes = "录音时长") @ApiModelProperty(notes = "录音时长")
private Long durationTime; private Long durationTime;
/**
* 产品名称(多条用"/"拼接)
*/
@ApiModelProperty(notes = "产品名称")
private String productName;
} }
\ No newline at end of file \ No newline at end of file
...@@ -79,4 +79,22 @@ public class LearningEffectAnalysisRequest implements Serializable { ...@@ -79,4 +79,22 @@ public class LearningEffectAnalysisRequest implements Serializable {
private String receptionDate; private String receptionDate;
private List<Integer> recordIdList; private List<Integer> recordIdList;
/**
* 客户名称(模糊搜索)
*/
@ApiModelProperty(notes = "客户名称(模糊搜索)")
private String customerName;
/**
* 车型(模糊搜索)
*/
@ApiModelProperty(notes = "车型(模糊搜索)")
private String carModel;
/**
* 产品名称(模糊搜索)
*/
@ApiModelProperty(notes = "产品名称(模糊搜索)")
private String productName;
} }
\ No newline at end of file \ No newline at end of file
...@@ -23,4 +23,13 @@ public interface CustomerOrderTempMapper extends OreMapper<CustomerOrderTemp> { ...@@ -23,4 +23,13 @@ public interface CustomerOrderTempMapper extends OreMapper<CustomerOrderTemp> {
List<CustomerOrderTemp> getByPhoneAndScenePairs(@Param("pairs") List<EmployeeBadgeV2DTO> pairs); List<CustomerOrderTemp> getByPhoneAndScenePairs(@Param("pairs") List<EmployeeBadgeV2DTO> pairs);
List<CustomerOrderTemp> findAllOrderByUpdateTime(); List<CustomerOrderTemp> findAllOrderByUpdateTime();
/**
* 按手机号列表批量查询产品名称(用于出参填充 productName)。
*
* @param phones 手机号列表
* @param sceneType 场景类型:0=权益延保,1=轻改
* @return 客户订单临时记录
*/
List<CustomerOrderTemp> selectByPhoneList(@Param("phones") List<String> phones, @Param("sceneType") Integer sceneType);
} }
\ No newline at end of file \ No newline at end of file
...@@ -7,6 +7,7 @@ import cn.com.glsx.dj.mindworkplate.manager.wechat.WechatManager; ...@@ -7,6 +7,7 @@ import cn.com.glsx.dj.mindworkplate.manager.wechat.WechatManager;
import cn.com.glsx.dj.mindworkplate.mapper.*; import cn.com.glsx.dj.mindworkplate.mapper.*;
import cn.com.glsx.dj.mindworkplate.model.BadgeRecordings; import cn.com.glsx.dj.mindworkplate.model.BadgeRecordings;
import cn.com.glsx.dj.mindworkplate.model.ConversationBatch; import cn.com.glsx.dj.mindworkplate.model.ConversationBatch;
import cn.com.glsx.dj.mindworkplate.model.CustomerOrderTemp;
import cn.com.glsx.dj.mindworkplate.model.ReceptionStaffStaticDTO; import cn.com.glsx.dj.mindworkplate.model.ReceptionStaffStaticDTO;
import cn.com.glsx.dj.mindworkplate.model.export.BadgeCheckExportModel; import cn.com.glsx.dj.mindworkplate.model.export.BadgeCheckExportModel;
import cn.com.glsx.dj.mindworkplate.model.export.BadgeReceptionExportModel; import cn.com.glsx.dj.mindworkplate.model.export.BadgeReceptionExportModel;
...@@ -37,6 +38,7 @@ import java.util.ArrayList; ...@@ -37,6 +38,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
...@@ -84,6 +86,9 @@ public class ConversationBatchService { ...@@ -84,6 +86,9 @@ public class ConversationBatchService {
@Autowired @Autowired
private AiInspectionRequestMapper aiInspectionRequestMapper; private AiInspectionRequestMapper aiInspectionRequestMapper;
@Autowired
private CustomerOrderTempMapper customerOrderTempMapper;
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
...@@ -545,9 +550,72 @@ public class ConversationBatchService { ...@@ -545,9 +550,72 @@ public class ConversationBatchService {
: Long.parseLong(conversationBatchDTO.getDuration()))); : Long.parseLong(conversationBatchDTO.getDuration())));
} }
} }
// 批量填充产品名称:按 phone + sceneType 聚合 upgrade_goods_name
fillProductNames(recordPageListByCondition, request.getCondition().getBusinessType());
return recordPageListByCondition; return recordPageListByCondition;
} }
/**
* 从 customer_order_temp 批量查询产品名称,按手机号分组拼接后回填到 DTO。
*
* @param dtos 录音记录列表
* @param businessType 业务类型(1=延保, 2=轻改, 3=权益)
*/
private void fillProductNames(List<ConversationBatchDTO> dtos, Integer businessType) {
if (CollectionUtils.isEmpty(dtos) || businessType == null) {
return;
}
// businessType → sceneType: 延保(1)→0, 轻改(2)→1, 权益(3)→0
int sceneType;
if (businessType == 2) {
sceneType = 1;
} else {
sceneType = 0;
}
// 收集所有手机号
List<String> phones = dtos.stream()
.map(ConversationBatchDTO::getPhoneNumber)
.filter(org.apache.commons.lang.StringUtils::isNotBlank)
.distinct()
.collect(Collectors.toList());
if (phones.isEmpty()) {
return;
}
// 批量查询
List<CustomerOrderTemp> orderTemps = customerOrderTempMapper.selectByPhoneList(phones, sceneType);
if (CollectionUtils.isEmpty(orderTemps)){
return;
}
// 按手机号分组,产品名称用"/"拼接去重
Map<String, String> phoneProductMap = orderTemps.stream()
.filter(ot -> org.apache.commons.lang.StringUtils.isNotBlank(ot.getUpgradeGoodsName()))
.collect(Collectors.groupingBy(
CustomerOrderTemp::getPhone,
LinkedHashMap::new,
Collectors.mapping(CustomerOrderTemp::getUpgradeGoodsName, Collectors.toSet())))
.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> String.join("/", e.getValue()),
(a, b) -> a,
LinkedHashMap::new));
// 回填 DTO
for (ConversationBatchDTO dto : dtos) {
if (dto.getPhoneNumber() != null) {
String productName = phoneProductMap.get(dto.getPhoneNumber());
if (productName != null) {
dto.setProductName(productName);
}
}
}
}
private void convertTime(LearningEffectAnalysisRequest condition) { private void convertTime(LearningEffectAnalysisRequest condition) {
Integer analysisPeriodDays = condition.getAnalysisPeriodDays(); Integer analysisPeriodDays = condition.getAnalysisPeriodDays();
if (analysisPeriodDays != null){ if (analysisPeriodDays != null){
......
...@@ -561,6 +561,27 @@ ...@@ -561,6 +561,27 @@
AND cot.order_status IN (4, 6) AND cot.order_status IN (4, 6)
) )
</if> </if>
<if test="condition.customerName != null and condition.customerName != ''">
and t4.customer_name like concat('%',#{condition.customerName},'%')
</if>
<if test="condition.carModel != null and condition.carModel != ''">
and t4.car_model like concat('%',#{condition.carModel},'%')
</if>
<if test="condition.productName != null and condition.productName != ''">
and EXISTS (
SELECT 1 FROM customer_order_temp cot
WHERE cot.phone = t4.phone_number
AND cot.upgrade_goods_name like concat('%',#{condition.productName},'%')
<if test="condition.businessType != null">
<if test="condition.businessType == 1 or condition.businessType == 3">
AND cot.scene_type = 0
</if>
<if test="condition.businessType == 2">
AND cot.scene_type = 1
</if>
</if>
)
</if>
order by t1.recording_start_time desc order by t1.recording_start_time desc
</select> </select>
<select id="getRecordStaticByCondition" <select id="getRecordStaticByCondition"
......
...@@ -104,6 +104,18 @@ ...@@ -104,6 +104,18 @@
</foreach> </foreach>
</select> </select>
<select id="selectByPhoneList" resultType="cn.com.glsx.dj.mindworkplate.model.CustomerOrderTemp">
SELECT phone, upgrade_goods_name upgradeGoodsName, scene_type sceneType
FROM customer_order_temp
WHERE scene_type = #{sceneType}
<if test="phones != null and phones.size() > 0">
AND phone IN
<foreach collection="phones" item="phone" open="(" separator="," close=")">
#{phone}
</foreach>
</if>
</select>
<select id="findAllOrderByUpdateTime" <select id="findAllOrderByUpdateTime"
resultMap="BaseResultMap"> resultMap="BaseResultMap">
SELECT dclgoc.order_code,dclgoc.customer_phone as phone, dclgo.scene_type as scene_type,dclgo.status as order_status, SELECT dclgoc.order_code,dclgoc.customer_phone as phone, dclgo.scene_type as scene_type,dclgo.status as order_status,
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议,如果必要,给出代码示例(仅限 Top 3)

    1. 严重违反架构规范:MyBatis 语句使用了子查询(功能实现与性能)

    • 问题描述:在 ConversationBatchMapper.xml 文件中,针对 condition.productName 的条件过滤使用了 EXISTS (SELECT 1 FROM customer_order_temp ...) 子查询。
    • 影响分析:严重违反了本次审查的强制规则(“mybatis的sql语句不允许使用子查询”)。在 MySQL 等关系型数据库中,相关子查询(Dependent Subquery)往往会导致外层查询的每一行都会触发一次内层查询,当主表数据量较大时,极易引发严重的性能瓶颈甚至慢 SQL 告警。
    • 优化建议:将子查询改造为 JOIN 关联查询。建议在主 SQL 的 FROM 语句中使用 INNER JOIN 或 LEFT JOIN 关联 customer_order_temp 表,并在 WHERE 语句中进行条件过滤(需注意使用 GROUP BY 或 DISTINCT 防止产生笛卡尔积导致数据重复)。

    2. 潜在的高危变更:Dubbo 接口请求参数结构变更(功能实现与健壮性)

    • 问题描述:在 rpc-dj-mindworkplate-api 模块的 LearningEffectAnalysisRequest.java 中,新增了 customerName、carModel、productName 三个请求参数。
    • 影响分析:触发了本次审查的强制规则(“dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现”)。虽然新增字段在 Hessian2 序列化下通常是向下兼容的,但如果消费者(Consumer)和提供者(Provider)的发布顺序不当,或者系统中使用了严格的序列化框架(如 Kryo),可能会导致反序列化异常,直接引发线上 RPC 调用失败。
    • 优化建议:
      1. 确认该 DTO 是否用于 Dubbo 远程调用。如果是,请严格评估上下游微服务的发布依赖顺序(通常需先发 Provider,后发 Consumer)。
      2. 建议在类上显式声明 serialVersionUID(当前代码未体现,若无请务必补充),以降低反序列化失败的风险。

    3. SQL 健壮性隐患:动态 SQL 缺乏防御性兜底(功能实现与健壮性)

    • 问题描述:在 CustomerOrderTempMapper.xml 的 selectByPhoneList 方法中,使用了 <if test="phones != null and phones.size() > 0"> 来包裹 IN 查询条件。
    • 影响分析:虽然在 Java 业务层(ConversationBatchService)已经做了 phones.isEmpty() 的拦截,但 Mapper 层的 SQL 缺乏独立的防御能力。如果未来其他业务复用该 Mapper 方法且未做判空,一旦传入空的 phones 集合,SQL 将退化为 SELECT ... WHERE scene_type = #{sceneType},这会引发全表扫描并返回大量数据,可能导致 OOM 或数据库 CPU 飙升。
    • 优化建议:在 XML 中增加防御性逻辑,确保当集合为空时,SQL 语法依然安全或者直接阻断。 xml <select id="selectByPhoneList" resultType="cn.com.glsx.dj.mindworkplate.model.CustomerOrderTemp"> SELECT phone, upgrade_goods_name upgradeGoodsName, scene_type sceneType FROM customer_order_temp WHERE scene_type = #{sceneType} <choose> <when test="phones != null and phones.size() > 0"> AND phone IN <foreach collection="phones" item="phone" open="(" separator="," close=")"> #{phone} </foreach> </when> <otherwise> AND 1 = 0 <!-- 兜底条件,防止全表扫描 --> </otherwise> </choose> </select>

    二、评分明细

    • 功能实现的正确性与健壮性(28/40分): 业务逻辑基本正确,Java 层的 Stream 聚合处理得当。但 XML 中使用了被明令禁止的子查询,且 Mapper 层的动态 SQL 缺乏防御性设计,扣除 12 分。

    • 安全性与潜在风险(24/30分): 未发现 SQL 注入(正确使用了 #{})及越权等常规安全漏洞。但在 API 模块修改 Dubbo 实体类触碰了高危规则,存在潜在的 RPC 序列化/兼容性风险,扣除 6 分。

    • 最佳实践与可维护性(18/20分): 代码结构清晰,变量命名规范,ConversationBatchService 中抽取 fillProductNames 独立方法符合单一职责原则。注释也较为完善。仅微小扣分。

    • 性能与资源利用(2/5分): 子查询的使用是严重的性能隐患,当外层表数据量增加时,查询性能会急剧下降,扣除 3 分。

    • 提交信息质量(5/5分): Commit Message 采用了 feat(scope): desc 的标准规范,且详细列出了变更的多个子项,清晰、准确、可追溯,得满分。

    总分:77分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!