订单提交

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

@@ -78,13 +78,31 @@ npm run bills
npm run messages
```
## 8. 从最新 checkpoint 继续抓账
## 8. 单独抓订
```powershell
npm run orders
```
订单增量:
```powershell
npm run orders -- --incremental
```
订单断点继续:
```powershell
npm run orders -- --resume
```
## 9. 从最新 checkpoint 继续抓账单
```powershell
npm run bills -- --resume
```
## 9. 定时任务
## 10. 定时任务
```powershell
npm run schedule
@@ -96,7 +114,7 @@ npm run schedule
ALIYUN_APS_SCHEDULE_MODE=incremental
```
## 10. 常用 `.env` 配置
## 11. 常用 `.env` 配置
```env
ALIYUN_APS_BASE_URL=https://aps.aliyun.com
@@ -159,7 +177,7 @@ ALIYUN_APS_BROWSER_MODE=cdp
ALIYUN_APS_CDP_URL=http://127.0.0.1:9222
```
## 11. 推荐执行顺序
## 12. 推荐执行顺序
### 首次初始化
@@ -184,6 +202,13 @@ cd D:\project\python\aliyun-sync\aliyun-aps-sync
npm run messages
```
### 单独同步订单
```powershell
cd D:\project\python\aliyun-sync\aliyun-aps-sync
npm run orders
```
### 账单长任务恢复
```powershell
@@ -199,7 +224,7 @@ cd D:\project\python\aliyun-sync\aliyun-aps-sync
npm run schedule
```
## 12. 错误文件
## 13. 错误文件
运行异常时会保存:
@@ -207,7 +232,7 @@ npm run schedule
data/errors/<dataset>/
```
## 13. 运行时热键
## 14. 运行时热键
| 按键 | 功能 |
| --- | --- |
@@ -215,7 +240,7 @@ data/errors/<dataset>/
| F8 | 继续 |
| F9 | 终止 |
## 14. 本地数据目录
## 15. 本地数据目录
```text
data/current/

View File

@@ -84,6 +84,26 @@ npm run bills
npm run bills -- --resume
```
## 订单
只同步订单:
```bash
npm run orders
```
订单增量:
```bash
npm run orders -- --incremental
```
订单从 checkpoint 继续:
```bash
npm run orders -- --resume
```
## 消息
单独抓消息:

View File

@@ -8,6 +8,7 @@
"sync": "node src/index.js sync",
"incremental": "node src/index.js incremental",
"bills": "node src/index.js bills",
"orders": "node src/index.js orders",
"messages": "node src/index.js messages",
"schedule": "node src/index.js schedule"
},

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();