<?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.scm.sale.mapper.IcSaleoutBMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="IcSaleoutBExt" type="com.hzs.common.domain.scm.sale.ext.IcSaleoutBExt">
        <id column="PK_ID" property="pkId" />
        <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_UNIT" property="pkUnit" />
        <result column="PK_SA_ORDER" property="pkSaOrder" />
        <result column="PK_SA_ORDER_ITEMS" property="pkSaOrderItems" />
        <result column="PK_DELIVERY" property="pkDelivery" />
        <result column="PK_DELIVER_ITEMS" property="pkDeliverItems" />
        <result column="PK_SALEOUT" property="pkSaleout" />
        <result column="PK_SOURCE" property="pkSource" />
        <result column="PK_SOURCE_B" property="pkSourceB" />
        <result column="PK_CLOCATION" property="pkClocation" />
        <result column="PK_PRODUCT" property="pkProduct" />
        <result column="PK_PRODUCT_BAS" property="pkProductBas" />
        <result column="PRODUCT_DATE" property="productDate" />
        <result column="EXPIRE_DATE" property="expireDate" />
        <result column="TRANS_TYPE" property="transType" />
        <result column="BIZ_DATE" property="bizDate" />
        <result column="PK_STOREHOUSE" property="pkStorehouse" />
        <result column="PK_RATE" property="pkRate" />
        <result column="NNUM" property="nnum" />
        <result column="NORIGPRICE" property="norigprice" />
        <result column="NTAXRATE" property="ntaxrate" />
        <result column="NORIGTAXPRICE" property="norigtaxprice" />
        <result column="NORIGMNY" property="norigmny" />
        <result column="NTAX" property="ntax" />
        <result column="NORIGTAXMNY" property="norigtaxmny" />
        <result column="PK_BATCH_CODE" property="pkBatchCode" />
        <result column="IS_GIFT" property="isGift" />
        <collection property="scmItemSpecsList" ofType="com.hzs.common.domain.scm.pub.ScmItemSpecs" >
            <result column="ORDER_TYPE" property="orderType" />
            <result column="PK_SPECS_TYPE" property="pkSpecsType" />
            <result column="PK_SPECS" property="pkSpecs" />
            <result column="SPECS_NAME" property="specsName" />
        </collection>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        CREATION_TIME,
        MODIFIED_TIME,
        DEL_FLAG,
        PK_CREATOR,
        PK_MODIFIED,
        PK_COUNTRY,
        PK_ID, PK_UNIT, PK_SA_ORDER, PK_SA_ORDER_ITEMS, PK_DELIVERY, PK_DELIVER_ITEMS, PK_SALEOUT, PK_CLOCATION, PK_PRODUCT, TRANS_TYPE, BIZ_DATE, PK_STOREHOUSE, PK_RATE, NNUM, NORIGPRICE, NTAXRATE, NORIGTAXPRICE, NORIGMNY, NTAX, NORIGTAXMNY, PK_BATCH_CODE, IS_GIFT
    </sql>
    <insert id="insertSaleOutBiByList">
        insert ALL
        <foreach item="item" index="index" collection="saleOutBiExtList" separator=" " >
            into IC_SALEOUT_B(PK_ID,PK_UNIT,PK_SA_ORDER,PK_SA_ORDER_ITEMS,
            PK_DELIVERY,PK_DELIVER_ITEMS,PK_SALEOUT,PK_CLOCATION,
            PK_PRODUCT,BIZ_DATE,PK_STOREHOUSE,PK_RATE,NNUM,
            NORIGPRICE,NTAXRATE,NORIGTAXPRICE,NORIGMNY,
            NTAX,NORIGTAXMNY,PK_BATCH_CODE,IS_GIFT,
            PK_CREATOR,PK_COUNTRY)
            values
            (
            #{item.pkId},#{item.pkUnit},#{item.pkSaOrder},#{item.pkSaOrderItems},
            #{item.pkDelivery},#{item.pkDeliverItems},#{item.pkSaleout},#{item.pkClocation,jdbcType=INTEGER},
            #{item.pkProduct},#{item.bizDate},#{item.pkStorehouse},#{item.pkRate,jdbcType=INTEGER},
            #{item.nnum},#{item.norigprice},#{item.ntaxrate},#{item.norigtaxprice},
            #{item.norigmny},#{item.ntax},#{item.norigtaxmny},#{item.pkBatchCode,jdbcType=BIGINT},
            #{item.isGift},#{item.pkCreator},#{item.pkCountry}
            )
        </foreach>
        SELECT 1 FROM dual
    </insert>
    <select id="querySaleOutBiSql" resultType="java.lang.Long">
        SELECT ic_saleout_b_seq.nextval
        FROM (select level from dual connect by #{size} >= level)
    </select>

    <select id="querySaleOutBiExtByPk" resultMap="IcSaleoutBExt">
        select ib.*,bp.pk_product_bas,ic.product_date,ic.expire_date,
               bp.pk_id pk_product,bp.product_code,bp.product_name,it.order_type,
               it.pk_specs_type,it.pk_specs,it.specs_name from ic_saleout_b ib
       inner join scm_item_specs it
                  on ib.pk_id=it.pk_order_items and it.order_type=6
       inner join bd_product bp
                  on bp.pk_id=ib.pk_product
       left join ic_batch_code ic
                 on ic.pk_id=ib.pk_batch_code
        where ib.del_flag=0 and it.del_flag=0 and bp.del_flag=0
          and ib.pk_country = #{pkCountry}
          and ib.pk_saleout = #{pkSaleOut}
    </select>
    <select id="queryBackSaleOutBiByPk" resultMap="IcSaleoutBExt">
        select ib.*,bp.pk_product_bas,ic.product_date,ic.expire_date,
        it.pk_specs_type,it.pk_specs,it.specs_name from ic_saleout_b ib
        inner join scm_item_specs it
        on ib.pk_id=it.pk_order_items and it.order_type=6
        inner join bd_product bp
        on bp.pk_id=ib.pk_product
        left join ic_batch_code ic
        on ic.pk_id=ib.pk_batch_code
        where ib.del_flag=0 and it.del_flag=0
        and it.pk_order_items in
        <foreach collection="saleOutBiExtList" item="item" open="(" close=")" separator=",">
            #{item.pkId}
        </foreach>
        order by ib.pk_id,it.pk_specs
    </select>
</mapper>
