<?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.hzs.system.config.mapper.BdMenuDetailMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.config.BdMenuDetail">
        <id column="PK_ID" property="pkId"/>
        <result column="PK_MENU" property="pkMenu"/>
        <result column="DETAIL_VALUE" property="detailValue"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
    </resultMap>

    <!-- 批量插入 -->
    <insert id="insertBatch">
        INSERT ALL
        <foreach collection="list" item="item" separator=" ">
            into BD_MENU_DETAIL(PK_MENU, DETAIL_VALUE,
            PK_COUNTRY, PK_CREATOR, CREATION_TIME)
            VALUES (#{item.pkMenu}, #{item.detailValue},
            #{item.pkCountry}, #{item.pkCreator}, #{item.creationTime}
            )
        </foreach>
        SELECT 1 FROM dual
    </insert>

    <!-- 查询会员显示菜单 -->
    <select id="showMenuDetail" resultMap="BaseResultMap">
        select distinct bmd.detail_value
        from (select bm.pk_id
              from BD_MENU bm
                       left join BD_MENU_AUTHORITY bma
                                 on bma.pk_menu = bm.pk_id
                                     and bma.del_flag = 0
              where bm.del_flag = 0
                and bm.pk_country = #{pkCountry}
                and (
                      (bma.authority_type = 1 and bma.authority_value = #{pkGrade}) or
                      (bma.authority_type = 2 and bma.authority_value = #{pkAwards}) or
                      (bma.authority_type = 3 and bma.authority_value = #{authority})
                  )
              group by bm.pk_id) bm
                 left join BD_MENU_DETAIL bmd
                           on bmd.pk_menu = bm.pk_id
                               and bmd.del_flag = 0
        order by detail_value
    </select>


</mapper>
