|
@@ -1,146 +1,146 @@
|
|
|
-<?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="com.backendsys.mapper.System.SysUserRoleMapper">
|
|
|
+<!--<?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="com.backendsys.mapper.System.SysUserRoleMapper">-->
|
|
|
|
|
|
- <sql id="includeUserRole">
|
|
|
- ur.id id,
|
|
|
- ur.id role_id,
|
|
|
- ur.role_name role_name,
|
|
|
--- ur.role_description role_description,
|
|
|
- COALESCE(ur.role_description, '') role_description,
|
|
|
--- COUNT(us.id) user_count,
|
|
|
--- NULLIF(COUNT(us.id), 0) AS user_count,
|
|
|
--- CASE WHEN COUNT(us.id) = 0 THEN NULL ELSE COUNT(us.id) END AS user_count,
|
|
|
- ur.sort sort,
|
|
|
- ur.status status
|
|
|
- </sql>
|
|
|
+<!-- <sql id="includeUserRole">-->
|
|
|
+<!-- ur.id id,-->
|
|
|
+<!-- ur.id role_id,-->
|
|
|
+<!-- ur.role_name role_name,-->
|
|
|
+<!---- ur.role_description role_description,-->
|
|
|
+<!-- COALESCE(ur.role_description, '') role_description,-->
|
|
|
+<!---- COUNT(us.id) user_count,-->
|
|
|
+<!---- NULLIF(COUNT(us.id), 0) AS user_count,-->
|
|
|
+<!---- CASE WHEN COUNT(us.id) = 0 THEN NULL ELSE COUNT(us.id) END AS user_count,-->
|
|
|
+<!-- ur.sort sort,-->
|
|
|
+<!-- ur.status status-->
|
|
|
+<!-- </sql>-->
|
|
|
|
|
|
- <resultMap id="resultMapUserRoleList" type="java.util.LinkedHashMap">
|
|
|
- <id property="id" column="id" jdbcType="BIGINT" />
|
|
|
- <result property="role_id" column="role_id" javaType="java.lang.Long"/>
|
|
|
- <result property="role_name" column="role_name" />
|
|
|
- <result property="role_description" column="role_description" />
|
|
|
- <result property="user_count" column="user_count" />
|
|
|
- <result property="sort" column="sort" />
|
|
|
- <result property="status" column="status" javaType="java.lang.Integer"/>
|
|
|
- </resultMap>
|
|
|
+<!-- <resultMap id="resultMapUserRoleList" type="java.util.LinkedHashMap">-->
|
|
|
+<!-- <id property="id" column="id" jdbcType="BIGINT" />-->
|
|
|
+<!-- <result property="role_id" column="role_id" javaType="java.lang.Long"/>-->
|
|
|
+<!-- <result property="role_name" column="role_name" />-->
|
|
|
+<!-- <result property="role_description" column="role_description" />-->
|
|
|
+<!-- <result property="user_count" column="user_count" />-->
|
|
|
+<!-- <result property="sort" column="sort" />-->
|
|
|
+<!-- <result property="status" column="status" javaType="java.lang.Integer"/>-->
|
|
|
+<!-- </resultMap>-->
|
|
|
|
|
|
- <resultMap id="resultMapUserRoleDetail" type="java.util.LinkedHashMap">
|
|
|
- <id property="id" column="id" jdbcType="BIGINT" />
|
|
|
- <result property="role_name" column="role_name" />
|
|
|
- <result property="role_description" column="role_description" />
|
|
|
- <result property="user_count" column="user_count" />
|
|
|
- <result property="sort" column="sort" />
|
|
|
- <result property="status" column="status" javaType="java.lang.Integer"/>
|
|
|
- <!--<result property="module_code" column="module_code" />-->
|
|
|
- <collection property="modules" javaType="java.util.List" ofType="java.util.LinkedHashMap"
|
|
|
- select="queryModulesByRoleId" column="id">
|
|
|
- <id property="module_id" column="module_id" />
|
|
|
- <result property="parent_id" column="parent_id" />
|
|
|
- <result property="module_name" column="module_name" />
|
|
|
- </collection>
|
|
|
- </resultMap>
|
|
|
- <!-- [嵌套查询] 查询角色下的全部模块 -->
|
|
|
- <!--um.module_code,-->
|
|
|
- <select id="queryModulesByRoleId" resultType="java.util.LinkedHashMap">
|
|
|
- SELECT
|
|
|
- um.id, um.module_name,
|
|
|
- COALESCE(um.parent_id, '') AS parent_id
|
|
|
- FROM sys_user_role_module_relation umr
|
|
|
- LEFT JOIN sys_user_role_module um ON umr.module_id = um.id
|
|
|
- WHERE umr.role_id = #{id}
|
|
|
- </select>
|
|
|
+<!-- <resultMap id="resultMapUserRoleDetail" type="java.util.LinkedHashMap">-->
|
|
|
+<!-- <id property="id" column="id" jdbcType="BIGINT" />-->
|
|
|
+<!-- <result property="role_name" column="role_name" />-->
|
|
|
+<!-- <result property="role_description" column="role_description" />-->
|
|
|
+<!-- <result property="user_count" column="user_count" />-->
|
|
|
+<!-- <result property="sort" column="sort" />-->
|
|
|
+<!-- <result property="status" column="status" javaType="java.lang.Integer"/>-->
|
|
|
+<!-- <!–<result property="module_code" column="module_code" />–>-->
|
|
|
+<!-- <collection property="modules" javaType="java.util.List" ofType="java.util.LinkedHashMap"-->
|
|
|
+<!-- select="queryModulesByRoleId" column="id">-->
|
|
|
+<!-- <id property="module_id" column="module_id" />-->
|
|
|
+<!-- <result property="parent_id" column="parent_id" />-->
|
|
|
+<!-- <result property="module_name" column="module_name" />-->
|
|
|
+<!-- </collection>-->
|
|
|
+<!-- </resultMap>-->
|
|
|
+<!-- <!– [嵌套查询] 查询角色下的全部模块 –>-->
|
|
|
+<!-- <!–um.module_code,–>-->
|
|
|
+<!-- <select id="queryModulesByRoleId" resultType="java.util.LinkedHashMap">-->
|
|
|
+<!-- SELECT-->
|
|
|
+<!-- um.id, um.module_name,-->
|
|
|
+<!-- COALESCE(um.parent_id, '') AS parent_id-->
|
|
|
+<!-- FROM sys_user_role_module_relation umr-->
|
|
|
+<!-- LEFT JOIN sys_user_role_module um ON umr.module_id = um.id-->
|
|
|
+<!-- WHERE umr.role_id = #{id}-->
|
|
|
+<!-- </select>-->
|
|
|
|
|
|
- <!-- 查询 用户角色列表 -->
|
|
|
- <select id="queryUserRoleList" resultMap="resultMapUserRoleList">
|
|
|
- SELECT <include refid="includeUserRole" />, COUNT(us.id) user_count
|
|
|
- FROM sys_user_role ur
|
|
|
- LEFT JOIN sys_user_role_relation urr ON ur.id = urr.role_id
|
|
|
- LEFT JOIN sys_user us ON us.id = urr.user_id
|
|
|
- <where>
|
|
|
- <if test="role_name != null and role_name != ''">
|
|
|
- AND ur.role_name LIKE CONCAT('%', #{role_name}, '%')
|
|
|
- </if>
|
|
|
- <if test="status != null and status != ''">
|
|
|
- AND ur.status = #{status}
|
|
|
- </if>
|
|
|
- </where>
|
|
|
- GROUP BY ur.id, ur.role_name
|
|
|
- ORDER BY ur.sort ASC
|
|
|
- </select>
|
|
|
+<!-- <!– 查询 用户角色列表 –>-->
|
|
|
+<!-- <select id="queryUserRoleList" resultMap="resultMapUserRoleList">-->
|
|
|
+<!-- SELECT <include refid="includeUserRole" />, COUNT(us.id) user_count-->
|
|
|
+<!-- FROM sys_user_role ur-->
|
|
|
+<!-- LEFT JOIN sys_user_role_relation urr ON ur.id = urr.role_id-->
|
|
|
+<!-- LEFT JOIN sys_user us ON us.id = urr.user_id-->
|
|
|
+<!-- <where>-->
|
|
|
+<!-- <if test="role_name != null and role_name != ''">-->
|
|
|
+<!-- AND ur.role_name LIKE CONCAT('%', #{role_name}, '%')-->
|
|
|
+<!-- </if>-->
|
|
|
+<!-- <if test="status != null and status != ''">-->
|
|
|
+<!-- AND ur.status = #{status}-->
|
|
|
+<!-- </if>-->
|
|
|
+<!-- </where>-->
|
|
|
+<!-- GROUP BY ur.id, ur.role_name-->
|
|
|
+<!-- ORDER BY ur.sort ASC-->
|
|
|
+<!-- </select>-->
|
|
|
|
|
|
- <!-- 查询 用户角色详情 -->
|
|
|
- <!-- 由于,在使用关联查询时,COUNT() 会导致输出的格式有误,从而导致原本输出 null 会变成 { user_count: 0 } -->
|
|
|
- <!-- 因此,在使用 @QueryNullCheck 判断是否存在时,不要出现 COUNT 语法 -->
|
|
|
- <!-- 此处关联查询改为 impl 中查询合并 -->
|
|
|
- <select id="queryUserRoleDetail" resultMap="resultMapUserRoleDetail">
|
|
|
- SELECT <include refid="includeUserRole" />
|
|
|
- FROM sys_user_role ur
|
|
|
--- LEFT JOIN sys_user_role_relation urr ON ur.id = urr.role_id
|
|
|
--- LEFT JOIN sys_user us ON us.id = urr.user_id
|
|
|
- WHERE ur.id = #{role_id}
|
|
|
- </select>
|
|
|
+<!-- <!– 查询 用户角色详情 –>-->
|
|
|
+<!-- <!– 由于,在使用关联查询时,COUNT() 会导致输出的格式有误,从而导致原本输出 null 会变成 { user_count: 0 } –>-->
|
|
|
+<!-- <!– 因此,在使用 @QueryNullCheck 判断是否存在时,不要出现 COUNT 语法 –>-->
|
|
|
+<!-- <!– 此处关联查询改为 impl 中查询合并 –>-->
|
|
|
+<!-- <select id="queryUserRoleDetail" resultMap="resultMapUserRoleDetail">-->
|
|
|
+<!-- SELECT <include refid="includeUserRole" />-->
|
|
|
+<!-- FROM sys_user_role ur-->
|
|
|
+<!---- LEFT JOIN sys_user_role_relation urr ON ur.id = urr.role_id-->
|
|
|
+<!---- LEFT JOIN sys_user us ON us.id = urr.user_id-->
|
|
|
+<!-- WHERE ur.id = #{role_id}-->
|
|
|
+<!-- </select>-->
|
|
|
|
|
|
- <!-- 根据角色关系表,查询用户数量 -->
|
|
|
- <select id="queryUserCountByRoleId" resultType="java.util.LinkedHashMap">
|
|
|
- SELECT COUNT(us.id) user_count
|
|
|
- FROM sys_user_role_relation urr
|
|
|
- LEFT JOIN sys_user us ON us.id = urr.user_id
|
|
|
- WHERE urr.role_id = #{role_id}
|
|
|
- </select>
|
|
|
+<!-- <!– 根据角色关系表,查询用户数量 –>-->
|
|
|
+<!-- <select id="queryUserCountByRoleId" resultType="java.util.LinkedHashMap">-->
|
|
|
+<!-- SELECT COUNT(us.id) user_count-->
|
|
|
+<!-- FROM sys_user_role_relation urr-->
|
|
|
+<!-- LEFT JOIN sys_user us ON us.id = urr.user_id-->
|
|
|
+<!-- WHERE urr.role_id = #{role_id}-->
|
|
|
+<!-- </select>-->
|
|
|
|
|
|
|
|
|
- <!-- 创建 用户角色 -->
|
|
|
- <insert id="insertUserRole" parameterType="com.backendsys.entity.System.SysUserRoleDTO" useGeneratedKeys="true" keyProperty="id">
|
|
|
- INSERT INTO sys_user_role (role_name
|
|
|
- <if test="role_description != null">, role_description</if>
|
|
|
- <if test="sort != null">, sort</if>
|
|
|
- <if test="status != null">, status</if>
|
|
|
- ) VALUES (#{role_name}
|
|
|
- <if test="role_description != null">, #{role_description}</if>
|
|
|
- <if test="sort != null">, #{sort}</if>
|
|
|
- <if test="status != null">, #{status}</if>
|
|
|
- )
|
|
|
- </insert>
|
|
|
- <!-- 创建 用户角色 对应的 模块关系 -->
|
|
|
- <insert id="insertUserRoleModuleRelation" parameterType="com.backendsys.entity.System.SysUserRoleDTO">
|
|
|
- INSERT INTO sys_user_role_module_relation (role_id, module_id)
|
|
|
- VALUES
|
|
|
- <foreach collection="modules" item="module" separator=",">
|
|
|
- (#{id}, #{module.id})
|
|
|
- </foreach>
|
|
|
- </insert>
|
|
|
+<!-- <!– 创建 用户角色 –>-->
|
|
|
+<!-- <insert id="insertUserRole" parameterType="com.backendsys.entity.System.SysUserRoleDTO" useGeneratedKeys="true" keyProperty="id">-->
|
|
|
+<!-- INSERT INTO sys_user_role (role_name-->
|
|
|
+<!-- <if test="role_description != null">, role_description</if>-->
|
|
|
+<!-- <if test="sort != null">, sort</if>-->
|
|
|
+<!-- <if test="status != null">, status</if>-->
|
|
|
+<!-- ) VALUES (#{role_name}-->
|
|
|
+<!-- <if test="role_description != null">, #{role_description}</if>-->
|
|
|
+<!-- <if test="sort != null">, #{sort}</if>-->
|
|
|
+<!-- <if test="status != null">, #{status}</if>-->
|
|
|
+<!-- )-->
|
|
|
+<!-- </insert>-->
|
|
|
+<!-- <!– 创建 用户角色 对应的 模块关系 –>-->
|
|
|
+<!-- <insert id="insertUserRolePermissionRelation" parameterType="com.backendsys.entity.System.SysUserRoleDTO">-->
|
|
|
+<!-- INSERT INTO sys_user_role_module_relation (role_id, module_id)-->
|
|
|
+<!-- VALUES-->
|
|
|
+<!-- <foreach collection="modules" item="module" separator=",">-->
|
|
|
+<!-- (#{id}, #{module.id})-->
|
|
|
+<!-- </foreach>-->
|
|
|
+<!-- </insert>-->
|
|
|
|
|
|
|
|
|
- <!-- 编辑 用户角色 -->
|
|
|
- <update id="updateUserRole" parameterType="com.backendsys.entity.System.SysUserRoleDTO">
|
|
|
- UPDATE sys_user_role SET
|
|
|
- <trim suffixOverrides="," suffix=" ">
|
|
|
- <if test="role_name != null and role_name != ''">role_name = #{role_name},</if>
|
|
|
- <if test="role_description != null and role_description != ''">role_description = #{role_description},</if>
|
|
|
- <if test="sort != null and sort != ''">sort = #{sort},</if>
|
|
|
- <if test="status != null and status != ''">status = #{status},</if>
|
|
|
- </trim>
|
|
|
- WHERE id = #{role_id}
|
|
|
- </update>
|
|
|
- <!-- 编辑 用户角色 对应的 模块关系-->
|
|
|
- <update id="updateUserRoleModuleRelation" parameterType="com.backendsys.entity.System.SysUserRoleDTO">
|
|
|
- <!--删除符合条件的数据-->
|
|
|
- DELETE FROM sys_user_role_module_relation WHERE role_id = #{role_id};
|
|
|
- <!--判断是否有新的数据需要插入-->
|
|
|
- <if test="modules != null and modules.size() > 0">
|
|
|
- INSERT INTO sys_user_role_module_relation (role_id, module_id)
|
|
|
- VALUES
|
|
|
- <foreach collection="modules" item="module" separator=",">
|
|
|
- (#{role_id}, #{module.id})
|
|
|
- </foreach>
|
|
|
- </if>
|
|
|
- </update>
|
|
|
+<!-- <!– 编辑 用户角色 –>-->
|
|
|
+<!-- <update id="updateUserRole" parameterType="com.backendsys.entity.System.SysUserRoleDTO">-->
|
|
|
+<!-- UPDATE sys_user_role SET-->
|
|
|
+<!-- <trim suffixOverrides="," suffix=" ">-->
|
|
|
+<!-- <if test="role_name != null and role_name != ''">role_name = #{role_name},</if>-->
|
|
|
+<!-- <if test="role_description != null and role_description != ''">role_description = #{role_description},</if>-->
|
|
|
+<!-- <if test="sort != null and sort != ''">sort = #{sort},</if>-->
|
|
|
+<!-- <if test="status != null and status != ''">status = #{status},</if>-->
|
|
|
+<!-- </trim>-->
|
|
|
+<!-- WHERE id = #{role_id}-->
|
|
|
+<!-- </update>-->
|
|
|
+<!-- <!– 编辑 用户角色 对应的 模块关系–>-->
|
|
|
+<!-- <update id="updateUserRolePermissionRelation" parameterType="com.backendsys.entity.System.SysUserRoleDTO">-->
|
|
|
+<!-- <!–删除符合条件的数据–>-->
|
|
|
+<!-- DELETE FROM sys_user_role_module_relation WHERE role_id = #{role_id};-->
|
|
|
+<!-- <!–判断是否有新的数据需要插入–>-->
|
|
|
+<!-- <if test="modules != null and modules.size() > 0">-->
|
|
|
+<!-- INSERT INTO sys_user_role_module_relation (role_id, module_id)-->
|
|
|
+<!-- VALUES-->
|
|
|
+<!-- <foreach collection="modules" item="module" separator=",">-->
|
|
|
+<!-- (#{role_id}, #{module.id})-->
|
|
|
+<!-- </foreach>-->
|
|
|
+<!-- </if>-->
|
|
|
+<!-- </update>-->
|
|
|
|
|
|
- <!-- 删除 用户角色 (同时删除模块关系) -->
|
|
|
- <delete id="deleteUserRole" parameterType="java.lang.Long">
|
|
|
- DELETE FROM sys_user_role WHERE id = #{role_id};
|
|
|
- DELETE FROM sys_user_role_module_relation WHERE role_id = #{role_id};
|
|
|
- </delete>
|
|
|
+<!-- <!– 删除 用户角色 (同时删除模块关系) –>-->
|
|
|
+<!-- <delete id="deleteUserRole" parameterType="java.lang.Long">-->
|
|
|
+<!-- DELETE FROM sys_user_role WHERE id = #{role_id};-->
|
|
|
+<!-- DELETE FROM sys_user_role_module_relation WHERE role_id = #{role_id};-->
|
|
|
+<!-- </delete>-->
|
|
|
|
|
|
-</mapper>
|
|
|
+<!--</mapper>-->
|