From 84e908b9f0800b6c18aa951b515683ccbb13d10f Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期二, 03 六月 2025 13:56:08 +0800
Subject: [PATCH] mysql中find_in_set改成PostgreSQL 的 string_to_array + = ANY()

---
 ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml                |    4 ++--
 ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml                |    2 +-
 ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java |    6 ++++--
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
index b2337c9..0f56ad6 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
@@ -135,8 +135,10 @@
             }
             else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope))
             {
-                sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", deptAlias, user.getDeptId(), user.getDeptId()));
-            }
+                sqlString.append(StringUtils.format(
+                        " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} OR {} = ANY(string_to_array(ancestors, ',')::bigint[]) )",
+                        deptAlias, user.getDeptId(), user.getDeptId()
+                ));            }
             else if (DATA_SCOPE_SELF.equals(dataScope))
             {
                 if (StringUtils.isNotBlank(userAlias))
diff --git a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
index 02fddc5..d4f9464 100644
--- a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
@@ -75,11 +75,11 @@
 	</select>
 	
 	<select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
-		select * from sys_dept where find_in_set(#{deptId}, ancestors)
+		select * from sys_dept where #{deptId} = ANY(string_to_array(ancestors, ',')::bigint[])
 	</select>
 	
 	<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
-		select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
+		select count(*) from sys_dept where status = 0 and del_flag = '0' and #{deptId} = ANY(string_to_array(ancestors, ',')::bigint[])
 	</select>
 	
 	<select id="checkDeptNameUnique" resultMap="SysDeptResult">
diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
index 3cac427..d44c977 100644
--- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
@@ -79,7 +79,7 @@
 			AND date_format(u.create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
 		</if>
 		<if test="deptId != null and deptId != 0">
-			AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
+			AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE #{deptId} = ANY(string_to_array(t.ancestors, ',')::bigint[]) ))
 		</if>
 		<!-- 鏁版嵁鑼冨洿杩囨护 -->
 		${params.dataScope}

--
Gitblit v1.9.3