订单提交

This commit is contained in:
ray
2026-05-06 15:13:03 +08:00
parent ac4c7d9c3f
commit d14ed90597
5 changed files with 90 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ const args = process.argv.slice(2);
const command = args[0] || 'sync';
const extraArgs = args.slice(1);
const billsResume = extraArgs.includes('--resume');
const ordersIncremental = extraArgs.includes('--incremental');
for (const arg of extraArgs) {
if (arg.startsWith('--incremental-order-start-date=')) {
@@ -11,7 +12,7 @@ for (const arg of extraArgs) {
}
}
const { login, scheduleSync, syncAll, syncAllIncremental, syncBillsOnly, syncMessagesOnly } = await import('./sync.js');
const { login, scheduleSync, syncAll, syncAllIncremental, syncBillsOnly, syncMessagesOnly, syncOrdersOnly } = await import('./sync.js');
if (command === 'login') {
await login();
@@ -36,6 +37,12 @@ if (command === 'bills') {
process.exit(0);
}
if (command === 'orders') {
const summary = await syncOrdersOnly({ resume: billsResume, incremental: ordersIncremental });
console.log(JSON.stringify(summary, null, 2));
process.exit(0);
}
if (command === 'messages') {
const summary = await syncMessagesOnly({ incremental: config.scheduleMode === 'incremental' });
console.log(JSON.stringify(summary, null, 2));

View File

@@ -543,6 +543,35 @@ export async function syncBillsOnly(options = {}) {
}
}
export async function syncOrdersOnly(options = {}) {
const runtimeController = getRuntimeController();
runtimeController.bind();
const context = await getContext();
let page = null;
try {
const summary = { startedAt: new Date().toISOString(), datasets: {} };
page = await resolveActivePage(context, '/detail/order/~/costCenter/order');
summary.datasets.orders = await syncOrders(page, options);
summary.finishedAt = new Date().toISOString();
const stamp = nowStamp();
saveRunSummary(stamp, summary);
return summary;
} catch (error) {
await reportRuntimeError(error, page, { label: 'syncOrdersOnly', dataset: 'orders', mode: options.incremental ? 'incremental' : 'full' });
throw error;
} finally {
if (config.closeBrowser) {
await closeContextIfNeeded();
} else {
console.log('浏览器保持运行');
}
await closeDbPool();
runtimeController.unbind();
}
}
export async function syncMessagesOnly(options = {}) {
const runtimeController = getRuntimeController();
runtimeController.bind();