186 lines
7.8 KiB
XML
186 lines
7.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.PermissionMapper">
|
|||
|
|
|
|||
|
|
<!-- 基础结果映射 -->
|
|||
|
|
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.permission.TbSysPermission">
|
|||
|
|
<id column="id" property="id" jdbcType="VARCHAR"/>
|
|||
|
|
<result column="permission_id" property="permissionID" jdbcType="VARCHAR"/>
|
|||
|
|
<result column="name" property="permissionName" jdbcType="VARCHAR"/>
|
|||
|
|
<result column="code" property="permissionCode" 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, permission_id, name, code, description, creator, updater,
|
|||
|
|
create_time, update_time, delete_time, deleted
|
|||
|
|
</sql>
|
|||
|
|
|
|||
|
|
<!-- 通用条件 -->
|
|||
|
|
<sql id="Where_Clause">
|
|||
|
|
<where>
|
|||
|
|
deleted = 0
|
|||
|
|
<if test="permissionName != null and permissionName != ''">
|
|||
|
|
AND permission_name LIKE CONCAT('%', #{permissionName}, '%')
|
|||
|
|
</if>
|
|||
|
|
<if test="permissionCode != null and permissionCode != ''">
|
|||
|
|
AND permission_code = #{permissionCode}
|
|||
|
|
</if>
|
|||
|
|
<if test="permissionType != null">
|
|||
|
|
AND permission_type = #{permissionType}
|
|||
|
|
</if>
|
|||
|
|
<if test="status != null">
|
|||
|
|
AND status = #{status}
|
|||
|
|
</if>
|
|||
|
|
</where>
|
|||
|
|
</sql>
|
|||
|
|
|
|||
|
|
<!-- 根据用户ID查询权限列表 -->
|
|||
|
|
<select id="selectPermissionsByUserId" resultMap="BaseResultMap">
|
|||
|
|
SELECT DISTINCT
|
|||
|
|
p.id, p.permission_id, p.permission_name, p.permission_code,
|
|||
|
|
p.permission_type, p.resource_url, p.http_method, p.description,
|
|||
|
|
p.status, p.sort, p.creator, p.updater,
|
|||
|
|
p.create_time, p.update_time, p.delete_time, p.deleted
|
|||
|
|
FROM tb_sys_permission p
|
|||
|
|
INNER JOIN tb_sys_role_permission rp ON p.permission_id = rp.permission_id
|
|||
|
|
INNER JOIN tb_sys_user_role ur ON rp.role_id = ur.role_id
|
|||
|
|
WHERE p.deleted = 0
|
|||
|
|
AND rp.deleted = 0
|
|||
|
|
AND ur.deleted = 0
|
|||
|
|
AND ur.user_id = #{userID}
|
|||
|
|
AND p.status = 1
|
|||
|
|
ORDER BY p.sort ASC, p.create_time ASC
|
|||
|
|
</select>
|
|||
|
|
|
|||
|
|
<!-- 根据角色ID查询权限列表 -->
|
|||
|
|
<select id="selectPermissionsByRoleId" resultMap="BaseResultMap">
|
|||
|
|
SELECT
|
|||
|
|
p.id, p.permission_id, p.permission_name, p.permission_code,
|
|||
|
|
p.permission_type, p.resource_url, p.http_method, p.description,
|
|||
|
|
p.status, p.sort, p.creator, p.updater,
|
|||
|
|
p.create_time, p.update_time, p.delete_time, p.deleted
|
|||
|
|
FROM tb_sys_permission p
|
|||
|
|
INNER JOIN tb_sys_role_permission rp ON p.permission_id = rp.permission_id
|
|||
|
|
WHERE p.deleted = 0
|
|||
|
|
AND rp.deleted = 0
|
|||
|
|
AND rp.role_id = #{roleId}
|
|||
|
|
ORDER BY p.sort ASC, p.create_time ASC
|
|||
|
|
</select>
|
|||
|
|
|
|||
|
|
<!-- 根据权限编码查询权限 -->
|
|||
|
|
<select id="selectByPermissionCode" resultMap="BaseResultMap">
|
|||
|
|
SELECT
|
|||
|
|
<include refid="Base_Column_List"/>
|
|||
|
|
FROM tb_sys_permission
|
|||
|
|
WHERE deleted = 0
|
|||
|
|
AND permission_code = #{permissionCode}
|
|||
|
|
LIMIT 1
|
|||
|
|
</select>
|
|||
|
|
|
|||
|
|
<!-- 检查权限名称是否存在 -->
|
|||
|
|
<select id="countByPermissionName" resultType="int">
|
|||
|
|
SELECT COUNT(1)
|
|||
|
|
FROM tb_sys_permission
|
|||
|
|
WHERE deleted = 0
|
|||
|
|
AND permission_name = #{permissionName}
|
|||
|
|
<if test="excludeId != null and excludeId != ''">
|
|||
|
|
AND id != #{excludeId}
|
|||
|
|
</if>
|
|||
|
|
</select>
|
|||
|
|
|
|||
|
|
<!-- 检查权限编码是否存在 -->
|
|||
|
|
<select id="countByPermissionCode" resultType="int">
|
|||
|
|
SELECT COUNT(1)
|
|||
|
|
FROM tb_sys_permission
|
|||
|
|
WHERE deleted = 0
|
|||
|
|
AND permission_code = #{permissionCode}
|
|||
|
|
<if test="excludeId != null and excludeId != ''">
|
|||
|
|
AND id != #{excludeId}
|
|||
|
|
</if>
|
|||
|
|
</select>
|
|||
|
|
|
|||
|
|
<!-- 批量删除权限(逻辑删除) -->
|
|||
|
|
<update id="batchDeleteByIds">
|
|||
|
|
UPDATE tb_sys_permission
|
|||
|
|
SET deleted = 1,
|
|||
|
|
delete_time = NOW(),
|
|||
|
|
updater = #{updater}
|
|||
|
|
WHERE deleted = 0
|
|||
|
|
AND id IN
|
|||
|
|
<foreach collection="permissionIds" item="permissionId" open="(" separator="," close=")">
|
|||
|
|
#{permissionId}
|
|||
|
|
</foreach>
|
|||
|
|
</update>
|
|||
|
|
|
|||
|
|
<!-- 插入权限 -->
|
|||
|
|
<insert id="insert" parameterType="org.xyzh.common.dto.permission.TbSysPermission">
|
|||
|
|
INSERT INTO tb_sys_permission
|
|||
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|||
|
|
<if test="id != null">id,</if>
|
|||
|
|
<if test="permissionID != null">permission_id,</if>
|
|||
|
|
<if test="permissionName != null">permission_name,</if>
|
|||
|
|
<if test="permissionCode != null">permission_code,</if>
|
|||
|
|
<if test="permissionType != null">permission_type,</if>
|
|||
|
|
<if test="resourceUrl != null">resource_url,</if>
|
|||
|
|
<if test="httpMethod != null">http_method,</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="permissionID != null">#{permissionID},</if>
|
|||
|
|
<if test="permissionName != null">#{permissionName},</if>
|
|||
|
|
<if test="permissionCode != null">#{permissionCode},</if>
|
|||
|
|
<if test="permissionType != null">#{permissionType},</if>
|
|||
|
|
<if test="resourceUrl != null">#{resourceUrl},</if>
|
|||
|
|
<if test="httpMethod != null">#{httpMethod},</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.permission.TbSysPermission">
|
|||
|
|
UPDATE tb_sys_permission
|
|||
|
|
<set>
|
|||
|
|
<if test="permissionID != null">permission_id = #{permissionID},</if>
|
|||
|
|
<if test="permissionName != null">permission_name = #{permissionName},</if>
|
|||
|
|
<if test="permissionCode != null">permission_code = #{permissionCode},</if>
|
|||
|
|
<if test="permissionType != null">permission_type = #{permissionType},</if>
|
|||
|
|
<if test="resourceUrl != null">resource_url = #{resourceUrl},</if>
|
|||
|
|
<if test="httpMethod != null">http_method = #{httpMethod},</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_permission
|
|||
|
|
SET deleted = 1,
|
|||
|
|
delete_time = NOW()
|
|||
|
|
WHERE id = #{id} AND deleted = 0
|
|||
|
|
</update>
|
|||
|
|
|
|||
|
|
</mapper>
|