mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-25 20:35:35 +08:00
fixed: 资源的列表无分类筛选 && 分类资源数量计算
This commit is contained in:
@@ -5,23 +5,24 @@
|
||||
<mapper namespace="xyz.playedu.api.mapper.ResourceMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.Resource">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="adminId" column="admin_id" jdbcType="INTEGER"/>
|
||||
<result property="type" column="type" jdbcType="VARCHAR"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="extension" column="extension" jdbcType="VARCHAR"/>
|
||||
<result property="size" column="size" jdbcType="BIGINT"/>
|
||||
<result property="disk" column="disk" jdbcType="VARCHAR"/>
|
||||
<result property="fileId" column="file_id" jdbcType="VARCHAR"/>
|
||||
<result property="path" column="path" jdbcType="VARCHAR"/>
|
||||
<result property="url" column="url" jdbcType="VARCHAR"/>
|
||||
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="parentId" column="parent_id" jdbcType="INTEGER"/>
|
||||
<result property="isHidden" column="is_hidden" jdbcType="TINYINT"/>
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="adminId" column="admin_id" jdbcType="INTEGER"/>
|
||||
<result property="type" column="type" jdbcType="VARCHAR"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="extension" column="extension" jdbcType="VARCHAR"/>
|
||||
<result property="size" column="size" jdbcType="BIGINT"/>
|
||||
<result property="disk" column="disk" jdbcType="VARCHAR"/>
|
||||
<result property="fileId" column="file_id" jdbcType="VARCHAR"/>
|
||||
<result property="path" column="path" jdbcType="VARCHAR"/>
|
||||
<result property="url" column="url" jdbcType="VARCHAR"/>
|
||||
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="parentId" column="parent_id" jdbcType="INTEGER"/>
|
||||
<result property="isHidden" column="is_hidden" jdbcType="TINYINT"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,admin_id,type,
|
||||
id
|
||||
,admin_id,type,
|
||||
name,extension,size,
|
||||
disk,file_id,path,
|
||||
url,created_at,parent_id,
|
||||
@@ -33,15 +34,122 @@
|
||||
FROM `resources`
|
||||
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
|
||||
WHERE `resources`.`type` = #{type}
|
||||
AND `resources`.`is_hidden` = 0
|
||||
GROUP BY `resource_category`.`cid`;
|
||||
</select>
|
||||
|
||||
<select id="getNoneCategoryCount" resultType="java.lang.Integer">
|
||||
SELECT count(DISTINCT `resources`.`id`) AS `total`
|
||||
<select id="getNunCategoryCount" resultType="java.lang.Integer">
|
||||
SELECT count(1) AS `total`
|
||||
FROM `resources`
|
||||
LEFT JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
|
||||
WHERE `resources`.`type` = #{type}
|
||||
AND `resource_category`.`cid` IS NULL;
|
||||
AND `resources`.`is_hidden` = 0
|
||||
AND `resource_category`.`rid` IS NULL;
|
||||
</select>
|
||||
|
||||
<select id="paginate" resultType="xyz.playedu.api.domain.Resource">
|
||||
SELECT `resources`.*
|
||||
FROM `resources`
|
||||
<choose>
|
||||
<when test="categoryIds != null and categoryIds != ''">
|
||||
<choose>
|
||||
<when test="categoryIds.indexOf('0') == 0">
|
||||
LEFT JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
|
||||
WHERE `resources`.`is_hidden` = 0
|
||||
AND `resource_category`.`cid` IS NULL
|
||||
</when>
|
||||
<otherwise>
|
||||
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
|
||||
WHERE `resources`.`is_hidden` = 0
|
||||
AND `resource_category`.`cid` IN (#{categoryIds})
|
||||
</otherwise>
|
||||
</choose>
|
||||
</when>
|
||||
<otherwise>
|
||||
WHERE `resources`.`is_hidden` = 0
|
||||
</otherwise>
|
||||
</choose>
|
||||
<if test="name != null and name != ''">
|
||||
AND `resources`.`name` LIKE concat('%',#{name},'%')
|
||||
</if>
|
||||
<if test="disk != null and disk != ''">
|
||||
AND `resources`.`disk` = #{disk}
|
||||
</if>
|
||||
<if test="extension != null and extension != ''">
|
||||
AND `resources`.`extension` = #{extension}
|
||||
</if>
|
||||
<if test="type != null and type != ''">
|
||||
AND `resources`.`type` = #{type}
|
||||
</if>
|
||||
<if test="adminId != null and adminId != 0">
|
||||
AND `resources`.`admin_id` = #{adminId}
|
||||
</if>
|
||||
<if test="sortAlgo == 'asc'">
|
||||
<choose>
|
||||
<when test="sortField == 'size'">
|
||||
ORDER BY `resources`.`size` ASC
|
||||
</when>
|
||||
<when test="sortField == 'created_at'">
|
||||
ORDER BY `resources`.`size` ASC
|
||||
</when>
|
||||
<otherwise>
|
||||
ORDER BY `resources`.`id` ASC
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="sortAlgo != 'asc'">
|
||||
<choose>
|
||||
<when test="sortField == 'size'">
|
||||
ORDER BY `resources`.`size` DESC
|
||||
</when>
|
||||
<when test="sortField == 'created_at'">
|
||||
ORDER BY `resources`.`size` DESC
|
||||
</when>
|
||||
<otherwise>
|
||||
ORDER BY `resources`.`id` DESC
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
LIMIT #{pageStart}, #{pageSize};
|
||||
</select>
|
||||
|
||||
<select id="paginateCount" resultType="java.lang.Long">
|
||||
SELECT count(1)
|
||||
FROM `resources`
|
||||
<choose>
|
||||
<when test="categoryIds != null and categoryIds != ''">
|
||||
<choose>
|
||||
<when test="categoryIds.indexOf('0') == 0">
|
||||
LEFT JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
|
||||
WHERE `resources`.`is_hidden` = 0
|
||||
AND `resource_category`.`cid` IS NULL
|
||||
</when>
|
||||
<otherwise>
|
||||
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
|
||||
WHERE `resources`.`is_hidden` = 0
|
||||
AND `resource_category`.`cid` IN (#{categoryIds})
|
||||
</otherwise>
|
||||
</choose>
|
||||
</when>
|
||||
<otherwise>
|
||||
WHERE `resources`.`is_hidden` = 0
|
||||
</otherwise>
|
||||
</choose>
|
||||
<if test="name != null and name != ''">
|
||||
AND `resources`.`name` LIKE concat('%',#{name},'%')
|
||||
</if>
|
||||
<if test="disk != null and disk != ''">
|
||||
AND `resources`.`disk` = #{disk}
|
||||
</if>
|
||||
<if test="extension != null and extension != ''">
|
||||
AND `resources`.`extension` = #{extension}
|
||||
</if>
|
||||
<if test="type != null and type != ''">
|
||||
AND `resources`.`type` = #{type}
|
||||
</if>
|
||||
<if test="adminId != null and adminId != 0">
|
||||
AND `resources`.`admin_id` = #{adminId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user