serv\web- 多租户修改
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
<result column="dept_id" property="deptID" jdbcType="VARCHAR"/>
|
||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="parent_id" property="parentID" jdbcType="VARCHAR"/>
|
||||
<result column="dept_path" property="deptPath" jdbcType="VARCHAR"/>
|
||||
<result column="description" property="description" jdbcType="VARCHAR"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
@@ -19,7 +20,7 @@
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, dept_id, name, parent_id, description, creator, updater,
|
||||
id, dept_id, name, parent_id, dept_path, description, creator, updater,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
@@ -39,14 +40,54 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectDepts -->
|
||||
<!-- 权限过滤条件(基于dept_path的高效继承) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_resource_permission rp ON d.dept_id = rp.resource_id
|
||||
AND rp.resource_type = 4
|
||||
AND rp.deleted = 0
|
||||
AND rp.can_read = 1
|
||||
AND (
|
||||
-- 全局权限:所有用户可访问
|
||||
(rp.dept_id IS NULL AND rp.role_id IS NULL)
|
||||
<if test="userDeptRoles != null and userDeptRoles.size() > 0">
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM (
|
||||
<foreach collection="userDeptRoles" item="udr" separator=" UNION ALL ">
|
||||
SELECT #{udr.deptID} AS dept_id, #{udr.deptPath} AS dept_path, #{udr.roleID} AS role_id
|
||||
</foreach>
|
||||
) user_roles
|
||||
LEFT JOIN tb_sys_dept perm_dept ON perm_dept.dept_id = rp.dept_id AND perm_dept.deleted = 0
|
||||
WHERE
|
||||
-- 部门级权限:当前部门或父部门(通过dept_path判断继承关系)
|
||||
(rp.role_id IS NULL AND rp.dept_id IS NOT NULL
|
||||
AND user_roles.dept_path LIKE CONCAT(perm_dept.dept_path, '%'))
|
||||
-- 角色级权限:跨部门的角色权限
|
||||
OR (rp.dept_id IS NULL AND rp.role_id = user_roles.role_id)
|
||||
-- 精确权限:特定部门的特定角色
|
||||
OR (rp.dept_id = user_roles.dept_id AND rp.role_id = user_roles.role_id)
|
||||
)
|
||||
</if>
|
||||
)
|
||||
</sql>
|
||||
|
||||
<!-- selectDepts - 添加权限过滤 -->
|
||||
|
||||
<select id="selectDepts">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_dept
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY dept_id,create_time DESC
|
||||
SELECT DISTINCT d.*
|
||||
FROM tb_sys_dept d
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE d.deleted = 0
|
||||
<if test="filter.deptID != null and filter.deptID != ''">
|
||||
AND d.dept_id = #{filter.deptID}
|
||||
</if>
|
||||
<if test="filter.parentID != null and filter.parentID != ''">
|
||||
AND d.parent_id = #{filter.parentID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND d.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
ORDER BY d.dept_id, d.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据父部门ID查询子部门列表 -->
|
||||
@@ -95,64 +136,63 @@
|
||||
create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 批量删除部门(逻辑删除) -->
|
||||
<update id="batchDeleteByIds">
|
||||
UPDATE tb_sys_dept
|
||||
SET deleted = 1,
|
||||
delete_time = NOW(),
|
||||
updater = #{updater}
|
||||
WHERE deleted = 0
|
||||
AND dept_id IN
|
||||
<foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 插入部门 -->
|
||||
<insert id="insert" parameterType="org.xyzh.common.dto.dept.TbSysDept">
|
||||
INSERT INTO tb_sys_dept
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="deptID != null">dept_id,</if>
|
||||
<if test="parentID != null">parent_id,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="description != null">description,</if>
|
||||
<if test="creator != null">creator,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<!-- insertDept -->
|
||||
<insert id="insertDept" parameterType="org.xyzh.common.dto.dept.TbSysDept">
|
||||
INSERT INTO tb_sys_dept (
|
||||
id,
|
||||
dept_id,
|
||||
name,
|
||||
parent_id,
|
||||
dept_path,
|
||||
description,
|
||||
creator,
|
||||
create_time,
|
||||
deleted
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="deptID != null">#{deptID},</if>
|
||||
<if test="parentID != null">#{parentID},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="description != null">#{description},</if>
|
||||
<if test="creator != null">#{creator},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
0
|
||||
</trim>
|
||||
) VALUES (
|
||||
#{id},
|
||||
#{deptID},
|
||||
#{name},
|
||||
#{parentID},
|
||||
#{deptPath},
|
||||
#{description},
|
||||
#{creator},
|
||||
#{createTime},
|
||||
#{deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 更新部门 -->
|
||||
<update id="updateById" parameterType="org.xyzh.common.dto.dept.TbSysDept">
|
||||
<!-- updateDept -->
|
||||
<update id="updateDept" parameterType="org.xyzh.common.dto.dept.TbSysDept">
|
||||
UPDATE tb_sys_dept
|
||||
<set>
|
||||
<if test="deptID != null">dept_id = #{deptID},</if>
|
||||
<if test="parentID != null">parent_id = #{parentID},</if>
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
<if test="name != null and name != ''">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="parentID != null">
|
||||
parent_id = #{parentID},
|
||||
</if>
|
||||
<if test="deptPath != null">
|
||||
dept_path = #{deptPath},
|
||||
</if>
|
||||
<if test="description != null">
|
||||
description = #{description},
|
||||
</if>
|
||||
<if test="updater != null">
|
||||
updater = #{updater},
|
||||
</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE dept_id = #{deptID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 根据ID删除(逻辑删除) -->
|
||||
<update id="deleteById">
|
||||
UPDATE tb_sys_dept
|
||||
<!-- deleteDept - 逻辑删除 -->
|
||||
<update id="deleteDept" parameterType="org.xyzh.common.dto.dept.TbSysDept">
|
||||
UPDATE tb_sys_dept
|
||||
SET deleted = 1,
|
||||
delete_time = NOW()
|
||||
<if test="updater != null">
|
||||
, updater = #{updater}
|
||||
</if>
|
||||
WHERE dept_id = #{deptID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -39,11 +39,29 @@
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectDeptRoleList">
|
||||
<!-- 部门角色VO结果映射 -->
|
||||
<resultMap id="DeptRoleVOResultMap" type="org.xyzh.common.vo.UserDeptRoleVO">
|
||||
<result column="dept_id" property="deptID" jdbcType="VARCHAR"/>
|
||||
<result column="dept_name" property="deptName" jdbcType="VARCHAR"/>
|
||||
<result column="dept_description" property="deptDescription" jdbcType="VARCHAR"/>
|
||||
<result column="role_id" property="roleID" jdbcType="VARCHAR"/>
|
||||
<result column="role_name" property="roleName" jdbcType="VARCHAR"/>
|
||||
<result column="role_description" property="roleDescription" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectDeptRoleList" resultMap="DeptRoleVOResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_dept_role
|
||||
ORDER BY dept_id, role_id, create_time DESC
|
||||
dr.dept_id,
|
||||
d.name AS dept_name,
|
||||
d.description AS dept_description,
|
||||
dr.role_id,
|
||||
r.name AS role_name,
|
||||
r.description AS role_description
|
||||
FROM tb_sys_dept_role dr
|
||||
LEFT JOIN tb_sys_dept d ON dr.dept_id = d.dept_id AND d.deleted = 0
|
||||
LEFT JOIN tb_sys_role r ON dr.role_id = r.role_id AND r.deleted = 0
|
||||
WHERE dr.deleted = 0
|
||||
ORDER BY dr.dept_id, dr.role_id, dr.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- batchBindDeptRole -->
|
||||
@@ -65,4 +83,81 @@
|
||||
(#{deptRole.deptID}, #{deptRole.roleID})
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- selectParentDeptAdmin -->
|
||||
|
||||
<select id="selectParentDeptAdmin">
|
||||
WITH RECURSIVE dept_hierarchy AS (
|
||||
-- 基础查询:查询起始部门
|
||||
SELECT
|
||||
dept_id,
|
||||
parent_id,
|
||||
name,
|
||||
description,
|
||||
1 AS level
|
||||
FROM tb_sys_dept
|
||||
WHERE dept_id = #{deptID}
|
||||
AND deleted = 0
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 递归查询:查询父级部门
|
||||
SELECT
|
||||
d.dept_id,
|
||||
d.parent_id,
|
||||
d.name,
|
||||
d.description,
|
||||
dh.level + 1 AS level
|
||||
FROM tb_sys_dept d
|
||||
INNER JOIN dept_hierarchy dh ON d.dept_id = dh.parent_id
|
||||
WHERE d.deleted = 0
|
||||
AND d.parent_id IS NOT NULL
|
||||
)
|
||||
SELECT
|
||||
dh.dept_id AS deptID,
|
||||
tsdr.role_id
|
||||
FROM dept_hierarchy dh
|
||||
INNER JOIN tb_sys_dept_role tsdr ON dh.dept_id = tsdr.dept_id
|
||||
WHERE tsdr.role_id = 'admin'
|
||||
AND tsdr.deleted = 0
|
||||
ORDER BY level DESC
|
||||
</select>
|
||||
|
||||
<!-- selectChildDeptRole -->
|
||||
|
||||
<select id="selectChildDeptRole">
|
||||
WITH RECURSIVE dept_hierarchy AS (
|
||||
-- 基础查询:查询起始部门
|
||||
SELECT
|
||||
dept_id,
|
||||
parent_id,
|
||||
name,
|
||||
description,
|
||||
1 AS level
|
||||
FROM tb_sys_dept
|
||||
WHERE dept_id = #{deptID}
|
||||
AND deleted = 0
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 递归查询:查询子级部门
|
||||
SELECT
|
||||
d.dept_id,
|
||||
d.parent_id,
|
||||
d.name,
|
||||
d.description,
|
||||
dh.level + 1 AS level
|
||||
FROM tb_sys_dept d
|
||||
INNER JOIN dept_hierarchy dh ON d.parent_id = dh.dept_id
|
||||
WHERE d.deleted = 0
|
||||
AND d.parent_id IS NOT NULL
|
||||
)
|
||||
SELECT
|
||||
dh.dept_id AS deptID,
|
||||
tsdr.role_id
|
||||
FROM dept_hierarchy dh
|
||||
INNER JOIN tb_sys_dept_role tsdr ON dh.dept_id = tsdr.dept_id
|
||||
AND tsdr.deleted = 0
|
||||
ORDER BY level DESC
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.xyzh.system.mapper.ResourcePermissionMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.permission.TbResourcePermission">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="resource_type" property="resourceType" jdbcType="INTEGER"/>
|
||||
<result column="resource_id" property="resourceID" jdbcType="VARCHAR"/>
|
||||
<result column="dept_id" property="deptID" jdbcType="VARCHAR"/>
|
||||
<result column="role_id" property="roleID" jdbcType="VARCHAR"/>
|
||||
<result column="can_read" property="canRead" jdbcType="TINYINT"/>
|
||||
<result column="can_write" property="canWrite" jdbcType="TINYINT"/>
|
||||
<result column="can_execute" property="canExecute" jdbcType="TINYINT"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="TINYINT"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 视图对象映射 -->
|
||||
<resultMap id="ResourcePermissionVO" type="org.xyzh.common.vo.ResourcePermissionVO">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="resource_type" property="resourceType" jdbcType="INTEGER"/>
|
||||
<result column="resource_id" property="resourceID" jdbcType="VARCHAR"/>
|
||||
<result column="dept_id" property="deptID" jdbcType="VARCHAR"/>
|
||||
<result column="role_id" property="roleID" jdbcType="VARCHAR"/>
|
||||
<result column="can_read" property="canRead" jdbcType="TINYINT"/>
|
||||
<result column="can_write" property="canWrite" jdbcType="TINYINT"/>
|
||||
<result column="can_execute" property="canExecute" jdbcType="TINYINT"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="TINYINT"/>
|
||||
<result column="dept_name" property="deptName" jdbcType="VARCHAR"/>
|
||||
<result column="role_name" property="roleName" jdbcType="VARCHAR"/>
|
||||
<result column="resource_title" property="resourceTitle" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, resource_type, resource_id, dept_id, role_id,
|
||||
can_read, can_write, can_execute,
|
||||
creator, updater, create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 插入资源权限 -->
|
||||
<insert id="insertResourcePermission" parameterType="org.xyzh.common.dto.permission.TbResourcePermission">
|
||||
INSERT INTO tb_resource_permission (
|
||||
id, resource_type, resource_id, dept_id, role_id,
|
||||
can_read, can_write, can_execute,
|
||||
creator, create_time, deleted
|
||||
) VALUES (
|
||||
#{id}, #{resourceType}, #{resourceID}, #{deptID}, #{roleID},
|
||||
#{canRead}, #{canWrite}, #{canExecute},
|
||||
#{creator}, #{createTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 批量插入资源权限 -->
|
||||
<insert id="batchInsertResourcePermission" parameterType="java.util.List">
|
||||
INSERT INTO tb_resource_permission (
|
||||
id, resource_type, resource_id, dept_id, role_id,
|
||||
can_read, can_write, can_execute,
|
||||
creator, create_time, deleted
|
||||
) VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(
|
||||
#{item.id}, #{item.resourceType}, #{item.resourceID}, #{item.deptID}, #{item.roleID},
|
||||
#{item.canRead}, #{item.canWrite}, #{item.canExecute},
|
||||
#{item.creator}, #{item.createTime}, #{item.deleted}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
@@ -17,42 +17,22 @@
|
||||
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="deptRoleVOResultMap" type="org.xyzh.common.vo.DeptRoleVO">
|
||||
<result column="dept_id" property="dept.deptID" jdbcType="VARCHAR"/>
|
||||
<result column="dept_name" property="dept.name" jdbcType="VARCHAR"/>
|
||||
<result column="dept_description" property="dept.description" jdbcType="VARCHAR"/>
|
||||
<result column="dept_creator" property="dept.creator" jdbcType="VARCHAR"/>
|
||||
<result column="dept_updater" property="dept.updater" jdbcType="VARCHAR"/>
|
||||
<result column="dept_create_time" property="dept.createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="dept_update_time" property="dept.updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="dept_delete_time" property="dept.deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="dept_deleted" property="dept.deleted" jdbcType="BOOLEAN"/>
|
||||
<result column="role_id" property="role.roleID" jdbcType="VARCHAR"/>
|
||||
<result column="role_name" property="role.name" jdbcType="VARCHAR"/>
|
||||
<result column="role_description" property="role.description" jdbcType="VARCHAR"/>
|
||||
<result column="role_creator" property="role.creator" jdbcType="VARCHAR"/>
|
||||
<result column="role_updater" property="role.updater" jdbcType="VARCHAR"/>
|
||||
<result column="role_create_time" property="role.createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="role_update_time" property="role.updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="role_delete_time" property="role.deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="role_deleted" property="role.deleted" jdbcType="BOOLEAN"/>
|
||||
<resultMap id="deptRoleVOResultMap" type="org.xyzh.common.vo.UserDeptRoleVO">
|
||||
<result column="user_id" property="userID" jdbcType="VARCHAR"/>
|
||||
<result column="username" property="username" jdbcType="VARCHAR"/>
|
||||
<result column="dept_id" property="deptID" jdbcType="VARCHAR"/>
|
||||
<result column="dept_name" property="deptName" jdbcType="VARCHAR"/>
|
||||
<result column="dept_description" property="deptDescription" jdbcType="VARCHAR"/>
|
||||
<result column="dept_path" property="deptPath" jdbcType="VARCHAR"/>
|
||||
<result column="role_id" property="roleID" jdbcType="VARCHAR"/>
|
||||
<result column="role_name" property="roleName" jdbcType="VARCHAR"/>
|
||||
<result column="role_description" property="roleDescription" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
<!-- 基础字段 -->
|
||||
<sql id="TbSysRole_Column_List">
|
||||
id, role_id, name, description, creator, updater,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
<sql id="TbSysDeptRole_Column_List">
|
||||
dr.id, dr.dept_id, dr.role_id,
|
||||
r.name as role_name, d.name as dept_name,
|
||||
r.description as role_description, d.description as dept_description,
|
||||
r.creator as role_creator, d.creator as dept_creator,
|
||||
r.updater as role_updater, d.updater as dept_updater,
|
||||
r.create_time as role_create_time, d.create_time as dept_create_time,
|
||||
r.update_time as role_update_time, d.update_time as dept_update_time,
|
||||
r.delete_time as role_delete_time, d.delete_time as dept_delete_time,
|
||||
r.deleted as role_deleted, d.deleted as dept_deleted
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
@@ -110,10 +90,19 @@
|
||||
<!-- 根据用户ID查询角色列表 -->
|
||||
<select id="selectDeptRolesByUserId" resultMap="deptRoleVOResultMap">
|
||||
SELECT
|
||||
<include refid="TbSysDeptRole_Column_List"/>
|
||||
dr.user_id,
|
||||
u.username,
|
||||
dr.dept_id,
|
||||
d.name AS dept_name,
|
||||
d.description AS dept_description,
|
||||
d.dept_path,
|
||||
dr.role_id,
|
||||
r.name AS role_name,
|
||||
r.description AS role_description
|
||||
FROM tb_sys_user_dept_role dr
|
||||
INNER JOIN tb_sys_role r ON r.role_id = dr.role_id
|
||||
INNER JOIN tb_sys_dept d ON d.dept_id = dr.dept_id
|
||||
LEFT JOIN tb_sys_user u ON dr.user_id = u.id AND u.deleted = 0
|
||||
LEFT JOIN tb_sys_role r ON dr.role_id = r.role_id AND r.deleted = 0
|
||||
LEFT JOIN tb_sys_dept d ON dr.dept_id = d.dept_id AND d.deleted = 0
|
||||
WHERE dr.deleted = 0
|
||||
AND dr.user_id = #{userId}
|
||||
ORDER BY dr.create_time ASC
|
||||
|
||||
@@ -44,14 +44,47 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 用户部门角色VO结果映射 -->
|
||||
<resultMap id="UserDeptRoleVOResultMap" type="org.xyzh.common.vo.UserDeptRoleVO">
|
||||
<result column="user_id" property="userID" jdbcType="VARCHAR"/>
|
||||
<result column="username" property="username" jdbcType="VARCHAR"/>
|
||||
<result column="dept_id" property="deptID" jdbcType="VARCHAR"/>
|
||||
<result column="dept_name" property="deptName" jdbcType="VARCHAR"/>
|
||||
<result column="dept_description" property="deptDescription" jdbcType="VARCHAR"/>
|
||||
<result column="role_id" property="roleID" jdbcType="VARCHAR"/>
|
||||
<result column="role_name" property="roleName" jdbcType="VARCHAR"/>
|
||||
<result column="role_description" property="roleDescription" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- selectByFilter -->
|
||||
|
||||
<select id="selectByFilter">
|
||||
<select id="selectByFilter" resultMap="UserDeptRoleVOResultMap">
|
||||
SELECT
|
||||
<include refid="UserDeptRole_Column_List"/>
|
||||
FROM tb_sys_user_dept_role
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY user_id, dept_id, role_id, create_time DESC
|
||||
udr.user_id,
|
||||
u.username AS username,
|
||||
udr.dept_id,
|
||||
d.name AS dept_name,
|
||||
d.description AS dept_description,
|
||||
udr.role_id,
|
||||
r.name AS role_name,
|
||||
r.description AS role_description
|
||||
FROM tb_sys_user_dept_role udr
|
||||
LEFT JOIN tb_sys_user u ON udr.user_id = u.id AND u.deleted = 0
|
||||
LEFT JOIN tb_sys_dept d ON udr.dept_id = d.dept_id AND d.deleted = 0
|
||||
LEFT JOIN tb_sys_role r ON udr.role_id = r.role_id AND r.deleted = 0
|
||||
<where>
|
||||
udr.deleted = 0
|
||||
<if test="userID != null">
|
||||
AND udr.user_id = #{userID}
|
||||
</if>
|
||||
<if test="deptID != null">
|
||||
AND udr.dept_id = #{deptID}
|
||||
</if>
|
||||
<if test="roleID != null">
|
||||
AND udr.role_id = #{roleID}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY udr.user_id, udr.dept_id, udr.role_id, udr.create_time DESC
|
||||
</select>
|
||||
|
||||
<insert id="bindUser" parameterType="TbSysUserDeptRole">
|
||||
@@ -70,4 +103,20 @@
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- deleteUserDeptRole - 物理删除所有记录(包括软删除的) -->
|
||||
|
||||
<delete id="deleteUserDeptRole">
|
||||
DELETE FROM tb_sys_user_dept_role
|
||||
WHERE user_id = #{userID}
|
||||
</delete>
|
||||
|
||||
<!-- deleteUserDeptRoleByUserIds - 批量删除多个用户的绑定 -->
|
||||
|
||||
<delete id="deleteUserDeptRoleByUserIds">
|
||||
DELETE FROM tb_sys_user_dept_role
|
||||
WHERE user_id IN
|
||||
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -242,12 +242,10 @@
|
||||
</update>
|
||||
|
||||
<!-- 根据ID删除(逻辑删除) -->
|
||||
<update id="deleteUser">
|
||||
UPDATE tb_sys_user
|
||||
SET deleted = 1,
|
||||
delete_time = NOW()
|
||||
WHERE id = #{id} AND deleted = 0
|
||||
</update>
|
||||
<delete id="deleteUser">
|
||||
DELETE FROM tb_sys_user
|
||||
WHERE id = #{userID} AND deleted = 0
|
||||
</delete>
|
||||
|
||||
<!-- 用户信息相关 -->
|
||||
|
||||
@@ -293,10 +291,7 @@
|
||||
INNER JOIN tb_sys_user_dept_role tsudr ON tsui.user_id = tsudr.user_id
|
||||
INNER JOIN tb_sys_dept tsd ON tsudr.dept_id = tsd.dept_id
|
||||
WHERE tsui.user_id = #{userId} AND tsui.deleted = 0
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 递归查询:向上查找父部门
|
||||
SELECT
|
||||
p.dept_id,
|
||||
p.name,
|
||||
@@ -304,12 +299,12 @@
|
||||
CONCAT(p.name, '/', dh.dept_path) as dept_path,
|
||||
dh.level + 1 as level
|
||||
FROM tb_sys_dept p
|
||||
INNER JOIN dept_hierarchy dh ON p.dept_id = dh.parent_id
|
||||
INNER JOIN dept_hierarchy dh ON dh.parent_id = p.dept_id
|
||||
WHERE p.deleted = 0
|
||||
)
|
||||
SELECT dh.dept_path
|
||||
FROM dept_hierarchy dh
|
||||
WHERE dh.parent_id IS NULL -- 只取最顶层的部门路径
|
||||
WHERE dh.parent_id IS NULL
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
@@ -317,7 +312,6 @@
|
||||
|
||||
<select id="selectUserInfoTotal" resultMap="UserInfoTotalResultMap">
|
||||
WITH RECURSIVE dept_hierarchy AS (
|
||||
-- 基础查询:获取用户直接所属的部门
|
||||
SELECT
|
||||
tsd.dept_id,
|
||||
tsd.name,
|
||||
@@ -328,10 +322,7 @@
|
||||
INNER JOIN tb_sys_user_dept_role tsudr ON tsui.user_id = tsudr.user_id
|
||||
INNER JOIN tb_sys_dept tsd ON tsudr.dept_id = tsd.dept_id
|
||||
WHERE tsui.user_id = #{userId} AND tsui.deleted = 0
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 递归查询:向上查找父部门
|
||||
SELECT
|
||||
p.dept_id,
|
||||
p.name,
|
||||
@@ -339,7 +330,7 @@
|
||||
CONCAT(p.name, '/', dh.dept_path) as dept_path,
|
||||
dh.level + 1 as level
|
||||
FROM tb_sys_dept p
|
||||
INNER JOIN dept_hierarchy dh ON p.dept_id = dh.parent_id
|
||||
INNER JOIN dept_hierarchy dh ON dh.parent_id = p.dept_id
|
||||
WHERE p.deleted = 0
|
||||
)
|
||||
SELECT
|
||||
@@ -349,7 +340,7 @@
|
||||
tus.email,
|
||||
tsui.avatar,
|
||||
tsui.gender,
|
||||
dh.dept_path as dept_name,
|
||||
(SELECT dept_path FROM dept_hierarchy WHERE parent_id IS NULL LIMIT 1) as dept_name,
|
||||
tsr.name as role_name,
|
||||
tsui.level,
|
||||
tsui.id_card,
|
||||
@@ -357,10 +348,8 @@
|
||||
FROM tb_sys_user_info tsui
|
||||
INNER JOIN tb_sys_user tus ON tsui.user_id = tus.id
|
||||
INNER JOIN tb_sys_user_dept_role tsudr ON tsui.user_id = tsudr.user_id
|
||||
INNER JOIN dept_hierarchy dh ON tsudr.dept_id = dh.dept_id
|
||||
INNER JOIN tb_sys_role tsr ON tsudr.role_id = tsr.role_id
|
||||
INNER JOIN tb_sys_role tsr ON tsudr.role_id = tsr.role_id
|
||||
WHERE tsui.user_id = #{userId}
|
||||
AND tsui.deleted = 0
|
||||
AND dh.parent_id IS NULL -- 只取最顶层的部门路径
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user