<?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.gic.haoban.manage.service.dao.mapper.role.TabHaobanRoleMenuMapper">

    <resultMap type="com.gic.haoban.manage.service.entity.role.TabHaobanRoleMenu" id="TabHaobanRoleMenuMap">
        <result property="roleMenuId" column="role_menu_id" jdbcType="INTEGER"/>
        <result property="roleId" column="role_id" jdbcType="INTEGER"/>
        <result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
        <result property="menuCode" column="menu_code" jdbcType="VARCHAR"/>
        <result property="statusFlag" column="status_flag" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
    role_menu_id, role_id, wx_enterprise_id ,menu_code, status_flag, create_time, update_time
  </sql>

    <insert id="insertBatch" keyProperty="roleMenuId" useGeneratedKeys="true">
        insert into tab_haoban_role_menu( role_menu_id, role_id,wx_enterprise_id,menu_code, status_flag, create_time, update_time)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.roleMenuId},#{entity.roleId}, #{entity.wxEnterpriseId},#{entity.menuCode}, #{entity.statusFlag}, #{entity.createTime}, #{entity.updateTime})
        </foreach>
    </insert>

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


    <select id="getByWxEnterpriseIdAndRoleId" resultType="java.lang.String">
        select
        menu_code
        from tab_haoban_role_menu
        where wx_enterprise_id = #{wxEnterpriseId} and role_id = #{roleId}
    </select>

    <delete id="deleteByWxEnterpriseId">
        delete from tab_haoban_role_menu where wx_enterprise_id = #{wxEnterpriseId}
    </delete>


    <select id="getMenuInMenuCodes" resultType="java.lang.String">
        select
            menu_code
        from tab_haoban_role_menu
        where wx_enterprise_id = #{wxEnterpriseId} and role_id = #{roleId}
        and menu_code in
        <foreach collection="menuCodes" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </select>

    <delete id="deleteByMenuCodeAndRoleId">
        delete from tab_haoban_role_menu where wx_enterprise_id = #{wxEnterpriseId} and menu_code = #{menuCode} and role_id = #{roleId}
    </delete>

</mapper>

