<?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.general.mapper.IcGeneralInBMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="IcGeneralInBExt" type="com.hzs.common.domain.scm.general.ext.IcGeneralInBExt">
        <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_GENERAL" property="pkGeneral" />
        <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="NCOSTPRICE" property="ncostprice" />
        <result column="NCOSTMNY" property="ncostmny" />
        <result column="PK_BATCH_CODE" property="pkBatchCode" />
        <result column="PRODUCT_CODE" property="productCode" />
        <result column="PRODUCT_NAME" property="productName" />
        <collection property="scmItemSpecsList" ofType="com.hzs.common.domain.scm.pub.ScmItemSpecs" >
            <result column="PK_SPECS_TYPE" property="pkSpecsType" />
            <result column="PK_SPECS" property="pkSpecs" />
            <result column="SPECS_NAME" property="specsName" />
        </collection>
    </resultMap>

    <update id="deleteGeneralItemsByList">
        update ic_generalin_b set del_flag = 1,pk_modified=#{pkMember},modified_time = sysdate where del_flag=0 and
        pk_id in
        <foreach collection="icGeneralInbList" item="item" open="(" close=")" separator=",">
            #{item.pkId}
        </foreach>
    </update>
    <select id="queryGeneralInbByList" resultMap="IcGeneralInBExt">
        select ib.*,bp.pk_product_bas,ic.product_date,ic.expire_date,it.pk_specs_type,it.pk_specs,it.specs_name from ic_generalin_b ib
        inner join scm_item_specs it
        on ib.pk_id=it.pk_order_items
        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 it.order_type= #{orderType}
        and it.pk_order_items in
        <foreach collection="icGeneralInbExtList" item="item" open="(" close=")" separator=",">
            #{item.pkId}
        </foreach>
        order by ib.pk_id,it.pk_specs
    </select>
    <select id="queryGeneralInbByPk" resultMap="IcGeneralInBExt">
        select ib.*,bp.pk_product_bas,ic.product_date,ic.expire_date,
               bp.pk_id pk_product,bp.product_code,bp.product_name,it.pk_specs_type,it.pk_specs,it.specs_name from ic_generalin_b ib
        inner join scm_item_specs it
        on ib.pk_id=it.pk_order_items and it.order_type=3
        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_general = #{pkOrder}
    </select>

</mapper>
