Commit 9f4cff7f by 林冲

Merge branch 'v5.8.1' into 'master'

上线合并

See merge request !21
2 parents e59f733c 0945a04f
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
</parent> </parent>
<groupId>cn.com.glsx</groupId> <groupId>cn.com.glsx</groupId>
<artifactId>rpc-dj-mindworkplate-api</artifactId> <artifactId>rpc-dj-mindworkplate-api</artifactId>
<version>5.8.0-SNAPSHOT</version> <version>5.8.1-SNAPSHOT</version>
<name>rpc-dj-mindworkplate-api</name> <name>rpc-dj-mindworkplate-api</name>
<properties> <properties>
<deploy.scanPackage>cn.com.glsx.remote</deploy.scanPackage> <deploy.scanPackage>cn.com.glsx.remote</deploy.scanPackage>
......
...@@ -5,6 +5,7 @@ import java.math.BigDecimal; ...@@ -5,6 +5,7 @@ import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import javax.persistence.*; import javax.persistence.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -100,4 +101,13 @@ public class StaffBeisenSourse implements Serializable { ...@@ -100,4 +101,13 @@ public class StaffBeisenSourse implements Serializable {
@ApiModelProperty(notes = "课程的总学分") @ApiModelProperty(notes = "课程的总学分")
private Double totalCredit; private Double totalCredit;
@ApiModelProperty(notes = "发布时间")
@Column(name = "publish_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date publishTime;
@ApiModelProperty(notes = "标签名称")
@Transient
private String tagName;
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.mindworkplate.model.course; package cn.com.glsx.dj.mindworkplate.model.course;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.ToString; import lombok.ToString;
...@@ -27,4 +31,15 @@ public class CourseSearchReuqestDTO implements Serializable { ...@@ -27,4 +31,15 @@ public class CourseSearchReuqestDTO implements Serializable {
private String staffPhone; private String staffPhone;
@ApiModelProperty(notes = "课程目录")
private String categoryName;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(notes = "北森课程发布开始时间")
private Date publishTimeStart;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(notes = "北森课程发布结束时间")
private Date publishTimeEnd;
} }
...@@ -51,12 +51,12 @@ ...@@ -51,12 +51,12 @@
<dependency> <dependency>
<groupId>cn.com.glsx</groupId> <groupId>cn.com.glsx</groupId>
<artifactId>rpc-dj-mindworkplate-api</artifactId> <artifactId>rpc-dj-mindworkplate-api</artifactId>
<version>5.7.5-SNAPSHOT</version> <version>5.8.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.com.glsx.dj</groupId> <groupId>cn.com.glsx.dj</groupId>
<artifactId>rpc-dj-smartcarlife-api</artifactId> <artifactId>rpc-dj-smartcarlife-api</artifactId>
<version>5.7.5-SNAPSHOT</version> <version>5.8.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.com.glsx.dj</groupId> <groupId>cn.com.glsx.dj</groupId>
......
...@@ -93,7 +93,7 @@ public class StaffTagCourseService { ...@@ -93,7 +93,7 @@ public class StaffTagCourseService {
CourseSearchReuqestDTO condition = rpcPagination.getCondition(); CourseSearchReuqestDTO condition = rpcPagination.getCondition();
parseCourseIdByStaffPhone(condition); parseCourseIdByStaffPhone(condition);
parseCourseIdByTagId(condition); parseCourseIdByTagId(condition);
log.info("查询课程参数:{}", condition); log.info("查询课程参数:{}", rpcPagination);
Page<StaffBeisenSourse> page = PageHelper.startPage(rpcPagination.getPageNum(), Page<StaffBeisenSourse> page = PageHelper.startPage(rpcPagination.getPageNum(),
rpcPagination.getPageSize()); rpcPagination.getPageSize());
staffBeisenSourseMapper.findStaffTagCoursePage(condition); staffBeisenSourseMapper.findStaffTagCoursePage(condition);
...@@ -268,6 +268,7 @@ public class StaffTagCourseService { ...@@ -268,6 +268,7 @@ public class StaffTagCourseService {
entity.setCourseStatus(item.getCourseStatus()); entity.setCourseStatus(item.getCourseStatus());
entity.setCreatedDate(item.getCreatedDate()); entity.setCreatedDate(item.getCreatedDate());
entity.setUpdatedDate(item.getModifiedDate()); entity.setUpdatedDate(item.getModifiedDate());
entity.setPublishTime(item.getPublishTime());
entity.setDeletedFlag("N"); entity.setDeletedFlag("N");
entity.setRecommendStatus(item.getRecommendStatus()); entity.setRecommendStatus(item.getRecommendStatus());
entity.setTotalChapter(item.getTotalChapter()); entity.setTotalChapter(item.getTotalChapter());
......
...@@ -18,25 +18,27 @@ ...@@ -18,25 +18,27 @@
<result column="total_chapter" property="totalChapter" jdbcType="INTEGER" /> <result column="total_chapter" property="totalChapter" jdbcType="INTEGER" />
<result column="total_duration" property="totalDuration" jdbcType="DECIMAL" /> <result column="total_duration" property="totalDuration" jdbcType="DECIMAL" />
<result column="course_file_type" property="courseFileType" jdbcType="VARCHAR" /> <result column="course_file_type" property="courseFileType" jdbcType="VARCHAR" />
<result column="publish_time" property="publishTime" jdbcType="TIMESTAMP" />
<result column="tag_name" property="tagName" jdbcType="VARCHAR" />
</resultMap> </resultMap>
<sql id="Base_Column_List" > <sql id="Base_Column_List" >
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
course_title, course_id, course_status, created_by, created_date, updated_by, total_credit, course_title, course_id, course_status, created_by, created_date, updated_by, total_credit,
updated_date, deleted_flag,catalog_name,recommend_status,total_chapter,total_duration,course_file_type updated_date, deleted_flag,catalog_name,recommend_status,total_chapter,total_duration,course_file_type, publish_time
</sql> </sql>
<update id="batchSaveOrUpdate"> <update id="batchSaveOrUpdate">
INSERT INTO staff_beisen_course ( INSERT INTO staff_beisen_course (
course_title, course_id, course_status, course_title, course_id, course_status,
created_by, created_date, updated_by, updated_date, deleted_flag,catalog_name, created_by, created_date, updated_by, updated_date, deleted_flag,catalog_name,
course_file_type, recommend_status, total_duration, total_chapter, total_credit course_file_type, recommend_status, total_duration, total_chapter, total_credit, publish_time
) )
VALUES VALUES
<foreach collection="entityList" item="item" separator=","> <foreach collection="entityList" item="item" separator=",">
(#{item.courseTitle}, #{item.courseId}, #{item.courseStatus}, (#{item.courseTitle}, #{item.courseId}, #{item.courseStatus},
#{item.createdBy}, #{item.createdDate}, #{item.updatedBy}, #{item.updatedDate}, #{item.deletedFlag},#{item.catalogName}, #{item.createdBy}, #{item.createdDate}, #{item.updatedBy}, #{item.updatedDate}, #{item.deletedFlag},#{item.catalogName},
#{item.courseFileType},#{item.recommendStatus},#{item.totalDuration},#{item.totalChapter},#{item.totalCredit} #{item.courseFileType},#{item.recommendStatus},#{item.totalDuration},#{item.totalChapter},#{item.totalCredit},#{item.publishTime}
) )
</foreach> </foreach>
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
...@@ -49,14 +51,19 @@ ...@@ -49,14 +51,19 @@
recommend_status = VALUES(recommend_status), recommend_status = VALUES(recommend_status),
total_duration = VALUES(total_duration), total_duration = VALUES(total_duration),
total_chapter = VALUES(total_chapter), total_chapter = VALUES(total_chapter),
total_credit = VALUES(total_credit) total_credit = VALUES(total_credit),
publish_time = VALUES(publish_time)
</update> </update>
<select id="findStaffTagCoursePage" parameterType="cn.com.glsx.dj.mindworkplate.model.course.CourseSearchReuqestDTO" <select id="findStaffTagCoursePage" parameterType="cn.com.glsx.dj.mindworkplate.model.course.CourseSearchReuqestDTO"
resultMap="BaseResultMap"> resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> bc.*,
group_concat(distinct bct.tag_name) as tag_name
from staff_beisen_course bc from staff_beisen_course bc
where 1=1 and bc.course_status=40 left join staff_beisen_course_tag bct on bct.course_id = bc.course_id and bct.deleted_flag = "N"
where 1=1
and bc.deleted_flag = "N"
and bc.course_status=40
<if test="condition.courseName != null"> <if test="condition.courseName != null">
and bc.course_title like concat('%',#{condition.courseName},'%') and bc.course_title like concat('%',#{condition.courseName},'%')
</if> </if>
...@@ -67,13 +74,23 @@ ...@@ -67,13 +74,23 @@
</foreach> </foreach>
</if> </if>
<if test="condition.tagSearch != null and condition.tagSearch != ''"> <if test="condition.tagSearch != null and condition.tagSearch != ''">
and and exists (
( select 1 from staff_beisen_course_tag bct_filter
bc.course_title like concat('%', #{condition.tagSearch} ,'%') where bct_filter.course_id = bc.course_id
or and bct_filter.deleted_flag = "N"
exists(select 1 from staff_beisen_course_tag bct where bct.deleted_flag = "N" and bct.tag_name like concat('%',#{condition.tagSearch},'%') and bct.course_id = bc.course_id) and bct_filter.tag_name like concat('%',#{condition.tagSearch},'%')
) )
</if> </if>
<if test="condition.categoryName != null and condition.categoryName != ''">
and bc.catalog_name = #{condition.categoryName}
</if>
<if test="condition.publishTimeStart != null">
and bc.publish_time &gt;= #{condition.publishTimeStart}
</if>
<if test="condition.publishTimeEnd != null">
and bc.publish_time &lt; #{condition.publishTimeEnd}
</if>
group by bc.course_id
</select> </select>
<select id="findStaffTagCourseByCondition" resultMap="BaseResultMap"> <select id="findStaffTagCourseByCondition" resultMap="BaseResultMap">
select select
......
  • @wangxw1
    commented
    Master

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

    1. 严重违规:MyBatis SQL 中使用了禁止的子查询(最高优先级)

    • 问题描述:在 StaffBeisenSourseMapper.xml 的 findStaffTagCoursePage 方法中,针对 condition.tagSearch 的条件判断使用了 EXISTS (select 1 from staff_beisen_course_tag ...) 子查询。这直接违反了“mybatis的sql语句不允许使用子查询”的硬性规定。
    • 影响分析:子查询(尤其是 EXISTS 或 IN 相关的相关子查询)在数据量增大时极易引发严重的性能瓶颈,导致慢 SQL,且不利于数据库查询优化器的索引选择。
    • 优化建议:消除子查询,改用 JOIN 来实现标签的过滤。由于主查询已经对 course_id 进行了 GROUP BY,可以通过 INNER JOIN 或在现有的 LEFT JOIN 基础上配合 HAVING 子句来实现过滤。
    • 代码示例: xml <!-- 建议移除 EXISTS 子查询,改为通过 JOIN 过滤 --> <if test="condition.tagSearch != null and condition.tagSearch != ''"> <!-- 方式一:增加一个专门用于过滤的 INNER JOIN --> INNER JOIN staff_beisen_course_tag bct_filter ON bct_filter.course_id = bc.course_id AND bct_filter.deleted_flag = 'N' AND bct_filter.tag_name LIKE concat('%',#{condition.tagSearch},'%') </if>

    2. 危险实现:Dubbo 接口请求参数模型发生变更

    • 问题描述:在 rpc-dj-mindworkplate-api 模块中,CourseSearchReuqestDTO 类新增了 categoryName、publishTimeStart、publishTimeEnd 三个字段。这触碰了“dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现”的规则。
    • 影响分析:虽然在 Dubbo (Hessian2 序列化) 中新增字段通常是向下兼容的,但直接修改 API 包中的已有 DTO 仍然存在风险。如果消费端未同步升级 API 依赖版本,传递的旧版 DTO 到达提供者时新字段将为 null。如果服务端的业务逻辑强依赖这些新字段且未做严格的判空处理,可能会导致 NPE。
    • 优化建议:
      1. 必须确保所有调用该接口的消费端(Consumer)知晓此次变更,并评估是否需要同步升级 5.8.1-SNAPSHOT 版本。
      2. 确保服务提供方(Provider)的逻辑对新增字段做好了完善的兼容和判空处理(当前 XML 中已加 <if test="... != null">,此点基本满足,但需警惕 Java 代码中的直接调用)。

    3. 最佳实践与稳定性风险:使用 SELECT * 配合 GROUP BY

    • 问题描述:在 StaffBeisenSourseMapper.xml 的 findStaffTagCoursePage 查询中,将原本明确的 <include refid="Base_Column_List" /> 替换为了 bc.*,并且在末尾新增了 group by bc.course_id。
    • 影响分析:
      1. SELECT * 是工程实践中的反模式,会增加不必要的网络传输开销和内存占用,且表结构变更时容易引发隐蔽的映射错误。
      2. 在 MySQL 5.7 及以上版本中,如果开启了 ONLY_FULL_GROUP_BY 模式,SELECT bc.* 配合 GROUP BY bc.course_id 只有在 course_id 是主键或具有唯一约束时才合法,否则会直接报 SQL 语法错误,存在生产环境报错的隐患。
    • 优化建议:避免使用 bc.*,恢复使用具体的字段列表,为避免字段名冲突,可以给 Base_Column_List 中的字段加上表别名。
    • 代码示例: xml <!-- 建议将 base column 加上别名,或者显式写出需要的字段 --> select bc.course_title, bc.course_id, bc.course_status, ... (列出具体字段), bc.publish_time, group_concat(distinct bct.tag_name) as tag_name from staff_beisen_course bc ...

    二、评分明细

    • 功能实现的正确性与健壮性(25/40分): 扣分主要在于直接违反了“不允许使用子查询”的硬性规定(扣15分)。业务逻辑(如分页、条件判断)基本正确,但底层 SQL 实现方式违规。
    • 安全性与潜在风险(20/30分): 触发了“Dubbo 接口已有请求参数变更”的危险行为规则(扣10分)。虽然新增字段在序列化层面通常兼容,但属于高危变更操作,需严格评估上下游影响。
    • 最佳实践与可维护性(15/20分): 代码结构基本清晰,但在 SQL 映射文件中使用了 SELECT * 这种不推荐的写法,且与 GROUP BY 混用存在环境兼容性风险(扣5分)。
    • 性能与资源利用(3/5分): EXISTS 子查询和 SELECT * 均会对数据库性能和网络资源造成不必要的损耗(扣2分)。
    • 提交信息质量(5/5分): Commit message 非常详尽,严格遵循了 Angular 规范(feat/fix),清晰列出了修改点和目的,可追溯性极强(满分)。

    总分:68分

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