@pisell/pisellos 2.3.65 → 2.3.67

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