From 3524bd78770d3dd16b8be3e4fa9cba06a42cefa0 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Thu, 25 Jan 2024 14:52:25 +0800
Subject: [PATCH] 住户监管柱状图

---
 src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml |   93 +++++++++++++++++++++++++---------------------
 1 files changed, 51 insertions(+), 42 deletions(-)

diff --git a/src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml b/src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml
index fd241a2..5709e20 100644
--- a/src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml
+++ b/src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml
@@ -28,28 +28,26 @@
         <result column="has_children" property="hasChildren"/>
     </resultMap>
 
-    <resultMap id="treeNodeResultMap" type="org.springblade.core.tool.node.TreeNode">
+    <resultMap id="treeNodeResultMap" type="org.springblade.modules.system.vo.DeptVO">
         <id column="id" property="id"/>
         <result column="parent_id" property="parentId"/>
         <result column="title" property="title"/>
-        <result column="value" property="value"/>
-        <result column="key" property="key"/>
         <result column="has_children" property="hasChildren"/>
     </resultMap>
 
     <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,40 +65,51 @@
     </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>
-
-        <if test="param2!=null and param2!=''">
-            and parent_id = #{param2}
-        </if>
-
-        <if test="param3!=null and param3!=''">
-            and id = #{param3}
-        </if>
-        ORDER BY sort
+        SELECT
+        a.id,
+        a.dept_name AS title,
+        a.parent_id,
+        b.id,
+        IF
+        ( b.id > 0, FALSE, TRUE ) disabled
+        FROM
+        blade_dept a
+        LEFT JOIN (
+        SELECT
+        id,
+        dept_name AS title,
+        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
+        ) b ON a.id = b.id
+        WHERE
+        is_deleted = 0
+        AND tenant_id = #{param1}  ORDER BY a.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,
+        (
+        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
+        parent_id = dept.id and is_deleted = 0
+        ) AS "has_children"
+        FROM
+        blade_dept dept
+        WHERE
+        dept.parent_id = #{param2} AND dept.is_deleted = 0
         <if test="param1!=null and param1!=''">
             and dept.tenant_id = #{param1}
         </if>

--
Gitblit v1.9.3