Commit 5a5bcc89 by 范富荣

优化查询飞行督导逻辑

1 parent 7d62e44f
......@@ -367,7 +367,8 @@ public class MerchantOutputValueTargetService {
RpcAssert.assertNotNull(pagination.getCondition().getSupervisorUuid(), DefaultErrorEnum.DATA_NULL, "supervisorUuid must not ne null");
try {
Page<MerchantAreaOperatorDTO> page = PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize(), pagination.isNeedCount());
ShopMerchantDirectorConfigDTO shopMerchantDirectorConfigDTO = ShopMerchantDirectorConfigDTO.builder().directorType(DirectorTypeEnum.FLIGHT_SUPERVISION.getValue())
ShopMerchantDirectorConfigDTO shopMerchantDirectorConfigDTO = ShopMerchantDirectorConfigDTO.builder()
.directorTypes(Arrays.asList(DirectorTypeEnum.FLIGHT_SUPERVISION.getValue(),DirectorTypeEnum.FLIGHT_SUPERVISION_2_1.getValue()))
.directorUserId(pagination.getCondition().getSupervisorUuid()).merchantName(pagination.getCondition().getMerchantName())
.deletedFlag(BaseModel.DeletedFlagEnum.N.name()).build();
List<MerchantAreaOperatorDTO> merchantAreaOperatorDTOList = shopMerchantDirectorConfigService.listFlightSupervisorMerchantInfo(shopMerchantDirectorConfigDTO);
......
......@@ -122,6 +122,12 @@
<if test="directorType != null">
and mdc.director_type = #{directorType,jdbcType=TINYINT}
</if>
<if test="directorTypes != null and directorTypes.size()>0">
and mdc.director_type in
<foreach collection="directorTypes" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="directorUserId != null and directorUserId != ''">
and mdc.director_user_id = #{directorUserId,jdbcType=VARCHAR}
</if>
......
  • @wangxw1
    commented
    Master

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

    1. 潜在的 Dubbo 接口兼容性风险(高危)

    • 问题描述:当前项目为 RPC 服务提供者(rpc-dj-smartcarlife),代码中使用了 ShopMerchantDirectorConfigDTO 的新字段 directorTypes。这表明该 DTO 的数据结构发生了变更(新增了字段)。根据核心审查规则:Dubbo 服务提供者 Remote 接口中的已有请求参数变更视为危险实现。
    • 影响分析:如果该 DTO 被用作 Dubbo 暴露接口的入参,虽然新增字段在 Java 序列化/Hessian 中通常是向下兼容的,但如果在此次修改中删除了原有的 directorType 字段或更改了其类型,将直接导致旧版本消费端调用报错(反序列化失败或找不到方法)。
    • 优化建议:
      1. 严格确认 ShopMerchantDirectorConfigDTO 中是否保留了原有的 directorType 字段,绝对不能删除或修改旧字段,以保证向下兼容。
      2. 建议在该 DTO 的 directorType 字段上标记 @Deprecated(如果未来计划废弃),并通知所有消费端升级。

    2. MyBatis 动态 SQL 存在条件冲突隐患(中等)

    • 问题描述:在 ShopMerchantDirectorConfigMapper.xml 中,新增了对 directorTypes 的 <if> 判断,但它是与原有的 directorType 并列使用 AND 连接的。
    • 影响分析:如果其他业务场景复用该查询时,传入的 DTO 同时包含了 directorType(旧逻辑)和 directorTypes(新逻辑),SQL 将被渲染为 and mdc.director_type = ? and mdc.director_type in (?, ?)。如果这两个条件的值不一致,将导致查询结果永远为空,引发隐蔽的业务 Bug。
    • 优化建议:建议在 XML 中使用 <choose> 标签进行互斥判断,优先使用集合查询,或者在 Java 业务层确保这两个参数不会同时被赋值。 xml <choose> <when test="directorTypes != null and directorTypes.size() > 0"> and mdc.director_type in <foreach collection="directorTypes" item="item" open="(" separator="," close=")"> #{item} </foreach> </when> <when test="directorType != null"> and mdc.director_type = #{directorType,jdbcType=TINYINT} </when> </choose>

    3. 提交信息(Commit Message)缺乏业务上下文(低)

    • 问题描述:提交信息为 "优化查询飞行督导逻辑 (by fanfr)",过于简略。
    • 影响分析:无法从 commit 信息中看出本次修改的核心原因(即为何需要引入 FLIGHT_SUPERVISION_2_1 这个新的枚举类型进行联合查询)。随着时间推移,这会增加代码的可追溯成本和后期的维护难度。
    • 优化建议:建议遵循规范的 Commit 格式,说明“做了什么”以及“为什么做”。例如:feat: 优化飞行督导查询逻辑,兼容新增的 FLIGHT_SUPERVISION_2_1 类型数据,以支持XX业务场景。

    二、评分明细

    • 功能实现的正确性与健壮性(36/40分): 业务逻辑修改正确,能够实现多类型的联合查询。未发现 MyBatis 使用子查询(符合红线规则)。扣分点在于 XML 动态 SQL 的并列条件在特定场景下可能引发逻辑冲突。
    • 安全性与潜在风险(24/30分): SQL 注入防护良好(使用了 #{} 和 foreach 构建 IN 条件)。扣分点主要在于 DTO 结构变更触发了 Dubbo 接口参数变更的危险警告,需高度关注接口兼容性。
    • 最佳实践与可维护性(18/20分): 代码整洁,变量命名规范,Arrays.asList() 使用得当。Mapper XML 的缩进稍有不齐,但整体可读性良好。
    • 性能与资源利用(5/5分): IN 查询的集合元素极少(仅2个),不会造成数据库性能瓶颈,资源利用合理,无额外内存浪费。
    • 提交信息质量(3/5分): 提交信息存在,但过于单薄,缺乏对新增枚举类型的业务背景说明。

    总分:86分

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