<?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.ruoyi.ss.menuRole.mapper.MenuRoleMapper">

    <resultMap type="MenuRoleVO" id="MenuRoleResult" autoMapping="true" />

    <sql id="selectMenuRoleVo">
        select
            role_id,
            menu_id
        from ss_menu_role
    </sql>

    <sql id="searchCondition">
    </sql>

    <select id="selectMenuRoleList" parameterType="MenuRoleQuery" resultMap="MenuRoleResult">
        <include refid="selectMenuRoleVo"/>
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <select id="selectMenuRoleByRoleId" parameterType="String" resultMap="MenuRoleResult">
        <include refid="selectMenuRoleVo"/>
        where role_id = #{roleId}
    </select>

    <insert id="insertMenuRole" parameterType="MenuRole">
        insert into ss_menu_role
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="roleId != null">role_id,</if>
            <if test="menuId != null">menu_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="roleId != null">#{roleId},</if>
            <if test="menuId != null">#{menuId},</if>
         </trim>
    </insert>

    <update id="updateMenuRole" parameterType="MenuRole">
        update ss_menu_role
        <trim prefix="SET" suffixOverrides=",">
            <include refid="updateColumns"/>
        </trim>
        where role_id = #{data.roleId}
    </update>

    <sql id="updateColumns">
        <if test="data.menuId != null">menu_id = #{data.menuId},</if>
    </sql>

    <delete id="deleteMenuRoleByRoleId" parameterType="String">
        delete from ss_menu_role where role_id = #{roleId}
    </delete>

    <delete id="deleteMenuRoleByRoleIds" parameterType="String">
        delete from ss_menu_role where role_id in
        <foreach item="roleId" collection="array" open="(" separator="," close=")">
            #{roleId}
        </foreach>
    </delete>
</mapper>
