<?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.ground.postage.mapper.ThSupplierPostageMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.scm.postage.ThSupplierPostage">
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_ID" property="pkId"/>
        <result column="PK_WARES" property="pkWares"/>
        <result column="PK_CUBASDOC" property="pkCubasdoc"/>

        <result column="PK_AREA" property="pkArea"/>
        <result column="POSTAGE" property="postage"/>
    </resultMap>

    <select id="querySupplierPostageByOrder" resultType="com.hzs.common.domain.scm.postage.ext.ThSupplierPostageExt">
        <foreach item="item" index="index" collection="orderItemsExtList" separator=" union ">
            select #{item.pkOrder} pk_order,a.* from th_supplier_postage a where del_flag=0
            and pk_wares=#{item.pkWares} and a.pk_cubasdoc=#{item.pkSupplier}
        </foreach>
    </select>

    <select id="selectByQueryList" resultType="com.hzs.ground.postage.vo.SupplierPostageVo">
        select sp.PK_ID       pkId,
               sp.PK_WARES    pkWares,
               sp.PK_CUBASDOC pkCubasdoc,
               sp.PK_AREA     pkArea,
               sp.POSTAGE     postage,
               bw.WARES_NAME  waresName,
               bc.CUST_NAME   custName,
               ba.name        areaName
        from th_supplier_postage sp
                 left join bd_wares bw on bw.pk_id = sp.PK_WARES
                 left join BD_CUBASDOC bc on bc.pk_id = sp.PK_CUBASDOC
                 left join BD_AREA ba on ba.pk_id = sp.PK_AREA
        where  1 = 1 and sp.del_flag = 0
        <if test="waresName != null and waresName != ''">
            and bw.WARES_NAME  like #{waresName} || '%'
        </if>
        <if test="custName != null and custName != ''">
            and bc.CUST_NAME  like #{custName} || '%'
        </if>
        <if test="pkArea != null">
            and ba.PK_ID  = #{pkArea}
        </if>
        <if test="pkCubasdoc != null">
            and sp.PK_CUBASDOC  = #{pkCubasdoc}
        </if>
    </select>

    <select id="selectByPkId" resultType="com.hzs.ground.postage.vo.SupplierPostageVo">
        select sp.PK_ID       pkId,
               sp.PK_WARES    pkWares,
               sp.PK_CUBASDOC pkCubasdoc,
               sp.PK_AREA     pkArea,
               sp.POSTAGE     postage,
               bw.WARES_NAME  waresName,
               bc.CUST_NAME   custName,
               ba.name        areaName
        from th_supplier_postage sp
                 left join bd_wares bw on bw.pk_id = sp.PK_WARES
                 left join BD_CUBASDOC bc on bc.PK_ID = sp.PK_CUBASDOC
                 left join BD_AREA ba on ba.pk_id = sp.PK_AREA
where sp.PK_ID = #{pkSupplierPostage}
    </select>

</mapper>
