Commit 467293ae by 庞善天

mapper增加映射

1 parent 9c55f565
...@@ -72,7 +72,35 @@ ...@@ -72,7 +72,35 @@
and deadline <= #{now} and deadline <= #{now}
</update> </update>
<select id="getByMsgBosId" resultType="cn.com.glsx.dj.mindworkplate.model.sop.SopShortCourseTask"> <resultMap id="TaskMap" type="cn.com.glsx.dj.mindworkplate.model.sop.SopShortCourseTask">
<id column="id" property="id" />
<result column="short_course_config_id" property="shortCourseConfigId" />
<result column="staff_name" property="staffName" />
<result column="staff_phone" property="staffPhone" />
<result column="superiors" property="superiors" />
<result column="mentors" property="mentors" />
<result column="entry_date" property="entryDate" />
<result column="merchant_name" property="merchantName" />
<result column="defeat_customer_names" property="defeatCustomerNames" />
<result column="tag_names" property="tagNames" />
<result column="check_date" property="checkDate" />
<result column="task_status" property="taskStatus" />
<result column="progress" property="progress" />
<result column="msg_bos_id" property="msgBosId" />
<result column="complete_time" property="completeTime" />
<result column="deadline" property="deadline" />
<result column="punish_type" property="punishType" />
<result column="punish_status" property="punishStatus" />
<result column="punish_flag" property="punishFlag" />
<result column="bussiness_type" property="bussinessType" />
<result column="created_by" property="createdBy" />
<result column="created_date" property="createdDate" />
<result column="updated_by" property="updatedBy" />
<result column="updated_date" property="updatedDate" />
<result column="deleted_flag" property="deletedFlag" />
</resultMap>
<select id="getByMsgBosId" resultMap="TaskMap">
select * select *
from sop_short_course_task from sop_short_course_task
where deleted_flag = 'N' where deleted_flag = 'N'
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议

    • 问题 1:在 SQL 语句中使用 SELECT * 导致性能与稳定性风险

      • 问题描述:getByMsgBosId 查询语句中使用了 select *。
      • 影响分析:违反了 SQL 开发的最佳实践。当表结构变更(如增加大字段)时,会产生不必要的网络 IO 开销和内存消耗;同时,SELECT * 无法利用覆盖索引,在大数据量情况下可能导致查询性能下降。
      • 优化建议:应在 SQL 中明确列出业务所需的具体字段名,避免使用通配符。 xml <select id="getByMsgBosId" resultMap="TaskMap"> select id, short_course_config_id, staff_name, staff_phone, ... -- 列出具体字段 from sop_short_course_task where deleted_flag = 'N' and msg_bos_id = #{msgBosId} </select>
    • 问题 2:冗余的 ResultMap 配置

      • 问题描述:代码中新增了详尽的 TaskMap,但观察映射关系,字段名与属性名均遵循标准的“下划线转驼峰”规则。
      • 影响分析:如果项目中已开启 MyBatis 的 mapUnderscoreToCamelCase 全局配置,这种手动的 resultMap 是多余的。它不仅增加了 XML 文件的体积,还带来了额外的维护成本——每当数据库增加字段时,开发者必须同步修改 resultMap,否则会导致字段映射缺失。
      • 优化建议:若全局配置已开启,建议保留原有的 resultType 方式;若确需手动映射(如存在非标准映射),请确保 resultMap 包含所有业务字段,并配合明确的字段列表查询。
    • 问题 3:提交信息(Commit Message)质量低下

      • 问题描述:Commit 信息为 "mapper增加映射 (by pangst)"。
      • 影响分析:提交信息过于简略,未说明“为什么要将 resultType 改为 resultMap”这一核心意图(例如是为了解决映射失效、准备做多表关联,还是其他原因)。此外,在 Git 信息中手动标注 "(by xxx)" 属于冗余信息。
      • 优化建议:应遵循标准的提交规范,例如:refactor(mapper): 为 SopShortCourseTask 显式定义 ResultMap 以规范字段映射。

    二、评分明细

    • 功能实现的正确性与健壮性(38分):逻辑正确,未发现子查询。扣分项主要是 select * 在表结构变更时可能带来的不确定性。
    • 安全性与潜在风险(30分):使用 #{} 占位符,无 SQL 注入风险,未发现敏感信息泄露。
    • 最佳实践与可维护性(12分):扣分较多。主要原因是引入了可能不必要的冗余配置(ResultMap),且未使用显式字段列表。
    • 性能与资源利用(4分):select * 存在潜在的 IO 与内存资源浪费。
    • 提交信息质量(2分):信息过于简单,缺乏变更动机说明,不符合专业工程实践。

    总分:86分

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