From 2cba01a6b6f67cfa97d0c4e0cc589302fab817ba Mon Sep 17 00:00:00 2001
From: aix <vip_xiaobin810@163.com>
Date: Wed, 24 Jul 2024 11:41:37 +0800
Subject: [PATCH] 查询有变形水库

---
 skjcmanager/skjcmanager-service/skjcmanager-system/src/main/java/cn/gistack/system/mapper/DeptMapper.xml |  110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 109 insertions(+), 1 deletions(-)

diff --git a/skjcmanager/skjcmanager-service/skjcmanager-system/src/main/java/cn/gistack/system/mapper/DeptMapper.xml b/skjcmanager/skjcmanager-service/skjcmanager-system/src/main/java/cn/gistack/system/mapper/DeptMapper.xml
index 654eb1d..182a709 100644
--- a/skjcmanager/skjcmanager-service/skjcmanager-system/src/main/java/cn/gistack/system/mapper/DeptMapper.xml
+++ b/skjcmanager/skjcmanager-service/skjcmanager-system/src/main/java/cn/gistack/system/mapper/DeptMapper.xml
@@ -13,6 +13,7 @@
         <result column="sort" property="sort"/>
         <result column="remark" property="remark"/>
         <result column="is_deleted" property="isDeleted"/>
+        <result column="ad_code" property="adCode"/>
     </resultMap>
 
     <resultMap id="deptVOResultMap" type="cn.gistack.system.vo.DeptVO">
@@ -26,6 +27,7 @@
         <result column="remark" property="remark"/>
         <result column="is_deleted" property="isDeleted"/>
         <result column="has_children" property="hasChildren"/>
+        <result column="ad_code" property="adCode"/>
     </resultMap>
 
     <resultMap id="treeNodeResultMap" type="org.springblade.core.tool.node.TreeNode">
@@ -74,6 +76,22 @@
         ORDER BY sort
     </select>
 
+    <select id="treeByParentId" 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="parentIds!=null and parentIds!=''">
+            and
+
+            <foreach item="id" collection="parentIds" open="(" separator="or" close=")">
+                id = #{id} or parent_id = #{id} or parent_id in (
+                select b.id from blade_dept b where b.is_deleted = 0 and b.PARENT_ID = #{id}
+                )
+
+            </foreach>
+
+        </if>
+        ORDER BY sort
+    </select>
+
     <select id="lazyTree" resultMap="treeNodeResultMap" >
         SELECT
             dept.id,
@@ -92,7 +110,10 @@
         FROM
             blade_dept dept
         WHERE
-            dept.parent_id = #{param2} AND dept.is_deleted = 0
+        <foreach item="id" collection="param2" open="(" separator="or" close=")">
+            dept.parent_id = #{id}
+        </foreach>
+             AND dept.is_deleted = 0
         <if test="param1!=null and param1!=''">
             and dept.tenant_id = #{param1}
         </if>
@@ -112,4 +133,91 @@
         and is_deleted = 0
     </select>
 
+    <!--查询组织机构树数据(下级包含人员信息)-->
+    <select id="getDeptAndUserTree" resultType="cn.gistack.common.node.DeptUserTreeNode">
+        (
+            SELECT
+            dept.id,
+            dept.parent_id parentId,
+            dept.dept_name AS name,
+            0 AS phone,
+            (
+                SELECT
+                CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
+                FROM
+                blade_dept
+                WHERE
+                parent_id = dept.id and is_deleted = 0
+            ) AS hasChildren
+            FROM
+            blade_dept dept WHERE dept.is_deleted = 0
+            <if test="treeNode.id!=null and treeNode.id!=''">
+                and dept.id = #{treeNode.id}
+            </if>
+        )
+        union
+        (
+            select
+            bu.id,
+            bu.dept_id parentId,
+            bu.account AS name,
+            bu.phone,
+            0 as hasChildren
+            from blade_user bu left join blade_dept bd on bd.id = bu.dept_id
+            where 1=1 and bu.is_deleted = 0 and bu.status = 1
+            <if test="treeNode.id!=null and treeNode.id!=''">
+                and bu.dept_id like concat(concat('%',#{treeNode.id}),'%')
+            </if>
+        )
+    </select>
+
+    <!--查询组织机构树-->
+    <select id="getDeptMap" resultType="cn.gistack.common.node.DeptUserTreeNode">
+        SELECT
+        dept.id,
+        dept.parent_id parentId,
+        dept.dept_name AS name,
+        1 as isMan,
+        0 AS phone,
+        (
+            SELECT
+            CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
+            FROM
+            blade_dept
+            WHERE
+            parent_id = dept.id and is_deleted = 0
+        ) AS hasChildren
+        FROM
+        blade_dept dept WHERE dept.is_deleted = 0
+        <if test="treeNode.id!=null and treeNode.id!=''">
+            and dept.id = #{treeNode.id}
+        </if>
+    </select>
+
+    <!--查询组织机构树数据(下级包含人员信息)(排除组织机构对应不上的人员)-->
+    <select id="getUserMap" resultType="cn.gistack.common.node.DeptUserTreeNode">
+        select
+        bu.id,
+        bu.dept_id parentId,
+        bu.real_name AS name,
+        bu.phone,
+        2 as isMan,
+        0 as hasChildren
+        from blade_user bu join blade_dept bd on find_in_set(bu.dept_id,bd.id)
+        where 1=1 and bu.is_deleted = 0 and bu.status = 1
+        <if test="treeNode.id!=null and treeNode.id!=''">
+            and bu.dept_id like concat(concat('%',#{treeNode.id}),'%')
+        </if>
+    </select>
+    <select id="getResDept" resultType="java.lang.String">
+
+        SELECT WM_CONCAT(res_guid)
+        FROM blade_dept where res_guid is not null and res_guid != ''
+        and id in
+        <foreach collection="deptIds.split(',')" item="item" index="index" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+
+    </select>
+
 </mapper>

--
Gitblit v1.9.3