linwe
2024-08-09 8b7258c9427882bb1798f1502eaa35184c6e374e
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?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="org.springblade.modules.label.mapper.LabelMapper">
 
    <!--自定义列表-->
    <select id="selectLabelPage" resultType="org.springblade.modules.label.vo.LabelVO">
        select * from jczz_label where 1=1
    </select>
 
    <!--标签查询,按父id查询下级 mysql 5.7 有时会查询无结果-->
<!--    <select id="getLabelList" resultType="org.springblade.common.node.TreeIntegerNode">-->
<!--        SELECT-->
<!--            jl.id as id,jl.parent_id as parentId,jl.label_name as name-->
<!--        FROM-->
<!--            (-->
<!--            SELECT-->
<!--                @ids AS ids,-->
<!--                ( SELECT @ids := GROUP_CONCAT( id ) FROM jczz_label WHERE FIND_IN_SET( parent_id, @ids ) ) AS cids-->
<!--            FROM-->
<!--                jczz_label-->
<!--            WHERE-->
<!--                @ids IS NOT NULL-->
<!--                AND @ids := #{label.parentId}-->
<!--            ) id,-->
<!--            jczz_label jl-->
<!--        WHERE-->
<!--            FIND_IN_SET(jl.parent_id,ids)-->
<!--    </select>-->
 
    <!--标签查询,按父id查询下级-->
    <select id="getLabelList" resultType="org.springblade.common.node.TreeIntegerNode">
        SELECT
            jl.id as id,jl.parent_id as parentId,jl.label_name as name,
            (
                SELECT
                    CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
                FROM
                    jczz_label
                WHERE
                    parent_id = jl.id and is_deleted = 0
            ) AS hasChildren
        FROM
         jczz_label jl
        where is_deleted = 0
        and parent_id = #{label.parentId}
    </select>
 
    <!--标签查询,按父id查询下级-->
    <select id="getChildrenLabelList" resultType="org.springblade.common.node.TreeIntegerNode">
        SELECT
            jl.id as id,jl.parent_id as parentId,jl.label_name as name,
            (
                SELECT
                    CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
                FROM
                    jczz_label
                WHERE
                    parent_id = jl.id and is_deleted = 0
            ) AS hasChildren
        FROM
         jczz_label jl
        where is_deleted = 0
        and parent_id in
        <foreach collection="list" separator="," item="id" open="(" close=")">
            #{id}
        </foreach>
    </select>
 
 
    <select id="getLabelTreeList" resultType="org.springblade.common.node.TreeIntegerNode">
        SELECT
            jl.id AS id,
            jl.parent_id AS parentId,
            jl.label_name AS NAME,
            jl.sort,
            (SELECT count(1) from jczz_user_house_label where label_id = jl.id ) count
        FROM
            jczz_label jl  where is_deleted = 0
            and jl.id != '1002'
            order by jl.sort desc
    </select>
 
    <!--查询人员标签(不包含人这一级)-->
    <select id="getPersonLabelList" resultType="org.springblade.common.node.TreeIntegerNode">
        SELECT
            jl.id AS id,
            jl.parent_id AS parentId,
            jl.label_name AS NAME,
            jl.sort,
            (SELECT count(1) from jczz_user_house_label where label_id = jl.id ) count,
            (
                SELECT
                    CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
                FROM
                    jczz_label
                WHERE
                    parent_id = jl.id and is_deleted = 0
            ) AS hasChildren
        FROM
            jczz_label jl  where is_deleted = 0
            and jl.id != '1002'
            and jl.id != '1000'
            order by jl.sort desc
    </select>
 
 
</mapper>