<?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.fs.company.mapper.CompanyRoleMenuMapper">
    
    <resultMap type="CompanyRoleMenu" id="CompanyRoleMenuResult">
        <result property="roleId"    column="role_id"    />
        <result property="menuId"    column="menu_id"    />
    </resultMap>

    <sql id="selectCompanyRoleMenuVo">
        select role_id, menu_id from company_role_menu
    </sql>

    <select id="selectCompanyRoleMenuList" parameterType="CompanyRoleMenu" resultMap="CompanyRoleMenuResult">
        <include refid="selectCompanyRoleMenuVo"/>
        <where>  
        </where>
    </select>
    
    <select id="selectCompanyRoleMenuById" parameterType="Long" resultMap="CompanyRoleMenuResult">
        <include refid="selectCompanyRoleMenuVo"/>
        where role_id = #{roleId}
    </select>
        
    <insert id="insertCompanyRoleMenu" parameterType="CompanyRoleMenu">
        insert into company_role_menu
        <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="updateCompanyRoleMenu" parameterType="CompanyRoleMenu">
        update company_role_menu
        <trim prefix="SET" suffixOverrides=",">
            <if test="menuId != null">menu_id = #{menuId},</if>
        </trim>
        where role_id = #{roleId}
    </update>

    <delete id="deleteCompanyRoleMenuById" parameterType="Long">
        delete from company_role_menu where role_id = #{roleId}
    </delete>

    <delete id="deleteCompanyRoleMenuByIds" parameterType="String">
        delete from company_role_menu where role_id in 
        <foreach item="roleId" collection="array" open="(" separator="," close=")">
            #{roleId}
        </foreach>
    </delete>
    <select id="checkMenuExistRole" resultType="Integer">
	    select count(1) from company_role_menu where menu_id = #{menuId}
	</select>


    <delete id="deleteRoleMenuByRoleId" parameterType="Long">
		delete from company_role_menu where role_id=#{roleId}
	</delete>

    <insert id="batchRoleMenu">
        insert into company_role_menu(role_id, menu_id) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.roleId},#{item.menuId})
        </foreach>
    </insert>
</mapper>