Commit 5f89d2a9 by 叶立庆

增加查询字段:bizInstanceIds

1 parent 092382f4
...@@ -44,6 +44,10 @@ public class TaskQueryConditionDTO implements Serializable { ...@@ -44,6 +44,10 @@ public class TaskQueryConditionDTO implements Serializable {
@ApiModelProperty(notes = "业务实例ID") @ApiModelProperty(notes = "业务实例ID")
private String bizInstanceId; private String bizInstanceId;
/** 业务实例ID列表。 */
@ApiModelProperty(notes = "业务实例ID列表")
private List<String> bizInstanceIds;
/** 任务状态。 */ /** 任务状态。 */
@ApiModelProperty(notes = "任务状态") @ApiModelProperty(notes = "任务状态")
private String status; private String status;
......
...@@ -115,6 +115,12 @@ ...@@ -115,6 +115,12 @@
<if test="condition != null and (condition.bizTypes == null or condition.bizTypes.size() == 0) and condition.bizType != null and condition.bizType != ''"> <if test="condition != null and (condition.bizTypes == null or condition.bizTypes.size() == 0) and condition.bizType != null and condition.bizType != ''">
and t.biz_type = #{condition.bizType} and t.biz_type = #{condition.bizType}
</if> </if>
<if test="condition != null and condition.bizInstanceIds != null and condition.bizInstanceIds.size() > 0">
and t.biz_instance_id in
<foreach collection="condition.bizInstanceIds" item="bizInstanceId" open="(" separator="," close=")">
#{bizInstanceId}
</foreach>
</if>
<if test="condition != null and condition.bizInstanceId != null and condition.bizInstanceId != ''"> <if test="condition != null and condition.bizInstanceId != null and condition.bizInstanceId != ''">
and t.biz_instance_id = #{condition.bizInstanceId} and t.biz_instance_id = #{condition.bizInstanceId}
</if> </if>
...@@ -242,6 +248,12 @@ ...@@ -242,6 +248,12 @@
<if test="condition != null and (condition.bizTypes == null or condition.bizTypes.size() == 0) and condition.bizType != null and condition.bizType != ''"> <if test="condition != null and (condition.bizTypes == null or condition.bizTypes.size() == 0) and condition.bizType != null and condition.bizType != ''">
and t.biz_type = #{condition.bizType} and t.biz_type = #{condition.bizType}
</if> </if>
<if test="condition != null and condition.bizInstanceIds != null and condition.bizInstanceIds.size() > 0">
and t.biz_instance_id in
<foreach collection="condition.bizInstanceIds" item="bizInstanceId" open="(" separator="," close=")">
#{bizInstanceId}
</foreach>
</if>
<if test="condition != null and condition.bizInstanceId != null and condition.bizInstanceId != ''"> <if test="condition != null and condition.bizInstanceId != null and condition.bizInstanceId != ''">
and t.biz_instance_id = #{condition.bizInstanceId} and t.biz_instance_id = #{condition.bizInstanceId}
</if> </if>
......
...@@ -44,10 +44,16 @@ ...@@ -44,10 +44,16 @@
#{bizType} #{bizType}
</foreach> </foreach>
</if> </if>
<if test="condition != null and (condition.bizTypes == null or condition.bizTypes.size() == 0) and condition.bizType != null and condition.bizType != ''"> <if test="condition != null and condition.bizType != null and condition.bizType != ''">
and t.biz_type = #{condition.bizType} and t.biz_type = #{condition.bizType}
</if> </if>
<if test="condition != null and condition.bizInstanceId != null and condition.bizInstanceId != ''"> <if test="condition != null and condition.bizInstanceIds != null and condition.bizInstanceIds.size() > 0">
and t.biz_instance_id in
<foreach collection="condition.bizInstanceIds" item="bizInstanceId" open="(" separator="," close=")">
#{bizInstanceId}
</foreach>
</if>
<if test="condition != null and condition.bizInstanceId != null and condition.bizInstanceId != ''">
and t.biz_instance_id = #{condition.bizInstanceId} and t.biz_instance_id = #{condition.bizInstanceId}
</if> </if>
<if test="condition != null and condition.status != null and condition.status != ''"> <if test="condition != null and condition.status != null and condition.status != ''">
......
  • @wangxw1
    commented
    Master

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

    1. 破坏了原有查询条件的互斥逻辑(功能正确性风险 - 高)

    • 问题描述:在 TaskMapper.xml 中,你删除了 bizType 标签中关于 (condition.bizTypes == null or condition.bizTypes.size() == 0) 的判断条件。同时,新增的 bizInstanceIds(集合)与原有的 bizInstanceId(单值)也没有做互斥处理。
    • 影响分析:这是一个未在 commit message 中声明的逻辑变更。如果调用方同时传入了 bizTypes 和 bizType(或者同时传入 bizInstanceIds 和 bizInstanceId),生成的 SQL 将同时包含 IN (...) 和 = ... 两个条件。这极易导致条件互斥,从而查不到任何数据,引发线上业务异常。
    • 优化建议:恢复 bizType 的互斥判断逻辑,并为新增的 bizInstanceIds 增加类似的互斥保护。 xml <!-- 建议的 bizInstanceId 互斥处理示例 --> <if test="condition != null and (condition.bizInstanceIds == null or condition.bizInstanceIds.size() == 0) and condition.bizInstanceId != null and condition.bizInstanceId != ''"> and t.biz_instance_id = #{condition.bizInstanceId} </if>

    2. IN 查询集合未做容量限制(性能与稳定性风险 - 中)

    • 问题描述:在 TaskAssigneeMapper.xml 和 TaskMapper.xml 中,新增了对 bizInstanceIds 的 <foreach> 遍历以生成 IN 查询,但未对集合的大小进行限制。
    • 影响分析:如果上游业务传入的 bizInstanceIds 列表非常大(例如超过 1000 个),会导致生成的 SQL 语句过长,引发数据库性能瓶颈(如全表扫描、解析耗时),甚至直接触发数据库的 IN 参数数量上限报错(如 Oracle 限制 1000,MySQL 也会因 max_allowed_packet 报错)。
    • 优化建议:在 Java 业务逻辑层(Service 层)对传入的 bizInstanceIds 集合大小进行校验和限制(例如最大允许 500 个)。如果确实有大批量查询需求,建议在 Java 层进行分批查询(Partition)。

    3. Dubbo DTO 变更与序列化兼容性(最佳实践 - 中)

    • 问题描述:在 TaskQueryConditionDTO.java 中新增了 bizInstanceIds 字段。鉴于该类位于 rpc-dj-taskcenter-api 模块,属于 Dubbo RPC 调用的参数对象。
    • 影响分析:虽然新增字段(非修改已有字段)在 Dubbo 默认的 Hessian2 序列化中通常是向下兼容的,但如果该 DTO 没有固定 serialVersionUID,或者消费端(Consumer)强依赖此新字段而提供端(Provider)未及时全量发布,可能会导致反序列化异常或业务逻辑漏处理。
    • 优化建议:
      1. 确保 TaskQueryConditionDTO 显式定义了固定的 serialVersionUID。
      2. 确保在上线时,先发布服务提供者(Provider),再发布服务消费者(Consumer)。

    二、评分明细

    • 功能实现的正确性与健壮性(30 / 40分)
      • 扣分原因:在 TaskMapper.xml 中意外移除了原有 bizType 的互斥逻辑,且新增的单值与集合查询条件缺乏互斥保护,存在产生矛盾 SQL 导致查询失效的风险。MyBatis 语法使用正确,未发现子查询。
    • 安全性与潜在风险(30 / 30分)
      • 评分理由:MyBatis 传参正确使用了 #{} 进行预编译,不存在 SQL 注入风险。未见越权或敏感信息泄露等安全隐患。
    • 最佳实践与可维护性(18 / 20分)
      • 扣分原因:DTO 增加字段符合标准做法,注解清晰。但修改已有 mapper 逻辑时缺乏防御性编程思维(未处理单值与集合共存的边界情况)。
    • 性能与资源利用(3 / 5分)
      • 扣分原因:新增的 IN 查询缺乏集合大小的硬性兜底限制,存在潜在的慢 SQL 及数据库崩溃风险。
    • 提交信息质量(3 / 5分)
      • 扣分原因:Commit 信息 增加查询字段:bizInstanceIds 过于简略。未说明业务背景(Why),且未提及对 TaskMapper.xml 中原有逻辑的修改(如果是误删则反映出 review 不仔细)。

    总分:84分

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