154 lines
5.8 KiB
XML
154 lines
5.8 KiB
XML
|
|
<?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">
|
|||
|
|
|
|||
|
|
<!-- 基础结果映射 -->
|
|||
|
|
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.role.TbSysRole">
|
|||
|
|
<id column="id" property="id" jdbcType="VARCHAR"/>
|
|||
|
|
<result column="role_id" property="roleID" jdbcType="VARCHAR"/>
|
|||
|
|
<result column="name" property="roleName" jdbcType="VARCHAR"/>
|
|||
|
|
<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>
|
|||
|
|
|
|||
|
|
<!-- 基础字段 -->
|
|||
|
|
<sql id="Base_Column_List">
|
|||
|
|
id, role_id, name, description, creator, updater,
|
|||
|
|
create_time, update_time, delete_time, deleted
|
|||
|
|
</sql>
|
|||
|
|
|
|||
|
|
<!-- 通用条件 -->
|
|||
|
|
<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>
|
|||
|
|
|
|||
|
|
<!-- 根据用户ID查询角色列表 -->
|
|||
|
|
<select id="selectRolesByUserId" resultMap="BaseResultMap">
|
|||
|
|
SELECT
|
|||
|
|
r.id, r.role_id, r.role_name, r.role_code, r.description,
|
|||
|
|
r.status, r.sort, r.creator, r.updater,
|
|||
|
|
r.create_time, r.update_time, r.delete_time, r.deleted
|
|||
|
|
FROM tb_sys_role r
|
|||
|
|
INNER JOIN tb_sys_user_role ur ON r.role_id = ur.role_id
|
|||
|
|
WHERE r.deleted = 0
|
|||
|
|
AND ur.deleted = 0
|
|||
|
|
AND ur.user_id = #{userID}
|
|||
|
|
ORDER BY r.sort ASC, r.create_time ASC
|
|||
|
|
</select>
|
|||
|
|
|
|||
|
|
<!-- 根据角色编码查询角色 -->
|
|||
|
|
<select id="selectByRoleCode" resultMap="BaseResultMap">
|
|||
|
|
SELECT
|
|||
|
|
<include refid="Base_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 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="sort != null">sort,</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="sort != null">#{sort},</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="sort != null">sort = #{sort},</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>
|
|||
|
|
|
|||
|
|
</mapper>
|