2021-02-24 21:09:51 +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="ink.wgink.service.role.dao.IRoleUserDao">
|
|
|
|
|
|
|
|
<cache flushInterval="3600000"/>
|
|
|
|
|
|
|
|
<!-- 建表 -->
|
|
|
|
<update id="createTable">
|
|
|
|
CREATE TABLE IF NOT EXISTS `sys_role_user` (
|
|
|
|
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
|
|
|
`role_id` char(36) NOT NULL COMMENT '组ID',
|
|
|
|
`user_id` char(36) NOT NULL,
|
|
|
|
PRIMARY KEY (`id`),
|
|
|
|
KEY `user_id_idx` (`user_id`) USING BTREE,
|
|
|
|
KEY `role_id_idx` (`role_id`) USING BTREE
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
</update>
|
|
|
|
|
|
|
|
<!-- 新增 -->
|
|
|
|
<insert id="save" parameterType="map" flushCache="true">
|
|
|
|
INSERT INTO sys_role_user(
|
|
|
|
role_id,
|
|
|
|
user_id
|
|
|
|
) VALUES(
|
|
|
|
#{roleId},
|
|
|
|
#{userId}
|
|
|
|
)
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
<!-- 删除 -->
|
|
|
|
<delete id="delete" parameterType="map" flushCache="true">
|
|
|
|
DELETE FROM
|
|
|
|
sys_role_user
|
|
|
|
WHERE
|
|
|
|
1 = 1
|
|
|
|
<if test="roleId != null and roleId != ''">
|
|
|
|
AND
|
|
|
|
role_id = #{roleId}
|
|
|
|
</if>
|
|
|
|
<if test="userId != null and userId != ''">
|
|
|
|
AND
|
|
|
|
user_id = #{userId}
|
|
|
|
</if>
|
|
|
|
<if test="userIds != null and userIds.size > 0">
|
|
|
|
AND
|
|
|
|
user_id IN
|
|
|
|
<foreach collection="userIds" index="index" open="(" separator="," close=")">
|
|
|
|
#{userIds[${index}]}
|
|
|
|
</foreach>
|
|
|
|
</if>
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
<!-- 用户ID列表 -->
|
|
|
|
<select id="listUserId" parameterType="map" resultType="java.lang.String" useCache="true">
|
|
|
|
SELECT
|
|
|
|
user_id
|
|
|
|
FROM
|
|
|
|
sys_role_user
|
2022-02-04 21:29:20 +08:00
|
|
|
<where>
|
2021-02-24 21:09:51 +08:00
|
|
|
<if test="roleId != null and roleId != ''">
|
|
|
|
role_id = #{roleId}
|
|
|
|
</if>
|
|
|
|
<if test="roleIds != null and roleIds.size > 0">
|
2022-02-04 21:29:20 +08:00
|
|
|
AND
|
|
|
|
role_id IN
|
2021-02-24 21:09:51 +08:00
|
|
|
<foreach collection="roleIds" index="index" open="(" separator="," close=")">
|
|
|
|
#{roleIds[${index}]}
|
|
|
|
</foreach>
|
|
|
|
</if>
|
2022-02-04 21:29:20 +08:00
|
|
|
<if test="userIds != null and userIds.size > 0">
|
|
|
|
AND
|
|
|
|
user_id IN
|
|
|
|
<foreach collection="userIds" index="index" open="(" separator="," close=")">
|
|
|
|
#{userIds[${index}]}
|
|
|
|
</foreach>
|
|
|
|
</if>
|
|
|
|
</where>
|
2021-02-24 21:09:51 +08:00
|
|
|
</select>
|
|
|
|
|
2021-04-07 23:10:07 +08:00
|
|
|
<!-- 角色ID列表 -->
|
|
|
|
<select id="listRoleId" parameterType="map" resultType="java.lang.String" useCache="true">
|
|
|
|
SELECT
|
|
|
|
role_id
|
|
|
|
FROM
|
|
|
|
sys_role_user
|
|
|
|
WHERE
|
|
|
|
<if test="userId != null and userId != ''">
|
|
|
|
user_id = #{userId}
|
|
|
|
</if>
|
|
|
|
<if test="userIds != null and userIds.size > 0">
|
|
|
|
user_id IN (
|
|
|
|
<foreach collection="userIds" index="index" open="(" separator="," close=")">
|
|
|
|
#{userIds[${index}]}
|
|
|
|
</foreach>
|
|
|
|
)
|
|
|
|
</if>
|
|
|
|
</select>
|
|
|
|
|
2021-02-24 21:09:51 +08:00
|
|
|
<!-- 用户ID列表 -->
|
2021-04-07 23:10:07 +08:00
|
|
|
<select id="listGroupUserId" parameterType="map" resultType="java.lang.String" useCache="true">
|
2021-02-24 21:09:51 +08:00
|
|
|
SELECT
|
|
|
|
user_id
|
|
|
|
FROM
|
|
|
|
sys_role_user
|
|
|
|
WHERE
|
|
|
|
1 = 1
|
|
|
|
GROUP BY
|
|
|
|
user_id
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
</mapper>
|