<?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.sale.postage.mapper.BdPostageAreaMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.sale.postage.BdPostageArea">
    <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="PK_POSTAGE" property="pkPostage" />
        <result column="SPECIAL_AREA" property="specialArea" />
        <result column="FREE_AMOUNT" property="freeAmount" />
        <result column="PROVINCE" property="province" />
        <result column="CITY" property="city" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        CREATION_TIME,
        MODIFIED_TIME,
        DEL_FLAG,
        CITY,
        PROVINCE,
        PK_COUNTRY,
        PK_CREATOR,
        PK_MODIFIED,
        PK_ID, PK_POSTAGE, SPECIAL_AREA, FREE_AMOUNT
    </sql>
    <select id="getPostageArea" resultType="com.hzs.common.domain.sale.postage.BdPostageArea">
        select bd.* from bd_postage bp
        inner join bd_postage_area bd
        on bp.pk_id = bd.pk_postage
        where bp.del_flag=0 and bd.del_flag=0
        <if test="pkCountry != null">
            and bp.pk_country = #{pkCountry}
        </if>
        <if test="pkPostage != null and pkPostage != ''">
            and bd.pk_postage = #{pkPostage}
        </if>
        <if test="tranType != null and tranType != ''">
            and bp.tran_type=#{tranType}
        </if>
        <if test="specialArea != null and specialArea != ''">
            and bd.special_area = #{specialArea}
        </if>
        order by bd.city,bd.province
    </select>

    <select id="selectBySpecialAreaPostage" resultType="com.hzs.common.domain.sale.postage.BdPostageArea">
        select * from bd_postage_area where PK_POSTAGE = #{pkPostage} and PROVINCE  is null and CITY  is null and DEL_FLAG = 0
    </select>
</mapper>
