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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.sale.postage.BdPostage">
        <id column="PK_ID" property="pkId"/>
        <result column="TEMP_NAME" property="tempName"/>
        <result column="PK_TRANSACTION_KEY" property="pkTransactionKey"/>
        <result column="TRAN_TYPE" property="tranType"/>
        <result column="REMARK" property="remark"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="CHARGE_TYPE" property="chargeType"/>
        <result column="QUANTITY_MODE" property="quantityMode"/>
    </resultMap>

    <resultMap id="BaseResultVoMap" type="com.hzs.sale.postage.vo.PostageVo">
        <id column="PK_ID" property="pkId"/>
        <result column="TEMP_NAME" property="tempName"/>
        <result column="PK_TRANSACTION_KEY" property="pkTransactionKey"/>
        <result column="TRAN_TYPE" property="tranType"/>
        <result column="REMARK" property="remark"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="CHARGE_TYPE" property="chargeType"/>
        <result column="NATIONAL_FLAG2" property="nationalFlag2"/>
        <result column="SHORT_NAME" property="shortName"/>
        <result column="specialPostageCount" property="specialPostageCount"/>
    </resultMap>

    <select id="selectByList" resultMap="BaseResultVoMap">
        select bp.PK_ID,
               bp.TEMP_NAME,
               bp.REMARK,
               bp.CREATION_TIME,
               bp.MODIFIED_TIME,
               bp.DEL_FLAG,
               bp.PK_COUNTRY,
               bp.TRAN_TYPE,
               bp.PK_CREATOR,
               bp.PK_MODIFIED,
               bp.CHARGE_TYPE,
               bd.NATIONAL_FLAG2,
               bd.SHORT_NAME,
               (select count(sp.PK_ID) from bd_wares_special_postage sp where sp.PK_POSTAGE = bp.PK_ID) specialPostageCount
        from bd_postage bp
                 left join bd_country bd on bd.PK_ID = bp.PK_COUNTRY
        where bp.PK_COUNTRY = #{pkCountry}
          and bp.del_flag = 0
        order by bp.creation_time desc
    </select>

</mapper>
