Commit 8c93de95 by 林永健

feat(service-center): 新增课程目录查询功能并优化课程搜索功能

- 添加课程配置-查询所有课程目录列表接口
- 在StaffTagCourseSearchReuqest中新增发布时间和课程目录字段
- 升级smartcarlife.api.version到5.8.1-SNAPSHOT
- 在StaffBeisenSourse实体类中添加发布时间字段映射
- 优化数据库映射文件,添加发布时间字段和标签名称字段
- 在CourseSearchReuqestDTO中新增课程目录和发布时间范围查询参数
- 在StaffBeisenSourse模型中新增发布时间和标签名称属性
- 升级mindworkplate-api版本到5.8.1-SNAPSHOT
- 在StaffStudyCourseMapper中新增listCourseCategories方法
- 在ContentManagerTaskService中实现课程目录列表查询功能
- 优化课程搜索逻辑,支持按目录名称和发布时间范围筛选
- 在StaffStudyCourseDTO中新增发布时间相关字段
- 完善课程目录查询的SQL映射配置
1 parent e653508b
...@@ -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.7.4-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.4-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.0-SNAPSHOT</version> <version>5.8.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.com.glsx.dj</groupId> <groupId>cn.com.glsx.dj</groupId>
......
...@@ -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,20 @@ ...@@ -49,14 +51,20 @@
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" /> <include refid="Base_Column_List" />
, 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
where 1=1
and bc.deleted_flag = "N"
and bct.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,12 +75,16 @@ ...@@ -67,12 +75,16 @@
</foreach> </foreach>
</if> </if>
<if test="condition.tagSearch != null and condition.tagSearch != ''"> <if test="condition.tagSearch != null and condition.tagSearch != ''">
and and bct.tag_name like concat('%',#{condition.tagSearch},'%')
( </if>
bc.course_title like concat('%', #{condition.tagSearch} ,'%') <if test="condition.categoryName != null condition.categoryName and != ''">
or and bc.catalog_name = #{condition.categoryName}
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) </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> </if>
</select> </select>
<select id="findStaffTagCourseByCondition" resultMap="BaseResultMap"> <select id="findStaffTagCourseByCondition" resultMap="BaseResultMap">
......
  • @wangxw1
    commented
    Master

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

    1. MyBatis 语法错误与 SQL 聚合逻辑严重缺陷(极其重要)

    • 问题描述:
      1. 语法错误:StaffBeisenSourseMapper.xml 中 <if test="condition.categoryName != null condition.categoryName and != ''"> 存在明显的 OGNL 表达式语法错误(多余的 condition.categoryName and)。
      2. 缺少 GROUP BY:SQL 查询列中使用了聚合函数 group_concat(distinct bct.tag_name),但整个 SQL 语句缺少 GROUP BY 子句。
    • 影响分析: 语法错误会导致 MyBatis 在启动或运行时解析 XML 失败,直接抛出异常;缺少 GROUP BY 会导致 MySQL 将所有匹配的记录压缩成单行结果返回,完全破坏了分页和列表查询功能。
    • 优化建议: 修复 OGNL 语法,并按主表的主键或唯一标识进行分组。 ```xml <!-- 修复语法错误 --> and bc.catalog_name = #{condition.categoryName}

    <!-- 在 SQL 末尾(条件之后)添加 GROUP BY --> GROUP BY bc.course_id

    
    #### 2. LEFT JOIN 退化为 INNER JOIN 导致数据丢失
    - **问题描述**:
      在 `StaffBeisenSourseMapper.xml` 的 `findStaffTagCoursePage` 方法中,使用了 `left join staff_beisen_course_tag bct`,但在全局的 `where` 条件中直接写了 `and bct.deleted_flag = "N"`。
    - **影响分析**:
      在 `where` 子句中对 `LEFT JOIN` 的右表字段进行过滤,会导致 `LEFT JOIN` 隐式转换为 `INNER JOIN`。这意味着**没有标签的课程将无法被查询出来**,严重偏离了业务预期的外连接语义。
    - **优化建议**:
      将右表的过滤条件移至 `ON` 子句中。
      ```xml
      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
    

    3. 搜索业务逻辑回归(丢失了课程标题搜索)

    • 问题描述: 原代码中 tagSearch 条件的逻辑是:匹配 course_title 或 子查询中的 tag_name。重构为了消除子查询(符合规范),直接关联了标签表,但 <if test="condition.tagSearch != null...> 中的逻辑变成了仅匹配 bct.tag_name。
    • 影响分析: 破坏了原有的搜索逻辑。用户在前端输入关键字搜索课程时,如果关键字是课程标题,将无法搜索到任何结果。
    • 优化建议: 在使用 LEFT JOIN 的基础上,恢复原有的 OR 逻辑。 xml <if test="condition.tagSearch != null and condition.tagSearch != ''"> and ( bc.course_title like concat('%', #{condition.tagSearch} ,'%') or bct.tag_name like concat('%', #{condition.tagSearch} ,'%') ) </if>

    二、评分明细

    • 功能实现的正确性与健壮性(10/40分) 扣分严重。代码存在致命的 OGNL 语法错误,且缺少 GROUP BY 导致聚合查询逻辑完全崩溃;LEFT JOIN 过滤条件位置错误导致数据丢失;重构去除了子查询(符合规范),但丢失了原有的 course_title 搜索条件,引发了业务逻辑回归。代码在当前状态下无法正常运行。

    • 安全性与潜在风险(30/30分) 满分。SQL 参数均使用了 `#{}安全绑定,不存在 SQL 注入风险;Dubbo 接口的 Request DTO 仅进行了字段新增,未修改或删除已有字段,符合向下兼容原则,未触发危险实现规则。

    • 最佳实践与可维护性(15/20分) 良好。使用 GROUP_CONCAT 替代子查询关联标签是解决 N+1 和子查询规范的合理思路。扣分点在于 CourseSearchReuqestDTO 类名存在拼写错误(Reuqest 应为 Request),虽然可能是历史遗留问题,但建议在合适的时机进行重构。

    • 性能与资源利用(3/5分) 一般。将子查询优化为 LEFT JOIN + GROUP_CONCAT 有助于提升数据库执行效率,但在 1对N 关系较大的情况下,GROUP_CONCAT 可能会受限于 MySQL 的 group_concat_max_len 配置,需确保标签数量在安全范围内。

    • 提交信息质量(5/5分) 优秀。Commit 信息采用了 Conventional Commits 规范(feat(...)),清晰详尽地列出了所有变更点,可追溯性极强。

    总分:63分

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