2025-09-28 17:32:37 +08:00
|
|
|
<?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.RoleMapper">
|
|
|
|
|
|
|
|
|
|
<!-- 基础结果映射 -->
|
2025-10-06 16:20:05 +08:00
|
|
|
<resultMap id="tbSysRoleResultMap" type="org.xyzh.common.dto.role.TbSysRole">
|
2025-09-28 17:32:37 +08:00
|
|
|
<id column="id" property="id" jdbcType="VARCHAR"/>
|
2025-10-06 16:20:05 +08:00
|
|
|
<result column="dept_id" property="deptID" jdbcType="VARCHAR"/>
|
2025-09-28 17:32:37 +08:00
|
|
|
<result column="role_id" property="roleID" jdbcType="VARCHAR"/>
|
2025-10-06 16:20:05 +08:00
|
|
|
<result column="name" property="name" jdbcType="VARCHAR"/>
|
2025-09-28 17:32:37 +08:00
|
|
|
<result column="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>
|
|
|
|
|
|
2025-10-29 19:08:22 +08:00
|
|
|
<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"/>
|
2025-10-06 16:20:05 +08:00
|
|
|
</resultMap>
|
2025-09-28 17:32:37 +08:00
|
|
|
<!-- 基础字段 -->
|
2025-10-06 16:20:05 +08:00
|
|
|
<sql id="TbSysRole_Column_List">
|
2025-10-09 11:11:14 +08:00
|
|
|
id, role_id, name, description, creator, updater,
|
2025-09-28 17:32:37 +08:00
|
|
|
create_time, update_time, delete_time, deleted
|
|
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
<!-- 通用条件 -->
|
|
|
|
|
<sql id="Where_Clause">
|
|
|
|
|
<where>
|
|
|
|
|
deleted = 0
|
2025-10-09 16:35:49 +08:00
|
|
|
<if test="roleID != null and roleID != ''">
|
|
|
|
|
AND role_id = #{roleID}
|
2025-09-28 17:32:37 +08:00
|
|
|
</if>
|
2025-10-09 16:35:49 +08:00
|
|
|
<if test="name != null and name != ''">
|
|
|
|
|
AND name LIKE CONCAT('%', #{name}, '%')
|
2025-09-28 17:32:37 +08:00
|
|
|
</if>
|
|
|
|
|
</where>
|
|
|
|
|
</sql>
|
|
|
|
|
|
2025-10-09 11:11:14 +08:00
|
|
|
<!-- selectAllRoles -->
|
|
|
|
|
|
|
|
|
|
<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
|
|
|
|
|
</select>
|
|
|
|
|
|
2025-10-09 16:35:49 +08:00
|
|
|
<!-- 根据过滤条件查询角色列表 -->
|
|
|
|
|
<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>
|
|
|
|
|
|
|
|
|
|
<!-- 插入角色 -->
|
|
|
|
|
<insert id="insertRole" parameterType="org.xyzh.common.dto.role.TbSysRole">
|
|
|
|
|
INSERT INTO tb_sys_role
|
|
|
|
|
(id, role_id, name, description, creator, create_time)
|
|
|
|
|
VALUES (#{id}, #{roleID}, #{name}, #{description}, #{creator}, #{createTime})
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
<!-- 更新角色 -->
|
|
|
|
|
<update id="updateRole" parameterType="org.xyzh.common.dto.role.TbSysRole">
|
|
|
|
|
UPDATE tb_sys_role
|
|
|
|
|
(name, description, updater, update_time)
|
|
|
|
|
VALUES (#{name}, #{description}, #{updater}, #{updateTime})
|
|
|
|
|
WHERE role_id = #{roleID}
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
<!-- 删除角色 -->
|
|
|
|
|
<delete id="deleteRole" parameterType="org.xyzh.common.dto.role.TbSysRole">
|
|
|
|
|
DELETE FROM tb_sys_role
|
|
|
|
|
WHERE role_id = #{roleID}
|
|
|
|
|
</delete>
|
|
|
|
|
|
2025-09-28 17:32:37 +08:00
|
|
|
<!-- 根据用户ID查询角色列表 -->
|
2025-10-06 16:20:05 +08:00
|
|
|
<select id="selectDeptRolesByUserId" resultMap="deptRoleVOResultMap">
|
2025-09-28 17:32:37 +08:00
|
|
|
SELECT
|
2025-10-29 19:08:22 +08:00
|
|
|
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
|
2025-10-06 16:20:05 +08:00
|
|
|
FROM tb_sys_user_dept_role dr
|
2025-10-29 19:08:22 +08:00
|
|
|
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
|
2025-10-06 16:20:05 +08:00
|
|
|
WHERE dr.deleted = 0
|
|
|
|
|
AND dr.user_id = #{userId}
|
|
|
|
|
ORDER BY dr.create_time ASC
|
2025-09-28 17:32:37 +08:00
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 根据角色编码查询角色 -->
|
2025-10-06 16:20:05 +08:00
|
|
|
<select id="selectByRoleCode" resultMap="tbSysRoleResultMap">
|
2025-09-28 17:32:37 +08:00
|
|
|
SELECT
|
2025-10-06 16:20:05 +08:00
|
|
|
<include refid="TbSysRole_Column_List"/>
|
2025-09-28 17:32:37 +08:00
|
|
|
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
|
2025-10-09 16:35:49 +08:00
|
|
|
AND name = #{roleName}
|
2025-09-28 17:32:37 +08:00
|
|
|
<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}
|
|
|
|
|
</if>
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 批量删除角色(逻辑删除) -->
|
|
|
|
|
<update id="batchDeleteByIds">
|
|
|
|
|
UPDATE tb_sys_role
|
|
|
|
|
SET deleted = 1,
|
|
|
|
|
delete_time = NOW(),
|
|
|
|
|
updater = #{updater}
|
|
|
|
|
WHERE deleted = 0
|
|
|
|
|
AND id IN
|
|
|
|
|
<foreach collection="roleIds" item="roleId" open="(" separator="," close=")">
|
|
|
|
|
#{roleId}
|
|
|
|
|
</foreach>
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-07 11:02:35 +08:00
|
|
|
<!-- checkRoleExists -->
|
|
|
|
|
|
|
|
|
|
<select id="checkRoleExists">
|
|
|
|
|
SELECT
|
|
|
|
|
<include refid="TbSysRole_Column_List"/>
|
|
|
|
|
FROM tb_sys_role
|
|
|
|
|
WHERE deleted = 0
|
|
|
|
|
AND role_id IN
|
|
|
|
|
<foreach collection="roleIds" item="roleId" open="(" separator="," close=")">
|
|
|
|
|
#{roleId}
|
|
|
|
|
</foreach>
|
|
|
|
|
</select>
|
2025-09-28 17:32:37 +08:00
|
|
|
</mapper>
|