Files
BMS/bms-back/bms-system/src/main/resources/mapper/price/UuidToNewSyncMapper.xml
T

342 lines
17 KiB
XML

<?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.bms.price.migration.mapper.UuidToNewSyncMapper">
<select id="selectPendingBillIds" resultType="com.bms.price.migration.domain.UuidToNewPendingRow">
select o.bill_id as billId, o.create_time as createTime
from prc_order_bill o
where 1 = 1
<if test="lastCreateTime != null and lastBillId != null and lastBillId != ''">
and (
o.create_time &gt; #{lastCreateTime}
or (o.create_time = #{lastCreateTime} and o.bill_id &gt; #{lastBillId})
)
</if>
and not exists (
select 1 from mig_bi_order_done d
where d.old_bill_id = o.bill_id
)
order by o.create_time, o.bill_id
limit #{limit}
</select>
<select id="selectPendingCursorBootstrap" resultType="com.bms.price.migration.domain.UuidToNewPendingRow">
select o.bill_id as billId, o.create_time as createTime
from mig_bi_order_done d
inner join prc_order_bill o on o.bill_id = d.old_bill_id
order by o.create_time desc, o.bill_id desc
limit 1
</select>
<select id="selectOrderNo" resultType="String">
select order_no from prc_order_bill where bill_id = #{oldBillId} limit 1
</select>
<select id="countOrderBill" resultType="int">
select count(1) from prc_order_bill where bill_id = #{oldBillId}
</select>
<insert id="insertOrderBillNew" useGeneratedKeys="true" keyProperty="newBillId" keyColumn="bill_id">
insert into prc_order_bill_new (
bill_key, order_no, tracking_no, transfer_no,
belong_saler, belong_saler_code, settlement_man, settlement_man_code,
service_man, service_man_code, customer_id, customer_code,
customer_name, pieces, actual_weight, receive_weight,
volume, volume_weight, pkg_length, pkg_width,
pkg_height, shipper_name, consignee_name, dest_postcode,
warehouse_code, order_time, order_status, bl_pickup,
pickup_date, order_remark, product_code, product_name,
country_code, country_name, weight, biz_date,
tms_id, product_floor_code, product_floor, price_set_id,
price_set_code, price_set_name, set_type, bind_priority,
customer_priceset_id, psv_id, psd_id, weight_min,
weight_max, weight_label, effective_date, charge_weight,
freight_rate, base_freight_rate, discount_percent, registration_fee,
freight_amount, surcharge_amount, income_total, pay_total,
currency, ar_bill_status, customer_active_status, credit_arrears_status,
refund_status, billing_fail_status, error_message, round_mode,
created_by, create_time, updated_by, update_time
)
select
o.bill_key, o.order_no, o.tracking_no, o.transfer_no,
o.belong_saler, o.belong_saler_code, o.settlement_man, o.settlement_man_code,
o.service_man, o.service_man_code, o.customer_id, o.customer_code,
o.customer_name, o.pieces, o.actual_weight, o.receive_weight,
o.volume, o.volume_weight, o.pkg_length, o.pkg_width,
o.pkg_height, o.shipper_name, o.consignee_name, o.dest_postcode,
o.warehouse_code, o.order_time, o.order_status, o.bl_pickup,
o.pickup_date, o.order_remark, o.product_code, o.product_name,
o.country_code, o.country_name, o.weight, o.biz_date,
o.tms_id, o.product_floor_code, o.product_floor, o.price_set_id,
o.price_set_code, o.price_set_name, o.set_type, o.bind_priority,
o.customer_priceset_id, o.psv_id, o.psd_id, o.weight_min,
o.weight_max, o.weight_label, o.effective_date, o.charge_weight,
o.freight_rate, o.base_freight_rate, o.discount_percent, o.registration_fee,
o.freight_amount, o.surcharge_amount, o.income_total, o.pay_total,
o.currency, o.ar_bill_status, o.customer_active_status, o.credit_arrears_status,
o.refund_status, o.billing_fail_status, o.error_message, o.round_mode,
o.created_by, o.create_time, o.updated_by, o.update_time
from prc_order_bill o
where o.bill_id = #{oldBillId}
</insert>
<insert id="insertOrderDone">
insert into mig_bi_order_done (old_bill_id, new_bill_id, order_no, status, fail_reason, synced_at)
values (#{oldBillId}, #{newBillId}, #{orderNo}, #{status}, #{failReason}, now())
</insert>
<insert id="claimOrderDone">
insert ignore into mig_bi_order_done (old_bill_id, new_bill_id, order_no, status, fail_reason, synced_at)
values (#{oldBillId}, #{newBillId}, #{orderNo}, #{status}, #{failReason}, now())
</insert>
<update id="updateOrderDoneSuccess">
update mig_bi_order_done
set new_bill_id = #{newBillId},
order_no = #{orderNo},
status = 'SUCCESS',
fail_reason = null,
updated_at = now()
where old_bill_id = #{oldBillId}
</update>
<update id="updateOrderDoneFail">
update mig_bi_order_done
set status = 'FAIL',
fail_reason = #{failReason},
updated_at = now()
where old_bill_id = #{oldBillId}
</update>
<insert id="insertOrderExtNew">
insert into prc_order_bill_ext_new (
bill_id, order_no, create_time, update_time,
upstream_id, line_no, package_num, actual_volume,
cp_type, consignee_mobile, order_returnsign, trade_type,
duty_type, battery_type, consignee_companyname, consignee_address,
consignee_telephone, consignee_state, consignee_city, consignee_suburb,
consignee_passportno, consignee_email, consignee_taxno, consignee_taxnotype,
consignee_taxnocountry, consignee_streetno, consignee_doorno, shipper_taxnotype,
shipper_taxno, shipper_taxnocountry, customer_id, product_imagepath,
order_transactionurl, order_cargoamount, cargo_type, shipper_companyname,
shipper_address1, shipper_address2, shipper_address3, shipper_city,
shipper_state, shipper_postcode, shipper_country, shipper_telephone,
shipper_suburb, shipper_email, shipper_passportno, import_code,
import_name, import_companyname, import_address, import_address2,
import_address3, import_telephone, import_email, import_postcode,
import_city, import_state, import_country, buyerid,
create_at, pay_type, line_code, line_name,
product_code, product_name, product_type, line_type,
cargo_name, order_insurance, product_sum_price, product_sum,
shipper_doorno, tariff_payment_account, topayment, product_floor,
latest_trajectory, way_bill, bl_baging, bag_date,
org_order_status, status_description, zz_date, shipping_date,
order_type, receiving_photo, freight, is_receivable,
is_meet, bill_no_receivable, bill_no_meet, country_eingth_name,
is_receivable_fee, settlement_fee, product_id, service_freight,
is_pay_fee, has_added_surcharge, yf_fee, yf_totail_fee,
trajectory_status, cargo_type_name, service_code, three_code,
volume_height_old, volume_length_old, volume_width_old, register_man_old,
bag_no_old, air_no_old, lading_id, box_sizi_old,
baging_man_old, retrieval_man_old, invoice_amount_old, invoice_title_old,
invoice_weight_old, sku_old, hs_code_old, register_date_old,
invoice_currency_old, trajectory_sub_state, sign_in_time, warehouse_time,
declaration_time, release_time, station_time, takeoff_time,
landing_time, clearance_and_delivery_time, supplier_name, credit_code,
other_id, platform_code, sync_shipment_status, update_weight,
other_bag_no, bag_flag, online_time, outbound_time,
air_confirm_date, shipment_type, track_query_time, air_confirm_time,
package_type, confirm_weight, update_by, customer_pickup_site,
barcode_number, tracking_reflect_status, remote_postcode, clearance_time,
arrive_stock_time, departure_time, first_deliver_time, hs_code_tax_count,
hs_code_tax_amount, hs_code_tax_currency, invoice_url, clearance_no,
push_weight, internal_check_time, air_delay_time, first_landing_time,
second_takeoff_time, des_port_check_time, stay_remark, miss_box_remark,
product_channel_id, customer_track_id, register_site, package_type_financial,
mrn, product_floor_code, order_status, pickup_date,
bl_pickup, dimensional_weight_factor
)
select
#{newBillId}, e.order_no, e.create_time, e.update_time,
e.upstream_id, e.line_no, e.package_num, e.actual_volume,
e.cp_type, e.consignee_mobile, e.order_returnsign, e.trade_type,
e.duty_type, e.battery_type, e.consignee_companyname, e.consignee_address,
e.consignee_telephone, e.consignee_state, e.consignee_city, e.consignee_suburb,
e.consignee_passportno, e.consignee_email, e.consignee_taxno, e.consignee_taxnotype,
e.consignee_taxnocountry, e.consignee_streetno, e.consignee_doorno, e.shipper_taxnotype,
e.shipper_taxno, e.shipper_taxnocountry, e.customer_id, e.product_imagepath,
e.order_transactionurl, e.order_cargoamount, e.cargo_type, e.shipper_companyname,
e.shipper_address1, e.shipper_address2, e.shipper_address3, e.shipper_city,
e.shipper_state, e.shipper_postcode, e.shipper_country, e.shipper_telephone,
e.shipper_suburb, e.shipper_email, e.shipper_passportno, e.import_code,
e.import_name, e.import_companyname, e.import_address, e.import_address2,
e.import_address3, e.import_telephone, e.import_email, e.import_postcode,
e.import_city, e.import_state, e.import_country, e.buyerid,
e.create_at, e.pay_type, e.line_code, e.line_name,
e.product_code, e.product_name, e.product_type, e.line_type,
e.cargo_name, e.order_insurance, e.product_sum_price, e.product_sum,
e.shipper_doorno, e.tariff_payment_account, e.topayment, e.product_floor,
e.latest_trajectory, e.way_bill, e.bl_baging, e.bag_date,
e.org_order_status, e.status_description, e.zz_date, e.shipping_date,
e.order_type, e.receiving_photo, e.freight, e.is_receivable,
e.is_meet, e.bill_no_receivable, e.bill_no_meet, e.country_eingth_name,
e.is_receivable_fee, e.settlement_fee, e.product_id, e.service_freight,
e.is_pay_fee, e.has_added_surcharge, e.yf_fee, e.yf_totail_fee,
e.trajectory_status, e.cargo_type_name, e.service_code, e.three_code,
e.volume_height_old, e.volume_length_old, e.volume_width_old, e.register_man_old,
e.bag_no_old, e.air_no_old, e.lading_id, e.box_sizi_old,
e.baging_man_old, e.retrieval_man_old, e.invoice_amount_old, e.invoice_title_old,
e.invoice_weight_old, e.sku_old, e.hs_code_old, e.register_date_old,
e.invoice_currency_old, e.trajectory_sub_state, e.sign_in_time, e.warehouse_time,
e.declaration_time, e.release_time, e.station_time, e.takeoff_time,
e.landing_time, e.clearance_and_delivery_time, e.supplier_name, e.credit_code,
e.other_id, e.platform_code, e.sync_shipment_status, e.update_weight,
e.other_bag_no, e.bag_flag, e.online_time, e.outbound_time,
e.air_confirm_date, e.shipment_type, e.track_query_time, e.air_confirm_time,
e.package_type, e.confirm_weight, e.update_by, e.customer_pickup_site,
e.barcode_number, e.tracking_reflect_status, e.remote_postcode, e.clearance_time,
e.arrive_stock_time, e.departure_time, e.first_deliver_time, e.hs_code_tax_count,
e.hs_code_tax_amount, e.hs_code_tax_currency, e.invoice_url, e.clearance_no,
e.push_weight, e.internal_check_time, e.air_delay_time, e.first_landing_time,
e.second_takeoff_time, e.des_port_check_time, e.stay_remark, e.miss_box_remark,
e.product_channel_id, e.customer_track_id, e.register_site, e.package_type_financial,
e.mrn, e.product_floor_code, e.order_status, e.pickup_date,
e.bl_pickup, e.dimensional_weight_factor
from prc_order_bill_ext e
where e.bill_id = #{oldBillId}
</insert>
<select id="selectIncomeIds" resultType="String">
select income_bill_id from prc_income_bill where bill_id = #{oldBillId}
</select>
<insert id="insertIncomeBillNew" useGeneratedKeys="true" keyProperty="newId" keyColumn="income_bill_id">
insert into prc_income_bill_new (
bill_id, currency, product_amount, redline_amount,
sales_amount, income_total, refund_status, belong_saler,
belong_saler_code, settlement_man, settlement_man_code, create_by,
create_time, update_by, update_time
)
select
#{newBillId}, i.currency, i.product_amount, i.redline_amount,
i.sales_amount, i.income_total, i.refund_status, i.belong_saler,
i.belong_saler_code, i.settlement_man, i.settlement_man_code, i.create_by,
i.create_time, i.update_by, i.update_time
from prc_income_bill i
where i.income_bill_id = #{oldId}
</insert>
<select id="selectIncomeFees" resultType="com.bms.price.migration.domain.UuidToNewFeeRow">
select fee_id as feeId, income_bill_id as parentId
from prc_income_bill_fee
where bill_id = #{oldBillId}
order by fee_id
</select>
<insert id="insertIncomeFeeNew" useGeneratedKeys="true" keyProperty="newId" keyColumn="fee_id">
insert into prc_income_bill_fee_new (
bill_id, income_bill_id, fee_type, fee_name,
sc_id, amount, product_amount, redline_amount,
currency, round_mode, remark, ar_bill_status,
manual_flag, create_time
)
select
#{newBillId}, #{newIncomeId}, f.fee_type, f.fee_name,
f.sc_id, f.amount, f.product_amount, f.redline_amount,
f.currency, f.round_mode, f.remark, f.ar_bill_status,
f.manual_flag, f.create_time
from prc_income_bill_fee f
where f.fee_id = #{oldId}
</insert>
<update id="updateArDetailFeeIncomeFeeId">
update ar_bill_detail_fee
set income_fee_id = #{newFeeId}
where prc_income_bill_fee_id = #{oldFeeId}
</update>
<!-- 应付表:正式列 bill_id/order_bill_id;旧 UUID 保留在 *_old -->
<update id="updatePayBillOrderId">
update prc_pay_bill
set bill_id = #{newBillId}
where bill_id_old = #{oldBillId}
</update>
<update id="updatePayFeeOrderId">
update prc_pay_bill_fee
set bill_id = #{newBillId}
where bill_id_old = #{oldBillId}
</update>
<update id="updateArDetailOrderId">
update ar_bill_detail
set order_id = #{newBillId}
where prc_order_bill_id = #{oldBillId}
</update>
<update id="updatePayBillLineOrderId">
update pay_bill_line
set order_bill_id = #{newBillId}
where order_bill_id_old = #{oldBillId}
</update>
<!-- bill_id dropped; order_id is the live FK. No-op for legacy sync. -->
<update id="updateBillingTaskOrderId">
update prc_billing_task
set order_id = #{newBillId}
where 1 = 0
</update>
<update id="updateArGenTaskOrderId">
update ar_bill_generate_task
set order_id = #{newBillId}
where last_source_bill_id = #{oldBillId}
</update>
<insert id="insertJobLogStart" useGeneratedKeys="true" keyProperty="jobLogId" keyColumn="id">
insert into mig_bi_job_log (batch_no, fetched, success, fail, skip, started_at, remark)
values (#{batchNo}, 0, 0, 0, 0, now(), null)
</insert>
<update id="updateJobLogFinish">
update mig_bi_job_log
set fetched = #{fetched},
success = #{success},
fail = #{fail},
skip = #{skip},
finished_at = now(),
remark = #{failReason}
where id = #{jobLogId}
</update>
<select id="selectProgress" resultType="com.bms.price.migration.domain.UuidToNewProgressVo">
select
(select count(*) from prc_order_bill) as oldCnt,
(select count(*) from mig_bi_order_done where status = 'SUCCESS') as doneCnt,
(select count(*) from prc_order_bill_new) as newCnt
</select>
<select id="selectJobLogList" resultType="com.bms.price.migration.domain.MigBiJobLog">
select id, batch_no as batchNo, fetched, success, fail, skip,
started_at as startedAt, finished_at as finishedAt, remark
from mig_bi_job_log
<where>
<if test="batchNo != null and batchNo != ''">
and batch_no = #{batchNo}
</if>
<if test="beginStartedAt != null and beginStartedAt != ''">
and started_at &gt;= #{beginStartedAt}
</if>
<if test="endStartedAt != null and endStartedAt != ''">
and started_at &lt;= #{endStartedAt}
</if>
</where>
order by id desc
</select>
</mapper>