@pisell/pisellos 2.3.170 → 2.3.171

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.
Files changed (31) hide show
  1. package/dist/model/strategy/adapter/promotion/evaluator.js +5 -4
  2. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  3. package/dist/modules/Discount/types.d.ts +4 -0
  4. package/dist/modules/Order/index.js +27 -13
  5. package/dist/modules/Product/index.d.ts +1 -1
  6. package/dist/modules/Rules/index.d.ts +3 -10
  7. package/dist/modules/Rules/index.js +169 -87
  8. package/dist/modules/Rules/promotionSelection.d.ts +14 -0
  9. package/dist/modules/Rules/promotionSelection.js +390 -0
  10. package/dist/modules/Rules/types.d.ts +9 -0
  11. package/dist/server/modules/order/index.d.ts +6 -0
  12. package/dist/server/modules/order/index.js +782 -447
  13. package/dist/solution/BaseSales/index.js +41 -21
  14. package/dist/solution/BaseSales/utils/cartPromotion.js +5 -2
  15. package/dist/solution/BookingByStep/index.d.ts +2 -2
  16. package/lib/model/strategy/adapter/promotion/evaluator.js +5 -4
  17. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  18. package/lib/modules/Discount/types.d.ts +4 -0
  19. package/lib/modules/Order/index.js +11 -0
  20. package/lib/modules/Product/index.d.ts +1 -1
  21. package/lib/modules/Rules/index.d.ts +3 -10
  22. package/lib/modules/Rules/index.js +62 -22
  23. package/lib/modules/Rules/promotionSelection.d.ts +14 -0
  24. package/lib/modules/Rules/promotionSelection.js +230 -0
  25. package/lib/modules/Rules/types.d.ts +9 -0
  26. package/lib/server/modules/order/index.d.ts +6 -0
  27. package/lib/server/modules/order/index.js +226 -29
  28. package/lib/solution/BaseSales/index.js +19 -5
  29. package/lib/solution/BaseSales/utils/cartPromotion.js +5 -2
  30. package/lib/solution/BookingByStep/index.d.ts +2 -2
  31. package/package.json +1 -1
@@ -1904,6 +1904,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1904
1904
  normalizedOrder,
1905
1905
  pendingOrder,
1906
1906
  storageKey,
1907
+ storageKeyMigrations,
1908
+ previousStorageKeys,
1907
1909
  mergeActions,
1908
1910
  updatedList,
1909
1911
  identityKeyToIndex,
@@ -1920,6 +1922,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1920
1922
  existingOrder,
1921
1923
  mergedOrder,
1922
1924
  nextOrder,
1925
+ previousStorageKey,
1926
+ _nextOrder$order_id2,
1923
1927
  pendingSnapshot,
1924
1928
  insertIndex,
1925
1929
  patchedOrders,
@@ -1988,6 +1992,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1988
1992
  this.logInfo('upsertPendingSyncOrders-开始', {
1989
1993
  count: pendingMap.size
1990
1994
  });
1995
+ storageKeyMigrations = [];
1996
+ previousStorageKeys = this.store.list.map(function (order) {
1997
+ return _this11.getPersistedOrderStorageKey(order);
1998
+ });
1991
1999
  mergeActions = {};
1992
2000
  updatedList = this.store.list.map(function (order) {
1993
2001
  return _this11.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
@@ -2009,17 +2017,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2009
2017
  }
2010
2018
  }
2011
2019
  _iterator9 = _createForOfIteratorHelper(memoryPendingMap.entries());
2012
- _context17.prev = 37;
2020
+ _context17.prev = 39;
2013
2021
  _iterator9.s();
2014
- case 39:
2022
+ case 41:
2015
2023
  if ((_step9 = _iterator9.n()).done) {
2016
- _context17.next = 58;
2024
+ _context17.next = 62;
2017
2025
  break;
2018
2026
  }
2019
2027
  _step9$value = _slicedToArray(_step9.value, 2), _storageKey = _step9$value[0], _pendingOrder = _step9$value[1];
2020
- matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
2028
+ matchIndex = this.findLocalOrderIndexByIdentity(identityKeyToIndex, updatedList, _pendingOrder);
2021
2029
  if (!(matchIndex >= 0)) {
2022
- _context17.next = 52;
2030
+ _context17.next = 56;
2023
2031
  break;
2024
2032
  }
2025
2033
  existingOrder = updatedList[matchIndex];
@@ -2028,6 +2036,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2028
2036
  need_sync: 1,
2029
2037
  is_draft_order: 0
2030
2038
  });
2039
+ previousStorageKey = previousStorageKeys[matchIndex];
2040
+ if (previousStorageKey && previousStorageKey !== _storageKey) {
2041
+ storageKeyMigrations.push({
2042
+ orderId: (_nextOrder$order_id2 = nextOrder.order_id) !== null && _nextOrder$order_id2 !== void 0 ? _nextOrder$order_id2 : null,
2043
+ from: previousStorageKey,
2044
+ to: _storageKey
2045
+ });
2046
+ delete nextOrder[ORDER_STORAGE_KEY_FIELD];
2047
+ }
2031
2048
  updatedList[matchIndex] = nextOrder;
2032
2049
  pendingSnapshot = pendingMap.get(_storageKey);
2033
2050
  if (pendingSnapshot) {
@@ -2036,55 +2053,57 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2036
2053
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
2037
2054
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
2038
2055
  mergeActions[_storageKey] = 'update';
2039
- return _context17.abrupt("continue", 56);
2040
- case 52:
2056
+ return _context17.abrupt("continue", 60);
2057
+ case 56:
2041
2058
  insertIndex = updatedList.length;
2042
2059
  updatedList.push(_pendingOrder);
2043
2060
  this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
2044
2061
  mergeActions[_storageKey] = 'insert';
2045
- case 56:
2046
- _context17.next = 39;
2062
+ case 60:
2063
+ _context17.next = 41;
2047
2064
  break;
2048
- case 58:
2049
- _context17.next = 63;
2065
+ case 62:
2066
+ _context17.next = 67;
2050
2067
  break;
2051
- case 60:
2052
- _context17.prev = 60;
2053
- _context17.t1 = _context17["catch"](37);
2068
+ case 64:
2069
+ _context17.prev = 64;
2070
+ _context17.t1 = _context17["catch"](39);
2054
2071
  _iterator9.e(_context17.t1);
2055
- case 63:
2056
- _context17.prev = 63;
2072
+ case 67:
2073
+ _context17.prev = 67;
2057
2074
  _iterator9.f();
2058
- return _context17.finish(63);
2059
- case 66:
2075
+ return _context17.finish(67);
2076
+ case 70:
2060
2077
  patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
2061
2078
  previousList = this.store.list;
2062
2079
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
2063
2080
  this.syncOrdersMap();
2064
- _context17.prev = 70;
2065
- _context17.next = 73;
2066
- return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
2067
- case 73:
2068
- _context17.next = 80;
2081
+ _context17.prev = 74;
2082
+ _context17.next = 77;
2083
+ return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, _objectSpread(_objectSpread({}, options), {}, {
2084
+ storageKeyMigrations: storageKeyMigrations
2085
+ }));
2086
+ case 77:
2087
+ _context17.next = 84;
2069
2088
  break;
2070
- case 75:
2071
- _context17.prev = 75;
2072
- _context17.t2 = _context17["catch"](70);
2089
+ case 79:
2090
+ _context17.prev = 79;
2091
+ _context17.t2 = _context17["catch"](74);
2073
2092
  this.store.list = previousList;
2074
2093
  this.syncOrdersMap();
2075
2094
  throw _context17.t2;
2076
- case 80:
2095
+ case 84:
2077
2096
  this.logInfo('upsertPendingSyncOrders-结束', {
2078
2097
  count: patchedOrders.length,
2079
2098
  storeOrderCountAfter: this.store.list.length
2080
2099
  });
2081
- _context17.next = 83;
2100
+ _context17.next = 87;
2082
2101
  return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
2083
- case 83:
2102
+ case 87:
2084
2103
  case "end":
2085
2104
  return _context17.stop();
2086
2105
  }
2087
- }, _callee17, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
2106
+ }, _callee17, this, [[7, 22, 25, 28], [39, 64, 67, 70], [74, 79]]);
2088
2107
  }));
2089
2108
  function upsertPendingSyncOrders(_x13) {
2090
2109
  return _upsertPendingSyncOrders.apply(this, arguments);
@@ -2101,7 +2120,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2101
2120
  value: (function () {
2102
2121
  var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(draftOrders) {
2103
2122
  var _this12 = this;
2104
- var draftMap, memoryDraftMap, _iterator10, _step10, order, draftOrder, storageKey, memoryDraftOrder, mergeActions, updatedList, identityKeyToIndex, index, _iterator11, _step11, key, _iterator12, _step12, _step12$value, _storageKey2, _draftOrder, matchIndex, existingOrder, reconciledDraftOrder, mergedOrder, nextOrder, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
2123
+ var draftMap, memoryDraftMap, _iterator10, _step10, order, draftOrder, storageKey, memoryDraftOrder, storageKeyMigrations, mergeActions, updatedList, previousStorageKeys, identityKeyToIndex, index, _iterator11, _step11, key, _iterator12, _step12, _step12$value, _storageKey2, _draftOrder, matchIndex, existingOrder, previousStorageKey, reconciledDraftOrder, mergedOrder, nextOrder, _nextOrder$order_id3, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
2105
2124
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2106
2125
  while (1) switch (_context18.prev = _context18.next) {
2107
2126
  case 0:
@@ -2168,10 +2187,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2168
2187
  memoryDraftCount: memoryDraftMap.size,
2169
2188
  sqliteOnlyDraftCount: draftMap.size - memoryDraftMap.size
2170
2189
  });
2190
+ storageKeyMigrations = [];
2171
2191
  mergeActions = {};
2172
2192
  updatedList = this.store.list.filter(function (order) {
2173
2193
  return _this12.shouldKeepOrderInMemory(order);
2174
2194
  });
2195
+ previousStorageKeys = updatedList.map(function (order) {
2196
+ return _this12.getPersistedOrderStorageKey(order);
2197
+ });
2175
2198
  identityKeyToIndex = new Map();
2176
2199
  for (index = 0; index < updatedList.length; index += 1) {
2177
2200
  _iterator11 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
@@ -2187,20 +2210,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2187
2210
  }
2188
2211
  }
2189
2212
  _iterator12 = _createForOfIteratorHelper(memoryDraftMap.entries());
2190
- _context18.prev = 36;
2213
+ _context18.prev = 38;
2191
2214
  _iterator12.s();
2192
- case 38:
2215
+ case 40:
2193
2216
  if ((_step12 = _iterator12.n()).done) {
2194
- _context18.next = 58;
2217
+ _context18.next = 62;
2195
2218
  break;
2196
2219
  }
2197
2220
  _step12$value = _slicedToArray(_step12.value, 2), _storageKey2 = _step12$value[0], _draftOrder = _step12$value[1];
2198
- matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
2221
+ matchIndex = this.findLocalOrderIndexByIdentity(identityKeyToIndex, updatedList, _draftOrder);
2199
2222
  if (!(matchIndex >= 0)) {
2200
- _context18.next = 52;
2223
+ _context18.next = 56;
2201
2224
  break;
2202
2225
  }
2203
2226
  existingOrder = updatedList[matchIndex];
2227
+ previousStorageKey = previousStorageKeys[matchIndex];
2204
2228
  reconciledDraftOrder = this.preserveExistingBusinessCodeForDraft(existingOrder, _draftOrder);
2205
2229
  this.applyHolderRelationsSnapshot(reconciledDraftOrder, existingOrder, _draftOrder);
2206
2230
  mergedOrder = this.mergeOrderRecords(existingOrder, reconciledDraftOrder);
@@ -2208,51 +2232,60 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2208
2232
  need_sync: 0,
2209
2233
  is_draft_order: 1
2210
2234
  });
2235
+ if (previousStorageKey && previousStorageKey !== _storageKey2) {
2236
+ storageKeyMigrations.push({
2237
+ orderId: (_nextOrder$order_id3 = nextOrder.order_id) !== null && _nextOrder$order_id3 !== void 0 ? _nextOrder$order_id3 : null,
2238
+ from: previousStorageKey,
2239
+ to: _storageKey2
2240
+ });
2241
+ delete nextOrder[ORDER_STORAGE_KEY_FIELD];
2242
+ }
2211
2243
  updatedList[matchIndex] = nextOrder;
2212
2244
  // SQLite 必须与内存中的草稿保持同一份 business_code,避免下次 hydrate 再次丢失分类。
2213
2245
  draftMap.set(_storageKey2, reconciledDraftOrder);
2214
2246
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
2215
2247
  mergeActions[_storageKey2] = 'update';
2216
- return _context18.abrupt("continue", 56);
2217
- case 52:
2248
+ return _context18.abrupt("continue", 60);
2249
+ case 56:
2218
2250
  insertIndex = updatedList.length;
2219
2251
  updatedList.push(_draftOrder);
2220
2252
  this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
2221
2253
  mergeActions[_storageKey2] = 'insert';
2222
- case 56:
2223
- _context18.next = 38;
2254
+ case 60:
2255
+ _context18.next = 40;
2224
2256
  break;
2225
- case 58:
2226
- _context18.next = 63;
2257
+ case 62:
2258
+ _context18.next = 67;
2227
2259
  break;
2228
- case 60:
2229
- _context18.prev = 60;
2230
- _context18.t1 = _context18["catch"](36);
2260
+ case 64:
2261
+ _context18.prev = 64;
2262
+ _context18.t1 = _context18["catch"](38);
2231
2263
  _iterator12.e(_context18.t1);
2232
- case 63:
2233
- _context18.prev = 63;
2264
+ case 67:
2265
+ _context18.prev = 67;
2234
2266
  _iterator12.f();
2235
- return _context18.finish(63);
2236
- case 66:
2267
+ return _context18.finish(67);
2268
+ case 70:
2237
2269
  patchedOrders = _toConsumableArray(draftMap.values());
2238
2270
  previousList = this.store.list;
2239
2271
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
2240
2272
  this.syncOrdersMap();
2241
- _context18.prev = 70;
2242
- _context18.next = 73;
2273
+ _context18.prev = 74;
2274
+ _context18.next = 77;
2243
2275
  return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
2244
- throwOnError: true
2276
+ throwOnError: true,
2277
+ storageKeyMigrations: storageKeyMigrations
2245
2278
  });
2246
- case 73:
2247
- _context18.next = 80;
2279
+ case 77:
2280
+ _context18.next = 84;
2248
2281
  break;
2249
- case 75:
2250
- _context18.prev = 75;
2251
- _context18.t2 = _context18["catch"](70);
2282
+ case 79:
2283
+ _context18.prev = 79;
2284
+ _context18.t2 = _context18["catch"](74);
2252
2285
  this.store.list = previousList;
2253
2286
  this.syncOrdersMap();
2254
2287
  throw _context18.t2;
2255
- case 80:
2288
+ case 84:
2256
2289
  this.logInfo('upsertLocalDraftOrders-结束', {
2257
2290
  count: patchedOrders.length,
2258
2291
  storeOrderCountAfter: this.store.list.length
@@ -2261,18 +2294,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2261
2294
  return !_this12.shouldKeepOrderInMemory(order);
2262
2295
  });
2263
2296
  if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
2264
- _context18.next = 85;
2297
+ _context18.next = 89;
2265
2298
  break;
2266
2299
  }
2267
- _context18.next = 85;
2300
+ _context18.next = 89;
2268
2301
  return this.emitOrdersChanged(patchedOrders.filter(function (order) {
2269
2302
  return _this12.shouldKeepOrderInMemory(order);
2270
2303
  }), 'upsertLocalDraftOrders');
2271
- case 85:
2304
+ case 89:
2272
2305
  case "end":
2273
2306
  return _context18.stop();
2274
2307
  }
2275
- }, _callee18, this, [[6, 21, 24, 27], [36, 60, 63, 66], [70, 75]]);
2308
+ }, _callee18, this, [[6, 21, 24, 27], [38, 64, 67, 70], [74, 79]]);
2276
2309
  }));
2277
2310
  function upsertLocalDraftOrders(_x14) {
2278
2311
  return _upsertLocalDraftOrders.apply(this, arguments);
@@ -3346,6 +3379,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3346
3379
  }
3347
3380
  return this.getOrderStorageKey(order);
3348
3381
  }
3382
+ }, {
3383
+ key: "getRealOrderId",
3384
+ value: function getRealOrderId(order) {
3385
+ if (this.isBlankIdentityValue(order.order_id)) return '';
3386
+ if (String(order.order_id) === String(order.external_sale_number)) return '';
3387
+ return String(order.order_id);
3388
+ }
3389
+ }, {
3390
+ key: "findLocalOrderIndexByIdentity",
3391
+ value: function findLocalOrderIndexByIdentity(identityKeyToIndex, orders, target) {
3392
+ var _indexes$find,
3393
+ _this21 = this;
3394
+ var id = this.getRealOrderId(target);
3395
+ var keys = id ? ["order_id:".concat(id)] : [];
3396
+ if (!this.isBlankIdentityValue(target.external_sale_number)) {
3397
+ keys.push("external_sale_number:".concat(target.external_sale_number));
3398
+ }
3399
+ var indexes = keys.map(function (key) {
3400
+ return identityKeyToIndex.get(key);
3401
+ }).filter(function (index) {
3402
+ return index !== undefined;
3403
+ }).sort(function (left, right) {
3404
+ return left - right;
3405
+ });
3406
+ return (_indexes$find = indexes.find(function (index) {
3407
+ var existingId = _this21.getRealOrderId(orders[index]);
3408
+ return !id || !existingId || id === existingId;
3409
+ })) !== null && _indexes$find !== void 0 ? _indexes$find : -1;
3410
+ }
3349
3411
  }, {
3350
3412
  key: "getOrderIdentityMatchKeys",
3351
3413
  value: function getOrderIdentityMatchKeys(order) {
@@ -3365,10 +3427,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3365
3427
  }, {
3366
3428
  key: "findOrderIndexByIdentity",
3367
3429
  value: function findOrderIndexByIdentity(orders, target) {
3368
- var _this21 = this;
3430
+ var _this22 = this;
3369
3431
  if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
3370
3432
  return orders.findIndex(function (order) {
3371
- return _this21.doOrdersShareIdentity(order, target);
3433
+ return _this22.doOrdersShareIdentity(order, target);
3372
3434
  });
3373
3435
  }
3374
3436
  }, {
@@ -3525,7 +3587,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3525
3587
  }, {
3526
3588
  key: "preserveOmittedHolderRelations",
3527
3589
  value: function preserveOmittedHolderRelations(incomingOrders, existingOrders) {
3528
- var _this22 = this;
3590
+ var _this23 = this;
3529
3591
  var existingByIdentity = new Map();
3530
3592
  var _iterator29 = _createForOfIteratorHelper(existingOrders),
3531
3593
  _step29;
@@ -3553,12 +3615,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3553
3615
  }
3554
3616
  return incomingOrders.map(function (order) {
3555
3617
  if (Array.isArray(order.holder_relations)) return order;
3556
- var existingOrder = _this22.getOrderIdentityMatchKeys(order).map(function (key) {
3618
+ var existingOrder = _this23.getOrderIdentityMatchKeys(order).map(function (key) {
3557
3619
  return existingByIdentity.get(key);
3558
3620
  }).find(Boolean);
3559
3621
  if (!existingOrder) return order;
3560
3622
  var nextOrder = _objectSpread({}, order);
3561
- _this22.applyHolderRelationsSnapshot(nextOrder, existingOrder, order);
3623
+ _this23.applyHolderRelationsSnapshot(nextOrder, existingOrder, order);
3562
3624
  return nextOrder;
3563
3625
  });
3564
3626
  }
@@ -3858,67 +3920,398 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3858
3920
  }, {
3859
3921
  key: "loadOrdersFromSQLite",
3860
3922
  value: function () {
3861
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
3862
- var _this23 = this;
3923
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
3924
+ var _this24 = this;
3863
3925
  var options,
3864
- _options$onTiming,
3865
3926
  loadStartedAt,
3866
- rawReadStartedAt,
3867
- orders,
3868
- sqliteRawReadMs,
3869
- normalizeStartedAt,
3927
+ memoryBeforeLoad,
3870
3928
  normalizedOrders,
3871
- sqliteNormalizeMs,
3872
- _args24 = arguments;
3873
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3874
- while (1) switch (_context24.prev = _context24.next) {
3929
+ previousOrders,
3930
+ protectedMemoryOrders,
3931
+ _args25 = arguments;
3932
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3933
+ while (1) switch (_context25.prev = _context25.next) {
3875
3934
  case 0:
3876
- options = _args24.length > 0 && _args24[0] !== undefined ? _args24[0] : {};
3935
+ options = _args25.length > 0 && _args25[0] !== undefined ? _args25[0] : {};
3877
3936
  if (this.dbManager) {
3878
- _context24.next = 3;
3937
+ _context25.next = 3;
3879
3938
  break;
3880
3939
  }
3881
- return _context24.abrupt("return", []);
3940
+ return _context25.abrupt("return", []);
3882
3941
  case 3:
3883
- _context24.prev = 3;
3942
+ _context25.prev = 3;
3884
3943
  loadStartedAt = performance.now();
3885
- rawReadStartedAt = performance.now();
3886
- _context24.next = 8;
3887
- return this.dbManager.getAll(INDEXDB_STORE_NAME);
3888
- case 8:
3889
- orders = _context24.sent;
3890
- sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3891
- normalizeStartedAt = performance.now();
3892
- normalizedOrders = (orders || []).map(function (order) {
3893
- return _this23.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3894
- });
3895
- sqliteNormalizeMs = +(performance.now() - normalizeStartedAt).toFixed(2);
3896
- (_options$onTiming = options.onTiming) === null || _options$onTiming === void 0 || _options$onTiming.call(options, {
3897
- sqliteRawReadMs: sqliteRawReadMs,
3898
- sqliteNormalizeMs: sqliteNormalizeMs,
3899
- sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
3900
- });
3901
- return _context24.abrupt("return", normalizedOrders);
3902
- case 17:
3903
- _context24.prev = 17;
3904
- _context24.t0 = _context24["catch"](3);
3944
+ memoryBeforeLoad = this.store.list;
3945
+ normalizedOrders = []; // 读修复与普通订单写入共用队列,避免用排队前的旧快照覆盖新的待同步订单。
3946
+ _context25.next = 9;
3947
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
3948
+ var _options$onTiming;
3949
+ var rawReadStartedAt, orders, sqliteRawReadMs, normalizeStartedAt, _this24$deduplicateSt, list, repairs, obsoleteKeys, sqliteNormalizeMs, _iterator34, _step34, key;
3950
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3951
+ while (1) switch (_context24.prev = _context24.next) {
3952
+ case 0:
3953
+ rawReadStartedAt = performance.now();
3954
+ _context24.next = 3;
3955
+ return _this24.dbManager.getAll(INDEXDB_STORE_NAME);
3956
+ case 3:
3957
+ orders = _context24.sent;
3958
+ sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3959
+ normalizeStartedAt = performance.now();
3960
+ _this24$deduplicateSt = _this24.deduplicateStoredOrders(orders || []), list = _this24$deduplicateSt.list, repairs = _this24$deduplicateSt.repairs, obsoleteKeys = _this24$deduplicateSt.obsoleteKeys;
3961
+ normalizedOrders = list;
3962
+ sqliteNormalizeMs = +(performance.now() - normalizeStartedAt).toFixed(2);
3963
+ if (!(repairs.length > 0)) {
3964
+ _context24.next = 38;
3965
+ break;
3966
+ }
3967
+ _context24.prev = 10;
3968
+ _context24.next = 13;
3969
+ return _this24.writeOrderRowsToSQLite(repairs);
3970
+ case 13:
3971
+ _this24.recordRecentSqliteWrite('loadOrdersFromSQLite.deduplicate', repairs);
3972
+ _iterator34 = _createForOfIteratorHelper(obsoleteKeys);
3973
+ _context24.prev = 15;
3974
+ _iterator34.s();
3975
+ case 17:
3976
+ if ((_step34 = _iterator34.n()).done) {
3977
+ _context24.next = 24;
3978
+ break;
3979
+ }
3980
+ key = _step34.value;
3981
+ _context24.next = 21;
3982
+ return _this24.dbManager.delete(INDEXDB_STORE_NAME, key);
3983
+ case 21:
3984
+ _this24.recentSqliteWriteByStorageKey.delete(key);
3985
+ case 22:
3986
+ _context24.next = 17;
3987
+ break;
3988
+ case 24:
3989
+ _context24.next = 29;
3990
+ break;
3991
+ case 26:
3992
+ _context24.prev = 26;
3993
+ _context24.t0 = _context24["catch"](15);
3994
+ _iterator34.e(_context24.t0);
3995
+ case 29:
3996
+ _context24.prev = 29;
3997
+ _iterator34.f();
3998
+ return _context24.finish(29);
3999
+ case 32:
4000
+ _this24.logInfo('SQLite重复订单已修复', {
4001
+ beforeCount: orders.length,
4002
+ afterCount: list.length,
4003
+ repairedCount: repairs.length,
4004
+ deletedKeyCount: obsoleteKeys.size
4005
+ });
4006
+ _context24.next = 38;
4007
+ break;
4008
+ case 35:
4009
+ _context24.prev = 35;
4010
+ _context24.t1 = _context24["catch"](10);
4011
+ // 本次仍使用去重后的内存快照;保留磁盘记录,后续读取可重试修复。
4012
+ _this24.logError('SQLite重复订单修复写入失败', {
4013
+ error: _context24.t1 instanceof Error ? _context24.t1.message : String(_context24.t1),
4014
+ repairedCount: repairs.length
4015
+ });
4016
+ case 38:
4017
+ (_options$onTiming = options.onTiming) === null || _options$onTiming === void 0 || _options$onTiming.call(options, {
4018
+ sqliteRawReadMs: sqliteRawReadMs,
4019
+ sqliteNormalizeMs: sqliteNormalizeMs,
4020
+ sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
4021
+ });
4022
+ case 39:
4023
+ case "end":
4024
+ return _context24.stop();
4025
+ }
4026
+ }, _callee24, null, [[10, 35], [15, 26, 29, 32]]);
4027
+ })));
4028
+ case 9:
4029
+ if (this.store.list !== memoryBeforeLoad) {
4030
+ // 读取期间可能已开始新的本地结账;回灌不能抹掉尚在排队落库的修改。
4031
+ previousOrders = new Map(memoryBeforeLoad.map(function (order) {
4032
+ return [_this24.getOrderStorageKey(order), order];
4033
+ }));
4034
+ protectedMemoryOrders = this.store.list.filter(function (order) {
4035
+ return _this24.shouldProtectLocalOrderFromRemoteSnapshot(order) && !isEqual(previousOrders.get(_this24.getOrderStorageKey(order)), order);
4036
+ });
4037
+ normalizedOrders = this.deduplicateStoredOrders([].concat(_toConsumableArray(normalizedOrders), _toConsumableArray(protectedMemoryOrders)), new Set(protectedMemoryOrders)).list;
4038
+ }
4039
+ return _context25.abrupt("return", normalizedOrders);
4040
+ case 13:
4041
+ _context25.prev = 13;
4042
+ _context25.t0 = _context25["catch"](3);
3905
4043
  if (!options.throwOnError) {
3906
- _context24.next = 21;
4044
+ _context25.next = 17;
3907
4045
  break;
3908
4046
  }
3909
- throw _context24.t0;
3910
- case 21:
3911
- return _context24.abrupt("return", []);
3912
- case 22:
4047
+ throw _context25.t0;
4048
+ case 17:
4049
+ return _context25.abrupt("return", []);
4050
+ case 18:
3913
4051
  case "end":
3914
- return _context24.stop();
4052
+ return _context25.stop();
3915
4053
  }
3916
- }, _callee24, this, [[3, 17]]);
4054
+ }, _callee25, this, [[3, 13]]);
3917
4055
  }));
3918
4056
  function loadOrdersFromSQLite() {
3919
4057
  return _loadOrdersFromSQLite.apply(this, arguments);
3920
4058
  }
3921
4059
  return loadOrdersFromSQLite;
4060
+ }() /** 历史记录只按真实订单 ID / 唯一本地编号归组,不使用桌号或小票短号。 */
4061
+ }, {
4062
+ key: "deduplicateStoredOrders",
4063
+ value: function deduplicateStoredOrders(orders) {
4064
+ var _this25 = this;
4065
+ var authoritativeOrders = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Set();
4066
+ var idsByExternal = new Map();
4067
+ var _iterator35 = _createForOfIteratorHelper(orders),
4068
+ _step35;
4069
+ try {
4070
+ for (_iterator35.s(); !(_step35 = _iterator35.n()).done;) {
4071
+ var order = _step35.value;
4072
+ var id = this.getRealOrderId(order);
4073
+ var external = order.external_sale_number;
4074
+ if (!id || this.isBlankIdentityValue(external)) continue;
4075
+ var key = String(external);
4076
+ var previous = idsByExternal.get(key);
4077
+ idsByExternal.set(key, previous === undefined || previous === id ? id : null);
4078
+ }
4079
+ } catch (err) {
4080
+ _iterator35.e(err);
4081
+ } finally {
4082
+ _iterator35.f();
4083
+ }
4084
+ var groups = new Map();
4085
+ var _iterator36 = _createForOfIteratorHelper(orders.entries()),
4086
+ _step36;
4087
+ try {
4088
+ for (_iterator36.s(); !(_step36 = _iterator36.n()).done;) {
4089
+ var _step36$value = _slicedToArray(_step36.value, 2),
4090
+ index = _step36$value[0],
4091
+ rawOrder = _step36$value[1];
4092
+ var _external = this.isBlankIdentityValue(rawOrder.external_sale_number) ? '' : String(rawOrder.external_sale_number);
4093
+ var _id = this.getRealOrderId(rawOrder) || _external && idsByExternal.get(_external);
4094
+ var identity = _id ? "id:".concat(_id) : _external ? "external:".concat(_external) : "row:".concat(index);
4095
+ var storageKey = this.getPersistedOrderStorageKey(rawOrder);
4096
+ var _order = this.normalizeOrderCollectionsForIngress(rawOrder, 'loadOrdersFromSQLite');
4097
+ var group = groups.get(identity);
4098
+ if (group) {
4099
+ group.order = this.mergeStoredOrderCopies(group.order, _order, authoritativeOrders.has(rawOrder));
4100
+ group.keys.add(storageKey);
4101
+ group.count += 1;
4102
+ } else {
4103
+ groups.set(identity, {
4104
+ order: _order,
4105
+ keys: new Set([storageKey]),
4106
+ count: 1
4107
+ });
4108
+ }
4109
+ }
4110
+ } catch (err) {
4111
+ _iterator36.e(err);
4112
+ } finally {
4113
+ _iterator36.f();
4114
+ }
4115
+ var canonicalKeyCounts = new Map();
4116
+ var _iterator37 = _createForOfIteratorHelper(groups.values()),
4117
+ _step37;
4118
+ try {
4119
+ for (_iterator37.s(); !(_step37 = _iterator37.n()).done;) {
4120
+ var _order2 = _step37.value.order;
4121
+ var _key4 = this.getOrderStorageKey(_order2);
4122
+ canonicalKeyCounts.set(_key4, (canonicalKeyCounts.get(_key4) || 0) + 1);
4123
+ }
4124
+ } catch (err) {
4125
+ _iterator37.e(err);
4126
+ } finally {
4127
+ _iterator37.f();
4128
+ }
4129
+ var list = [];
4130
+ var repairs = [];
4131
+ var obsoleteKeys = new Set();
4132
+ var _iterator38 = _createForOfIteratorHelper(groups.values()),
4133
+ _step38;
4134
+ try {
4135
+ var _loop3 = function _loop3() {
4136
+ var group = _step38.value;
4137
+ var key = _this25.getOrderStorageKey(group.order);
4138
+ var needsRepair = group.count > 1 || _toConsumableArray(group.keys).some(function (oldKey) {
4139
+ return oldKey !== key;
4140
+ });
4141
+ // 不同真实订单若错误地共用 external 编号,不允许修复写入互相覆盖。
4142
+ if (needsRepair && key && canonicalKeyCounts.get(key) === 1) {
4143
+ group.order = _objectSpread(_objectSpread({}, group.order), {}, _defineProperty({}, ORDER_STORAGE_KEY_FIELD, key));
4144
+ repairs.push(group.order);
4145
+ var _iterator39 = _createForOfIteratorHelper(group.keys),
4146
+ _step39;
4147
+ try {
4148
+ for (_iterator39.s(); !(_step39 = _iterator39.n()).done;) {
4149
+ var oldKey = _step39.value;
4150
+ if (oldKey && oldKey !== key && !canonicalKeyCounts.has(oldKey)) obsoleteKeys.add(oldKey);
4151
+ }
4152
+ } catch (err) {
4153
+ _iterator39.e(err);
4154
+ } finally {
4155
+ _iterator39.f();
4156
+ }
4157
+ }
4158
+ list.push(group.order);
4159
+ };
4160
+ for (_iterator38.s(); !(_step38 = _iterator38.n()).done;) {
4161
+ _loop3();
4162
+ }
4163
+ } catch (err) {
4164
+ _iterator38.e(err);
4165
+ } finally {
4166
+ _iterator38.f();
4167
+ }
4168
+ return {
4169
+ list: list,
4170
+ repairs: repairs,
4171
+ obsoleteKeys: obsoleteKeys
4172
+ };
4173
+ }
4174
+ }, {
4175
+ key: "mergeStoredOrderCopies",
4176
+ value: function mergeStoredOrderCopies(left, right) {
4177
+ var _this26 = this;
4178
+ var preferIncoming = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
4179
+ var priority = function priority(order) {
4180
+ return _this26.isPendingSyncOrder(order) ? 2 : _this26.isDraftOrder(order) ? 1 : 0;
4181
+ };
4182
+ var leftHasExternal = !this.isBlankIdentityValue(left.external_sale_number);
4183
+ var rightHasExternal = !this.isBlankIdentityValue(right.external_sale_number);
4184
+ var preferred = leftHasExternal !== rightHasExternal ? leftHasExternal ? left : right : this.pickPreferredOrder(left, right);
4185
+ if (preferIncoming) {
4186
+ preferred = right;
4187
+ } else if (priority(left) !== priority(right)) {
4188
+ preferred = priority(left) > priority(right) ? left : right;
4189
+ } else {
4190
+ var _iterator40 = _createForOfIteratorHelper(['updated_at', 'created_at']),
4191
+ _step40;
4192
+ try {
4193
+ var _loop4 = function _loop4() {
4194
+ var field = _step40.value;
4195
+ var timestamp = function timestamp(order) {
4196
+ var value = order[field];
4197
+ if (!value) return 0;
4198
+ var parsed = dayjs(value);
4199
+ return parsed.isValid() ? parsed.valueOf() : 0;
4200
+ };
4201
+ if (timestamp(left) === timestamp(right)) return 0; // continue
4202
+ preferred = timestamp(left) > timestamp(right) ? left : right;
4203
+ return 1; // break
4204
+ },
4205
+ _ret2;
4206
+ for (_iterator40.s(); !(_step40 = _iterator40.n()).done;) {
4207
+ _ret2 = _loop4();
4208
+ if (_ret2 === 0) continue;
4209
+ if (_ret2 === 1) break;
4210
+ }
4211
+ } catch (err) {
4212
+ _iterator40.e(err);
4213
+ } finally {
4214
+ _iterator40.f();
4215
+ }
4216
+ }
4217
+ var secondary = preferred === left ? right : left;
4218
+ // 复用集合合并中的 pending/finalized 支付保护,但完整业务快照以胜者为准。
4219
+ var reconciled = this.mergeOrderRecords(secondary, preferred);
4220
+ var merged = _objectSpread(_objectSpread({}, reconciled), cloneDeep(preferred));
4221
+ var realOrder = this.getRealOrderId(preferred) ? preferred : secondary;
4222
+ if (this.getRealOrderId(realOrder)) merged.order_id = realOrder.order_id;
4223
+ var _iterator41 = _createForOfIteratorHelper(this.getOrderIdentityEntries(reconciled)),
4224
+ _step41;
4225
+ try {
4226
+ for (_iterator41.s(); !(_step41 = _iterator41.n()).done;) {
4227
+ var _field3 = _step41.value.field;
4228
+ if (this.isBlankIdentityValue(merged[_field3])) merged[_field3] = reconciled[_field3];
4229
+ }
4230
+ } catch (err) {
4231
+ _iterator41.e(err);
4232
+ } finally {
4233
+ _iterator41.f();
4234
+ }
4235
+ for (var _i8 = 0, _ORDER_AUTHORITATIVE_3 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i8 < _ORDER_AUTHORITATIVE_3.length; _i8++) {
4236
+ var field = _ORDER_AUTHORITATIVE_3[_i8];
4237
+ if (Object.prototype.hasOwnProperty.call(reconciled, field)) merged[field] = reconciled[field];
4238
+ }
4239
+ if (requiresLocalPaymentRefresh(secondary)) {
4240
+ merged.metadata = _objectSpread(_objectSpread({}, merged.metadata), {}, _defineProperty({}, LOCAL_EFTPOS_REFRESH_REQUIRED, true));
4241
+ }
4242
+ merged.need_sync = this.isPendingSyncOrder(left) || this.isPendingSyncOrder(right) ? 1 : 0;
4243
+ merged.is_draft_order = this.isDraftOrder(preferred) ? 1 : 0;
4244
+ return merged;
4245
+ }
4246
+ }, {
4247
+ key: "writeOrderRowsToSQLite",
4248
+ value: function () {
4249
+ var _writeOrderRowsToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(orders) {
4250
+ var _iterator42, _step42, order;
4251
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4252
+ while (1) switch (_context26.prev = _context26.next) {
4253
+ case 0:
4254
+ if (!(typeof this.dbManager.bulkUpdate === 'function')) {
4255
+ _context26.next = 4;
4256
+ break;
4257
+ }
4258
+ _context26.next = 3;
4259
+ return this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, orders);
4260
+ case 3:
4261
+ return _context26.abrupt("return", 'bulkUpdate');
4262
+ case 4:
4263
+ if (!(typeof this.dbManager.bulkAdd === 'function')) {
4264
+ _context26.next = 8;
4265
+ break;
4266
+ }
4267
+ _context26.next = 7;
4268
+ return this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orders);
4269
+ case 7:
4270
+ return _context26.abrupt("return", 'bulkAdd');
4271
+ case 8:
4272
+ if (!(typeof this.dbManager.update === 'function')) {
4273
+ _context26.next = 27;
4274
+ break;
4275
+ }
4276
+ _iterator42 = _createForOfIteratorHelper(orders);
4277
+ _context26.prev = 10;
4278
+ _iterator42.s();
4279
+ case 12:
4280
+ if ((_step42 = _iterator42.n()).done) {
4281
+ _context26.next = 18;
4282
+ break;
4283
+ }
4284
+ order = _step42.value;
4285
+ _context26.next = 16;
4286
+ return this.dbManager.update(INDEXDB_STORE_NAME, order);
4287
+ case 16:
4288
+ _context26.next = 12;
4289
+ break;
4290
+ case 18:
4291
+ _context26.next = 23;
4292
+ break;
4293
+ case 20:
4294
+ _context26.prev = 20;
4295
+ _context26.t0 = _context26["catch"](10);
4296
+ _iterator42.e(_context26.t0);
4297
+ case 23:
4298
+ _context26.prev = 23;
4299
+ _iterator42.f();
4300
+ return _context26.finish(23);
4301
+ case 26:
4302
+ return _context26.abrupt("return", 'update');
4303
+ case 27:
4304
+ throw new Error('订单 SQLite 数据库不支持写入');
4305
+ case 28:
4306
+ case "end":
4307
+ return _context26.stop();
4308
+ }
4309
+ }, _callee26, this, [[10, 20, 23, 26]]);
4310
+ }));
4311
+ function writeOrderRowsToSQLite(_x18) {
4312
+ return _writeOrderRowsToSQLite.apply(this, arguments);
4313
+ }
4314
+ return writeOrderRowsToSQLite;
3922
4315
  }()
3923
4316
  }, {
3924
4317
  key: "isPendingSyncOrder",
@@ -3952,8 +4345,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3952
4345
  value: function mergeRemoteIdentityIntoDraftOrder(draftOrder, remoteOrder) {
3953
4346
  var merged = _objectSpread({}, this.withoutSyntheticDraftOrderId(draftOrder));
3954
4347
  var remote = remoteOrder;
3955
- for (var _i8 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i8 < _arr.length; _i8++) {
3956
- var field = _arr[_i8];
4348
+ for (var _i9 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i9 < _arr.length; _i9++) {
4349
+ var field = _arr[_i9];
3957
4350
  if (this.isBlankIdentityValue(merged[field]) && !this.isBlankIdentityValue(remote[field])) {
3958
4351
  merged[field] = remote[field];
3959
4352
  }
@@ -3963,15 +4356,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3963
4356
  }, {
3964
4357
  key: "mergeRemoteSnapshotWithPendingOrders",
3965
4358
  value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
3966
- var _this24 = this;
4359
+ var _this27 = this;
3967
4360
  var merged = remoteOrders.map(function (order) {
3968
- return _this24.normalizeRemoteSyncedOrder(order);
4361
+ return _this27.normalizeRemoteSyncedOrder(order);
3969
4362
  });
3970
- var _iterator34 = _createForOfIteratorHelper(existingOrders),
3971
- _step34;
4363
+ var _iterator43 = _createForOfIteratorHelper(existingOrders),
4364
+ _step43;
3972
4365
  try {
3973
- for (_iterator34.s(); !(_step34 = _iterator34.n()).done;) {
3974
- var rawOrder = _step34.value;
4366
+ for (_iterator43.s(); !(_step43 = _iterator43.n()).done;) {
4367
+ var rawOrder = _step43.value;
3975
4368
  var order = this.normalizeOrderCollectionsForIngress(rawOrder, 'mergeRemoteSnapshotWithPendingOrders.existingSQLite');
3976
4369
  if (!this.shouldProtectLocalOrderFromRemoteSnapshot(order)) continue;
3977
4370
  var matchIndex = this.findOrderIndexByIdentity(merged, order);
@@ -3987,9 +4380,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3987
4380
  merged.push(order);
3988
4381
  }
3989
4382
  } catch (err) {
3990
- _iterator34.e(err);
4383
+ _iterator43.e(err);
3991
4384
  } finally {
3992
- _iterator34.f();
4385
+ _iterator43.f();
3993
4386
  }
3994
4387
  return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
3995
4388
  }
@@ -4005,10 +4398,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4005
4398
  }, {
4006
4399
  key: "runInOrderSQLiteSaveQueue",
4007
4400
  value: (function () {
4008
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(task) {
4401
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(task) {
4009
4402
  var queuedTask;
4010
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4011
- while (1) switch (_context25.prev = _context25.next) {
4403
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4404
+ while (1) switch (_context27.prev = _context27.next) {
4012
4405
  case 0:
4013
4406
  queuedTask = this.orderSQLiteSaveQueue.then(task, task);
4014
4407
  this.orderSQLiteSaveQueue = queuedTask.then(function () {
@@ -4016,14 +4409,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4016
4409
  }, function () {
4017
4410
  return undefined;
4018
4411
  });
4019
- return _context25.abrupt("return", queuedTask);
4412
+ return _context27.abrupt("return", queuedTask);
4020
4413
  case 3:
4021
4414
  case "end":
4022
- return _context25.stop();
4415
+ return _context27.stop();
4023
4416
  }
4024
- }, _callee25, this);
4417
+ }, _callee27, this);
4025
4418
  }));
4026
- function runInOrderSQLiteSaveQueue(_x18) {
4419
+ function runInOrderSQLiteSaveQueue(_x19) {
4027
4420
  return _runInOrderSQLiteSaveQueue.apply(this, arguments);
4028
4421
  }
4029
4422
  return runInOrderSQLiteSaveQueue;
@@ -4038,8 +4431,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4038
4431
  }, {
4039
4432
  key: "patchOrdersInSQLite",
4040
4433
  value: (function () {
4041
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orders, source) {
4042
- var _this25 = this;
4434
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(orders, source) {
4435
+ var _this28 = this;
4043
4436
  var mergeActions,
4044
4437
  options,
4045
4438
  forceWriteStorageKeys,
@@ -4051,300 +4444,242 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4051
4444
  compactedToWrite,
4052
4445
  writtenStorageKeys,
4053
4446
  storageKeyMigrations,
4054
- _iterator35,
4055
- _step35,
4447
+ _iterator44,
4448
+ _step44,
4056
4449
  migration,
4057
- _args27 = arguments;
4058
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4059
- while (1) switch (_context27.prev = _context27.next) {
4450
+ _args29 = arguments;
4451
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4452
+ while (1) switch (_context29.prev = _context29.next) {
4060
4453
  case 0:
4061
- mergeActions = _args27.length > 2 && _args27[2] !== undefined ? _args27[2] : {};
4062
- options = _args27.length > 3 && _args27[3] !== undefined ? _args27[3] : {};
4063
- forceWriteStorageKeys = _args27.length > 4 && _args27[4] !== undefined ? _args27[4] : new Set();
4454
+ mergeActions = _args29.length > 2 && _args29[2] !== undefined ? _args29[2] : {};
4455
+ options = _args29.length > 3 && _args29[3] !== undefined ? _args29[3] : {};
4456
+ forceWriteStorageKeys = _args29.length > 4 && _args29[4] !== undefined ? _args29[4] : new Set();
4064
4457
  if (!(orders.length === 0)) {
4065
- _context27.next = 5;
4458
+ _context29.next = 5;
4066
4459
  break;
4067
4460
  }
4068
- return _context27.abrupt("return");
4461
+ return _context29.abrupt("return");
4069
4462
  case 5:
4070
4463
  if (this.dbManager) {
4071
- _context27.next = 9;
4464
+ _context29.next = 9;
4072
4465
  break;
4073
4466
  }
4074
4467
  if (!options.throwOnError) {
4075
- _context27.next = 8;
4468
+ _context29.next = 8;
4076
4469
  break;
4077
4470
  }
4078
4471
  throw new Error('订单 SQLite 数据库未初始化');
4079
4472
  case 8:
4080
- return _context27.abrupt("return");
4473
+ return _context29.abrupt("return");
4081
4474
  case 9:
4082
4475
  migrationTargetStorageKeys = new Set((options.storageKeyMigrations || []).map(function (migration) {
4083
4476
  return migration.to;
4084
4477
  }));
4085
4478
  ordersSnapshot = cloneDeep(orders).map(function (order) {
4086
- return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
4479
+ return _this28.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
4087
4480
  }).map(function (order) {
4088
- var storageKey = _this25.getOrderStorageKey(order);
4481
+ var storageKey = _this28.getOrderStorageKey(order);
4089
4482
  if (!storageKey || !migrationTargetStorageKeys.has(storageKey)) return order;
4090
4483
  return _objectSpread(_objectSpread({}, order), {}, _defineProperty({}, ORDER_STORAGE_KEY_FIELD, storageKey));
4091
4484
  }).filter(function (order) {
4092
- return _this25.getOrderStorageKey(order);
4485
+ return _this28.getOrderStorageKey(order);
4093
4486
  });
4094
4487
  if (!(ordersSnapshot.length === 0)) {
4095
- _context27.next = 13;
4488
+ _context29.next = 13;
4096
4489
  break;
4097
4490
  }
4098
- return _context27.abrupt("return");
4491
+ return _context29.abrupt("return");
4099
4492
  case 13:
4100
- _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
4493
+ _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, new Set([].concat(_toConsumableArray(forceWriteStorageKeys), _toConsumableArray(migrationTargetStorageKeys)))), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
4101
4494
  if (!(toWrite.length === 0)) {
4102
- _context27.next = 16;
4495
+ _context29.next = 16;
4103
4496
  break;
4104
4497
  }
4105
- return _context27.abrupt("return");
4498
+ return _context29.abrupt("return");
4106
4499
  case 16:
4107
4500
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
4108
4501
  if (!(compactedToWrite.length === 0)) {
4109
- _context27.next = 19;
4502
+ _context29.next = 19;
4110
4503
  break;
4111
4504
  }
4112
- return _context27.abrupt("return");
4505
+ return _context29.abrupt("return");
4113
4506
  case 19:
4114
4507
  writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
4115
- return _this25.getOrderStorageKey(order);
4508
+ return _this28.getOrderStorageKey(order);
4116
4509
  }).filter(Boolean));
4117
4510
  storageKeyMigrations = new Map();
4118
- _iterator35 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
4119
- _context27.prev = 22;
4120
- _iterator35.s();
4511
+ _iterator44 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
4512
+ _context29.prev = 22;
4513
+ _iterator44.s();
4121
4514
  case 24:
4122
- if ((_step35 = _iterator35.n()).done) {
4123
- _context27.next = 33;
4515
+ if ((_step44 = _iterator44.n()).done) {
4516
+ _context29.next = 33;
4124
4517
  break;
4125
4518
  }
4126
- migration = _step35.value;
4519
+ migration = _step44.value;
4127
4520
  if (writtenStorageKeys.has(migration.to)) {
4128
- _context27.next = 28;
4521
+ _context29.next = 28;
4129
4522
  break;
4130
4523
  }
4131
- return _context27.abrupt("continue", 31);
4524
+ return _context29.abrupt("continue", 31);
4132
4525
  case 28:
4133
4526
  if (!writtenStorageKeys.has(migration.from)) {
4134
- _context27.next = 30;
4527
+ _context29.next = 30;
4135
4528
  break;
4136
4529
  }
4137
- return _context27.abrupt("continue", 31);
4530
+ return _context29.abrupt("continue", 31);
4138
4531
  case 30:
4139
4532
  storageKeyMigrations.set(migration.from, migration);
4140
4533
  case 31:
4141
- _context27.next = 24;
4534
+ _context29.next = 24;
4142
4535
  break;
4143
4536
  case 33:
4144
- _context27.next = 38;
4537
+ _context29.next = 38;
4145
4538
  break;
4146
4539
  case 35:
4147
- _context27.prev = 35;
4148
- _context27.t0 = _context27["catch"](22);
4149
- _iterator35.e(_context27.t0);
4540
+ _context29.prev = 35;
4541
+ _context29.t0 = _context29["catch"](22);
4542
+ _iterator44.e(_context29.t0);
4150
4543
  case 38:
4151
- _context27.prev = 38;
4152
- _iterator35.f();
4153
- return _context27.finish(38);
4544
+ _context29.prev = 38;
4545
+ _iterator44.f();
4546
+ return _context29.finish(38);
4154
4547
  case 41:
4155
- _context27.prev = 41;
4156
- _context27.next = 44;
4157
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
4158
- var writeMethod, _iterator36, _step36, order, _iterator37, _step37, migration, _iterator38, _step38, _orderRecord$ORDER_ST, _order, orderRecord;
4159
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4160
- while (1) switch (_context26.prev = _context26.next) {
4548
+ _context29.prev = 41;
4549
+ _context29.next = 44;
4550
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
4551
+ var writeMethod, _iterator45, _step45, migration, _iterator46, _step46, _orderRecord$ORDER_ST, order, orderRecord;
4552
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4553
+ while (1) switch (_context28.prev = _context28.next) {
4161
4554
  case 0:
4162
4555
  writeMethod = 'none';
4163
- _this25.logInfo('patchOrdersInSQLite-开始', {
4556
+ _this28.logInfo('patchOrdersInSQLite-开始', {
4164
4557
  source: source,
4165
4558
  count: compactedToWrite.length,
4166
4559
  dedupedCount: skipped.length
4167
4560
  });
4168
- if (!(typeof _this25.dbManager.bulkUpdate === 'function')) {
4169
- _context26.next = 8;
4170
- break;
4171
- }
4172
- writeMethod = 'bulkUpdate';
4173
- _context26.next = 6;
4174
- return _this25.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
4175
- case 6:
4176
- _context26.next = 37;
4177
- break;
4178
- case 8:
4179
- if (!(typeof _this25.dbManager.bulkAdd === 'function')) {
4180
- _context26.next = 14;
4181
- break;
4182
- }
4183
- writeMethod = 'bulkAdd';
4184
- _context26.next = 12;
4185
- return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
4186
- case 12:
4187
- _context26.next = 37;
4188
- break;
4189
- case 14:
4190
- if (!(typeof _this25.dbManager.update === 'function')) {
4191
- _context26.next = 35;
4192
- break;
4193
- }
4194
- writeMethod = 'update';
4195
- _iterator36 = _createForOfIteratorHelper(compactedToWrite);
4196
- _context26.prev = 17;
4197
- _iterator36.s();
4198
- case 19:
4199
- if ((_step36 = _iterator36.n()).done) {
4200
- _context26.next = 25;
4201
- break;
4202
- }
4203
- order = _step36.value;
4204
- _context26.next = 23;
4205
- return _this25.dbManager.update(INDEXDB_STORE_NAME, order);
4206
- case 23:
4207
- _context26.next = 19;
4208
- break;
4209
- case 25:
4210
- _context26.next = 30;
4211
- break;
4212
- case 27:
4213
- _context26.prev = 27;
4214
- _context26.t0 = _context26["catch"](17);
4215
- _iterator36.e(_context26.t0);
4216
- case 30:
4217
- _context26.prev = 30;
4218
- _iterator36.f();
4219
- return _context26.finish(30);
4220
- case 33:
4221
- _context26.next = 37;
4222
- break;
4223
- case 35:
4224
- if (!options.throwOnError) {
4225
- _context26.next = 37;
4226
- break;
4227
- }
4228
- throw new Error('订单 SQLite 数据库不支持写入');
4229
- case 37:
4230
- _this25.recordRecentSqliteWrite(source, compactedToWrite);
4561
+ _context28.next = 4;
4562
+ return _this28.writeOrderRowsToSQLite(compactedToWrite);
4563
+ case 4:
4564
+ writeMethod = _context28.sent;
4565
+ _this28.recordRecentSqliteWrite(source, compactedToWrite);
4231
4566
  if (!(writeMethod !== 'none')) {
4232
- _context26.next = 84;
4567
+ _context28.next = 52;
4233
4568
  break;
4234
4569
  }
4235
- _iterator37 = _createForOfIteratorHelper(storageKeyMigrations.values());
4236
- _context26.prev = 40;
4237
- _iterator37.s();
4238
- case 42:
4239
- if ((_step37 = _iterator37.n()).done) {
4240
- _context26.next = 76;
4570
+ _iterator45 = _createForOfIteratorHelper(storageKeyMigrations.values());
4571
+ _context28.prev = 8;
4572
+ _iterator45.s();
4573
+ case 10:
4574
+ if ((_step45 = _iterator45.n()).done) {
4575
+ _context28.next = 44;
4241
4576
  break;
4242
4577
  }
4243
- migration = _step37.value;
4244
- _context26.prev = 44;
4245
- _context26.next = 47;
4246
- return _this25.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
4247
- case 47:
4248
- _this25.recentSqliteWriteByStorageKey.delete(migration.from);
4249
- _iterator38 = _createForOfIteratorHelper(orders);
4250
- _context26.prev = 49;
4251
- _iterator38.s();
4252
- case 51:
4253
- if ((_step38 = _iterator38.n()).done) {
4254
- _context26.next = 61;
4578
+ migration = _step45.value;
4579
+ _context28.prev = 12;
4580
+ _context28.next = 15;
4581
+ return _this28.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
4582
+ case 15:
4583
+ _this28.recentSqliteWriteByStorageKey.delete(migration.from);
4584
+ _iterator46 = _createForOfIteratorHelper(orders);
4585
+ _context28.prev = 17;
4586
+ _iterator46.s();
4587
+ case 19:
4588
+ if ((_step46 = _iterator46.n()).done) {
4589
+ _context28.next = 29;
4255
4590
  break;
4256
4591
  }
4257
- _order = _step38.value;
4258
- if (!(_this25.getOrderStorageKey(_order) !== migration.to)) {
4259
- _context26.next = 55;
4592
+ order = _step46.value;
4593
+ if (!(_this28.getOrderStorageKey(order) !== migration.to)) {
4594
+ _context28.next = 23;
4260
4595
  break;
4261
4596
  }
4262
- return _context26.abrupt("continue", 59);
4263
- case 55:
4264
- orderRecord = _order;
4597
+ return _context28.abrupt("continue", 27);
4598
+ case 23:
4599
+ orderRecord = order;
4265
4600
  if (!(String((_orderRecord$ORDER_ST = orderRecord[ORDER_STORAGE_KEY_FIELD]) !== null && _orderRecord$ORDER_ST !== void 0 ? _orderRecord$ORDER_ST : '') !== migration.from)) {
4266
- _context26.next = 58;
4601
+ _context28.next = 26;
4267
4602
  break;
4268
4603
  }
4269
- return _context26.abrupt("continue", 59);
4270
- case 58:
4604
+ return _context28.abrupt("continue", 27);
4605
+ case 26:
4271
4606
  orderRecord[ORDER_STORAGE_KEY_FIELD] = migration.to;
4272
- case 59:
4273
- _context26.next = 51;
4607
+ case 27:
4608
+ _context28.next = 19;
4274
4609
  break;
4275
- case 61:
4276
- _context26.next = 66;
4610
+ case 29:
4611
+ _context28.next = 34;
4277
4612
  break;
4278
- case 63:
4279
- _context26.prev = 63;
4280
- _context26.t1 = _context26["catch"](49);
4281
- _iterator38.e(_context26.t1);
4282
- case 66:
4283
- _context26.prev = 66;
4284
- _iterator38.f();
4285
- return _context26.finish(66);
4286
- case 69:
4287
- _context26.next = 74;
4613
+ case 31:
4614
+ _context28.prev = 31;
4615
+ _context28.t0 = _context28["catch"](17);
4616
+ _iterator46.e(_context28.t0);
4617
+ case 34:
4618
+ _context28.prev = 34;
4619
+ _iterator46.f();
4620
+ return _context28.finish(34);
4621
+ case 37:
4622
+ _context28.next = 42;
4288
4623
  break;
4289
- case 71:
4290
- _context26.prev = 71;
4291
- _context26.t2 = _context26["catch"](44);
4292
- _this25.logError('删除订单旧 SQLite storage key 失败', {
4624
+ case 39:
4625
+ _context28.prev = 39;
4626
+ _context28.t1 = _context28["catch"](12);
4627
+ _this28.logError('删除订单旧 SQLite storage key 失败', {
4293
4628
  source: source,
4294
4629
  order_id: migration.orderId,
4295
4630
  oldStorageKey: migration.from,
4296
4631
  newStorageKey: migration.to,
4297
- error: _context26.t2 instanceof Error ? _context26.t2.message : String(_context26.t2)
4632
+ error: _context28.t1 instanceof Error ? _context28.t1.message : String(_context28.t1)
4298
4633
  });
4299
- case 74:
4300
- _context26.next = 42;
4634
+ case 42:
4635
+ _context28.next = 10;
4301
4636
  break;
4302
- case 76:
4303
- _context26.next = 81;
4637
+ case 44:
4638
+ _context28.next = 49;
4304
4639
  break;
4305
- case 78:
4306
- _context26.prev = 78;
4307
- _context26.t3 = _context26["catch"](40);
4308
- _iterator37.e(_context26.t3);
4309
- case 81:
4310
- _context26.prev = 81;
4311
- _iterator37.f();
4312
- return _context26.finish(81);
4313
- case 84:
4314
- _this25.logInfo('patchOrdersInSQLite-完成', {
4640
+ case 46:
4641
+ _context28.prev = 46;
4642
+ _context28.t2 = _context28["catch"](8);
4643
+ _iterator45.e(_context28.t2);
4644
+ case 49:
4645
+ _context28.prev = 49;
4646
+ _iterator45.f();
4647
+ return _context28.finish(49);
4648
+ case 52:
4649
+ _this28.logInfo('patchOrdersInSQLite-完成', {
4315
4650
  source: source,
4316
4651
  count: compactedToWrite.length,
4317
4652
  writeMethod: writeMethod,
4318
4653
  dedupedCount: skipped.length
4319
4654
  });
4320
- case 85:
4655
+ case 53:
4321
4656
  case "end":
4322
- return _context26.stop();
4657
+ return _context28.stop();
4323
4658
  }
4324
- }, _callee26, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
4659
+ }, _callee28, null, [[8, 46, 49, 52], [12, 39], [17, 31, 34, 37]]);
4325
4660
  })));
4326
4661
  case 44:
4327
- _context27.next = 51;
4662
+ _context29.next = 51;
4328
4663
  break;
4329
4664
  case 46:
4330
- _context27.prev = 46;
4331
- _context27.t1 = _context27["catch"](41);
4665
+ _context29.prev = 46;
4666
+ _context29.t1 = _context29["catch"](41);
4332
4667
  this.logError('增量保存订单到 SQLite 失败', {
4333
- error: _context27.t1 instanceof Error ? _context27.t1.message : String(_context27.t1),
4668
+ error: _context29.t1 instanceof Error ? _context29.t1.message : String(_context29.t1),
4334
4669
  orderCount: ordersSnapshot.length
4335
4670
  });
4336
4671
  if (!options.throwOnError) {
4337
- _context27.next = 51;
4672
+ _context29.next = 51;
4338
4673
  break;
4339
4674
  }
4340
- throw _context27.t1;
4675
+ throw _context29.t1;
4341
4676
  case 51:
4342
4677
  case "end":
4343
- return _context27.stop();
4678
+ return _context29.stop();
4344
4679
  }
4345
- }, _callee27, this, [[22, 35, 38, 41], [41, 46]]);
4680
+ }, _callee29, this, [[22, 35, 38, 41], [41, 46]]);
4346
4681
  }));
4347
- function patchOrdersInSQLite(_x19, _x20) {
4682
+ function patchOrdersInSQLite(_x20, _x21) {
4348
4683
  return _patchOrdersInSQLite.apply(this, arguments);
4349
4684
  }
4350
4685
  return patchOrdersInSQLite;
@@ -4359,128 +4694,128 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4359
4694
  }, {
4360
4695
  key: "updateOrderInSQLite",
4361
4696
  value: (function () {
4362
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(order, source) {
4363
- var _this26 = this;
4697
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(order, source) {
4698
+ var _this29 = this;
4364
4699
  var options,
4365
4700
  orderSnapshot,
4366
4701
  _orderSnapshot$order_3,
4367
- _args29 = arguments;
4368
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4369
- while (1) switch (_context29.prev = _context29.next) {
4702
+ _args31 = arguments;
4703
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
4704
+ while (1) switch (_context31.prev = _context31.next) {
4370
4705
  case 0:
4371
- options = _args29.length > 2 && _args29[2] !== undefined ? _args29[2] : {};
4706
+ options = _args31.length > 2 && _args31[2] !== undefined ? _args31[2] : {};
4372
4707
  if (this.getOrderStorageKey(order)) {
4373
- _context29.next = 5;
4708
+ _context31.next = 5;
4374
4709
  break;
4375
4710
  }
4376
4711
  if (!options.throwOnError) {
4377
- _context29.next = 4;
4712
+ _context31.next = 4;
4378
4713
  break;
4379
4714
  }
4380
4715
  throw new Error('订单缺少可用的 SQLite 存储主键');
4381
4716
  case 4:
4382
- return _context29.abrupt("return");
4717
+ return _context31.abrupt("return");
4383
4718
  case 5:
4384
4719
  if (this.dbManager) {
4385
- _context29.next = 9;
4720
+ _context31.next = 9;
4386
4721
  break;
4387
4722
  }
4388
4723
  if (!options.throwOnError) {
4389
- _context29.next = 8;
4724
+ _context31.next = 8;
4390
4725
  break;
4391
4726
  }
4392
4727
  throw new Error('订单 SQLite 数据库未初始化');
4393
4728
  case 8:
4394
- return _context29.abrupt("return");
4729
+ return _context31.abrupt("return");
4395
4730
  case 9:
4396
4731
  orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
4397
- _context29.prev = 10;
4398
- _context29.next = 13;
4399
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
4732
+ _context31.prev = 10;
4733
+ _context31.next = 13;
4734
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4400
4735
  var _orderSnapshot$order_, _orderSnapshot$order_2;
4401
4736
  var writeMethod;
4402
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4403
- while (1) switch (_context28.prev = _context28.next) {
4737
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4738
+ while (1) switch (_context30.prev = _context30.next) {
4404
4739
  case 0:
4405
4740
  writeMethod = 'none';
4406
- _this26.logInfo('updateOrderInSQLite-开始', {
4741
+ _this29.logInfo('updateOrderInSQLite-开始', {
4407
4742
  source: source,
4408
4743
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
4409
- storageKey: _this26.getOrderStorageKey(orderSnapshot)
4744
+ storageKey: _this29.getOrderStorageKey(orderSnapshot)
4410
4745
  });
4411
- if (!(typeof _this26.dbManager.update === 'function')) {
4412
- _context28.next = 8;
4746
+ if (!(typeof _this29.dbManager.update === 'function')) {
4747
+ _context30.next = 8;
4413
4748
  break;
4414
4749
  }
4415
4750
  writeMethod = 'update';
4416
- _context28.next = 6;
4417
- return _this26.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4751
+ _context30.next = 6;
4752
+ return _this29.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4418
4753
  case 6:
4419
- _context28.next = 22;
4754
+ _context30.next = 22;
4420
4755
  break;
4421
4756
  case 8:
4422
- if (!(typeof _this26.dbManager.bulkUpdate === 'function')) {
4423
- _context28.next = 14;
4757
+ if (!(typeof _this29.dbManager.bulkUpdate === 'function')) {
4758
+ _context30.next = 14;
4424
4759
  break;
4425
4760
  }
4426
4761
  writeMethod = 'bulkUpdate';
4427
- _context28.next = 12;
4428
- return _this26.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4762
+ _context30.next = 12;
4763
+ return _this29.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4429
4764
  case 12:
4430
- _context28.next = 22;
4765
+ _context30.next = 22;
4431
4766
  break;
4432
4767
  case 14:
4433
- if (!(typeof _this26.dbManager.bulkAdd === 'function')) {
4434
- _context28.next = 20;
4768
+ if (!(typeof _this29.dbManager.bulkAdd === 'function')) {
4769
+ _context30.next = 20;
4435
4770
  break;
4436
4771
  }
4437
4772
  writeMethod = 'bulkAdd';
4438
- _context28.next = 18;
4439
- return _this26.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4773
+ _context30.next = 18;
4774
+ return _this29.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4440
4775
  case 18:
4441
- _context28.next = 22;
4776
+ _context30.next = 22;
4442
4777
  break;
4443
4778
  case 20:
4444
4779
  if (!options.throwOnError) {
4445
- _context28.next = 22;
4780
+ _context30.next = 22;
4446
4781
  break;
4447
4782
  }
4448
4783
  throw new Error('订单 SQLite 数据库不支持写入');
4449
4784
  case 22:
4450
- _this26.recordRecentSqliteWrite(source, [orderSnapshot]);
4451
- _this26.logInfo('updateOrderInSQLite-完成', {
4785
+ _this29.recordRecentSqliteWrite(source, [orderSnapshot]);
4786
+ _this29.logInfo('updateOrderInSQLite-完成', {
4452
4787
  source: source,
4453
4788
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
4454
4789
  writeMethod: writeMethod
4455
4790
  });
4456
4791
  case 24:
4457
4792
  case "end":
4458
- return _context28.stop();
4793
+ return _context30.stop();
4459
4794
  }
4460
- }, _callee28);
4795
+ }, _callee30);
4461
4796
  })));
4462
4797
  case 13:
4463
- _context29.next = 20;
4798
+ _context31.next = 20;
4464
4799
  break;
4465
4800
  case 15:
4466
- _context29.prev = 15;
4467
- _context29.t0 = _context29["catch"](10);
4801
+ _context31.prev = 15;
4802
+ _context31.t0 = _context31["catch"](10);
4468
4803
  this.logError('单条保存订单到 SQLite 失败', {
4469
- error: _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0),
4804
+ error: _context31.t0 instanceof Error ? _context31.t0.message : String(_context31.t0),
4470
4805
  orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
4471
4806
  });
4472
4807
  if (!options.throwOnError) {
4473
- _context29.next = 20;
4808
+ _context31.next = 20;
4474
4809
  break;
4475
4810
  }
4476
- throw _context29.t0;
4811
+ throw _context31.t0;
4477
4812
  case 20:
4478
4813
  case "end":
4479
- return _context29.stop();
4814
+ return _context31.stop();
4480
4815
  }
4481
- }, _callee29, this, [[10, 15]]);
4816
+ }, _callee31, this, [[10, 15]]);
4482
4817
  }));
4483
- function updateOrderInSQLite(_x21, _x22) {
4818
+ function updateOrderInSQLite(_x22, _x23) {
4484
4819
  return _updateOrderInSQLite.apply(this, arguments);
4485
4820
  }
4486
4821
  return updateOrderInSQLite;
@@ -4496,76 +4831,76 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4496
4831
  }, {
4497
4832
  key: "replaceOrdersSnapshotInSQLite",
4498
4833
  value: (function () {
4499
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(orderList, source) {
4500
- var _this27 = this;
4834
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(orderList, source) {
4835
+ var _this30 = this;
4501
4836
  var protectedOrdersBeforeRemoteFetch,
4502
4837
  remoteSnapshot,
4503
4838
  mergedSnapshot,
4504
4839
  persisted,
4505
- _args31 = arguments;
4506
- return _regeneratorRuntime().wrap(function _callee31$(_context31) {
4507
- while (1) switch (_context31.prev = _context31.next) {
4840
+ _args33 = arguments;
4841
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
4842
+ while (1) switch (_context33.prev = _context33.next) {
4508
4843
  case 0:
4509
- protectedOrdersBeforeRemoteFetch = _args31.length > 2 && _args31[2] !== undefined ? _args31[2] : [];
4844
+ protectedOrdersBeforeRemoteFetch = _args33.length > 2 && _args33[2] !== undefined ? _args33[2] : [];
4510
4845
  if (this.dbManager) {
4511
- _context31.next = 3;
4846
+ _context33.next = 3;
4512
4847
  break;
4513
4848
  }
4514
- return _context31.abrupt("return", {
4849
+ return _context33.abrupt("return", {
4515
4850
  orders: this.compactOrderListByIdentity(this.preserveOmittedHolderRelations(orderList, this.store.list).map(function (order) {
4516
- return _this27.normalizeRemoteSyncedOrder(order);
4851
+ return _this30.normalizeRemoteSyncedOrder(order);
4517
4852
  }), "".concat(source, ".snapshotNoDb")).list,
4518
4853
  persisted: false
4519
4854
  });
4520
4855
  case 3:
4521
4856
  remoteSnapshot = cloneDeep(orderList).map(function (order) {
4522
- return _this27.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
4857
+ return _this30.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
4523
4858
  });
4524
4859
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
4525
- return _this27.normalizeRemoteSyncedOrder(order);
4860
+ return _this30.normalizeRemoteSyncedOrder(order);
4526
4861
  }), "".concat(source, ".remoteSnapshot")).list;
4527
4862
  persisted = false;
4528
- _context31.prev = 6;
4529
- _context31.next = 9;
4530
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4531
- var existingOrders, remoteSnapshotWithHolderRelations, protectedLocalOrders, _iterator39, _step39, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4532
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4533
- while (1) switch (_context30.prev = _context30.next) {
4863
+ _context33.prev = 6;
4864
+ _context33.next = 9;
4865
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
4866
+ var existingOrders, remoteSnapshotWithHolderRelations, protectedLocalOrders, _iterator47, _step47, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4867
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
4868
+ while (1) switch (_context32.prev = _context32.next) {
4534
4869
  case 0:
4535
- if (!(typeof _this27.dbManager.getAll === 'function')) {
4536
- _context30.next = 6;
4870
+ if (!(typeof _this30.dbManager.getAll === 'function')) {
4871
+ _context32.next = 6;
4537
4872
  break;
4538
4873
  }
4539
- _context30.next = 3;
4540
- return _this27.dbManager.getAll(INDEXDB_STORE_NAME);
4874
+ _context32.next = 3;
4875
+ return _this30.dbManager.getAll(INDEXDB_STORE_NAME);
4541
4876
  case 3:
4542
- _context30.t0 = _context30.sent;
4543
- _context30.next = 7;
4877
+ _context32.t0 = _context32.sent;
4878
+ _context32.next = 7;
4544
4879
  break;
4545
4880
  case 6:
4546
- _context30.t0 = [];
4881
+ _context32.t0 = [];
4547
4882
  case 7:
4548
- existingOrders = _context30.t0;
4549
- remoteSnapshotWithHolderRelations = _this27.preserveOmittedHolderRelations(remoteSnapshot, [].concat(_toConsumableArray(protectedOrdersBeforeRemoteFetch), _toConsumableArray(existingOrders || [])));
4883
+ existingOrders = _context32.t0;
4884
+ remoteSnapshotWithHolderRelations = _this30.preserveOmittedHolderRelations(remoteSnapshot, [].concat(_toConsumableArray(protectedOrdersBeforeRemoteFetch), _toConsumableArray(existingOrders || [])));
4550
4885
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
4551
- return _this27.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4886
+ return _this30.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4552
4887
  }).filter(function (order) {
4553
- return _this27.shouldProtectLocalOrderFromRemoteSnapshot(order);
4888
+ return _this30.shouldProtectLocalOrderFromRemoteSnapshot(order);
4554
4889
  });
4555
- _iterator39 = _createForOfIteratorHelper(existingOrders || []);
4556
- _context30.prev = 11;
4557
- _iterator39.s();
4890
+ _iterator47 = _createForOfIteratorHelper(existingOrders || []);
4891
+ _context32.prev = 11;
4892
+ _iterator47.s();
4558
4893
  case 13:
4559
- if ((_step39 = _iterator39.n()).done) {
4560
- _context30.next = 24;
4894
+ if ((_step47 = _iterator47.n()).done) {
4895
+ _context32.next = 24;
4561
4896
  break;
4562
4897
  }
4563
- rawCurrentOrder = _step39.value;
4564
- currentOrder = _this27.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4565
- protectedIndex = _this27.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4566
- currentNeedsProtection = _this27.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4898
+ rawCurrentOrder = _step47.value;
4899
+ currentOrder = _this30.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4900
+ protectedIndex = _this30.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4901
+ currentNeedsProtection = _this30.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4567
4902
  if (!(protectedIndex >= 0)) {
4568
- _context30.next = 21;
4903
+ _context32.next = 21;
4569
4904
  break;
4570
4905
  }
4571
4906
  if (currentNeedsProtection) {
@@ -4573,27 +4908,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4573
4908
  } else {
4574
4909
  protectedLocalOrders.splice(protectedIndex, 1);
4575
4910
  }
4576
- return _context30.abrupt("continue", 22);
4911
+ return _context32.abrupt("continue", 22);
4577
4912
  case 21:
4578
4913
  if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
4579
4914
  case 22:
4580
- _context30.next = 13;
4915
+ _context32.next = 13;
4581
4916
  break;
4582
4917
  case 24:
4583
- _context30.next = 29;
4918
+ _context32.next = 29;
4584
4919
  break;
4585
4920
  case 26:
4586
- _context30.prev = 26;
4587
- _context30.t1 = _context30["catch"](11);
4588
- _iterator39.e(_context30.t1);
4921
+ _context32.prev = 26;
4922
+ _context32.t1 = _context32["catch"](11);
4923
+ _iterator47.e(_context32.t1);
4589
4924
  case 29:
4590
- _context30.prev = 29;
4591
- _iterator39.f();
4592
- return _context30.finish(29);
4925
+ _context32.prev = 29;
4926
+ _iterator47.f();
4927
+ return _context32.finish(29);
4593
4928
  case 32:
4594
- orderListSnapshot = _this27.mergeRemoteSnapshotWithPendingOrders(remoteSnapshotWithHolderRelations, protectedLocalOrders);
4595
- mergedSnapshot = _this27.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4596
- _this27.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4929
+ orderListSnapshot = _this30.mergeRemoteSnapshotWithPendingOrders(remoteSnapshotWithHolderRelations, protectedLocalOrders);
4930
+ mergedSnapshot = _this30.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4931
+ _this30.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4597
4932
  source: source,
4598
4933
  count: mergedSnapshot.length,
4599
4934
  remoteCount: remoteSnapshot.length,
@@ -4601,10 +4936,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4601
4936
  protectedLocalOrderCount: protectedLocalOrders.length,
4602
4937
  preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
4603
4938
  protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
4604
- return count + _this27.getIdentifiedPendingPayments(order).length;
4939
+ return count + _this30.getIdentifiedPendingPayments(order).length;
4605
4940
  }, 0),
4606
4941
  protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
4607
- return _this27.getIdentifiedPendingPayments(order).map(function (payment) {
4942
+ return _this30.getIdentifiedPendingPayments(order).map(function (payment) {
4608
4943
  var _order$order_id5, _external_sale_number5;
4609
4944
  return {
4610
4945
  order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
@@ -4614,55 +4949,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4614
4949
  });
4615
4950
  })
4616
4951
  });
4617
- _context30.next = 37;
4618
- return _this27.dbManager.clear(INDEXDB_STORE_NAME);
4952
+ _context32.next = 37;
4953
+ return _this30.dbManager.clear(INDEXDB_STORE_NAME);
4619
4954
  case 37:
4620
- _this27.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4955
+ _this30.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4621
4956
  count: mergedSnapshot.length
4622
4957
  });
4623
4958
  if (!(mergedSnapshot.length === 0)) {
4624
- _context30.next = 40;
4959
+ _context32.next = 40;
4625
4960
  break;
4626
4961
  }
4627
- return _context30.abrupt("return");
4962
+ return _context32.abrupt("return");
4628
4963
  case 40:
4629
- _context30.next = 42;
4630
- return _this27.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4964
+ _context32.next = 42;
4965
+ return _this30.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4631
4966
  case 42:
4632
- _this27.recordRecentSqliteWrite(source, mergedSnapshot);
4633
- _this27.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4967
+ _this30.recordRecentSqliteWrite(source, mergedSnapshot);
4968
+ _this30.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4634
4969
  source: source,
4635
4970
  count: mergedSnapshot.length
4636
4971
  });
4637
4972
  case 44:
4638
4973
  case "end":
4639
- return _context30.stop();
4974
+ return _context32.stop();
4640
4975
  }
4641
- }, _callee30, null, [[11, 26, 29, 32]]);
4976
+ }, _callee32, null, [[11, 26, 29, 32]]);
4642
4977
  })));
4643
4978
  case 9:
4644
4979
  persisted = true;
4645
- _context31.next = 15;
4980
+ _context33.next = 15;
4646
4981
  break;
4647
4982
  case 12:
4648
- _context31.prev = 12;
4649
- _context31.t0 = _context31["catch"](6);
4983
+ _context33.prev = 12;
4984
+ _context33.t0 = _context33["catch"](6);
4650
4985
  this.logError('全量保存订单到 SQLite 失败', {
4651
- error: _context31.t0 instanceof Error ? _context31.t0.message : String(_context31.t0),
4986
+ error: _context33.t0 instanceof Error ? _context33.t0.message : String(_context33.t0),
4652
4987
  orderList: remoteSnapshot.length
4653
4988
  });
4654
4989
  case 15:
4655
- return _context31.abrupt("return", {
4990
+ return _context33.abrupt("return", {
4656
4991
  orders: mergedSnapshot,
4657
4992
  persisted: persisted
4658
4993
  });
4659
4994
  case 16:
4660
4995
  case "end":
4661
- return _context31.stop();
4996
+ return _context33.stop();
4662
4997
  }
4663
- }, _callee31, this, [[6, 12]]);
4998
+ }, _callee33, this, [[6, 12]]);
4664
4999
  }));
4665
- function replaceOrdersSnapshotInSQLite(_x23, _x24) {
5000
+ function replaceOrdersSnapshotInSQLite(_x24, _x25) {
4666
5001
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
4667
5002
  }
4668
5003
  return replaceOrdersSnapshotInSQLite;
@@ -4677,38 +5012,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4677
5012
  }, {
4678
5013
  key: "clear",
4679
5014
  value: (function () {
4680
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
4681
- var _this28 = this;
4682
- return _regeneratorRuntime().wrap(function _callee33$(_context33) {
4683
- while (1) switch (_context33.prev = _context33.next) {
5015
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
5016
+ var _this31 = this;
5017
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
5018
+ while (1) switch (_context35.prev = _context35.next) {
4684
5019
  case 0:
4685
5020
  this.store.list = [];
4686
5021
  this.store.map = new Map();
4687
5022
  if (!this.dbManager) {
4688
- _context33.next = 5;
5023
+ _context35.next = 5;
4689
5024
  break;
4690
5025
  }
4691
- _context33.next = 5;
4692
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
4693
- return _regeneratorRuntime().wrap(function _callee32$(_context32) {
4694
- while (1) switch (_context32.prev = _context32.next) {
5026
+ _context35.next = 5;
5027
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
5028
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
5029
+ while (1) switch (_context34.prev = _context34.next) {
4695
5030
  case 0:
4696
- _context32.next = 2;
4697
- return _this28.dbManager.clear(INDEXDB_STORE_NAME);
5031
+ _context34.next = 2;
5032
+ return _this31.dbManager.clear(INDEXDB_STORE_NAME);
4698
5033
  case 2:
4699
5034
  case "end":
4700
- return _context32.stop();
5035
+ return _context34.stop();
4701
5036
  }
4702
- }, _callee32);
5037
+ }, _callee34);
4703
5038
  })));
4704
5039
  case 5:
4705
5040
  this.clearOrderSnapshotMarker();
4706
5041
  this.emitOrdersChanged([], 'clear');
4707
5042
  case 7:
4708
5043
  case "end":
4709
- return _context33.stop();
5044
+ return _context35.stop();
4710
5045
  }
4711
- }, _callee33, this);
5046
+ }, _callee35, this);
4712
5047
  }));
4713
5048
  function clear() {
4714
5049
  return _clear.apply(this, arguments);