@pisell/pisellos 2.3.67 → 2.3.68

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 (85) hide show
  1. package/dist/core/index.d.ts +0 -7
  2. package/dist/core/index.js +65 -109
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -1
  4. package/dist/model/strategy/adapter/walletPass/utils.js +0 -2
  5. package/dist/modules/BaseModule.d.ts +1 -0
  6. package/dist/modules/BaseModule.js +24 -28
  7. package/dist/modules/Customer/index.d.ts +4 -0
  8. package/dist/modules/Customer/index.js +91 -59
  9. package/dist/modules/Customer/types.d.ts +2 -0
  10. package/dist/modules/Order/index.d.ts +22 -2
  11. package/dist/modules/Order/index.js +313 -142
  12. package/dist/modules/Order/types.d.ts +13 -1
  13. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +15 -0
  14. package/dist/modules/Order/utils/orderCollectionIdentity.js +75 -0
  15. package/dist/modules/Order/utils.js +0 -1
  16. package/dist/modules/Payment/index.d.ts +4 -0
  17. package/dist/modules/Payment/index.js +14 -4
  18. package/dist/modules/Payment/walletpass.js +52 -18
  19. package/dist/modules/Quotation/index.d.ts +0 -6
  20. package/dist/modules/Quotation/index.js +19 -75
  21. package/dist/modules/Rules/index.js +46 -31
  22. package/dist/plugins/request.d.ts +0 -1
  23. package/dist/server/index.d.ts +2 -8
  24. package/dist/server/index.js +143 -212
  25. package/dist/server/modules/floor-plan/index.d.ts +0 -4
  26. package/dist/server/modules/floor-plan/index.js +98 -240
  27. package/dist/server/modules/menu/index.js +23 -48
  28. package/dist/server/modules/order/index.d.ts +8 -17
  29. package/dist/server/modules/order/index.js +453 -506
  30. package/dist/server/modules/products/index.d.ts +2 -8
  31. package/dist/server/modules/products/index.js +75 -167
  32. package/dist/server/modules/resource/index.js +13 -21
  33. package/dist/server/utils/small-ticket.js +2 -1
  34. package/dist/solution/BaseSales/index.d.ts +3 -1
  35. package/dist/solution/BaseSales/index.js +99 -82
  36. package/dist/solution/BaseSales/utils.js +31 -20
  37. package/dist/solution/BookingTicket/index.d.ts +6 -2
  38. package/dist/solution/BookingTicket/index.js +123 -75
  39. package/dist/solution/ScanOrder/utils.js +31 -20
  40. package/dist/solution/UnifiedBookingSales/index.d.ts +25 -0
  41. package/dist/solution/UnifiedBookingSales/index.js +640 -321
  42. package/dist/solution/UnifiedBookingSales/types.d.ts +7 -0
  43. package/lib/core/index.d.ts +0 -7
  44. package/lib/core/index.js +2 -20
  45. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -1
  46. package/lib/model/strategy/adapter/walletPass/utils.js +0 -1
  47. package/lib/modules/BaseModule.d.ts +1 -0
  48. package/lib/modules/BaseModule.js +24 -37
  49. package/lib/modules/Customer/index.d.ts +4 -0
  50. package/lib/modules/Customer/index.js +11 -0
  51. package/lib/modules/Customer/types.d.ts +2 -0
  52. package/lib/modules/Order/index.d.ts +22 -2
  53. package/lib/modules/Order/index.js +212 -54
  54. package/lib/modules/Order/types.d.ts +13 -1
  55. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +15 -0
  56. package/lib/modules/Order/utils/orderCollectionIdentity.js +70 -0
  57. package/lib/modules/Order/utils.js +0 -1
  58. package/lib/modules/Payment/index.d.ts +4 -0
  59. package/lib/modules/Payment/index.js +7 -0
  60. package/lib/modules/Payment/walletpass.js +27 -2
  61. package/lib/modules/Quotation/index.d.ts +0 -6
  62. package/lib/modules/Quotation/index.js +5 -49
  63. package/lib/modules/Rules/index.js +17 -1
  64. package/lib/plugins/request.d.ts +0 -1
  65. package/lib/server/index.d.ts +2 -8
  66. package/lib/server/index.js +20 -58
  67. package/lib/server/modules/floor-plan/index.d.ts +0 -4
  68. package/lib/server/modules/floor-plan/index.js +6 -54
  69. package/lib/server/modules/menu/index.js +5 -31
  70. package/lib/server/modules/order/index.d.ts +8 -17
  71. package/lib/server/modules/order/index.js +106 -199
  72. package/lib/server/modules/products/index.d.ts +2 -8
  73. package/lib/server/modules/products/index.js +24 -97
  74. package/lib/server/modules/resource/index.js +2 -7
  75. package/lib/server/utils/small-ticket.js +1 -1
  76. package/lib/solution/BaseSales/index.d.ts +3 -1
  77. package/lib/solution/BaseSales/index.js +29 -16
  78. package/lib/solution/BaseSales/utils.js +29 -18
  79. package/lib/solution/BookingTicket/index.d.ts +6 -2
  80. package/lib/solution/BookingTicket/index.js +53 -14
  81. package/lib/solution/ScanOrder/utils.js +29 -18
  82. package/lib/solution/UnifiedBookingSales/index.d.ts +25 -0
  83. package/lib/solution/UnifiedBookingSales/index.js +188 -0
  84. package/lib/solution/UnifiedBookingSales/types.d.ts +7 -0
  85. package/package.json +1 -1
@@ -41,8 +41,8 @@ import { getOrderPaymentIdentityKeys, isIdentifiedPendingOrderPayment, isPending
41
41
  * SQLite 存储名称
42
42
  */
43
43
  var INDEXDB_STORE_NAME = 'orders';
44
+ var ORDER_STORAGE_KEY_FIELD = '__order_storage_key';
44
45
  var ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY = 'server_order_last_full_fetch_at';
45
- var ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY = 'server_order_last_full_fetch_shop_id';
46
46
  var ORDER_SYNC_THROTTLE_MS_STORAGE_KEY = 'order_sync_throttle_ms';
47
47
  var DEFAULT_ORDER_SYNC_THROTTLE_MS = 2000;
48
48
  /** pubsub 回声写入去重窗口:业务 API 刚写入后,跳过同单 SQLite patch */
@@ -308,23 +308,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
308
308
  }, {
309
309
  key: "normalizeOrderCollectionsForIngress",
310
310
  value: function normalizeOrderCollectionsForIngress(order, source) {
311
- var sourceOrderRecord = order;
312
- var sourceOrder = sourceOrderRecord;
311
+ var sourceOrder = cloneDeep(order);
312
+ var sourceOrderRecord = sourceOrder;
313
313
  if (Array.isArray(sourceOrderRecord.payments)) {
314
- sourceOrder = _objectSpread(_objectSpread({}, sourceOrderRecord), {}, {
315
- payments: sourceOrderRecord.payments.map(function (payment) {
316
- if (!isPendingOrderPayment(payment) || getOrderPaymentIdentityKeys(payment).some(function (key) {
317
- return key.startsWith('unique_payment_number:');
318
- })) {
319
- return payment;
320
- }
321
- return _objectSpread(_objectSpread({}, payment), {}, _defineProperty({}, PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER, true));
322
- })
314
+ sourceOrderRecord.payments = sourceOrderRecord.payments.map(function (payment) {
315
+ if (!isPendingOrderPayment(payment) || getOrderPaymentIdentityKeys(payment).some(function (key) {
316
+ return key.startsWith('unique_payment_number:');
317
+ })) {
318
+ return payment;
319
+ }
320
+ return _objectSpread(_objectSpread({}, payment), {}, _defineProperty({}, PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER, true));
323
321
  });
324
322
  }
325
-
326
- // normalizeOrderCollections 内部已经 cloneDeep;这里只浅复制被改写的 payments,
327
- // 既不修改调用方对象,也避免对整笔订单重复深拷贝。
328
323
  var result = normalizeOrderCollections(sourceOrder);
329
324
  var normalizedOrderRecord = result.order;
330
325
  if (Array.isArray(normalizedOrderRecord.payments)) {
@@ -705,96 +700,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
705
700
  key: "preload",
706
701
  value: function () {
707
702
  var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
708
- var preloadStartedAt, cachedOrders, sqliteLoadTimings, memoryPrepareStartedAt, memoryOrders, memoryPrepareMs, syncMapStartedAt, syncMapMs, onOrdersLoadedStartedAt, onOrdersLoadedMs, emitOrdersChangedStartedAt, emitOrdersChangedMs, orders;
703
+ var orders;
709
704
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
710
705
  while (1) switch (_context4.prev = _context4.next) {
711
706
  case 0:
712
- preloadStartedAt = Date.now();
713
- cachedOrders = null;
714
- if (!this.dbManager) {
715
- _context4.next = 12;
716
- break;
717
- }
718
- _context4.prev = 3;
719
- _context4.next = 6;
720
- return this.loadOrdersFromSQLite({
721
- throwOnError: true,
722
- onTiming: function onTiming(timings) {
723
- sqliteLoadTimings = timings;
724
- }
725
- });
726
- case 6:
727
- cachedOrders = _context4.sent;
728
- _context4.next = 12;
729
- break;
730
- case 9:
731
- _context4.prev = 9;
732
- _context4.t0 = _context4["catch"](3);
733
- this.logWarning('preload-SQLite读取失败,回退远端全量拉取', {
734
- error: _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0)
735
- });
736
- case 12:
737
- if (!(cachedOrders !== null && this.hasPulledOrdersToday())) {
738
- _context4.next = 30;
739
- break;
740
- }
741
- memoryPrepareStartedAt = performance.now();
742
- memoryOrders = this.prepareNormalizedOrdersForMemoryList(cachedOrders);
743
- memoryPrepareMs = +(performance.now() - memoryPrepareStartedAt).toFixed(2); // loadOrdersFromSQLite 已返回独立且完成集合规范化的新对象;直接进入 store,
744
- // 不再进行第二轮 normalize 和没有隔离收益的最终 cloneDeep。
745
- this.store.list = memoryOrders;
746
- syncMapStartedAt = performance.now();
747
- this.syncOrdersMap();
748
- syncMapMs = +(performance.now() - syncMapStartedAt).toFixed(2);
749
- onOrdersLoadedStartedAt = performance.now();
750
- _context4.next = 23;
751
- return this.core.effects.emit(OrderHooks.onOrdersLoaded, this.store.list);
752
- case 23:
753
- onOrdersLoadedMs = +(performance.now() - onOrdersLoadedStartedAt).toFixed(2);
754
- emitOrdersChangedStartedAt = performance.now();
755
- _context4.next = 27;
756
- return this.emitOrdersChanged([], 'preload.sqlite');
757
- case 27:
758
- emitOrdersChangedMs = +(performance.now() - emitOrdersChangedStartedAt).toFixed(2);
759
- this.logInfo('预加载完成', {
760
- trigger: 'preload',
761
- source: 'SQLite',
762
- orderCount: this.store.list.length,
763
- duration: "".concat(Date.now() - preloadStartedAt, "ms"),
764
- stages: _objectSpread(_objectSpread({}, sqliteLoadTimings || {}), {}, {
765
- memoryPrepareMs: memoryPrepareMs,
766
- syncMapMs: syncMapMs,
767
- onOrdersLoadedMs: onOrdersLoadedMs,
768
- emitOrdersChangedMs: emitOrdersChangedMs
769
- })
770
- });
771
- return _context4.abrupt("return");
772
- case 30:
773
- _context4.next = 32;
774
- return this.loadOrdersByServer({
775
- trigger: 'preload'
776
- });
777
- case 32:
707
+ _context4.next = 2;
708
+ return this.loadOrdersByServer();
709
+ case 2:
778
710
  orders = _context4.sent;
779
711
  this.store.list = cloneDeep(orders);
780
712
  this.syncOrdersMap();
781
- _context4.next = 37;
713
+ _context4.next = 7;
782
714
  return this.emitOrdersChanged([], 'preload');
783
- case 37:
784
- _context4.next = 39;
715
+ case 7:
716
+ _context4.next = 9;
785
717
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
786
- case 39:
787
- this.logInfo('预加载完成', {
788
- trigger: 'preload',
789
- source: 'Server',
790
- orderCount: this.store.list.length,
791
- duration: "".concat(Date.now() - preloadStartedAt, "ms")
792
- });
793
- case 40:
718
+ case 9:
794
719
  case "end":
795
720
  return _context4.stop();
796
721
  }
797
- }, _callee4, this, [[3, 9]]);
722
+ }, _callee4, this);
798
723
  }));
799
724
  function preload() {
800
725
  return _preload.apply(this, arguments);
@@ -1127,32 +1052,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1127
1052
  var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1128
1053
  var _this5 = this,
1129
1054
  _this$store;
1130
- var options,
1131
- orderList,
1132
- hasFetchedRemoteSnapshot,
1133
- trigger,
1134
- protectedOrdersBeforeRemoteFetch,
1135
- data,
1136
- _yield$this$replaceOr,
1137
- mergedOrders,
1138
- isRemoteSnapshotPersisted,
1139
- memoryOrders,
1140
- _args8 = arguments;
1055
+ var orderList, protectedOrdersBeforeRemoteFetch, data, mergedOrders, memoryOrders;
1141
1056
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1142
1057
  while (1) switch (_context8.prev = _context8.next) {
1143
1058
  case 0:
1144
- options = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
1145
1059
  orderList = [];
1146
- hasFetchedRemoteSnapshot = false;
1147
- trigger = options.trigger || 'unknown';
1148
- _context8.next = 6;
1060
+ _context8.next = 3;
1149
1061
  return this.loadOrdersFromSQLite();
1150
- case 6:
1062
+ case 3:
1151
1063
  protectedOrdersBeforeRemoteFetch = _context8.sent.filter(function (order) {
1152
1064
  return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
1153
1065
  });
1154
1066
  this.logInfo('loadOrdersByServer-开始', {
1155
- trigger: trigger,
1156
1067
  hasOrderDataSource: !!this.orderDataSource,
1157
1068
  query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
1158
1069
  protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
@@ -1161,61 +1072,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1161
1072
  }, 0)
1162
1073
  });
1163
1074
  if (!this.orderDataSource) {
1164
- _context8.next = 23;
1075
+ _context8.next = 20;
1165
1076
  break;
1166
1077
  }
1167
- _context8.prev = 9;
1168
- _context8.next = 12;
1078
+ _context8.prev = 6;
1079
+ _context8.next = 9;
1169
1080
  return this.orderDataSource.run({
1170
1081
  sse: {
1171
1082
  query: this.store.createdAtQuery
1172
1083
  }
1173
1084
  });
1174
- case 12:
1085
+ case 9:
1175
1086
  data = _context8.sent;
1176
1087
  orderList = data || [];
1177
1088
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
1178
- trigger: trigger,
1179
1089
  count: orderList.length
1180
1090
  });
1181
- hasFetchedRemoteSnapshot = true;
1091
+ this.markOrderPulledAtNow();
1182
1092
  this.lastServerFullFetchAtMs = Date.now();
1183
- _context8.next = 23;
1093
+ _context8.next = 20;
1184
1094
  break;
1185
- case 19:
1186
- _context8.prev = 19;
1187
- _context8.t0 = _context8["catch"](9);
1095
+ case 16:
1096
+ _context8.prev = 16;
1097
+ _context8.t0 = _context8["catch"](6);
1188
1098
  this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
1189
1099
  return _context8.abrupt("return", this.store.list);
1190
- case 23:
1191
- if (hasFetchedRemoteSnapshot) {
1192
- this.clearOrderSnapshotMarker();
1193
- }
1194
- _context8.next = 26;
1100
+ case 20:
1101
+ _context8.next = 22;
1195
1102
  return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
1196
- case 26:
1197
- _yield$this$replaceOr = _context8.sent;
1198
- mergedOrders = _yield$this$replaceOr.orders;
1199
- isRemoteSnapshotPersisted = _yield$this$replaceOr.persisted;
1200
- if (hasFetchedRemoteSnapshot && isRemoteSnapshotPersisted) {
1201
- this.markOrderPulledAtNow();
1202
- }
1103
+ case 22:
1104
+ mergedOrders = _context8.sent;
1203
1105
  memoryOrders = this.normalizeOrdersForMemoryList(mergedOrders, 'loadOrdersByServer.memory');
1204
1106
  this.logInfo('loadOrdersByServer-结束', {
1205
- trigger: trigger,
1206
1107
  count: memoryOrders.length,
1207
1108
  persistedCount: mergedOrders.length,
1208
1109
  sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
1209
1110
  });
1210
- _context8.next = 34;
1111
+ _context8.next = 27;
1211
1112
  return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
1212
- case 34:
1113
+ case 27:
1213
1114
  return _context8.abrupt("return", memoryOrders);
1214
- case 35:
1115
+ case 28:
1215
1116
  case "end":
1216
1117
  return _context8.stop();
1217
1118
  }
1218
- }, _callee8, this, [[9, 19]]);
1119
+ }, _callee8, this, [[6, 16]]);
1219
1120
  }));
1220
1121
  function loadOrdersByServer() {
1221
1122
  return _loadOrdersByServer.apply(this, arguments);
@@ -1231,76 +1132,53 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1231
1132
  key: "silentRefresh",
1232
1133
  value: (function () {
1233
1134
  var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1234
- var options,
1235
- startTime,
1236
- trigger,
1237
- elapsedSinceFullFetch,
1238
- orders,
1239
- errorMessage,
1240
- _args9 = arguments;
1135
+ var startTime, elapsedSinceFullFetch, orders, errorMessage;
1241
1136
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1242
1137
  while (1) switch (_context9.prev = _context9.next) {
1243
1138
  case 0:
1244
- options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
1245
1139
  startTime = Date.now();
1246
- trigger = options.trigger || 'background';
1247
1140
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
1248
1141
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
1249
- _context9.next = 7;
1142
+ _context9.next = 4;
1250
1143
  break;
1251
1144
  }
1252
- this.logInfo('silentRefresh 跳过全量 SSE', {
1253
- trigger: trigger,
1254
- reason: 'within_min_interval',
1255
- minIntervalMs: ORDER_SILENT_REFRESH_MIN_INTERVAL_MS,
1256
- elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1257
- orderCount: this.store.list.length
1258
- });
1259
1145
  return _context9.abrupt("return", this.store.list);
1260
- case 7:
1261
- this.logInfo('silentRefresh 开始', {
1262
- trigger: trigger,
1263
- elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1264
- orderCount: this.store.list.length
1265
- });
1266
- _context9.prev = 8;
1146
+ case 4:
1147
+ this.logInfo('silentRefresh 开始');
1148
+ _context9.prev = 5;
1267
1149
  // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
1268
1150
  this.updateCreateStore();
1269
- _context9.next = 12;
1270
- return this.loadOrdersByServer({
1271
- trigger: trigger
1272
- });
1273
- case 12:
1151
+ _context9.next = 9;
1152
+ return this.loadOrdersByServer();
1153
+ case 9:
1274
1154
  orders = _context9.sent;
1275
1155
  this.store.list = cloneDeep(orders);
1276
1156
  this.syncOrdersMap();
1277
- _context9.next = 17;
1157
+ _context9.next = 14;
1278
1158
  return this.emitOrdersChanged([], 'silentRefresh');
1279
- case 17:
1280
- _context9.next = 19;
1159
+ case 14:
1160
+ _context9.next = 16;
1281
1161
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1282
- case 19:
1162
+ case 16:
1283
1163
  this.logInfo('silentRefresh 完成', {
1284
- trigger: trigger,
1285
1164
  orderCount: orders.length,
1286
1165
  duration: "".concat(Date.now() - startTime, "ms")
1287
1166
  });
1288
1167
  return _context9.abrupt("return", this.store.list);
1289
- case 23:
1290
- _context9.prev = 23;
1291
- _context9.t0 = _context9["catch"](8);
1168
+ case 20:
1169
+ _context9.prev = 20;
1170
+ _context9.t0 = _context9["catch"](5);
1292
1171
  errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
1293
1172
  this.logError('silentRefresh 失败', {
1294
- trigger: trigger,
1295
1173
  duration: "".concat(Date.now() - startTime, "ms"),
1296
1174
  error: errorMessage
1297
1175
  });
1298
1176
  return _context9.abrupt("return", this.store.list);
1299
- case 28:
1177
+ case 25:
1300
1178
  case "end":
1301
1179
  return _context9.stop();
1302
1180
  }
1303
- }, _callee9, this, [[8, 23]]);
1181
+ }, _callee9, this, [[5, 20]]);
1304
1182
  }));
1305
1183
  function silentRefresh() {
1306
1184
  return _silentRefresh.apply(this, arguments);
@@ -1312,15 +1190,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1312
1190
  value: function normalizeOrderForMemoryList(order) {
1313
1191
  var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'normalizeOrderForMemoryList';
1314
1192
  var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, source);
1315
- return this.prepareNormalizedOrderForMemoryList(normalizedOrder);
1316
- }
1317
-
1318
- /**
1319
- * 将已经完成集合规范化的订单转换为内存身份,不重复扫描 products/bookings/payments。
1320
- */
1321
- }, {
1322
- key: "prepareNormalizedOrderForMemoryList",
1323
- value: function prepareNormalizedOrderForMemoryList(normalizedOrder) {
1324
1193
  var externalSaleNumber = normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.external_sale_number;
1325
1194
  if (this.isDraftOrder(normalizedOrder) && !this.hasRealOrderId(normalizedOrder)) {
1326
1195
  return normalizedOrder;
@@ -1335,24 +1204,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1335
1204
  order_id: externalSaleNumber
1336
1205
  });
1337
1206
  }
1338
- }, {
1339
- key: "prepareNormalizedOrdersForMemoryList",
1340
- value: function prepareNormalizedOrdersForMemoryList(orders) {
1341
- var _this6 = this;
1342
- return orders.map(function (order) {
1343
- return _this6.prepareNormalizedOrderForMemoryList(order);
1344
- }).filter(function (order) {
1345
- return _this6.shouldKeepOrderInMemory(order);
1346
- });
1347
- }
1348
1207
  }, {
1349
1208
  key: "normalizeOrdersForMemoryList",
1350
1209
  value: function normalizeOrdersForMemoryList(orders, source) {
1351
- var _this7 = this;
1210
+ var _this6 = this;
1352
1211
  return orders.map(function (order) {
1353
- return _this7.normalizeOrderForMemoryList(order, source);
1212
+ return _this6.normalizeOrderForMemoryList(order, source);
1354
1213
  }).filter(function (order) {
1355
- return _this7.shouldKeepOrderInMemory(order);
1214
+ return _this6.shouldKeepOrderInMemory(order);
1356
1215
  });
1357
1216
  }
1358
1217
  }, {
@@ -1387,7 +1246,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1387
1246
  key: "overwriteExistingOrder",
1388
1247
  value: (function () {
1389
1248
  var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fresh) {
1390
- var _this8 = this;
1249
+ var _this7 = this;
1391
1250
  var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
1392
1251
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1393
1252
  while (1) switch (_context10.prev = _context10.next) {
@@ -1424,9 +1283,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1424
1283
  this.store.list = this.store.list.map(function (order) {
1425
1284
  var id = order === null || order === void 0 ? void 0 : order.order_id;
1426
1285
  if (id === undefined || id === null) {
1427
- return _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1286
+ return _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1428
1287
  }
1429
- return _this8.getIdKey(id) === key ? reconciledFresh : _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1288
+ return _this7.getIdKey(id) === key ? reconciledFresh : _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1430
1289
  });
1431
1290
  this.syncOrdersMap();
1432
1291
  _context10.next = 16;
@@ -1498,7 +1357,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1498
1357
  key: "markOrderSyncedByExternalSaleNumber",
1499
1358
  value: function () {
1500
1359
  var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
1501
- var _this9 = this,
1360
+ var _this8 = this,
1502
1361
  _existing$external_sa,
1503
1362
  _nextOrder$order_id;
1504
1363
  var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
@@ -1519,7 +1378,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1519
1378
  targetIndex = this.store.list.findIndex(function (order) {
1520
1379
  var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
1521
1380
  if (value === undefined || value === null || value === '') return false;
1522
- return _this9.getIdKey(value) === key;
1381
+ return _this8.getIdKey(value) === key;
1523
1382
  });
1524
1383
  if (!(targetIndex < 0)) {
1525
1384
  _context12.next = 9;
@@ -1577,7 +1436,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1577
1436
  key: "upsertPendingSyncOrders",
1578
1437
  value: (function () {
1579
1438
  var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(pendingOrders) {
1580
- var _this10 = this;
1439
+ var _this9 = this;
1581
1440
  var options,
1582
1441
  pendingMap,
1583
1442
  memoryPendingMap,
@@ -1673,7 +1532,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1673
1532
  });
1674
1533
  mergeActions = {};
1675
1534
  updatedList = this.store.list.map(function (order) {
1676
- return _this10.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1535
+ return _this9.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1677
1536
  }); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
1678
1537
  // 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
1679
1538
  identityKeyToIndex = new Map();
@@ -1783,7 +1642,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1783
1642
  key: "upsertLocalDraftOrders",
1784
1643
  value: (function () {
1785
1644
  var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(draftOrders) {
1786
- var _this11 = this;
1645
+ var _this10 = this;
1787
1646
  var draftMap, memoryDraftMap, _iterator9, _step9, order, draftOrder, storageKey, memoryDraftOrder, mergeActions, updatedList, identityKeyToIndex, index, _iterator10, _step10, key, _iterator11, _step11, _step11$value, _storageKey2, _draftOrder, matchIndex, existingOrder, reconciledDraftOrder, mergedOrder, nextOrder, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
1788
1647
  return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1789
1648
  while (1) switch (_context14.prev = _context14.next) {
@@ -1853,7 +1712,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1853
1712
  });
1854
1713
  mergeActions = {};
1855
1714
  updatedList = this.store.list.filter(function (order) {
1856
- return _this11.shouldKeepOrderInMemory(order);
1715
+ return _this10.shouldKeepOrderInMemory(order);
1857
1716
  });
1858
1717
  identityKeyToIndex = new Map();
1859
1718
  for (index = 0; index < updatedList.length; index += 1) {
@@ -1940,7 +1799,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1940
1799
  storeOrderCountAfter: this.store.list.length
1941
1800
  });
1942
1801
  removedLegacyMemoryDraft = previousList.some(function (order) {
1943
- return !_this11.shouldKeepOrderInMemory(order);
1802
+ return !_this10.shouldKeepOrderInMemory(order);
1944
1803
  });
1945
1804
  if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
1946
1805
  _context14.next = 84;
@@ -1948,7 +1807,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1948
1807
  }
1949
1808
  _context14.next = 84;
1950
1809
  return this.emitOrdersChanged(patchedOrders.filter(function (order) {
1951
- return _this11.shouldKeepOrderInMemory(order);
1810
+ return _this10.shouldKeepOrderInMemory(order);
1952
1811
  }), 'upsertLocalDraftOrders');
1953
1812
  case 84:
1954
1813
  case "end":
@@ -2031,9 +1890,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2031
1890
  }, {
2032
1891
  key: "syncOrdersMap",
2033
1892
  value: function syncOrdersMap() {
2034
- var _this12 = this;
1893
+ var _this11 = this;
2035
1894
  this.store.list = this.store.list.filter(function (order) {
2036
- return _this12.shouldKeepOrderInMemory(order);
1895
+ return _this11.shouldKeepOrderInMemory(order);
2037
1896
  });
2038
1897
  this.store.map.clear();
2039
1898
  var _iterator12 = _createForOfIteratorHelper(this.store.list),
@@ -2089,7 +1948,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2089
1948
  }, {
2090
1949
  key: "getOrderIdentityEntries",
2091
1950
  value: function getOrderIdentityEntries(order) {
2092
- var _this13 = this;
1951
+ var _this12 = this;
2093
1952
  if (!order) return [];
2094
1953
  var record = order;
2095
1954
  var candidates = [{
@@ -2108,8 +1967,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2108
1967
  var entries = [];
2109
1968
  var _loop = function _loop() {
2110
1969
  var candidate = _candidates[_i2];
2111
- if (_this13.isBlankIdentityValue(candidate.value)) return 0; // continue
2112
- var key = _this13.getIdKey(candidate.value);
1970
+ if (_this12.isBlankIdentityValue(candidate.value)) return 0; // continue
1971
+ var key = _this12.getIdKey(candidate.value);
2113
1972
  if (entries.some(function (entry) {
2114
1973
  return entry.field === candidate.field && entry.key === key;
2115
1974
  })) return 0; // continue
@@ -2176,7 +2035,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2176
2035
  }, {
2177
2036
  key: "setupOrderSync",
2178
2037
  value: function setupOrderSync() {
2179
- var _this14 = this;
2038
+ var _this13 = this;
2180
2039
  if (!this.orderDataSource) return;
2181
2040
  this.orderDataSource.run({
2182
2041
  pubsub: {
@@ -2184,22 +2043,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2184
2043
  var _message$id, _message$order_id, _message$type;
2185
2044
  console.log('orderDataSource', res);
2186
2045
  var pubsubReceivedAt = Date.now();
2187
- var message = _this14.normalizeOrderSyncMessage(res);
2046
+ var message = _this13.normalizeOrderSyncMessage(res);
2188
2047
  if (!message) return;
2189
2048
  message._pubsubReceivedAt = pubsubReceivedAt;
2190
- _this14.pendingSyncMessages.push(message);
2191
- var throttleMs = _this14.getOrderSyncThrottleMs();
2192
- var routeInfo = _this14.resolveSyncMessageRoute(message);
2193
- _this14.logInfo('orderSync-收到消息并入队', {
2049
+ _this13.pendingSyncMessages.push(message);
2050
+ var throttleMs = _this13.getOrderSyncThrottleMs();
2051
+ var routeInfo = _this13.resolveSyncMessageRoute(message);
2052
+ _this13.logInfo('orderSync-收到消息并入队', {
2194
2053
  id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
2195
2054
  order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
2196
2055
  type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
2197
- pendingCount: _this14.pendingSyncMessages.length,
2056
+ pendingCount: _this13.pendingSyncMessages.length,
2198
2057
  throttleMs: throttleMs,
2199
2058
  pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
2200
2059
  fullMessage: JSON.stringify(message)
2201
2060
  });
2202
- _this14.scheduleOrderSyncThrottle();
2061
+ _this13.scheduleOrderSyncThrottle();
2203
2062
  }
2204
2063
  }
2205
2064
  }).catch(function () {
@@ -2216,7 +2075,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2216
2075
  }, {
2217
2076
  key: "scheduleOrderSyncThrottle",
2218
2077
  value: function scheduleOrderSyncThrottle() {
2219
- var _this15 = this;
2078
+ var _this14 = this;
2220
2079
  if (this.isProcessingSyncBatch) return;
2221
2080
  if (this.isIdlePhase) {
2222
2081
  this.isIdlePhase = false;
@@ -2227,8 +2086,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2227
2086
  if (this.syncTimer) return;
2228
2087
  var throttleMs = this.getOrderSyncThrottleMs();
2229
2088
  this.syncTimer = setTimeout(function () {
2230
- _this15.syncTimer = undefined;
2231
- void _this15.flushOrderSyncMessagesByThrottle();
2089
+ _this14.syncTimer = undefined;
2090
+ void _this14.flushOrderSyncMessagesByThrottle();
2232
2091
  }, throttleMs);
2233
2092
  }
2234
2093
 
@@ -2296,7 +2155,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2296
2155
  key: "processOrderSyncMessages",
2297
2156
  value: (function () {
2298
2157
  var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2299
- var _this16 = this;
2158
+ var _this15 = this;
2300
2159
  var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
2301
2160
  return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2302
2161
  while (1) switch (_context17.prev = _context17.next) {
@@ -2323,13 +2182,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2323
2182
  upsertOrders = new Map();
2324
2183
  refreshIds = [];
2325
2184
  messages.forEach(function (msg, msgIndex) {
2326
- var routeInfo = _this16.resolveSyncMessageRoute(msg);
2185
+ var routeInfo = _this15.resolveSyncMessageRoute(msg);
2327
2186
  var hasBatchIds = routeInfo.hasBatchIds;
2328
2187
  var singleId = routeInfo.singleId;
2329
2188
  var hasSingleId = routeInfo.hasSingleId;
2330
- var normalizedBody = _this16.normalizeOrderSyncPayload(msg.body || msg.data);
2189
+ var normalizedBody = _this15.normalizeOrderSyncPayload(msg.body || msg.data);
2331
2190
  if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
2332
- upsertOrders.set(_this16.getIdKey(normalizedBody.order_id), normalizedBody);
2191
+ upsertOrders.set(_this15.getIdKey(normalizedBody.order_id), normalizedBody);
2333
2192
  return;
2334
2193
  }
2335
2194
  if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));else if (routeInfo.route === 'httpRefresh.singleId' && singleId !== null) refreshIds.push(singleId);else if (routeInfo.route === 'httpRefresh.relationIds') refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));
@@ -2467,8 +2326,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2467
2326
  key: "mergeOrdersToStore",
2468
2327
  value: (function () {
2469
2328
  var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(freshOrders, source) {
2470
- var _this17 = this;
2471
- var storeOrderCountBefore, normalizedFreshOrders, incomingProductsHaveStableIdentity, _iterator14, _step14, order, id, rawProducts, _incomingProductsHave, allProductsHaveStableIdentity, orderIdKey, uniqueFreshOrders, uniqueFreshCount, patchedOrders, remoteProductMembershipChanges, forceWriteStorageKeys, mergeActions, existingProductsHaveStableIdentity, updatedList, identityKeyToIndex, index, identityKeys, _iterator15, _step15, key, _iterator16, _step16, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _ref, _existingOrder$order_, _ref2, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, _ref3, _existingOrder$order_2, _ref4, _external_sale_number3, _existingOrder$is_dra, _fresh$is_draft_order, mergedOrder, freshOrderId, incomingProductsAreStable, membershipChange, mergedProductsHaveStableIdentity, adjustedMatchIndex, duplicateIndexes, _iterator17, _step17, _key2, _duplicateIndex, _iterator18, _step18, duplicateIndex, _index, _iterator19, _step19, _key, mergedStorageKey, insertIndex, insertCount, updateCount;
2329
+ var _this16 = this;
2330
+ var storeOrderCountBefore, normalizedFreshOrders, incomingProductsHaveStableIdentity, _iterator14, _step14, order, id, rawProducts, _incomingProductsHave, allProductsHaveStableIdentity, orderIdKey, uniqueFreshOrders, uniqueFreshCount, patchedOrders, remoteProductMembershipChanges, forceWriteStorageKeys, storageKeyMigrations, mergeActions, existingProductsHaveStableIdentity, updatedList, identityKeyToIndex, index, identityKeys, _iterator15, _step15, key, _iterator16, _step16, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, previousStorageKey, _ref, _existingOrder$order_, _ref2, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, _ref3, _existingOrder$order_2, _ref4, _external_sale_number3, _existingOrder$is_dra, _fresh$is_draft_order, mergedOrder, freshOrderId, incomingProductsAreStable, membershipChange, mergedProductsHaveStableIdentity, adjustedMatchIndex, duplicateIndexes, _iterator17, _step17, _key2, _duplicateIndex, _iterator18, _step18, duplicateIndex, _index, _iterator19, _step19, _key, nextStorageKey, _ref5, _ref6, _mergedOrder$order_id, mergedStorageKey, insertIndex, insertCount, updateCount;
2472
2331
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2473
2332
  while (1) switch (_context19.prev = _context19.next) {
2474
2333
  case 0:
@@ -2525,12 +2384,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2525
2384
  patchedOrders = [];
2526
2385
  remoteProductMembershipChanges = [];
2527
2386
  forceWriteStorageKeys = new Set();
2387
+ storageKeyMigrations = [];
2528
2388
  mergeActions = {};
2529
2389
  existingProductsHaveStableIdentity = this.store.list.map(function (order) {
2530
- return _this17.doProductsHaveStableMembershipIdentity(order.products);
2390
+ return _this16.doProductsHaveStableMembershipIdentity(order.products);
2531
2391
  });
2532
2392
  updatedList = this.store.list.map(function (order) {
2533
- return _this17.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2393
+ return _this16.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
2534
2394
  }); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
2535
2395
  // 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
2536
2396
  // 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
@@ -2551,11 +2411,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2551
2411
  }
2552
2412
  }
2553
2413
  _iterator16 = _createForOfIteratorHelper(uniqueFreshOrders);
2554
- _context19.prev = 37;
2414
+ _context19.prev = 38;
2555
2415
  _iterator16.s();
2556
- case 39:
2416
+ case 40:
2557
2417
  if ((_step16 = _iterator16.n()).done) {
2558
- _context19.next = 96;
2418
+ _context19.next = 100;
2559
2419
  break;
2560
2420
  }
2561
2421
  fresh = _step16.value;
@@ -2564,12 +2424,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2564
2424
  storageKey = this.getOrderStorageKey(fresh);
2565
2425
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
2566
2426
  if (!(matchIndex >= 0)) {
2567
- _context19.next = 88;
2427
+ _context19.next = 92;
2568
2428
  break;
2569
2429
  }
2570
2430
  existingOrder = updatedList[matchIndex];
2431
+ previousStorageKey = this.getPersistedOrderStorageKey(existingOrder);
2571
2432
  if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
2572
- _context19.next = 50;
2433
+ _context19.next = 52;
2573
2434
  break;
2574
2435
  }
2575
2436
  this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
@@ -2582,10 +2443,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2582
2443
  remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2583
2444
  reason: 'protect_pending_sync_order_from_remote_echo'
2584
2445
  });
2585
- return _context19.abrupt("continue", 94);
2586
- case 50:
2446
+ return _context19.abrupt("continue", 98);
2447
+ case 52:
2587
2448
  if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2588
- _context19.next = 53;
2449
+ _context19.next = 55;
2589
2450
  break;
2590
2451
  }
2591
2452
  this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
@@ -2596,8 +2457,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2596
2457
  remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
2597
2458
  reason: 'protect_draft_order_from_remote_echo'
2598
2459
  });
2599
- return _context19.abrupt("continue", 94);
2600
- case 53:
2460
+ return _context19.abrupt("continue", 98);
2461
+ case 55:
2601
2462
  mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2602
2463
  freshOrderId = fresh.order_id;
2603
2464
  incomingProductsAreStable = freshOrderId !== undefined && freshOrderId !== null && incomingProductsHaveStableIdentity.get(this.getIdKey(freshOrderId)) !== false;
@@ -2609,37 +2470,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2609
2470
  adjustedMatchIndex = matchIndex;
2610
2471
  duplicateIndexes = new Set();
2611
2472
  _iterator17 = _createForOfIteratorHelper(freshIdentityKeys);
2612
- _context19.prev = 62;
2473
+ _context19.prev = 64;
2613
2474
  _iterator17.s();
2614
- case 64:
2475
+ case 66:
2615
2476
  if ((_step17 = _iterator17.n()).done) {
2616
- _context19.next = 72;
2477
+ _context19.next = 74;
2617
2478
  break;
2618
2479
  }
2619
2480
  _key2 = _step17.value;
2620
2481
  _duplicateIndex = identityKeyToIndex.get(_key2);
2621
2482
  if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
2622
- _context19.next = 69;
2483
+ _context19.next = 71;
2623
2484
  break;
2624
2485
  }
2625
- return _context19.abrupt("continue", 70);
2626
- case 69:
2486
+ return _context19.abrupt("continue", 72);
2487
+ case 71:
2627
2488
  duplicateIndexes.add(_duplicateIndex);
2628
- case 70:
2629
- _context19.next = 64;
2630
- break;
2631
2489
  case 72:
2632
- _context19.next = 77;
2490
+ _context19.next = 66;
2633
2491
  break;
2634
2492
  case 74:
2635
- _context19.prev = 74;
2636
- _context19.t1 = _context19["catch"](62);
2493
+ _context19.next = 79;
2494
+ break;
2495
+ case 76:
2496
+ _context19.prev = 76;
2497
+ _context19.t1 = _context19["catch"](64);
2637
2498
  _iterator17.e(_context19.t1);
2638
- case 77:
2639
- _context19.prev = 77;
2499
+ case 79:
2500
+ _context19.prev = 79;
2640
2501
  _iterator17.f();
2641
- return _context19.finish(77);
2642
- case 80:
2502
+ return _context19.finish(79);
2503
+ case 82:
2643
2504
  if (duplicateIndexes.size > 0) {
2644
2505
  _iterator18 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
2645
2506
  return right - left;
@@ -2673,6 +2534,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2673
2534
  }
2674
2535
  }
2675
2536
  }
2537
+ nextStorageKey = this.getOrderStorageKey(mergedOrder);
2538
+ if (previousStorageKey && nextStorageKey && previousStorageKey !== nextStorageKey) {
2539
+ storageKeyMigrations.push({
2540
+ orderId: (_ref5 = (_ref6 = (_mergedOrder$order_id = mergedOrder.order_id) !== null && _mergedOrder$order_id !== void 0 ? _mergedOrder$order_id : existingOrder.order_id) !== null && _ref6 !== void 0 ? _ref6 : fresh.order_id) !== null && _ref5 !== void 0 ? _ref5 : null,
2541
+ from: previousStorageKey,
2542
+ to: nextStorageKey
2543
+ });
2544
+ }
2676
2545
  updatedList[adjustedMatchIndex] = mergedOrder;
2677
2546
  existingProductsHaveStableIdentity[adjustedMatchIndex] = mergedProductsHaveStableIdentity;
2678
2547
  if (membershipChange) {
@@ -2685,29 +2554,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2685
2554
  this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
2686
2555
  patchedOrders.push(mergedOrder);
2687
2556
  if (mergeKey) mergeActions[mergeKey] = 'update';
2688
- return _context19.abrupt("continue", 94);
2689
- case 88:
2557
+ return _context19.abrupt("continue", 98);
2558
+ case 92:
2690
2559
  insertIndex = updatedList.length;
2691
2560
  updatedList.push(fresh);
2692
2561
  existingProductsHaveStableIdentity.push(fresh.order_id !== undefined && fresh.order_id !== null && incomingProductsHaveStableIdentity.get(this.getIdKey(fresh.order_id)) !== false);
2693
2562
  this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
2694
2563
  patchedOrders.push(fresh);
2695
2564
  if (mergeKey) mergeActions[mergeKey] = 'insert';
2696
- case 94:
2697
- _context19.next = 39;
2565
+ case 98:
2566
+ _context19.next = 40;
2698
2567
  break;
2699
- case 96:
2700
- _context19.next = 101;
2568
+ case 100:
2569
+ _context19.next = 105;
2701
2570
  break;
2702
- case 98:
2703
- _context19.prev = 98;
2704
- _context19.t2 = _context19["catch"](37);
2571
+ case 102:
2572
+ _context19.prev = 102;
2573
+ _context19.t2 = _context19["catch"](38);
2705
2574
  _iterator16.e(_context19.t2);
2706
- case 101:
2707
- _context19.prev = 101;
2575
+ case 105:
2576
+ _context19.prev = 105;
2708
2577
  _iterator16.f();
2709
- return _context19.finish(101);
2710
- case 104:
2578
+ return _context19.finish(105);
2579
+ case 108:
2711
2580
  insertCount = Object.values(mergeActions).filter(function (v) {
2712
2581
  return v === 'insert';
2713
2582
  }).length;
@@ -2723,25 +2592,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2723
2592
  // 仅在自检开关开启时做一次兜底校验。
2724
2593
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
2725
2594
  this.syncOrdersMap();
2726
- _context19.next = 111;
2727
- return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {}, forceWriteStorageKeys);
2728
- case 111:
2595
+ _context19.next = 115;
2596
+ return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {
2597
+ storageKeyMigrations: storageKeyMigrations
2598
+ }, forceWriteStorageKeys);
2599
+ case 115:
2729
2600
  this.logInfo('mergeOrdersToStore-结束', {
2730
2601
  uniqueFreshCount: uniqueFreshCount,
2731
2602
  storeOrderCountAfter: this.store.list.length,
2732
2603
  insertCount: insertCount,
2733
2604
  updateCount: updateCount
2734
2605
  });
2735
- _context19.next = 114;
2606
+ _context19.next = 118;
2736
2607
  return this.emitRemoteProductMembershipChanges(remoteProductMembershipChanges);
2737
- case 114:
2738
- _context19.next = 116;
2608
+ case 118:
2609
+ _context19.next = 120;
2739
2610
  return this.emitOrdersChanged(patchedOrders, source);
2740
- case 116:
2611
+ case 120:
2741
2612
  case "end":
2742
2613
  return _context19.stop();
2743
2614
  }
2744
- }, _callee19, this, [[6, 20, 23, 26], [37, 98, 101, 104], [62, 74, 77, 80]]);
2615
+ }, _callee19, this, [[6, 20, 23, 26], [38, 102, 105, 108], [64, 76, 79, 82]]);
2745
2616
  }));
2746
2617
  function mergeOrdersToStore(_x13, _x14) {
2747
2618
  return _mergeOrdersToStore.apply(this, arguments);
@@ -2823,8 +2694,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2823
2694
  }, {
2824
2695
  key: "getRemoteProductMembershipChange",
2825
2696
  value: function getRemoteProductMembershipChange(existingOrder, mergedOrder, source) {
2826
- var _this18 = this,
2827
- _mergedOrder$order_id;
2697
+ var _this17 = this,
2698
+ _mergedOrder$order_id2;
2828
2699
  if (!this.isRemoteProductMembershipChangeSource(source)) return null;
2829
2700
  var previousProducts = Array.isArray(existingOrder.products) ? existingOrder.products : [];
2830
2701
  var currentProducts = Array.isArray(mergedOrder.products) ? mergedOrder.products : [];
@@ -2838,13 +2709,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2838
2709
  var _loop2 = function _loop2() {
2839
2710
  var previousProduct = _step21.value;
2840
2711
  var matchedIndex = currentProducts.findIndex(function (currentProduct, index) {
2841
- return unmatchedCurrentIndexes.has(index) && _this18.isSameProductMembershipItem(previousProduct, currentProduct);
2712
+ return unmatchedCurrentIndexes.has(index) && _this17.isSameProductMembershipItem(previousProduct, currentProduct);
2842
2713
  });
2843
2714
  if (matchedIndex >= 0) {
2844
2715
  unmatchedCurrentIndexes.delete(matchedIndex);
2845
2716
  return 1; // continue
2846
2717
  }
2847
- var productKey = _this18.getProductMembershipKey(previousProduct);
2718
+ var productKey = _this17.getProductMembershipKey(previousProduct);
2848
2719
  if (productKey) removedProductKeys.push(productKey);
2849
2720
  };
2850
2721
  for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
@@ -2856,12 +2727,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2856
2727
  _iterator21.f();
2857
2728
  }
2858
2729
  var addedProductKeys = _toConsumableArray(unmatchedCurrentIndexes).map(function (index) {
2859
- return _this18.getProductMembershipKey(currentProducts[index]);
2730
+ return _this17.getProductMembershipKey(currentProducts[index]);
2860
2731
  }).filter(Boolean);
2861
2732
  if (addedProductKeys.length === 0 && removedProductKeys.length === 0) {
2862
2733
  return null;
2863
2734
  }
2864
- var orderId = (_mergedOrder$order_id = mergedOrder.order_id) !== null && _mergedOrder$order_id !== void 0 ? _mergedOrder$order_id : existingOrder.order_id;
2735
+ var orderId = (_mergedOrder$order_id2 = mergedOrder.order_id) !== null && _mergedOrder$order_id2 !== void 0 ? _mergedOrder$order_id2 : existingOrder.order_id;
2865
2736
  if (orderId === undefined || orderId === null) return null;
2866
2737
  return {
2867
2738
  order_id: orderId,
@@ -2971,12 +2842,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2971
2842
  }, {
2972
2843
  key: "isOrderLookupMatch",
2973
2844
  value: function isOrderLookupMatch(order, lookupKey) {
2974
- var _this19 = this;
2845
+ var _this18 = this;
2975
2846
  if (!order || !lookupKey) return false;
2976
2847
  var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
2977
2848
  return candidates.some(function (value) {
2978
2849
  if (value === undefined || value === null || value === '') return false;
2979
- return _this19.getIdKey(value) === lookupKey;
2850
+ return _this18.getIdKey(value) === lookupKey;
2980
2851
  });
2981
2852
  }
2982
2853
 
@@ -3000,6 +2871,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3000
2871
  }
3001
2872
  return '';
3002
2873
  }
2874
+ }, {
2875
+ key: "getPersistedOrderStorageKey",
2876
+ value: function getPersistedOrderStorageKey(order) {
2877
+ var persistedStorageKey = order === null || order === void 0 ? void 0 : order[ORDER_STORAGE_KEY_FIELD];
2878
+ if (persistedStorageKey !== undefined && persistedStorageKey !== null && persistedStorageKey !== '') {
2879
+ return String(persistedStorageKey);
2880
+ }
2881
+ return this.getOrderStorageKey(order);
2882
+ }
3003
2883
  }, {
3004
2884
  key: "getOrderIdentityMatchKeys",
3005
2885
  value: function getOrderIdentityMatchKeys(order) {
@@ -3019,10 +2899,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3019
2899
  }, {
3020
2900
  key: "findOrderIndexByIdentity",
3021
2901
  value: function findOrderIndexByIdentity(orders, target) {
3022
- var _this20 = this;
2902
+ var _this19 = this;
3023
2903
  if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
3024
2904
  return orders.findIndex(function (order) {
3025
- return _this20.doOrdersShareIdentity(order, target);
2905
+ return _this19.doOrdersShareIdentity(order, target);
3026
2906
  });
3027
2907
  }
3028
2908
  }, {
@@ -3201,10 +3081,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3201
3081
  if (_field2 === 'payments') {
3202
3082
  var preservedPending = this.getUnmatchedIdentifiedPendingPayments(existingRecord[_field2], incomingRecord[_field2]);
3203
3083
  if (preservedPending.length > 0) {
3204
- var _ref5, _existing$order_id, _ref6, _existingRecord$exter;
3084
+ var _ref7, _existing$order_id, _ref8, _existingRecord$exter;
3205
3085
  this.logInfo('mergeOrderRecords-保留本地 pending 支付项', {
3206
- order_id: (_ref5 = (_existing$order_id = existing.order_id) !== null && _existing$order_id !== void 0 ? _existing$order_id : incoming.order_id) !== null && _ref5 !== void 0 ? _ref5 : null,
3207
- external_sale_number: (_ref6 = (_existingRecord$exter = existingRecord.external_sale_number) !== null && _existingRecord$exter !== void 0 ? _existingRecord$exter : incomingRecord.external_sale_number) !== null && _ref6 !== void 0 ? _ref6 : null,
3086
+ order_id: (_ref7 = (_existing$order_id = existing.order_id) !== null && _existing$order_id !== void 0 ? _existing$order_id : incoming.order_id) !== null && _ref7 !== void 0 ? _ref7 : null,
3087
+ external_sale_number: (_ref8 = (_existingRecord$exter = existingRecord.external_sale_number) !== null && _existingRecord$exter !== void 0 ? _existingRecord$exter : incomingRecord.external_sale_number) !== null && _ref8 !== void 0 ? _ref8 : null,
3208
3088
  preserved_pending_count: preservedPending.length,
3209
3089
  preserved_payment_identities: preservedPending.map(function (payment) {
3210
3090
  return getOrderPaymentIdentityKeys(payment);
@@ -3257,14 +3137,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3257
3137
  } finally {
3258
3138
  _iterator28.f();
3259
3139
  }
3260
- return _toConsumableArray(groups.entries()).filter(function (_ref7) {
3261
- var _ref8 = _slicedToArray(_ref7, 2),
3262
- group = _ref8[1];
3263
- return group.length > 1;
3264
- }).slice(0, 20).map(function (_ref9) {
3140
+ return _toConsumableArray(groups.entries()).filter(function (_ref9) {
3265
3141
  var _ref10 = _slicedToArray(_ref9, 2),
3266
- key = _ref10[0],
3267
3142
  group = _ref10[1];
3143
+ return group.length > 1;
3144
+ }).slice(0, 20).map(function (_ref11) {
3145
+ var _ref12 = _slicedToArray(_ref11, 2),
3146
+ key = _ref12[0],
3147
+ group = _ref12[1];
3268
3148
  return {
3269
3149
  key: key,
3270
3150
  count: group.length,
@@ -3334,32 +3214,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3334
3214
  }
3335
3215
 
3336
3216
  /**
3337
- * 当前订单缓存可复用窗口。
3338
- * start_time 模式使用精确的营业日起止时间;配置缺失或异常时退化为自然日。
3217
+ * 当前订单拉取窗口:
3218
+ * - 优先使用 createdAtQuery.sales_time_between(已按营业日边界初始化)
3219
+ * - 无法解析时退化为自然日窗口
3339
3220
  */
3340
3221
  }, {
3341
- key: "getCurrentOrderCacheWindow",
3342
- value: function getCurrentOrderCacheWindow() {
3222
+ key: "getCurrentPullWindow",
3223
+ value: function getCurrentPullWindow() {
3224
+ var _this$store2;
3343
3225
  var now = dayjs();
3344
- try {
3345
- var _coreData$core;
3346
- var appPlugin = this.core.getPlugin('app');
3347
- var app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
3348
- var coreData = app === null || app === void 0 ? void 0 : app.data.store.getStore().getDataByModel('core');
3349
- var boundary = coreData === null || coreData === void 0 || (_coreData$core = coreData.core) === null || _coreData$core === void 0 ? void 0 : _coreData$core.operating_day_boundary;
3350
- if ((boundary === null || boundary === void 0 ? void 0 : boundary.type) === 'start_time') {
3351
- var boundaryTime = String(boundary.time || '').trim();
3352
- var todayBoundary = dayjs("".concat(now.format('YYYY-MM-DD'), " ").concat(boundaryTime));
3353
- if (todayBoundary.isValid()) {
3354
- var _startAt = now.isBefore(todayBoundary) ? todayBoundary.subtract(1, 'day') : todayBoundary;
3355
- return {
3356
- startAt: _startAt,
3357
- endExclusiveAt: _startAt.add(1, 'day')
3358
- };
3359
- }
3226
+ var range = (_this$store2 = this.store) === null || _this$store2 === void 0 || (_this$store2 = _this$store2.createdAtQuery) === null || _this$store2 === void 0 ? void 0 : _this$store2.sales_time_between;
3227
+ if (Array.isArray(range) && range.length >= 2) {
3228
+ var _startAt = dayjs(range[0]);
3229
+ var endExclusiveAt = dayjs(range[1]);
3230
+ if (_startAt.isValid() && endExclusiveAt.isValid() && endExclusiveAt.isAfter(_startAt)) {
3231
+ return {
3232
+ startAt: _startAt,
3233
+ endExclusiveAt: endExclusiveAt
3234
+ };
3360
3235
  }
3361
- } catch (_unused6) {
3362
- // 读取营业日配置失败时按自然日兜底,不影响启动。
3363
3236
  }
3364
3237
  var startAt = now.startOf('day');
3365
3238
  return {
@@ -3372,47 +3245,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3372
3245
  value: function hasPulledOrdersToday() {
3373
3246
  var lastFullFetchAt = this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY);
3374
3247
  if (!lastFullFetchAt) return false;
3375
- var currentShopId = this.getCurrentShopId();
3376
- var lastFullFetchShopId = this.getStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY);
3377
- if (!currentShopId || !lastFullFetchShopId || currentShopId !== lastFullFetchShopId) {
3378
- return false;
3379
- }
3380
3248
  var parsed = dayjs(lastFullFetchAt);
3381
3249
  if (!parsed.isValid()) return false;
3382
- var _this$getCurrentOrder = this.getCurrentOrderCacheWindow(),
3383
- startAt = _this$getCurrentOrder.startAt,
3384
- endExclusiveAt = _this$getCurrentOrder.endExclusiveAt;
3250
+
3251
+ // 按当前拉取窗口判断,而不是自然日判断。
3252
+ // 这样在营业日跨日边界(start_time)场景下也能正确判定是否需要重新拉取。
3253
+ var _this$getCurrentPullW = this.getCurrentPullWindow(),
3254
+ startAt = _this$getCurrentPullW.startAt,
3255
+ endExclusiveAt = _this$getCurrentPullW.endExclusiveAt;
3385
3256
  return (parsed.isAfter(startAt) || parsed.isSame(startAt)) && parsed.isBefore(endExclusiveAt);
3386
3257
  }
3387
3258
  }, {
3388
3259
  key: "markOrderPulledAtNow",
3389
3260
  value: function markOrderPulledAtNow() {
3390
- var currentShopId = this.getCurrentShopId();
3391
- if (!currentShopId) return;
3392
3261
  this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, dayjs().format('YYYY-MM-DD HH:mm:ss'));
3393
- this.setStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY, currentShopId);
3394
- }
3395
- }, {
3396
- key: "clearOrderSnapshotMarker",
3397
- value: function clearOrderSnapshotMarker() {
3398
- this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
3399
- this.setStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY, '');
3400
- }
3401
- }, {
3402
- key: "getCurrentShopId",
3403
- value: function getCurrentShopId() {
3404
- try {
3405
- var _coreData$core2;
3406
- var appPlugin = this.core.getPlugin('app');
3407
- var app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
3408
- if (!app) return null;
3409
- var coreData = app.data.store.getStore().getDataByModel('core');
3410
- var shopId = coreData === null || coreData === void 0 || (_coreData$core2 = coreData.core) === null || _coreData$core2 === void 0 ? void 0 : _coreData$core2.id;
3411
- if (shopId === undefined || shopId === null || shopId === '') return null;
3412
- return String(shopId);
3413
- } catch (_unused7) {
3414
- return null;
3415
- }
3416
3262
  }
3417
3263
  }, {
3418
3264
  key: "getStorageItem",
@@ -3423,7 +3269,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3423
3269
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
3424
3270
  return globalThis.localStorage.getItem(key);
3425
3271
  }
3426
- } catch (_unused8) {
3272
+ } catch (_unused6) {
3427
3273
  // 忽略存储异常,避免影响主流程
3428
3274
  }
3429
3275
  return null;
@@ -3440,7 +3286,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3440
3286
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
3441
3287
  globalThis.localStorage.setItem(key, value);
3442
3288
  }
3443
- } catch (_unused9) {
3289
+ } catch (_unused7) {
3444
3290
  // 忽略存储异常,避免影响主流程
3445
3291
  }
3446
3292
  }
@@ -3448,61 +3294,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3448
3294
  key: "loadOrdersFromSQLite",
3449
3295
  value: function () {
3450
3296
  var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
3451
- var _this21 = this;
3452
- var options,
3453
- _options$onTiming,
3454
- loadStartedAt,
3455
- rawReadStartedAt,
3456
- orders,
3457
- sqliteRawReadMs,
3458
- normalizeStartedAt,
3459
- normalizedOrders,
3460
- sqliteNormalizeMs,
3461
- _args20 = arguments;
3297
+ var _this20 = this;
3298
+ var orders;
3462
3299
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
3463
3300
  while (1) switch (_context20.prev = _context20.next) {
3464
3301
  case 0:
3465
- options = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {};
3466
3302
  if (this.dbManager) {
3467
- _context20.next = 3;
3303
+ _context20.next = 2;
3468
3304
  break;
3469
3305
  }
3470
3306
  return _context20.abrupt("return", []);
3471
- case 3:
3472
- _context20.prev = 3;
3473
- loadStartedAt = performance.now();
3474
- rawReadStartedAt = performance.now();
3475
- _context20.next = 8;
3307
+ case 2:
3308
+ _context20.prev = 2;
3309
+ _context20.next = 5;
3476
3310
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
3477
- case 8:
3311
+ case 5:
3478
3312
  orders = _context20.sent;
3479
- sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3480
- normalizeStartedAt = performance.now();
3481
- normalizedOrders = (orders || []).map(function (order) {
3482
- return _this21.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3483
- });
3484
- sqliteNormalizeMs = +(performance.now() - normalizeStartedAt).toFixed(2);
3485
- (_options$onTiming = options.onTiming) === null || _options$onTiming === void 0 || _options$onTiming.call(options, {
3486
- sqliteRawReadMs: sqliteRawReadMs,
3487
- sqliteNormalizeMs: sqliteNormalizeMs,
3488
- sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
3489
- });
3490
- return _context20.abrupt("return", normalizedOrders);
3491
- case 17:
3492
- _context20.prev = 17;
3493
- _context20.t0 = _context20["catch"](3);
3494
- if (!options.throwOnError) {
3495
- _context20.next = 21;
3496
- break;
3497
- }
3498
- throw _context20.t0;
3499
- case 21:
3313
+ return _context20.abrupt("return", (orders || []).map(function (order) {
3314
+ return _this20.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3315
+ }));
3316
+ case 9:
3317
+ _context20.prev = 9;
3318
+ _context20.t0 = _context20["catch"](2);
3500
3319
  return _context20.abrupt("return", []);
3501
- case 22:
3320
+ case 12:
3502
3321
  case "end":
3503
3322
  return _context20.stop();
3504
3323
  }
3505
- }, _callee20, this, [[3, 17]]);
3324
+ }, _callee20, this, [[2, 9]]);
3506
3325
  }));
3507
3326
  function loadOrdersFromSQLite() {
3508
3327
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -3552,9 +3371,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3552
3371
  }, {
3553
3372
  key: "mergeRemoteSnapshotWithPendingOrders",
3554
3373
  value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
3555
- var _this22 = this;
3374
+ var _this21 = this;
3556
3375
  var merged = remoteOrders.map(function (order) {
3557
- return _this22.normalizeRemoteSyncedOrder(order);
3376
+ return _this21.normalizeRemoteSyncedOrder(order);
3558
3377
  });
3559
3378
  var _iterator31 = _createForOfIteratorHelper(existingOrders),
3560
3379
  _step31;
@@ -3628,15 +3447,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3628
3447
  key: "patchOrdersInSQLite",
3629
3448
  value: (function () {
3630
3449
  var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(orders, source) {
3631
- var _this23 = this;
3450
+ var _this22 = this;
3632
3451
  var mergeActions,
3633
3452
  options,
3634
3453
  forceWriteStorageKeys,
3454
+ migrationTargetStorageKeys,
3635
3455
  ordersSnapshot,
3636
3456
  _this$filterRedundant2,
3637
3457
  toWrite,
3638
3458
  skipped,
3639
3459
  compactedToWrite,
3460
+ writtenStorageKeys,
3461
+ storageKeyMigrations,
3462
+ _iterator32,
3463
+ _step32,
3464
+ migration,
3640
3465
  _args23 = arguments;
3641
3466
  return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3642
3467
  while (1) switch (_context23.prev = _context23.next) {
@@ -3662,82 +3487,130 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3662
3487
  case 8:
3663
3488
  return _context23.abrupt("return");
3664
3489
  case 9:
3490
+ migrationTargetStorageKeys = new Set((options.storageKeyMigrations || []).map(function (migration) {
3491
+ return migration.to;
3492
+ }));
3665
3493
  ordersSnapshot = cloneDeep(orders).map(function (order) {
3666
- return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
3494
+ return _this22.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
3495
+ }).map(function (order) {
3496
+ var storageKey = _this22.getOrderStorageKey(order);
3497
+ if (!storageKey || !migrationTargetStorageKeys.has(storageKey)) return order;
3498
+ return _objectSpread(_objectSpread({}, order), {}, _defineProperty({}, ORDER_STORAGE_KEY_FIELD, storageKey));
3667
3499
  }).filter(function (order) {
3668
- return _this23.getOrderStorageKey(order);
3500
+ return _this22.getOrderStorageKey(order);
3669
3501
  });
3670
3502
  if (!(ordersSnapshot.length === 0)) {
3671
- _context23.next = 12;
3503
+ _context23.next = 13;
3672
3504
  break;
3673
3505
  }
3674
3506
  return _context23.abrupt("return");
3675
- case 12:
3507
+ case 13:
3676
3508
  _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
3677
3509
  if (!(toWrite.length === 0)) {
3678
- _context23.next = 15;
3510
+ _context23.next = 16;
3679
3511
  break;
3680
3512
  }
3681
3513
  return _context23.abrupt("return");
3682
- case 15:
3514
+ case 16:
3683
3515
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
3684
3516
  if (!(compactedToWrite.length === 0)) {
3685
- _context23.next = 18;
3517
+ _context23.next = 19;
3686
3518
  break;
3687
3519
  }
3688
3520
  return _context23.abrupt("return");
3689
- case 18:
3690
- _context23.prev = 18;
3691
- _context23.next = 21;
3521
+ case 19:
3522
+ writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
3523
+ return _this22.getOrderStorageKey(order);
3524
+ }).filter(Boolean));
3525
+ storageKeyMigrations = new Map();
3526
+ _iterator32 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
3527
+ _context23.prev = 22;
3528
+ _iterator32.s();
3529
+ case 24:
3530
+ if ((_step32 = _iterator32.n()).done) {
3531
+ _context23.next = 33;
3532
+ break;
3533
+ }
3534
+ migration = _step32.value;
3535
+ if (writtenStorageKeys.has(migration.to)) {
3536
+ _context23.next = 28;
3537
+ break;
3538
+ }
3539
+ return _context23.abrupt("continue", 31);
3540
+ case 28:
3541
+ if (!writtenStorageKeys.has(migration.from)) {
3542
+ _context23.next = 30;
3543
+ break;
3544
+ }
3545
+ return _context23.abrupt("continue", 31);
3546
+ case 30:
3547
+ storageKeyMigrations.set(migration.from, migration);
3548
+ case 31:
3549
+ _context23.next = 24;
3550
+ break;
3551
+ case 33:
3552
+ _context23.next = 38;
3553
+ break;
3554
+ case 35:
3555
+ _context23.prev = 35;
3556
+ _context23.t0 = _context23["catch"](22);
3557
+ _iterator32.e(_context23.t0);
3558
+ case 38:
3559
+ _context23.prev = 38;
3560
+ _iterator32.f();
3561
+ return _context23.finish(38);
3562
+ case 41:
3563
+ _context23.prev = 41;
3564
+ _context23.next = 44;
3692
3565
  return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
3693
- var writeMethod, _iterator32, _step32, order;
3566
+ var writeMethod, _iterator33, _step33, order, _iterator34, _step34, migration, _iterator35, _step35, _orderRecord$ORDER_ST, _order, orderRecord;
3694
3567
  return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3695
3568
  while (1) switch (_context22.prev = _context22.next) {
3696
3569
  case 0:
3697
3570
  writeMethod = 'none';
3698
- _this23.logInfo('patchOrdersInSQLite-开始', {
3571
+ _this22.logInfo('patchOrdersInSQLite-开始', {
3699
3572
  source: source,
3700
3573
  count: compactedToWrite.length,
3701
3574
  dedupedCount: skipped.length
3702
3575
  });
3703
- if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
3576
+ if (!(typeof _this22.dbManager.bulkUpdate === 'function')) {
3704
3577
  _context22.next = 8;
3705
3578
  break;
3706
3579
  }
3707
3580
  writeMethod = 'bulkUpdate';
3708
3581
  _context22.next = 6;
3709
- return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3582
+ return _this22.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3710
3583
  case 6:
3711
3584
  _context22.next = 37;
3712
3585
  break;
3713
3586
  case 8:
3714
- if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
3587
+ if (!(typeof _this22.dbManager.bulkAdd === 'function')) {
3715
3588
  _context22.next = 14;
3716
3589
  break;
3717
3590
  }
3718
3591
  writeMethod = 'bulkAdd';
3719
3592
  _context22.next = 12;
3720
- return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3593
+ return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3721
3594
  case 12:
3722
3595
  _context22.next = 37;
3723
3596
  break;
3724
3597
  case 14:
3725
- if (!(typeof _this23.dbManager.update === 'function')) {
3598
+ if (!(typeof _this22.dbManager.update === 'function')) {
3726
3599
  _context22.next = 35;
3727
3600
  break;
3728
3601
  }
3729
3602
  writeMethod = 'update';
3730
- _iterator32 = _createForOfIteratorHelper(compactedToWrite);
3603
+ _iterator33 = _createForOfIteratorHelper(compactedToWrite);
3731
3604
  _context22.prev = 17;
3732
- _iterator32.s();
3605
+ _iterator33.s();
3733
3606
  case 19:
3734
- if ((_step32 = _iterator32.n()).done) {
3607
+ if ((_step33 = _iterator33.n()).done) {
3735
3608
  _context22.next = 25;
3736
3609
  break;
3737
3610
  }
3738
- order = _step32.value;
3611
+ order = _step33.value;
3739
3612
  _context22.next = 23;
3740
- return _this23.dbManager.update(INDEXDB_STORE_NAME, order);
3613
+ return _this22.dbManager.update(INDEXDB_STORE_NAME, order);
3741
3614
  case 23:
3742
3615
  _context22.next = 19;
3743
3616
  break;
@@ -3747,10 +3620,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3747
3620
  case 27:
3748
3621
  _context22.prev = 27;
3749
3622
  _context22.t0 = _context22["catch"](17);
3750
- _iterator32.e(_context22.t0);
3623
+ _iterator33.e(_context22.t0);
3751
3624
  case 30:
3752
3625
  _context22.prev = 30;
3753
- _iterator32.f();
3626
+ _iterator33.f();
3754
3627
  return _context22.finish(30);
3755
3628
  case 33:
3756
3629
  _context22.next = 37;
@@ -3762,39 +3635,122 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3762
3635
  }
3763
3636
  throw new Error('订单 SQLite 数据库不支持写入');
3764
3637
  case 37:
3765
- _this23.recordRecentSqliteWrite(source, compactedToWrite);
3766
- _this23.logInfo('patchOrdersInSQLite-完成', {
3638
+ _this22.recordRecentSqliteWrite(source, compactedToWrite);
3639
+ if (!(writeMethod !== 'none')) {
3640
+ _context22.next = 84;
3641
+ break;
3642
+ }
3643
+ _iterator34 = _createForOfIteratorHelper(storageKeyMigrations.values());
3644
+ _context22.prev = 40;
3645
+ _iterator34.s();
3646
+ case 42:
3647
+ if ((_step34 = _iterator34.n()).done) {
3648
+ _context22.next = 76;
3649
+ break;
3650
+ }
3651
+ migration = _step34.value;
3652
+ _context22.prev = 44;
3653
+ _context22.next = 47;
3654
+ return _this22.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
3655
+ case 47:
3656
+ _this22.recentSqliteWriteByStorageKey.delete(migration.from);
3657
+ _iterator35 = _createForOfIteratorHelper(orders);
3658
+ _context22.prev = 49;
3659
+ _iterator35.s();
3660
+ case 51:
3661
+ if ((_step35 = _iterator35.n()).done) {
3662
+ _context22.next = 61;
3663
+ break;
3664
+ }
3665
+ _order = _step35.value;
3666
+ if (!(_this22.getOrderStorageKey(_order) !== migration.to)) {
3667
+ _context22.next = 55;
3668
+ break;
3669
+ }
3670
+ return _context22.abrupt("continue", 59);
3671
+ case 55:
3672
+ orderRecord = _order;
3673
+ if (!(String((_orderRecord$ORDER_ST = orderRecord[ORDER_STORAGE_KEY_FIELD]) !== null && _orderRecord$ORDER_ST !== void 0 ? _orderRecord$ORDER_ST : '') !== migration.from)) {
3674
+ _context22.next = 58;
3675
+ break;
3676
+ }
3677
+ return _context22.abrupt("continue", 59);
3678
+ case 58:
3679
+ orderRecord[ORDER_STORAGE_KEY_FIELD] = migration.to;
3680
+ case 59:
3681
+ _context22.next = 51;
3682
+ break;
3683
+ case 61:
3684
+ _context22.next = 66;
3685
+ break;
3686
+ case 63:
3687
+ _context22.prev = 63;
3688
+ _context22.t1 = _context22["catch"](49);
3689
+ _iterator35.e(_context22.t1);
3690
+ case 66:
3691
+ _context22.prev = 66;
3692
+ _iterator35.f();
3693
+ return _context22.finish(66);
3694
+ case 69:
3695
+ _context22.next = 74;
3696
+ break;
3697
+ case 71:
3698
+ _context22.prev = 71;
3699
+ _context22.t2 = _context22["catch"](44);
3700
+ _this22.logError('删除订单旧 SQLite storage key 失败', {
3701
+ source: source,
3702
+ order_id: migration.orderId,
3703
+ oldStorageKey: migration.from,
3704
+ newStorageKey: migration.to,
3705
+ error: _context22.t2 instanceof Error ? _context22.t2.message : String(_context22.t2)
3706
+ });
3707
+ case 74:
3708
+ _context22.next = 42;
3709
+ break;
3710
+ case 76:
3711
+ _context22.next = 81;
3712
+ break;
3713
+ case 78:
3714
+ _context22.prev = 78;
3715
+ _context22.t3 = _context22["catch"](40);
3716
+ _iterator34.e(_context22.t3);
3717
+ case 81:
3718
+ _context22.prev = 81;
3719
+ _iterator34.f();
3720
+ return _context22.finish(81);
3721
+ case 84:
3722
+ _this22.logInfo('patchOrdersInSQLite-完成', {
3767
3723
  source: source,
3768
3724
  count: compactedToWrite.length,
3769
3725
  writeMethod: writeMethod,
3770
3726
  dedupedCount: skipped.length
3771
3727
  });
3772
- case 39:
3728
+ case 85:
3773
3729
  case "end":
3774
3730
  return _context22.stop();
3775
3731
  }
3776
- }, _callee22, null, [[17, 27, 30, 33]]);
3732
+ }, _callee22, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
3777
3733
  })));
3778
- case 21:
3779
- _context23.next = 28;
3734
+ case 44:
3735
+ _context23.next = 51;
3780
3736
  break;
3781
- case 23:
3782
- _context23.prev = 23;
3783
- _context23.t0 = _context23["catch"](18);
3737
+ case 46:
3738
+ _context23.prev = 46;
3739
+ _context23.t1 = _context23["catch"](41);
3784
3740
  this.logError('增量保存订单到 SQLite 失败', {
3785
- error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
3741
+ error: _context23.t1 instanceof Error ? _context23.t1.message : String(_context23.t1),
3786
3742
  orderCount: ordersSnapshot.length
3787
3743
  });
3788
3744
  if (!options.throwOnError) {
3789
- _context23.next = 28;
3745
+ _context23.next = 51;
3790
3746
  break;
3791
3747
  }
3792
- throw _context23.t0;
3793
- case 28:
3748
+ throw _context23.t1;
3749
+ case 51:
3794
3750
  case "end":
3795
3751
  return _context23.stop();
3796
3752
  }
3797
- }, _callee23, this, [[18, 23]]);
3753
+ }, _callee23, this, [[22, 35, 38, 41], [41, 46]]);
3798
3754
  }));
3799
3755
  function patchOrdersInSQLite(_x16, _x17) {
3800
3756
  return _patchOrdersInSQLite.apply(this, arguments);
@@ -3812,7 +3768,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3812
3768
  key: "updateOrderInSQLite",
3813
3769
  value: (function () {
3814
3770
  var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order, source) {
3815
- var _this24 = this;
3771
+ var _this23 = this;
3816
3772
  var options,
3817
3773
  orderSnapshot,
3818
3774
  _orderSnapshot$order_3,
@@ -3855,40 +3811,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3855
3811
  while (1) switch (_context24.prev = _context24.next) {
3856
3812
  case 0:
3857
3813
  writeMethod = 'none';
3858
- _this24.logInfo('updateOrderInSQLite-开始', {
3814
+ _this23.logInfo('updateOrderInSQLite-开始', {
3859
3815
  source: source,
3860
3816
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
3861
- storageKey: _this24.getOrderStorageKey(orderSnapshot)
3817
+ storageKey: _this23.getOrderStorageKey(orderSnapshot)
3862
3818
  });
3863
- if (!(typeof _this24.dbManager.update === 'function')) {
3819
+ if (!(typeof _this23.dbManager.update === 'function')) {
3864
3820
  _context24.next = 8;
3865
3821
  break;
3866
3822
  }
3867
3823
  writeMethod = 'update';
3868
3824
  _context24.next = 6;
3869
- return _this24.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
3825
+ return _this23.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
3870
3826
  case 6:
3871
3827
  _context24.next = 22;
3872
3828
  break;
3873
3829
  case 8:
3874
- if (!(typeof _this24.dbManager.bulkUpdate === 'function')) {
3830
+ if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
3875
3831
  _context24.next = 14;
3876
3832
  break;
3877
3833
  }
3878
3834
  writeMethod = 'bulkUpdate';
3879
3835
  _context24.next = 12;
3880
- return _this24.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
3836
+ return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
3881
3837
  case 12:
3882
3838
  _context24.next = 22;
3883
3839
  break;
3884
3840
  case 14:
3885
- if (!(typeof _this24.dbManager.bulkAdd === 'function')) {
3841
+ if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
3886
3842
  _context24.next = 20;
3887
3843
  break;
3888
3844
  }
3889
3845
  writeMethod = 'bulkAdd';
3890
3846
  _context24.next = 18;
3891
- return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
3847
+ return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
3892
3848
  case 18:
3893
3849
  _context24.next = 22;
3894
3850
  break;
@@ -3899,8 +3855,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3899
3855
  }
3900
3856
  throw new Error('订单 SQLite 数据库不支持写入');
3901
3857
  case 22:
3902
- _this24.recordRecentSqliteWrite(source, [orderSnapshot]);
3903
- _this24.logInfo('updateOrderInSQLite-完成', {
3858
+ _this23.recordRecentSqliteWrite(source, [orderSnapshot]);
3859
+ _this23.logInfo('updateOrderInSQLite-完成', {
3904
3860
  source: source,
3905
3861
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
3906
3862
  writeMethod: writeMethod
@@ -3942,18 +3898,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3942
3898
  * 用于 SSE 全量拉取与营业日窗口裁剪。
3943
3899
  *
3944
3900
  * @example
3945
- * const { orders, persisted } = await this.replaceOrdersSnapshotInSQLite(orderList, 'refresh')
3901
+ * await this.replaceOrdersSnapshotInSQLite(orderList)
3946
3902
  */
3947
3903
  )
3948
3904
  }, {
3949
3905
  key: "replaceOrdersSnapshotInSQLite",
3950
3906
  value: (function () {
3951
3907
  var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orderList, source) {
3952
- var _this25 = this;
3908
+ var _this24 = this;
3953
3909
  var protectedOrdersBeforeRemoteFetch,
3954
3910
  remoteSnapshot,
3955
3911
  mergedSnapshot,
3956
- persisted,
3957
3912
  _args27 = arguments;
3958
3913
  return _regeneratorRuntime().wrap(function _callee27$(_context27) {
3959
3914
  while (1) switch (_context27.prev = _context27.next) {
@@ -3963,33 +3918,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3963
3918
  _context27.next = 3;
3964
3919
  break;
3965
3920
  }
3966
- return _context27.abrupt("return", {
3967
- orders: this.compactOrderListByIdentity(orderList.map(function (order) {
3968
- return _this25.normalizeRemoteSyncedOrder(order);
3969
- }), "".concat(source, ".snapshotNoDb")).list,
3970
- persisted: false
3971
- });
3921
+ return _context27.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
3922
+ return _this24.normalizeRemoteSyncedOrder(order);
3923
+ }), "".concat(source, ".snapshotNoDb")).list);
3972
3924
  case 3:
3973
3925
  remoteSnapshot = cloneDeep(orderList).map(function (order) {
3974
- return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
3926
+ return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
3975
3927
  });
3976
3928
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
3977
- return _this25.normalizeRemoteSyncedOrder(order);
3929
+ return _this24.normalizeRemoteSyncedOrder(order);
3978
3930
  }), "".concat(source, ".remoteSnapshot")).list;
3979
- persisted = false;
3980
- _context27.prev = 6;
3981
- _context27.next = 9;
3931
+ _context27.prev = 5;
3932
+ _context27.next = 8;
3982
3933
  return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
3983
- var existingOrders, protectedLocalOrders, _iterator33, _step33, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
3934
+ var existingOrders, protectedLocalOrders, _iterator36, _step36, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
3984
3935
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3985
3936
  while (1) switch (_context26.prev = _context26.next) {
3986
3937
  case 0:
3987
- if (!(typeof _this25.dbManager.getAll === 'function')) {
3938
+ if (!(typeof _this24.dbManager.getAll === 'function')) {
3988
3939
  _context26.next = 6;
3989
3940
  break;
3990
3941
  }
3991
3942
  _context26.next = 3;
3992
- return _this25.dbManager.getAll(INDEXDB_STORE_NAME);
3943
+ return _this24.dbManager.getAll(INDEXDB_STORE_NAME);
3993
3944
  case 3:
3994
3945
  _context26.t0 = _context26.sent;
3995
3946
  _context26.next = 7;
@@ -3999,22 +3950,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3999
3950
  case 7:
4000
3951
  existingOrders = _context26.t0;
4001
3952
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
4002
- return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
3953
+ return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4003
3954
  }).filter(function (order) {
4004
- return _this25.shouldProtectLocalOrderFromRemoteSnapshot(order);
3955
+ return _this24.shouldProtectLocalOrderFromRemoteSnapshot(order);
4005
3956
  });
4006
- _iterator33 = _createForOfIteratorHelper(existingOrders || []);
3957
+ _iterator36 = _createForOfIteratorHelper(existingOrders || []);
4007
3958
  _context26.prev = 10;
4008
- _iterator33.s();
3959
+ _iterator36.s();
4009
3960
  case 12:
4010
- if ((_step33 = _iterator33.n()).done) {
3961
+ if ((_step36 = _iterator36.n()).done) {
4011
3962
  _context26.next = 23;
4012
3963
  break;
4013
3964
  }
4014
- rawCurrentOrder = _step33.value;
4015
- currentOrder = _this25.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
4016
- protectedIndex = _this25.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4017
- currentNeedsProtection = _this25.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
3965
+ rawCurrentOrder = _step36.value;
3966
+ currentOrder = _this24.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
3967
+ protectedIndex = _this24.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
3968
+ currentNeedsProtection = _this24.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4018
3969
  if (!(protectedIndex >= 0)) {
4019
3970
  _context26.next = 20;
4020
3971
  break;
@@ -4036,15 +3987,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4036
3987
  case 25:
4037
3988
  _context26.prev = 25;
4038
3989
  _context26.t1 = _context26["catch"](10);
4039
- _iterator33.e(_context26.t1);
3990
+ _iterator36.e(_context26.t1);
4040
3991
  case 28:
4041
3992
  _context26.prev = 28;
4042
- _iterator33.f();
3993
+ _iterator36.f();
4043
3994
  return _context26.finish(28);
4044
3995
  case 31:
4045
- orderListSnapshot = _this25.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
4046
- mergedSnapshot = _this25.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
4047
- _this25.logInfo('replaceOrdersSnapshotInSQLite-开始', {
3996
+ orderListSnapshot = _this24.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
3997
+ mergedSnapshot = _this24.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
3998
+ _this24.logInfo('replaceOrdersSnapshotInSQLite-开始', {
4048
3999
  source: source,
4049
4000
  count: mergedSnapshot.length,
4050
4001
  remoteCount: remoteSnapshot.length,
@@ -4052,10 +4003,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4052
4003
  protectedLocalOrderCount: protectedLocalOrders.length,
4053
4004
  preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
4054
4005
  protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
4055
- return count + _this25.getIdentifiedPendingPayments(order).length;
4006
+ return count + _this24.getIdentifiedPendingPayments(order).length;
4056
4007
  }, 0),
4057
4008
  protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
4058
- return _this25.getIdentifiedPendingPayments(order).map(function (payment) {
4009
+ return _this24.getIdentifiedPendingPayments(order).map(function (payment) {
4059
4010
  var _order$order_id5, _external_sale_number5;
4060
4011
  return {
4061
4012
  order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
@@ -4066,9 +4017,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4066
4017
  })
4067
4018
  });
4068
4019
  _context26.next = 36;
4069
- return _this25.dbManager.clear(INDEXDB_STORE_NAME);
4020
+ return _this24.dbManager.clear(INDEXDB_STORE_NAME);
4070
4021
  case 36:
4071
- _this25.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4022
+ _this24.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4072
4023
  count: mergedSnapshot.length
4073
4024
  });
4074
4025
  if (!(mergedSnapshot.length === 0)) {
@@ -4078,10 +4029,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4078
4029
  return _context26.abrupt("return");
4079
4030
  case 39:
4080
4031
  _context26.next = 41;
4081
- return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4032
+ return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4082
4033
  case 41:
4083
- _this25.recordRecentSqliteWrite(source, mergedSnapshot);
4084
- _this25.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4034
+ _this24.recordRecentSqliteWrite(source, mergedSnapshot);
4035
+ _this24.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
4085
4036
  source: source,
4086
4037
  count: mergedSnapshot.length
4087
4038
  });
@@ -4091,27 +4042,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4091
4042
  }
4092
4043
  }, _callee26, null, [[10, 25, 28, 31]]);
4093
4044
  })));
4094
- case 9:
4095
- persisted = true;
4096
- _context27.next = 15;
4045
+ case 8:
4046
+ _context27.next = 13;
4097
4047
  break;
4098
- case 12:
4099
- _context27.prev = 12;
4100
- _context27.t0 = _context27["catch"](6);
4048
+ case 10:
4049
+ _context27.prev = 10;
4050
+ _context27.t0 = _context27["catch"](5);
4101
4051
  this.logError('全量保存订单到 SQLite 失败', {
4102
4052
  error: _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0),
4103
4053
  orderList: remoteSnapshot.length
4104
4054
  });
4105
- case 15:
4106
- return _context27.abrupt("return", {
4107
- orders: mergedSnapshot,
4108
- persisted: persisted
4109
- });
4110
- case 16:
4055
+ case 13:
4056
+ return _context27.abrupt("return", mergedSnapshot);
4057
+ case 14:
4111
4058
  case "end":
4112
4059
  return _context27.stop();
4113
4060
  }
4114
- }, _callee27, this, [[6, 12]]);
4061
+ }, _callee27, this, [[5, 10]]);
4115
4062
  }));
4116
4063
  function replaceOrdersSnapshotInSQLite(_x20, _x21) {
4117
4064
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
@@ -4129,7 +4076,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4129
4076
  key: "clear",
4130
4077
  value: (function () {
4131
4078
  var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4132
- var _this26 = this;
4079
+ var _this25 = this;
4133
4080
  return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4134
4081
  while (1) switch (_context29.prev = _context29.next) {
4135
4082
  case 0:
@@ -4145,7 +4092,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4145
4092
  while (1) switch (_context28.prev = _context28.next) {
4146
4093
  case 0:
4147
4094
  _context28.next = 2;
4148
- return _this26.dbManager.clear(INDEXDB_STORE_NAME);
4095
+ return _this25.dbManager.clear(INDEXDB_STORE_NAME);
4149
4096
  case 2:
4150
4097
  case "end":
4151
4098
  return _context28.stop();
@@ -4153,7 +4100,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4153
4100
  }, _callee28);
4154
4101
  })));
4155
4102
  case 5:
4156
- this.clearOrderSnapshotMarker();
4103
+ this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
4157
4104
  this.emitOrdersChanged([], 'clear');
4158
4105
  case 7:
4159
4106
  case "end":