| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825 |
- <?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.sale.OrderItemMapper">
- <!-- 通用设置 -->
- <!-- 通用查询列 -->
- <sql id="Base_Column_List">
- item_id
- , order_id, item_index, sku_id, sub_unit_id, unit_id,pack_box,box, piece,
- sys.f_remove_zero(item_qty) as item_qty, price_std, amt_std, price_sale, item_amt, price_discount, non_std_code, out_status,
- sys.f_remove_zero(outing_qty) as outing_qty, outing_amt, sys.f_remove_zero(out_qty) as out_qty, out_amt,
- sys.f_remove_zero(return_qty) as return_qty, return_amt, remarks, flg_valid, cp_id, wh_id,
- fact_price,fact_amt,use_place,discount
- </sql>
- <sql id="Base_Column_List_Response">
- t.item_id, t.order_id, t.item_index, t.sku_id, sys.f_remove_zero(t.item_qty) as item_qty, t.price_std, t.amt_std, t.price_sale, t.item_amt, t.price_discount, t.non_std_code,
- t.out_status, sys.f_remove_zero(t.outing_qty) as outing_qty, t.outing_amt, sys.f_remove_zero(t.out_qty) as out_qty, t.out_amt,
- sys.f_remove_zero(t.return_qty) as return_qty, t.return_amt, t.remarks, t.flg_valid, t.cp_id, t.wh_id
- ,t.box,t.piece,t.sub_unit_id,t.unit_id,t.pack_box,
- t.fact_price,t.fact_amt,t.use_place,t.discount
- </sql>
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.sale.OrderItem">
- <id column="item_id" property="itemId"/>
- <result column="order_id" property="orderId" typeHandler="UuidTypeHandler"/>
- <result column="item_index" property="itemIndex"/>
- <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
- <result column="unit_id" property="unitId" typeHandler="UuidTypeHandler"/>
- <result column="sub_unit_id" property="subUnitId" typeHandler="UuidTypeHandler"/>
- <result column="pack_box" property="packBox"/>
- <result column="box" property="box"/>
- <result column="piece" property="piece"/>
- <result column="item_qty" property="itemQty"/>
- <result column="price_std" property="priceStd"/>
- <result column="amt_std" property="amtStd"/>
- <result column="price_sale" property="priceSale"/>
- <result column="item_amt" property="itemAmt"/>
- <result column="price_discount" property="priceDiscount"/>
- <result column="non_std_code" property="nonStdCode"/>
- <result column="out_status" property="outStatus"/>
- <result column="outing_qty" property="outingQty"/>
- <result column="outing_amt" property="outingAmt"/>
- <result column="out_qty" property="outQty"/>
- <result column="out_amt" property="outAmt"/>
- <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="wh_id" property="whId"/>
- <result column="decimalPlaces" property="decimalPlaces"/>
- <result column="fact_price" property="factPrice"/>
- <result column="fact_amt" property="factAmt"/>
- <result column="use_place" property="usePlace"/>
- <result column="discount" property="discount"/>
- <result column="sup_id" property="supId"/>
- </resultMap>
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMapResponse" type="com.dk.mdm.model.response.sale.OrderItemResponse">
- <id column="item_id" property="itemId"/>
- <result column="order_id" property="orderId" typeHandler="UuidTypeHandler"/>
- <result column="item_index" property="itemIndex"/>
- <result column="sku_id" property="skuId" typeHandler="UuidTypeHandler"/>
- <result column="unit_id" property="unitId" typeHandler="UuidTypeHandler"/>
- <result column="sub_unit_id" property="subUnitId" typeHandler="UuidTypeHandler"/>
- <result column="pack_box" property="packBox"/>
- <result column="item_qty" property="itemQty"/>
- <result column="price_std" property="priceStd"/>
- <result column="amt_std" property="amtStd"/>
- <result column="price_sale" property="priceSale"/>
- <result column="item_amt" property="itemAmt"/>
- <result column="price_discount" property="priceDiscount"/>
- <result column="non_std_code" property="nonStdCode"/>
- <result column="out_status" property="outStatus"/>
- <result column="outing_qty" property="outingQty"/>
- <result column="outing_amt" property="outingAmt"/>
- <result column="out_qty" property="outQty"/>
- <result column="out_amt" property="outAmt"/>
- <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="wh_id" property="whId"/>
- <result column="wh_name" property="whName"/>
- <result column="order_no" property="orderNo"/>
- <result column="brand_name" property="brandName"/>
- <result column="short_name" property="shortName"/>
- <result column="sku_images" property="skuImages" typeHandler="JsonTypeHandler"/>
- <result column="transferableQuantity" property="transferableQuantity"/>
- <result column="skuImages" property="skuImages" typeHandler="JsonTypeHandler"/>
- <result column="decimalPlaces" property="decimalPlaces"/>
- <result column="fact_price" property="factPrice"/>
- <result column="fact_amt" property="factAmt"/>
- <result column="use_place" property="usePlace"/>
- <result column="discount" property="discount"/>
- <result column="sup_id" property="supId" typeHandler="UuidTypeHandler"/>
- <result column="canOutingQty" property="canOutingQty"/>
- <result column="canReturnQty" property="canReturnQty"/>
- <result column="cus_code" property="cusCode"/>
- <result column="cus_name" property="cusName"/>
- <result column="cus_phone" property="cusPhone"/>
- <result column="address_full" property="addressFull"/>
- <result column="channel_name" property="channelName"/>
- <result column="sku_code" property="skuCode"/>
- <result column="sku_model" property="skuModel"/>
- <result column="sku_name" property="skuName"/>
- <result column="skuModel" property="skuModel"/>
- <result column="skuName" property="skuName"/>
- <result column="can_out_qty" property="canOutQty"/>
- <result column="cost_price" property="costPrice"/>
- <result column="cost_amt" property="costAmt"/>
- <result column="into_id" property="intoId" typeHandler="UuidTypeHandler"/>
- <result column="price_purchase" property="pricePurchase"/>
- </resultMap>
- <!-- 通用条件列 -->
- <sql id="Condition">
- <where>
- <if test="orderId != null and orderId != ''">
- AND t.order_id = #{orderId}::uuid
- </if>
- <if test="itemIndex != null">
- AND t.item_index = #{itemIndex}
- </if>
- <if test="skuId != null and skuId != ''">
- AND t.sku_id = #{skuId}
- </if>
- <if test="itemQty != null">
- AND t.item_qty = #{itemQty}
- </if>
- <if test="priceStd != null">
- AND t.price_std = #{priceStd}
- </if>
- <if test="amtStd != null">
- AND t.amt_std = #{amtStd}
- </if>
- <if test="priceSale != null">
- AND t.price_sale = #{priceSale}
- </if>
- <if test="itemAmt != null">
- AND t.item_amt = #{itemAmt}
- </if>
- <if test="priceDiscount != null">
- AND t.price_discount = #{priceDiscount}
- </if>
- <if test="nonStdCode != null and nonStdCode != ''">
- AND t.non_std_code = #{nonStdCode}
- </if>
- <if test="outStatus != null and outStatus != ''">
- AND t.out_status = #{outStatus}
- </if>
- <if test="outingQty != null">
- AND t.outing_qty = #{outingQty}
- </if>
- <if test="outingAmt != null">
- AND t.outing_amt = #{outingAmt}
- </if>
- <if test="outQty != null">
- AND t.out_qty = #{outQty}
- </if>
- <if test="outAmt != null">
- AND t.out_amt = #{outAmt}
- </if>
- <if test="returnQty != null">
- AND t.return_qty = #{returnQty}
- </if>
- <if test="returnAmt != null">
- AND t.return_amt = #{returnAmt}
- </if>
- <if test="remarks != null and remarks != ''">
- AND t.remarks = #{remarks}
- </if>
- <if test="flgValid != null">
- AND t.flg_valid = #{flgValid}
- </if>
- <if test="cpId != null">
- AND t.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>
- <!-- 查询表t_psi_order_item,(条件查询+分页)列表 -->
- <select id="selectByCond" resultMap="BaseResultMapResponse">
- SELECT t.item_id,
- t.order_id,
- t.item_index,
- t.sku_id,
- tmgs.sku_code as "skuCode",
- t.sku_model as "skuModel",
- t.sku_name as "skuName",
- tmgs.sku_images,
- case when t.sku_id is null then '外协' else tmgb.brand_name end AS brand_name,
- tmgb.short_name,
- dkic_b.f_box_piece(u2.unit_name,ul.unit_name,t.box,t.piece) AS "boxPiece",
- t.pack_box,
- t.box,
- t.piece,
- sys.f_remove_zero(t.item_qty) as item_qty,
- t.price_std,
- t.amt_std,
- t.price_sale,
- t.item_amt,
- t.price_discount,
- t.fact_price,
- t.fact_amt,
- t.use_place,
- t.discount,
- t.non_std_code,
- t.out_status,
- sys.f_remove_zero(t.outing_qty) as outing_qty,
- t.outing_amt,
- sys.f_remove_zero(t.out_qty) as out_qty,
- t.out_amt,
- sys.f_remove_zero(t.return_qty) as return_qty,
- t.return_amt,
- t.remarks,
- t.wh_id,
- tmw.wh_name
- ,ul.decimal_places as "decimalPlaces"
- ,t.unit_id
- ,t.sup_id
- ,t.sub_unit_id
- ,ul.unit_name as "unitName"
- ,u2.unit_name as "subUnitName"
- ,t.cost_price
- ,t.cost_amt
- ,tpii.into_id
- FROM dkic_b.t_psi_order_item as t
- LEFT join dkic_b.t_psi_inbound_item tpii on t.item_id = tpii.from_item_id
- LEFT join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
- LEFT JOIN dkic_b.t_mst_unit AS ul ON tmgs.unit_id = ul.unit_id
- LEFT JOIN dkic_b.t_mst_unit AS u2 ON tmgs.sub_unit_id = u2.unit_id
- LEFT join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
- left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = t.wh_id
- <include refid="Condition"/>
- order by t.item_index
- <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
- limit #{end} offset #{start}
- </if>
- </select>
- <!-- 查询表t_psi_order_item,(条件查询)个数 -->
- <select id="countByCond" resultType="Long">
- SELECT
- count(1)
- FROM dkic_b.t_psi_order_item as t
- <include refid="Condition"/>
- </select>
- <!-- 根据主键查询表t_psi_order_item的一行数据 -->
- <select id="selectById" resultMap="BaseResultMapResponse">
- SELECT
- <include refid="Base_Column_List_Response"/>
- ,(select ul.decimal_places from dkic_b.t_mst_unit ul where t.unit_id = ul.unit_id) as "decimalPlaces"
- FROM dkic_b.t_psi_order_item t
- WHERE t.item_id = #{id}::uuid
- </select>
- <!-- 根据主键锁定表t_psi_order_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_order_item.unit_id = ul.unit_id) as "decimalPlaces"
- FROM dkic_b.t_psi_order_item
- WHERE item_id = #{id}::uuid
- for update
- </select>
- <!-- 根据主表主键锁定表t_psi_order_item的一行数据 -->
- <select id="selectByZIdForUpdate" resultMap="BaseResultMap">
- SELECT
- <include refid="Base_Column_List"/>
- ,(select ul.decimal_places from dkic_b.t_mst_unit ul where dkic_b.t_psi_order_item.unit_id = ul.unit_id) as "decimalPlaces"
- FROM dkic_b.t_psi_order_item
- WHERE order_id = #{id}::uuid
- for update
- </select>
- <!-- 根据主键锁定表t_psi_order_item的多行数据 -->
- <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
- SELECT
- <include refid="Base_Column_List"/>
- ,(select ul.decimal_places from dkic_b.t_mst_unit ul where dkic_b.t_psi_order_item.unit_id = ul.unit_id) as "decimalPlaces"
- FROM dkic_b.t_psi_order_item
- <include refid="idsForeach"/>
- for update
- </select>
- <insert id="insertBatch">
- insert into dkic_b.t_psi_order_item
- (
- <trim suffixOverrides=",">
- order_id,
- item_index,
- sku_id,
- item_qty,
- price_std,
- amt_std,
- price_sale,
- item_amt,
- price_discount,
- non_std_code,
- out_status,
- outing_qty,
- outing_amt,
- out_qty,
- out_amt,
- return_qty,
- return_amt,
- remarks,
- cp_id,
- wh_id,
- </trim>
- )
- values
- <foreach collection="list" index="index" item="item" separator=",">
- (
- <trim suffixOverrides=",">
- #{item.orderId}::uuid,
- #{item.itemIndex},
- #{item.skuId}::uuid,
- #{item.itemQty},
- #{item.priceStd},
- #{item.amtStd},
- #{item.priceSale},
- #{item.itemAmt},
- #{item.priceDiscount},
- #{item.nonStdCode},
- #{item.outStatus},
- #{item.outingQty},
- #{item.outingAmt},
- #{item.outQty},
- #{item.outAmt},
- #{item.returnQty},
- #{item.returnAmt},
- #{item.remarks},
- #{item.cpId},
- #{item.whId},
- </trim>
- )
- </foreach>
- </insert>
- <delete id="deleteById">
- DELETE FROM dkic_b.t_psi_order_item
- WHERE item_id = #{id}::UUID;
- </delete>
- <!-- 根据条件进行查询(出库用) -->
- <select id="selectByCondForOut" resultMap="BaseResultMapResponse">
- SELECT t.item_id as "fromItemId",
- t.order_id as "fromId",
- t.item_index,
- t.sku_id,
- tmgs.sku_code as "skuCode",
- t.sku_model as "skuModel",
- t.sku_name as "skuName",
- tmgs.sku_images AS "skuImages",
- t.pack_box ,
- sys.f_remove_zero(t.item_qty) as "orderQty",
- t.box,
- t.piece,
- sys.f_remove_zero(t.item_qty - t.outing_qty - t.out_qty) as "canOutingQty",
- sys.f_remove_zero(t.item_qty - t.outing_qty - t.out_qty) as outing_qty,
- -- (t.item_qty - t.outing_qty - t.out_qty)/t.pack_box as "outingBox",
- -- (t.item_qty - t.outing_qty - t.out_qty)%t.pack_box as "outingPiece",
- case
- when t.sub_unit_id ISNULL
- then 0
- else
- floor((T.item_qty - T.outing_qty - T.out_qty) / T.pack_box)
- end AS "outingBox",
- case
- when t.sub_unit_id ISNULL
- then floor(T.item_qty - T.outing_qty - T.out_qty)
- else
- floor((T.item_qty - T.outing_qty - T.out_qty) % T.pack_box)
- end AS "outingPiece",
- case
- when t.sub_unit_id ISNULL
- then dkic_b.f_box_piece(u2.unit_name, ul.unit_name, 0,
- floor(T.item_qty - T.outing_qty - T.out_qty)::INT)
- else
- dkic_b.f_box_piece(u2.unit_name, ul.unit_name,
- floor((T.item_qty - T.outing_qty - T.out_qty) / T.pack_box)::INT,
- floor((T.item_qty - T.outing_qty - T.out_qty) % T.pack_box)::INT)
- end AS "thisOutBoxPiece",
- t.price_sale as "priceOut",
- t.price_sale * (t.item_qty - t.outing_qty - t.out_qty) as outing_amt,
- t.fact_price,
- t.fact_amt,
- t.discount,
- t.non_std_code,
- t.remarks,
- t.wh_id,
- t.sup_id,
- t.unit_id,
- t.sub_unit_id,
- tmw.wh_name,
- tpi.inv_id as "invId",
- sys.f_remove_zero(tpi.inv_qty) as "invQty",
- sys.f_remove_zero(tpi.usable_qty) as "usableQty"
- ,(select ul.decimal_places from dkic_b.t_mst_unit ul where t.unit_id = ul.unit_id) as "decimalPlaces"
- ,ul.unit_name as "unitName"
- ,u2.unit_name as "subUnitName"
- ,tmgb.brand_name
- ,tmgb.short_name
- ,dkic_b.f_box_piece(u2.unit_name,ul.unit_name,t.box,t.piece) as "boxPiece"
- FROM dkic_b.t_psi_order_item as t
- LEFT join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
- left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = t.wh_id
- left join dkic_b.t_psi_inventory as tpi
- on tpi.sku_id = t.sku_id and tpi.non_std_code = t.non_std_code
- and tpi.wh_id = t.wh_id and tpi.cp_id = t.cp_id
- LEFT JOIN dkic_b.t_mst_unit AS ul ON t.unit_id = ul.unit_id
- LEFT JOIN dkic_b.t_mst_unit AS u2 ON t.sub_unit_id = u2.unit_id
- LEFT join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
- where t.flg_valid
- and t.item_qty > t.outing_qty
- and t.order_id = #{orderId}::uuid
- order by t.item_index
- </select>
- <!-- 根据条件进行查询(退货用) -->
- <select id="selectByCondForReturn" resultMap="BaseResultMapResponse">
- SELECT tpobi.out_id as "sOutId",
- tpobi.item_id as "sOutItemId",
- t.order_id as "sOrderId",
- t.item_id as "sOrderItemId",
- t.sku_id,
- tmgs.sku_code as "skuCode",
- tpobi.sku_model as "skuModel",
- tpobi.sku_name as "skuName",
- tmgs.sku_images as "skuImages",
- tpobi.out_qty as "outboundOutQty",
- sys.f_remove_zero(tpobi.out_qty - tpobi.return_qty) as "canReturnQty",
- - sys.f_remove_zero(tpobi.out_qty - tpobi.return_qty) as outing_qty,
- t.price_sale as "priceOut",
- - t.price_sale * (tpobi.out_qty - tpobi.return_qty) as outing_amt,
- tpobi.inv_id as "invId",
- 0 as out_qty,
- 0 as out_amt,
- t.non_std_code,
- t.sup_id,
- tpobi.remarks,
- t.wh_id,
- tmw.wh_name
- ,(select ul.decimal_places from dkic_b.t_mst_unit ul where tpobi.unit_id = ul.unit_id) as "decimalPlaces"
- ,tpobi.pack_box
- ,tpobi.unit_id
- ,tpobi.sub_unit_id
- ,ul.unit_name as "unitName"
- ,u2.unit_name as "subUnitName"
- ,dkic_b.f_box_piece(u2.unit_name,ul.unit_name,tpobi.outing_box,tpobi.outing_piece) AS "outingBoxPiece"
- ,dkic_b.f_box_piece(u2.unit_name,ul.unit_name,tpobi.out_box,tpobi.out_piece) AS "outBoxPiece"
- ,tpobi.cost_price
- ,tpobi.cost_amt
- FROM dkic_b.t_psi_outbound_item as tpobi
- inner join dkic_b.t_psi_order_item as t on t.item_id = tpobi.from_item_id
- LEFT join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
- left join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = t.wh_id
- LEFT JOIN dkic_b.t_mst_unit AS ul ON tpobi.unit_id = ul.unit_id
- LEFT JOIN dkic_b.t_mst_unit AS u2 ON tpobi.sub_unit_id = u2.unit_id
- where tpobi.flg_valid
- and tpobi.out_type = '出库类型-销售出库'
- and tpobi.out_qty > tpobi.return_qty
- and t.order_id = #{orderId}::uuid
- order by t.item_index
- </select>
- <!-- 根据id修改-->
- <update id="updateById" parameterType="com.dk.mdm.model.pojo.sale.OrderItem">
- update dkic_b.t_psi_order_item
- <set>
- <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.priceSale != null">
- price_sale = #{et.priceSale,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.outStatus != null">
- out_status = #{et.outStatus,jdbcType=VARCHAR},
- </if>
- <if test=" et!=null and et.outingQty != null">
- outing_qty = outing_qty + #{et.outingQty,jdbcType=NUMERIC},
- </if>
- <if test=" et!=null and et.outingAmt != null">
- outing_amt = outing_amt + #{et.outingAmt,jdbcType=NUMERIC},
- </if>
- <if test=" et!=null and et.outQty != null">
- out_qty = out_qty + #{et.outQty,jdbcType=NUMERIC},
- </if>
- <if test=" et!=null and et.outAmt != null">
- out_amt = out_amt + #{et.outAmt,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>
- <if test=" et!=null and et.factPrice != null">
- fact_price = #{et.factPrice,jdbcType=NUMERIC},
- </if>
- <if test=" et!=null and et.factAmt != null">
- fact_amt = #{et.factAmt,jdbcType=NUMERIC},
- </if>
- <if test=" et!=null and et.usePlace != null">
- use_place = #{et.usePlace,jdbcType=VARCHAR},
- </if>
- <if test=" et!=null and et.discount != null">
- discount = #{et.discount,jdbcType=VARCHAR},
- </if>
- <if test=" et!=null and et.costPrice != null">
- cost_price = #{et.costPrice,jdbcType=NUMERIC},
- </if>
- <if test=" et!=null and et.costAmt != null">
- cost_amt = #{et.costAmt,jdbcType=NUMERIC},
- </if>
- </set>
- where item_id = #{et.itemId,typeHandler=UuidTypeHandler}
- and item_qty >=(
- out_qty
- <if test=" et!=null and et.updateOutMessageFlag != null and et.updateOutMessageFlag ">
- + #{et.outQty,jdbcType=NUMERIC}
- </if>
- + outing_qty
- <if test=" et!=null and et.updateOutingMessageFlag != null and et.updateOutingMessageFlag ">
- + #{et.outingQty,jdbcType=NUMERIC}
- </if>
- )
- </update>
- <!--修改退货信息 -->
- <update id="updateReturnMessage" parameterType="com.dk.mdm.model.pojo.sale.OrderItem">
- update dkic_b.t_psi_order_item
- <set>
- <if test=" returnQty != null">
- return_qty = return_qty + #{returnQty,jdbcType=NUMERIC},
- </if>
- <if test=" returnAmt != null">
- return_amt = return_amt + #{returnAmt,jdbcType=NUMERIC},
- </if>
- </set>
- where item_id = #{itemId,typeHandler=UuidTypeHandler}
- and item_qty >= return_qty
- </update>
- <!-- 通用条件列 -->
- <sql id="Condition_pur">
- <where>
- <if test="orderNo != null">
- AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
- </if>
- <if test="orderId != null and orderId != ''">
- AND t.order_id = #{orderId}::uuid
- </if>
- <if test="itemIndex != null">
- AND t.item_index = #{itemIndex}
- </if>
- <if test="skuId != null and skuId != ''">
- AND t.sku_id = #{skuId}
- </if>
- <if test="itemQty != null">
- AND t.item_qty = #{itemQty}
- </if>
- <if test="priceStd != null">
- AND t.price_std = #{priceStd}
- </if>
- <if test="amtStd != null">
- AND t.amt_std = #{amtStd}
- </if>
- <if test="priceSale != null">
- AND t.price_sale = #{priceSale}
- </if>
- <if test="itemAmt != null">
- AND t.item_amt = #{itemAmt}
- </if>
- <if test="priceDiscount != null">
- AND t.price_discount = #{priceDiscount}
- </if>
- <if test="nonStdCode != null and nonStdCode != ''">
- AND t.non_std_code = #{nonStdCode}
- </if>
- <if test="outStatus != null and outStatus != ''">
- AND t.out_status = #{outStatus}
- </if>
- <if test="outingQty != null">
- AND t.outing_qty = #{outingQty}
- </if>
- <if test="outingAmt != null">
- AND t.outing_amt = #{outingAmt}
- </if>
- <if test="outQty != null">
- AND t.out_qty = #{outQty}
- </if>
- <if test="outAmt != null">
- AND t.out_amt = #{outAmt}
- </if>
- <if test="returnQty != null">
- AND t.return_qty = #{returnQty}
- </if>
- <if test="returnAmt != null">
- AND t.return_amt = #{returnAmt}
- </if>
- <if test="remarks != null and remarks != ''">
- AND t.remarks = #{remarks}
- </if>
- <if test="flgValid != null">
- AND t.flg_valid = #{flgValid}
- </if>
- <if test="cpId != null">
- AND t.cp_id = #{cpId}
- </if>
- </where>
- </sql>
- <!-- 查询表t_psi_order_item,(条件查询+分页)列表 -->
- <select id="purchaseBasedOnSaleSelectByCond" resultMap="BaseResultMapResponse">
- SELECT t.item_id,
- t.order_id,
- tpo.order_no,
- tms.cus_code,
- tms.cus_name,
- tms.cus_phone,
- tpo.make_time AS "makingTime",
- t.item_index,
- t.sku_id,
- tmgs.sku_code,
- tmgs.sku_model as "skuModel",
- tmgs.sku_name as "skuName",
- sys.f_remove_zero(t.item_qty) as item_qty,
- t.price_std,
- t.amt_std,
- t.price_sale,
- t.item_amt,
- t.price_discount,
- t.fact_price,
- t.fact_amt,
- t.use_place,
- t.discount,
- t.non_std_code AS "nonStdCode",
- t.out_status,
- sys.f_remove_zero(t.outing_qty) as outing_qty,
- t.outing_amt,
- sys.f_remove_zero(t.out_qty) as out_qty,
- t.out_amt,
- sys.f_remove_zero(t.return_qty) as return_qty,
- t.return_amt,
- t.remarks,
- t.item_qty - coalesce(sumQty,0) as "transferableQuantity"
- ,ul.decimal_places as "decimalPlaces"
- ,t.box
- ,t.piece
- ,t.pack_box
- ,t.unit_id
- ,t.sub_unit_id
- ,ul.unit_name as "unitName"
- ,u2.unit_name as "subUnitName"
- ,dkic_b.f_box_piece(u2.unit_name,ul.unit_name,t.box,t.piece) as "boxPiece"
- ,tmgs.price_purchase
- FROM dkic_b.t_psi_order_item as t
- left join dkic_b.t_psi_order as tpo on tpo.order_id = t.order_id
- left join dkic_b.t_mst_customer as tms on tpo.cus_id = tms.cus_id
- LEFT join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
- left join dkic_b.t_mst_unit ul on t.unit_id = ul.unit_id
- left join dkic_b.t_mst_unit u2 on t.sub_unit_id = u2.unit_id
- left join(select from_item_id,sum(item_qty) as sumQty from dkic_b.t_psi_purchase_item
- group by from_item_id) as pi on pi.from_item_id = t.item_id
- <where>
- t.item_qty - coalesce(sumQty,0) > 0
- AND t.sku_id is not null
- AND t.flg_valid
- AND tpo.flg_valid
- <if test="cpId != null">
- AND t.cp_id = #{cpId}
- </if>
- <if test="orderNo != null">
- AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
- </if>
- </where>
- order by t.item_id
- <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
- limit #{end} offset #{start}
- </if>
- </select>
- <!-- 查询表t_psi_order_item,(条件查询+分页)列表 -->
- <select id="purchaseBasedOnSaleContByCond" resultType="Long">
- SELECT count(1)
- FROM dkic_b.t_psi_order_item as t
- left join dkic_b.t_psi_order as tpo on tpo.order_id = t.order_id
- inner join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
- left join(select from_item_id,sum(item_qty) as sumQty from dkic_b.t_psi_purchase_item
- group by from_item_id) as pi on pi.from_item_id = t.item_id
- <where>
- t.item_qty - coalesce(sumQty,0) > 0
- AND t.sku_id is not null
- AND t.flg_valid
- AND tpo.flg_valid
- <if test="cpId != null">
- AND t.cp_id = #{cpId}
- </if>
- <if test="orderNo != null">
- AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
- </if>
- </where>
- <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
- limit #{end} offset #{start}
- </if>
- </select>
- <!-- 销售出库页面选择源单 -->
- <select id="selectBySaleOut" resultMap="BaseResultMapResponse">
- SELECT
- <include refid="Base_Column_List_Response"/>,
- tpo.order_no ,
- tmc.cus_code ,
- tmc.cus_name ,
- tmc.cus_phone ,
- tmc.address_full ,
- tmsc.channel_name ,
- tmgs.sku_code ,
- tmgs.sku_model ,
- tmgs.sku_name ,
- tmgb.brand_name ,
- tmgb.short_name,
- t.item_qty - (t.outing_qty + t.out_qty) as can_out_qty
- FROM dkic_b.t_psi_order_item t
- LEFT JOIN dkic_b.t_psi_order as tpo ON t.order_id = tpo.order_id
- LEFT JOIN dkic_b.t_mst_customer tmc ON tmc.cus_id = tpo.cus_id
- LEFT JOIN dkic_b.t_mst_sale_channel tmsc ON tpo.sales_channel = tmsc.channel_id
- LEFT JOIN dkic_b.t_mst_goods_sku tmgs ON tmgs.sku_id = t.sku_id
- LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
- WHERE
- t.cp_id = #{cpId}
- and t.item_qty - t.outing_qty - t.out_qty > 0
- <if test="orderNo != null">
- AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
- </if>
- order by t.op_create_time desc
- <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
- limit #{end} offset #{start}
- </if>
- </select>
- <!-- 销售出库页面选择源单个数 -->
- <select id="selectBySaleOutByCound" resultMap="BaseResultMapResponse">
- SELECT
- count(1)
- FROM dkic_b.t_psi_order_item t
- LEFT JOIN dkic_b.t_psi_order as tpo ON t.order_id = tpo.order_id
- LEFT JOIN dkic_b.t_mst_customer tmc ON tmc.cus_id = tpo.cus_id
- LEFT JOIN dkic_b.t_mst_sale_channel tmsc ON tpo.sales_channel = tmsc.channel_id
- LEFT JOIN dkic_b.t_mst_goods_sku tmgs ON tmgs.sku_id = t.sku_id
- LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
- WHERE
- t.cp_id = #{cpId}
- and t.item_qty - t.outing_qty - t.out_qty > 0
- <if test="orderNo != null">
- AND tpo.order_no like concat('%', my_ex.likequery(#{orderNo}) , '%')
- </if>
- </select>
- <update id="updateCost" parameterType="com.dk.mdm.model.pojo.sale.OrderItem">
- update dkic_b.t_psi_order_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>
|