mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:19:19 +08:00
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
import cliProgress from 'cli-progress';
|
|
|
|
export const BATCH_SIZE = 1000;
|
|
|
|
export async function deleteExistingOrders(conn, companyId, specs, verbose) {
|
|
let total = 0;
|
|
for (const spec of specs) {
|
|
const [result] = await conn.execute(
|
|
'DELETE FROM ec_order WHERE company_id = ? AND product_spec_id = ?',
|
|
[companyId, spec.id]
|
|
);
|
|
total += result.affectedRows;
|
|
if (verbose) {
|
|
console.log(` Deleted ${result.affectedRows} orders for spec [${spec.id}] ${spec.name}`);
|
|
}
|
|
}
|
|
return total;
|
|
}
|
|
|
|
const SQL = `INSERT INTO ec_order
|
|
(company_id, shop_id, product_spec_id, spec_code, status_id, platform_order_no,
|
|
link_product_name, link_spec_name, received_amount, quantity, unit_price,
|
|
product_cost, shipping_cost, other_cost, remark, import_task_id, confirm, order_time)
|
|
VALUES ?`;
|
|
|
|
function toRow(o) {
|
|
return [
|
|
o.company_id, o.shop_id, o.product_spec_id, o.spec_code, o.status_id, o.platform_order_no,
|
|
o.link_product_name, o.link_spec_name, o.received_amount, o.quantity, o.unit_price,
|
|
o.product_cost, o.shipping_cost, o.other_cost,
|
|
o.remark, null, o.confirm, o.order_time,
|
|
];
|
|
}
|
|
|
|
export async function insertBatch(conn, batch) {
|
|
const rows = batch.map(toRow);
|
|
const [result] = await conn.query(SQL, [rows]);
|
|
return result.affectedRows;
|
|
}
|