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-06 16:20:05 +08:00
|
|
|
|
<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>
|
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>
|
2025-10-06 16:20:05 +08:00
|
|
|
|
<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>
|
2025-09-28 17:32:37 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- 通用条件 -->
|
|
|
|
|
|
<sql id="Where_Clause">
|
|
|
|
|
|
<where>
|
|
|
|
|
|
deleted = 0
|
|
|
|
|
|
<if test="roleName != null and roleName != ''">
|
|
|
|
|
|
AND role_name LIKE CONCAT('%', #{roleName}, '%')
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="roleCode != null and roleCode != ''">
|
|
|
|
|
|
AND role_code = #{roleCode}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="status != null">
|
|
|
|
|
|
AND status = #{status}
|
|
|
|
|
|
</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-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-06 16:20:05 +08:00
|
|
|
|
<include refid="TbSysDeptRole_Column_List"/>
|
|
|
|
|
|
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
|
|
|
|
|
|
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
|
|
|
|
|
|
AND role_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}
|
|
|
|
|
|
</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>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 插入角色 -->
|
|
|
|
|
|
<insert id="insert" parameterType="org.xyzh.common.dto.role.TbSysRole">
|
|
|
|
|
|
INSERT INTO tb_sys_role
|
|
|
|
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
|
|
|
<if test="id != null">id,</if>
|
|
|
|
|
|
<if test="roleID != null">role_id,</if>
|
|
|
|
|
|
<if test="roleName != null">role_name,</if>
|
|
|
|
|
|
<if test="roleCode != null">role_code,</if>
|
|
|
|
|
|
<if test="description != null">description,</if>
|
|
|
|
|
|
<if test="status != null">status,</if>
|
|
|
|
|
|
<if test="creator != null">creator,</if>
|
|
|
|
|
|
<if test="createTime != null">create_time,</if>
|
|
|
|
|
|
deleted
|
|
|
|
|
|
</trim>
|
|
|
|
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
|
|
|
<if test="id != null">#{id},</if>
|
|
|
|
|
|
<if test="roleID != null">#{roleID},</if>
|
|
|
|
|
|
<if test="roleName != null">#{roleName},</if>
|
|
|
|
|
|
<if test="roleCode != null">#{roleCode},</if>
|
|
|
|
|
|
<if test="description != null">#{description},</if>
|
|
|
|
|
|
<if test="status != null">#{status},</if>
|
|
|
|
|
|
<if test="creator != null">#{creator},</if>
|
|
|
|
|
|
<if test="createTime != null">#{createTime},</if>
|
|
|
|
|
|
0
|
|
|
|
|
|
</trim>
|
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 更新角色 -->
|
|
|
|
|
|
<update id="updateById" parameterType="org.xyzh.common.dto.role.TbSysRole">
|
|
|
|
|
|
UPDATE tb_sys_role
|
|
|
|
|
|
<set>
|
|
|
|
|
|
<if test="roleID != null">role_id = #{roleID},</if>
|
|
|
|
|
|
<if test="roleName != null">role_name = #{roleName},</if>
|
|
|
|
|
|
<if test="roleCode != null">role_code = #{roleCode},</if>
|
|
|
|
|
|
<if test="description != null">description = #{description},</if>
|
|
|
|
|
|
<if test="status != null">status = #{status},</if>
|
|
|
|
|
|
<if test="updater != null">updater = #{updater},</if>
|
|
|
|
|
|
update_time = NOW()
|
|
|
|
|
|
</set>
|
|
|
|
|
|
WHERE id = #{id} AND deleted = 0
|
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 根据ID删除(逻辑删除) -->
|
|
|
|
|
|
<update id="deleteById">
|
|
|
|
|
|
UPDATE tb_sys_role
|
|
|
|
|
|
SET deleted = 1,
|
|
|
|
|
|
delete_time = NOW()
|
|
|
|
|
|
WHERE id = #{id} AND deleted = 0
|
|
|
|
|
|
</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>
|