From 2d928646669fe6026c7d63f6b409d9b2790aa65e Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期五, 19 七月 2024 16:09:20 +0800
Subject: [PATCH] feat:设置部门管理员报错解决

---
 src/main/resources/mapper/UserMapper.xml |   24 ++++++++----------------
 1 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml
index 4797580..1a1de5d 100644
--- a/src/main/resources/mapper/UserMapper.xml
+++ b/src/main/resources/mapper/UserMapper.xml
@@ -523,18 +523,10 @@
     </update>
 
     <update id="cancelUserDeptAdmin">
-        update t_user set role = 1 where id in(
-            select user_id from t_user_department where department_id = #{id} and user_id not in
-            <foreach collection="adminIds" item="id" open="(" separator="," close=")">
-                #{id}
-            </foreach>
-             and user_id not in
-            (select user_id from t_user_department where dept_admin = 1 and user_id in
-            (select user_id from t_user_department where department_id = #{id} and user_id not in
-           <foreach collection="adminIds" item="id" open="(" separator="," close=")">
-                #{id}
-            </foreach>
-        )))
+        update t_user set role = 1 where id in
+        <foreach collection="userIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
     </update>
 
     <select id="getDeptAdminIds" resultType="java.lang.Integer" parameterType="java.lang.Integer">
@@ -551,10 +543,10 @@
             dept_admin = 1 and user_id = #{userId}
     </select>
 
-    <select id="getDeptAdmins" resultType="com.mindskip.xzs.domain.Department" parameterType="java.lang.Integer">
-        <if test="id != null">
+    <select id="getDeptAdmins" resultType="com.mindskip.xzs.domain.Department">
+        <if test="ids != null and ids.size() != 0">
         WITH RECURSIVE temp_table AS (
-        select a.id, a.name, a.parent_id from t_department a inner join t_user_department b on a.id = b.department_id where a.deleted = 0 and b.dept_admin = 1 and b.user_id = #{id}
+        select a.id, a.name, a.parent_id from t_department a WHERE id IN <foreach collection="ids" item="id" open="(" separator="," close=")"> #{id} </foreach>
         UNION ALL
         SELECT
         so.id, so.name, so.parent_id FROM t_department so INNER JOIN temp_table tb ON so.parent_id = tb.id
@@ -564,7 +556,7 @@
         FROM
         temp_table
         </if>
-        <if test="id == null">
+        <if test="ids == null or ids.size() == 0">
         select a.id, a.name, a.parent_id from t_department a where a.deleted = 0 order by a.id
         </if>
     </select>

--
Gitblit v1.8.0