Commit 4f751a22 by 崔彦峰

fix(clues): 修复线索状态统计查询条件问题

- 移除 CluesStatusCountReq 中 sellerMerchantId 的非空验证注解
- 修改 CluesInfoMapper.xml 中的查询逻辑,添加 sellerMerchantId 条件判断
- 优化 SQL 查询,仅当 sellerMerchantId 不为空时才添加该过滤条件
- 修复因必填验证导致的查询异常问题
- 确保查询条件的灵活适配,提升接口可用性
1 parent 44694fad
...@@ -83,7 +83,9 @@ ...@@ -83,7 +83,9 @@
COALESCE(SUM(CASE WHEN c.clues_status = 4 THEN 1 ELSE 0 END), 0) AS successCount COALESCE(SUM(CASE WHEN c.clues_status = 4 THEN 1 ELSE 0 END), 0) AS successCount
FROM vcp_clues_info c FROM vcp_clues_info c
WHERE c.deleted_flag = 'N' WHERE c.deleted_flag = 'N'
<if test="request.sellerMerchantId != null and request.sellerMerchantId != ''">
AND c.seller_merchant_id = #{req.sellerMerchantId} AND c.seller_merchant_id = #{req.sellerMerchantId}
</if>
<if test="request.sellerUserId != null and request.sellerUserId != ''"> <if test="request.sellerUserId != null and request.sellerUserId != ''">
AND c.seller_user_id = #{request.sellerUserId} AND c.seller_user_id = #{request.sellerUserId}
</if> </if>
......
  • @wangxw1
    commented
    Master

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

    1. 参数引用名称不一致导致运行时异常(严重)

    • 问题描述:在新增的 <if> 标签中,条件判断使用的是 request.sellerMerchantId,但内部 SQL 赋值时使用的是 #{req.sellerMerchantId}。
    • 影响分析:这是一个致命的代码逻辑错误。当传入的 request.sellerMerchantId 不为空时,MyBatis 会尝试解析并注入 req.sellerMerchantId。由于上下文中大概率不存在 req 对象(从其他条件 #{request.sellerUserId} 推断),这将在运行时触发 BindingException 或 ReflectionException,导致整个查询接口崩溃。
    • 优化建议:统一参数引用名称,将 req 修正为 request。 xml <if test="request.sellerMerchantId != null and request.sellerMerchantId != ''"> AND c.seller_merchant_id = #{request.sellerMerchantId} </if>

    2. OGNL 表达式中针对 ID 类型的空字符串判断(最佳实践)

    • 问题描述:<if> 标签中包含了 request.sellerMerchantId != '' 的判断。
    • 影响分析:通常带有 Id 后缀的字段在 Java 中会被定义为数值类型(如 Long 或 Integer)。在 MyBatis 的 OGNL 表达式中,如果对数值类型进行 != ''(空字符串)的比较,不仅没有必要,还可能在某些版本或特定传参下引发 NumberFormatException 或隐式类型转换带来的意料之外的评估结果。
    • 优化建议:确认 sellerMerchantId 的 Java 类型。如果它是数值类型(如 Long),请移除空字符串判断;如果是 String 类型,则保留。 xml <!-- 如果 sellerMerchantId 是 Long/Integer 类型 --> <if test="request.sellerMerchantId != null"> AND c.seller_merchant_id = #{request.sellerMerchantId} </if>

    二、评分明细

    • 功能实现的正确性与健壮性(20/40分):扣分严重。虽然移除了必填校验并添加了动态 SQL 逻辑,但由于 request 与 req 的拼写错误,导致该分支逻辑在触发时必然报错,未能实现预期的功能正确性。未发现使用子查询。
    • 安全性与潜在风险(30/30分):SQL 参数注入使用了安全的 #{} 占位符,不存在 SQL 注入风险;未见越权或敏感信息泄露问题。
    • 最佳实践与可维护性(18/20分):代码结构清晰,但对于可能为数值类型的 ID 字段使用了空字符串判断,略微不符合 MyBatis 严谨的 OGNL 编写习惯。
    • 性能与资源利用(5/5分):动态拼接条件过滤,有助于利用数据库索引,无明显性能瓶颈或资源浪费。
    • 提交信息质量(5/5分):Commit message 非常优秀。采用了标准的 Angular 规范(fix(clues):),详细列出了修改点及修复原因,逻辑清晰,具有极高的可追溯性。

    总分:78分

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