@pisell/pisellos 2.2.191 → 2.2.193
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
- package/dist/modules/Order/index.d.ts +12 -10
- package/dist/modules/Order/index.js +462 -571
- package/dist/modules/Order/types.d.ts +5 -5
- package/dist/modules/Order/utils.js +3 -3
- package/dist/modules/Payment/utils.js +2 -1
- package/dist/modules/SalesSummary/utils.js +1 -1
- package/dist/server/index.d.ts +8 -1
- package/dist/server/index.js +651 -464
- package/dist/server/modules/order/index.d.ts +4 -70
- package/dist/server/modules/order/index.js +336 -747
- package/dist/server/modules/products/index.d.ts +0 -57
- package/dist/server/modules/products/index.js +347 -706
- package/dist/solution/BaseSales/index.d.ts +2 -1
- package/dist/solution/BaseSales/index.js +116 -122
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ScanOrder/index.js +3 -1
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +3 -2
- package/lib/modules/Order/index.d.ts +12 -10
- package/lib/modules/Order/index.js +94 -118
- package/lib/modules/Order/types.d.ts +5 -5
- package/lib/modules/Order/utils.js +4 -4
- package/lib/modules/Payment/utils.js +2 -1
- package/lib/modules/SalesSummary/utils.js +1 -3
- package/lib/server/index.d.ts +8 -1
- package/lib/server/index.js +143 -24
- package/lib/server/modules/order/index.d.ts +4 -70
- package/lib/server/modules/order/index.js +31 -391
- package/lib/server/modules/products/index.d.ts +0 -57
- package/lib/server/modules/products/index.js +0 -333
- package/lib/solution/BaseSales/index.d.ts +2 -1
- package/lib/solution/BaseSales/index.js +53 -16
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/ScanOrder/index.js +3 -1
- package/package.json +1 -1
|
@@ -40,9 +40,6 @@ var INDEXDB_STORE_NAME = "orders";
|
|
|
40
40
|
var ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY = "server_order_last_full_fetch_at";
|
|
41
41
|
var ORDER_SYNC_THROTTLE_MS_STORAGE_KEY = "order_sync_throttle_ms";
|
|
42
42
|
var DEFAULT_ORDER_SYNC_THROTTLE_MS = 2e3;
|
|
43
|
-
var ORDER_FLOW_LOG_WINDOW_KEY = "__orderModuleFlowLogs";
|
|
44
|
-
var ORDER_WRITE_STATS_WINDOW_KEY = "__orderModuleWriteStats";
|
|
45
|
-
var ORDER_FLOW_LOG_MAX_LENGTH = 1e3;
|
|
46
43
|
var ORDER_SQLITE_DEDUPE_MS = 15e3;
|
|
47
44
|
var ORDER_SILENT_REFRESH_MIN_INTERVAL_MS = 3e4;
|
|
48
45
|
var ORDER_BUSINESS_WRITE_SOURCES = /* @__PURE__ */ new Set([
|
|
@@ -60,8 +57,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
60
57
|
// Map<resource_id, OrderId[]> 资源到订单的倒排索引
|
|
61
58
|
this.resourceIdIndex = /* @__PURE__ */ new Map();
|
|
62
59
|
this.orderSQLiteSaveQueue = Promise.resolve();
|
|
63
|
-
/** 全局递增的 SQLite 写入序号,便于日志关联同一次操作 */
|
|
64
|
-
this.orderFlowWriteSeq = 0;
|
|
65
60
|
/** 按 storageKey 记录最近一次 SQLite 写入来源与时间,用于去重 */
|
|
66
61
|
this.recentSqliteWriteByStorageKey = /* @__PURE__ */ new Map();
|
|
67
62
|
/** 最近一次 SSE 全量拉取完成时间 */
|
|
@@ -128,15 +123,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
128
123
|
this.store.list = [];
|
|
129
124
|
this.store.map = /* @__PURE__ */ new Map();
|
|
130
125
|
}
|
|
131
|
-
this.initOrderFlowLogs();
|
|
132
126
|
this.initOrderDataSource();
|
|
133
127
|
this.setupOrderSync();
|
|
134
|
-
this.pushOrderFlowLog("initialize.complete", {
|
|
135
|
-
hasDbManager: !!this.dbManager,
|
|
136
|
-
hasLogger: !!this.logger,
|
|
137
|
-
initialOrderCount: this.store.list.length,
|
|
138
|
-
createdAtQuery: this.store.createdAtQuery || null
|
|
139
|
-
});
|
|
140
128
|
this.logInfo("OrderServer模块初始化完成", {
|
|
141
129
|
hasDbManager: !!this.dbManager,
|
|
142
130
|
hasLogger: !!this.logger,
|
|
@@ -176,144 +164,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
176
164
|
}
|
|
177
165
|
} catch {
|
|
178
166
|
}
|
|
179
|
-
this.pushOrderFlowLog(`error.${title}`, metadata);
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* 初始化 window 上的订单流程调试日志数组及辅助方法。
|
|
183
|
-
*
|
|
184
|
-
* @example
|
|
185
|
-
* window.clearOrderModuleFlowLogs()
|
|
186
|
-
* // 操作完成后:
|
|
187
|
-
* copy(window.exportOrderModuleFlowLogs?.() || '[]')
|
|
188
|
-
*/
|
|
189
|
-
initOrderFlowLogs() {
|
|
190
|
-
try {
|
|
191
|
-
const win = typeof globalThis !== "undefined" ? globalThis.window : void 0;
|
|
192
|
-
if (!win)
|
|
193
|
-
return;
|
|
194
|
-
win[ORDER_FLOW_LOG_WINDOW_KEY] = [];
|
|
195
|
-
win[ORDER_WRITE_STATS_WINDOW_KEY] = {};
|
|
196
|
-
win.clearOrderModuleFlowLogs = () => {
|
|
197
|
-
win[ORDER_FLOW_LOG_WINDOW_KEY] = [];
|
|
198
|
-
win[ORDER_WRITE_STATS_WINDOW_KEY] = {};
|
|
199
|
-
this.orderFlowWriteSeq = 0;
|
|
200
|
-
this.recentSqliteWriteByStorageKey.clear();
|
|
201
|
-
this.lastServerFullFetchAtMs = 0;
|
|
202
|
-
this.pushOrderFlowLog("debug.clear", {});
|
|
203
|
-
};
|
|
204
|
-
win.exportOrderModuleFlowLogs = () => {
|
|
205
|
-
const logs = win[ORDER_FLOW_LOG_WINDOW_KEY] || [];
|
|
206
|
-
return JSON.stringify(logs, null, 2);
|
|
207
|
-
};
|
|
208
|
-
win.exportOrderModuleWriteStats = () => {
|
|
209
|
-
const stats = win[ORDER_WRITE_STATS_WINDOW_KEY] || {};
|
|
210
|
-
return JSON.stringify(stats, null, 2);
|
|
211
|
-
};
|
|
212
|
-
win.summarizeOrderModuleWrites = (topN = 20) => {
|
|
213
|
-
const stats = win[ORDER_WRITE_STATS_WINDOW_KEY] || {};
|
|
214
|
-
return Object.entries(stats).map(([storageKey, entries]) => {
|
|
215
|
-
const list = entries || [];
|
|
216
|
-
const sources = [...new Set(list.map((item) => item.source))];
|
|
217
|
-
const last = list[list.length - 1];
|
|
218
|
-
return {
|
|
219
|
-
storageKey,
|
|
220
|
-
orderId: (last == null ? void 0 : last.orderId) ?? null,
|
|
221
|
-
writeCount: list.length,
|
|
222
|
-
sources,
|
|
223
|
-
lastWriteAt: (last == null ? void 0 : last.ts) || ""
|
|
224
|
-
};
|
|
225
|
-
}).sort((a, b) => b.writeCount - a.writeCount).slice(0, topN);
|
|
226
|
-
};
|
|
227
|
-
this.pushOrderFlowLog("debug.init", {
|
|
228
|
-
logKey: ORDER_FLOW_LOG_WINDOW_KEY,
|
|
229
|
-
writeStatsKey: ORDER_WRITE_STATS_WINDOW_KEY,
|
|
230
|
-
helpers: [
|
|
231
|
-
"clearOrderModuleFlowLogs",
|
|
232
|
-
"exportOrderModuleFlowLogs",
|
|
233
|
-
"exportOrderModuleWriteStats",
|
|
234
|
-
"summarizeOrderModuleWrites"
|
|
235
|
-
]
|
|
236
|
-
});
|
|
237
|
-
} catch {
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* 写入 window 订单流程调试日志。
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* this.pushOrderFlowLog('mergeOrdersToStore.start', { count: 3 })
|
|
245
|
-
*/
|
|
246
|
-
pushOrderFlowLog(step, metadata) {
|
|
247
|
-
try {
|
|
248
|
-
const win = typeof globalThis !== "undefined" ? globalThis.window : void 0;
|
|
249
|
-
if (!win)
|
|
250
|
-
return;
|
|
251
|
-
if (!Array.isArray(win[ORDER_FLOW_LOG_WINDOW_KEY])) {
|
|
252
|
-
win[ORDER_FLOW_LOG_WINDOW_KEY] = [];
|
|
253
|
-
}
|
|
254
|
-
const entry = {
|
|
255
|
-
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
256
|
-
step,
|
|
257
|
-
metadata: metadata || {}
|
|
258
|
-
};
|
|
259
|
-
win[ORDER_FLOW_LOG_WINDOW_KEY].push(entry);
|
|
260
|
-
const logs = win[ORDER_FLOW_LOG_WINDOW_KEY];
|
|
261
|
-
if (logs.length > ORDER_FLOW_LOG_MAX_LENGTH) {
|
|
262
|
-
logs.splice(0, logs.length - ORDER_FLOW_LOG_MAX_LENGTH);
|
|
263
|
-
}
|
|
264
|
-
console.log(`[OrderFlow] ${step}`, metadata || {});
|
|
265
|
-
} catch {
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
/** 当前内存 store 快照信息,供流程日志使用 */
|
|
269
|
-
getOrderStoreSnapshot() {
|
|
270
|
-
return {
|
|
271
|
-
storeListCount: this.store.list.length,
|
|
272
|
-
storeMapCount: this.store.map.size,
|
|
273
|
-
pendingSyncCount: this.pendingSyncMessages.length,
|
|
274
|
-
isProcessingSyncBatch: this.isProcessingSyncBatch,
|
|
275
|
-
isIdlePhase: this.isIdlePhase
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* 记录一次 SQLite 写入到 window 统计,用于排查同一订单被多次写入的原因。
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* this.trackOrderWrite('upsertOrdersFromRemote', 'bulkUpdate', orders, 'insert')
|
|
283
|
-
*/
|
|
284
|
-
trackOrderWrite(source, writeMethod, orders, mergeActions = {}, defaultMergeAction = "update") {
|
|
285
|
-
this.orderFlowWriteSeq += 1;
|
|
286
|
-
const writeSeq = this.orderFlowWriteSeq;
|
|
287
|
-
try {
|
|
288
|
-
const win = typeof globalThis !== "undefined" ? globalThis.window : void 0;
|
|
289
|
-
if (!win)
|
|
290
|
-
return writeSeq;
|
|
291
|
-
if (!win[ORDER_WRITE_STATS_WINDOW_KEY]) {
|
|
292
|
-
win[ORDER_WRITE_STATS_WINDOW_KEY] = {};
|
|
293
|
-
}
|
|
294
|
-
const stats = win[ORDER_WRITE_STATS_WINDOW_KEY];
|
|
295
|
-
for (const order of orders) {
|
|
296
|
-
const storageKey = this.getOrderStorageKey(order);
|
|
297
|
-
if (!storageKey)
|
|
298
|
-
continue;
|
|
299
|
-
const orderKey = order.order_id !== void 0 && order.order_id !== null ? this.getIdKey(order.order_id) : "";
|
|
300
|
-
const mergeAction = orderKey && mergeActions[orderKey] || defaultMergeAction;
|
|
301
|
-
const entry = {
|
|
302
|
-
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
303
|
-
writeSeq,
|
|
304
|
-
source,
|
|
305
|
-
writeMethod,
|
|
306
|
-
orderId: order.order_id ?? null,
|
|
307
|
-
storageKey,
|
|
308
|
-
mergeAction
|
|
309
|
-
};
|
|
310
|
-
if (!stats[storageKey])
|
|
311
|
-
stats[storageKey] = [];
|
|
312
|
-
stats[storageKey].push(entry);
|
|
313
|
-
}
|
|
314
|
-
} catch {
|
|
315
|
-
}
|
|
316
|
-
return writeSeq;
|
|
317
167
|
}
|
|
318
168
|
/**
|
|
319
169
|
* 记录订单最近一次 SQLite 写入,供 pubsub 回声去重使用。
|
|
@@ -478,21 +328,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
478
328
|
return DEFAULT_ORDER_SYNC_THROTTLE_MS;
|
|
479
329
|
}
|
|
480
330
|
async preload() {
|
|
481
|
-
this.pushOrderFlowLog("preload.start", this.getOrderStoreSnapshot());
|
|
482
331
|
const getData = async () => {
|
|
483
332
|
const orders = await this.loadOrdersByServer();
|
|
484
333
|
if (orders.length === 0) {
|
|
485
|
-
this.pushOrderFlowLog("preload.empty", this.getOrderStoreSnapshot());
|
|
486
334
|
return;
|
|
487
335
|
}
|
|
488
336
|
this.store.list = (0, import_lodash_es.cloneDeep)(orders);
|
|
489
337
|
this.syncOrdersMap();
|
|
490
338
|
this.core.effects.emit(import_types.OrderHooks.onOrdersChanged, this.store.list);
|
|
491
339
|
this.core.effects.emit(import_types.OrderHooks.onOrdersSyncCompleted, null);
|
|
492
|
-
this.pushOrderFlowLog("preload.done", {
|
|
493
|
-
...this.getOrderStoreSnapshot(),
|
|
494
|
-
loadedCount: orders.length
|
|
495
|
-
});
|
|
496
340
|
};
|
|
497
341
|
getData();
|
|
498
342
|
}
|
|
@@ -502,28 +346,20 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
502
346
|
getOrderById(id) {
|
|
503
347
|
return this.store.map.get(this.getIdKey(id));
|
|
504
348
|
}
|
|
505
|
-
/** 按 order_id
|
|
349
|
+
/** 按 order_id 查询内存订单。 */
|
|
506
350
|
getOrderByOrderId(orderId) {
|
|
507
351
|
return this.store.map.get(this.getIdKey(orderId));
|
|
508
352
|
}
|
|
509
|
-
async
|
|
510
|
-
const key = this.getIdKey(
|
|
511
|
-
const
|
|
512
|
-
if (
|
|
513
|
-
|
|
353
|
+
async getLocalOrderByLookup(lookup) {
|
|
354
|
+
const key = this.getIdKey(lookup);
|
|
355
|
+
const memoryOrderById = this.store.map.get(key);
|
|
356
|
+
if (memoryOrderById)
|
|
357
|
+
return memoryOrderById;
|
|
358
|
+
const memoryOrder = this.store.list.find((order) => this.isOrderLookupMatch(order, key));
|
|
359
|
+
if (memoryOrder)
|
|
514
360
|
return memoryOrder;
|
|
515
|
-
}
|
|
516
|
-
this.pushOrderFlowLog("getLocalOrderByOrderId.missMemory", { orderId, key });
|
|
517
361
|
const orders = await this.loadOrdersFromSQLite();
|
|
518
|
-
const localOrder = orders.find((order) =>
|
|
519
|
-
const shopOrderNumber = order == null ? void 0 : order.shop_order_number;
|
|
520
|
-
if (shopOrderNumber && this.getIdKey(shopOrderNumber) === key)
|
|
521
|
-
return true;
|
|
522
|
-
const id = order == null ? void 0 : order.order_id;
|
|
523
|
-
if (id === void 0 || id === null)
|
|
524
|
-
return false;
|
|
525
|
-
return this.getIdKey(id) === key;
|
|
526
|
-
});
|
|
362
|
+
const localOrder = orders.find((order) => this.isOrderLookupMatch(order, key));
|
|
527
363
|
if (!localOrder)
|
|
528
364
|
return null;
|
|
529
365
|
this.store.list = orders;
|
|
@@ -531,16 +367,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
531
367
|
return localOrder;
|
|
532
368
|
}
|
|
533
369
|
async loadOrdersByServer() {
|
|
534
|
-
var _a
|
|
370
|
+
var _a;
|
|
535
371
|
let orderList = [];
|
|
536
|
-
this.pushOrderFlowLog("loadOrdersByServer.start", {
|
|
537
|
-
...this.getOrderStoreSnapshot(),
|
|
538
|
-
query: ((_a = this.store) == null ? void 0 : _a.createdAtQuery) || null,
|
|
539
|
-
hasOrderDataSource: !!this.orderDataSource
|
|
540
|
-
});
|
|
541
372
|
this.logInfo("loadOrdersByServer-开始", {
|
|
542
373
|
hasOrderDataSource: !!this.orderDataSource,
|
|
543
|
-
query: ((
|
|
374
|
+
query: ((_a = this.store) == null ? void 0 : _a.createdAtQuery) || null
|
|
544
375
|
});
|
|
545
376
|
if (this.orderDataSource) {
|
|
546
377
|
try {
|
|
@@ -550,7 +381,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
550
381
|
}
|
|
551
382
|
});
|
|
552
383
|
orderList = data || [];
|
|
553
|
-
this.pushOrderFlowLog("loadOrdersByServer.sseSuccess", { count: orderList.length });
|
|
554
384
|
this.logInfo("loadOrdersByServer-SSE拉取成功", {
|
|
555
385
|
count: orderList.length
|
|
556
386
|
});
|
|
@@ -558,15 +388,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
558
388
|
this.lastServerFullFetchAtMs = Date.now();
|
|
559
389
|
} catch {
|
|
560
390
|
orderList = [];
|
|
561
|
-
this.pushOrderFlowLog("loadOrdersByServer.sseFailed", {});
|
|
562
391
|
this.logInfo("loadOrdersByServer-SSE拉取失败,回退为空数组");
|
|
563
392
|
}
|
|
564
393
|
}
|
|
565
394
|
await this.replaceOrdersSnapshotInSQLite(orderList, "loadOrdersByServer");
|
|
566
|
-
this.pushOrderFlowLog("loadOrdersByServer.done", {
|
|
567
|
-
count: orderList.length,
|
|
568
|
-
...this.getOrderStoreSnapshot()
|
|
569
|
-
});
|
|
570
395
|
this.logInfo("loadOrdersByServer-结束", {
|
|
571
396
|
count: orderList.length
|
|
572
397
|
});
|
|
@@ -582,17 +407,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
582
407
|
const startTime = Date.now();
|
|
583
408
|
const elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
|
|
584
409
|
if (this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS) {
|
|
585
|
-
this.pushOrderFlowLog("silentRefresh.skipped", {
|
|
586
|
-
elapsedMs: elapsedSinceFullFetch,
|
|
587
|
-
minIntervalMs: ORDER_SILENT_REFRESH_MIN_INTERVAL_MS,
|
|
588
|
-
...this.getOrderStoreSnapshot()
|
|
589
|
-
});
|
|
590
410
|
return this.store.list;
|
|
591
411
|
}
|
|
592
|
-
this.pushOrderFlowLog("silentRefresh.start", {
|
|
593
|
-
...this.getOrderStoreSnapshot(),
|
|
594
|
-
callerHint: "Server.refreshOrdersInBackground 或其他调用方"
|
|
595
|
-
});
|
|
596
412
|
this.logInfo("silentRefresh 开始");
|
|
597
413
|
try {
|
|
598
414
|
const orders = await this.loadOrdersByServer();
|
|
@@ -601,17 +417,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
601
417
|
this.syncOrdersMap();
|
|
602
418
|
this.core.effects.emit(import_types.OrderHooks.onOrdersChanged, this.store.list);
|
|
603
419
|
await this.core.effects.emit(import_types.OrderHooks.onOrdersSyncCompleted, null);
|
|
604
|
-
this.pushOrderFlowLog("silentRefresh.done", {
|
|
605
|
-
orderCount: orders.length,
|
|
606
|
-
durationMs: Date.now() - startTime,
|
|
607
|
-
...this.getOrderStoreSnapshot()
|
|
608
|
-
});
|
|
609
420
|
this.logInfo("silentRefresh 完成", {
|
|
610
421
|
orderCount: orders.length,
|
|
611
422
|
duration: `${Date.now() - startTime}ms`
|
|
612
423
|
});
|
|
613
424
|
} else {
|
|
614
|
-
this.pushOrderFlowLog("silentRefresh.empty", { durationMs: Date.now() - startTime });
|
|
615
425
|
this.logInfo("silentRefresh: 服务器未返回数据");
|
|
616
426
|
}
|
|
617
427
|
return this.store.list;
|
|
@@ -643,12 +453,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
643
453
|
this.logInfo("overwriteExistingOrder-本地不存在该订单,跳过", { orderId });
|
|
644
454
|
return { overwritten: false };
|
|
645
455
|
}
|
|
646
|
-
this.pushOrderFlowLog("overwriteExistingOrder.start", {
|
|
647
|
-
orderId,
|
|
648
|
-
storageKey: this.getOrderStorageKey(fresh),
|
|
649
|
-
...this.getOrderStoreSnapshot(),
|
|
650
|
-
callerHint: "Server.handleUpdateLocalOrder 本地已存在时"
|
|
651
|
-
});
|
|
652
456
|
this.logInfo("overwriteExistingOrder-开始覆盖", {
|
|
653
457
|
orderId,
|
|
654
458
|
storeOrderCountBefore: this.store.list.length
|
|
@@ -661,10 +465,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
661
465
|
});
|
|
662
466
|
this.syncOrdersMap();
|
|
663
467
|
await this.updateOrderInSQLite(fresh, "overwriteExistingOrder");
|
|
664
|
-
this.pushOrderFlowLog("overwriteExistingOrder.done", {
|
|
665
|
-
orderId,
|
|
666
|
-
...this.getOrderStoreSnapshot()
|
|
667
|
-
});
|
|
668
468
|
this.logInfo("overwriteExistingOrder-结束", {
|
|
669
469
|
orderId,
|
|
670
470
|
storeOrderCountAfter: this.store.list.length
|
|
@@ -681,11 +481,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
681
481
|
this.logInfo("upsertOrdersFromRemote-订单列表为空", {});
|
|
682
482
|
return;
|
|
683
483
|
}
|
|
684
|
-
this.pushOrderFlowLog("upsertOrdersFromRemote.start", {
|
|
685
|
-
count: freshOrders.length,
|
|
686
|
-
orderIds: freshOrders.map((o) => o.order_id).filter((id) => id !== void 0 && id !== null),
|
|
687
|
-
callerHint: "Server.handleUpdateLocalOrder / handleOrderSalesDetail / handleUpdateLocalOrdersBatch"
|
|
688
|
-
});
|
|
689
484
|
this.logInfo("upsertOrdersFromRemote-开始", { count: freshOrders.length });
|
|
690
485
|
await this.mergeOrdersToStore(freshOrders, "upsertOrdersFromRemote");
|
|
691
486
|
}
|
|
@@ -804,15 +599,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
804
599
|
this.pendingSyncMessages.push(message);
|
|
805
600
|
const throttleMs = this.getOrderSyncThrottleMs();
|
|
806
601
|
const routeInfo = this.resolveSyncMessageRoute(message);
|
|
807
|
-
this.pushOrderFlowLog("orderSync.received", {
|
|
808
|
-
id: message.id ?? null,
|
|
809
|
-
order_id: message.order_id ?? null,
|
|
810
|
-
type: message.type ?? null,
|
|
811
|
-
pendingCount: this.pendingSyncMessages.length,
|
|
812
|
-
throttleMs,
|
|
813
|
-
...routeInfo,
|
|
814
|
-
duplicateRiskHint: routeInfo.route === "httpRefresh.batchIds" && routeInfo.hasNormalizedBody ? "有 body 但被 ids 优先,会走 HTTP 重拉" : routeInfo.route === "bodyUpsert" ? "body 直写,可能与 upsertOrdersFromRemote 重复" : null
|
|
815
|
-
});
|
|
816
602
|
this.logInfo("orderSync-收到消息并入队", {
|
|
817
603
|
id: message.id ?? null,
|
|
818
604
|
order_id: message.order_id ?? null,
|
|
@@ -838,9 +624,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
838
624
|
return;
|
|
839
625
|
if (this.isIdlePhase) {
|
|
840
626
|
this.isIdlePhase = false;
|
|
841
|
-
this.pushOrderFlowLog("orderSync.flushImmediate", {
|
|
842
|
-
pendingCount: this.pendingSyncMessages.length
|
|
843
|
-
});
|
|
844
627
|
this.logInfo("orderSync-首条消息立即触发处理");
|
|
845
628
|
void this.flushOrderSyncMessagesByThrottle();
|
|
846
629
|
return;
|
|
@@ -848,10 +631,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
848
631
|
if (this.syncTimer)
|
|
849
632
|
return;
|
|
850
633
|
const throttleMs = this.getOrderSyncThrottleMs();
|
|
851
|
-
this.pushOrderFlowLog("orderSync.flushScheduled", {
|
|
852
|
-
pendingCount: this.pendingSyncMessages.length,
|
|
853
|
-
throttleMs
|
|
854
|
-
});
|
|
855
634
|
this.syncTimer = setTimeout(() => {
|
|
856
635
|
this.syncTimer = void 0;
|
|
857
636
|
void this.flushOrderSyncMessagesByThrottle();
|
|
@@ -869,9 +648,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
869
648
|
return;
|
|
870
649
|
}
|
|
871
650
|
this.isProcessingSyncBatch = true;
|
|
872
|
-
this.pushOrderFlowLog("orderSync.flushStart", {
|
|
873
|
-
pendingCount: this.pendingSyncMessages.length
|
|
874
|
-
});
|
|
875
651
|
try {
|
|
876
652
|
await this.processOrderSyncMessages();
|
|
877
653
|
} finally {
|
|
@@ -900,10 +676,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
900
676
|
if (messages.length === 0)
|
|
901
677
|
return;
|
|
902
678
|
const batchProcessStartAt = Date.now();
|
|
903
|
-
this.pushOrderFlowLog("processOrderSyncMessages.start", {
|
|
904
|
-
messageCount: messages.length,
|
|
905
|
-
...this.getOrderStoreSnapshot()
|
|
906
|
-
});
|
|
907
679
|
const earliestReceivedAt = Math.min(
|
|
908
680
|
...messages.map((m) => m._pubsubReceivedAt ?? batchProcessStartAt)
|
|
909
681
|
);
|
|
@@ -917,10 +689,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
917
689
|
const refreshIds = [];
|
|
918
690
|
messages.forEach((msg, msgIndex) => {
|
|
919
691
|
const routeInfo = this.resolveSyncMessageRoute(msg);
|
|
920
|
-
this.pushOrderFlowLog("processOrderSyncMessages.messageRoute", {
|
|
921
|
-
msgIndex,
|
|
922
|
-
...routeInfo
|
|
923
|
-
});
|
|
924
692
|
const hasBatchIds = routeInfo.hasBatchIds;
|
|
925
693
|
const singleId = routeInfo.singleId;
|
|
926
694
|
const hasSingleId = routeInfo.hasSingleId;
|
|
@@ -938,13 +706,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
938
706
|
});
|
|
939
707
|
const uniqueRefreshIds = this.uniqueOrderIds(refreshIds);
|
|
940
708
|
const upsertList = [...upsertOrders.values()];
|
|
941
|
-
this.pushOrderFlowLog("processOrderSyncMessages.deduped", {
|
|
942
|
-
upsertCount: upsertList.length,
|
|
943
|
-
upsertOrderIds: upsertList.map((o) => o.order_id),
|
|
944
|
-
refreshIdCount: uniqueRefreshIds.length,
|
|
945
|
-
refreshIds: uniqueRefreshIds,
|
|
946
|
-
willCallMergeTimes: (upsertList.length > 0 ? 1 : 0) + (uniqueRefreshIds.length > 0 ? 1 : 0)
|
|
947
|
-
});
|
|
948
709
|
this.logInfo("processOrderSyncMessages-去重完成", {
|
|
949
710
|
upsertCount: upsertList.length,
|
|
950
711
|
refreshIdCount: uniqueRefreshIds.length
|
|
@@ -955,34 +716,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
955
716
|
if (uniqueRefreshIds.length > 0) {
|
|
956
717
|
const { toFetch, skipped } = this.filterRedundantHttpRefreshIds(uniqueRefreshIds);
|
|
957
718
|
if (skipped.length > 0) {
|
|
958
|
-
this.pushOrderFlowLog("processOrderSyncMessages.httpRefreshFiltered", {
|
|
959
|
-
requestedIds: uniqueRefreshIds,
|
|
960
|
-
skippedIds: skipped.map((item) => item.orderId),
|
|
961
|
-
skipped
|
|
962
|
-
});
|
|
963
719
|
}
|
|
964
720
|
if (toFetch.length > 0) {
|
|
965
721
|
const freshOrders = await this.fetchOrdersByHttp(toFetch);
|
|
966
722
|
if (freshOrders.length > 0) {
|
|
967
723
|
await this.mergeOrdersToStore(freshOrders, "pubsub.httpRefresh");
|
|
968
724
|
} else {
|
|
969
|
-
this.pushOrderFlowLog("processOrderSyncMessages.httpRefreshEmpty", {
|
|
970
|
-
refreshIds: toFetch
|
|
971
|
-
});
|
|
972
725
|
}
|
|
973
726
|
}
|
|
974
727
|
}
|
|
975
728
|
if (upsertList.length === 0 && uniqueRefreshIds.length === 0) {
|
|
976
|
-
this.pushOrderFlowLog("processOrderSyncMessages.noop", {});
|
|
977
729
|
return;
|
|
978
730
|
}
|
|
979
731
|
const batchProcessEndAt = Date.now();
|
|
980
|
-
this.pushOrderFlowLog("processOrderSyncMessages.done", {
|
|
981
|
-
upsertCount: upsertList.length,
|
|
982
|
-
refreshIdCount: uniqueRefreshIds.length,
|
|
983
|
-
batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
|
|
984
|
-
...this.getOrderStoreSnapshot()
|
|
985
|
-
});
|
|
986
732
|
this.logInfo("processOrderSyncMessages-结束", {
|
|
987
733
|
upsertCount: upsertList.length,
|
|
988
734
|
refreshIdCount: uniqueRefreshIds.length,
|
|
@@ -1004,15 +750,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1004
750
|
async fetchOrdersByHttp(ids) {
|
|
1005
751
|
if (!this.orderDataSource || ids.length === 0)
|
|
1006
752
|
return [];
|
|
1007
|
-
this.pushOrderFlowLog("fetchOrdersByHttp.start", { ids, count: ids.length });
|
|
1008
753
|
try {
|
|
1009
754
|
if (typeof this.orderDataSource.fetchOrdersByIds === "function") {
|
|
1010
755
|
const orderList2 = await this.orderDataSource.fetchOrdersByIds(ids);
|
|
1011
|
-
this.pushOrderFlowLog("fetchOrdersByHttp.done", {
|
|
1012
|
-
ids,
|
|
1013
|
-
count: (orderList2 == null ? void 0 : orderList2.length) || 0,
|
|
1014
|
-
via: "fetchOrdersByIds"
|
|
1015
|
-
});
|
|
1016
756
|
return orderList2 || [];
|
|
1017
757
|
}
|
|
1018
758
|
const orderList = await this.orderDataSource.run({
|
|
@@ -1020,14 +760,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1020
760
|
query: { ids }
|
|
1021
761
|
}
|
|
1022
762
|
});
|
|
1023
|
-
this.pushOrderFlowLog("fetchOrdersByHttp.done", {
|
|
1024
|
-
ids,
|
|
1025
|
-
count: (orderList == null ? void 0 : orderList.length) || 0,
|
|
1026
|
-
via: "run.http"
|
|
1027
|
-
});
|
|
1028
763
|
return orderList || [];
|
|
1029
764
|
} catch {
|
|
1030
|
-
this.pushOrderFlowLog("fetchOrdersByHttp.failed", { ids });
|
|
1031
765
|
return [];
|
|
1032
766
|
}
|
|
1033
767
|
}
|
|
@@ -1035,12 +769,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1035
769
|
* 将增量订单合并到 store
|
|
1036
770
|
*/
|
|
1037
771
|
async mergeOrdersToStore(freshOrders, source) {
|
|
1038
|
-
this.pushOrderFlowLog("mergeOrdersToStore.start", {
|
|
1039
|
-
source,
|
|
1040
|
-
freshOrderCount: freshOrders.length,
|
|
1041
|
-
freshOrderIds: freshOrders.map((o) => o.order_id).filter((id) => id !== void 0 && id !== null),
|
|
1042
|
-
...this.getOrderStoreSnapshot()
|
|
1043
|
-
});
|
|
1044
772
|
this.logInfo("mergeOrdersToStore-开始", {
|
|
1045
773
|
freshOrderCount: freshOrders.length,
|
|
1046
774
|
storeOrderCountBefore: this.store.list.length
|
|
@@ -1079,17 +807,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1079
807
|
this.store.list = updatedList;
|
|
1080
808
|
this.syncOrdersMap();
|
|
1081
809
|
await this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
|
|
1082
|
-
this.pushOrderFlowLog("mergeOrdersToStore.done", {
|
|
1083
|
-
source,
|
|
1084
|
-
uniqueFreshCount,
|
|
1085
|
-
insertCount,
|
|
1086
|
-
updateCount,
|
|
1087
|
-
patchedCount: patchedOrders.length,
|
|
1088
|
-
patchedOrderIds: patchedOrders.map((o) => o.order_id),
|
|
1089
|
-
patchedStorageKeys: patchedOrders.map((o) => this.getOrderStorageKey(o)),
|
|
1090
|
-
mergeActions,
|
|
1091
|
-
...this.getOrderStoreSnapshot()
|
|
1092
|
-
});
|
|
1093
810
|
this.logInfo("mergeOrdersToStore-结束", {
|
|
1094
811
|
uniqueFreshCount,
|
|
1095
812
|
storeOrderCountAfter: this.store.list.length
|
|
@@ -1139,6 +856,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1139
856
|
getIdKey(id) {
|
|
1140
857
|
return String(id);
|
|
1141
858
|
}
|
|
859
|
+
isOrderLookupMatch(order, lookupKey) {
|
|
860
|
+
if (!order || !lookupKey)
|
|
861
|
+
return false;
|
|
862
|
+
const candidates = [
|
|
863
|
+
order.order_id,
|
|
864
|
+
order.external_sale_number,
|
|
865
|
+
order.order_number,
|
|
866
|
+
order.shop_order_number,
|
|
867
|
+
order.shop_full_order_number
|
|
868
|
+
];
|
|
869
|
+
return candidates.some((value) => {
|
|
870
|
+
if (value === void 0 || value === null || value === "")
|
|
871
|
+
return false;
|
|
872
|
+
return this.getIdKey(value) === lookupKey;
|
|
873
|
+
});
|
|
874
|
+
}
|
|
1142
875
|
/**
|
|
1143
876
|
* 解析订单 SQLite 主键,规则与宿主 OrderDataSource.getOrderStorageKey 一致。
|
|
1144
877
|
*
|
|
@@ -1248,19 +981,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1248
981
|
*/
|
|
1249
982
|
async patchOrdersInSQLite(orders, source, mergeActions = {}) {
|
|
1250
983
|
if (!this.dbManager || orders.length === 0) {
|
|
1251
|
-
this.pushOrderFlowLog("patchOrdersInSQLite.skip", {
|
|
1252
|
-
source,
|
|
1253
|
-
hasDbManager: !!this.dbManager,
|
|
1254
|
-
inputCount: orders.length
|
|
1255
|
-
});
|
|
1256
984
|
return;
|
|
1257
985
|
}
|
|
1258
986
|
const ordersSnapshot = (0, import_lodash_es.cloneDeep)(orders).filter((order) => this.getOrderStorageKey(order));
|
|
1259
987
|
if (ordersSnapshot.length === 0) {
|
|
1260
|
-
this.pushOrderFlowLog("patchOrdersInSQLite.skipNoStorageKey", {
|
|
1261
|
-
source,
|
|
1262
|
-
inputCount: orders.length
|
|
1263
|
-
});
|
|
1264
988
|
return;
|
|
1265
989
|
}
|
|
1266
990
|
const { toWrite, skipped } = this.filterRedundantPatchOrders(
|
|
@@ -1268,35 +992,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1268
992
|
ordersSnapshot,
|
|
1269
993
|
mergeActions
|
|
1270
994
|
);
|
|
1271
|
-
if (skipped.length > 0) {
|
|
1272
|
-
this.pushOrderFlowLog("patchOrdersInSQLite.dedupeSkipped", {
|
|
1273
|
-
source,
|
|
1274
|
-
skippedCount: skipped.length,
|
|
1275
|
-
skipped
|
|
1276
|
-
});
|
|
1277
|
-
}
|
|
1278
995
|
if (toWrite.length === 0) {
|
|
1279
|
-
this.pushOrderFlowLog("patchOrdersInSQLite.skipAllDeduped", {
|
|
1280
|
-
source,
|
|
1281
|
-
inputCount: ordersSnapshot.length,
|
|
1282
|
-
skipped
|
|
1283
|
-
});
|
|
1284
996
|
return;
|
|
1285
997
|
}
|
|
1286
998
|
try {
|
|
1287
999
|
await this.runInOrderSQLiteSaveQueue(async () => {
|
|
1288
1000
|
let writeMethod = "none";
|
|
1289
|
-
this.
|
|
1001
|
+
this.logInfo("patchOrdersInSQLite-开始", {
|
|
1290
1002
|
source,
|
|
1291
1003
|
count: toWrite.length,
|
|
1292
|
-
orderIds: toWrite.map((o) => o.order_id),
|
|
1293
|
-
storageKeys: toWrite.map((o) => this.getOrderStorageKey(o)),
|
|
1294
1004
|
dedupedCount: skipped.length
|
|
1295
1005
|
});
|
|
1296
|
-
this.logInfo("patchOrdersInSQLite-开始", {
|
|
1297
|
-
source,
|
|
1298
|
-
count: toWrite.length
|
|
1299
|
-
});
|
|
1300
1006
|
if (typeof this.dbManager.bulkUpdate === "function") {
|
|
1301
1007
|
writeMethod = "bulkUpdate";
|
|
1302
1008
|
await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, toWrite);
|
|
@@ -1309,27 +1015,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1309
1015
|
await this.dbManager.update(INDEXDB_STORE_NAME, order);
|
|
1310
1016
|
}
|
|
1311
1017
|
}
|
|
1312
|
-
const writeSeq = this.trackOrderWrite(source, writeMethod, toWrite, mergeActions);
|
|
1313
1018
|
this.recordRecentSqliteWrite(source, toWrite);
|
|
1314
|
-
this.pushOrderFlowLog("patchOrdersInSQLite.done", {
|
|
1315
|
-
source,
|
|
1316
|
-
writeSeq,
|
|
1317
|
-
count: toWrite.length,
|
|
1318
|
-
writeMethod,
|
|
1319
|
-
dedupedCount: skipped.length
|
|
1320
|
-
});
|
|
1321
1019
|
this.logInfo("patchOrdersInSQLite-完成", {
|
|
1322
1020
|
source,
|
|
1323
1021
|
count: toWrite.length,
|
|
1022
|
+
writeMethod,
|
|
1324
1023
|
dedupedCount: skipped.length
|
|
1325
1024
|
});
|
|
1326
1025
|
});
|
|
1327
1026
|
} catch (error) {
|
|
1328
|
-
this.pushOrderFlowLog("patchOrdersInSQLite.error", {
|
|
1329
|
-
source,
|
|
1330
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1331
|
-
orderCount: ordersSnapshot.length
|
|
1332
|
-
});
|
|
1333
1027
|
this.logError("增量保存订单到 SQLite 失败", {
|
|
1334
1028
|
error: error instanceof Error ? error.message : String(error),
|
|
1335
1029
|
orderCount: ordersSnapshot.length
|
|
@@ -1344,22 +1038,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1344
1038
|
*/
|
|
1345
1039
|
async updateOrderInSQLite(order, source) {
|
|
1346
1040
|
if (!this.dbManager || !this.getOrderStorageKey(order)) {
|
|
1347
|
-
this.pushOrderFlowLog("updateOrderInSQLite.skip", {
|
|
1348
|
-
source,
|
|
1349
|
-
hasDbManager: !!this.dbManager,
|
|
1350
|
-
orderId: (order == null ? void 0 : order.order_id) ?? null
|
|
1351
|
-
});
|
|
1352
1041
|
return;
|
|
1353
1042
|
}
|
|
1354
1043
|
const orderSnapshot = (0, import_lodash_es.cloneDeep)(order);
|
|
1355
1044
|
try {
|
|
1356
1045
|
await this.runInOrderSQLiteSaveQueue(async () => {
|
|
1357
1046
|
let writeMethod = "none";
|
|
1358
|
-
this.pushOrderFlowLog("updateOrderInSQLite.start", {
|
|
1359
|
-
source,
|
|
1360
|
-
orderId: orderSnapshot.order_id ?? null,
|
|
1361
|
-
storageKey: this.getOrderStorageKey(orderSnapshot)
|
|
1362
|
-
});
|
|
1363
1047
|
this.logInfo("updateOrderInSQLite-开始", {
|
|
1364
1048
|
source,
|
|
1365
1049
|
orderId: orderSnapshot.order_id ?? null,
|
|
@@ -1375,31 +1059,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1375
1059
|
writeMethod = "bulkAdd";
|
|
1376
1060
|
await this.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
1377
1061
|
}
|
|
1378
|
-
const writeSeq = this.trackOrderWrite(
|
|
1379
|
-
source,
|
|
1380
|
-
writeMethod,
|
|
1381
|
-
[orderSnapshot],
|
|
1382
|
-
{},
|
|
1383
|
-
"singleUpdate"
|
|
1384
|
-
);
|
|
1385
1062
|
this.recordRecentSqliteWrite(source, [orderSnapshot]);
|
|
1386
|
-
this.
|
|
1063
|
+
this.logInfo("updateOrderInSQLite-完成", {
|
|
1387
1064
|
source,
|
|
1388
|
-
writeSeq,
|
|
1389
1065
|
orderId: orderSnapshot.order_id ?? null,
|
|
1390
|
-
storageKey: this.getOrderStorageKey(orderSnapshot),
|
|
1391
1066
|
writeMethod
|
|
1392
1067
|
});
|
|
1393
|
-
this.logInfo("updateOrderInSQLite-完成", {
|
|
1394
|
-
orderId: orderSnapshot.order_id ?? null
|
|
1395
|
-
});
|
|
1396
1068
|
});
|
|
1397
1069
|
} catch (error) {
|
|
1398
|
-
this.pushOrderFlowLog("updateOrderInSQLite.error", {
|
|
1399
|
-
source,
|
|
1400
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1401
|
-
orderId: orderSnapshot.order_id ?? null
|
|
1402
|
-
});
|
|
1403
1070
|
this.logError("单条保存订单到 SQLite 失败", {
|
|
1404
1071
|
error: error instanceof Error ? error.message : String(error),
|
|
1405
1072
|
orderId: orderSnapshot.order_id ?? null
|
|
@@ -1414,57 +1081,30 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1414
1081
|
*/
|
|
1415
1082
|
async replaceOrdersSnapshotInSQLite(orderList, source) {
|
|
1416
1083
|
if (!this.dbManager) {
|
|
1417
|
-
this.pushOrderFlowLog("replaceOrdersSnapshotInSQLite.skip", { source, count: orderList.length });
|
|
1418
1084
|
return;
|
|
1419
1085
|
}
|
|
1420
1086
|
const orderListSnapshot = (0, import_lodash_es.cloneDeep)(orderList);
|
|
1421
1087
|
try {
|
|
1422
1088
|
await this.runInOrderSQLiteSaveQueue(async () => {
|
|
1423
|
-
this.pushOrderFlowLog("replaceOrdersSnapshotInSQLite.start", {
|
|
1424
|
-
source,
|
|
1425
|
-
count: orderListSnapshot.length
|
|
1426
|
-
});
|
|
1427
1089
|
this.logInfo("replaceOrdersSnapshotInSQLite-开始", {
|
|
1428
1090
|
source,
|
|
1429
1091
|
count: orderListSnapshot.length
|
|
1430
1092
|
});
|
|
1431
1093
|
await this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
1432
|
-
this.pushOrderFlowLog("replaceOrdersSnapshotInSQLite.cleared", {
|
|
1433
|
-
source,
|
|
1434
|
-
count: orderListSnapshot.length
|
|
1435
|
-
});
|
|
1436
1094
|
this.logInfo("replaceOrdersSnapshotInSQLite-clear完成", {
|
|
1437
1095
|
count: orderListSnapshot.length
|
|
1438
1096
|
});
|
|
1439
1097
|
if (orderListSnapshot.length === 0) {
|
|
1440
|
-
this.pushOrderFlowLog("replaceOrdersSnapshotInSQLite.doneEmpty", { source });
|
|
1441
1098
|
return;
|
|
1442
1099
|
}
|
|
1443
1100
|
await this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderListSnapshot);
|
|
1444
|
-
const writeSeq = this.trackOrderWrite(
|
|
1445
|
-
source,
|
|
1446
|
-
"clear+bulkAdd",
|
|
1447
|
-
orderListSnapshot,
|
|
1448
|
-
{},
|
|
1449
|
-
"snapshot"
|
|
1450
|
-
);
|
|
1451
1101
|
this.recordRecentSqliteWrite(source, orderListSnapshot);
|
|
1452
|
-
this.pushOrderFlowLog("replaceOrdersSnapshotInSQLite.done", {
|
|
1453
|
-
source,
|
|
1454
|
-
writeSeq,
|
|
1455
|
-
count: orderListSnapshot.length,
|
|
1456
|
-
writeMethod: "clear+bulkAdd"
|
|
1457
|
-
});
|
|
1458
1102
|
this.logInfo("replaceOrdersSnapshotInSQLite-bulkAdd完成", {
|
|
1103
|
+
source,
|
|
1459
1104
|
count: orderListSnapshot.length
|
|
1460
1105
|
});
|
|
1461
1106
|
});
|
|
1462
1107
|
} catch (error) {
|
|
1463
|
-
this.pushOrderFlowLog("replaceOrdersSnapshotInSQLite.error", {
|
|
1464
|
-
source,
|
|
1465
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1466
|
-
orderList: orderListSnapshot.length
|
|
1467
|
-
});
|
|
1468
1108
|
this.logError("全量保存订单到 SQLite 失败", {
|
|
1469
1109
|
error: error instanceof Error ? error.message : String(error),
|
|
1470
1110
|
orderList: orderListSnapshot.length
|