@pisell/pisellos 2.3.62 → 2.3.64

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 (56) 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/BookingContext/utils/buildCacheItemFromOrderLine.js +7 -3
  6. package/dist/modules/Customer/index.d.ts +4 -0
  7. package/dist/modules/Customer/index.js +91 -59
  8. package/dist/modules/Customer/types.d.ts +2 -0
  9. package/dist/modules/Order/index.js +4 -1
  10. package/dist/modules/Order/utils.js +36 -30
  11. package/dist/modules/Payment/walletpass.js +4 -5
  12. package/dist/modules/Quotation/index.d.ts +0 -6
  13. package/dist/modules/Quotation/index.js +19 -75
  14. package/dist/plugins/request.d.ts +0 -1
  15. package/dist/server/index.d.ts +2 -6
  16. package/dist/server/index.js +92 -133
  17. package/dist/server/modules/floor-plan/index.d.ts +0 -4
  18. package/dist/server/modules/floor-plan/index.js +98 -240
  19. package/dist/server/modules/menu/index.js +23 -48
  20. package/dist/server/modules/order/index.d.ts +8 -12
  21. package/dist/server/modules/order/index.js +348 -342
  22. package/dist/server/modules/products/index.d.ts +2 -8
  23. package/dist/server/modules/products/index.js +75 -167
  24. package/dist/server/modules/resource/index.js +13 -21
  25. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  26. package/dist/solution/BookingTicket/index.d.ts +2 -0
  27. package/dist/solution/BookingTicket/index.js +34 -10
  28. package/lib/core/index.d.ts +0 -7
  29. package/lib/core/index.js +2 -20
  30. package/lib/model/strategy/adapter/promotion/index.js +0 -51
  31. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -1
  32. package/lib/model/strategy/adapter/walletPass/utils.js +0 -1
  33. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -0
  34. package/lib/modules/Customer/index.d.ts +4 -0
  35. package/lib/modules/Customer/index.js +11 -0
  36. package/lib/modules/Customer/types.d.ts +2 -0
  37. package/lib/modules/Order/index.js +3 -2
  38. package/lib/modules/Order/utils.js +3 -0
  39. package/lib/modules/Payment/walletpass.js +0 -1
  40. package/lib/modules/Quotation/index.d.ts +0 -6
  41. package/lib/modules/Quotation/index.js +5 -49
  42. package/lib/plugins/request.d.ts +0 -1
  43. package/lib/server/index.d.ts +2 -6
  44. package/lib/server/index.js +12 -34
  45. package/lib/server/modules/floor-plan/index.d.ts +0 -4
  46. package/lib/server/modules/floor-plan/index.js +6 -54
  47. package/lib/server/modules/menu/index.js +5 -31
  48. package/lib/server/modules/order/index.d.ts +8 -12
  49. package/lib/server/modules/order/index.js +94 -145
  50. package/lib/server/modules/products/index.d.ts +2 -8
  51. package/lib/server/modules/products/index.js +24 -97
  52. package/lib/server/modules/resource/index.js +2 -7
  53. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -0
  54. package/lib/solution/BookingTicket/index.d.ts +2 -0
  55. package/lib/solution/BookingTicket/index.js +18 -2
  56. 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 */
@@ -65,7 +65,6 @@ var ORDER_COLLECTION_KIND_BY_FIELD = {
65
65
  bookings: 'booking',
66
66
  payments: 'payment'
67
67
  };
68
-
69
68
  /**
70
69
  * Order 模块 - 基础框架
71
70
  */
@@ -701,78 +700,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
701
700
  key: "preload",
702
701
  value: function () {
703
702
  var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
704
- var preloadStartedAt, cachedOrders, memoryOrders, orders;
703
+ var orders;
705
704
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
706
705
  while (1) switch (_context4.prev = _context4.next) {
707
706
  case 0:
708
- preloadStartedAt = Date.now();
709
- cachedOrders = null;
710
- if (!this.dbManager) {
711
- _context4.next = 12;
712
- break;
713
- }
714
- _context4.prev = 3;
715
- _context4.next = 6;
716
- return this.loadOrdersFromSQLite({
717
- throwOnError: true
718
- });
719
- case 6:
720
- cachedOrders = _context4.sent;
721
- _context4.next = 12;
722
- break;
723
- case 9:
724
- _context4.prev = 9;
725
- _context4.t0 = _context4["catch"](3);
726
- this.logWarning('preload-SQLite读取失败,回退远端全量拉取', {
727
- error: _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0)
728
- });
729
- case 12:
730
- if (!(cachedOrders !== null && this.hasPulledOrdersToday())) {
731
- _context4.next = 22;
732
- break;
733
- }
734
- memoryOrders = this.normalizeOrdersForMemoryList(cachedOrders, 'preload.sqliteMemory');
735
- this.store.list = cloneDeep(memoryOrders);
736
- this.syncOrdersMap();
737
- _context4.next = 18;
738
- return this.core.effects.emit(OrderHooks.onOrdersLoaded, this.store.list);
739
- case 18:
740
- _context4.next = 20;
741
- return this.emitOrdersChanged([], 'preload.sqlite');
742
- case 20:
743
- this.logInfo('预加载完成', {
744
- trigger: 'preload',
745
- source: 'SQLite',
746
- orderCount: this.store.list.length,
747
- duration: "".concat(Date.now() - preloadStartedAt, "ms")
748
- });
749
- return _context4.abrupt("return");
750
- case 22:
751
- _context4.next = 24;
752
- return this.loadOrdersByServer({
753
- trigger: 'preload'
754
- });
755
- case 24:
707
+ _context4.next = 2;
708
+ return this.loadOrdersByServer();
709
+ case 2:
756
710
  orders = _context4.sent;
757
711
  this.store.list = cloneDeep(orders);
758
712
  this.syncOrdersMap();
759
- _context4.next = 29;
713
+ _context4.next = 7;
760
714
  return this.emitOrdersChanged([], 'preload');
761
- case 29:
762
- _context4.next = 31;
715
+ case 7:
716
+ _context4.next = 9;
763
717
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
764
- case 31:
765
- this.logInfo('预加载完成', {
766
- trigger: 'preload',
767
- source: 'Server',
768
- orderCount: this.store.list.length,
769
- duration: "".concat(Date.now() - preloadStartedAt, "ms")
770
- });
771
- case 32:
718
+ case 9:
772
719
  case "end":
773
720
  return _context4.stop();
774
721
  }
775
- }, _callee4, this, [[3, 9]]);
722
+ }, _callee4, this);
776
723
  }));
777
724
  function preload() {
778
725
  return _preload.apply(this, arguments);
@@ -1105,32 +1052,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1105
1052
  var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1106
1053
  var _this5 = this,
1107
1054
  _this$store;
1108
- var options,
1109
- orderList,
1110
- hasFetchedRemoteSnapshot,
1111
- trigger,
1112
- protectedOrdersBeforeRemoteFetch,
1113
- data,
1114
- _yield$this$replaceOr,
1115
- mergedOrders,
1116
- isRemoteSnapshotPersisted,
1117
- memoryOrders,
1118
- _args8 = arguments;
1055
+ var orderList, protectedOrdersBeforeRemoteFetch, data, mergedOrders, memoryOrders;
1119
1056
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1120
1057
  while (1) switch (_context8.prev = _context8.next) {
1121
1058
  case 0:
1122
- options = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
1123
1059
  orderList = [];
1124
- hasFetchedRemoteSnapshot = false;
1125
- trigger = options.trigger || 'unknown';
1126
- _context8.next = 6;
1060
+ _context8.next = 3;
1127
1061
  return this.loadOrdersFromSQLite();
1128
- case 6:
1062
+ case 3:
1129
1063
  protectedOrdersBeforeRemoteFetch = _context8.sent.filter(function (order) {
1130
1064
  return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
1131
1065
  });
1132
1066
  this.logInfo('loadOrdersByServer-开始', {
1133
- trigger: trigger,
1134
1067
  hasOrderDataSource: !!this.orderDataSource,
1135
1068
  query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
1136
1069
  protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
@@ -1139,61 +1072,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1139
1072
  }, 0)
1140
1073
  });
1141
1074
  if (!this.orderDataSource) {
1142
- _context8.next = 23;
1075
+ _context8.next = 20;
1143
1076
  break;
1144
1077
  }
1145
- _context8.prev = 9;
1146
- _context8.next = 12;
1078
+ _context8.prev = 6;
1079
+ _context8.next = 9;
1147
1080
  return this.orderDataSource.run({
1148
1081
  sse: {
1149
1082
  query: this.store.createdAtQuery
1150
1083
  }
1151
1084
  });
1152
- case 12:
1085
+ case 9:
1153
1086
  data = _context8.sent;
1154
1087
  orderList = data || [];
1155
1088
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
1156
- trigger: trigger,
1157
1089
  count: orderList.length
1158
1090
  });
1159
- hasFetchedRemoteSnapshot = true;
1091
+ this.markOrderPulledAtNow();
1160
1092
  this.lastServerFullFetchAtMs = Date.now();
1161
- _context8.next = 23;
1093
+ _context8.next = 20;
1162
1094
  break;
1163
- case 19:
1164
- _context8.prev = 19;
1165
- _context8.t0 = _context8["catch"](9);
1095
+ case 16:
1096
+ _context8.prev = 16;
1097
+ _context8.t0 = _context8["catch"](6);
1166
1098
  this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
1167
1099
  return _context8.abrupt("return", this.store.list);
1168
- case 23:
1169
- if (hasFetchedRemoteSnapshot) {
1170
- this.clearOrderSnapshotMarker();
1171
- }
1172
- _context8.next = 26;
1100
+ case 20:
1101
+ _context8.next = 22;
1173
1102
  return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
1174
- case 26:
1175
- _yield$this$replaceOr = _context8.sent;
1176
- mergedOrders = _yield$this$replaceOr.orders;
1177
- isRemoteSnapshotPersisted = _yield$this$replaceOr.persisted;
1178
- if (hasFetchedRemoteSnapshot && isRemoteSnapshotPersisted) {
1179
- this.markOrderPulledAtNow();
1180
- }
1103
+ case 22:
1104
+ mergedOrders = _context8.sent;
1181
1105
  memoryOrders = this.normalizeOrdersForMemoryList(mergedOrders, 'loadOrdersByServer.memory');
1182
1106
  this.logInfo('loadOrdersByServer-结束', {
1183
- trigger: trigger,
1184
1107
  count: memoryOrders.length,
1185
1108
  persistedCount: mergedOrders.length,
1186
1109
  sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
1187
1110
  });
1188
- _context8.next = 34;
1111
+ _context8.next = 27;
1189
1112
  return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
1190
- case 34:
1113
+ case 27:
1191
1114
  return _context8.abrupt("return", memoryOrders);
1192
- case 35:
1115
+ case 28:
1193
1116
  case "end":
1194
1117
  return _context8.stop();
1195
1118
  }
1196
- }, _callee8, this, [[9, 19]]);
1119
+ }, _callee8, this, [[6, 16]]);
1197
1120
  }));
1198
1121
  function loadOrdersByServer() {
1199
1122
  return _loadOrdersByServer.apply(this, arguments);
@@ -1209,76 +1132,53 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1209
1132
  key: "silentRefresh",
1210
1133
  value: (function () {
1211
1134
  var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1212
- var options,
1213
- startTime,
1214
- trigger,
1215
- elapsedSinceFullFetch,
1216
- orders,
1217
- errorMessage,
1218
- _args9 = arguments;
1135
+ var startTime, elapsedSinceFullFetch, orders, errorMessage;
1219
1136
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1220
1137
  while (1) switch (_context9.prev = _context9.next) {
1221
1138
  case 0:
1222
- options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
1223
1139
  startTime = Date.now();
1224
- trigger = options.trigger || 'background';
1225
1140
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
1226
1141
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
1227
- _context9.next = 7;
1142
+ _context9.next = 4;
1228
1143
  break;
1229
1144
  }
1230
- this.logInfo('silentRefresh 跳过全量 SSE', {
1231
- trigger: trigger,
1232
- reason: 'within_min_interval',
1233
- minIntervalMs: ORDER_SILENT_REFRESH_MIN_INTERVAL_MS,
1234
- elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1235
- orderCount: this.store.list.length
1236
- });
1237
1145
  return _context9.abrupt("return", this.store.list);
1238
- case 7:
1239
- this.logInfo('silentRefresh 开始', {
1240
- trigger: trigger,
1241
- elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1242
- orderCount: this.store.list.length
1243
- });
1244
- _context9.prev = 8;
1146
+ case 4:
1147
+ this.logInfo('silentRefresh 开始');
1148
+ _context9.prev = 5;
1245
1149
  // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
1246
1150
  this.updateCreateStore();
1247
- _context9.next = 12;
1248
- return this.loadOrdersByServer({
1249
- trigger: trigger
1250
- });
1251
- case 12:
1151
+ _context9.next = 9;
1152
+ return this.loadOrdersByServer();
1153
+ case 9:
1252
1154
  orders = _context9.sent;
1253
1155
  this.store.list = cloneDeep(orders);
1254
1156
  this.syncOrdersMap();
1255
- _context9.next = 17;
1157
+ _context9.next = 14;
1256
1158
  return this.emitOrdersChanged([], 'silentRefresh');
1257
- case 17:
1258
- _context9.next = 19;
1159
+ case 14:
1160
+ _context9.next = 16;
1259
1161
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1260
- case 19:
1162
+ case 16:
1261
1163
  this.logInfo('silentRefresh 完成', {
1262
- trigger: trigger,
1263
1164
  orderCount: orders.length,
1264
1165
  duration: "".concat(Date.now() - startTime, "ms")
1265
1166
  });
1266
1167
  return _context9.abrupt("return", this.store.list);
1267
- case 23:
1268
- _context9.prev = 23;
1269
- _context9.t0 = _context9["catch"](8);
1168
+ case 20:
1169
+ _context9.prev = 20;
1170
+ _context9.t0 = _context9["catch"](5);
1270
1171
  errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
1271
1172
  this.logError('silentRefresh 失败', {
1272
- trigger: trigger,
1273
1173
  duration: "".concat(Date.now() - startTime, "ms"),
1274
1174
  error: errorMessage
1275
1175
  });
1276
1176
  return _context9.abrupt("return", this.store.list);
1277
- case 28:
1177
+ case 25:
1278
1178
  case "end":
1279
1179
  return _context9.stop();
1280
1180
  }
1281
- }, _callee9, this, [[8, 23]]);
1181
+ }, _callee9, this, [[5, 20]]);
1282
1182
  }));
1283
1183
  function silentRefresh() {
1284
1184
  return _silentRefresh.apply(this, arguments);
@@ -2427,7 +2327,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2427
2327
  value: (function () {
2428
2328
  var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(freshOrders, source) {
2429
2329
  var _this16 = this;
2430
- 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;
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;
2431
2331
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2432
2332
  while (1) switch (_context19.prev = _context19.next) {
2433
2333
  case 0:
@@ -2484,6 +2384,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2484
2384
  patchedOrders = [];
2485
2385
  remoteProductMembershipChanges = [];
2486
2386
  forceWriteStorageKeys = new Set();
2387
+ storageKeyMigrations = [];
2487
2388
  mergeActions = {};
2488
2389
  existingProductsHaveStableIdentity = this.store.list.map(function (order) {
2489
2390
  return _this16.doProductsHaveStableMembershipIdentity(order.products);
@@ -2510,11 +2411,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2510
2411
  }
2511
2412
  }
2512
2413
  _iterator16 = _createForOfIteratorHelper(uniqueFreshOrders);
2513
- _context19.prev = 37;
2414
+ _context19.prev = 38;
2514
2415
  _iterator16.s();
2515
- case 39:
2416
+ case 40:
2516
2417
  if ((_step16 = _iterator16.n()).done) {
2517
- _context19.next = 96;
2418
+ _context19.next = 100;
2518
2419
  break;
2519
2420
  }
2520
2421
  fresh = _step16.value;
@@ -2523,12 +2424,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2523
2424
  storageKey = this.getOrderStorageKey(fresh);
2524
2425
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
2525
2426
  if (!(matchIndex >= 0)) {
2526
- _context19.next = 88;
2427
+ _context19.next = 92;
2527
2428
  break;
2528
2429
  }
2529
2430
  existingOrder = updatedList[matchIndex];
2431
+ previousStorageKey = this.getPersistedOrderStorageKey(existingOrder);
2530
2432
  if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
2531
- _context19.next = 50;
2433
+ _context19.next = 52;
2532
2434
  break;
2533
2435
  }
2534
2436
  this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
@@ -2541,10 +2443,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2541
2443
  remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2542
2444
  reason: 'protect_pending_sync_order_from_remote_echo'
2543
2445
  });
2544
- return _context19.abrupt("continue", 94);
2545
- case 50:
2446
+ return _context19.abrupt("continue", 98);
2447
+ case 52:
2546
2448
  if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2547
- _context19.next = 53;
2449
+ _context19.next = 55;
2548
2450
  break;
2549
2451
  }
2550
2452
  this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
@@ -2555,8 +2457,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2555
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,
2556
2458
  reason: 'protect_draft_order_from_remote_echo'
2557
2459
  });
2558
- return _context19.abrupt("continue", 94);
2559
- case 53:
2460
+ return _context19.abrupt("continue", 98);
2461
+ case 55:
2560
2462
  mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2561
2463
  freshOrderId = fresh.order_id;
2562
2464
  incomingProductsAreStable = freshOrderId !== undefined && freshOrderId !== null && incomingProductsHaveStableIdentity.get(this.getIdKey(freshOrderId)) !== false;
@@ -2568,37 +2470,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2568
2470
  adjustedMatchIndex = matchIndex;
2569
2471
  duplicateIndexes = new Set();
2570
2472
  _iterator17 = _createForOfIteratorHelper(freshIdentityKeys);
2571
- _context19.prev = 62;
2473
+ _context19.prev = 64;
2572
2474
  _iterator17.s();
2573
- case 64:
2475
+ case 66:
2574
2476
  if ((_step17 = _iterator17.n()).done) {
2575
- _context19.next = 72;
2477
+ _context19.next = 74;
2576
2478
  break;
2577
2479
  }
2578
2480
  _key2 = _step17.value;
2579
2481
  _duplicateIndex = identityKeyToIndex.get(_key2);
2580
2482
  if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
2581
- _context19.next = 69;
2483
+ _context19.next = 71;
2582
2484
  break;
2583
2485
  }
2584
- return _context19.abrupt("continue", 70);
2585
- case 69:
2486
+ return _context19.abrupt("continue", 72);
2487
+ case 71:
2586
2488
  duplicateIndexes.add(_duplicateIndex);
2587
- case 70:
2588
- _context19.next = 64;
2589
- break;
2590
2489
  case 72:
2591
- _context19.next = 77;
2490
+ _context19.next = 66;
2592
2491
  break;
2593
2492
  case 74:
2594
- _context19.prev = 74;
2595
- _context19.t1 = _context19["catch"](62);
2493
+ _context19.next = 79;
2494
+ break;
2495
+ case 76:
2496
+ _context19.prev = 76;
2497
+ _context19.t1 = _context19["catch"](64);
2596
2498
  _iterator17.e(_context19.t1);
2597
- case 77:
2598
- _context19.prev = 77;
2499
+ case 79:
2500
+ _context19.prev = 79;
2599
2501
  _iterator17.f();
2600
- return _context19.finish(77);
2601
- case 80:
2502
+ return _context19.finish(79);
2503
+ case 82:
2602
2504
  if (duplicateIndexes.size > 0) {
2603
2505
  _iterator18 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
2604
2506
  return right - left;
@@ -2632,6 +2534,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2632
2534
  }
2633
2535
  }
2634
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
+ }
2635
2545
  updatedList[adjustedMatchIndex] = mergedOrder;
2636
2546
  existingProductsHaveStableIdentity[adjustedMatchIndex] = mergedProductsHaveStableIdentity;
2637
2547
  if (membershipChange) {
@@ -2644,29 +2554,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2644
2554
  this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
2645
2555
  patchedOrders.push(mergedOrder);
2646
2556
  if (mergeKey) mergeActions[mergeKey] = 'update';
2647
- return _context19.abrupt("continue", 94);
2648
- case 88:
2557
+ return _context19.abrupt("continue", 98);
2558
+ case 92:
2649
2559
  insertIndex = updatedList.length;
2650
2560
  updatedList.push(fresh);
2651
2561
  existingProductsHaveStableIdentity.push(fresh.order_id !== undefined && fresh.order_id !== null && incomingProductsHaveStableIdentity.get(this.getIdKey(fresh.order_id)) !== false);
2652
2562
  this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
2653
2563
  patchedOrders.push(fresh);
2654
2564
  if (mergeKey) mergeActions[mergeKey] = 'insert';
2655
- case 94:
2656
- _context19.next = 39;
2565
+ case 98:
2566
+ _context19.next = 40;
2657
2567
  break;
2658
- case 96:
2659
- _context19.next = 101;
2568
+ case 100:
2569
+ _context19.next = 105;
2660
2570
  break;
2661
- case 98:
2662
- _context19.prev = 98;
2663
- _context19.t2 = _context19["catch"](37);
2571
+ case 102:
2572
+ _context19.prev = 102;
2573
+ _context19.t2 = _context19["catch"](38);
2664
2574
  _iterator16.e(_context19.t2);
2665
- case 101:
2666
- _context19.prev = 101;
2575
+ case 105:
2576
+ _context19.prev = 105;
2667
2577
  _iterator16.f();
2668
- return _context19.finish(101);
2669
- case 104:
2578
+ return _context19.finish(105);
2579
+ case 108:
2670
2580
  insertCount = Object.values(mergeActions).filter(function (v) {
2671
2581
  return v === 'insert';
2672
2582
  }).length;
@@ -2682,25 +2592,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2682
2592
  // 仅在自检开关开启时做一次兜底校验。
2683
2593
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
2684
2594
  this.syncOrdersMap();
2685
- _context19.next = 111;
2686
- return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {}, forceWriteStorageKeys);
2687
- case 111:
2595
+ _context19.next = 115;
2596
+ return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {
2597
+ storageKeyMigrations: storageKeyMigrations
2598
+ }, forceWriteStorageKeys);
2599
+ case 115:
2688
2600
  this.logInfo('mergeOrdersToStore-结束', {
2689
2601
  uniqueFreshCount: uniqueFreshCount,
2690
2602
  storeOrderCountAfter: this.store.list.length,
2691
2603
  insertCount: insertCount,
2692
2604
  updateCount: updateCount
2693
2605
  });
2694
- _context19.next = 114;
2606
+ _context19.next = 118;
2695
2607
  return this.emitRemoteProductMembershipChanges(remoteProductMembershipChanges);
2696
- case 114:
2697
- _context19.next = 116;
2608
+ case 118:
2609
+ _context19.next = 120;
2698
2610
  return this.emitOrdersChanged(patchedOrders, source);
2699
- case 116:
2611
+ case 120:
2700
2612
  case "end":
2701
2613
  return _context19.stop();
2702
2614
  }
2703
- }, _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]]);
2704
2616
  }));
2705
2617
  function mergeOrdersToStore(_x13, _x14) {
2706
2618
  return _mergeOrdersToStore.apply(this, arguments);
@@ -2783,7 +2695,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2783
2695
  key: "getRemoteProductMembershipChange",
2784
2696
  value: function getRemoteProductMembershipChange(existingOrder, mergedOrder, source) {
2785
2697
  var _this17 = this,
2786
- _mergedOrder$order_id;
2698
+ _mergedOrder$order_id2;
2787
2699
  if (!this.isRemoteProductMembershipChangeSource(source)) return null;
2788
2700
  var previousProducts = Array.isArray(existingOrder.products) ? existingOrder.products : [];
2789
2701
  var currentProducts = Array.isArray(mergedOrder.products) ? mergedOrder.products : [];
@@ -2820,7 +2732,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2820
2732
  if (addedProductKeys.length === 0 && removedProductKeys.length === 0) {
2821
2733
  return null;
2822
2734
  }
2823
- 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;
2824
2736
  if (orderId === undefined || orderId === null) return null;
2825
2737
  return {
2826
2738
  order_id: orderId,
@@ -2959,6 +2871,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2959
2871
  }
2960
2872
  return '';
2961
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
+ }
2962
2883
  }, {
2963
2884
  key: "getOrderIdentityMatchKeys",
2964
2885
  value: function getOrderIdentityMatchKeys(order) {
@@ -3160,10 +3081,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3160
3081
  if (_field2 === 'payments') {
3161
3082
  var preservedPending = this.getUnmatchedIdentifiedPendingPayments(existingRecord[_field2], incomingRecord[_field2]);
3162
3083
  if (preservedPending.length > 0) {
3163
- var _ref5, _existing$order_id, _ref6, _existingRecord$exter;
3084
+ var _ref7, _existing$order_id, _ref8, _existingRecord$exter;
3164
3085
  this.logInfo('mergeOrderRecords-保留本地 pending 支付项', {
3165
- 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,
3166
- 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,
3167
3088
  preserved_pending_count: preservedPending.length,
3168
3089
  preserved_payment_identities: preservedPending.map(function (payment) {
3169
3090
  return getOrderPaymentIdentityKeys(payment);
@@ -3216,14 +3137,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3216
3137
  } finally {
3217
3138
  _iterator28.f();
3218
3139
  }
3219
- return _toConsumableArray(groups.entries()).filter(function (_ref7) {
3220
- var _ref8 = _slicedToArray(_ref7, 2),
3221
- group = _ref8[1];
3222
- return group.length > 1;
3223
- }).slice(0, 20).map(function (_ref9) {
3140
+ return _toConsumableArray(groups.entries()).filter(function (_ref9) {
3224
3141
  var _ref10 = _slicedToArray(_ref9, 2),
3225
- key = _ref10[0],
3226
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];
3227
3148
  return {
3228
3149
  key: key,
3229
3150
  count: group.length,
@@ -3293,32 +3214,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3293
3214
  }
3294
3215
 
3295
3216
  /**
3296
- * 当前订单缓存可复用窗口。
3297
- * start_time 模式使用精确的营业日起止时间;配置缺失或异常时退化为自然日。
3217
+ * 当前订单拉取窗口:
3218
+ * - 优先使用 createdAtQuery.sales_time_between(已按营业日边界初始化)
3219
+ * - 无法解析时退化为自然日窗口
3298
3220
  */
3299
3221
  }, {
3300
- key: "getCurrentOrderCacheWindow",
3301
- value: function getCurrentOrderCacheWindow() {
3222
+ key: "getCurrentPullWindow",
3223
+ value: function getCurrentPullWindow() {
3224
+ var _this$store2;
3302
3225
  var now = dayjs();
3303
- try {
3304
- var _coreData$core;
3305
- var appPlugin = this.core.getPlugin('app');
3306
- var app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
3307
- var coreData = app === null || app === void 0 ? void 0 : app.data.store.getStore().getDataByModel('core');
3308
- var boundary = coreData === null || coreData === void 0 || (_coreData$core = coreData.core) === null || _coreData$core === void 0 ? void 0 : _coreData$core.operating_day_boundary;
3309
- if ((boundary === null || boundary === void 0 ? void 0 : boundary.type) === 'start_time') {
3310
- var boundaryTime = String(boundary.time || '').trim();
3311
- var todayBoundary = dayjs("".concat(now.format('YYYY-MM-DD'), " ").concat(boundaryTime));
3312
- if (todayBoundary.isValid()) {
3313
- var _startAt = now.isBefore(todayBoundary) ? todayBoundary.subtract(1, 'day') : todayBoundary;
3314
- return {
3315
- startAt: _startAt,
3316
- endExclusiveAt: _startAt.add(1, 'day')
3317
- };
3318
- }
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
+ };
3319
3235
  }
3320
- } catch (_unused6) {
3321
- // 读取营业日配置失败时按自然日兜底,不影响启动。
3322
3236
  }
3323
3237
  var startAt = now.startOf('day');
3324
3238
  return {
@@ -3331,47 +3245,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3331
3245
  value: function hasPulledOrdersToday() {
3332
3246
  var lastFullFetchAt = this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY);
3333
3247
  if (!lastFullFetchAt) return false;
3334
- var currentShopId = this.getCurrentShopId();
3335
- var lastFullFetchShopId = this.getStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY);
3336
- if (!currentShopId || !lastFullFetchShopId || currentShopId !== lastFullFetchShopId) {
3337
- return false;
3338
- }
3339
3248
  var parsed = dayjs(lastFullFetchAt);
3340
3249
  if (!parsed.isValid()) return false;
3341
- var _this$getCurrentOrder = this.getCurrentOrderCacheWindow(),
3342
- startAt = _this$getCurrentOrder.startAt,
3343
- 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;
3344
3256
  return (parsed.isAfter(startAt) || parsed.isSame(startAt)) && parsed.isBefore(endExclusiveAt);
3345
3257
  }
3346
3258
  }, {
3347
3259
  key: "markOrderPulledAtNow",
3348
3260
  value: function markOrderPulledAtNow() {
3349
- var currentShopId = this.getCurrentShopId();
3350
- if (!currentShopId) return;
3351
3261
  this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, dayjs().format('YYYY-MM-DD HH:mm:ss'));
3352
- this.setStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY, currentShopId);
3353
- }
3354
- }, {
3355
- key: "clearOrderSnapshotMarker",
3356
- value: function clearOrderSnapshotMarker() {
3357
- this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
3358
- this.setStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY, '');
3359
- }
3360
- }, {
3361
- key: "getCurrentShopId",
3362
- value: function getCurrentShopId() {
3363
- try {
3364
- var _coreData$core2;
3365
- var appPlugin = this.core.getPlugin('app');
3366
- var app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
3367
- if (!app) return null;
3368
- var coreData = app.data.store.getStore().getDataByModel('core');
3369
- var shopId = coreData === null || coreData === void 0 || (_coreData$core2 = coreData.core) === null || _coreData$core2 === void 0 ? void 0 : _coreData$core2.id;
3370
- if (shopId === undefined || shopId === null || shopId === '') return null;
3371
- return String(shopId);
3372
- } catch (_unused7) {
3373
- return null;
3374
- }
3375
3262
  }
3376
3263
  }, {
3377
3264
  key: "getStorageItem",
@@ -3382,7 +3269,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3382
3269
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
3383
3270
  return globalThis.localStorage.getItem(key);
3384
3271
  }
3385
- } catch (_unused8) {
3272
+ } catch (_unused6) {
3386
3273
  // 忽略存储异常,避免影响主流程
3387
3274
  }
3388
3275
  return null;
@@ -3399,7 +3286,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3399
3286
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
3400
3287
  globalThis.localStorage.setItem(key, value);
3401
3288
  }
3402
- } catch (_unused9) {
3289
+ } catch (_unused7) {
3403
3290
  // 忽略存储异常,避免影响主流程
3404
3291
  }
3405
3292
  }
@@ -3408,42 +3295,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3408
3295
  value: function () {
3409
3296
  var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
3410
3297
  var _this20 = this;
3411
- var options,
3412
- orders,
3413
- _args20 = arguments;
3298
+ var orders;
3414
3299
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
3415
3300
  while (1) switch (_context20.prev = _context20.next) {
3416
3301
  case 0:
3417
- options = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {};
3418
3302
  if (this.dbManager) {
3419
- _context20.next = 3;
3303
+ _context20.next = 2;
3420
3304
  break;
3421
3305
  }
3422
3306
  return _context20.abrupt("return", []);
3423
- case 3:
3424
- _context20.prev = 3;
3425
- _context20.next = 6;
3307
+ case 2:
3308
+ _context20.prev = 2;
3309
+ _context20.next = 5;
3426
3310
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
3427
- case 6:
3311
+ case 5:
3428
3312
  orders = _context20.sent;
3429
3313
  return _context20.abrupt("return", (orders || []).map(function (order) {
3430
3314
  return _this20.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
3431
3315
  }));
3432
- case 10:
3433
- _context20.prev = 10;
3434
- _context20.t0 = _context20["catch"](3);
3435
- if (!options.throwOnError) {
3436
- _context20.next = 14;
3437
- break;
3438
- }
3439
- throw _context20.t0;
3440
- case 14:
3316
+ case 9:
3317
+ _context20.prev = 9;
3318
+ _context20.t0 = _context20["catch"](2);
3441
3319
  return _context20.abrupt("return", []);
3442
- case 15:
3320
+ case 12:
3443
3321
  case "end":
3444
3322
  return _context20.stop();
3445
3323
  }
3446
- }, _callee20, this, [[3, 10]]);
3324
+ }, _callee20, this, [[2, 9]]);
3447
3325
  }));
3448
3326
  function loadOrdersFromSQLite() {
3449
3327
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -3573,11 +3451,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3573
3451
  var mergeActions,
3574
3452
  options,
3575
3453
  forceWriteStorageKeys,
3454
+ migrationTargetStorageKeys,
3576
3455
  ordersSnapshot,
3577
3456
  _this$filterRedundant2,
3578
3457
  toWrite,
3579
3458
  skipped,
3580
3459
  compactedToWrite,
3460
+ writtenStorageKeys,
3461
+ storageKeyMigrations,
3462
+ _iterator32,
3463
+ _step32,
3464
+ migration,
3581
3465
  _args23 = arguments;
3582
3466
  return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3583
3467
  while (1) switch (_context23.prev = _context23.next) {
@@ -3603,35 +3487,83 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3603
3487
  case 8:
3604
3488
  return _context23.abrupt("return");
3605
3489
  case 9:
3490
+ migrationTargetStorageKeys = new Set((options.storageKeyMigrations || []).map(function (migration) {
3491
+ return migration.to;
3492
+ }));
3606
3493
  ordersSnapshot = cloneDeep(orders).map(function (order) {
3607
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));
3608
3499
  }).filter(function (order) {
3609
3500
  return _this22.getOrderStorageKey(order);
3610
3501
  });
3611
3502
  if (!(ordersSnapshot.length === 0)) {
3612
- _context23.next = 12;
3503
+ _context23.next = 13;
3613
3504
  break;
3614
3505
  }
3615
3506
  return _context23.abrupt("return");
3616
- case 12:
3507
+ case 13:
3617
3508
  _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
3618
3509
  if (!(toWrite.length === 0)) {
3619
- _context23.next = 15;
3510
+ _context23.next = 16;
3620
3511
  break;
3621
3512
  }
3622
3513
  return _context23.abrupt("return");
3623
- case 15:
3514
+ case 16:
3624
3515
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
3625
3516
  if (!(compactedToWrite.length === 0)) {
3626
- _context23.next = 18;
3517
+ _context23.next = 19;
3627
3518
  break;
3628
3519
  }
3629
3520
  return _context23.abrupt("return");
3630
- case 18:
3631
- _context23.prev = 18;
3632
- _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;
3633
3565
  return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
3634
- var writeMethod, _iterator32, _step32, order;
3566
+ var writeMethod, _iterator33, _step33, order, _iterator34, _step34, migration, _iterator35, _step35, _orderRecord$ORDER_ST, _order, orderRecord;
3635
3567
  return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3636
3568
  while (1) switch (_context22.prev = _context22.next) {
3637
3569
  case 0:
@@ -3668,15 +3600,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3668
3600
  break;
3669
3601
  }
3670
3602
  writeMethod = 'update';
3671
- _iterator32 = _createForOfIteratorHelper(compactedToWrite);
3603
+ _iterator33 = _createForOfIteratorHelper(compactedToWrite);
3672
3604
  _context22.prev = 17;
3673
- _iterator32.s();
3605
+ _iterator33.s();
3674
3606
  case 19:
3675
- if ((_step32 = _iterator32.n()).done) {
3607
+ if ((_step33 = _iterator33.n()).done) {
3676
3608
  _context22.next = 25;
3677
3609
  break;
3678
3610
  }
3679
- order = _step32.value;
3611
+ order = _step33.value;
3680
3612
  _context22.next = 23;
3681
3613
  return _this22.dbManager.update(INDEXDB_STORE_NAME, order);
3682
3614
  case 23:
@@ -3688,10 +3620,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3688
3620
  case 27:
3689
3621
  _context22.prev = 27;
3690
3622
  _context22.t0 = _context22["catch"](17);
3691
- _iterator32.e(_context22.t0);
3623
+ _iterator33.e(_context22.t0);
3692
3624
  case 30:
3693
3625
  _context22.prev = 30;
3694
- _iterator32.f();
3626
+ _iterator33.f();
3695
3627
  return _context22.finish(30);
3696
3628
  case 33:
3697
3629
  _context22.next = 37;
@@ -3704,38 +3636,121 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3704
3636
  throw new Error('订单 SQLite 数据库不支持写入');
3705
3637
  case 37:
3706
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:
3707
3722
  _this22.logInfo('patchOrdersInSQLite-完成', {
3708
3723
  source: source,
3709
3724
  count: compactedToWrite.length,
3710
3725
  writeMethod: writeMethod,
3711
3726
  dedupedCount: skipped.length
3712
3727
  });
3713
- case 39:
3728
+ case 85:
3714
3729
  case "end":
3715
3730
  return _context22.stop();
3716
3731
  }
3717
- }, _callee22, null, [[17, 27, 30, 33]]);
3732
+ }, _callee22, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
3718
3733
  })));
3719
- case 21:
3720
- _context23.next = 28;
3734
+ case 44:
3735
+ _context23.next = 51;
3721
3736
  break;
3722
- case 23:
3723
- _context23.prev = 23;
3724
- _context23.t0 = _context23["catch"](18);
3737
+ case 46:
3738
+ _context23.prev = 46;
3739
+ _context23.t1 = _context23["catch"](41);
3725
3740
  this.logError('增量保存订单到 SQLite 失败', {
3726
- error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
3741
+ error: _context23.t1 instanceof Error ? _context23.t1.message : String(_context23.t1),
3727
3742
  orderCount: ordersSnapshot.length
3728
3743
  });
3729
3744
  if (!options.throwOnError) {
3730
- _context23.next = 28;
3745
+ _context23.next = 51;
3731
3746
  break;
3732
3747
  }
3733
- throw _context23.t0;
3734
- case 28:
3748
+ throw _context23.t1;
3749
+ case 51:
3735
3750
  case "end":
3736
3751
  return _context23.stop();
3737
3752
  }
3738
- }, _callee23, this, [[18, 23]]);
3753
+ }, _callee23, this, [[22, 35, 38, 41], [41, 46]]);
3739
3754
  }));
3740
3755
  function patchOrdersInSQLite(_x16, _x17) {
3741
3756
  return _patchOrdersInSQLite.apply(this, arguments);
@@ -3883,7 +3898,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3883
3898
  * 用于 SSE 全量拉取与营业日窗口裁剪。
3884
3899
  *
3885
3900
  * @example
3886
- * const { orders, persisted } = await this.replaceOrdersSnapshotInSQLite(orderList, 'refresh')
3901
+ * await this.replaceOrdersSnapshotInSQLite(orderList)
3887
3902
  */
3888
3903
  )
3889
3904
  }, {
@@ -3894,7 +3909,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3894
3909
  var protectedOrdersBeforeRemoteFetch,
3895
3910
  remoteSnapshot,
3896
3911
  mergedSnapshot,
3897
- persisted,
3898
3912
  _args27 = arguments;
3899
3913
  return _regeneratorRuntime().wrap(function _callee27$(_context27) {
3900
3914
  while (1) switch (_context27.prev = _context27.next) {
@@ -3904,12 +3918,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3904
3918
  _context27.next = 3;
3905
3919
  break;
3906
3920
  }
3907
- return _context27.abrupt("return", {
3908
- orders: this.compactOrderListByIdentity(orderList.map(function (order) {
3909
- return _this24.normalizeRemoteSyncedOrder(order);
3910
- }), "".concat(source, ".snapshotNoDb")).list,
3911
- persisted: false
3912
- });
3921
+ return _context27.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
3922
+ return _this24.normalizeRemoteSyncedOrder(order);
3923
+ }), "".concat(source, ".snapshotNoDb")).list);
3913
3924
  case 3:
3914
3925
  remoteSnapshot = cloneDeep(orderList).map(function (order) {
3915
3926
  return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
@@ -3917,11 +3928,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3917
3928
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
3918
3929
  return _this24.normalizeRemoteSyncedOrder(order);
3919
3930
  }), "".concat(source, ".remoteSnapshot")).list;
3920
- persisted = false;
3921
- _context27.prev = 6;
3922
- _context27.next = 9;
3931
+ _context27.prev = 5;
3932
+ _context27.next = 8;
3923
3933
  return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
3924
- var existingOrders, protectedLocalOrders, _iterator33, _step33, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
3934
+ var existingOrders, protectedLocalOrders, _iterator36, _step36, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
3925
3935
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3926
3936
  while (1) switch (_context26.prev = _context26.next) {
3927
3937
  case 0:
@@ -3944,15 +3954,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3944
3954
  }).filter(function (order) {
3945
3955
  return _this24.shouldProtectLocalOrderFromRemoteSnapshot(order);
3946
3956
  });
3947
- _iterator33 = _createForOfIteratorHelper(existingOrders || []);
3957
+ _iterator36 = _createForOfIteratorHelper(existingOrders || []);
3948
3958
  _context26.prev = 10;
3949
- _iterator33.s();
3959
+ _iterator36.s();
3950
3960
  case 12:
3951
- if ((_step33 = _iterator33.n()).done) {
3961
+ if ((_step36 = _iterator36.n()).done) {
3952
3962
  _context26.next = 23;
3953
3963
  break;
3954
3964
  }
3955
- rawCurrentOrder = _step33.value;
3965
+ rawCurrentOrder = _step36.value;
3956
3966
  currentOrder = _this24.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
3957
3967
  protectedIndex = _this24.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
3958
3968
  currentNeedsProtection = _this24.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
@@ -3977,10 +3987,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3977
3987
  case 25:
3978
3988
  _context26.prev = 25;
3979
3989
  _context26.t1 = _context26["catch"](10);
3980
- _iterator33.e(_context26.t1);
3990
+ _iterator36.e(_context26.t1);
3981
3991
  case 28:
3982
3992
  _context26.prev = 28;
3983
- _iterator33.f();
3993
+ _iterator36.f();
3984
3994
  return _context26.finish(28);
3985
3995
  case 31:
3986
3996
  orderListSnapshot = _this24.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
@@ -4032,27 +4042,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4032
4042
  }
4033
4043
  }, _callee26, null, [[10, 25, 28, 31]]);
4034
4044
  })));
4035
- case 9:
4036
- persisted = true;
4037
- _context27.next = 15;
4045
+ case 8:
4046
+ _context27.next = 13;
4038
4047
  break;
4039
- case 12:
4040
- _context27.prev = 12;
4041
- _context27.t0 = _context27["catch"](6);
4048
+ case 10:
4049
+ _context27.prev = 10;
4050
+ _context27.t0 = _context27["catch"](5);
4042
4051
  this.logError('全量保存订单到 SQLite 失败', {
4043
4052
  error: _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0),
4044
4053
  orderList: remoteSnapshot.length
4045
4054
  });
4046
- case 15:
4047
- return _context27.abrupt("return", {
4048
- orders: mergedSnapshot,
4049
- persisted: persisted
4050
- });
4051
- case 16:
4055
+ case 13:
4056
+ return _context27.abrupt("return", mergedSnapshot);
4057
+ case 14:
4052
4058
  case "end":
4053
4059
  return _context27.stop();
4054
4060
  }
4055
- }, _callee27, this, [[6, 12]]);
4061
+ }, _callee27, this, [[5, 10]]);
4056
4062
  }));
4057
4063
  function replaceOrdersSnapshotInSQLite(_x20, _x21) {
4058
4064
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
@@ -4094,7 +4100,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4094
4100
  }, _callee28);
4095
4101
  })));
4096
4102
  case 5:
4097
- this.clearOrderSnapshotMarker();
4103
+ this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
4098
4104
  this.emitOrdersChanged([], 'clear');
4099
4105
  case 7:
4100
4106
  case "end":