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 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 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()) 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 mig_bi_order_done set status = 'FAIL', fail_reason = #{failReason}, updated_at = now() where old_bill_id = #{oldBillId} 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 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 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 into prc_pay_bill_new ( bill_id, currency, product_amount, redline_amount, cost_amount, pay_total, amount_a, amount_b, amount_c, amount_d, belong_saler, belong_saler_code, settlement_man, settlement_man_code, create_by, create_time, update_by, update_time ) select #{newBillId}, p.currency, p.product_amount, p.redline_amount, p.cost_amount, p.pay_total, p.amount_a, p.amount_b, p.amount_c, p.amount_d, p.belong_saler, p.belong_saler_code, p.settlement_man, p.settlement_man_code, p.create_by, p.create_time, p.update_by, p.update_time from prc_pay_bill p where p.pay_bill_id = #{oldId} insert into prc_pay_bill_fee_new ( fee_id, bill_id, pay_bill_id, fee_type, sc_id, fee_level, amount, currency, round_mode, remark, fee_source, source_id, is_deleted, statement_line_id, settle_supplier_id, settle_supplier_name, create_time ) select 0, #{newBillId}, #{newPayId}, f.fee_type, f.sc_id, f.fee_level, f.amount, f.currency, f.round_mode, f.remark, f.fee_source, f.source_id, f.is_deleted, f.statement_line_id, f.settle_supplier_id, f.settle_supplier_name, f.create_time from prc_pay_bill_fee f where f.fee_id = #{oldId} update prc_pay_bill_fee_new set fee_id = id where id = #{id} insert into ar_bill_detail_new ( detail_id, ar_bill_id, prc_order_bill_id, detail_no, order_no, tracking_no, transfer_no, receive_time, product_code, product_name, goods_description, country_code, country_name, dest_postcode, actual_weight, receive_weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height, currency, total_amount, product_amount, redline_amount, billing_fail_status, remark, create_by, create_time ) select d.detail_id, d.ar_bill_id, #{newBillId}, d.detail_no, d.order_no, d.tracking_no, d.transfer_no, d.receive_time, d.product_code, d.product_name, d.goods_description, d.country_code, d.country_name, d.dest_postcode, d.actual_weight, d.receive_weight, d.volume_weight, d.charge_weight, d.freight_rate, d.registration_fee, d.pkg_length, d.pkg_width, d.pkg_height, d.currency, d.total_amount, d.product_amount, d.redline_amount, d.billing_fail_status, d.remark, d.create_by, d.create_time from ar_bill_detail d where d.prc_order_bill_id = #{oldBillId} insert into ar_bill_detail_fee_new ( detail_fee_id, detail_id, prc_income_bill_fee_id, fee_no, fee_type, fee_name, sc_id, quantity, unit, unit_price, amount, product_amount, redline_amount, currency, calculation_formula, round_mode, remark, create_by, create_time ) select f.detail_fee_id, f.detail_id, #{newFeeId}, f.fee_no, f.fee_type, f.fee_name, f.sc_id, f.quantity, f.unit, f.unit_price, f.amount, f.product_amount, f.redline_amount, f.currency, f.calculation_formula, f.round_mode, f.remark, f.create_by, f.create_time from ar_bill_detail_fee f where f.detail_fee_id = #{detailFeeId} insert into pay_bill_line_new ( line_id, bill_id, fee_id, order_bill_id, order_no, lading_no, lading_fee_id, fee_name, fee_source, fee_level, amount, supplier_amount, diff_amount, diff_status, tax_rate, amount_net, tax_amount, base_amount, currency, price_date, version_no, remote_flag, density_level, line_source ) select l.line_id, l.bill_id, #{newFeeId}, #{newBillId}, l.order_no, l.lading_no, l.lading_fee_id, l.fee_name, l.fee_source, l.fee_level, l.amount, l.supplier_amount, l.diff_amount, l.diff_status, l.tax_rate, l.amount_net, l.tax_amount, l.base_amount, l.currency, l.price_date, l.version_no, l.remote_flag, l.density_level, l.line_source from pay_bill_line l where l.line_id = #{lineId} insert into prc_billing_task_new ( task_id, transfer_no, tracking_no, order_no, customer_code, bill_type, success_status, bill_time, bill_id, fail_code, error_message, create_by, create_time, update_by, update_time ) select t.task_id, t.transfer_no, t.tracking_no, t.order_no, t.customer_code, t.bill_type, t.success_status, t.bill_time, #{newBillId}, t.fail_code, t.error_message, t.create_by, t.create_time, t.update_by, t.update_time from prc_billing_task t where t.bill_id = #{oldBillId} insert into mig_bi_job_log (batch_no, fetched, success, fail, skip, started_at, remark) values (#{batchNo}, 0, 0, 0, 0, now(), null) update mig_bi_job_log set fetched = #{fetched}, success = #{success}, fail = #{fail}, skip = #{skip}, finished_at = now(), remark = #{failReason} where id = #{jobLogId}