serv\web- 日志
This commit is contained in:
@@ -14,7 +14,26 @@
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="DeptRoleResultMap" type="org.xyzh.common.dto.role.TbSysRole">
|
||||
<id column="role_id" property="roleID" jdbcType="VARCHAR"/>
|
||||
<result column="role_name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="role_description" property="description" jdbcType="VARCHAR"/>
|
||||
<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="BOOLEAN"/>
|
||||
</resultMap>
|
||||
<!-- 部门角色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>
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, dept_id, role_id, creator, updater,
|
||||
@@ -29,25 +48,24 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectDeptRole -->
|
||||
<!-- selectDeptRole - 查询指定部门的角色绑定(包含名称) -->
|
||||
|
||||
<select id="selectDeptRole">
|
||||
<select id="selectDeptRole" resultMap="DeptRoleVOResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_dept_role
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY 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
|
||||
AND dr.dept_id = #{deptId}
|
||||
ORDER BY dr.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 部门角色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
|
||||
|
||||
@@ -15,6 +15,24 @@
|
||||
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 权限VO结果映射(用于菜单权限查询) -->
|
||||
<resultMap id="PermissionVOResultMap" type="org.xyzh.common.vo.PermissionVO">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="module_id" property="moduleID" jdbcType="VARCHAR"/>
|
||||
<result column="module_name" property="moduleName" jdbcType="VARCHAR"/>
|
||||
<result column="module_description" property="moduleDescription" jdbcType="VARCHAR"/>
|
||||
<result column="permission_id" property="permissionID" jdbcType="VARCHAR"/>
|
||||
<result column="permission_name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="permission_code" property="code" jdbcType="VARCHAR"/>
|
||||
<result column="permission_description" property="description" jdbcType="VARCHAR"/>
|
||||
<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="BOOLEAN"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, menu_id, permission_id, creator, updater,
|
||||
@@ -51,14 +69,29 @@
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 根据菜单ID查询权限关联列表 -->
|
||||
<select id="selectByMenuId" resultMap="BaseResultMap">
|
||||
<!-- 根据菜单ID查询权限列表(返回PermissionVO) -->
|
||||
<select id="selectByMenuId" resultMap="PermissionVOResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_menu_permission
|
||||
WHERE deleted = 0
|
||||
AND menu_id = #{menuId}
|
||||
ORDER BY create_time ASC
|
||||
mp.id,
|
||||
p.module_id,
|
||||
m.name AS module_name,
|
||||
m.description AS module_description,
|
||||
mp.permission_id,
|
||||
p.name AS permission_name,
|
||||
p.code AS permission_code,
|
||||
p.description AS permission_description,
|
||||
mp.creator,
|
||||
mp.updater,
|
||||
mp.create_time,
|
||||
mp.update_time,
|
||||
mp.delete_time,
|
||||
mp.deleted
|
||||
FROM tb_sys_menu_permission mp
|
||||
LEFT JOIN tb_sys_permission p ON mp.permission_id = p.permission_id AND p.deleted = 0
|
||||
LEFT JOIN tb_sys_module m ON p.module_id = m.module_id AND m.deleted = 0
|
||||
WHERE mp.deleted = 0
|
||||
AND mp.menu_id = #{menuId}
|
||||
ORDER BY mp.create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 根据权限ID查询菜单关联列表 -->
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
|
||||
<resultMap id="PermissionVO" type="org.xyzh.common.vo.PermissionVO">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="module_id" property="moduleID" jdbcType="VARCHAR"/>
|
||||
<result column="module_name" property="moduleName" jdbcType="VARCHAR"/>
|
||||
<result column="module_description" property="moduleDescription" jdbcType="VARCHAR"/>
|
||||
<result column="permission_id" property="permissionID" jdbcType="VARCHAR"/>
|
||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="code" property="code" jdbcType="VARCHAR"/>
|
||||
@@ -47,6 +50,26 @@
|
||||
<result column="description" property="description" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 权限绑定菜单VO结果映射 -->
|
||||
<resultMap id="PermissionBindMenuVO" type="org.xyzh.common.vo.PermissionVO">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="menu_id" property="menuID" jdbcType="VARCHAR"/>
|
||||
<result column="menu_name" property="menuName" jdbcType="VARCHAR"/>
|
||||
<result column="menu_url" property="menuUrl" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 权限绑定角色VO结果映射 -->
|
||||
<resultMap id="PermissionBindRoleVO" type="org.xyzh.common.vo.PermissionVO">
|
||||
<id column="id" property="id" 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"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="creator_name" property="creatorName" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="updater_name" property="updaterName" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, permission_id, name, code, description, module_id, creator, updater,
|
||||
@@ -226,13 +249,15 @@
|
||||
|
||||
<select id="selectPermissionList" resultMap="PermissionVO" >
|
||||
SELECT
|
||||
tsp.id, tsp.permission_id, tsp.name, tsp.code, tsp.description,
|
||||
tsp.id, tsp.module_id, tsp.permission_id, tsp.name, tsp.code, tsp.description,
|
||||
tsp.creator, tsp.updater,
|
||||
tsu.username as creator_name, tuu.username as updater_name,
|
||||
m.name as module_name, m.description as module_description,
|
||||
tsp.create_time, tsp.update_time, tsp.delete_time, tsp.deleted
|
||||
FROM tb_sys_permission tsp
|
||||
INNER JOIN tb_sys_user tsu ON tsp.creator = tsu.id
|
||||
LEFT JOIN tb_sys_user tuu ON tsp.updater = tuu.id
|
||||
LEFT JOIN tb_sys_module m ON tsp.module_id = m.module_id AND m.deleted = 0
|
||||
WHERE tsp.deleted = 0
|
||||
<if test="permission.name != null and permission.name != ''">
|
||||
AND tsp.name LIKE CONCAT('%', #{permission.name}, '%')
|
||||
@@ -247,13 +272,15 @@
|
||||
|
||||
<select id="selectPermissionVO" resultMap="PermissionVO" >
|
||||
SELECT
|
||||
tsp.id, tsp.permission_id, tsp.name, tsp.code, tsp.description,
|
||||
tsp.id, tsp.module_id, tsp.permission_id, tsp.name, tsp.code, tsp.description,
|
||||
tsp.creator, tsp.updater,
|
||||
tsu.username as creator_name, tuu.username as updater_name,
|
||||
m.name as module_name, m.description as module_description,
|
||||
tsp.create_time, tsp.update_time, tsp.delete_time, tsp.deleted
|
||||
FROM tb_sys_permission tsp
|
||||
INNER JOIN tb_sys_user tsu ON tsp.creator = tsu.id
|
||||
LEFT JOIN tb_sys_user tuu ON tsp.updater = tuu.id
|
||||
LEFT JOIN tb_sys_module m ON tsp.module_id = m.module_id AND m.deleted = 0
|
||||
WHERE tsp.deleted = 0
|
||||
<if test="permission.name != null and permission.name != ''">
|
||||
AND tsp.name LIKE CONCAT('%', #{permission.name}, '%')
|
||||
@@ -269,9 +296,12 @@
|
||||
|
||||
<!-- selectPermissionBindMenu -->
|
||||
|
||||
<select id="selectPermissionBindMenu" resultMap="PermissionBindMenu">
|
||||
<select id="selectPermissionBindMenu" resultMap="PermissionBindMenuVO">
|
||||
SELECT
|
||||
tsm.id, tsm.menu_id, tsm.name
|
||||
tsm.id,
|
||||
tsm.menu_id,
|
||||
tsm.name AS menu_name,
|
||||
tsm.url AS menu_url
|
||||
FROM tb_sys_menu tsm
|
||||
INNER JOIN tb_sys_menu_permission tsmp ON tsmp.menu_id = tsm.menu_id
|
||||
WHERE tsm.deleted = 0
|
||||
@@ -281,11 +311,20 @@
|
||||
</select>
|
||||
|
||||
<!-- selectPermissionBindRole -->
|
||||
<select id="selectPermissionBindRole" resultMap="PermissionBindRole">
|
||||
<select id="selectPermissionBindRole" resultMap="PermissionBindRoleVO">
|
||||
SELECT
|
||||
tsr.id, tsr.role_id, tsr.name, tsr.description
|
||||
tsr.id,
|
||||
tsr.role_id,
|
||||
tsr.name AS role_name,
|
||||
tsr.description AS role_description,
|
||||
tsr.creator,
|
||||
cu.username AS creator_name,
|
||||
tsr.updater,
|
||||
uu.username AS updater_name
|
||||
FROM tb_sys_role tsr
|
||||
INNER JOIN tb_sys_role_permission tsrp ON tsrp.role_id = tsr.role_id
|
||||
LEFT JOIN tb_sys_user cu ON tsr.creator = cu.id AND cu.deleted = 0
|
||||
LEFT JOIN tb_sys_user uu ON tsr.updater = uu.id AND uu.deleted = 0
|
||||
WHERE tsr.deleted = 0
|
||||
AND tsrp.deleted = 0
|
||||
AND tsrp.permission_id = #{permission.permissionID}
|
||||
|
||||
@@ -47,23 +47,97 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectAllRoles -->
|
||||
<!-- 权限过滤条件(基于dept_path的高效继承) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_resource_permission rp ON r.role_id = rp.resource_id
|
||||
AND rp.resource_type = 5
|
||||
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>
|
||||
|
||||
<select id="selectAllRoles" resultMap="tbSysRoleResultMap">
|
||||
SELECT
|
||||
<include refid="TbSysRole_Column_List"/>
|
||||
FROM tb_sys_role
|
||||
WHERE deleted = 0
|
||||
ORDER BY role_id, create_time ASC
|
||||
<!-- 角色VO结果映射(包含创建人更新人名称) -->
|
||||
<resultMap id="RoleVOResultMap" type="org.xyzh.common.vo.PermissionVO">
|
||||
<id column="id" property="id" 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"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="creator_name" property="creatorName" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="updater_name" property="updaterName" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- selectAllRoles - 添加权限过滤和VO返回 -->
|
||||
<select id="selectAllRoles" resultMap="RoleVOResultMap">
|
||||
SELECT DISTINCT
|
||||
r.id,
|
||||
r.role_id,
|
||||
r.name AS role_name,
|
||||
r.description AS role_description,
|
||||
r.creator,
|
||||
cu.username AS creator_name,
|
||||
r.updater,
|
||||
uu.username AS updater_name,
|
||||
r.create_time,
|
||||
r.update_time
|
||||
FROM tb_sys_role r
|
||||
<include refid="Permission_Filter"/>
|
||||
LEFT JOIN tb_sys_user cu ON r.creator = cu.id AND cu.deleted = 0
|
||||
LEFT JOIN tb_sys_user uu ON r.updater = uu.id AND uu.deleted = 0
|
||||
WHERE r.deleted = 0
|
||||
ORDER BY r.role_id, r.create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 根据过滤条件查询角色列表 -->
|
||||
<select id="selectRole" resultMap="tbSysRoleResultMap">
|
||||
SELECT
|
||||
<include refid="TbSysRole_Column_List"/>
|
||||
FROM tb_sys_role
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY role_id, create_time ASC
|
||||
<!-- 根据过滤条件查询角色列表 - 添加权限过滤 -->
|
||||
<select id="selectRole" resultMap="RoleVOResultMap">
|
||||
SELECT DISTINCT
|
||||
r.id,
|
||||
r.role_id,
|
||||
r.name AS role_name,
|
||||
r.description AS role_description,
|
||||
r.creator,
|
||||
cu.username AS creator_name,
|
||||
r.updater,
|
||||
uu.username AS updater_name,
|
||||
r.create_time,
|
||||
r.update_time
|
||||
FROM tb_sys_role r
|
||||
<include refid="Permission_Filter"/>
|
||||
LEFT JOIN tb_sys_user cu ON r.creator = cu.id AND cu.deleted = 0
|
||||
LEFT JOIN tb_sys_user uu ON r.updater = uu.id AND uu.deleted = 0
|
||||
WHERE r.deleted = 0
|
||||
<if test="filter.roleID != null and filter.roleID != ''">
|
||||
AND r.role_id = #{filter.roleID}
|
||||
</if>
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND r.name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
ORDER BY r.role_id, r.create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 插入角色 -->
|
||||
@@ -108,35 +182,15 @@
|
||||
ORDER BY dr.create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 根据角色编码查询角色 -->
|
||||
<select id="selectByRoleCode" resultMap="tbSysRoleResultMap">
|
||||
SELECT
|
||||
<include refid="TbSysRole_Column_List"/>
|
||||
FROM tb_sys_role
|
||||
WHERE deleted = 0
|
||||
AND role_code = #{roleCode}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 检查角色名称是否存在 -->
|
||||
<!-- 检查角色名称是否存在 - 添加权限过滤 -->
|
||||
<select id="countByRoleName" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_sys_role
|
||||
WHERE deleted = 0
|
||||
AND name = #{roleName}
|
||||
SELECT COUNT(DISTINCT r.id)
|
||||
FROM tb_sys_role r
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE r.deleted = 0
|
||||
AND r.name = #{roleName}
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND id != #{excludeId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 检查角色编码是否存在 -->
|
||||
<select id="countByRoleCode" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_sys_role
|
||||
WHERE deleted = 0
|
||||
AND role_code = #{roleCode}
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND id != #{excludeId}
|
||||
AND r.id != #{excludeId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
@@ -155,9 +209,8 @@
|
||||
|
||||
|
||||
|
||||
<!-- checkRoleExists -->
|
||||
|
||||
<select id="checkRoleExists">
|
||||
<!-- checkRoleExists - 检查角色是否存在,不需要权限过滤 -->
|
||||
<select id="checkRoleExists" resultMap="tbSysRoleResultMap">
|
||||
SELECT
|
||||
<include refid="TbSysRole_Column_List"/>
|
||||
FROM tb_sys_role
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
<?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.SysLoginLogMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.system.TbSysLoginLog">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="user_id" property="userID" jdbcType="VARCHAR"/>
|
||||
<result column="username" property="username" jdbcType="VARCHAR"/>
|
||||
<result column="ip_address" property="ipAddress" jdbcType="VARCHAR"/>
|
||||
<result column="ip_source" property="ipSource" jdbcType="VARCHAR"/>
|
||||
<result column="browser" property="browser" jdbcType="VARCHAR"/>
|
||||
<result column="os" property="os" jdbcType="VARCHAR"/>
|
||||
<result column="password" property="password" jdbcType="VARCHAR"/>
|
||||
<result column="login_time" property="loginTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="error_count" property="errorCount" jdbcType="INTEGER"/>
|
||||
<result column="message" property="message" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 权限过滤:通过用户的部门路径进行权限控制,superadmin可查看所有 -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_sys_user u ON ll.user_id = u.id AND u.deleted = 0
|
||||
INNER JOIN tb_sys_user_dept_role udr ON u.id = udr.user_id AND udr.deleted = 0
|
||||
INNER JOIN tb_sys_dept d ON udr.dept_id = d.dept_id AND d.deleted = 0
|
||||
WHERE (
|
||||
-- superadmin 可以查看所有登录日志
|
||||
EXISTS (
|
||||
SELECT 1 FROM (
|
||||
<foreach collection="userDeptRoles" item="currentRole" separator=" UNION ALL ">
|
||||
SELECT #{currentRole.deptID} AS dept_id, #{currentRole.roleID} AS role_id
|
||||
</foreach>
|
||||
) admin_check
|
||||
WHERE admin_check.dept_id = 'root_department'
|
||||
AND admin_check.role_id = 'superadmin'
|
||||
)
|
||||
-- 普通用户按部门路径过滤(本部门及子部门)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM (
|
||||
<foreach collection="userDeptRoles" item="currentRole" separator=" UNION ALL ">
|
||||
SELECT #{currentRole.deptPath} AS user_dept_path
|
||||
</foreach>
|
||||
) user_roles
|
||||
WHERE d.dept_path LIKE CONCAT(user_roles.user_dept_path, '%')
|
||||
)
|
||||
)
|
||||
</sql>
|
||||
|
||||
<insert id="insertLoginLog" parameterType="org.xyzh.common.dto.system.TbSysLoginLog">
|
||||
INSERT INTO tb_sys_login_log (id, user_id, username, ip_address, ip_source, browser, os, password, login_time, status, error_count, message, create_time)
|
||||
VALUES (#{id}, #{userID}, #{username}, #{ipAddress}, #{ipSource}, #{browser}, #{os}, #{password}, #{loginTime, jdbcType=TIMESTAMP}, #{status}, #{errorCount}, #{message}, now());
|
||||
</insert>
|
||||
|
||||
<!-- 查询登录日志列表(带权限过滤) -->
|
||||
<select id="selectLoginLogList" resultMap="BaseResultMap">
|
||||
SELECT DISTINCT ll.*
|
||||
FROM tb_sys_login_log ll
|
||||
<include refid="Permission_Filter"/>
|
||||
<if test="loginLog.userID != null and loginLog.userID != ''">
|
||||
AND ll.user_id = #{loginLog.userID}
|
||||
</if>
|
||||
<if test="loginLog.username != null and loginLog.username != ''">
|
||||
AND ll.username LIKE CONCAT('%', #{loginLog.username}, '%')
|
||||
</if>
|
||||
<if test="loginLog.ipAddress != null and loginLog.ipAddress != ''">
|
||||
AND ll.ip_address = #{loginLog.ipAddress}
|
||||
</if>
|
||||
<if test="loginLog.status != null">
|
||||
AND ll.status = #{loginLog.status}
|
||||
</if>
|
||||
<if test="loginLog.browser != null and loginLog.browser != ''">
|
||||
AND ll.browser LIKE CONCAT('%', #{loginLog.browser}, '%')
|
||||
</if>
|
||||
<if test="loginLog.os != null and loginLog.os != ''">
|
||||
AND ll.os LIKE CONCAT('%', #{loginLog.os}, '%')
|
||||
</if>
|
||||
ORDER BY ll.login_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 分页查询登录日志列表(带权限过滤) -->
|
||||
<select id="selectLoginLogPage" resultMap="BaseResultMap">
|
||||
SELECT DISTINCT ll.*
|
||||
FROM tb_sys_login_log ll
|
||||
<include refid="Permission_Filter"/>
|
||||
<if test="loginLog.userID != null and loginLog.userID != ''">
|
||||
AND ll.user_id = #{loginLog.userID}
|
||||
</if>
|
||||
<if test="loginLog.username != null and loginLog.username != ''">
|
||||
AND ll.username LIKE CONCAT('%', #{loginLog.username}, '%')
|
||||
</if>
|
||||
<if test="loginLog.ipAddress != null and loginLog.ipAddress != ''">
|
||||
AND ll.ip_address = #{loginLog.ipAddress}
|
||||
</if>
|
||||
<if test="loginLog.status != null">
|
||||
AND ll.status = #{loginLog.status}
|
||||
</if>
|
||||
<if test="loginLog.browser != null and loginLog.browser != ''">
|
||||
AND ll.browser LIKE CONCAT('%', #{loginLog.browser}, '%')
|
||||
</if>
|
||||
<if test="loginLog.os != null and loginLog.os != ''">
|
||||
AND ll.os LIKE CONCAT('%', #{loginLog.os}, '%')
|
||||
</if>
|
||||
ORDER BY ll.login_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 统计登录日志数量(带权限过滤) -->
|
||||
<select id="countLoginLog" resultType="int">
|
||||
SELECT COUNT(DISTINCT ll.id)
|
||||
FROM tb_sys_login_log ll
|
||||
<include refid="Permission_Filter"/>
|
||||
<if test="loginLog.userID != null and loginLog.userID != ''">
|
||||
AND ll.user_id = #{loginLog.userID}
|
||||
</if>
|
||||
<if test="loginLog.username != null and loginLog.username != ''">
|
||||
AND ll.username LIKE CONCAT('%', #{loginLog.username}, '%')
|
||||
</if>
|
||||
<if test="loginLog.ipAddress != null and loginLog.ipAddress != ''">
|
||||
AND ll.ip_address = #{loginLog.ipAddress}
|
||||
</if>
|
||||
<if test="loginLog.status != null">
|
||||
AND ll.status = #{loginLog.status}
|
||||
</if>
|
||||
<if test="loginLog.browser != null and loginLog.browser != ''">
|
||||
AND ll.browser LIKE CONCAT('%', #{loginLog.browser}, '%')
|
||||
</if>
|
||||
<if test="loginLog.os != null and loginLog.os != ''">
|
||||
AND ll.os LIKE CONCAT('%', #{loginLog.os}, '%')
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -31,37 +31,99 @@
|
||||
browser, os, status, error_message, execute_time, create_time
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
<where>
|
||||
<if test="userID != null and userID != ''">
|
||||
AND user_id = #{userID}
|
||||
</if>
|
||||
<if test="username != null and username != ''">
|
||||
AND username LIKE CONCAT('%', #{username}, '%')
|
||||
</if>
|
||||
<if test="module != null and module != ''">
|
||||
AND module = #{module}
|
||||
</if>
|
||||
<if test="operation != null and operation != ''">
|
||||
AND operation = #{operation}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
<if test="ipAddress != null and ipAddress != ''">
|
||||
AND ip_address = #{ipAddress}
|
||||
</if>
|
||||
</where>
|
||||
<!-- 权限过滤:通过用户的部门路径进行权限控制,superadmin可查看所有 -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_sys_user u ON ol.user_id = u.id AND u.deleted = 0
|
||||
INNER JOIN tb_sys_user_dept_role udr ON u.id = udr.user_id AND udr.deleted = 0
|
||||
INNER JOIN tb_sys_dept d ON udr.dept_id = d.dept_id AND d.deleted = 0
|
||||
WHERE (
|
||||
-- superadmin 可以查看所有操作日志
|
||||
EXISTS (
|
||||
SELECT 1 FROM (
|
||||
<foreach collection="userDeptRoles" item="currentRole" separator=" UNION ALL ">
|
||||
SELECT #{currentRole.deptID} AS dept_id, #{currentRole.roleID} AS role_id
|
||||
</foreach>
|
||||
) admin_check
|
||||
WHERE admin_check.dept_id = 'root_department'
|
||||
AND admin_check.role_id = 'superadmin'
|
||||
)
|
||||
-- 普通用户按部门路径过滤(本部门及子部门)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM (
|
||||
<foreach collection="userDeptRoles" item="currentRole" separator=" UNION ALL ">
|
||||
SELECT #{currentRole.deptPath} AS user_dept_path
|
||||
</foreach>
|
||||
) user_roles
|
||||
WHERE d.dept_path LIKE CONCAT(user_roles.user_dept_path, '%')
|
||||
)
|
||||
)
|
||||
</sql>
|
||||
|
||||
<!-- selectSysOperationLogs -->
|
||||
<select id="selectSysOperationLogs" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_operation_log
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
<if test="operationLog.userID != null and operationLog.userID != ''">
|
||||
AND ol.user_id = #{operationLog.userID}
|
||||
</if>
|
||||
<if test="operationLog.username != null and operationLog.username != ''">
|
||||
AND ol.username LIKE CONCAT('%', #{operationLog.username}, '%')
|
||||
</if>
|
||||
<if test="operationLog.module != null and operationLog.module != ''">
|
||||
AND ol.module LIKE CONCAT('%', #{operationLog.module}, '%')
|
||||
</if>
|
||||
<if test="operationLog.operation != null and operationLog.operation != ''">
|
||||
AND ol.operation = #{operationLog.operation}
|
||||
</if>
|
||||
<if test="operationLog.status != null">
|
||||
AND ol.status = #{operationLog.status}
|
||||
</if>
|
||||
<if test="operationLog.ipAddress != null and operationLog.ipAddress != ''">
|
||||
AND ol.ip_address = #{operationLog.ipAddress}
|
||||
</if>
|
||||
<if test="operationLog.requestUrl != null and operationLog.requestUrl != ''">
|
||||
AND ol.request_url LIKE CONCAT('%', #{operationLog.requestUrl}, '%')
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<!-- 插入操作日志 -->
|
||||
<insert id="insertOperationLog" parameterType="org.xyzh.common.dto.system.TbSysOperationLog">
|
||||
INSERT INTO tb_sys_operation_log (
|
||||
id, user_id, username, module, operation, method,
|
||||
request_url, request_method, request_params, response_data,
|
||||
ip_address, ip_source, browser, os, status,
|
||||
error_message, execute_time, create_time
|
||||
) VALUES (
|
||||
#{id}, #{userID}, #{username}, #{module}, #{operation}, #{method},
|
||||
#{requestUrl}, #{requestMethod}, #{requestParams}, #{responseData},
|
||||
#{ipAddress}, #{ipSource}, #{browser}, #{os}, #{status},
|
||||
#{errorMessage}, #{executeTime}, #{createTime, jdbcType=TIMESTAMP}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 查询操作日志列表(带权限过滤) -->
|
||||
<select id="selectOperationLogList" resultMap="BaseResultMap">
|
||||
SELECT DISTINCT ol.*
|
||||
FROM tb_sys_operation_log ol
|
||||
<include refid="Permission_Filter"/>
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY ol.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 分页查询操作日志列表(带权限过滤) -->
|
||||
<select id="selectOperationLogPage" resultMap="BaseResultMap">
|
||||
SELECT DISTINCT ol.*
|
||||
FROM tb_sys_operation_log ol
|
||||
<include refid="Permission_Filter"/>
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY ol.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 统计操作日志数量(带权限过滤) -->
|
||||
<select id="countOperationLog" resultType="int">
|
||||
SELECT COUNT(DISTINCT ol.id)
|
||||
FROM tb_sys_operation_log ol
|
||||
<include refid="Permission_Filter"/>
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -33,11 +33,20 @@
|
||||
<result column="deleted" property="deleted" jdbcType="INTEGER"/>
|
||||
</resultMap>
|
||||
<resultMap id="UserInfoTotalResultMap" type="org.xyzh.common.vo.UserVO">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="user_id" property="userID" jdbcType="VARCHAR"/>
|
||||
<result column="username" property="username" jdbcType="VARCHAR"/>
|
||||
<result column="avatar" property="avatar" jdbcType="VARCHAR"/>
|
||||
<result column="gender" property="gender" jdbcType="INTEGER"/>
|
||||
<result column="phone" property="phone" jdbcType="VARCHAR"/>
|
||||
<result column="email" property="email" jdbcType="VARCHAR"/>
|
||||
<result column="wechat_id" property="wechatID" jdbcType="VARCHAR"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="family_name" property="familyName" jdbcType="VARCHAR"/>
|
||||
<result column="given_name" property="givenName" jdbcType="VARCHAR"/>
|
||||
<result column="full_name" property="fullName" jdbcType="VARCHAR"/>
|
||||
<result column="dept_id" property="deptID" jdbcType="VARCHAR"/>
|
||||
<result column="parent_id" property="parentID" jdbcType="VARCHAR"/>
|
||||
<result column="dept_name" property="deptName" jdbcType="VARCHAR"/>
|
||||
<result column="role_name" property="roleName" jdbcType="VARCHAR"/>
|
||||
<result column="level" property="level" jdbcType="INTEGER"/>
|
||||
@@ -108,6 +117,31 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 权限过滤条件(基于dept_path的用户权限过滤,superadmin可查看所有) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_sys_user_dept_role udr ON u.id = udr.user_id AND udr.deleted = 0
|
||||
INNER JOIN tb_sys_dept d ON udr.dept_id = d.dept_id AND d.deleted = 0
|
||||
WHERE (
|
||||
EXISTS (
|
||||
SELECT 1 FROM (
|
||||
<foreach collection="userDeptRoles" item="currentRole" separator=" UNION ALL ">
|
||||
SELECT #{currentRole.deptID} AS dept_id, #{currentRole.roleID} AS role_id
|
||||
</foreach>
|
||||
) admin_check
|
||||
WHERE admin_check.dept_id = 'root_department'
|
||||
AND admin_check.role_id = 'superadmin'
|
||||
)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM (
|
||||
<foreach collection="userDeptRoles" item="currentRole" separator=" UNION ALL ">
|
||||
SELECT #{currentRole.deptPath} AS user_dept_path
|
||||
</foreach>
|
||||
) user_roles
|
||||
WHERE d.dept_path LIKE CONCAT(user_roles.user_dept_path, '%')
|
||||
)
|
||||
)
|
||||
</sql>
|
||||
|
||||
<!-- 根据用户名查询用户 -->
|
||||
<select id="selectByUsername" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
@@ -138,50 +172,223 @@
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 根据过滤条件查询用户 -->
|
||||
<!-- 根据过滤条件查询用户(包含权限过滤) -->
|
||||
<select id="selectByFilter" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_user
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="filter.id != null and filter.id != ''">
|
||||
AND id = #{filter.id}
|
||||
</if>
|
||||
<if test="filter.username != null and filter.username != ''">
|
||||
AND username = #{filter.username}
|
||||
</if>
|
||||
<if test="filter.email != null and filter.email != ''">
|
||||
AND email = #{filter.email}
|
||||
</if>
|
||||
<if test="filter.phone != null and filter.phone != ''">
|
||||
AND phone = #{filter.phone}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.wechatID != null and filter.wechatID != ''">
|
||||
AND wechat_id = #{filter.wechatID}
|
||||
</if>
|
||||
</where>
|
||||
SELECT DISTINCT u.*
|
||||
FROM tb_sys_user u
|
||||
<include refid="Permission_Filter"/>
|
||||
AND u.deleted = 0
|
||||
<if test="filter.id != null and filter.id != ''">
|
||||
AND u.id = #{filter.id}
|
||||
</if>
|
||||
<if test="filter.username != null and filter.username != ''">
|
||||
AND u.username = #{filter.username}
|
||||
</if>
|
||||
<if test="filter.email != null and filter.email != ''">
|
||||
AND u.email = #{filter.email}
|
||||
</if>
|
||||
<if test="filter.phone != null and filter.phone != ''">
|
||||
AND u.phone = #{filter.phone}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND u.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.wechatID != null and filter.wechatID != ''">
|
||||
AND u.wechat_id = #{filter.wechatID}
|
||||
</if>
|
||||
ORDER BY u.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 查询用户列表 -->
|
||||
<!-- 根据过滤条件查询用户VO列表(包含userinfo和deptrole信息,包含权限过滤) -->
|
||||
<select id="selectUserVOByFilter" resultMap="UserInfoTotalResultMap">
|
||||
SELECT DISTINCT
|
||||
u.id,
|
||||
u.username,
|
||||
u.email,
|
||||
u.phone,
|
||||
u.wechat_id,
|
||||
u.status,
|
||||
ui.user_id,
|
||||
ui.avatar,
|
||||
ui.gender,
|
||||
ui.family_name,
|
||||
ui.given_name,
|
||||
ui.full_name,
|
||||
ui.level,
|
||||
ui.id_card,
|
||||
ui.address,
|
||||
udr.dept_id,
|
||||
d.parent_id,
|
||||
GROUP_CONCAT(DISTINCT d.name ORDER BY d.name SEPARATOR ', ') as dept_name,
|
||||
GROUP_CONCAT(DISTINCT r.name ORDER BY r.name SEPARATOR ', ') as role_name,
|
||||
u.create_time,
|
||||
u.update_time
|
||||
FROM tb_sys_user u
|
||||
LEFT JOIN tb_sys_user_info ui ON u.id = ui.user_id AND ui.deleted = 0
|
||||
INNER JOIN tb_sys_user_dept_role udr ON u.id = udr.user_id AND udr.deleted = 0
|
||||
INNER 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 (
|
||||
EXISTS (
|
||||
SELECT 1 FROM (
|
||||
<foreach collection="userDeptRoles" item="currentRole" separator=" UNION ALL ">
|
||||
SELECT #{currentRole.deptID} AS dept_id, #{currentRole.roleID} AS role_id
|
||||
</foreach>
|
||||
) admin_check
|
||||
WHERE admin_check.dept_id = 'root_department'
|
||||
AND admin_check.role_id = 'superadmin'
|
||||
)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM (
|
||||
<foreach collection="userDeptRoles" item="currentRole" separator=" UNION ALL ">
|
||||
SELECT #{currentRole.deptPath} AS user_dept_path
|
||||
</foreach>
|
||||
) user_roles
|
||||
WHERE d.dept_path LIKE CONCAT(user_roles.user_dept_path, '%')
|
||||
)
|
||||
)
|
||||
AND u.deleted = 0
|
||||
<if test="filter.id != null and filter.id != ''">
|
||||
AND u.id = #{filter.id}
|
||||
</if>
|
||||
<if test="filter.username != null and filter.username != ''">
|
||||
AND u.username LIKE CONCAT('%', #{filter.username}, '%')
|
||||
</if>
|
||||
<if test="filter.email != null and filter.email != ''">
|
||||
AND u.email LIKE CONCAT('%', #{filter.email}, '%')
|
||||
</if>
|
||||
<if test="filter.phone != null and filter.phone != ''">
|
||||
AND u.phone = #{filter.phone}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND u.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.wechatID != null and filter.wechatID != ''">
|
||||
AND u.wechat_id = #{filter.wechatID}
|
||||
</if>
|
||||
GROUP BY u.id, u.username, u.email, u.phone, u.wechat_id, u.status,
|
||||
ui.user_id, ui.avatar, ui.gender, ui.family_name, ui.given_name,
|
||||
ui.full_name, ui.level, ui.id_card, ui.address, udr.dept_id, d.parent_id, u.create_time, u.update_time
|
||||
ORDER BY u.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 查询用户列表(包含权限过滤) -->
|
||||
<select id="selectUserList" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_user
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY create_time DESC
|
||||
SELECT DISTINCT u.*
|
||||
FROM tb_sys_user u
|
||||
<include refid="Permission_Filter"/>
|
||||
AND u.deleted = 0
|
||||
<if test="username != null and username != ''">
|
||||
AND u.username LIKE CONCAT('%', #{username}, '%')
|
||||
</if>
|
||||
<if test="email != null and email != ''">
|
||||
AND u.email LIKE CONCAT('%', #{email}, '%')
|
||||
</if>
|
||||
<if test="status != null and status != ''">
|
||||
AND u.status = #{status}
|
||||
</if>
|
||||
ORDER BY u.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 查询用户列表(分页) -->
|
||||
<!-- 查询用户列表(分页,包含权限过滤) -->
|
||||
<select id="selectUserPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_sys_user
|
||||
<include refid="Filter_Clause"/>
|
||||
ORDER BY create_time DESC
|
||||
SELECT DISTINCT u.*
|
||||
FROM tb_sys_user u
|
||||
<include refid="Permission_Filter"/>
|
||||
AND u.deleted = 0
|
||||
<if test="filter.id != null and filter.id != ''">
|
||||
AND u.id = #{filter.id}
|
||||
</if>
|
||||
<if test="filter.username != null and filter.username != ''">
|
||||
AND u.username = #{filter.username}
|
||||
</if>
|
||||
<if test="filter.email != null and filter.email != ''">
|
||||
AND u.email = #{filter.email}
|
||||
</if>
|
||||
<if test="filter.phone != null and filter.phone != ''">
|
||||
AND u.phone = #{filter.phone}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND u.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.wechatID != null and filter.wechatID != ''">
|
||||
AND u.wechat_id = #{filter.wechatID}
|
||||
</if>
|
||||
ORDER BY u.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 查询用户VO列表(分页,包含userinfo和deptrole信息,包含权限过滤) -->
|
||||
<select id="selectUserVOPage" resultMap="UserInfoTotalResultMap">
|
||||
SELECT DISTINCT
|
||||
u.id,
|
||||
u.username,
|
||||
u.email,
|
||||
u.phone,
|
||||
u.wechat_id,
|
||||
u.status,
|
||||
ui.user_id,
|
||||
ui.avatar,
|
||||
ui.gender,
|
||||
ui.family_name,
|
||||
ui.given_name,
|
||||
ui.full_name,
|
||||
ui.level,
|
||||
ui.id_card,
|
||||
ui.address,
|
||||
udr.dept_id,
|
||||
d.parent_id,
|
||||
GROUP_CONCAT(DISTINCT d.name ORDER BY d.name SEPARATOR ', ') as dept_name,
|
||||
GROUP_CONCAT(DISTINCT r.name ORDER BY r.name SEPARATOR ', ') as role_name,
|
||||
u.create_time,
|
||||
u.update_time
|
||||
FROM tb_sys_user u
|
||||
LEFT JOIN tb_sys_user_info ui ON u.id = ui.user_id AND ui.deleted = 0
|
||||
INNER JOIN tb_sys_user_dept_role udr ON u.id = udr.user_id AND udr.deleted = 0
|
||||
INNER 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 (
|
||||
EXISTS (
|
||||
SELECT 1 FROM (
|
||||
<foreach collection="userDeptRoles" item="currentRole" separator=" UNION ALL ">
|
||||
SELECT #{currentRole.deptID} AS dept_id, #{currentRole.roleID} AS role_id
|
||||
</foreach>
|
||||
) admin_check
|
||||
WHERE admin_check.dept_id = 'root_department'
|
||||
AND admin_check.role_id = 'superadmin'
|
||||
)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM (
|
||||
<foreach collection="userDeptRoles" item="currentRole" separator=" UNION ALL ">
|
||||
SELECT #{currentRole.deptPath} AS user_dept_path
|
||||
</foreach>
|
||||
) user_roles
|
||||
WHERE d.dept_path LIKE CONCAT(user_roles.user_dept_path, '%')
|
||||
)
|
||||
)
|
||||
AND u.deleted = 0
|
||||
<if test="filter.id != null and filter.id != ''">
|
||||
AND u.id = #{filter.id}
|
||||
</if>
|
||||
<if test="filter.username != null and filter.username != ''">
|
||||
AND u.username LIKE CONCAT('%', #{filter.username}, '%')
|
||||
</if>
|
||||
<if test="filter.email != null and filter.email != ''">
|
||||
AND u.email LIKE CONCAT('%', #{filter.email}, '%')
|
||||
</if>
|
||||
<if test="filter.phone != null and filter.phone != ''">
|
||||
AND u.phone = #{filter.phone}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND u.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.wechatID != null and filter.wechatID != ''">
|
||||
AND u.wechat_id = #{filter.wechatID}
|
||||
</if>
|
||||
GROUP BY u.id, u.username, u.email, u.phone, u.wechat_id, u.status,
|
||||
ui.user_id, ui.avatar, ui.gender, ui.family_name, ui.given_name,
|
||||
ui.full_name, ui.level, ui.id_card, ui.address, udr.dept_id, d.parent_id, u.create_time, u.update_time
|
||||
ORDER BY u.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
@@ -352,4 +559,26 @@
|
||||
WHERE tsui.user_id = #{userId}
|
||||
AND tsui.deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- countDeptUser - 递归统计部门及其子部门的用户数量 -->
|
||||
<select id="countDeptUser" resultType="int">
|
||||
SELECT COUNT(DISTINCT tudr.user_id)
|
||||
FROM tb_sys_user_dept_role tudr
|
||||
INNER JOIN tb_sys_dept d ON tudr.dept_id = d.dept_id AND d.deleted = 0
|
||||
INNER JOIN tb_sys_user u ON tudr.user_id = u.id AND u.deleted = 0
|
||||
WHERE tudr.deleted = 0
|
||||
AND d.dept_path LIKE CONCAT(
|
||||
(SELECT dept_path FROM tb_sys_dept WHERE dept_id = #{deptId} AND deleted = 0),
|
||||
'%'
|
||||
)
|
||||
</select>
|
||||
|
||||
<!-- selectLoginUser -->
|
||||
|
||||
<select id="selectLoginUser">
|
||||
SELECT DISTINCT u.*
|
||||
FROM tb_sys_user u
|
||||
<include refid="Filter_Clause"/>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user