linwei
2024-01-31 b3b566ebdfed4005aaa513da3d5d2fd3924903cc
src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml
@@ -39,17 +39,17 @@
    <select id="lazyList" resultMap="deptVOResultMap">
        SELECT
            dept.* ,
            (
                SELECT
                    CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
                FROM
                    blade_dept
                WHERE
                    parent_id = dept.id and is_deleted = 0
            ) AS "has_children"
        dept.* ,
        (
        SELECT
        CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
        FROM
            blade_dept dept
        blade_dept
        WHERE
        parent_id = dept.id and is_deleted = 0
        ) AS "has_children"
        FROM
        blade_dept dept
        WHERE dept.is_deleted = 0
        <if test="param1!=null and param1!=''">
            and dept.tenant_id = #{param1}
@@ -67,43 +67,59 @@
    </select>
    <select id="tree" resultMap="treeNodeResultMap">
        select id, parent_id, dept_name as title, id as "value", id as "key" from blade_dept where is_deleted = 0
        <if test="param1!=null and param1!=''">
            and tenant_id = #{param1}
        <if test="param2!=null">
            SELECT
            id,
            dept_name AS title,
            id AS "value",
            id AS "key",
            parent_id
            FROM
            ( SELECT * FROM blade_dept WHERE is_deleted = 0 AND tenant_id = #{param1} ORDER BY parent_id, id )
            org_query,
            ( SELECT @id := #{param2} ) initialisation
            WHERE
            (FIND_IN_SET( parent_id, @id ) > 0 or FIND_IN_SET( id, @id ) > 0)
            AND @id := CONCAT(@id,',',id) ORDER BY sort
        </if>
        <if test="param2!=null and param2!=''">
            and parent_id = #{param2}
        <if test="param2==null">
            select id, parent_id, dept_name as title, id as "value", id as "key" from blade_dept where is_deleted = 0
            <if test="param1!=null and param1!=''">
                and tenant_id = #{param1}
            </if>
            ORDER BY sort
        </if>
        <if test="param3!=null and param3!=''">
            and id = #{param3}
        </if>
        ORDER BY sort
    </select>
    <select id="lazyTree" resultMap="treeNodeResultMap" >
    <select id="lazyTree" resultMap="treeNodeResultMap">
        SELECT
            dept.id,
            dept.parent_id,
            dept.dept_name AS title,
            dept.id AS "value",
            dept.id AS "key",
            (
                SELECT
                    CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
                FROM
                    blade_dept
                WHERE
                    parent_id = dept.id and is_deleted = 0
            ) AS "has_children"
        dept.id,
        dept.parent_id,
        dept.dept_name AS title,
        dept.id AS "value",
        dept.id AS "key",
        (
        SELECT
        CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
        FROM
            blade_dept dept
        blade_dept
        WHERE
            dept.parent_id = #{param2} AND dept.is_deleted = 0
        <if test="param1!=null and param1!=''">
            and dept.tenant_id = #{param1}
        </if>
        parent_id = dept.id and is_deleted = 0
        ) AS "has_children"
        FROM
        blade_dept dept
        <where>
            <if test="param2!=null and param2!=''">
                and dept.parent_id = #{param2}
            </if>
            AND dept.is_deleted = 0
            <if test="param1!=null and param1!=''">
                and dept.tenant_id = #{param1}
            </if>
        </where>
        ORDER BY dept.sort
    </select>