<?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.cool.store.mapper.SysRoleMenuMapper">
    <resultMap id="BaseResultMap" type="com.cool.store.entity.SysRoleMenuDO">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="menu_id" jdbcType="BIGINT" property="menuId"/>
        <result column="role_id" jdbcType="VARCHAR" property="roleId"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, menu_id, role_id
    </sql>
    <insert id="batchInsert">
        <foreach collection="recordList" item="record" separator=";">
            insert into sys_role_menu
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="record.menuId != null">
                    menu_id,
                </if>
                <if test="record.roleId != null">
                    role_id,
                </if>
            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="record.menuId != null">
                    #{record.menuId},
                </if>
                <if test="record.roleId != null">
                    #{record.roleId},
                </if>
            </trim>
        </foreach>
    </insert>
    <update id="updateByPrimaryKeySelective">
        update sys_role_menu
        <set>
            <if test="record.menuId != null">
                menu_id = #{record.menuId},
            </if>
            <if test="record.roleId != null">
                role_id = #{record.roleId},
            </if>
        </set>
        where id = #{record.id}
    </update>

    <select id="getRoleMenuByRoleId" resultMap="BaseResultMap">
        select
            <include refid="Base_Column_List"/>
        from
            sys_role_menu
        where
            role_id=#{roleId}
    </select>
    
    <delete id="deleteRoleAuth">
        delete from sys_role_menu where role_id=#{roleId}
    </delete>
</mapper>