优化线上课列表

This commit is contained in:
none
2023-03-18 21:08:29 +08:00
parent 0689c0d428
commit 17d18da19b
6 changed files with 167 additions and 62 deletions

View File

@@ -5,19 +5,20 @@
<mapper namespace="xyz.playedu.api.mapper.CourseMapper">
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.Course">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="title" column="title" jdbcType="VARCHAR"/>
<result property="thumb" column="thumb" jdbcType="VARCHAR"/>
<result property="charge" column="charge" jdbcType="INTEGER"/>
<result property="classHour" column="class_hour" jdbcType="INTEGER"/>
<result property="isShow" column="is_show" jdbcType="TINYINT"/>
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
<result property="deletedAt" column="deleted_at" jdbcType="TIMESTAMP"/>
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="title" column="title" jdbcType="VARCHAR"/>
<result property="thumb" column="thumb" jdbcType="VARCHAR"/>
<result property="charge" column="charge" jdbcType="INTEGER"/>
<result property="classHour" column="class_hour" jdbcType="INTEGER"/>
<result property="isShow" column="is_show" jdbcType="TINYINT"/>
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
<result property="deletedAt" column="deleted_at" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id,title,thumb,
id
,title,thumb,
charge,class_hour,is_show,
created_at,updated_at,deleted_at
</sql>
@@ -27,4 +28,142 @@
FROM `resource_course_category`
GROUP BY `resource_course_category`.`category_id`;
</select>
<select id="paginate" resultType="xyz.playedu.api.domain.Course">
SELECT `courses`.*
FROM `courses`
<if test="depIds != null and depIds != ''">
<choose>
<when test="depIds.indexOf('0')==0">
LEFT JOIN `course_department` ON `course_department`.`course_id` = `courses`.`id`
</when>
<otherwise>
INNER JOIN `course_department` ON `course_department`.`course_id` = `courses`.`id`
</otherwise>
</choose>
</if>
<if test="categoryIds != null and categoryIds != ''">
<choose>
<when test="categoryIds.indexOf('0')==0">
LEFT JOIN `resource_course_category` ON `resource_course_category`.`course_id` = `courses`.`id`
</when>
<otherwise>
INNER JOIN `resource_course_category` ON `resource_course_category`.`course_id` = `courses`.`id`
</otherwise>
</choose>
</if>
<where>
<if test="depIds != null and depIds != ''">
<choose>
<when test="depIds.indexOf('0')==0">
AND `course_department`.`course_id` IS NULL
</when>
<otherwise>
AND `course_department`.`dep_id` IN (#{depIds})
</otherwise>
</choose>
</if>
<if test="categoryIds != null and categoryIds != ''">
<choose>
<when test="categoryIds.indexOf('0')==0">
AND `resource_course_category`.`course_id` IS NULL
</when>
<otherwise>
AND `resource_course_category`.`category_id` IN (#{categoryIds})
</otherwise>
</choose>
</if>
<if test="title != null and title != ''">
AND `courses`.`title` LIKE concat('%',#{title},'%')
</if>
</where>
<if test="sortAlgo == 'asc'">
<choose>
<when test="sortField == 'charge'">
ORDER BY `courses`.`charge` ASC
</when>
<when test="sortField == 'class_hour'">
ORDER BY `courses`.`class_hour` ASC
</when>
<when test="sortField == 'created_at'">
ORDER BY `courses`.`created_at` ASC
</when>
<otherwise>
ORDER BY `courses`.`id` ASC
</otherwise>
</choose>
</if>
<if test="sortAlgo != 'asc'">
<choose>
<when test="sortField == 'charge'">
ORDER BY `courses`.`charge` DESC
</when>
<when test="sortField == 'class_hour'">
ORDER BY `courses`.`class_hour` DESC
</when>
<when test="sortField == 'created_at'">
ORDER BY `courses`.`created_at` DESC
</when>
<otherwise>
ORDER BY `courses`.`id` ASC
</otherwise>
</choose>
</if>
LIMIT #{pageStart}, #{pageSize};
</select>
<select id="paginateCount" resultType="java.lang.Long">
SELECT count(1)
FROM `courses`
<if test="depIds != null and depIds != ''">
<choose>
<when test="depIds.indexOf('0')==0">
LEFT JOIN `course_department` ON `course_department`.`course_id` = `courses`.`id`
</when>
<otherwise>
INNER JOIN `course_department` ON `course_department`.`course_id` = `courses`.`id`
</otherwise>
</choose>
</if>
<if test="categoryIds != null and categoryIds != ''">
<choose>
<when test="categoryIds.indexOf('0')==0">
LEFT JOIN `resource_course_category` ON `resource_course_category`.`course_id` = `courses`.`id`
</when>
<otherwise>
INNER JOIN `resource_course_category` ON `resource_course_category`.`course_id` = `courses`.`id`
</otherwise>
</choose>
</if>
<where>
<if test="depIds != null and depIds != ''">
<choose>
<when test="depIds.indexOf('0')==0">
AND `course_department`.`course_id` IS NULL
</when>
<otherwise>
AND `course_department`.`dep_id` IN (#{depIds})
</otherwise>
</choose>
</if>
<if test="categoryIds != null and categoryIds != ''">
<choose>
<when test="categoryIds.indexOf('0')==0">
AND `resource_course_category`.`course_id` IS NULL
</when>
<otherwise>
AND `resource_course_category`.`category_id` IN (#{categoryIds})
</otherwise>
</choose>
</if>
<if test="title != null and title != ''">
AND `courses`.`title` LIKE concat('%',#{title},'%')
</if>
</where>
</select>
</mapper>