<?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.dk.mdm.mapper.ivt.InboundItemMapper">

    <!-- 通用设置 -->
    <!-- 通用查询列 -->
    <sql id="Base_Column_List">
        item_id, into_id, into_type, from_id, from_item_id, item_index, sku_id, price_into, non_std_code,
        into_status, intoing_qty, intoing_amt, into_qty, into_amt, return_qty, return_amt,
        remarks, inv_id, cost_price, cost_amt, out_qty, inv_qty, flg_valid, cp_id, op_create_time,
        op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user,
        s_into_id,s_into_item_id,s_pur_id,s_pur_item_id
    </sql>

    <!-- response通用查询列 -->
    <sql id="Base_Column_List_Response">
        tpii.item_id, tpii.into_id, tpii.into_type, tpii.from_id, tpii.from_item_id, tpii.item_index, tpii.sku_id, tpii.price_into,
        tpii.non_std_code, tpii.into_status, tpii.intoing_qty, tpii.intoing_amt, tpii.into_qty, tpii.into_amt, tpii.return_qty,
        tpii.return_amt, tpii.remarks, tpii.inv_id, tpii.cost_price, tpii.cost_amt, tpii.out_qty, tpii.inv_qty, tpii.flg_valid,
        tpii.cp_id,tpii.s_into_id,tpii.s_into_item_id,tpii.s_pur_id,tpii.s_pur_item_id
    </sql>


    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.ivt.InboundItem">
        <id column="item_id" property="itemId"/>
                <result column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
                <result column="into_type" property="intoType"/>
                <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
                <result column="from_item_id" property="fromItemId" typeHandler="UuidTypeHandler"/>
                <result column="item_index" property="itemIndex"/>
                <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
                <result column="price_into" property="priceInto"/>
                <result column="non_std_code" property="nonStdCode"/>
                <result column="into_status" property="intoStatus"/>
                <result column="intoing_qty" property="intoingQty"/>
                <result column="intoing_amt" property="intoingAmt"/>
                <result column="into_qty" property="intoQty"/>
                <result column="into_amt" property="intoAmt"/>
                <result column="return_qty" property="returnQty"/>
                <result column="return_amt" property="returnAmt"/>
                <result column="remarks" property="remarks"/>
                <result column="inv_id" property="invId" typeHandler="UuidTypeHandler"/>
                <result column="cost_price" property="costPrice"/>
                <result column="cost_amt" property="costAmt"/>
                <result column="out_qty" property="outQty"/>
                <result column="inv_qty" property="invQty"/>
                <result column="flg_valid" property="flgValid"/>
                <result column="cp_id" property="cpId"/>
            <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
                <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
            <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
                <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
                <result column="op_app_code" property="opAppCode"/>
            <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
                <result column="op_db_user" property="opDbUser"/>
        <result column="s_into_id" property="sIntoId" typeHandler="UuidTypeHandler"/>
        <result column="s_into_item_id" property="sIntoItemId" typeHandler="UuidTypeHandler"/>
        <result column="s_pur_id" property="sPurId" typeHandler="UuidTypeHandler"/>
        <result column="s_pur_item_id" property="sPurItemId" typeHandler="UuidTypeHandler"/>
    </resultMap>


    <!-- response查询映射结果 -->
    <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.ivt.InboundItemResponse">
        <id column="item_id" property="itemId"/>
        <result column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
        <result column="into_type" property="intoType"/>
        <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
        <result column="from_item_id" property="fromItemId" typeHandler="UuidTypeHandler"/>
        <result column="item_index" property="itemIndex"/>
        <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
        <result column="price_into" property="priceInto"/>
        <result column="non_std_code" property="nonStdCode"/>
        <result column="into_status" property="intoStatus"/>
        <result column="intoing_qty" property="intoingQty"/>
        <result column="intoing_amt" property="intoingAmt"/>
        <result column="into_qty" property="intoQty"/>
        <result column="into_amt" property="intoAmt"/>
        <result column="return_qty" property="returnQty"/>
        <result column="return_amt" property="returnAmt"/>
        <result column="remarks" property="remarks"/>
        <result column="inv_id" property="invId" typeHandler="UuidTypeHandler"/>
        <result column="cost_price" property="costPrice"/>
        <result column="cost_amt" property="costAmt"/>
        <result column="brandName" property="brandName"/>
        <result column="out_qty" property="outQty"/>
        <result column="inv_qty" property="invQty"/>
        <result column="flg_valid" property="flgValid"/>
        <result column="cp_id" property="cpId"/>
        <result column="price_purchase" property="pricePurchase"/>
        <result column="sku_images" property="skuImages" typeHandler="JsonTypeHandler"/>
        <result column="s_into_id" property="sIntoId" typeHandler="UuidTypeHandler"/>
        <result column="s_into_item_id" property="sIntoItemId" typeHandler="UuidTypeHandler"/>
        <result column="s_pur_id" property="sPurId" typeHandler="UuidTypeHandler"/>
        <result column="s_pur_item_id" property="sPurItemId" typeHandler="UuidTypeHandler"/>
    </resultMap>
<!--    退货用-->
    <resultMap id="BaseResultMapReturnResponse" type="com.dk.mdm.model.response.ivt.InboundItemResponse">
        <id column="item_id" property="itemId"/>
        <result column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
        <result column="into_type" property="intoType"/>
        <result column="from_id" property="fromId" typeHandler="UuidTypeHandler"/>
        <result column="from_item_id" property="fromItemId" typeHandler="UuidTypeHandler"/>
        <result column="item_index" property="itemIndex"/>
        <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
        <result column="price_into" property="priceInto"/>
        <result column="non_std_code" property="nonStdCode"/>
        <result column="into_status" property="intoStatus"/>
        <result column="intoing_qty" property="intoingQty"/>
        <result column="intoing_amt" property="intoingAmt"/>
        <result column="into_qty" property="intoQty"/>
        <result column="into_amt" property="intoAmt"/>
        <result column="return_qty" property="returnQty"/>
        <result column="return_amt" property="returnAmt"/>
        <result column="remarks" property="remarks"/>
        <result column="inv_id" property="invId" typeHandler="UuidTypeHandler"/>
        <result column="cost_price" property="costPrice"/>
        <result column="cost_amt" property="costAmt"/>
        <result column="out_qty" property="outQty"/>
        <result column="inv_qty" property="invQty"/>
        <result column="flg_valid" property="flgValid"/>
        <result column="cp_id" property="cpId"/>
        <result column="s_into_id" property="sIntoId" typeHandler="UuidTypeHandler"/>
        <result column="s_into_item_id" property="sIntoItemId" typeHandler="UuidTypeHandler"/>
        <result column="s_pur_id" property="sPurId" typeHandler="UuidTypeHandler"/>
        <result column="s_pur_item_id" property="sPurItemId" typeHandler="UuidTypeHandler"/>
        <result column="sku_images" property="skuImages" typeHandler="JsonTypeHandler"/>
        <result column="sIntoItemIntoingQty" property="sIntoItemIntoingQty"/>
        <result column="sIntoItemIntoingAmt" property="sIntoItemIntoingAmt"/>
        <result column="sIntoItemIntoQty" property="sIntoItemIntoQty"/>
        <result column="sIntoItemIntoAmt" property="sIntoItemIntoAmt"/>
        <result column="sIntoItemReturnQty" property="sIntoItemReturnQty"/>
        <result column="sIntoItemReturnAmt" property="sIntoItemReturnAmt"/>


        <result column="sPurItemIntoingQty" property="sPurItemIntoingQty"/>
        <result column="sPurItemIntoingAmt" property="sPurItemIntoingAmt"/>
        <result column="sPurItemIntoQty" property="sPurItemIntoQty"/>
        <result column="sPurItemIntoAmt" property="sPurItemIntoAmt"/>
        <result column="sPurItemReturnQty" property="sPurItemReturnQty"/>
        <result column="sPurItemReturnAmt" property="sPurItemReturnAmt"/>
        <result column="usableQty" property="usableQty"/>
        <result column="nonStdCode" property="nonStdCode"/>

    </resultMap>

    <!-- 通用条件列 -->
    <sql id="Condition">
        <where>
            tpii.flg_valid
            <if test="intoId != null and intoId != ''">
                AND tpii.into_id = #{intoId}::uuid
            </if>
            <if test="intoType != null and intoType != ''">
                AND tpii.into_type = #{intoType}
            </if>
            <if test="fromId != null and fromId != ''">
                AND tpii.from_id = #{fromId}
            </if>
            <if test="fromItemId != null and fromItemId != ''">
                AND tpii.from_item_id = #{fromItemId}
            </if>
            <if test="itemIndex != null">
                AND tpii.item_index = #{itemIndex}
            </if>
            <if test="skuId != null and skuId != ''">
                AND tpii.sku_id = #{skuId}
            </if>
            <if test="priceInto != null">
                AND tpii.price_into = #{priceInto}
            </if>
            <if test="nonStdCode != null and nonStdCode != ''">
                AND tpii.non_std_code = #{nonStdCode}
            </if>
            <if test="invId != null and invId != ''">
                AND tpii.inv_id = #{invId}
            </if>
            <if test="cpId != null">
                AND tpii.cp_id = #{cpId}
            </if>
        </where>
    </sql>

    <sql id="idsForeach">
        <!-- 根据主键itemId批量操作 -->
        WHERE item_id in
        <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </sql>

    <!-- 查询表dkic_b.t_psi_inbound_item，（条件查询+分页）列表 -->
    <select id="selectByCond" resultMap="BaseResultMapResponse">
        SELECT
        <include refid="Base_Column_List_Response"/>
        ,tpii.wh_id as "whId"
        ,tmw.wh_name as "whName"
        ,tmgs.sku_code  as "skuCode"
        ,tmgs.sku_model as "skuModel"
        ,tmgs.sku_name  as "skuName"
        ,tmgs.sku_spec  as "skuSpec"
        ,tmgs.price_purchase
        ,tmgs.sku_images
        ,tmgb.brand_name  as "brandName"
        ,tmgb.short_name  as "shortName"
        ,tpp.pur_id as "purId"
        ,tpp.pur_no as "purNo"
        ,tppi.item_qty as "purItemQty"
        ,tppi.intoing_qty as "purItemIntoingQty"
        ,tppi.into_qty as "purItemIntoQty"
        ,tpiv.inv_qty
        FROM dkic_b.t_psi_inbound_item tpii
        left join dkic_b.t_psi_inventory tpiv on tpiv.inv_id = tpii.inv_id
        left join dkic_b.t_psi_purchase_item tppi on tppi.item_id = tpii.from_item_id
        left join dkic_b.t_psi_purchase tpp on tpp.pur_id = tpii.from_id
        left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
        left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpii.inv_id
        left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
        <include refid="Condition"/>
        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
            limit #{end} offset #{start}
        </if>
    </select>

    <!-- 查询表dkic_b.t_psi_inbound_item，（条件查询）个数 -->
    <select id="countByCond" resultType="Long">
        SELECT
        count(1)
        FROM dkic_b.t_psi_inbound_item tpii
        left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
        left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpii.inv_id
        left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
        <include refid="Condition"/>
    </select>

    <!-- 根据主键查询表dkic_b.t_psi_inbound_item的一行数据 -->
    <select id="selectById" resultMap="BaseResultMapResponse">
        SELECT
        <include refid="Base_Column_List_Response"/>
        FROM dkic_b.t_psi_inbound_item tpii
        WHERE tpii.item_id = #{id}::uuid
    </select>

    <!-- 根据主键锁定表dkic_b.t_psi_inbound_item的一行数据 -->
    <select id="selectByIdForUpdate" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM dkic_b.t_psi_inbound_item
        WHERE item_id = #{itemId}
        for update
    </select>

    <!-- 根据主键锁定表dkic_b.t_psi_inbound_item的多行数据 -->
    <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM dkic_b.t_psi_inbound_item
        <include refid="idsForeach"/>
        for update
    </select>

    <insert id="insertBatch">
        insert into dkic_b.t_psi_inbound_item
        (
        <trim suffixOverrides=",">
            into_id,
            into_type,
            from_id,
            from_item_id,
            item_index,
            sku_id,
            price_into,
            non_std_code,
            into_status,
            intoing_qty,
            intoing_amt,
            into_qty,
            into_amt,
            return_qty,
            return_amt,
            remarks,
            inv_id,
            cost_price,
            cost_amt,
            out_qty,
            inv_qty,
            cp_id,
            op_app_code,
            s_into_id,
            s_into_item_id,
            s_pur_id,
            s_pur_item_id,
        </trim>
        )
        values
        <foreach collection="list" index="index" item="item" separator=",">
            (
            <trim suffixOverrides=",">
                #{item.intoId}::uuid,
                #{item.intoType},
                #{item.fromId}::uuid,
                #{item.fromItemId}::uuid,
                #{item.itemIndex},
                #{item.skuId}::uuid,
                #{item.priceInto},
                #{item.nonStdCode},
                #{item.intoStatus},
                #{item.intoingQty},
                #{item.intoingAmt},
                #{item.intoQty},
                #{item.intoAmt},
                #{item.returnQty},
                #{item.returnAmt},
                #{item.remarks},
                #{item.invId}::uuid,
                #{item.costPrice},
                #{item.costAmt},
                #{item.outQty},
                #{item.invQty},
                #{item.cpId},
                #{item.opAppCode},
                #{item.sIntoId}::uuid,
                #{item.sIntoItemId}::uuid,
                #{item.sPurId}::uuid,
                #{item.sPurItemId}::uuid,
            </trim>
            )
        </foreach>
    </insert>

    <update id="updateAmount" parameterType="com.dk.mdm.model.pojo.ivt.InboundItem">
        update dkic_b.t_psi_inbound_item
        <set>
            <if test="returnQty!= null">
                return_qty= #{returnQty},
            </if>
            <if test="returnAmt!= null">
                return_amt = #{returnAmt},
            </if>
        </set>
        where item_id = #{itemId}::uuid
    </update>


    <!-- 入库办理显示字段 -->
    <sql id="Base_Column_List_Response_Into">
        tpii.item_id,
        tpii.into_id,
        tpii.into_type,
        tpii.from_id,
        tpii.from_item_id,
        tpii.item_index,
        tpii.sku_id,
        tpii.price_into,
        tpii.non_std_code,
        tpii.into_status,
        tpii.intoing_qty,
        tpii.intoing_amt,
        tpii.into_qty,
        tpii.into_amt,
        tpii.return_qty,
        tpii.return_amt,
        tpii.remarks,
        tpii.inv_id,
        tpii.cost_price,
        tpii.cost_amt,
        tpii.wh_id,
        tpii.inv_qty
    </sql>
    <sql id="Base_Column_List_Response_Out">
        tpoi.item_id,
        tpoi.out_id as into_id,
        tpoi.out_type as into_type,
        tpoi.from_id,
        tpoi.from_item_id,
        tpoi.item_index,
        tpoi.sku_id,
        tpoi.price_out as price_into,
        tpoi.non_std_code,
        tpoi.out_status as into_status,
        tpoi.outing_qty as intoing_amt ,
        tpoi.outing_amt as intoing_qty ,
        tpoi.out_qty as into_qty ,
        tpoi.out_amt as into_amt ,
        tpoi.return_qty,
        tpoi.return_amt,
        tpoi.remarks,
        tpoi.inv_id,
        tpoi.cost_price,
        tpoi.cost_amt,
        null as  wh_id,
        null  as inv_qty
    </sql>
    <!--条件查询 web端入库办理用-->
    <select id="selectInboundItem" resultMap="BaseResultMapResponse">
        SELECT
        <include refid="Base_Column_List_Response_Into"/>
        ,tmgs.sku_code  as "skuCode"
        ,tmgs.sku_model as "skuModel"
        ,tmgs.sku_name  as "skuName"
        ,tmgs.sku_spec  as "skuSpec"
        ,tmgb.brand_name  as "brandName"
        ,tmgb.short_name  as "shortName"
        ,tmw.wh_name as "whName"
        FROM dkic_b.t_psi_inbound_item tpii
        <include refid="Select_Inbound_Join_Table_Into"/>
        <where>
            tpii.flg_valid
            <if test="intoId != null and intoId != ''">
                AND tpii.into_id = #{intoId}::uuid
            </if>
        </where>
        union all
        select
        <include refid="Base_Column_List_Response_Out"/>
        ,tmgs.sku_code  as "skuCode"
        ,tmgs.sku_model as "skuModel"
        ,tmgs.sku_name  as "skuName"
        ,tmgs.sku_spec  as "skuSpec"
        ,tmgb.brand_name  as "brandName"
        ,tmgb.short_name  as "shortName"
        ,null as "whName"
        from dkic_b.t_psi_outbound_item tpoi
        <include refid="Select_Inbound_Join_Table_Out"/>
        <where>
            tpoi.flg_valid
            <if test="intoId != null and intoId != ''">
                AND tpoi.out_id = #{intoId}::uuid
            </if>
        </where>
    </select>
    <!--入库办理显示入库关联表-->
    <sql id="Select_Inbound_Join_Table_Into">
        left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
        left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpii.inv_id
        left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
    </sql>
    <sql id="Select_Inbound_Join_Table_Out">
        left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpoi.sku_id
        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
        left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpoi.inv_id
    </sql>


    <delete id="deleteByFromId" parameterType="com.dk.mdm.model.pojo.ivt.InboundItem">

        DELETE FROM dkic_b.t_psi_inbound_item WHERE from_item_id =  #{fromItemId}::uuid
    </delete>



    <update id="updateIntoStatus" parameterType="com.dk.mdm.model.pojo.ivt.InboundItem">
        update dkic_b.t_psi_inbound_item
        <set>
            <if test="intoStatus!= null">
                into_status= #{intoStatus},
            </if>

        </set>
        where item_id = #{itemId}::uuid
    </update>

    <select id="selectByInboundReturnCond" resultMap="BaseResultMapReturnResponse">
        SELECT
        <include refid="Base_Column_List_Response"/>
        ,tmgs.sku_code  as "skuCode"
        ,tmgs.sku_model as "skuModel"
        ,tmgs.sku_name  as "skuName"
        ,tmgs.sku_spec  as "skuSpec"
        ,tmgs.sku_images
        ,tmgb.brand_name  as "brandName"
        ,tmgb.short_name  as "shortName"
        ,tmw.wh_id as "whId"
        ,tmw.wh_code as "whCode"
        ,tmw.wh_name as "whName"
        ,tpsii.intoing_qty as "sIntoItemIntoingQty"
        ,tpsii.intoing_amt as "sIntoItemIntoingAmt"
        ,tpsii.into_qty as "sIntoItemIntoQty"
        ,tpsii.into_amt as "sIntoItemIntoAmt"
        ,tpsii.return_qty as "sIntoItemReturnQty"
        ,tpsii.return_amt as "sIntoItemReturnAmt"

        ,tppi.intoing_qty as "sPurItemIntoingQty"
        ,tppi.intoing_amt as "sPurItemIntoingAmt"
        ,tppi.into_qty as "sPurItemIntoQty"
        ,tppi.into_amt as "sPurItemIntoAmt"
        ,tppi.return_qty as "sPurItemReturnQty"
        ,tppi.return_amt as "sPurItemReturnAmt"

        ,tpi.usable_qty AS "usableQty"
        ,tpi.non_std_code AS "nonStdCode"
        FROM dkic_b.t_psi_inbound_item tpii
        left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
        left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpii.inv_id
        left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id

        left join  dkic_b.t_psi_inbound_item  tpsii  on  tpsii.item_id = tpii.s_into_item_id
        left join  dkic_b.t_psi_purchase_item  tppi  on  tppi.item_id = tpii.s_pur_item_id
        <include refid="Condition"/>
        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
            limit #{end} offset #{start}
        </if>
    </select>



    <!-- 条件查询 (入库成本核对用) -->
    <select id="selectCostCheck" resultMap="BaseResultMapResponse">
        SELECT
        <include refid="Base_Column_List_Response"/>
        ,tpid.into_no as "intoNo"
        ,tmgs.sku_code  as "skuCode"
        ,tmgs.sku_model as "skuModel"
        ,tmgs.sku_name  as "skuName"
        ,tmgs.sku_spec  as "skuSpec"
        ,tmgb.brand_name  as "brandName"
        ,tmgb.short_name  as "shortName"
        ,tpp.pur_id as "purId"
        ,tpp.pur_no as "purNo"
        ,tppi.item_qty as "purItemQty"
        ,tppi.intoing_qty as "purItemIntoingQty"
        ,tppi.into_qty as "purItemIntoQty"
        ,tmp.sup_code as "supCode"
        ,tmp.sup_name as "supName"
        ,tpiv.inv_qty
        FROM dkic_b.t_psi_inbound_item tpii
        left join dkic_b.t_psi_inbound tpid on tpii.into_id = tpid.into_id
        left join dkic_b.t_psi_inventory tpiv on tpiv.inv_id = tpii.inv_id
        left join dkic_b.t_psi_purchase_item tppi on tppi.item_id = tpii.from_item_id
        left join dkic_b.t_psi_purchase tpp on tpp.pur_id = tpii.from_id
        left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
        left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpii.inv_id
        left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
        Left join dkic_b.t_mst_supplier tmp on tpid.sup_id = tmp.sup_id
        <where>
            tpii.flg_valid
            and tpii.into_qty &lt;&gt; 0
            <if test="intoId != null and intoId != ''">
                AND tpii.into_id = #{intoId}::uuid
            </if>
            <if test="intoNo != null and intoNo != ''">
                AND tpid.into_no LIKE concat('%',my_ex.likequery(#{intoNo}),'%')
            </if>
            <if test="supId != null and supId != ''">
                AND tpid.sup_id = #{supId}::uuid
            </if>
            <if test="intoDateStart != null">
                AND tpid.into_date &gt;= #{intoDateStart}::timestamp with time zone
            </if>
            <if test="intoDateEnd != null">
                AND tpid.into_date &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
            </if>
            <if test="skuName != null and skuName!='' ">
                AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
            </if>
            <if test="cpId != null">
                AND tpii.cp_id = #{cpId}
            </if>
        </where>
        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
            limit #{end} offset #{start}
        </if>
    </select>

    <!--入库成本核对-->
    <update id="updateCost" parameterType="com.dk.mdm.model.pojo.ivt.InboundItem">
        update dkic_b.t_psi_inbound_item
        <set>
            <if test="costPrice!= null">
                cost_price= #{costPrice},
            </if>
            <if test="costAmt!= null">
                cost_amt = #{costAmt},
            </if>
        </set>
        where item_id = #{itemId}::uuid
    </update>
</mapper>
