@pisell/pisellos 2.3.155 → 2.3.156

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.
@@ -31,6 +31,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
31
31
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
32
32
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
33
33
  import { cloneDeep } from 'lodash-es';
34
+ import { isLocalFinalizedPayment, LOCAL_EFTPOS_FINALIZED, LOCAL_EFTPOS_REFRESH_REQUIRED, requiresLocalPaymentRefresh } from "../../../modules/Order/localEftposState";
34
35
  import dayjs from 'dayjs';
35
36
  import { BaseModule } from "../../../modules/BaseModule";
36
37
  import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollections } from "../../../modules/Order/utils/orderCollectionIdentity";
@@ -387,9 +388,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
387
388
  var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
388
389
  var kind = ORDER_COLLECTION_KIND_BY_FIELD[field];
389
390
  var existingItems = Array.isArray(existing) ? existing : [];
390
- if (field === 'payments' && options.preserveIdentifiedPendingPayments) {
391
+ if (field === 'payments' && (options.preserveIdentifiedPendingPayments || existingItems.some(isLocalFinalizedPayment))) {
391
392
  return mergeOrderPaymentListsByIdentity(existingItems, incoming, {
392
- preserveUnmatchedExistingWhen: isIdentifiedPendingOrderPayment
393
+ preserveUnmatchedExistingWhen: function preserveUnmatchedExistingWhen(payment) {
394
+ return options.preserveIdentifiedPendingPayments === true && isIdentifiedPendingOrderPayment(payment) || isLocalFinalizedPayment(payment);
395
+ }
393
396
  });
394
397
  }
395
398
  return incoming.map(function (incomingItem) {
@@ -1050,6 +1053,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1050
1053
  key: "updateLocalPayment",
1051
1054
  value: function () {
1052
1055
  var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
1056
+ var _found$payment$metada;
1053
1057
  var logContext, found, previousPayment, nextPayment, nextOrder, paymentContext, targetIndex, shouldKeepInMemory, previousList, storageOrder, _storageOrder$order_i, _storageOrder$order_i2, _storageOrder$order_i3;
1054
1058
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1055
1059
  while (1) switch (_context7.prev = _context7.next) {
@@ -1073,6 +1077,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1073
1077
  return _context7.abrupt("return", null);
1074
1078
  case 8:
1075
1079
  previousPayment = cloneDeep(found.payment);
1080
+ if (!(params.finalizeUnsuccessful && (found.payment.status === 'paid' || (_found$payment$metada = found.payment.metadata) !== null && _found$payment$metada !== void 0 && (_found$payment$metada = _found$payment$metada.transactions) !== null && _found$payment$metada !== void 0 && _found$payment$metada.some(function (transaction) {
1081
+ return transaction.status === 'success';
1082
+ }) || isLocalFinalizedPayment(found.payment)))) {
1083
+ _context7.next = 11;
1084
+ break;
1085
+ }
1086
+ return _context7.abrupt("return", {
1087
+ order: found.order,
1088
+ payment: found.payment,
1089
+ previousPayment: previousPayment
1090
+ });
1091
+ case 11:
1076
1092
  nextPayment = mergeOrderPaymentRecord(found.payment, _objectSpread(_objectSpread({}, params.updates), {}, {
1077
1093
  updated_at: params.updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
1078
1094
  }));
@@ -1082,6 +1098,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1082
1098
  }),
1083
1099
  updated_at: dayjs().format('YYYY-MM-DD HH:mm:ss')
1084
1100
  });
1101
+ if (params.finalizeUnsuccessful && this.hasRealOrderId(found.order) && Number(found.order.need_sync || 0) === 0 && !(nextOrder.payments || []).some(isPendingOrderPayment)) {
1102
+ nextOrder.is_draft_order = 0;
1103
+ nextOrder.metadata = _objectSpread(_objectSpread({}, nextOrder.metadata), {}, _defineProperty({}, LOCAL_EFTPOS_REFRESH_REQUIRED, true));
1104
+ }
1085
1105
  paymentContext = _objectSpread(_objectSpread(_objectSpread({}, logContext), {}, {
1086
1106
  matched_by: found.matchedBy,
1087
1107
  payment_index: found.paymentIndex
@@ -1093,12 +1113,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1093
1113
  targetIndex = this.findOrderIndexByIdentity(this.store.list, found.order);
1094
1114
  shouldKeepInMemory = this.shouldKeepOrderInMemory(nextOrder);
1095
1115
  if (!(targetIndex < 0 && shouldKeepInMemory)) {
1096
- _context7.next = 18;
1116
+ _context7.next = 21;
1097
1117
  break;
1098
1118
  }
1099
1119
  this.logError('updateLocalPayment-订单Store索引未命中', paymentContext);
1100
1120
  return _context7.abrupt("return", null);
1101
- case 18:
1121
+ case 21:
1102
1122
  previousList = this.store.list;
1103
1123
  this.store.list = shouldKeepInMemory ? this.store.list.map(function (order, index) {
1104
1124
  return index === targetIndex ? nextOrder : order;
@@ -1107,23 +1127,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1107
1127
  });
1108
1128
  this.syncOrdersMap();
1109
1129
  storageOrder = this.withoutSyntheticDraftOrderId(nextOrder);
1110
- _context7.prev = 22;
1130
+ _context7.prev = 25;
1111
1131
  this.logInfo('updateLocalPayment-SQLite写入开始', _objectSpread(_objectSpread({}, paymentContext), {}, {
1112
1132
  storage_order_id: (_storageOrder$order_i = storageOrder.order_id) !== null && _storageOrder$order_i !== void 0 ? _storageOrder$order_i : null
1113
1133
  }));
1114
- _context7.next = 26;
1134
+ _context7.next = 29;
1115
1135
  return this.updateOrderInSQLite(storageOrder, 'updateLocalPayment', {
1116
1136
  throwOnError: true
1117
1137
  });
1118
- case 26:
1138
+ case 29:
1119
1139
  this.logInfo('updateLocalPayment-SQLite写入完成', _objectSpread(_objectSpread({}, paymentContext), {}, {
1120
1140
  storage_order_id: (_storageOrder$order_i2 = storageOrder.order_id) !== null && _storageOrder$order_i2 !== void 0 ? _storageOrder$order_i2 : null
1121
1141
  }));
1122
- _context7.next = 35;
1142
+ _context7.next = 38;
1123
1143
  break;
1124
- case 29:
1125
- _context7.prev = 29;
1126
- _context7.t0 = _context7["catch"](22);
1144
+ case 32:
1145
+ _context7.prev = 32;
1146
+ _context7.t0 = _context7["catch"](25);
1127
1147
  this.store.list = previousList;
1128
1148
  this.syncOrdersMap();
1129
1149
  this.logError('updateLocalPayment-SQLite写入失败并回滚内存', _objectSpread(_objectSpread({}, paymentContext), {}, {
@@ -1131,35 +1151,164 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1131
1151
  error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
1132
1152
  }));
1133
1153
  throw _context7.t0;
1134
- case 35:
1154
+ case 38:
1135
1155
  if (!(shouldKeepInMemory || targetIndex >= 0)) {
1136
- _context7.next = 38;
1156
+ _context7.next = 41;
1137
1157
  break;
1138
1158
  }
1139
- _context7.next = 38;
1159
+ _context7.next = 41;
1140
1160
  return this.emitOrdersChanged(shouldKeepInMemory ? [nextOrder] : [], shouldKeepInMemory ? 'updateLocalPayment' : 'updateLocalPayment.sqliteOnlyDraft');
1141
- case 38:
1161
+ case 41:
1142
1162
  this.logInfo('updateLocalPayment-变更事件完成', paymentContext);
1143
1163
  return _context7.abrupt("return", {
1144
1164
  order: nextOrder,
1145
1165
  payment: nextPayment,
1146
1166
  previousPayment: previousPayment
1147
1167
  });
1148
- case 40:
1168
+ case 43:
1149
1169
  case "end":
1150
1170
  return _context7.stop();
1151
1171
  }
1152
- }, _callee7, this, [[22, 29]]);
1172
+ }, _callee7, this, [[25, 32]]);
1153
1173
  }));
1154
1174
  function updateLocalPayment(_x6) {
1155
1175
  return _updateLocalPayment.apply(this, arguments);
1156
1176
  }
1157
1177
  return updateLocalPayment;
1158
1178
  }()
1179
+ }, {
1180
+ key: "finalizeLocalEftposPayment",
1181
+ value: function () {
1182
+ var _finalizeLocalEftposPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
1183
+ var _found$payment$metada2;
1184
+ var found, transactions;
1185
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1186
+ while (1) switch (_context8.prev = _context8.next) {
1187
+ case 0:
1188
+ _context8.next = 2;
1189
+ return this.getLocalPayment(params);
1190
+ case 2:
1191
+ found = _context8.sent;
1192
+ if (found) {
1193
+ _context8.next = 5;
1194
+ break;
1195
+ }
1196
+ throw new Error('未找到本地支付记录');
1197
+ case 5:
1198
+ transactions = ((_found$payment$metada2 = found.payment.metadata) === null || _found$payment$metada2 === void 0 ? void 0 : _found$payment$metada2.transactions) || [];
1199
+ if (!transactions.some(function (transaction) {
1200
+ return transaction.status !== 'fail' && transaction.status !== 'success' && !params.failedTransactionNumbers.includes(String(transaction.number));
1201
+ })) {
1202
+ _context8.next = 8;
1203
+ break;
1204
+ }
1205
+ throw new Error('仍有结果未知的交易,保留待确认支付');
1206
+ case 8:
1207
+ if (!(params.result === 'not_started' && transactions.length > 0 && !isLocalFinalizedPayment(found.payment) && found.payment.status !== 'paid')) {
1208
+ _context8.next = 10;
1209
+ break;
1210
+ }
1211
+ throw new Error('支付已有交易记录,不能按未发起交易结束');
1212
+ case 10:
1213
+ return _context8.abrupt("return", this.updateLocalPayment(_objectSpread(_objectSpread({}, params), {}, {
1214
+ finalizeUnsuccessful: true,
1215
+ updates: {
1216
+ status: 'voided',
1217
+ metadata: _defineProperty(_defineProperty({}, LOCAL_EFTPOS_FINALIZED, true), "transactions", params.failedTransactionNumbers.map(function (number) {
1218
+ return {
1219
+ number: number,
1220
+ status: 'fail'
1221
+ };
1222
+ }))
1223
+ }
1224
+ })));
1225
+ case 11:
1226
+ case "end":
1227
+ return _context8.stop();
1228
+ }
1229
+ }, _callee8, this);
1230
+ }));
1231
+ function finalizeLocalEftposPayment(_x7) {
1232
+ return _finalizeLocalEftposPayment.apply(this, arguments);
1233
+ }
1234
+ return finalizeLocalEftposPayment;
1235
+ }() /** Only a successful full detail GET may release the persisted payment gate. */
1236
+ }, {
1237
+ key: "completeLocalPaymentRefresh",
1238
+ value: (function () {
1239
+ var _completeLocalPaymentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fresh) {
1240
+ var existing, nextOrder, index;
1241
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1242
+ while (1) switch (_context9.prev = _context9.next) {
1243
+ case 0:
1244
+ _context9.next = 2;
1245
+ return this.getLocalOrderByLookup(fresh.order_id);
1246
+ case 2:
1247
+ existing = _context9.sent;
1248
+ if (!(!existing || !requiresLocalPaymentRefresh(existing))) {
1249
+ _context9.next = 12;
1250
+ break;
1251
+ }
1252
+ _context9.next = 6;
1253
+ return this.upsertOrdersFromRemote([fresh]);
1254
+ case 6:
1255
+ _context9.next = 8;
1256
+ return this.getLocalOrderByLookup(fresh.order_id);
1257
+ case 8:
1258
+ _context9.t0 = _context9.sent;
1259
+ if (_context9.t0) {
1260
+ _context9.next = 11;
1261
+ break;
1262
+ }
1263
+ _context9.t0 = fresh;
1264
+ case 11:
1265
+ return _context9.abrupt("return", _context9.t0);
1266
+ case 12:
1267
+ if (!(this.isPendingSyncOrder(existing) || this.isDraftOrder(existing) || (existing.payments || []).some(isPendingOrderPayment))) {
1268
+ _context9.next = 14;
1269
+ break;
1270
+ }
1271
+ throw new Error('订单仍有未结束支付或待同步改动,暂不能刷新');
1272
+ case 14:
1273
+ if (!(!Array.isArray(fresh.products) || !fresh.summary)) {
1274
+ _context9.next = 16;
1275
+ break;
1276
+ }
1277
+ throw new Error('远端订单详情不完整,请重新刷新');
1278
+ case 16:
1279
+ nextOrder = this.mergeOrderRecords(existing, this.normalizeRemoteSyncedOrder(fresh));
1280
+ nextOrder.metadata = _objectSpread({}, nextOrder.metadata);
1281
+ delete nextOrder.metadata[LOCAL_EFTPOS_REFRESH_REQUIRED];
1282
+ // Do not publish/clear the gate in memory until SQLite has accepted the full snapshot.
1283
+ _context9.next = 21;
1284
+ return this.updateOrderInSQLite(nextOrder, 'completeLocalPaymentRefresh', {
1285
+ throwOnError: true
1286
+ });
1287
+ case 21:
1288
+ index = this.findOrderIndexByIdentity(this.store.list, existing);
1289
+ this.store.list = index < 0 ? [].concat(_toConsumableArray(this.store.list), [nextOrder]) : this.store.list.map(function (order, i) {
1290
+ return i === index ? nextOrder : order;
1291
+ });
1292
+ this.syncOrdersMap();
1293
+ _context9.next = 26;
1294
+ return this.emitOrdersChanged([nextOrder], 'completeLocalPaymentRefresh');
1295
+ case 26:
1296
+ return _context9.abrupt("return", nextOrder);
1297
+ case 27:
1298
+ case "end":
1299
+ return _context9.stop();
1300
+ }
1301
+ }, _callee9, this);
1302
+ }));
1303
+ function completeLocalPaymentRefresh(_x8) {
1304
+ return _completeLocalPaymentRefresh.apply(this, arguments);
1305
+ }
1306
+ return completeLocalPaymentRefresh;
1307
+ }())
1159
1308
  }, {
1160
1309
  key: "loadOrdersByServer",
1161
1310
  value: function () {
1162
- var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1311
+ var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1163
1312
  var _this5 = this,
1164
1313
  _this$store;
1165
1314
  var options,
@@ -1172,18 +1321,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1172
1321
  mergedOrders,
1173
1322
  isRemoteSnapshotPersisted,
1174
1323
  memoryOrders,
1175
- _args8 = arguments;
1176
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1177
- while (1) switch (_context8.prev = _context8.next) {
1324
+ _args10 = arguments;
1325
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1326
+ while (1) switch (_context10.prev = _context10.next) {
1178
1327
  case 0:
1179
- options = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
1328
+ options = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
1180
1329
  orderList = [];
1181
1330
  hasFetchedRemoteSnapshot = false;
1182
1331
  trigger = options.trigger || 'unknown';
1183
- _context8.next = 6;
1332
+ _context10.next = 6;
1184
1333
  return this.loadOrdersFromSQLite();
1185
1334
  case 6:
1186
- protectedOrdersBeforeRemoteFetch = _context8.sent.filter(function (order) {
1335
+ protectedOrdersBeforeRemoteFetch = _context10.sent.filter(function (order) {
1187
1336
  return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
1188
1337
  });
1189
1338
  this.logInfo('loadOrdersByServer-开始', {
@@ -1196,18 +1345,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1196
1345
  }, 0)
1197
1346
  });
1198
1347
  if (!this.orderDataSource) {
1199
- _context8.next = 23;
1348
+ _context10.next = 23;
1200
1349
  break;
1201
1350
  }
1202
- _context8.prev = 9;
1203
- _context8.next = 12;
1351
+ _context10.prev = 9;
1352
+ _context10.next = 12;
1204
1353
  return this.orderDataSource.run({
1205
1354
  sse: {
1206
1355
  query: this.store.createdAtQuery
1207
1356
  }
1208
1357
  });
1209
1358
  case 12:
1210
- data = _context8.sent;
1359
+ data = _context10.sent;
1211
1360
  orderList = data || [];
1212
1361
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
1213
1362
  trigger: trigger,
@@ -1215,21 +1364,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1215
1364
  });
1216
1365
  hasFetchedRemoteSnapshot = true;
1217
1366
  this.lastServerFullFetchAtMs = Date.now();
1218
- _context8.next = 23;
1367
+ _context10.next = 23;
1219
1368
  break;
1220
1369
  case 19:
1221
- _context8.prev = 19;
1222
- _context8.t0 = _context8["catch"](9);
1370
+ _context10.prev = 19;
1371
+ _context10.t0 = _context10["catch"](9);
1223
1372
  this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
1224
- return _context8.abrupt("return", this.store.list);
1373
+ return _context10.abrupt("return", this.store.list);
1225
1374
  case 23:
1226
1375
  if (hasFetchedRemoteSnapshot) {
1227
1376
  this.clearOrderSnapshotMarker();
1228
1377
  }
1229
- _context8.next = 26;
1378
+ _context10.next = 26;
1230
1379
  return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
1231
1380
  case 26:
1232
- _yield$this$replaceOr = _context8.sent;
1381
+ _yield$this$replaceOr = _context10.sent;
1233
1382
  mergedOrders = _yield$this$replaceOr.orders;
1234
1383
  isRemoteSnapshotPersisted = _yield$this$replaceOr.persisted;
1235
1384
  if (hasFetchedRemoteSnapshot && isRemoteSnapshotPersisted) {
@@ -1242,15 +1391,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1242
1391
  persistedCount: mergedOrders.length,
1243
1392
  sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
1244
1393
  });
1245
- _context8.next = 34;
1394
+ _context10.next = 34;
1246
1395
  return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
1247
1396
  case 34:
1248
- return _context8.abrupt("return", memoryOrders);
1397
+ return _context10.abrupt("return", memoryOrders);
1249
1398
  case 35:
1250
1399
  case "end":
1251
- return _context8.stop();
1400
+ return _context10.stop();
1252
1401
  }
1253
- }, _callee8, this, [[9, 19]]);
1402
+ }, _callee10, this, [[9, 19]]);
1254
1403
  }));
1255
1404
  function loadOrdersByServer() {
1256
1405
  return _loadOrdersByServer.apply(this, arguments);
@@ -1264,25 +1413,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1264
1413
  }, {
1265
1414
  key: "refreshOrdersForCurrentBusinessDay",
1266
1415
  value: (function () {
1267
- var _refreshOrdersForCurrentBusinessDay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1416
+ var _refreshOrdersForCurrentBusinessDay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1268
1417
  var options,
1269
1418
  refreshPromise,
1270
- _args9 = arguments;
1271
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1272
- while (1) switch (_context9.prev = _context9.next) {
1419
+ _args11 = arguments;
1420
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1421
+ while (1) switch (_context11.prev = _context11.next) {
1273
1422
  case 0:
1274
- options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
1423
+ options = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : {};
1275
1424
  if (!this.businessDayRefreshPromise) {
1276
- _context9.next = 3;
1425
+ _context11.next = 3;
1277
1426
  break;
1278
1427
  }
1279
- return _context9.abrupt("return", this.businessDayRefreshPromise);
1428
+ return _context11.abrupt("return", this.businessDayRefreshPromise);
1280
1429
  case 3:
1281
1430
  if (!(!this.orderDataSource || !this.getCurrentShopId() || this.hasPulledOrdersToday())) {
1282
- _context9.next = 5;
1431
+ _context11.next = 5;
1283
1432
  break;
1284
1433
  }
1285
- return _context9.abrupt("return");
1434
+ return _context11.abrupt("return");
1286
1435
  case 5:
1287
1436
  refreshPromise = this.silentRefresh({
1288
1437
  trigger: options.trigger || 'business_day_rollover'
@@ -1290,18 +1439,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1290
1439
  return undefined;
1291
1440
  });
1292
1441
  this.businessDayRefreshPromise = refreshPromise;
1293
- _context9.prev = 7;
1294
- _context9.next = 10;
1442
+ _context11.prev = 7;
1443
+ _context11.next = 10;
1295
1444
  return refreshPromise;
1296
1445
  case 10:
1297
- _context9.prev = 10;
1446
+ _context11.prev = 10;
1298
1447
  this.businessDayRefreshPromise = null;
1299
- return _context9.finish(10);
1448
+ return _context11.finish(10);
1300
1449
  case 13:
1301
1450
  case "end":
1302
- return _context9.stop();
1451
+ return _context11.stop();
1303
1452
  }
1304
- }, _callee9, this, [[7,, 10, 13]]);
1453
+ }, _callee11, this, [[7,, 10, 13]]);
1305
1454
  }));
1306
1455
  function refreshOrdersForCurrentBusinessDay() {
1307
1456
  return _refreshOrdersForCurrentBusinessDay.apply(this, arguments);
@@ -1317,23 +1466,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1317
1466
  }, {
1318
1467
  key: "silentRefresh",
1319
1468
  value: (function () {
1320
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1469
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1321
1470
  var options,
1322
1471
  startTime,
1323
1472
  trigger,
1324
1473
  elapsedSinceFullFetch,
1325
1474
  orders,
1326
1475
  errorMessage,
1327
- _args10 = arguments;
1328
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1329
- while (1) switch (_context10.prev = _context10.next) {
1476
+ _args12 = arguments;
1477
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1478
+ while (1) switch (_context12.prev = _context12.next) {
1330
1479
  case 0:
1331
- options = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
1480
+ options = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
1332
1481
  startTime = Date.now();
1333
1482
  trigger = options.trigger || 'background';
1334
1483
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
1335
1484
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
1336
- _context10.next = 7;
1485
+ _context12.next = 7;
1337
1486
  break;
1338
1487
  }
1339
1488
  this.logInfo('silentRefresh 跳过全量 SSE', {
@@ -1343,28 +1492,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1343
1492
  elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1344
1493
  orderCount: this.store.list.length
1345
1494
  });
1346
- return _context10.abrupt("return", this.store.list);
1495
+ return _context12.abrupt("return", this.store.list);
1347
1496
  case 7:
1348
1497
  this.logInfo('silentRefresh 开始', {
1349
1498
  trigger: trigger,
1350
1499
  elapsedSinceFullFetchMs: elapsedSinceFullFetch,
1351
1500
  orderCount: this.store.list.length
1352
1501
  });
1353
- _context10.prev = 8;
1502
+ _context12.prev = 8;
1354
1503
  // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
1355
1504
  this.updateCreateStore();
1356
- _context10.next = 12;
1505
+ _context12.next = 12;
1357
1506
  return this.loadOrdersByServer({
1358
1507
  trigger: trigger
1359
1508
  });
1360
1509
  case 12:
1361
- orders = _context10.sent;
1510
+ orders = _context12.sent;
1362
1511
  this.store.list = cloneDeep(orders);
1363
1512
  this.syncOrdersMap();
1364
- _context10.next = 17;
1513
+ _context12.next = 17;
1365
1514
  return this.emitOrdersChanged([], 'silentRefresh');
1366
1515
  case 17:
1367
- _context10.next = 19;
1516
+ _context12.next = 19;
1368
1517
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1369
1518
  case 19:
1370
1519
  this.logInfo('silentRefresh 完成', {
@@ -1372,22 +1521,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1372
1521
  orderCount: orders.length,
1373
1522
  duration: "".concat(Date.now() - startTime, "ms")
1374
1523
  });
1375
- return _context10.abrupt("return", this.store.list);
1524
+ return _context12.abrupt("return", this.store.list);
1376
1525
  case 23:
1377
- _context10.prev = 23;
1378
- _context10.t0 = _context10["catch"](8);
1379
- errorMessage = _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0);
1526
+ _context12.prev = 23;
1527
+ _context12.t0 = _context12["catch"](8);
1528
+ errorMessage = _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0);
1380
1529
  this.logError('silentRefresh 失败', {
1381
1530
  trigger: trigger,
1382
1531
  duration: "".concat(Date.now() - startTime, "ms"),
1383
1532
  error: errorMessage
1384
1533
  });
1385
- return _context10.abrupt("return", this.store.list);
1534
+ return _context12.abrupt("return", this.store.list);
1386
1535
  case 28:
1387
1536
  case "end":
1388
- return _context10.stop();
1537
+ return _context12.stop();
1389
1538
  }
1390
- }, _callee10, this, [[8, 23]]);
1539
+ }, _callee12, this, [[8, 23]]);
1391
1540
  }));
1392
1541
  function silentRefresh() {
1393
1542
  return _silentRefresh.apply(this, arguments);
@@ -1473,31 +1622,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1473
1622
  }, {
1474
1623
  key: "overwriteExistingOrder",
1475
1624
  value: (function () {
1476
- var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(fresh) {
1625
+ var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(fresh) {
1477
1626
  var _this8 = this;
1478
1627
  var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
1479
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1480
- while (1) switch (_context11.prev = _context11.next) {
1628
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1629
+ while (1) switch (_context13.prev = _context13.next) {
1481
1630
  case 0:
1482
1631
  orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
1483
1632
  if (!(orderId === undefined || orderId === null)) {
1484
- _context11.next = 4;
1633
+ _context13.next = 4;
1485
1634
  break;
1486
1635
  }
1487
1636
  this.logError('overwriteExistingOrder-入参缺少 order_id');
1488
- return _context11.abrupt("return", {
1637
+ return _context13.abrupt("return", {
1489
1638
  overwritten: false
1490
1639
  });
1491
1640
  case 4:
1492
1641
  key = this.getIdKey(orderId);
1493
1642
  if (this.store.map.has(key)) {
1494
- _context11.next = 8;
1643
+ _context13.next = 8;
1495
1644
  break;
1496
1645
  }
1497
1646
  this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
1498
1647
  orderId: orderId
1499
1648
  });
1500
- return _context11.abrupt("return", {
1649
+ return _context13.abrupt("return", {
1501
1650
  overwritten: false
1502
1651
  });
1503
1652
  case 8:
@@ -1516,26 +1665,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1516
1665
  return _this8.getIdKey(id) === key ? reconciledFresh : _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
1517
1666
  });
1518
1667
  this.syncOrdersMap();
1519
- _context11.next = 16;
1668
+ _context13.next = 16;
1520
1669
  return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
1521
1670
  case 16:
1522
1671
  this.logInfo('overwriteExistingOrder-结束', {
1523
1672
  orderId: orderId,
1524
1673
  storeOrderCountAfter: this.store.list.length
1525
1674
  });
1526
- _context11.next = 19;
1675
+ _context13.next = 19;
1527
1676
  return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
1528
1677
  case 19:
1529
- return _context11.abrupt("return", {
1678
+ return _context13.abrupt("return", {
1530
1679
  overwritten: true
1531
1680
  });
1532
1681
  case 20:
1533
1682
  case "end":
1534
- return _context11.stop();
1683
+ return _context13.stop();
1535
1684
  }
1536
- }, _callee11, this);
1685
+ }, _callee13, this);
1537
1686
  }));
1538
- function overwriteExistingOrder(_x7) {
1687
+ function overwriteExistingOrder(_x9) {
1539
1688
  return _overwriteExistingOrder.apply(this, arguments);
1540
1689
  }
1541
1690
  return overwriteExistingOrder;
@@ -1548,35 +1697,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1548
1697
  }, {
1549
1698
  key: "upsertOrdersFromRemote",
1550
1699
  value: (function () {
1551
- var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(freshOrders) {
1700
+ var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(freshOrders) {
1552
1701
  var source,
1553
- _args12 = arguments;
1554
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1555
- while (1) switch (_context12.prev = _context12.next) {
1702
+ _args14 = arguments;
1703
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1704
+ while (1) switch (_context14.prev = _context14.next) {
1556
1705
  case 0:
1557
- source = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : 'upsertOrdersFromRemote';
1706
+ source = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : 'upsertOrdersFromRemote';
1558
1707
  if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
1559
- _context12.next = 4;
1708
+ _context14.next = 4;
1560
1709
  break;
1561
1710
  }
1562
1711
  this.logInfo('upsertOrdersFromRemote-订单列表为空', {
1563
1712
  source: source
1564
1713
  });
1565
- return _context12.abrupt("return");
1714
+ return _context14.abrupt("return");
1566
1715
  case 4:
1567
1716
  this.logInfo('upsertOrdersFromRemote-开始', {
1568
1717
  count: freshOrders.length,
1569
1718
  source: source
1570
1719
  });
1571
- _context12.next = 7;
1720
+ _context14.next = 7;
1572
1721
  return this.mergeOrdersToStore(freshOrders, source);
1573
1722
  case 7:
1574
1723
  case "end":
1575
- return _context12.stop();
1724
+ return _context14.stop();
1576
1725
  }
1577
- }, _callee12, this);
1726
+ }, _callee14, this);
1578
1727
  }));
1579
- function upsertOrdersFromRemote(_x8) {
1728
+ function upsertOrdersFromRemote(_x10) {
1580
1729
  return _upsertOrdersFromRemote.apply(this, arguments);
1581
1730
  }
1582
1731
  return upsertOrdersFromRemote;
@@ -1584,21 +1733,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1584
1733
  }, {
1585
1734
  key: "markOrderSyncedByExternalSaleNumber",
1586
1735
  value: function () {
1587
- var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(params) {
1736
+ var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1588
1737
  var _this9 = this,
1589
1738
  _existing$external_sa,
1590
1739
  _nextOrder$order_id;
1591
1740
  var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
1592
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1593
- while (1) switch (_context13.prev = _context13.next) {
1741
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1742
+ while (1) switch (_context15.prev = _context15.next) {
1594
1743
  case 0:
1595
1744
  externalSaleNumber = params.externalSaleNumber;
1596
1745
  if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
1597
- _context13.next = 4;
1746
+ _context15.next = 4;
1598
1747
  break;
1599
1748
  }
1600
1749
  this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
1601
- return _context13.abrupt("return", {
1750
+ return _context15.abrupt("return", {
1602
1751
  updated: false
1603
1752
  });
1604
1753
  case 4:
@@ -1609,13 +1758,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1609
1758
  return _this9.getIdKey(value) === key;
1610
1759
  });
1611
1760
  if (!(targetIndex < 0)) {
1612
- _context13.next = 9;
1761
+ _context15.next = 9;
1613
1762
  break;
1614
1763
  }
1615
1764
  this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
1616
1765
  external_sale_number: externalSaleNumber
1617
1766
  });
1618
- return _context13.abrupt("return", {
1767
+ return _context15.abrupt("return", {
1619
1768
  updated: false
1620
1769
  });
1621
1770
  case 9:
@@ -1631,27 +1780,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1631
1780
  return nextOrder;
1632
1781
  });
1633
1782
  this.syncOrdersMap();
1634
- _context13.next = 16;
1783
+ _context15.next = 16;
1635
1784
  return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
1636
1785
  case 16:
1637
1786
  this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
1638
1787
  external_sale_number: externalSaleNumber,
1639
1788
  order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
1640
1789
  });
1641
- _context13.next = 19;
1790
+ _context15.next = 19;
1642
1791
  return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
1643
1792
  case 19:
1644
- return _context13.abrupt("return", {
1793
+ return _context15.abrupt("return", {
1645
1794
  updated: true,
1646
1795
  order: nextOrder
1647
1796
  });
1648
1797
  case 20:
1649
1798
  case "end":
1650
- return _context13.stop();
1799
+ return _context15.stop();
1651
1800
  }
1652
- }, _callee13, this);
1801
+ }, _callee15, this);
1653
1802
  }));
1654
- function markOrderSyncedByExternalSaleNumber(_x9) {
1803
+ function markOrderSyncedByExternalSaleNumber(_x11) {
1655
1804
  return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
1656
1805
  }
1657
1806
  return markOrderSyncedByExternalSaleNumber;
@@ -1663,7 +1812,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1663
1812
  }, {
1664
1813
  key: "upsertPendingSyncOrders",
1665
1814
  value: (function () {
1666
- var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(pendingOrders) {
1815
+ var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(pendingOrders) {
1667
1816
  var _this10 = this;
1668
1817
  var options,
1669
1818
  pendingMap,
@@ -1694,26 +1843,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1694
1843
  insertIndex,
1695
1844
  patchedOrders,
1696
1845
  previousList,
1697
- _args14 = arguments;
1698
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1699
- while (1) switch (_context14.prev = _context14.next) {
1846
+ _args16 = arguments;
1847
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1848
+ while (1) switch (_context16.prev = _context16.next) {
1700
1849
  case 0:
1701
- options = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : {};
1850
+ options = _args16.length > 1 && _args16[1] !== undefined ? _args16[1] : {};
1702
1851
  if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
1703
- _context14.next = 4;
1852
+ _context16.next = 4;
1704
1853
  break;
1705
1854
  }
1706
1855
  this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
1707
- return _context14.abrupt("return");
1856
+ return _context16.abrupt("return");
1708
1857
  case 4:
1709
1858
  pendingMap = new Map();
1710
1859
  memoryPendingMap = new Map();
1711
1860
  _iterator7 = _createForOfIteratorHelper(pendingOrders);
1712
- _context14.prev = 7;
1861
+ _context16.prev = 7;
1713
1862
  _iterator7.s();
1714
1863
  case 9:
1715
1864
  if ((_step7 = _iterator7.n()).done) {
1716
- _context14.next = 20;
1865
+ _context16.next = 20;
1717
1866
  break;
1718
1867
  }
1719
1868
  order = _step7.value;
@@ -1724,36 +1873,36 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1724
1873
  });
1725
1874
  storageKey = this.getOrderStorageKey(pendingOrder);
1726
1875
  if (storageKey) {
1727
- _context14.next = 16;
1876
+ _context16.next = 16;
1728
1877
  break;
1729
1878
  }
1730
- return _context14.abrupt("continue", 18);
1879
+ return _context16.abrupt("continue", 18);
1731
1880
  case 16:
1732
1881
  pendingMap.set(storageKey, pendingOrder);
1733
1882
  memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(pendingOrder, 'upsertPendingSyncOrders.memory'));
1734
1883
  case 18:
1735
- _context14.next = 9;
1884
+ _context16.next = 9;
1736
1885
  break;
1737
1886
  case 20:
1738
- _context14.next = 25;
1887
+ _context16.next = 25;
1739
1888
  break;
1740
1889
  case 22:
1741
- _context14.prev = 22;
1742
- _context14.t0 = _context14["catch"](7);
1743
- _iterator7.e(_context14.t0);
1890
+ _context16.prev = 22;
1891
+ _context16.t0 = _context16["catch"](7);
1892
+ _iterator7.e(_context16.t0);
1744
1893
  case 25:
1745
- _context14.prev = 25;
1894
+ _context16.prev = 25;
1746
1895
  _iterator7.f();
1747
- return _context14.finish(25);
1896
+ return _context16.finish(25);
1748
1897
  case 28:
1749
1898
  if (!(pendingMap.size === 0)) {
1750
- _context14.next = 31;
1899
+ _context16.next = 31;
1751
1900
  break;
1752
1901
  }
1753
1902
  this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
1754
1903
  count: pendingOrders.length
1755
1904
  });
1756
- return _context14.abrupt("return");
1905
+ return _context16.abrupt("return");
1757
1906
  case 31:
1758
1907
  this.logInfo('upsertPendingSyncOrders-开始', {
1759
1908
  count: pendingMap.size
@@ -1779,17 +1928,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1779
1928
  }
1780
1929
  }
1781
1930
  _iterator9 = _createForOfIteratorHelper(memoryPendingMap.entries());
1782
- _context14.prev = 37;
1931
+ _context16.prev = 37;
1783
1932
  _iterator9.s();
1784
1933
  case 39:
1785
1934
  if ((_step9 = _iterator9.n()).done) {
1786
- _context14.next = 58;
1935
+ _context16.next = 58;
1787
1936
  break;
1788
1937
  }
1789
1938
  _step9$value = _slicedToArray(_step9.value, 2), _storageKey = _step9$value[0], _pendingOrder = _step9$value[1];
1790
1939
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
1791
1940
  if (!(matchIndex >= 0)) {
1792
- _context14.next = 52;
1941
+ _context16.next = 52;
1793
1942
  break;
1794
1943
  }
1795
1944
  existingOrder = updatedList[matchIndex];
@@ -1806,57 +1955,57 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1806
1955
  // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
1807
1956
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1808
1957
  mergeActions[_storageKey] = 'update';
1809
- return _context14.abrupt("continue", 56);
1958
+ return _context16.abrupt("continue", 56);
1810
1959
  case 52:
1811
1960
  insertIndex = updatedList.length;
1812
1961
  updatedList.push(_pendingOrder);
1813
1962
  this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
1814
1963
  mergeActions[_storageKey] = 'insert';
1815
1964
  case 56:
1816
- _context14.next = 39;
1965
+ _context16.next = 39;
1817
1966
  break;
1818
1967
  case 58:
1819
- _context14.next = 63;
1968
+ _context16.next = 63;
1820
1969
  break;
1821
1970
  case 60:
1822
- _context14.prev = 60;
1823
- _context14.t1 = _context14["catch"](37);
1824
- _iterator9.e(_context14.t1);
1971
+ _context16.prev = 60;
1972
+ _context16.t1 = _context16["catch"](37);
1973
+ _iterator9.e(_context16.t1);
1825
1974
  case 63:
1826
- _context14.prev = 63;
1975
+ _context16.prev = 63;
1827
1976
  _iterator9.f();
1828
- return _context14.finish(63);
1977
+ return _context16.finish(63);
1829
1978
  case 66:
1830
1979
  patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
1831
1980
  previousList = this.store.list;
1832
1981
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
1833
1982
  this.syncOrdersMap();
1834
- _context14.prev = 70;
1835
- _context14.next = 73;
1983
+ _context16.prev = 70;
1984
+ _context16.next = 73;
1836
1985
  return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
1837
1986
  case 73:
1838
- _context14.next = 80;
1987
+ _context16.next = 80;
1839
1988
  break;
1840
1989
  case 75:
1841
- _context14.prev = 75;
1842
- _context14.t2 = _context14["catch"](70);
1990
+ _context16.prev = 75;
1991
+ _context16.t2 = _context16["catch"](70);
1843
1992
  this.store.list = previousList;
1844
1993
  this.syncOrdersMap();
1845
- throw _context14.t2;
1994
+ throw _context16.t2;
1846
1995
  case 80:
1847
1996
  this.logInfo('upsertPendingSyncOrders-结束', {
1848
1997
  count: patchedOrders.length,
1849
1998
  storeOrderCountAfter: this.store.list.length
1850
1999
  });
1851
- _context14.next = 83;
2000
+ _context16.next = 83;
1852
2001
  return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
1853
2002
  case 83:
1854
2003
  case "end":
1855
- return _context14.stop();
2004
+ return _context16.stop();
1856
2005
  }
1857
- }, _callee14, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
2006
+ }, _callee16, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
1858
2007
  }));
1859
- function upsertPendingSyncOrders(_x10) {
2008
+ function upsertPendingSyncOrders(_x12) {
1860
2009
  return _upsertPendingSyncOrders.apply(this, arguments);
1861
2010
  }
1862
2011
  return upsertPendingSyncOrders;
@@ -1869,27 +2018,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1869
2018
  }, {
1870
2019
  key: "upsertLocalDraftOrders",
1871
2020
  value: (function () {
1872
- var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(draftOrders) {
2021
+ var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(draftOrders) {
1873
2022
  var _this11 = this;
1874
2023
  var draftMap, memoryDraftMap, _iterator10, _step10, order, draftOrder, storageKey, memoryDraftOrder, mergeActions, updatedList, identityKeyToIndex, index, _iterator11, _step11, key, _iterator12, _step12, _step12$value, _storageKey2, _draftOrder, matchIndex, existingOrder, reconciledDraftOrder, mergedOrder, nextOrder, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
1875
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1876
- while (1) switch (_context15.prev = _context15.next) {
2024
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2025
+ while (1) switch (_context17.prev = _context17.next) {
1877
2026
  case 0:
1878
2027
  if (draftOrders !== null && draftOrders !== void 0 && draftOrders.length) {
1879
- _context15.next = 3;
2028
+ _context17.next = 3;
1880
2029
  break;
1881
2030
  }
1882
2031
  this.logInfo('upsertLocalDraftOrders-订单列表为空', {});
1883
- return _context15.abrupt("return");
2032
+ return _context17.abrupt("return");
1884
2033
  case 3:
1885
2034
  draftMap = new Map();
1886
2035
  memoryDraftMap = new Map();
1887
2036
  _iterator10 = _createForOfIteratorHelper(draftOrders);
1888
- _context15.prev = 6;
2037
+ _context17.prev = 6;
1889
2038
  _iterator10.s();
1890
2039
  case 8:
1891
2040
  if ((_step10 = _iterator10.n()).done) {
1892
- _context15.next = 19;
2041
+ _context17.next = 19;
1893
2042
  break;
1894
2043
  }
1895
2044
  order = _step10.value;
@@ -1899,10 +2048,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1899
2048
  });
1900
2049
  storageKey = this.getOrderStorageKey(draftOrder);
1901
2050
  if (storageKey) {
1902
- _context15.next = 14;
2051
+ _context17.next = 14;
1903
2052
  break;
1904
2053
  }
1905
- return _context15.abrupt("continue", 17);
2054
+ return _context17.abrupt("continue", 17);
1906
2055
  case 14:
1907
2056
  draftMap.set(storageKey, draftOrder);
1908
2057
  memoryDraftOrder = this.normalizeOrderForMemoryList(draftOrder);
@@ -1910,28 +2059,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1910
2059
  memoryDraftMap.set(storageKey, memoryDraftOrder);
1911
2060
  }
1912
2061
  case 17:
1913
- _context15.next = 8;
2062
+ _context17.next = 8;
1914
2063
  break;
1915
2064
  case 19:
1916
- _context15.next = 24;
2065
+ _context17.next = 24;
1917
2066
  break;
1918
2067
  case 21:
1919
- _context15.prev = 21;
1920
- _context15.t0 = _context15["catch"](6);
1921
- _iterator10.e(_context15.t0);
2068
+ _context17.prev = 21;
2069
+ _context17.t0 = _context17["catch"](6);
2070
+ _iterator10.e(_context17.t0);
1922
2071
  case 24:
1923
- _context15.prev = 24;
2072
+ _context17.prev = 24;
1924
2073
  _iterator10.f();
1925
- return _context15.finish(24);
2074
+ return _context17.finish(24);
1926
2075
  case 27:
1927
2076
  if (!(draftMap.size === 0)) {
1928
- _context15.next = 30;
2077
+ _context17.next = 30;
1929
2078
  break;
1930
2079
  }
1931
2080
  this.logError('upsertLocalDraftOrders-订单缺少可落库标识', {
1932
2081
  count: draftOrders.length
1933
2082
  });
1934
- return _context15.abrupt("return");
2083
+ return _context17.abrupt("return");
1935
2084
  case 30:
1936
2085
  this.logInfo('upsertLocalDraftOrders-开始', {
1937
2086
  count: draftMap.size,
@@ -1957,17 +2106,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1957
2106
  }
1958
2107
  }
1959
2108
  _iterator12 = _createForOfIteratorHelper(memoryDraftMap.entries());
1960
- _context15.prev = 36;
2109
+ _context17.prev = 36;
1961
2110
  _iterator12.s();
1962
2111
  case 38:
1963
2112
  if ((_step12 = _iterator12.n()).done) {
1964
- _context15.next = 57;
2113
+ _context17.next = 57;
1965
2114
  break;
1966
2115
  }
1967
2116
  _step12$value = _slicedToArray(_step12.value, 2), _storageKey2 = _step12$value[0], _draftOrder = _step12$value[1];
1968
2117
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
1969
2118
  if (!(matchIndex >= 0)) {
1970
- _context15.next = 51;
2119
+ _context17.next = 51;
1971
2120
  break;
1972
2121
  }
1973
2122
  existingOrder = updatedList[matchIndex];
@@ -1982,45 +2131,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1982
2131
  draftMap.set(_storageKey2, reconciledDraftOrder);
1983
2132
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1984
2133
  mergeActions[_storageKey2] = 'update';
1985
- return _context15.abrupt("continue", 55);
2134
+ return _context17.abrupt("continue", 55);
1986
2135
  case 51:
1987
2136
  insertIndex = updatedList.length;
1988
2137
  updatedList.push(_draftOrder);
1989
2138
  this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
1990
2139
  mergeActions[_storageKey2] = 'insert';
1991
2140
  case 55:
1992
- _context15.next = 38;
2141
+ _context17.next = 38;
1993
2142
  break;
1994
2143
  case 57:
1995
- _context15.next = 62;
2144
+ _context17.next = 62;
1996
2145
  break;
1997
2146
  case 59:
1998
- _context15.prev = 59;
1999
- _context15.t1 = _context15["catch"](36);
2000
- _iterator12.e(_context15.t1);
2147
+ _context17.prev = 59;
2148
+ _context17.t1 = _context17["catch"](36);
2149
+ _iterator12.e(_context17.t1);
2001
2150
  case 62:
2002
- _context15.prev = 62;
2151
+ _context17.prev = 62;
2003
2152
  _iterator12.f();
2004
- return _context15.finish(62);
2153
+ return _context17.finish(62);
2005
2154
  case 65:
2006
2155
  patchedOrders = _toConsumableArray(draftMap.values());
2007
2156
  previousList = this.store.list;
2008
2157
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
2009
2158
  this.syncOrdersMap();
2010
- _context15.prev = 69;
2011
- _context15.next = 72;
2159
+ _context17.prev = 69;
2160
+ _context17.next = 72;
2012
2161
  return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
2013
2162
  throwOnError: true
2014
2163
  });
2015
2164
  case 72:
2016
- _context15.next = 79;
2165
+ _context17.next = 79;
2017
2166
  break;
2018
2167
  case 74:
2019
- _context15.prev = 74;
2020
- _context15.t2 = _context15["catch"](69);
2168
+ _context17.prev = 74;
2169
+ _context17.t2 = _context17["catch"](69);
2021
2170
  this.store.list = previousList;
2022
2171
  this.syncOrdersMap();
2023
- throw _context15.t2;
2172
+ throw _context17.t2;
2024
2173
  case 79:
2025
2174
  this.logInfo('upsertLocalDraftOrders-结束', {
2026
2175
  count: patchedOrders.length,
@@ -2030,20 +2179,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2030
2179
  return !_this11.shouldKeepOrderInMemory(order);
2031
2180
  });
2032
2181
  if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
2033
- _context15.next = 84;
2182
+ _context17.next = 84;
2034
2183
  break;
2035
2184
  }
2036
- _context15.next = 84;
2185
+ _context17.next = 84;
2037
2186
  return this.emitOrdersChanged(patchedOrders.filter(function (order) {
2038
2187
  return _this11.shouldKeepOrderInMemory(order);
2039
2188
  }), 'upsertLocalDraftOrders');
2040
2189
  case 84:
2041
2190
  case "end":
2042
- return _context15.stop();
2191
+ return _context17.stop();
2043
2192
  }
2044
- }, _callee15, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
2193
+ }, _callee17, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
2045
2194
  }));
2046
- function upsertLocalDraftOrders(_x11) {
2195
+ function upsertLocalDraftOrders(_x13) {
2047
2196
  return _upsertLocalDraftOrders.apply(this, arguments);
2048
2197
  }
2049
2198
  return upsertLocalDraftOrders;
@@ -2055,42 +2204,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2055
2204
  }, {
2056
2205
  key: "fetchOrdersBySSE",
2057
2206
  value: (function () {
2058
- var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2207
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
2059
2208
  var query,
2060
2209
  data,
2061
- _args16 = arguments;
2062
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
2063
- while (1) switch (_context16.prev = _context16.next) {
2210
+ _args18 = arguments;
2211
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2212
+ while (1) switch (_context18.prev = _context18.next) {
2064
2213
  case 0:
2065
- query = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {};
2214
+ query = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : {};
2066
2215
  if (this.orderDataSource) {
2067
- _context16.next = 3;
2216
+ _context18.next = 3;
2068
2217
  break;
2069
2218
  }
2070
- return _context16.abrupt("return", []);
2219
+ return _context18.abrupt("return", []);
2071
2220
  case 3:
2072
- _context16.prev = 3;
2073
- _context16.next = 6;
2221
+ _context18.prev = 3;
2222
+ _context18.next = 6;
2074
2223
  return this.orderDataSource.run({
2075
2224
  sse: {
2076
2225
  query: query
2077
2226
  }
2078
2227
  });
2079
2228
  case 6:
2080
- data = _context16.sent;
2081
- return _context16.abrupt("return", data || []);
2229
+ data = _context18.sent;
2230
+ return _context18.abrupt("return", data || []);
2082
2231
  case 10:
2083
- _context16.prev = 10;
2084
- _context16.t0 = _context16["catch"](3);
2232
+ _context18.prev = 10;
2233
+ _context18.t0 = _context18["catch"](3);
2085
2234
  this.logError('fetchOrdersBySSE-失败', {
2086
- error: _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0)
2235
+ error: _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0)
2087
2236
  });
2088
- return _context16.abrupt("return", []);
2237
+ return _context18.abrupt("return", []);
2089
2238
  case 14:
2090
2239
  case "end":
2091
- return _context16.stop();
2240
+ return _context18.stop();
2092
2241
  }
2093
- }, _callee16, this, [[3, 10]]);
2242
+ }, _callee18, this, [[3, 10]]);
2094
2243
  }));
2095
2244
  function fetchOrdersBySSE() {
2096
2245
  return _fetchOrdersBySSE.apply(this, arguments);
@@ -2327,41 +2476,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2327
2476
  }, {
2328
2477
  key: "flushOrderSyncMessagesByThrottle",
2329
2478
  value: (function () {
2330
- var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2331
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2332
- while (1) switch (_context17.prev = _context17.next) {
2479
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
2480
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2481
+ while (1) switch (_context19.prev = _context19.next) {
2333
2482
  case 0:
2334
2483
  if (!this.isProcessingSyncBatch) {
2335
- _context17.next = 2;
2484
+ _context19.next = 2;
2336
2485
  break;
2337
2486
  }
2338
- return _context17.abrupt("return");
2487
+ return _context19.abrupt("return");
2339
2488
  case 2:
2340
2489
  if (!(this.pendingSyncMessages.length === 0)) {
2341
- _context17.next = 5;
2490
+ _context19.next = 5;
2342
2491
  break;
2343
2492
  }
2344
2493
  this.isIdlePhase = true;
2345
- return _context17.abrupt("return");
2494
+ return _context19.abrupt("return");
2346
2495
  case 5:
2347
2496
  this.isProcessingSyncBatch = true;
2348
- _context17.prev = 6;
2349
- _context17.next = 9;
2497
+ _context19.prev = 6;
2498
+ _context19.next = 9;
2350
2499
  return this.processOrderSyncMessages();
2351
2500
  case 9:
2352
- _context17.prev = 9;
2501
+ _context19.prev = 9;
2353
2502
  this.isProcessingSyncBatch = false;
2354
2503
  if (this.pendingSyncMessages.length > 0) {
2355
2504
  this.scheduleOrderSyncThrottle();
2356
2505
  } else {
2357
2506
  this.isIdlePhase = true;
2358
2507
  }
2359
- return _context17.finish(9);
2508
+ return _context19.finish(9);
2360
2509
  case 13:
2361
2510
  case "end":
2362
- return _context17.stop();
2511
+ return _context19.stop();
2363
2512
  }
2364
- }, _callee17, this, [[6,, 9, 13]]);
2513
+ }, _callee19, this, [[6,, 9, 13]]);
2365
2514
  }));
2366
2515
  function flushOrderSyncMessagesByThrottle() {
2367
2516
  return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
@@ -2383,19 +2532,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2383
2532
  }, {
2384
2533
  key: "processOrderSyncMessages",
2385
2534
  value: (function () {
2386
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
2535
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2387
2536
  var _this16 = this;
2388
2537
  var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
2389
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2390
- while (1) switch (_context18.prev = _context18.next) {
2538
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2539
+ while (1) switch (_context20.prev = _context20.next) {
2391
2540
  case 0:
2392
2541
  messages = _toConsumableArray(this.pendingSyncMessages);
2393
2542
  this.pendingSyncMessages = [];
2394
2543
  if (!(messages.length === 0)) {
2395
- _context18.next = 4;
2544
+ _context20.next = 4;
2396
2545
  break;
2397
2546
  }
2398
- return _context18.abrupt("return");
2547
+ return _context20.abrupt("return");
2399
2548
  case 4:
2400
2549
  batchProcessStartAt = Date.now();
2401
2550
  earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
@@ -2429,41 +2578,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2429
2578
  refreshIdCount: uniqueRefreshIds.length
2430
2579
  });
2431
2580
  if (!(upsertList.length > 0)) {
2432
- _context18.next = 16;
2581
+ _context20.next = 16;
2433
2582
  break;
2434
2583
  }
2435
- _context18.next = 16;
2584
+ _context20.next = 16;
2436
2585
  return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
2437
2586
  case 16:
2438
2587
  if (!(uniqueRefreshIds.length > 0)) {
2439
- _context18.next = 28;
2588
+ _context20.next = 28;
2440
2589
  break;
2441
2590
  }
2442
2591
  _this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
2443
2592
  if (skipped.length > 0) {}
2444
2593
  if (!(toFetch.length > 0)) {
2445
- _context18.next = 28;
2594
+ _context20.next = 28;
2446
2595
  break;
2447
2596
  }
2448
- _context18.next = 22;
2597
+ _context20.next = 22;
2449
2598
  return this.fetchOrdersByHttp(toFetch);
2450
2599
  case 22:
2451
- freshOrders = _context18.sent;
2600
+ freshOrders = _context20.sent;
2452
2601
  if (!(freshOrders.length > 0)) {
2453
- _context18.next = 28;
2602
+ _context20.next = 28;
2454
2603
  break;
2455
2604
  }
2456
- _context18.next = 26;
2605
+ _context20.next = 26;
2457
2606
  return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
2458
2607
  case 26:
2459
- _context18.next = 28;
2608
+ _context20.next = 28;
2460
2609
  break;
2461
2610
  case 28:
2462
2611
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
2463
- _context18.next = 30;
2612
+ _context20.next = 30;
2464
2613
  break;
2465
2614
  }
2466
- return _context18.abrupt("return");
2615
+ return _context20.abrupt("return");
2467
2616
  case 30:
2468
2617
  batchProcessEndAt = Date.now();
2469
2618
  this.logInfo('processOrderSyncMessages-结束', {
@@ -2472,13 +2621,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2472
2621
  batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
2473
2622
  totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
2474
2623
  });
2475
- _context18.next = 34;
2624
+ _context20.next = 34;
2476
2625
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
2477
2626
  case 34:
2478
2627
  case "end":
2479
- return _context18.stop();
2628
+ return _context20.stop();
2480
2629
  }
2481
- }, _callee18, this);
2630
+ }, _callee20, this);
2482
2631
  }));
2483
2632
  function processOrderSyncMessages() {
2484
2633
  return _processOrderSyncMessages.apply(this, arguments);
@@ -2499,29 +2648,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2499
2648
  }, {
2500
2649
  key: "fetchOrdersByHttp",
2501
2650
  value: (function () {
2502
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(ids) {
2651
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(ids) {
2503
2652
  var _orderList, orderList;
2504
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2505
- while (1) switch (_context19.prev = _context19.next) {
2653
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2654
+ while (1) switch (_context21.prev = _context21.next) {
2506
2655
  case 0:
2507
2656
  if (!(!this.orderDataSource || ids.length === 0)) {
2508
- _context19.next = 2;
2657
+ _context21.next = 2;
2509
2658
  break;
2510
2659
  }
2511
- return _context19.abrupt("return", []);
2660
+ return _context21.abrupt("return", []);
2512
2661
  case 2:
2513
- _context19.prev = 2;
2662
+ _context21.prev = 2;
2514
2663
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
2515
- _context19.next = 8;
2664
+ _context21.next = 8;
2516
2665
  break;
2517
2666
  }
2518
- _context19.next = 6;
2667
+ _context21.next = 6;
2519
2668
  return this.orderDataSource.fetchOrdersByIds(ids);
2520
2669
  case 6:
2521
- _orderList = _context19.sent;
2522
- return _context19.abrupt("return", _orderList || []);
2670
+ _orderList = _context21.sent;
2671
+ return _context21.abrupt("return", _orderList || []);
2523
2672
  case 8:
2524
- _context19.next = 10;
2673
+ _context21.next = 10;
2525
2674
  return this.orderDataSource.run({
2526
2675
  http: {
2527
2676
  query: {
@@ -2530,19 +2679,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2530
2679
  }
2531
2680
  });
2532
2681
  case 10:
2533
- orderList = _context19.sent;
2534
- return _context19.abrupt("return", orderList || []);
2682
+ orderList = _context21.sent;
2683
+ return _context21.abrupt("return", orderList || []);
2535
2684
  case 14:
2536
- _context19.prev = 14;
2537
- _context19.t0 = _context19["catch"](2);
2538
- return _context19.abrupt("return", []);
2685
+ _context21.prev = 14;
2686
+ _context21.t0 = _context21["catch"](2);
2687
+ return _context21.abrupt("return", []);
2539
2688
  case 17:
2540
2689
  case "end":
2541
- return _context19.stop();
2690
+ return _context21.stop();
2542
2691
  }
2543
- }, _callee19, this, [[2, 14]]);
2692
+ }, _callee21, this, [[2, 14]]);
2544
2693
  }));
2545
- function fetchOrdersByHttp(_x12) {
2694
+ function fetchOrdersByHttp(_x14) {
2546
2695
  return _fetchOrdersByHttp.apply(this, arguments);
2547
2696
  }
2548
2697
  return fetchOrdersByHttp;
@@ -2554,11 +2703,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2554
2703
  }, {
2555
2704
  key: "mergeOrdersToStore",
2556
2705
  value: (function () {
2557
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(freshOrders, source) {
2706
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(freshOrders, source) {
2558
2707
  var _this17 = this;
2559
2708
  var storeOrderCountBefore, normalizedFreshOrders, incomingProductsHaveStableIdentity, _iterator15, _step15, order, id, rawProducts, _incomingProductsHave, allProductsHaveStableIdentity, orderIdKey, uniqueFreshOrders, uniqueFreshCount, patchedOrders, remoteProductMembershipChanges, forceWriteStorageKeys, storageKeyMigrations, mergeActions, existingProductsHaveStableIdentity, updatedList, identityKeyToIndex, index, identityKeys, _iterator16, _step16, key, _iterator17, _step17, 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, _iterator18, _step18, _key2, _duplicateIndex, _iterator19, _step19, duplicateIndex, _index, _iterator20, _step20, _key, nextStorageKey, _ref5, _ref6, _mergedOrder$order_id, mergedStorageKey, insertIndex, insertCount, updateCount;
2560
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2561
- while (1) switch (_context20.prev = _context20.next) {
2709
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2710
+ while (1) switch (_context22.prev = _context22.next) {
2562
2711
  case 0:
2563
2712
  storeOrderCountBefore = this.store.list.length;
2564
2713
  this.logInfo('mergeOrdersToStore-开始', {
@@ -2570,20 +2719,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2570
2719
  normalizedFreshOrders = [];
2571
2720
  incomingProductsHaveStableIdentity = new Map();
2572
2721
  _iterator15 = _createForOfIteratorHelper(freshOrders);
2573
- _context20.prev = 6;
2722
+ _context22.prev = 6;
2574
2723
  _iterator15.s();
2575
2724
  case 8:
2576
2725
  if ((_step15 = _iterator15.n()).done) {
2577
- _context20.next = 18;
2726
+ _context22.next = 18;
2578
2727
  break;
2579
2728
  }
2580
2729
  order = _step15.value;
2581
2730
  id = order === null || order === void 0 ? void 0 : order.order_id;
2582
2731
  if (!(id === undefined || id === null)) {
2583
- _context20.next = 13;
2732
+ _context22.next = 13;
2584
2733
  break;
2585
2734
  }
2586
- return _context20.abrupt("continue", 16);
2735
+ return _context22.abrupt("continue", 16);
2587
2736
  case 13:
2588
2737
  rawProducts = order.products;
2589
2738
  if (Array.isArray(rawProducts)) {
@@ -2593,19 +2742,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2593
2742
  }
2594
2743
  normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
2595
2744
  case 16:
2596
- _context20.next = 8;
2745
+ _context22.next = 8;
2597
2746
  break;
2598
2747
  case 18:
2599
- _context20.next = 23;
2748
+ _context22.next = 23;
2600
2749
  break;
2601
2750
  case 20:
2602
- _context20.prev = 20;
2603
- _context20.t0 = _context20["catch"](6);
2604
- _iterator15.e(_context20.t0);
2751
+ _context22.prev = 20;
2752
+ _context22.t0 = _context22["catch"](6);
2753
+ _iterator15.e(_context22.t0);
2605
2754
  case 23:
2606
- _context20.prev = 23;
2755
+ _context22.prev = 23;
2607
2756
  _iterator15.f();
2608
- return _context20.finish(23);
2757
+ return _context22.finish(23);
2609
2758
  case 26:
2610
2759
  // 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
2611
2760
  uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
@@ -2640,11 +2789,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2640
2789
  }
2641
2790
  }
2642
2791
  _iterator17 = _createForOfIteratorHelper(uniqueFreshOrders);
2643
- _context20.prev = 38;
2792
+ _context22.prev = 38;
2644
2793
  _iterator17.s();
2645
2794
  case 40:
2646
2795
  if ((_step17 = _iterator17.n()).done) {
2647
- _context20.next = 100;
2796
+ _context22.next = 100;
2648
2797
  break;
2649
2798
  }
2650
2799
  fresh = _step17.value;
@@ -2653,13 +2802,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2653
2802
  storageKey = this.getOrderStorageKey(fresh);
2654
2803
  mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
2655
2804
  if (!(matchIndex >= 0)) {
2656
- _context20.next = 92;
2805
+ _context22.next = 92;
2657
2806
  break;
2658
2807
  }
2659
2808
  existingOrder = updatedList[matchIndex];
2660
2809
  previousStorageKey = this.getPersistedOrderStorageKey(existingOrder);
2661
2810
  if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
2662
- _context20.next = 52;
2811
+ _context22.next = 52;
2663
2812
  break;
2664
2813
  }
2665
2814
  this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
@@ -2672,10 +2821,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2672
2821
  remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
2673
2822
  reason: 'protect_pending_sync_order_from_remote_echo'
2674
2823
  });
2675
- return _context20.abrupt("continue", 98);
2824
+ return _context22.abrupt("continue", 98);
2676
2825
  case 52:
2677
2826
  if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
2678
- _context20.next = 55;
2827
+ _context22.next = 55;
2679
2828
  break;
2680
2829
  }
2681
2830
  this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
@@ -2686,7 +2835,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2686
2835
  remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
2687
2836
  reason: 'protect_draft_order_from_remote_echo'
2688
2837
  });
2689
- return _context20.abrupt("continue", 98);
2838
+ return _context22.abrupt("continue", 98);
2690
2839
  case 55:
2691
2840
  mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
2692
2841
  freshOrderId = fresh.order_id;
@@ -2699,36 +2848,36 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2699
2848
  adjustedMatchIndex = matchIndex;
2700
2849
  duplicateIndexes = new Set();
2701
2850
  _iterator18 = _createForOfIteratorHelper(freshIdentityKeys);
2702
- _context20.prev = 64;
2851
+ _context22.prev = 64;
2703
2852
  _iterator18.s();
2704
2853
  case 66:
2705
2854
  if ((_step18 = _iterator18.n()).done) {
2706
- _context20.next = 74;
2855
+ _context22.next = 74;
2707
2856
  break;
2708
2857
  }
2709
2858
  _key2 = _step18.value;
2710
2859
  _duplicateIndex = identityKeyToIndex.get(_key2);
2711
2860
  if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
2712
- _context20.next = 71;
2861
+ _context22.next = 71;
2713
2862
  break;
2714
2863
  }
2715
- return _context20.abrupt("continue", 72);
2864
+ return _context22.abrupt("continue", 72);
2716
2865
  case 71:
2717
2866
  duplicateIndexes.add(_duplicateIndex);
2718
2867
  case 72:
2719
- _context20.next = 66;
2868
+ _context22.next = 66;
2720
2869
  break;
2721
2870
  case 74:
2722
- _context20.next = 79;
2871
+ _context22.next = 79;
2723
2872
  break;
2724
2873
  case 76:
2725
- _context20.prev = 76;
2726
- _context20.t1 = _context20["catch"](64);
2727
- _iterator18.e(_context20.t1);
2874
+ _context22.prev = 76;
2875
+ _context22.t1 = _context22["catch"](64);
2876
+ _iterator18.e(_context22.t1);
2728
2877
  case 79:
2729
- _context20.prev = 79;
2878
+ _context22.prev = 79;
2730
2879
  _iterator18.f();
2731
- return _context20.finish(79);
2880
+ return _context22.finish(79);
2732
2881
  case 82:
2733
2882
  if (duplicateIndexes.size > 0) {
2734
2883
  _iterator19 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
@@ -2783,7 +2932,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2783
2932
  this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
2784
2933
  patchedOrders.push(mergedOrder);
2785
2934
  if (mergeKey) mergeActions[mergeKey] = 'update';
2786
- return _context20.abrupt("continue", 98);
2935
+ return _context22.abrupt("continue", 98);
2787
2936
  case 92:
2788
2937
  insertIndex = updatedList.length;
2789
2938
  updatedList.push(fresh);
@@ -2792,19 +2941,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2792
2941
  patchedOrders.push(fresh);
2793
2942
  if (mergeKey) mergeActions[mergeKey] = 'insert';
2794
2943
  case 98:
2795
- _context20.next = 40;
2944
+ _context22.next = 40;
2796
2945
  break;
2797
2946
  case 100:
2798
- _context20.next = 105;
2947
+ _context22.next = 105;
2799
2948
  break;
2800
2949
  case 102:
2801
- _context20.prev = 102;
2802
- _context20.t2 = _context20["catch"](38);
2803
- _iterator17.e(_context20.t2);
2950
+ _context22.prev = 102;
2951
+ _context22.t2 = _context22["catch"](38);
2952
+ _iterator17.e(_context22.t2);
2804
2953
  case 105:
2805
- _context20.prev = 105;
2954
+ _context22.prev = 105;
2806
2955
  _iterator17.f();
2807
- return _context20.finish(105);
2956
+ return _context22.finish(105);
2808
2957
  case 108:
2809
2958
  insertCount = Object.values(mergeActions).filter(function (v) {
2810
2959
  return v === 'insert';
@@ -2821,7 +2970,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2821
2970
  // 仅在自检开关开启时做一次兜底校验。
2822
2971
  this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
2823
2972
  this.syncOrdersMap();
2824
- _context20.next = 115;
2973
+ _context22.next = 115;
2825
2974
  return this.patchOrdersInSQLite(patchedOrders, source, mergeActions, {
2826
2975
  storageKeyMigrations: storageKeyMigrations
2827
2976
  }, forceWriteStorageKeys);
@@ -2832,18 +2981,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2832
2981
  insertCount: insertCount,
2833
2982
  updateCount: updateCount
2834
2983
  });
2835
- _context20.next = 118;
2984
+ _context22.next = 118;
2836
2985
  return this.emitRemoteProductMembershipChanges(remoteProductMembershipChanges);
2837
2986
  case 118:
2838
- _context20.next = 120;
2987
+ _context22.next = 120;
2839
2988
  return this.emitOrdersChanged(patchedOrders, source);
2840
2989
  case 120:
2841
2990
  case "end":
2842
- return _context20.stop();
2991
+ return _context22.stop();
2843
2992
  }
2844
- }, _callee20, this, [[6, 20, 23, 26], [38, 102, 105, 108], [64, 76, 79, 82]]);
2993
+ }, _callee22, this, [[6, 20, 23, 26], [38, 102, 105, 108], [64, 76, 79, 82]]);
2845
2994
  }));
2846
- function mergeOrdersToStore(_x13, _x14) {
2995
+ function mergeOrdersToStore(_x15, _x16) {
2847
2996
  return _mergeOrdersToStore.apply(this, arguments);
2848
2997
  }
2849
2998
  return mergeOrdersToStore;
@@ -3254,7 +3403,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3254
3403
  }, {
3255
3404
  key: "shouldProtectLocalOrderFromRemoteSnapshot",
3256
3405
  value: function shouldProtectLocalOrderFromRemoteSnapshot(order) {
3257
- return this.isPendingSyncOrder(order) || this.isDraftOrder(order) || this.getIdentifiedPendingPayments(order).length > 0;
3406
+ return this.isPendingSyncOrder(order) || this.isDraftOrder(order) || this.getIdentifiedPendingPayments(order).length > 0 || requiresLocalPaymentRefresh(order) || (order.payments || []).some(isLocalFinalizedPayment);
3258
3407
  }
3259
3408
  }, {
3260
3409
  key: "getUnmatchedIdentifiedPendingPayments",
@@ -3283,6 +3432,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3283
3432
  var secondaryRecord = secondary;
3284
3433
  var existingRecord = existing;
3285
3434
  var incomingRecord = incoming;
3435
+ if (requiresLocalPaymentRefresh(existing)) {
3436
+ mergedRecord.metadata = _objectSpread(_objectSpread({}, mergedRecord.metadata), {}, _defineProperty({}, LOCAL_EFTPOS_REFRESH_REQUIRED, true));
3437
+ }
3286
3438
  var childUidRemaps = [];
3287
3439
  for (var _i4 = 0, _fieldsToPreserve = fieldsToPreserve; _i4 < _fieldsToPreserve.length; _i4++) {
3288
3440
  var field = _fieldsToPreserve[_i4];
@@ -3562,7 +3714,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3562
3714
  }, {
3563
3715
  key: "loadOrdersFromSQLite",
3564
3716
  value: function () {
3565
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
3717
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
3566
3718
  var _this21 = this;
3567
3719
  var options,
3568
3720
  _options$onTiming,
@@ -3573,24 +3725,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3573
3725
  normalizeStartedAt,
3574
3726
  normalizedOrders,
3575
3727
  sqliteNormalizeMs,
3576
- _args21 = arguments;
3577
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
3578
- while (1) switch (_context21.prev = _context21.next) {
3728
+ _args23 = arguments;
3729
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3730
+ while (1) switch (_context23.prev = _context23.next) {
3579
3731
  case 0:
3580
- options = _args21.length > 0 && _args21[0] !== undefined ? _args21[0] : {};
3732
+ options = _args23.length > 0 && _args23[0] !== undefined ? _args23[0] : {};
3581
3733
  if (this.dbManager) {
3582
- _context21.next = 3;
3734
+ _context23.next = 3;
3583
3735
  break;
3584
3736
  }
3585
- return _context21.abrupt("return", []);
3737
+ return _context23.abrupt("return", []);
3586
3738
  case 3:
3587
- _context21.prev = 3;
3739
+ _context23.prev = 3;
3588
3740
  loadStartedAt = performance.now();
3589
3741
  rawReadStartedAt = performance.now();
3590
- _context21.next = 8;
3742
+ _context23.next = 8;
3591
3743
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
3592
3744
  case 8:
3593
- orders = _context21.sent;
3745
+ orders = _context23.sent;
3594
3746
  sqliteRawReadMs = +(performance.now() - rawReadStartedAt).toFixed(2);
3595
3747
  normalizeStartedAt = performance.now();
3596
3748
  normalizedOrders = (orders || []).map(function (order) {
@@ -3602,22 +3754,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3602
3754
  sqliteNormalizeMs: sqliteNormalizeMs,
3603
3755
  sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
3604
3756
  });
3605
- return _context21.abrupt("return", normalizedOrders);
3757
+ return _context23.abrupt("return", normalizedOrders);
3606
3758
  case 17:
3607
- _context21.prev = 17;
3608
- _context21.t0 = _context21["catch"](3);
3759
+ _context23.prev = 17;
3760
+ _context23.t0 = _context23["catch"](3);
3609
3761
  if (!options.throwOnError) {
3610
- _context21.next = 21;
3762
+ _context23.next = 21;
3611
3763
  break;
3612
3764
  }
3613
- throw _context21.t0;
3765
+ throw _context23.t0;
3614
3766
  case 21:
3615
- return _context21.abrupt("return", []);
3767
+ return _context23.abrupt("return", []);
3616
3768
  case 22:
3617
3769
  case "end":
3618
- return _context21.stop();
3770
+ return _context23.stop();
3619
3771
  }
3620
- }, _callee21, this, [[3, 17]]);
3772
+ }, _callee23, this, [[3, 17]]);
3621
3773
  }));
3622
3774
  function loadOrdersFromSQLite() {
3623
3775
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -3709,10 +3861,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3709
3861
  }, {
3710
3862
  key: "runInOrderSQLiteSaveQueue",
3711
3863
  value: (function () {
3712
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(task) {
3864
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(task) {
3713
3865
  var queuedTask;
3714
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
3715
- while (1) switch (_context22.prev = _context22.next) {
3866
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3867
+ while (1) switch (_context24.prev = _context24.next) {
3716
3868
  case 0:
3717
3869
  queuedTask = this.orderSQLiteSaveQueue.then(task, task);
3718
3870
  this.orderSQLiteSaveQueue = queuedTask.then(function () {
@@ -3720,14 +3872,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3720
3872
  }, function () {
3721
3873
  return undefined;
3722
3874
  });
3723
- return _context22.abrupt("return", queuedTask);
3875
+ return _context24.abrupt("return", queuedTask);
3724
3876
  case 3:
3725
3877
  case "end":
3726
- return _context22.stop();
3878
+ return _context24.stop();
3727
3879
  }
3728
- }, _callee22, this);
3880
+ }, _callee24, this);
3729
3881
  }));
3730
- function runInOrderSQLiteSaveQueue(_x15) {
3882
+ function runInOrderSQLiteSaveQueue(_x17) {
3731
3883
  return _runInOrderSQLiteSaveQueue.apply(this, arguments);
3732
3884
  }
3733
3885
  return runInOrderSQLiteSaveQueue;
@@ -3742,7 +3894,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3742
3894
  }, {
3743
3895
  key: "patchOrdersInSQLite",
3744
3896
  value: (function () {
3745
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orders, source) {
3897
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(orders, source) {
3746
3898
  var _this23 = this;
3747
3899
  var mergeActions,
3748
3900
  options,
@@ -3758,30 +3910,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3758
3910
  _iterator33,
3759
3911
  _step33,
3760
3912
  migration,
3761
- _args24 = arguments;
3762
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
3763
- while (1) switch (_context24.prev = _context24.next) {
3913
+ _args26 = arguments;
3914
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3915
+ while (1) switch (_context26.prev = _context26.next) {
3764
3916
  case 0:
3765
- mergeActions = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : {};
3766
- options = _args24.length > 3 && _args24[3] !== undefined ? _args24[3] : {};
3767
- forceWriteStorageKeys = _args24.length > 4 && _args24[4] !== undefined ? _args24[4] : new Set();
3917
+ mergeActions = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : {};
3918
+ options = _args26.length > 3 && _args26[3] !== undefined ? _args26[3] : {};
3919
+ forceWriteStorageKeys = _args26.length > 4 && _args26[4] !== undefined ? _args26[4] : new Set();
3768
3920
  if (!(orders.length === 0)) {
3769
- _context24.next = 5;
3921
+ _context26.next = 5;
3770
3922
  break;
3771
3923
  }
3772
- return _context24.abrupt("return");
3924
+ return _context26.abrupt("return");
3773
3925
  case 5:
3774
3926
  if (this.dbManager) {
3775
- _context24.next = 9;
3927
+ _context26.next = 9;
3776
3928
  break;
3777
3929
  }
3778
3930
  if (!options.throwOnError) {
3779
- _context24.next = 8;
3931
+ _context26.next = 8;
3780
3932
  break;
3781
3933
  }
3782
3934
  throw new Error('订单 SQLite 数据库未初始化');
3783
3935
  case 8:
3784
- return _context24.abrupt("return");
3936
+ return _context26.abrupt("return");
3785
3937
  case 9:
3786
3938
  migrationTargetStorageKeys = new Set((options.storageKeyMigrations || []).map(function (migration) {
3787
3939
  return migration.to;
@@ -3796,72 +3948,72 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3796
3948
  return _this23.getOrderStorageKey(order);
3797
3949
  });
3798
3950
  if (!(ordersSnapshot.length === 0)) {
3799
- _context24.next = 13;
3951
+ _context26.next = 13;
3800
3952
  break;
3801
3953
  }
3802
- return _context24.abrupt("return");
3954
+ return _context26.abrupt("return");
3803
3955
  case 13:
3804
3956
  _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions, forceWriteStorageKeys), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
3805
3957
  if (!(toWrite.length === 0)) {
3806
- _context24.next = 16;
3958
+ _context26.next = 16;
3807
3959
  break;
3808
3960
  }
3809
- return _context24.abrupt("return");
3961
+ return _context26.abrupt("return");
3810
3962
  case 16:
3811
3963
  compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
3812
3964
  if (!(compactedToWrite.length === 0)) {
3813
- _context24.next = 19;
3965
+ _context26.next = 19;
3814
3966
  break;
3815
3967
  }
3816
- return _context24.abrupt("return");
3968
+ return _context26.abrupt("return");
3817
3969
  case 19:
3818
3970
  writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
3819
3971
  return _this23.getOrderStorageKey(order);
3820
3972
  }).filter(Boolean));
3821
3973
  storageKeyMigrations = new Map();
3822
3974
  _iterator33 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
3823
- _context24.prev = 22;
3975
+ _context26.prev = 22;
3824
3976
  _iterator33.s();
3825
3977
  case 24:
3826
3978
  if ((_step33 = _iterator33.n()).done) {
3827
- _context24.next = 33;
3979
+ _context26.next = 33;
3828
3980
  break;
3829
3981
  }
3830
3982
  migration = _step33.value;
3831
3983
  if (writtenStorageKeys.has(migration.to)) {
3832
- _context24.next = 28;
3984
+ _context26.next = 28;
3833
3985
  break;
3834
3986
  }
3835
- return _context24.abrupt("continue", 31);
3987
+ return _context26.abrupt("continue", 31);
3836
3988
  case 28:
3837
3989
  if (!writtenStorageKeys.has(migration.from)) {
3838
- _context24.next = 30;
3990
+ _context26.next = 30;
3839
3991
  break;
3840
3992
  }
3841
- return _context24.abrupt("continue", 31);
3993
+ return _context26.abrupt("continue", 31);
3842
3994
  case 30:
3843
3995
  storageKeyMigrations.set(migration.from, migration);
3844
3996
  case 31:
3845
- _context24.next = 24;
3997
+ _context26.next = 24;
3846
3998
  break;
3847
3999
  case 33:
3848
- _context24.next = 38;
4000
+ _context26.next = 38;
3849
4001
  break;
3850
4002
  case 35:
3851
- _context24.prev = 35;
3852
- _context24.t0 = _context24["catch"](22);
3853
- _iterator33.e(_context24.t0);
4003
+ _context26.prev = 35;
4004
+ _context26.t0 = _context26["catch"](22);
4005
+ _iterator33.e(_context26.t0);
3854
4006
  case 38:
3855
- _context24.prev = 38;
4007
+ _context26.prev = 38;
3856
4008
  _iterator33.f();
3857
- return _context24.finish(38);
4009
+ return _context26.finish(38);
3858
4010
  case 41:
3859
- _context24.prev = 41;
3860
- _context24.next = 44;
3861
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
4011
+ _context26.prev = 41;
4012
+ _context26.next = 44;
4013
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
3862
4014
  var writeMethod, _iterator34, _step34, order, _iterator35, _step35, migration, _iterator36, _step36, _orderRecord$ORDER_ST, _order, orderRecord;
3863
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
3864
- while (1) switch (_context23.prev = _context23.next) {
4015
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4016
+ while (1) switch (_context25.prev = _context25.next) {
3865
4017
  case 0:
3866
4018
  writeMethod = 'none';
3867
4019
  _this23.logInfo('patchOrdersInSQLite-开始', {
@@ -3870,150 +4022,150 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3870
4022
  dedupedCount: skipped.length
3871
4023
  });
3872
4024
  if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
3873
- _context23.next = 8;
4025
+ _context25.next = 8;
3874
4026
  break;
3875
4027
  }
3876
4028
  writeMethod = 'bulkUpdate';
3877
- _context23.next = 6;
4029
+ _context25.next = 6;
3878
4030
  return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
3879
4031
  case 6:
3880
- _context23.next = 37;
4032
+ _context25.next = 37;
3881
4033
  break;
3882
4034
  case 8:
3883
4035
  if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
3884
- _context23.next = 14;
4036
+ _context25.next = 14;
3885
4037
  break;
3886
4038
  }
3887
4039
  writeMethod = 'bulkAdd';
3888
- _context23.next = 12;
4040
+ _context25.next = 12;
3889
4041
  return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
3890
4042
  case 12:
3891
- _context23.next = 37;
4043
+ _context25.next = 37;
3892
4044
  break;
3893
4045
  case 14:
3894
4046
  if (!(typeof _this23.dbManager.update === 'function')) {
3895
- _context23.next = 35;
4047
+ _context25.next = 35;
3896
4048
  break;
3897
4049
  }
3898
4050
  writeMethod = 'update';
3899
4051
  _iterator34 = _createForOfIteratorHelper(compactedToWrite);
3900
- _context23.prev = 17;
4052
+ _context25.prev = 17;
3901
4053
  _iterator34.s();
3902
4054
  case 19:
3903
4055
  if ((_step34 = _iterator34.n()).done) {
3904
- _context23.next = 25;
4056
+ _context25.next = 25;
3905
4057
  break;
3906
4058
  }
3907
4059
  order = _step34.value;
3908
- _context23.next = 23;
4060
+ _context25.next = 23;
3909
4061
  return _this23.dbManager.update(INDEXDB_STORE_NAME, order);
3910
4062
  case 23:
3911
- _context23.next = 19;
4063
+ _context25.next = 19;
3912
4064
  break;
3913
4065
  case 25:
3914
- _context23.next = 30;
4066
+ _context25.next = 30;
3915
4067
  break;
3916
4068
  case 27:
3917
- _context23.prev = 27;
3918
- _context23.t0 = _context23["catch"](17);
3919
- _iterator34.e(_context23.t0);
4069
+ _context25.prev = 27;
4070
+ _context25.t0 = _context25["catch"](17);
4071
+ _iterator34.e(_context25.t0);
3920
4072
  case 30:
3921
- _context23.prev = 30;
4073
+ _context25.prev = 30;
3922
4074
  _iterator34.f();
3923
- return _context23.finish(30);
4075
+ return _context25.finish(30);
3924
4076
  case 33:
3925
- _context23.next = 37;
4077
+ _context25.next = 37;
3926
4078
  break;
3927
4079
  case 35:
3928
4080
  if (!options.throwOnError) {
3929
- _context23.next = 37;
4081
+ _context25.next = 37;
3930
4082
  break;
3931
4083
  }
3932
4084
  throw new Error('订单 SQLite 数据库不支持写入');
3933
4085
  case 37:
3934
4086
  _this23.recordRecentSqliteWrite(source, compactedToWrite);
3935
4087
  if (!(writeMethod !== 'none')) {
3936
- _context23.next = 84;
4088
+ _context25.next = 84;
3937
4089
  break;
3938
4090
  }
3939
4091
  _iterator35 = _createForOfIteratorHelper(storageKeyMigrations.values());
3940
- _context23.prev = 40;
4092
+ _context25.prev = 40;
3941
4093
  _iterator35.s();
3942
4094
  case 42:
3943
4095
  if ((_step35 = _iterator35.n()).done) {
3944
- _context23.next = 76;
4096
+ _context25.next = 76;
3945
4097
  break;
3946
4098
  }
3947
4099
  migration = _step35.value;
3948
- _context23.prev = 44;
3949
- _context23.next = 47;
4100
+ _context25.prev = 44;
4101
+ _context25.next = 47;
3950
4102
  return _this23.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
3951
4103
  case 47:
3952
4104
  _this23.recentSqliteWriteByStorageKey.delete(migration.from);
3953
4105
  _iterator36 = _createForOfIteratorHelper(orders);
3954
- _context23.prev = 49;
4106
+ _context25.prev = 49;
3955
4107
  _iterator36.s();
3956
4108
  case 51:
3957
4109
  if ((_step36 = _iterator36.n()).done) {
3958
- _context23.next = 61;
4110
+ _context25.next = 61;
3959
4111
  break;
3960
4112
  }
3961
4113
  _order = _step36.value;
3962
4114
  if (!(_this23.getOrderStorageKey(_order) !== migration.to)) {
3963
- _context23.next = 55;
4115
+ _context25.next = 55;
3964
4116
  break;
3965
4117
  }
3966
- return _context23.abrupt("continue", 59);
4118
+ return _context25.abrupt("continue", 59);
3967
4119
  case 55:
3968
4120
  orderRecord = _order;
3969
4121
  if (!(String((_orderRecord$ORDER_ST = orderRecord[ORDER_STORAGE_KEY_FIELD]) !== null && _orderRecord$ORDER_ST !== void 0 ? _orderRecord$ORDER_ST : '') !== migration.from)) {
3970
- _context23.next = 58;
4122
+ _context25.next = 58;
3971
4123
  break;
3972
4124
  }
3973
- return _context23.abrupt("continue", 59);
4125
+ return _context25.abrupt("continue", 59);
3974
4126
  case 58:
3975
4127
  orderRecord[ORDER_STORAGE_KEY_FIELD] = migration.to;
3976
4128
  case 59:
3977
- _context23.next = 51;
4129
+ _context25.next = 51;
3978
4130
  break;
3979
4131
  case 61:
3980
- _context23.next = 66;
4132
+ _context25.next = 66;
3981
4133
  break;
3982
4134
  case 63:
3983
- _context23.prev = 63;
3984
- _context23.t1 = _context23["catch"](49);
3985
- _iterator36.e(_context23.t1);
4135
+ _context25.prev = 63;
4136
+ _context25.t1 = _context25["catch"](49);
4137
+ _iterator36.e(_context25.t1);
3986
4138
  case 66:
3987
- _context23.prev = 66;
4139
+ _context25.prev = 66;
3988
4140
  _iterator36.f();
3989
- return _context23.finish(66);
4141
+ return _context25.finish(66);
3990
4142
  case 69:
3991
- _context23.next = 74;
4143
+ _context25.next = 74;
3992
4144
  break;
3993
4145
  case 71:
3994
- _context23.prev = 71;
3995
- _context23.t2 = _context23["catch"](44);
4146
+ _context25.prev = 71;
4147
+ _context25.t2 = _context25["catch"](44);
3996
4148
  _this23.logError('删除订单旧 SQLite storage key 失败', {
3997
4149
  source: source,
3998
4150
  order_id: migration.orderId,
3999
4151
  oldStorageKey: migration.from,
4000
4152
  newStorageKey: migration.to,
4001
- error: _context23.t2 instanceof Error ? _context23.t2.message : String(_context23.t2)
4153
+ error: _context25.t2 instanceof Error ? _context25.t2.message : String(_context25.t2)
4002
4154
  });
4003
4155
  case 74:
4004
- _context23.next = 42;
4156
+ _context25.next = 42;
4005
4157
  break;
4006
4158
  case 76:
4007
- _context23.next = 81;
4159
+ _context25.next = 81;
4008
4160
  break;
4009
4161
  case 78:
4010
- _context23.prev = 78;
4011
- _context23.t3 = _context23["catch"](40);
4012
- _iterator35.e(_context23.t3);
4162
+ _context25.prev = 78;
4163
+ _context25.t3 = _context25["catch"](40);
4164
+ _iterator35.e(_context25.t3);
4013
4165
  case 81:
4014
- _context23.prev = 81;
4166
+ _context25.prev = 81;
4015
4167
  _iterator35.f();
4016
- return _context23.finish(81);
4168
+ return _context25.finish(81);
4017
4169
  case 84:
4018
4170
  _this23.logInfo('patchOrdersInSQLite-完成', {
4019
4171
  source: source,
@@ -4023,32 +4175,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4023
4175
  });
4024
4176
  case 85:
4025
4177
  case "end":
4026
- return _context23.stop();
4178
+ return _context25.stop();
4027
4179
  }
4028
- }, _callee23, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
4180
+ }, _callee25, null, [[17, 27, 30, 33], [40, 78, 81, 84], [44, 71], [49, 63, 66, 69]]);
4029
4181
  })));
4030
4182
  case 44:
4031
- _context24.next = 51;
4183
+ _context26.next = 51;
4032
4184
  break;
4033
4185
  case 46:
4034
- _context24.prev = 46;
4035
- _context24.t1 = _context24["catch"](41);
4186
+ _context26.prev = 46;
4187
+ _context26.t1 = _context26["catch"](41);
4036
4188
  this.logError('增量保存订单到 SQLite 失败', {
4037
- error: _context24.t1 instanceof Error ? _context24.t1.message : String(_context24.t1),
4189
+ error: _context26.t1 instanceof Error ? _context26.t1.message : String(_context26.t1),
4038
4190
  orderCount: ordersSnapshot.length
4039
4191
  });
4040
4192
  if (!options.throwOnError) {
4041
- _context24.next = 51;
4193
+ _context26.next = 51;
4042
4194
  break;
4043
4195
  }
4044
- throw _context24.t1;
4196
+ throw _context26.t1;
4045
4197
  case 51:
4046
4198
  case "end":
4047
- return _context24.stop();
4199
+ return _context26.stop();
4048
4200
  }
4049
- }, _callee24, this, [[22, 35, 38, 41], [41, 46]]);
4201
+ }, _callee26, this, [[22, 35, 38, 41], [41, 46]]);
4050
4202
  }));
4051
- function patchOrdersInSQLite(_x16, _x17) {
4203
+ function patchOrdersInSQLite(_x18, _x19) {
4052
4204
  return _patchOrdersInSQLite.apply(this, arguments);
4053
4205
  }
4054
4206
  return patchOrdersInSQLite;
@@ -4063,48 +4215,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4063
4215
  }, {
4064
4216
  key: "updateOrderInSQLite",
4065
4217
  value: (function () {
4066
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(order, source) {
4218
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(order, source) {
4067
4219
  var _this24 = this;
4068
4220
  var options,
4069
4221
  orderSnapshot,
4070
4222
  _orderSnapshot$order_3,
4071
- _args26 = arguments;
4072
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
4073
- while (1) switch (_context26.prev = _context26.next) {
4223
+ _args28 = arguments;
4224
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4225
+ while (1) switch (_context28.prev = _context28.next) {
4074
4226
  case 0:
4075
- options = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : {};
4227
+ options = _args28.length > 2 && _args28[2] !== undefined ? _args28[2] : {};
4076
4228
  if (this.getOrderStorageKey(order)) {
4077
- _context26.next = 5;
4229
+ _context28.next = 5;
4078
4230
  break;
4079
4231
  }
4080
4232
  if (!options.throwOnError) {
4081
- _context26.next = 4;
4233
+ _context28.next = 4;
4082
4234
  break;
4083
4235
  }
4084
4236
  throw new Error('订单缺少可用的 SQLite 存储主键');
4085
4237
  case 4:
4086
- return _context26.abrupt("return");
4238
+ return _context28.abrupt("return");
4087
4239
  case 5:
4088
4240
  if (this.dbManager) {
4089
- _context26.next = 9;
4241
+ _context28.next = 9;
4090
4242
  break;
4091
4243
  }
4092
4244
  if (!options.throwOnError) {
4093
- _context26.next = 8;
4245
+ _context28.next = 8;
4094
4246
  break;
4095
4247
  }
4096
4248
  throw new Error('订单 SQLite 数据库未初始化');
4097
4249
  case 8:
4098
- return _context26.abrupt("return");
4250
+ return _context28.abrupt("return");
4099
4251
  case 9:
4100
4252
  orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
4101
- _context26.prev = 10;
4102
- _context26.next = 13;
4103
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
4253
+ _context28.prev = 10;
4254
+ _context28.next = 13;
4255
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
4104
4256
  var _orderSnapshot$order_, _orderSnapshot$order_2;
4105
4257
  var writeMethod;
4106
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
4107
- while (1) switch (_context25.prev = _context25.next) {
4258
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4259
+ while (1) switch (_context27.prev = _context27.next) {
4108
4260
  case 0:
4109
4261
  writeMethod = 'none';
4110
4262
  _this24.logInfo('updateOrderInSQLite-开始', {
@@ -4113,40 +4265,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4113
4265
  storageKey: _this24.getOrderStorageKey(orderSnapshot)
4114
4266
  });
4115
4267
  if (!(typeof _this24.dbManager.update === 'function')) {
4116
- _context25.next = 8;
4268
+ _context27.next = 8;
4117
4269
  break;
4118
4270
  }
4119
4271
  writeMethod = 'update';
4120
- _context25.next = 6;
4272
+ _context27.next = 6;
4121
4273
  return _this24.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
4122
4274
  case 6:
4123
- _context25.next = 22;
4275
+ _context27.next = 22;
4124
4276
  break;
4125
4277
  case 8:
4126
4278
  if (!(typeof _this24.dbManager.bulkUpdate === 'function')) {
4127
- _context25.next = 14;
4279
+ _context27.next = 14;
4128
4280
  break;
4129
4281
  }
4130
4282
  writeMethod = 'bulkUpdate';
4131
- _context25.next = 12;
4283
+ _context27.next = 12;
4132
4284
  return _this24.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
4133
4285
  case 12:
4134
- _context25.next = 22;
4286
+ _context27.next = 22;
4135
4287
  break;
4136
4288
  case 14:
4137
4289
  if (!(typeof _this24.dbManager.bulkAdd === 'function')) {
4138
- _context25.next = 20;
4290
+ _context27.next = 20;
4139
4291
  break;
4140
4292
  }
4141
4293
  writeMethod = 'bulkAdd';
4142
- _context25.next = 18;
4294
+ _context27.next = 18;
4143
4295
  return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
4144
4296
  case 18:
4145
- _context25.next = 22;
4297
+ _context27.next = 22;
4146
4298
  break;
4147
4299
  case 20:
4148
4300
  if (!options.throwOnError) {
4149
- _context25.next = 22;
4301
+ _context27.next = 22;
4150
4302
  break;
4151
4303
  }
4152
4304
  throw new Error('订单 SQLite 数据库不支持写入');
@@ -4159,32 +4311,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4159
4311
  });
4160
4312
  case 24:
4161
4313
  case "end":
4162
- return _context25.stop();
4314
+ return _context27.stop();
4163
4315
  }
4164
- }, _callee25);
4316
+ }, _callee27);
4165
4317
  })));
4166
4318
  case 13:
4167
- _context26.next = 20;
4319
+ _context28.next = 20;
4168
4320
  break;
4169
4321
  case 15:
4170
- _context26.prev = 15;
4171
- _context26.t0 = _context26["catch"](10);
4322
+ _context28.prev = 15;
4323
+ _context28.t0 = _context28["catch"](10);
4172
4324
  this.logError('单条保存订单到 SQLite 失败', {
4173
- error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0),
4325
+ error: _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0),
4174
4326
  orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
4175
4327
  });
4176
4328
  if (!options.throwOnError) {
4177
- _context26.next = 20;
4329
+ _context28.next = 20;
4178
4330
  break;
4179
4331
  }
4180
- throw _context26.t0;
4332
+ throw _context28.t0;
4181
4333
  case 20:
4182
4334
  case "end":
4183
- return _context26.stop();
4335
+ return _context28.stop();
4184
4336
  }
4185
- }, _callee26, this, [[10, 15]]);
4337
+ }, _callee28, this, [[10, 15]]);
4186
4338
  }));
4187
- function updateOrderInSQLite(_x18, _x19) {
4339
+ function updateOrderInSQLite(_x20, _x21) {
4188
4340
  return _updateOrderInSQLite.apply(this, arguments);
4189
4341
  }
4190
4342
  return updateOrderInSQLite;
@@ -4200,22 +4352,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4200
4352
  }, {
4201
4353
  key: "replaceOrdersSnapshotInSQLite",
4202
4354
  value: (function () {
4203
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(orderList, source) {
4355
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(orderList, source) {
4204
4356
  var _this25 = this;
4205
4357
  var protectedOrdersBeforeRemoteFetch,
4206
4358
  remoteSnapshot,
4207
4359
  mergedSnapshot,
4208
4360
  persisted,
4209
- _args28 = arguments;
4210
- return _regeneratorRuntime().wrap(function _callee28$(_context28) {
4211
- while (1) switch (_context28.prev = _context28.next) {
4361
+ _args30 = arguments;
4362
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4363
+ while (1) switch (_context30.prev = _context30.next) {
4212
4364
  case 0:
4213
- protectedOrdersBeforeRemoteFetch = _args28.length > 2 && _args28[2] !== undefined ? _args28[2] : [];
4365
+ protectedOrdersBeforeRemoteFetch = _args30.length > 2 && _args30[2] !== undefined ? _args30[2] : [];
4214
4366
  if (this.dbManager) {
4215
- _context28.next = 3;
4367
+ _context30.next = 3;
4216
4368
  break;
4217
4369
  }
4218
- return _context28.abrupt("return", {
4370
+ return _context30.abrupt("return", {
4219
4371
  orders: this.compactOrderListByIdentity(orderList.map(function (order) {
4220
4372
  return _this25.normalizeRemoteSyncedOrder(order);
4221
4373
  }), "".concat(source, ".snapshotNoDb")).list,
@@ -4229,38 +4381,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4229
4381
  return _this25.normalizeRemoteSyncedOrder(order);
4230
4382
  }), "".concat(source, ".remoteSnapshot")).list;
4231
4383
  persisted = false;
4232
- _context28.prev = 6;
4233
- _context28.next = 9;
4234
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
4384
+ _context30.prev = 6;
4385
+ _context30.next = 9;
4386
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4235
4387
  var existingOrders, protectedLocalOrders, _iterator37, _step37, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
4236
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
4237
- while (1) switch (_context27.prev = _context27.next) {
4388
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4389
+ while (1) switch (_context29.prev = _context29.next) {
4238
4390
  case 0:
4239
4391
  if (!(typeof _this25.dbManager.getAll === 'function')) {
4240
- _context27.next = 6;
4392
+ _context29.next = 6;
4241
4393
  break;
4242
4394
  }
4243
- _context27.next = 3;
4395
+ _context29.next = 3;
4244
4396
  return _this25.dbManager.getAll(INDEXDB_STORE_NAME);
4245
4397
  case 3:
4246
- _context27.t0 = _context27.sent;
4247
- _context27.next = 7;
4398
+ _context29.t0 = _context29.sent;
4399
+ _context29.next = 7;
4248
4400
  break;
4249
4401
  case 6:
4250
- _context27.t0 = [];
4402
+ _context29.t0 = [];
4251
4403
  case 7:
4252
- existingOrders = _context27.t0;
4404
+ existingOrders = _context29.t0;
4253
4405
  protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
4254
4406
  return _this25.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
4255
4407
  }).filter(function (order) {
4256
4408
  return _this25.shouldProtectLocalOrderFromRemoteSnapshot(order);
4257
4409
  });
4258
4410
  _iterator37 = _createForOfIteratorHelper(existingOrders || []);
4259
- _context27.prev = 10;
4411
+ _context29.prev = 10;
4260
4412
  _iterator37.s();
4261
4413
  case 12:
4262
4414
  if ((_step37 = _iterator37.n()).done) {
4263
- _context27.next = 23;
4415
+ _context29.next = 23;
4264
4416
  break;
4265
4417
  }
4266
4418
  rawCurrentOrder = _step37.value;
@@ -4268,7 +4420,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4268
4420
  protectedIndex = _this25.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
4269
4421
  currentNeedsProtection = _this25.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
4270
4422
  if (!(protectedIndex >= 0)) {
4271
- _context27.next = 20;
4423
+ _context29.next = 20;
4272
4424
  break;
4273
4425
  }
4274
4426
  if (currentNeedsProtection) {
@@ -4276,23 +4428,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4276
4428
  } else {
4277
4429
  protectedLocalOrders.splice(protectedIndex, 1);
4278
4430
  }
4279
- return _context27.abrupt("continue", 21);
4431
+ return _context29.abrupt("continue", 21);
4280
4432
  case 20:
4281
4433
  if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
4282
4434
  case 21:
4283
- _context27.next = 12;
4435
+ _context29.next = 12;
4284
4436
  break;
4285
4437
  case 23:
4286
- _context27.next = 28;
4438
+ _context29.next = 28;
4287
4439
  break;
4288
4440
  case 25:
4289
- _context27.prev = 25;
4290
- _context27.t1 = _context27["catch"](10);
4291
- _iterator37.e(_context27.t1);
4441
+ _context29.prev = 25;
4442
+ _context29.t1 = _context29["catch"](10);
4443
+ _iterator37.e(_context29.t1);
4292
4444
  case 28:
4293
- _context27.prev = 28;
4445
+ _context29.prev = 28;
4294
4446
  _iterator37.f();
4295
- return _context27.finish(28);
4447
+ return _context29.finish(28);
4296
4448
  case 31:
4297
4449
  orderListSnapshot = _this25.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
4298
4450
  mergedSnapshot = _this25.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
@@ -4317,19 +4469,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4317
4469
  });
4318
4470
  })
4319
4471
  });
4320
- _context27.next = 36;
4472
+ _context29.next = 36;
4321
4473
  return _this25.dbManager.clear(INDEXDB_STORE_NAME);
4322
4474
  case 36:
4323
4475
  _this25.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
4324
4476
  count: mergedSnapshot.length
4325
4477
  });
4326
4478
  if (!(mergedSnapshot.length === 0)) {
4327
- _context27.next = 39;
4479
+ _context29.next = 39;
4328
4480
  break;
4329
4481
  }
4330
- return _context27.abrupt("return");
4482
+ return _context29.abrupt("return");
4331
4483
  case 39:
4332
- _context27.next = 41;
4484
+ _context29.next = 41;
4333
4485
  return _this25.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
4334
4486
  case 41:
4335
4487
  _this25.recordRecentSqliteWrite(source, mergedSnapshot);
@@ -4339,33 +4491,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4339
4491
  });
4340
4492
  case 43:
4341
4493
  case "end":
4342
- return _context27.stop();
4494
+ return _context29.stop();
4343
4495
  }
4344
- }, _callee27, null, [[10, 25, 28, 31]]);
4496
+ }, _callee29, null, [[10, 25, 28, 31]]);
4345
4497
  })));
4346
4498
  case 9:
4347
4499
  persisted = true;
4348
- _context28.next = 15;
4500
+ _context30.next = 15;
4349
4501
  break;
4350
4502
  case 12:
4351
- _context28.prev = 12;
4352
- _context28.t0 = _context28["catch"](6);
4503
+ _context30.prev = 12;
4504
+ _context30.t0 = _context30["catch"](6);
4353
4505
  this.logError('全量保存订单到 SQLite 失败', {
4354
- error: _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0),
4506
+ error: _context30.t0 instanceof Error ? _context30.t0.message : String(_context30.t0),
4355
4507
  orderList: remoteSnapshot.length
4356
4508
  });
4357
4509
  case 15:
4358
- return _context28.abrupt("return", {
4510
+ return _context30.abrupt("return", {
4359
4511
  orders: mergedSnapshot,
4360
4512
  persisted: persisted
4361
4513
  });
4362
4514
  case 16:
4363
4515
  case "end":
4364
- return _context28.stop();
4516
+ return _context30.stop();
4365
4517
  }
4366
- }, _callee28, this, [[6, 12]]);
4518
+ }, _callee30, this, [[6, 12]]);
4367
4519
  }));
4368
- function replaceOrdersSnapshotInSQLite(_x20, _x21) {
4520
+ function replaceOrdersSnapshotInSQLite(_x22, _x23) {
4369
4521
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
4370
4522
  }
4371
4523
  return replaceOrdersSnapshotInSQLite;
@@ -4380,38 +4532,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4380
4532
  }, {
4381
4533
  key: "clear",
4382
4534
  value: (function () {
4383
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
4535
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
4384
4536
  var _this26 = this;
4385
- return _regeneratorRuntime().wrap(function _callee30$(_context30) {
4386
- while (1) switch (_context30.prev = _context30.next) {
4537
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
4538
+ while (1) switch (_context32.prev = _context32.next) {
4387
4539
  case 0:
4388
4540
  this.store.list = [];
4389
4541
  this.store.map = new Map();
4390
4542
  if (!this.dbManager) {
4391
- _context30.next = 5;
4543
+ _context32.next = 5;
4392
4544
  break;
4393
4545
  }
4394
- _context30.next = 5;
4395
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4396
- return _regeneratorRuntime().wrap(function _callee29$(_context29) {
4397
- while (1) switch (_context29.prev = _context29.next) {
4546
+ _context32.next = 5;
4547
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
4548
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
4549
+ while (1) switch (_context31.prev = _context31.next) {
4398
4550
  case 0:
4399
- _context29.next = 2;
4551
+ _context31.next = 2;
4400
4552
  return _this26.dbManager.clear(INDEXDB_STORE_NAME);
4401
4553
  case 2:
4402
4554
  case "end":
4403
- return _context29.stop();
4555
+ return _context31.stop();
4404
4556
  }
4405
- }, _callee29);
4557
+ }, _callee31);
4406
4558
  })));
4407
4559
  case 5:
4408
4560
  this.clearOrderSnapshotMarker();
4409
4561
  this.emitOrdersChanged([], 'clear');
4410
4562
  case 7:
4411
4563
  case "end":
4412
- return _context30.stop();
4564
+ return _context32.stop();
4413
4565
  }
4414
- }, _callee30, this);
4566
+ }, _callee32, this);
4415
4567
  }));
4416
4568
  function clear() {
4417
4569
  return _clear.apply(this, arguments);