Commit d9ec7f43 by chenxi

5.8.6 采购管理列表、导出新增商品ID字段

1 parent f22c777a
...@@ -170,4 +170,7 @@ public class PurchaseOrderPageDTO extends PurchaseOrder { ...@@ -170,4 +170,7 @@ public class PurchaseOrderPageDTO extends PurchaseOrder {
@ApiModelProperty(notes = "供应商名称,模糊搜索") @ApiModelProperty(notes = "供应商名称,模糊搜索")
private String thirdPartyName; private String thirdPartyName;
@ApiModelProperty(notes = "产品ID(升级商品编码),精确匹配采购订单商品 upgrade_goods_commodity_code")
private String commodityCode;
} }
...@@ -18,6 +18,11 @@ public class PurchaseOrderGoodsExportDTO implements Serializable{ ...@@ -18,6 +18,11 @@ public class PurchaseOrderGoodsExportDTO implements Serializable{
private String upgradeGoodsName; private String upgradeGoodsName;
/** /**
* 产品ID(升级商品编码)
*/
private String upgradeGoodsCommodityCode;
/**
* 产品别名 * 产品别名
*/ */
private String purchaseGoodsName; private String purchaseGoodsName;
......
...@@ -250,6 +250,15 @@ ...@@ -250,6 +250,15 @@
and dclpog.is_allocate = 1 and dclpog.is_allocate = 1
) )
</if> </if>
<if test="commodityCode != null and commodityCode != ''">
and exists(
select 1
from dj_car_life_purchase_order_goods dclpog
where dclpog.order_code = po.order_code
and dclpog.deleted_flag = 'N'
and dclpog.upgrade_goods_commodity_code like CONCAT('%', #{commodityCode},'%')
)
</if>
</sql> </sql>
<sql id="List_Condition_NoSubquery"> <sql id="List_Condition_NoSubquery">
......
  • @wangxw1
    commented
    Master

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

    1. 严重违反规范:MyBatis 语句使用了子查询

    • 问题描述:在 PurchaseOrderMapper.xml 文件中,新增的 commodityCode 查询条件使用了 exists (select 1 from ...) 结构。这直接违反了本次代码审查的强制规则:“mybatis的sql语句不允许使用子查询”。
    • 影响分析:子查询在部分数据库版本中可能导致执行计划不够优化,引发性能瓶颈。同时违反了团队既定的开发红线规范。
    • 优化建议:将子查询改造为 JOIN 关联查询(需注意去重),或者在 Java 代码层进行分步查询处理(先查出符合条件的 order_code 集合,再作为主查询的 IN 条件)。
    • 代码示例(基于 JOIN 的改造思路): xml <!-- 建议在主查询的 FROM/JOIN 部分进行关联,而不是在 WHERE 中使用 EXISTS --> <!-- 并在主查询增加 DISTINCT 或 GROUP BY 以防止主表数据重复 --> INNER JOIN dj_car_life_purchase_order_goods dclpog ON dclpog.order_code = po.order_code AND dclpog.deleted_flag = 'N'

    2. 逻辑缺陷:API 注释说明与实际 SQL 查询逻辑相悖

    • 问题描述:在 PurchaseOrderPageDTO.java 中,commodityCode 字段的 Swagger 注释明确写明为:“精确匹配采购订单商品...”。但在 PurchaseOrderMapper.xml 中,实际的 SQL 却使用了模糊查询 like CONCAT('%', #{commodityCode},'%')。
    • 影响分析:代码实现与接口文档/业务预期不一致。如果业务确实需要精确匹配,模糊查询会导致查出错误的数据;且前后带有 % 的模糊查询会导致索引失效,引发全表扫描。
    • 优化建议:根据实际业务需求对齐代码与注释。如果是精确匹配,请将 SQL 改为等值查询。
    • 代码示例(假设以注释要求的“精确匹配”为准): xml <if test="commodityCode != null and commodityCode != ''"> <!-- 假设已改为 JOIN 结构或外部传入,条件应改为精确匹配 --> and dclpog.upgrade_goods_commodity_code = #{commodityCode} </if>

    二、评分明细

    • 功能实现的正确性与健壮性(20/40分) 扣分理由:触犯了“MyBatis 不允许使用子查询”的强制红线规则;且 DTO 注释要求的“精确匹配”与底层 SQL 实现的“模糊匹配”逻辑存在明显冲突,可能导致业务查询结果不符合预期。

    • 安全性与潜在风险(30/30分) 得分理由:SQL 参数传递使用了 #{} 安全预编译语法,不存在 SQL 注入风险;新增字段为常规业务数据,未见越权或敏感信息泄露隐患。

    • 最佳实践与可维护性(17/20分) 扣分理由:代码注释与实际执行逻辑不一致,这在团队协作中会给前端对接或后期维护带来误导,降低了代码的可维护性。

    • 性能与资源利用(2/5分) 扣分理由:EXISTS 子查询在特定场景下存在性能隐患;同时 LIKE '%...%' 这种前缀带通配符的模糊查询会导致索引失效,在订单商品表数据量较大时极易引发慢 SQL。

    • 提交信息质量(4/5分) 得分理由:Commit 信息(5.8.6 采购管理列表、导出新增商品ID字段 (by chenxi))包含了版本号、业务模块、具体改动点及提交人,较为清晰可追溯。

    总分:73分

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