cloudroam
2025-05-26 25f83d7e36573da46bade5f54315797aa9c9e6cb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mzl.flower.mapper.film.FilmCategoryMapper">
 
    <resultMap id="BaseResultMap" type="com.mzl.flower.entity.film.FilmCategory">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="parent_id" property="parentId"/>
        <result column="parent_name" property="parentName"/>
        <result column="image_url" property="imageUrl"/>
        <result column="sort_by" property="sortBy"/>
        <result column="shown" property="shown"/>
        <result column="level_limit" property="levelLimit"/>
        <result column="create_by" property="createdBy"/>
        <result column="create_time" property="createdTime"/>
        <result column="update_by" property="updatedBy"/>
        <result column="update_time" property="updatedTime"/>
        <result column="deleted" property="deleted"/>
    </resultMap>
 
    <sql id="Base_Column_List">
        c.id, c.name, c.parent_id, c.parent_name, c.image_url, c.sort_by, c.shown, c.level_limit,
        c.create_by, c.create_time, c.update_by, c.update_time, c.deleted
    </sql>
 
    <select id="selectCategoryList" resultType="com.mzl.flower.dto.response.film.FilmCategoryTreeDTO">
        SELECT 
            <include refid="Base_Column_List"/>,
            (SELECT COUNT(1) FROM t_film_category f WHERE f.parent_id = c.id AND f.deleted = 0) childrenCount
        FROM t_film_category c
        WHERE c.deleted = 0
        <if test="name != null and name != ''">
            AND (
                c.name LIKE CONCAT('%', #{name}, '%')
                OR EXISTS (
                    SELECT 1 FROM t_film_category sc
                    WHERE sc.parent_id = c.id 
                    AND sc.name LIKE CONCAT('%', #{name}, '%')
                    AND sc.deleted = 0
                )
            )
        </if>
        <if test="parentId != null">
            AND c.parent_id = #{parentId}
        </if>
        <if test="shown != null">
            AND c.shown = #{shown}
        </if>
        ORDER BY c.sort_by ASC, c.create_time DESC
    </select>
 
    <select id="selectTreeList" resultType="com.mzl.flower.dto.response.film.FilmCategoryTreeDTO">
        SELECT 
            <include refid="Base_Column_List"/>,
            (SELECT COUNT(1) FROM t_film_category f WHERE f.parent_id = c.id AND f.deleted = 0) childrenCount
        FROM t_film_category c
        WHERE c.deleted = 0
        <if test="name != null and name != ''">
            AND c.name LIKE CONCAT('%', #{name}, '%')
        </if>
        <if test="parentId != null">
            AND c.parent_id = #{parentId}
        </if>
        <if test="shown != null">
            AND c.shown = #{shown}
        </if>
        ORDER BY c.sort_by ASC, c.create_time DESC
    </select>
 
</mapper>