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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.config.BdTradeConfig">
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_ID" property="pkId"/>
        <result column="PK_GRADE" property="pkGrade"/>
        <result column="PK_AWARDS" property="pkAwards"/>
        <result column="BUSINESS_MODULE" property="businessModule"/>
        <result column="REAL_NAME_STATE" property="realNameState"/>
        <result column="LICENSE_STATE" property="licenseState"/>
    </resultMap>

    <select id="selectTradeConfigList" resultMap="BaseResultMap">
        select * from BD_TRADE_CONFIG c where c.del_flag = 0
        and c.pk_country= #{pkCountry}
        <if test="pkGrade != null and pkGrade != ''">
            and instr(',' || c.PK_GRADE || ',', ',' || #{pkGrade} || ',') > 0
        </if>
        <if test="pkAwards != null and pkAwards != ''">
            and instr(',' || c.PK_AWARDS || ',', ',' || #{pkAwards} || ',') > 0
        </if>
        <if test="realNameState != null">
            and c.REAL_NAME_STATE = #{realNameState}
        </if>
        <if test="licenseState != null">
            and c.LICENSE_STATE = #{licenseState}
        </if>
        <if test="startDate != null and startDate != ''">
            and c.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate != ''">
            and c.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
        order by c.creation_time desc
    </select>


    <select id="selectTradeConfigByCondition" resultMap="BaseResultMap">
        select t.*
        from (select *
        from BD_TRADE_CONFIG c
        where c.del_flag = 0
        and c.pk_country= #{pkCountry}
        <if test="pkGrade != null and pkGrade != ''">
            and instr(',' || c.PK_GRADE || ',', ',' || #{pkGrade} || ',') > 0
        </if>
        <if test="pkAwards != null and pkAwards != ''">
            and instr(',' || c.PK_AWARDS || ',', ',' || #{pkAwards} || ',') > 0
        </if>
        <if test="realNameState != null">
            and c.REAL_NAME_STATE = #{realNameState}
        </if>
        <if test="licenseState != null">
            and c.LICENSE_STATE = #{licenseState}
        </if>
        <if test="businessModule != null">
            and c.BUSINESS_MODULE = #{businessModule}
        </if>
        order by c.creation_time desc) t
        where rownum = 1
    </select>

</mapper>
