<?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.github.tangyi.user.mapper.RoleMenuMapper">
    <resultMap id="roleMenuResultMap" type="com.github.tangyi.user.api.module.RoleMenu">
        <id column="id" property="id"/>
        <result column="role_id" property="roleId"/>
        <result column="menu_id" property="menuId"/>
    </resultMap>

    <sql id="roleMenuColumns">
        a.id,
        a.role_id,
        a.menu_id
    </sql>

    <insert id="insert">
        INSERT  INTO sys_role_menu (
            id,
            role_id,
            menu_id
        ) VALUES (
            #{id},
            #{roleId},
            #{menuId}
        )
    </insert>

    <insert id="insertBatch" useGeneratedKeys="false">
        INSERT INTO sys_role_menu (
            id,
            role_id,
            menu_id)
        VALUES
            <foreach collection="list" item="item" index="index" separator=",">
                (#{item.id}, #{item.roleId}, #{item.menuId})
            </foreach>
    </insert>

    <delete id="deleteByRoleId">
        delete from sys_role_menu
        where role_id = #{roleId}
    </delete>

    <delete id="deleteByMenuId">
        delete from sys_role_menu
        where menu_id = #{menuId}
    </delete>
</mapper>
