refactor: 订单生成改为流式迭代降低内存,新增删单模式(cleaner),批量插入(BATCH_SIZE),日期预设选择,CLI合并单入口

This commit is contained in:
小蟑螂
2026-05-28 02:13:47 +08:00
parent 054cac86a8
commit ede706a8e0
6 changed files with 496 additions and 260 deletions
+42
View File
@@ -0,0 +1,42 @@
export async function deleteOrders(conn, { companyId, specIds, shopIds, startDate, endDate, verbose, dryRun }) {
const conditions = ['company_id = ?'];
const params = [companyId];
if (specIds && specIds.length > 0) {
const placeholders = specIds.map(() => '?').join(',');
conditions.push(`product_spec_id IN (${placeholders})`);
params.push(...specIds);
}
if (shopIds && shopIds.length > 0) {
const placeholders = shopIds.map(() => '?').join(',');
conditions.push(`shop_id IN (${placeholders})`);
params.push(...shopIds);
}
if (startDate) {
conditions.push('order_time >= ?');
params.push(startDate + ' 00:00:00');
}
if (endDate) {
conditions.push('order_time <= ?');
params.push(endDate + ' 23:59:59');
}
const where = conditions.join(' AND ');
if (dryRun) {
const [rows] = await conn.execute(
`SELECT COUNT(*) AS cnt FROM ec_order WHERE ${where}`,
params
);
return { matched: rows[0].cnt, deleted: 0 };
}
const [result] = await conn.execute(
`DELETE FROM ec_order WHERE ${where}`,
params
);
return { matched: result.affectedRows, deleted: result.affectedRows };
}