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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.config.BdLabel">
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <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="LABEL_TYPE" property="labelType"/>
        <result column="PK_TRANSACTION" property="pkTransaction"/>
        <result column="LABEL" property="label"/>
        <result column="LABEL_IMAGE" property="labelImage"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        CREATION_TIME,
        MODIFIED_TIME,
        DEL_FLAG,
        PK_COUNTRY,
        PK_CREATOR,
        PK_MODIFIED,
        PK_ID, LABEL_TYPE, PK_TRANSACTION, LABLE
    </sql>

    <select id="getLabelByPkCountry" resultMap="BaseResultMap">
        select b.pk_id,
        b.label_type,
        b.label,
        b.label_image,
        b.creation_time
        from bd_label b
        where b.pk_country = #{pkCountry}
        and b.del_flag = 0
        <if test="label != null and label != ''">
            and b.label like  '%' || #{label} || '%'
        </if>
        <if test="labelType != null">
            and b.label_type = #{labelType}
        </if>
        <if test="startDate != null and startDate != ''">
            and b.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
        </if>
        <if test="endDate != null and endDate != ''">
            and b.CREATION_TIME &lt;= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
        </if>
    </select>

    <select id="findLabelByType" resultMap="BaseResultMap">
        select b.pk_id ,b.label_type,b.label
          from bd_label b
         where b.pk_country = #{pkCountry}
            and b.label_type = #{labelType}
           and b.del_flag = 0
    </select>


</mapper>
