order_id, order_no, order_type, org_id, staff_id, cus_id, address_area, address_name, address_no, address_gcj02, address_full, contact_name, contact_phone, sales_channel, delivery_date, sum_quantity, sum_standard, sum_amount, sale_discount, order_status, out_status, outing_qty, outing_amt, out_qty, out_amt, return_qty, return_amt, amt_receivable, amt_handle, amt_residue, remarks, annex_paths, make_staff, make_time, flg_valid, cp_id
t
.
order_id
,
t.order_no,
t.order_type,
t.org_id,
t.staff_id,
t.cus_id,
t.address_area,
t.address_name,
t.address_no,
t.address_gcj02,
t.address_full,
t.contact_name,
t.contact_phone,
t.sales_channel,
t.delivery_date,
t.sum_quantity,
t.sum_standard,
t.sum_amount, t.sale_discount,
t.order_status, t.out_status,
t.outing_qty, t.outing_amt, t.out_qty,
t.out_amt, t.return_qty, t.return_amt,
t.amt_receivable, amt_handle, amt_residue,
t.remarks, t.annex_paths, t.make_staff, t.make_time,
t.flg_valid, t.cp_id
toi.item_id AS list_item_id,
toi.order_id AS list_order_id,
t.order_no AS list_order_no,
toi.item_index AS list_item_index,
toi.sku_id AS list_sku_id,
toi.item_qty AS list_item_qty,
toi.item_qty AS list_order_qty,
toi.price_std AS list_price_std,
toi.amt_std AS list_amt_std,
toi.price_sale AS list_price_sale,
toi.price_sale AS list_price_out,
toi.item_amt AS list_item_amt,
toi.price_discount AS list_price_discount,
toi.non_std_code AS list_non_std_code,
toi.out_status AS list_out_status,
toi.outing_qty AS list_outing_qty,
toi.outing_amt AS list_outing_amt,
toi.out_qty AS list_out_qty,
toi.out_amt AS list_out_amt,
toi.return_qty AS list_return_qty,
toi.return_amt AS list_return_amt,
toi.remarks AS list_remarks,
toi.flg_valid AS list_flg_valid,
toi.cp_id AS list_cp_id,
tmgs.sku_code AS list_sku_code,
tmgs.sku_model AS list_sku_model,
tmgs.sku_name AS list_sku_name,
tmgb.brand_name AS list_brand_name,
tmgb.short_name AS list_short_name,
tmgs.price_purchase AS list_price_purchase,
tmgs.price_standard AS list_price_standard,
i.inv_id as list_inv_id,
i.wh_id as list_wh_id,
i.inv_qty as list_inv_qty,
i.usable_qty as list_usable_qty,
i.wh_name as list_wh_name
AND t.order_no LIKE concat('%',my_ex.likequery(#{orderNo}),'%')
AND t.order_type = #{orderType}
AND t.org_id = #{orgId}
AND t.staff_id = #{staffId}
AND t.cus_id = #{cusId}
AND t.address_area = #{addressArea}
AND t.address_name = #{addressName}
AND t.address_no = #{addressNo}
AND t.address_gcj02 = #{addressGcj02}
AND t.address_full LIKE concat('%',my_ex.likequery(#{addressFull}),'%')
AND t.contact_name LIKE concat('%',my_ex.likequery(#{contactName}),'%')
AND t.contact_phone LIKE concat('%',my_ex.likequery(#{contactPhone}),'%')
AND t.sales_channel = #{salesChannel}
AND t.sum_quantity = #{sumQuantity}
AND t.sum_standard = #{sumStandard}
AND t.sum_amount = #{sumAmount}
AND t.sale_discount = #{saleDiscount}
AND t.order_status = #{orderStatus}
AND t.out_status = #{outStatus}
AND t.outing_qty = #{outingQty}
AND t.outing_amt = #{outingAmt}
AND t.out_qty = #{outQty}
AND t.out_amt = #{outAmt}
AND t.return_qty = #{returnQty}
AND t.return_amt = #{returnAmt}
AND t.amt_receivable = #{amtReceivable}
AND t.amt_handle = #{amtHandle}
AND t.amt_residue = #{amtResidue}
AND t.remarks = #{remarks}
AND t.annex_paths = #{annexPaths}
AND t.make_staff = #{makeStaff}
AND t.make_time = #{makeTime}
AND t.cp_id = #{cpId}
AND tmc.cus_phone LIKE concat('%',my_ex.likequery(#{cusPhone}),'%')
AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
AND t.org_id =any(#{orgIdList, typeHandler=uuidListTypeHandler})
AND t.staff_id =any(#{staffIdList, typeHandler=uuidListTypeHandler})
AND t.out_status =any(#{outStatusList, typeHandler=StringListTypeHandler})
AND t.delivery_date >= #{deliveryDateStart}::timestamp with time zone
AND t.delivery_date < #{deliveryDateEnd}::timestamp with time zone + interval '1 day'
AND t.make_time >= #{makeTimeStart}::timestamp with time zone
AND t.make_time < #{makeTimeEnd}::timestamp with time zone + interval '1 day'
AND t.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
WHERE order_id in
#{item}
toi.item_id AS toi_item_id,
t.order_id AS toi_order_id,
t.order_no AS toi_order_no,
toi.order_id AS toi_order_id,
toi.item_index AS toi_item_index,
toi.sku_id AS toi_sku_id,
toi.item_qty AS toi_item_qty,
toi.price_std AS toi_price_std,
toi.amt_std AS toi_amt_std,
toi.price_sale AS toi_price_sale,
toi.item_amt AS toi_item_amt,
toi.price_discount AS toi_price_discount,
toi.non_std_code AS toi_non_std_code,
toi.out_status AS toi_out_status,
toi.outing_qty AS toi_outing_qty,
toi.outing_amt AS toi_outing_amt,
toi.out_qty AS toi_out_qty,
toi.out_amt AS toi_out_amt,
toi.return_qty AS toi_return_qty,
toi.return_amt AS toi_return_amt,
toi.remarks AS toi_remarks,
toi.flg_valid AS toi_flg_valid,
toi.cp_id AS toi_cp_id,
tmgs.sku_code AS toi_sku_code,
tmgs.sku_model AS toi_sku_model,
tmgs.sku_name AS toi_sku_name,
tmgb.brand_name AS toi_brand_name,
tmgb.short_name AS toi_short_name,
tmgs.price_purchase AS toi_price_purchase,
tmgs.price_standard AS toi_price_standard
insert into dkic_b.t_psi_order
(
order_no,
order_type,
org_id,
staff_id,
cus_id,
address_area,
address_name,
address_no,
address_gcj02,
address_full,
contact_name,
contact_phone,
sales_channel,
delivery_date,
sum_quantity,
sum_standard,
sum_amount,
sale_discount,
order_status,
out_status,
outing_qty,
outing_amt,
out_qty,
out_amt,
return_qty,
return_amt,
amt_receivable,
amt_handle,
amt_residue,
remarks,
annex_paths,
make_staff,
make_time,
cp_id,
op_app_code,
)
values
(
#{item.orderNo},
#{item.orderType},
#{item.orgId}::uuid,
#{item.staffId}::uuid,
#{item.cusId}::uuid,
#{item.addressArea},
#{item.addressName},
#{item.addressNo},
#{item.addressGcj02},
#{item.addressFull},
#{item.contactName},
#{item.contactPhone},
#{item.salesChannel}::uuid,
#{item.deliveryDate},
#{item.sumQuantity},
#{item.sumStandard},
#{item.sumAmount},
#{item.saleDiscount},
#{item.orderStatus},
#{item.outStatus},
#{item.outingQty},
#{item.outingAmt},
#{item.outQty},
#{item.outAmt},
#{item.returnQty},
#{item.returnAmt},
#{item.amtReceivable},
#{item.amtHandle},
#{item.amtResidue},
#{item.remarks},
#{item.annexPaths},
#{item.makeStaff}::uuid,
#{item.makeTime},
#{item.cpId},
#{item.opAppCode},
)
update dkic_b.t_psi_order
order_type =#{et.orderType,jdbcType=VARCHAR},
org_id =#{et.orgId,typeHandler=UuidTypeHandler},
staff_id =#{et.staffId,typeHandler=UuidTypeHandler},
cus_id =#{et.cusId,typeHandler=UuidTypeHandler},
address_area =#{et.addressArea,typeHandler=JsonTypeHandler},
address_name =#{et.addressName,jdbcType=VARCHAR},
address_no =#{et.addressNo,jdbcType=VARCHAR},
address_gcj02 =#{et.addressGcj02,typeHandler=JsonTypeHandler},
address_full =#{et.addressFull,jdbcType=VARCHAR},
contact_name =#{et.contactName,jdbcType=VARCHAR},
contact_phone =#{et.contactPhone,jdbcType=VARCHAR},
sales_channel =#{et.salesChannel,jdbcType=OTHER},
delivery_date =#{et.deliveryDate,jdbcType=DATE},
sum_quantity =#{et.sumQuantity,jdbcType=NUMERIC},
sum_standard =#{et.sumStandard,jdbcType=NUMERIC},
sum_amount =#{et.sumAmount,jdbcType=NUMERIC},
sale_discount =#{et.saleDiscount,jdbcType=NUMERIC},
order_status =#{et.orderStatus,jdbcType=VARCHAR},
out_status =#{et.outStatus,jdbcType=VARCHAR},
outing_qty = outing_qty + #{et.outingQty,jdbcType=NUMERIC},
outing_amt = outing_amt + #{et.outingAmt,jdbcType=NUMERIC},
out_qty =out_qty + #{et.outQty,jdbcType=NUMERIC},
out_amt = out_amt + #{et.outAmt,jdbcType=NUMERIC},
return_qty =#{et.returnQty,jdbcType=NUMERIC},
return_amt =#{et.returnAmt,jdbcType=NUMERIC},
amt_receivable =#{et.amtReceivable,jdbcType=NUMERIC},
amt_handle =#{et.amtHandle,jdbcType=NUMERIC},
amt_residue =#{et.amtResidue,jdbcType=NUMERIC},
remarks =#{et.remarks,jdbcType=VARCHAR},
annex_paths =#{et..annexPaths,typeHandler=JsonTypeHandler},
make_staff =#{et.makeStaff,jdbcType=OTHER},
make_time =#{et.makeTime,jdbcType=TIMESTAMP},
flg_valid =#{et.flgValid,jdbcType=BOOLEAN},
cp_id =#{et.cpId,jdbcType=INTEGER},
where order_id =#{et.orderId,typeHandler=UuidTypeHandler}
and sum_quantity >= (out_qty + outing_qty)
update dkic_b.t_psi_order
return_qty = return_qty + #{returnQty,jdbcType=NUMERIC},
return_amt = return_amt + #{returnAmt,jdbcType=NUMERIC},
where order_id = #{orderId,typeHandler=UuidTypeHandler}
and out_qty >= return_qty