<?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.pur.PurchaseItemMapper">

    <!-- 通用设置 -->
    <!-- 通用查询列 -->
    <sql id="Base_Column_List">
        item_id, pur_id, item_index, sku_id, sys.f_remove_zero(item_qty) as item_qty, price_std, amt_std, price_pur,
        item_amt, price_discount, non_std_code, into_status, sys.f_remove_zero(intoing_qty) as intoing_qty, intoing_amt,
        sys.f_remove_zero(into_qty) as into_qty, into_amt, sys.f_remove_zero(return_qty) as return_qty, return_amt,
        remarks, 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
    </sql>

    <!-- Response通用查询列 -->
    <sql id="Base_Column_List_Response">
        tppi.item_id,
        tppi.pur_id,
        tppi.item_index,
        tppi.sku_id,
        sys.f_remove_zero(tppi.item_qty) as item_qty,
        tppi.price_std as "pricePurchase",
        tppi.price_std,
        tppi.amt_std,
        tppi.price_pur,
        tppi.item_amt,
        tppi.price_discount,
        tppi.non_std_code,
        tppi.into_status,
        sys.f_remove_zero(tppi.intoing_qty) as intoing_qty,
        tppi.intoing_amt,
        sys.f_remove_zero(tppi.into_qty) as into_qty,
        tppi.into_amt,
        sys.f_remove_zero(tppi.return_qty) as return_qty,
        tppi.return_amt,
        tppi.remarks,
        tppi.flg_valid,
        tppi.cp_id,
        tppi.op_create_time,
        tppi.op_create_user_id,
        tppi.op_update_time,
        tppi.op_update_user_id,
        tppi.op_app_code,
        tppi.op_timestamp,
        tppi.op_db_user,
        tppi.from_id,
        tppi.from_item_id
        ,tppi.box
        ,tppi.piece
        ,tppi.unit_id
        ,tppi.sub_unit_id
        ,tppi.pack_box
    </sql>

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.pur.PurchaseItem">
        <id column="item_id" property="itemId"/>
                <result column="pur_id" property="purId" typeHandler="UuidTypeHandler"/>
                <result column="item_index" property="itemIndex"/>
                <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
                <result column="item_qty" property="itemQty"/>
                <result column="price_std" property="priceStd"/>
                <result column="amt_std" property="amtStd"/>
                <result column="price_pur" property="pricePur"/>
                <result column="item_amt" property="itemAmt"/>
                <result column="price_discount" property="priceDiscount"/>
                <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="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="decimalPlaces" property="decimalPlaces"/>
    </resultMap>

    <!-- Response通用查询映射结果 -->
    <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.pur.PurchaseItemResponse">
        <id column="item_id" property="itemId"/>
        <result column="pur_id" property="purId" typeHandler="UuidTypeHandler"/>
        <result column="item_index" property="itemIndex"/>
        <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
        <result column="item_qty" property="itemQty"/>
        <result column="price_std" property="priceStd"/>
        <result column="amt_std" property="amtStd"/>
        <result column="price_pur" property="pricePur"/>
        <result column="item_amt" property="itemAmt"/>
        <result column="price_discount" property="priceDiscount"/>
        <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="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="inv_id" property="invId"/>
        <result column="inv_qty" property="invQty"/>
        <result column="usable_qty" property="usableQty"/>
        <result column="box" property="box"/>
        <result column="piece" property="piece"/>
        <result column="pack_box" property="packBox"/>
        <result column="unit_id" property="unitId"/>
        <result column="sub_unit_id" property="subUnitId"/>
        <result column="subUnitName" property="subUnitName"/>
        <result column="unitName" property="unitName"/>
        <result column="flg_sub_unit" property="flgSubUnit"/>
        <result column="skuImages" property="skuImages" typeHandler="JsonTypeHandler"/>
        <result column="specsName" property="specsName"/>
        <result column="decimalPlaces" property="decimalPlaces"/>
    </resultMap>


    <!-- 通用条件列 -->
    <sql id="Condition">
        <where>
            <if test="purId != null and purId != ''">
                AND pur_id = #{purId}::uuid
            </if>
            <if test="itemIndex != null">
                AND item_index = #{itemIndex}
            </if>
            <if test="skuId != null and skuId != ''">
                AND sku_id = #{skuId}
            </if>
            <if test="itemQty != null">
                AND item_qty = #{itemQty}
            </if>
            <if test="priceStd != null">
                AND price_std = #{priceStd}
            </if>
            <if test="amtStd != null">
                AND amt_std = #{amtStd}
            </if>
            <if test="pricePur != null">
                AND price_pur = #{pricePur}
            </if>
            <if test="itemAmt != null">
                AND item_amt = #{itemAmt}
            </if>
            <if test="priceDiscount != null">
                AND price_discount = #{priceDiscount}
            </if>
            <if test="nonStdCode != null and nonStdCode != ''">
                AND non_std_code = #{nonStdCode}
            </if>
            <if test="intoStatus != null and intoStatus != ''">
                AND into_status = #{intoStatus}
            </if>
            <if test="intoingQty != null">
                AND intoing_qty = #{intoingQty}
            </if>
            <if test="intoingAmt != null">
                AND intoing_amt = #{intoingAmt}
            </if>
            <if test="intoQty != null">
                AND into_qty = #{intoQty}
            </if>
            <if test="intoAmt != null">
                AND into_amt = #{intoAmt}
            </if>
            <if test="returnQty != null">
                AND return_qty = #{returnQty}
            </if>
            <if test="returnAmt != null">
                AND return_amt = #{returnAmt}
            </if>
            <if test="remarks != null and remarks != ''">
                AND remarks = #{remarks}
            </if>
            <if test="flgValid != null">
                AND flg_valid = #{flgValid}
            </if>
            <if test="cpId != null">
                AND cp_id = #{cpId}
            </if>
            <if test="opCreateTime != null">
                AND op_create_time = #{opCreateTime}
            </if>
            <if test="opCreateUserId != null and opCreateUserId != ''">
                AND op_create_user_id = #{opCreateUserId}
            </if>
            <if test="opUpdateTime != null">
                AND op_update_time = #{opUpdateTime}
            </if>
            <if test="opUpdateUserId != null and opUpdateUserId != ''">
                AND op_update_user_id = #{opUpdateUserId}
            </if>
            <if test="opAppCode != null and opAppCode != ''">
                AND op_app_code = #{opAppCode}
            </if>
            <if test="opTimestamp != null">
                AND op_timestamp = #{opTimestamp}
            </if>
            <if test="opDbUser != null and opDbUser != ''">
                AND op_db_user = #{opDbUser}
            </if>
        </where>
    </sql>

    <!-- 通用条件列 -->
    <sql id="Condition_1">
        <where>
            <if test="purId != null and purId != ''">
                AND tppi.pur_id = #{purId}::uuid
            </if>
            <if test="itemIndex != null">
                AND tppi.item_index = #{itemIndex}
            </if>
            <if test="skuId != null and skuId != ''">
                AND tppi.sku_id = #{skuId}
            </if>
            <if test="itemQty != null">
                AND tppi.item_qty = #{itemQty}
            </if>
            <if test="priceStd != null">
                AND tppi.price_std = #{priceStd}
            </if>
            <if test="amtStd != null">
                AND tppi.amt_std = #{amtStd}
            </if>
            <if test="pricePur != null">
                AND tppi.price_pur = #{pricePur}
            </if>
            <if test="itemAmt != null">
                AND tppi.item_amt = #{itemAmt}
            </if>
            <if test="priceDiscount != null">
                AND tppi.price_discount = #{priceDiscount}
            </if>
            <if test="nonStdCode != null and nonStdCode != ''">
                AND tppi.non_std_code = #{nonStdCode}
            </if>
            <if test="intoStatus != null and intoStatus != ''">
                AND tppi.into_status = #{intoStatus}
            </if>
            <if test="intoingQty != null">
                AND tppi.intoing_qty = #{intoingQty}
            </if>
            <if test="intoingAmt != null">
                AND tppi.intoing_amt = #{intoingAmt}
            </if>
            <if test="intoQty != null">
                AND tppi.into_qty = #{intoQty}
            </if>
            <if test="intoAmt != null">
                AND tppi.into_amt = #{intoAmt}
            </if>
            <if test="returnQty != null">
                AND tppi.return_qty = #{returnQty}
            </if>
            <if test="returnAmt != null">
                AND tppi.return_amt = #{returnAmt}
            </if>
            <if test="remarks != null and remarks != ''">
                AND tppi.remarks = #{remarks}
            </if>
            <if test="flgValid != null">
                AND tppi.flg_valid = #{flgValid}
            </if>
            <if test="cpId != null">
                AND tppi.cp_id = #{cpId}
            </if>
            <if test="opCreateTime != null">
                AND tppi.op_create_time = #{opCreateTime}
            </if>
            <if test="opCreateUserId != null and opCreateUserId != ''">
                AND tppi.op_create_user_id = #{opCreateUserId}
            </if>
            <if test="opUpdateTime != null">
                AND tppi.op_update_time = #{opUpdateTime}
            </if>
            <if test="opUpdateUserId != null and opUpdateUserId != ''">
                AND tppi.op_update_user_id = #{opUpdateUserId}
            </if>
            <if test="opAppCode != null and opAppCode != ''">
                AND tppi.op_app_code = #{opAppCode}
            </if>
            <if test="opTimestamp != null">
                AND tppi.op_timestamp = #{opTimestamp}
            </if>
            <if test="opDbUser != null and opDbUser != ''">
                AND tppi.op_db_user = #{opDbUser}
            </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_purchase_item，（条件查询+分页）列表 -->
    <select id="selectByCond" resultMap="BaseResultMapResponse">
        SELECT
        <include refid="Base_Column_List_Response"/>
        ,tppi.from_id  as "fromId"
        ,tppi.from_item_id  as "fromItemId"
        ,tpo.order_no  as "orderNo"
        ,tmgs.sku_code  as "skuCode"
        ,tmgs.sku_model as "skuModel"
        ,tmgs.sku_name  as "skuName"
        ,tmgs.sku_images  as "skuImages"
        ,tmgb.brand_name  as "brandName"
        ,tmgb.short_name  as "shortName"
        ,tmgs.sku_spec  as "skuSpec"
        ,tmgs.price_purchase  as "pricePurchase"
        ,tmgs.price_standard  as "priceStandard"
        ,sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "intoStatusName"
        ,dkic_b.f_box_piece(tmgus.unit_name,tmgu.unit_name,tppi.box,tppi.piece) as "specsName"
        ,i.inv_id
        ,sys.f_remove_zero(i.inv_qty) as inv_qty
        ,sys.f_remove_zero(i.usable_qty) as usable_qty
        ,tpp.pur_no as "purNo"
        ,tmgus.unit_name        as "subUnitName"
        ,tmgu.unit_name         as "unitName"
        ,tmgs.flg_sub_unit
        ,tppi.intoing_qty/tppi.pack_box as "intoingBox"
        ,tppi.intoing_qty%tppi.pack_box as "intoingPiece"
        ,tppi.into_qty/tppi.pack_box as "intoBox"
        ,tppi.into_qty%tppi.pack_box as "intoPiece"
        ,tmgu.decimal_places    as "decimalPlaces"
        FROM dkic_b.t_psi_purchase_item tppi
        left join(SELECT T.*
        FROM (select tpi.inv_id,
        tpi.wh_id,
        tpi.inv_qty,
        tpi.usable_qty,
        tpi.sku_id,
        tpi.non_std_code,
        tpi.cp_id,
        tmw.wh_name,
        rank()
        over (partition by tpi.cp_id,tpi.sku_id,tpi.non_std_code order by tpi.inv_id) as RK
        from dkic_b.t_psi_inventory as tpi
        left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id) T
        WHERE T.RK = 1) as i on i.sku_id = tppi.sku_id and i.non_std_code = tppi.non_std_code and i.cp_id = tppi.cp_id
        left join dkic_b.t_psi_order tpo on tpo.order_id = tppi.from_id
        left join dkic_b.t_mst_goods_sku tmgs on tppi.sku_id = tmgs.sku_id
        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
        left join sys.t_data_kind tdk1 on tdk1.kind_code = tppi.into_status
        left join dkic_b.t_psi_purchase tpp  on tpp.pur_id = tppi.pur_id
        left join dkic_b.t_mst_unit as tmgu on tppi.unit_id = tmgu.unit_id
        left join dkic_b.t_mst_unit as tmgus on tppi.sub_unit_id = tmgus.unit_id

        <include refid="Condition_1"/>
        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
            limit #{end} offset #{start}
        </if>
    </select>

    <!-- 查询表dkic_b.t_psi_purchase_item，（条件查询+分页）列表 -->
    <select id="purSelectByCond" resultMap="BaseResultMapResponse">
        SELECT
        <include refid="Base_Column_List_Response"/>
        ,tppi.from_id  as "fromId"
        ,tppi.from_item_id  as "fromItemId"
        ,tpo.order_no  as "orderNo"
        ,tmgs.sku_code  as "skuCode"
        ,tmgs.sku_model as "skuModel"
        ,tmgs.sku_name  as "skuName"
        ,tmgs.sku_images  as "skuImages"
        ,tmgb.brand_name  as "brandName"
        ,tmgb.short_name  as "shortName"
        ,tmgs.sku_spec  as "skuSpec"
        ,tmgs.price_purchase  as "pricePurchase"
        ,tmgs.price_standard  as "priceStandard"
        ,sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "intoStatusName"
        ,
        i.inv_id,
        sys.f_remove_zero(i.inv_qty) as inv_qty,
        sys.f_remove_zero(i.usable_qty) as usable_qty
        ,tpp.pur_no as "purNo"
        ,tmgus.unit_name         as "subUnitName"
        ,tmgu.unit_name         as "unitName"
        ,tmgs.flg_sub_unit
        ,tmgu.decimal_places    as "decimalPlaces"
        FROM dkic_b.t_psi_purchase_item tppi
        left join dkic_b.t_mst_unit as tmgu on tppi.unit_id = tmgu.unit_id
        left join dkic_b.t_mst_unit as tmgus on tppi.sub_unit_id = tmgus.unit_id
        left join(SELECT T.*
        FROM (select tpi.inv_id,
        tpi.wh_id,
        tpi.inv_qty,
        tpi.usable_qty,
        tpi.sku_id,
        tpi.non_std_code,
        tpi.cp_id,
        tmw.wh_name,
        rank()
        over (partition by tpi.cp_id,tpi.sku_id,tpi.non_std_code order by tpi.inv_id) as RK
        from dkic_b.t_psi_inventory as tpi
        left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id) T
        WHERE T.RK = 1) as i on i.sku_id = tppi.sku_id and i.non_std_code = tppi.non_std_code and i.cp_id = tppi.cp_id
        left join dkic_b.t_psi_order tpo on tpo.order_id = tppi.from_id
        left join dkic_b.t_mst_goods_sku tmgs on tppi.sku_id = tmgs.sku_id
        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
        left join sys.t_data_kind tdk1 on tdk1.kind_code = tppi.into_status
        left join dkic_b.t_psi_purchase tpp  on tpp.pur_id = tppi.pur_id
        where
        tppi.into_status != '入库状态-已入库'
            AND tppi.flg_valid = true
        <if test="cpId != null">
            AND tppi.cp_id = #{cpId}
        </if>
        <if test="purId != null and purId != ''">
            AND tppi.pur_id = #{purId}::uuid
        </if>
        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
            limit #{end} offset #{start}
        </if>
    </select>


    <!-- 查询表dkic_b.t_psi_purchase_item，（条件查询）个数 -->
    <select id="countByCond" resultType="Long">
        SELECT
        count(1)
        FROM dkic_b.t_psi_purchase_item
        <include refid="Condition"/>
    </select>

    <!-- 根据主键查询表dkic_b.t_psi_purchase_item的一行数据 -->
    <select id="selectById" resultMap="BaseResultMapResponse">
        SELECT
        <include refid="Base_Column_List_Response"/>
        ,tppi.from_id  as "fromId"
        ,tppi.from_item_id  as "fromItemId"
        ,tpo.order_no  as "orderNo"
        ,tpp.pur_no as "purNo"
        ,(select ul.decimal_places from  dkic_b.t_mst_unit ul where tppi.unit_id = ul.unit_id) as "decimalPlaces"
        FROM dkic_b.t_psi_purchase_item tppi
        left join dkic_b.t_psi_order tpo on tpo.order_id = tppi.from_id
        left join dkic_b.t_psi_purchase tpp  on tpp.pur_id = tppi.pur_id
        left join  dkic_b.t_mst_goods_sku  tmgs on tmgs.sku_id = tppi.sku_id
        left join  dkic_b.t_mst_goods_brand  tmgb on tmgb.brand_id = tmgs.brand_id
        WHERE tppi.item_id = #{id}::uuid
    </select>

    <!-- 根据主键锁定表dkic_b.t_psi_purchase_item的一行数据 -->
    <select id="selectByIdForUpdate" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        ,(select ul.decimal_places from  dkic_b.t_mst_unit ul where dkic_b.t_psi_purchase_item.unit_id = ul.unit_id) as "decimalPlaces"
        FROM dkic_b.t_psi_purchase_item
        WHERE item_id = #{itemId}::uuid
        for update
    </select>

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

    <delete id="deleteById">
        DELETE FROM dkic_b.t_psi_purchase_item
        WHERE item_id = #{id}::UUID;
    </delete>


    <update id="updateAmount" parameterType="com.dk.mdm.model.pojo.pur.PurchaseItem">
        update dkic_b.t_psi_purchase_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>

    <!-- 根据id修改-->
    <update id="updateById" parameterType="com.dk.mdm.model.pojo.pur.PurchaseItem">
        update dkic_b.t_psi_purchase_item
        <set>
            <if test=" et!=null and et.purId != null">
                pur_id = #{et.purId,typeHandler=UuidTypeHandler},
            </if>
            <if test=" et!=null and et.itemIndex != null">
                item_index = #{et.itemIndex,jdbcType=INTEGER},
            </if>
            <if test=" et!=null and et.skuId != null">
                sku_id = #{et.skuId,typeHandler=UuidTypeHandler},
            </if>
            <if test=" et!=null and et.itemQty != null">
                item_qty = #{et.itemQty,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.priceStd != null">
                price_std = #{et.priceStd,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.amtStd != null">
                amt_std = #{et.amtStd,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.pricePur != null">
                price_pur = #{et.pricePur,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.itemAmt != null">
                item_amt = #{et.itemAmt,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.priceDiscount != null">
                price_discount = #{et.priceDiscount,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.nonStdCode != null">
                non_std_code = #{et.nonStdCode,jdbcType=VARCHAR},
            </if>
            <if test=" et!=null and et.intoStatus != null">
                into_status = #{et.intoStatus,jdbcType=VARCHAR},
            </if>
            <if test=" et!=null and et.intoingQty != null">
                intoing_qty = intoing_qty +  #{et.intoingQty,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.intoingAmt != null">
                intoing_amt = intoing_amt + #{et.intoingAmt,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.intoQty != null">
                into_qty = into_qty + #{et.intoQty,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.intoAmt != null">
                into_amt = into_amt + #{et.intoAmt,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.returnQty != null">
                return_qty = #{et.returnQty,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.returnAmt != null">
                return_amt = #{et.returnAmt,jdbcType=NUMERIC},
            </if>
            <if test=" et!=null and et.remarks != null">
                remarks = #{et.remarks,jdbcType=VARCHAR},
            </if>
            <if test=" et!=null and et.flgValid != null">
                flg_valid = #{et.flgValid,jdbcType=BOOLEAN},
            </if>
            <if test=" et!=null and et.cpId != null">
                cp_id = #{et.cpId,jdbcType=INTEGER},
            </if>
        </set>
        where item_id = #{et.itemId,typeHandler=UuidTypeHandler}
        and  item_qty >= (
        into_qty
        <if test=" et!=null and et.updateIntoMessageFlag != null and et.updateIntoMessageFlag ">
            + #{et.intoQty,jdbcType=NUMERIC}
        </if>
        + intoing_qty
        <if test=" et!=null and et.updateIntoingMessageFlag != null and et.updateIntoingMessageFlag ">
            + #{et.intoingQty,jdbcType=NUMERIC}
        </if>
        )
    </update>

</mapper>
