<?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.BdMenuMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.config.BdMenu">
        <id column="PK_ID" property="pkId"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <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="GRADE_VALUES" property="gradeValues"/>
        <result column="AWARD_VALUES" property="awardValues"/>
        <result column="MENU_VALUES" property="menuValues"/>
        <result column="AUTHORITY_VALUES" property="authorityValues"/>
    </resultMap>

    <!-- 查询列表 -->
    <select id="queryList" parameterType="com.hzs.system.config.param.MenuQueryParam"
            resultType="com.hzs.system.config.vo.MenuQueryVO">
        select *
        from BD_MENU bm
        where bm.pk_id in (select bm.pk_id
        from BD_MENU bm
        <if test="param.gradeId != null">
            left join BD_MENU_AUTHORITY bmag
            on bmag.del_flag = 0
            and bmag.pk_menu = bm.pk_id
            and bmag.authority_type = 1
            and bmag.authority_value = #{param.gradeId}
        </if>
        <if test="param.awardsId != null">
            left join BD_MENU_AUTHORITY bmaa
            on bmaa.del_flag = 0
            and bmaa.pk_menu = bm.pk_id
            and bmaa.authority_type = 2
            and bmaa.authority_value = #{param.awardsId}
        </if>
        <if test="param.authorityId != null">
            left join BD_MENU_AUTHORITY bmaa
            on bmaa.del_flag = 0
            and bmaa.pk_menu = bm.pk_id
            and bmaa.authority_type = 3
            and bmaa.authority_value = #{param.authorityId}
        </if>
        <if test="param.menuId != null">
            left join BD_MENU_DETAIL bmd
            on bmd.del_flag = 0
            and bmd.pk_menu = bm.pk_id
            and bmd.detail_value = #{param.menuId}
        </if>
        where bm.del_flag = 0
        and bm.pk_country = #{param.pkCountry}
        <if test="param.creationTime != null">
            and bm.creation_time >= #{param.creationTime[0]}
            and #{param.creationTime[1]} >= bm.creation_time
        </if>
        group by bm.pk_id)
        order by bm.creation_time desc
    </select>

</mapper>
