@pisell/pisellos 2.3.69 → 2.3.71
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.
- package/dist/core/index.d.ts +0 -7
- package/dist/core/index.js +65 -109
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/types.d.ts +2 -0
- package/dist/modules/Order/types.js +1 -0
- package/dist/modules/Quotation/index.d.ts +0 -6
- package/dist/modules/Quotation/index.js +19 -75
- package/dist/plugins/request.d.ts +0 -1
- package/dist/server/index.d.ts +2 -8
- package/dist/server/index.js +140 -206
- package/dist/server/modules/floor-plan/index.d.ts +0 -4
- package/dist/server/modules/floor-plan/index.js +98 -240
- package/dist/server/modules/menu/index.js +23 -48
- package/dist/server/modules/order/index.d.ts +7 -17
- package/dist/server/modules/order/index.js +207 -419
- package/dist/server/modules/products/index.d.ts +2 -8
- package/dist/server/modules/products/index.js +75 -167
- package/dist/server/modules/resource/index.js +13 -21
- package/dist/solution/BaseSales/index.js +15 -4
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +5 -15
- package/dist/solution/BookingTicket/index.js +21 -6
- package/lib/core/index.d.ts +0 -7
- package/lib/core/index.js +2 -20
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/types.d.ts +2 -0
- package/lib/modules/Quotation/index.d.ts +0 -6
- package/lib/modules/Quotation/index.js +5 -49
- package/lib/plugins/request.d.ts +0 -1
- package/lib/server/index.d.ts +2 -8
- package/lib/server/index.js +17 -52
- package/lib/server/modules/floor-plan/index.d.ts +0 -4
- package/lib/server/modules/floor-plan/index.js +6 -54
- package/lib/server/modules/menu/index.js +5 -31
- package/lib/server/modules/order/index.d.ts +7 -17
- package/lib/server/modules/order/index.js +40 -197
- package/lib/server/modules/products/index.d.ts +2 -8
- package/lib/server/modules/products/index.js +24 -97
- package/lib/server/modules/resource/index.js +2 -7
- package/lib/solution/BaseSales/index.js +4 -4
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +5 -15
- package/lib/solution/BookingTicket/index.js +15 -5
- package/package.json +1 -1
|
@@ -43,7 +43,6 @@ import { getOrderPaymentIdentityKeys, isIdentifiedPendingOrderPayment, isPending
|
|
|
43
43
|
var INDEXDB_STORE_NAME = 'orders';
|
|
44
44
|
var ORDER_STORAGE_KEY_FIELD = '__order_storage_key';
|
|
45
45
|
var ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY = 'server_order_last_full_fetch_at';
|
|
46
|
-
var ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY = 'server_order_last_full_fetch_shop_id';
|
|
47
46
|
var ORDER_SYNC_THROTTLE_MS_STORAGE_KEY = 'order_sync_throttle_ms';
|
|
48
47
|
var DEFAULT_ORDER_SYNC_THROTTLE_MS = 2000;
|
|
49
48
|
/** pubsub 回声写入去重窗口:业务 API 刚写入后,跳过同单 SQLite patch */
|
|
@@ -309,23 +308,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
309
308
|
}, {
|
|
310
309
|
key: "normalizeOrderCollectionsForIngress",
|
|
311
310
|
value: function normalizeOrderCollectionsForIngress(order, source) {
|
|
312
|
-
var
|
|
313
|
-
var
|
|
311
|
+
var sourceOrder = cloneDeep(order);
|
|
312
|
+
var sourceOrderRecord = sourceOrder;
|
|
314
313
|
if (Array.isArray(sourceOrderRecord.payments)) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return _objectSpread(_objectSpread({}, payment), {}, _defineProperty({}, PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER, true));
|
|
323
|
-
})
|
|
314
|
+
sourceOrderRecord.payments = sourceOrderRecord.payments.map(function (payment) {
|
|
315
|
+
if (!isPendingOrderPayment(payment) || getOrderPaymentIdentityKeys(payment).some(function (key) {
|
|
316
|
+
return key.startsWith('unique_payment_number:');
|
|
317
|
+
})) {
|
|
318
|
+
return payment;
|
|
319
|
+
}
|
|
320
|
+
return _objectSpread(_objectSpread({}, payment), {}, _defineProperty({}, PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER, true));
|
|
324
321
|
});
|
|
325
322
|
}
|
|
326
|
-
|
|
327
|
-
// normalizeOrderCollections 内部已经 cloneDeep;这里只浅复制被改写的 payments,
|
|
328
|
-
// 既不修改调用方对象,也避免对整笔订单重复深拷贝。
|
|
329
323
|
var result = normalizeOrderCollections(sourceOrder);
|
|
330
324
|
var normalizedOrderRecord = result.order;
|
|
331
325
|
if (Array.isArray(normalizedOrderRecord.payments)) {
|
|
@@ -706,96 +700,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
706
700
|
key: "preload",
|
|
707
701
|
value: function () {
|
|
708
702
|
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
709
|
-
var
|
|
703
|
+
var orders;
|
|
710
704
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
711
705
|
while (1) switch (_context4.prev = _context4.next) {
|
|
712
706
|
case 0:
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
_context4.next = 12;
|
|
717
|
-
break;
|
|
718
|
-
}
|
|
719
|
-
_context4.prev = 3;
|
|
720
|
-
_context4.next = 6;
|
|
721
|
-
return this.loadOrdersFromSQLite({
|
|
722
|
-
throwOnError: true,
|
|
723
|
-
onTiming: function onTiming(timings) {
|
|
724
|
-
sqliteLoadTimings = timings;
|
|
725
|
-
}
|
|
726
|
-
});
|
|
727
|
-
case 6:
|
|
728
|
-
cachedOrders = _context4.sent;
|
|
729
|
-
_context4.next = 12;
|
|
730
|
-
break;
|
|
731
|
-
case 9:
|
|
732
|
-
_context4.prev = 9;
|
|
733
|
-
_context4.t0 = _context4["catch"](3);
|
|
734
|
-
this.logWarning('preload-SQLite读取失败,回退远端全量拉取', {
|
|
735
|
-
error: _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0)
|
|
736
|
-
});
|
|
737
|
-
case 12:
|
|
738
|
-
if (!(cachedOrders !== null && this.hasPulledOrdersToday())) {
|
|
739
|
-
_context4.next = 30;
|
|
740
|
-
break;
|
|
741
|
-
}
|
|
742
|
-
memoryPrepareStartedAt = performance.now();
|
|
743
|
-
memoryOrders = this.prepareNormalizedOrdersForMemoryList(cachedOrders);
|
|
744
|
-
memoryPrepareMs = +(performance.now() - memoryPrepareStartedAt).toFixed(2); // loadOrdersFromSQLite 已返回独立且完成集合规范化的新对象;直接进入 store,
|
|
745
|
-
// 不再进行第二轮 normalize 和没有隔离收益的最终 cloneDeep。
|
|
746
|
-
this.store.list = memoryOrders;
|
|
747
|
-
syncMapStartedAt = performance.now();
|
|
748
|
-
this.syncOrdersMap();
|
|
749
|
-
syncMapMs = +(performance.now() - syncMapStartedAt).toFixed(2);
|
|
750
|
-
onOrdersLoadedStartedAt = performance.now();
|
|
751
|
-
_context4.next = 23;
|
|
752
|
-
return this.core.effects.emit(OrderHooks.onOrdersLoaded, this.store.list);
|
|
753
|
-
case 23:
|
|
754
|
-
onOrdersLoadedMs = +(performance.now() - onOrdersLoadedStartedAt).toFixed(2);
|
|
755
|
-
emitOrdersChangedStartedAt = performance.now();
|
|
756
|
-
_context4.next = 27;
|
|
757
|
-
return this.emitOrdersChanged([], 'preload.sqlite');
|
|
758
|
-
case 27:
|
|
759
|
-
emitOrdersChangedMs = +(performance.now() - emitOrdersChangedStartedAt).toFixed(2);
|
|
760
|
-
this.logInfo('预加载完成', {
|
|
761
|
-
trigger: 'preload',
|
|
762
|
-
source: 'SQLite',
|
|
763
|
-
orderCount: this.store.list.length,
|
|
764
|
-
duration: "".concat(Date.now() - preloadStartedAt, "ms"),
|
|
765
|
-
stages: _objectSpread(_objectSpread({}, sqliteLoadTimings || {}), {}, {
|
|
766
|
-
memoryPrepareMs: memoryPrepareMs,
|
|
767
|
-
syncMapMs: syncMapMs,
|
|
768
|
-
onOrdersLoadedMs: onOrdersLoadedMs,
|
|
769
|
-
emitOrdersChangedMs: emitOrdersChangedMs
|
|
770
|
-
})
|
|
771
|
-
});
|
|
772
|
-
return _context4.abrupt("return");
|
|
773
|
-
case 30:
|
|
774
|
-
_context4.next = 32;
|
|
775
|
-
return this.loadOrdersByServer({
|
|
776
|
-
trigger: 'preload'
|
|
777
|
-
});
|
|
778
|
-
case 32:
|
|
707
|
+
_context4.next = 2;
|
|
708
|
+
return this.loadOrdersByServer();
|
|
709
|
+
case 2:
|
|
779
710
|
orders = _context4.sent;
|
|
780
711
|
this.store.list = cloneDeep(orders);
|
|
781
712
|
this.syncOrdersMap();
|
|
782
|
-
_context4.next =
|
|
713
|
+
_context4.next = 7;
|
|
783
714
|
return this.emitOrdersChanged([], 'preload');
|
|
784
|
-
case
|
|
785
|
-
_context4.next =
|
|
715
|
+
case 7:
|
|
716
|
+
_context4.next = 9;
|
|
786
717
|
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
787
|
-
case
|
|
788
|
-
this.logInfo('预加载完成', {
|
|
789
|
-
trigger: 'preload',
|
|
790
|
-
source: 'Server',
|
|
791
|
-
orderCount: this.store.list.length,
|
|
792
|
-
duration: "".concat(Date.now() - preloadStartedAt, "ms")
|
|
793
|
-
});
|
|
794
|
-
case 40:
|
|
718
|
+
case 9:
|
|
795
719
|
case "end":
|
|
796
720
|
return _context4.stop();
|
|
797
721
|
}
|
|
798
|
-
}, _callee4, this
|
|
722
|
+
}, _callee4, this);
|
|
799
723
|
}));
|
|
800
724
|
function preload() {
|
|
801
725
|
return _preload.apply(this, arguments);
|
|
@@ -1128,32 +1052,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1128
1052
|
var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
1129
1053
|
var _this5 = this,
|
|
1130
1054
|
_this$store;
|
|
1131
|
-
var
|
|
1132
|
-
orderList,
|
|
1133
|
-
hasFetchedRemoteSnapshot,
|
|
1134
|
-
trigger,
|
|
1135
|
-
protectedOrdersBeforeRemoteFetch,
|
|
1136
|
-
data,
|
|
1137
|
-
_yield$this$replaceOr,
|
|
1138
|
-
mergedOrders,
|
|
1139
|
-
isRemoteSnapshotPersisted,
|
|
1140
|
-
memoryOrders,
|
|
1141
|
-
_args8 = arguments;
|
|
1055
|
+
var orderList, protectedOrdersBeforeRemoteFetch, data, mergedOrders, memoryOrders;
|
|
1142
1056
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1143
1057
|
while (1) switch (_context8.prev = _context8.next) {
|
|
1144
1058
|
case 0:
|
|
1145
|
-
options = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
|
|
1146
1059
|
orderList = [];
|
|
1147
|
-
|
|
1148
|
-
trigger = options.trigger || 'unknown';
|
|
1149
|
-
_context8.next = 6;
|
|
1060
|
+
_context8.next = 3;
|
|
1150
1061
|
return this.loadOrdersFromSQLite();
|
|
1151
|
-
case
|
|
1062
|
+
case 3:
|
|
1152
1063
|
protectedOrdersBeforeRemoteFetch = _context8.sent.filter(function (order) {
|
|
1153
1064
|
return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
|
|
1154
1065
|
});
|
|
1155
1066
|
this.logInfo('loadOrdersByServer-开始', {
|
|
1156
|
-
trigger: trigger,
|
|
1157
1067
|
hasOrderDataSource: !!this.orderDataSource,
|
|
1158
1068
|
query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
|
|
1159
1069
|
protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
|
|
@@ -1162,61 +1072,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1162
1072
|
}, 0)
|
|
1163
1073
|
});
|
|
1164
1074
|
if (!this.orderDataSource) {
|
|
1165
|
-
_context8.next =
|
|
1075
|
+
_context8.next = 20;
|
|
1166
1076
|
break;
|
|
1167
1077
|
}
|
|
1168
|
-
_context8.prev =
|
|
1169
|
-
_context8.next =
|
|
1078
|
+
_context8.prev = 6;
|
|
1079
|
+
_context8.next = 9;
|
|
1170
1080
|
return this.orderDataSource.run({
|
|
1171
1081
|
sse: {
|
|
1172
1082
|
query: this.store.createdAtQuery
|
|
1173
1083
|
}
|
|
1174
1084
|
});
|
|
1175
|
-
case
|
|
1085
|
+
case 9:
|
|
1176
1086
|
data = _context8.sent;
|
|
1177
1087
|
orderList = data || [];
|
|
1178
1088
|
this.logInfo('loadOrdersByServer-SSE拉取成功', {
|
|
1179
|
-
trigger: trigger,
|
|
1180
1089
|
count: orderList.length
|
|
1181
1090
|
});
|
|
1182
|
-
|
|
1091
|
+
this.markOrderPulledAtNow();
|
|
1183
1092
|
this.lastServerFullFetchAtMs = Date.now();
|
|
1184
|
-
_context8.next =
|
|
1093
|
+
_context8.next = 20;
|
|
1185
1094
|
break;
|
|
1186
|
-
case
|
|
1187
|
-
_context8.prev =
|
|
1188
|
-
_context8.t0 = _context8["catch"](
|
|
1095
|
+
case 16:
|
|
1096
|
+
_context8.prev = 16;
|
|
1097
|
+
_context8.t0 = _context8["catch"](6);
|
|
1189
1098
|
this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
|
|
1190
1099
|
return _context8.abrupt("return", this.store.list);
|
|
1191
|
-
case
|
|
1192
|
-
|
|
1193
|
-
this.clearOrderSnapshotMarker();
|
|
1194
|
-
}
|
|
1195
|
-
_context8.next = 26;
|
|
1100
|
+
case 20:
|
|
1101
|
+
_context8.next = 22;
|
|
1196
1102
|
return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
|
|
1197
|
-
case
|
|
1198
|
-
|
|
1199
|
-
mergedOrders = _yield$this$replaceOr.orders;
|
|
1200
|
-
isRemoteSnapshotPersisted = _yield$this$replaceOr.persisted;
|
|
1201
|
-
if (hasFetchedRemoteSnapshot && isRemoteSnapshotPersisted) {
|
|
1202
|
-
this.markOrderPulledAtNow();
|
|
1203
|
-
}
|
|
1103
|
+
case 22:
|
|
1104
|
+
mergedOrders = _context8.sent;
|
|
1204
1105
|
memoryOrders = this.normalizeOrdersForMemoryList(mergedOrders, 'loadOrdersByServer.memory');
|
|
1205
1106
|
this.logInfo('loadOrdersByServer-结束', {
|
|
1206
|
-
trigger: trigger,
|
|
1207
1107
|
count: memoryOrders.length,
|
|
1208
1108
|
persistedCount: mergedOrders.length,
|
|
1209
1109
|
sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
|
|
1210
1110
|
});
|
|
1211
|
-
_context8.next =
|
|
1111
|
+
_context8.next = 27;
|
|
1212
1112
|
return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
|
|
1213
|
-
case
|
|
1113
|
+
case 27:
|
|
1214
1114
|
return _context8.abrupt("return", memoryOrders);
|
|
1215
|
-
case
|
|
1115
|
+
case 28:
|
|
1216
1116
|
case "end":
|
|
1217
1117
|
return _context8.stop();
|
|
1218
1118
|
}
|
|
1219
|
-
}, _callee8, this, [[
|
|
1119
|
+
}, _callee8, this, [[6, 16]]);
|
|
1220
1120
|
}));
|
|
1221
1121
|
function loadOrdersByServer() {
|
|
1222
1122
|
return _loadOrdersByServer.apply(this, arguments);
|
|
@@ -1232,76 +1132,53 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1232
1132
|
key: "silentRefresh",
|
|
1233
1133
|
value: (function () {
|
|
1234
1134
|
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
1235
|
-
var
|
|
1236
|
-
startTime,
|
|
1237
|
-
trigger,
|
|
1238
|
-
elapsedSinceFullFetch,
|
|
1239
|
-
orders,
|
|
1240
|
-
errorMessage,
|
|
1241
|
-
_args9 = arguments;
|
|
1135
|
+
var startTime, elapsedSinceFullFetch, orders, errorMessage;
|
|
1242
1136
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1243
1137
|
while (1) switch (_context9.prev = _context9.next) {
|
|
1244
1138
|
case 0:
|
|
1245
|
-
options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
|
|
1246
1139
|
startTime = Date.now();
|
|
1247
|
-
trigger = options.trigger || 'background';
|
|
1248
1140
|
elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
|
|
1249
1141
|
if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
|
|
1250
|
-
_context9.next =
|
|
1142
|
+
_context9.next = 4;
|
|
1251
1143
|
break;
|
|
1252
1144
|
}
|
|
1253
|
-
this.logInfo('silentRefresh 跳过全量 SSE', {
|
|
1254
|
-
trigger: trigger,
|
|
1255
|
-
reason: 'within_min_interval',
|
|
1256
|
-
minIntervalMs: ORDER_SILENT_REFRESH_MIN_INTERVAL_MS,
|
|
1257
|
-
elapsedSinceFullFetchMs: elapsedSinceFullFetch,
|
|
1258
|
-
orderCount: this.store.list.length
|
|
1259
|
-
});
|
|
1260
1145
|
return _context9.abrupt("return", this.store.list);
|
|
1261
|
-
case
|
|
1262
|
-
this.logInfo('silentRefresh 开始'
|
|
1263
|
-
|
|
1264
|
-
elapsedSinceFullFetchMs: elapsedSinceFullFetch,
|
|
1265
|
-
orderCount: this.store.list.length
|
|
1266
|
-
});
|
|
1267
|
-
_context9.prev = 8;
|
|
1146
|
+
case 4:
|
|
1147
|
+
this.logInfo('silentRefresh 开始');
|
|
1148
|
+
_context9.prev = 5;
|
|
1268
1149
|
// 刷新前,需要更新当前营业日边界(store.createdAtQuery)
|
|
1269
1150
|
this.updateCreateStore();
|
|
1270
|
-
_context9.next =
|
|
1271
|
-
return this.loadOrdersByServer(
|
|
1272
|
-
|
|
1273
|
-
});
|
|
1274
|
-
case 12:
|
|
1151
|
+
_context9.next = 9;
|
|
1152
|
+
return this.loadOrdersByServer();
|
|
1153
|
+
case 9:
|
|
1275
1154
|
orders = _context9.sent;
|
|
1276
1155
|
this.store.list = cloneDeep(orders);
|
|
1277
1156
|
this.syncOrdersMap();
|
|
1278
|
-
_context9.next =
|
|
1157
|
+
_context9.next = 14;
|
|
1279
1158
|
return this.emitOrdersChanged([], 'silentRefresh');
|
|
1280
|
-
case
|
|
1281
|
-
_context9.next =
|
|
1159
|
+
case 14:
|
|
1160
|
+
_context9.next = 16;
|
|
1282
1161
|
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
1283
|
-
case
|
|
1162
|
+
case 16:
|
|
1284
1163
|
this.logInfo('silentRefresh 完成', {
|
|
1285
|
-
trigger: trigger,
|
|
1286
1164
|
orderCount: orders.length,
|
|
1287
1165
|
duration: "".concat(Date.now() - startTime, "ms")
|
|
1288
1166
|
});
|
|
1289
1167
|
return _context9.abrupt("return", this.store.list);
|
|
1290
|
-
case
|
|
1291
|
-
_context9.prev =
|
|
1292
|
-
_context9.t0 = _context9["catch"](
|
|
1168
|
+
case 20:
|
|
1169
|
+
_context9.prev = 20;
|
|
1170
|
+
_context9.t0 = _context9["catch"](5);
|
|
1293
1171
|
errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
|
|
1294
1172
|
this.logError('silentRefresh 失败', {
|
|
1295
|
-
trigger: trigger,
|
|
1296
1173
|
duration: "".concat(Date.now() - startTime, "ms"),
|
|
1297
1174
|
error: errorMessage
|
|
1298
1175
|
});
|
|
1299
1176
|
return _context9.abrupt("return", this.store.list);
|
|
1300
|
-
case
|
|
1177
|
+
case 25:
|
|
1301
1178
|
case "end":
|
|
1302
1179
|
return _context9.stop();
|
|
1303
1180
|
}
|
|
1304
|
-
}, _callee9, this, [[
|
|
1181
|
+
}, _callee9, this, [[5, 20]]);
|
|
1305
1182
|
}));
|
|
1306
1183
|
function silentRefresh() {
|
|
1307
1184
|
return _silentRefresh.apply(this, arguments);
|
|
@@ -1313,15 +1190,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1313
1190
|
value: function normalizeOrderForMemoryList(order) {
|
|
1314
1191
|
var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'normalizeOrderForMemoryList';
|
|
1315
1192
|
var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, source);
|
|
1316
|
-
return this.prepareNormalizedOrderForMemoryList(normalizedOrder);
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
/**
|
|
1320
|
-
* 将已经完成集合规范化的订单转换为内存身份,不重复扫描 products/bookings/payments。
|
|
1321
|
-
*/
|
|
1322
|
-
}, {
|
|
1323
|
-
key: "prepareNormalizedOrderForMemoryList",
|
|
1324
|
-
value: function prepareNormalizedOrderForMemoryList(normalizedOrder) {
|
|
1325
1193
|
var externalSaleNumber = normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.external_sale_number;
|
|
1326
1194
|
if (this.isDraftOrder(normalizedOrder) && !this.hasRealOrderId(normalizedOrder)) {
|
|
1327
1195
|
return normalizedOrder;
|
|
@@ -1336,24 +1204,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1336
1204
|
order_id: externalSaleNumber
|
|
1337
1205
|
});
|
|
1338
1206
|
}
|
|
1339
|
-
}, {
|
|
1340
|
-
key: "prepareNormalizedOrdersForMemoryList",
|
|
1341
|
-
value: function prepareNormalizedOrdersForMemoryList(orders) {
|
|
1342
|
-
var _this6 = this;
|
|
1343
|
-
return orders.map(function (order) {
|
|
1344
|
-
return _this6.prepareNormalizedOrderForMemoryList(order);
|
|
1345
|
-
}).filter(function (order) {
|
|
1346
|
-
return _this6.shouldKeepOrderInMemory(order);
|
|
1347
|
-
});
|
|
1348
|
-
}
|
|
1349
1207
|
}, {
|
|
1350
1208
|
key: "normalizeOrdersForMemoryList",
|
|
1351
1209
|
value: function normalizeOrdersForMemoryList(orders, source) {
|
|
1352
|
-
var
|
|
1210
|
+
var _this6 = this;
|
|
1353
1211
|
return orders.map(function (order) {
|
|
1354
|
-
return
|
|
1212
|
+
return _this6.normalizeOrderForMemoryList(order, source);
|
|
1355
1213
|
}).filter(function (order) {
|
|
1356
|
-
return
|
|
1214
|
+
return _this6.shouldKeepOrderInMemory(order);
|
|
1357
1215
|
});
|
|
1358
1216
|
}
|
|
1359
1217
|
}, {
|
|
@@ -1388,7 +1246,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1388
1246
|
key: "overwriteExistingOrder",
|
|
1389
1247
|
value: (function () {
|
|
1390
1248
|
var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fresh) {
|
|
1391
|
-
var
|
|
1249
|
+
var _this7 = this;
|
|
1392
1250
|
var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
|
|
1393
1251
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1394
1252
|
while (1) switch (_context10.prev = _context10.next) {
|
|
@@ -1425,9 +1283,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1425
1283
|
this.store.list = this.store.list.map(function (order) {
|
|
1426
1284
|
var id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
1427
1285
|
if (id === undefined || id === null) {
|
|
1428
|
-
return
|
|
1286
|
+
return _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
|
|
1429
1287
|
}
|
|
1430
|
-
return
|
|
1288
|
+
return _this7.getIdKey(id) === key ? reconciledFresh : _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
|
|
1431
1289
|
});
|
|
1432
1290
|
this.syncOrdersMap();
|
|
1433
1291
|
_context10.next = 16;
|
|
@@ -1499,7 +1357,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1499
1357
|
key: "markOrderSyncedByExternalSaleNumber",
|
|
1500
1358
|
value: function () {
|
|
1501
1359
|
var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
|
|
1502
|
-
var
|
|
1360
|
+
var _this8 = this,
|
|
1503
1361
|
_existing$external_sa,
|
|
1504
1362
|
_nextOrder$order_id;
|
|
1505
1363
|
var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
|
|
@@ -1520,7 +1378,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1520
1378
|
targetIndex = this.store.list.findIndex(function (order) {
|
|
1521
1379
|
var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
|
|
1522
1380
|
if (value === undefined || value === null || value === '') return false;
|
|
1523
|
-
return
|
|
1381
|
+
return _this8.getIdKey(value) === key;
|
|
1524
1382
|
});
|
|
1525
1383
|
if (!(targetIndex < 0)) {
|
|
1526
1384
|
_context12.next = 9;
|
|
@@ -1578,7 +1436,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1578
1436
|
key: "upsertPendingSyncOrders",
|
|
1579
1437
|
value: (function () {
|
|
1580
1438
|
var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(pendingOrders) {
|
|
1581
|
-
var
|
|
1439
|
+
var _this9 = this;
|
|
1582
1440
|
var options,
|
|
1583
1441
|
pendingMap,
|
|
1584
1442
|
memoryPendingMap,
|
|
@@ -1674,7 +1532,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1674
1532
|
});
|
|
1675
1533
|
mergeActions = {};
|
|
1676
1534
|
updatedList = this.store.list.map(function (order) {
|
|
1677
|
-
return
|
|
1535
|
+
return _this9.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
|
|
1678
1536
|
}); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
|
|
1679
1537
|
// 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
|
|
1680
1538
|
identityKeyToIndex = new Map();
|
|
@@ -1784,7 +1642,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1784
1642
|
key: "upsertLocalDraftOrders",
|
|
1785
1643
|
value: (function () {
|
|
1786
1644
|
var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(draftOrders) {
|
|
1787
|
-
var
|
|
1645
|
+
var _this10 = this;
|
|
1788
1646
|
var draftMap, memoryDraftMap, _iterator9, _step9, order, draftOrder, storageKey, memoryDraftOrder, mergeActions, updatedList, identityKeyToIndex, index, _iterator10, _step10, key, _iterator11, _step11, _step11$value, _storageKey2, _draftOrder, matchIndex, existingOrder, reconciledDraftOrder, mergedOrder, nextOrder, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
|
|
1789
1647
|
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1790
1648
|
while (1) switch (_context14.prev = _context14.next) {
|
|
@@ -1854,7 +1712,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1854
1712
|
});
|
|
1855
1713
|
mergeActions = {};
|
|
1856
1714
|
updatedList = this.store.list.filter(function (order) {
|
|
1857
|
-
return
|
|
1715
|
+
return _this10.shouldKeepOrderInMemory(order);
|
|
1858
1716
|
});
|
|
1859
1717
|
identityKeyToIndex = new Map();
|
|
1860
1718
|
for (index = 0; index < updatedList.length; index += 1) {
|
|
@@ -1941,7 +1799,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1941
1799
|
storeOrderCountAfter: this.store.list.length
|
|
1942
1800
|
});
|
|
1943
1801
|
removedLegacyMemoryDraft = previousList.some(function (order) {
|
|
1944
|
-
return !
|
|
1802
|
+
return !_this10.shouldKeepOrderInMemory(order);
|
|
1945
1803
|
});
|
|
1946
1804
|
if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
|
|
1947
1805
|
_context14.next = 84;
|
|
@@ -1949,7 +1807,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1949
1807
|
}
|
|
1950
1808
|
_context14.next = 84;
|
|
1951
1809
|
return this.emitOrdersChanged(patchedOrders.filter(function (order) {
|
|
1952
|
-
return
|
|
1810
|
+
return _this10.shouldKeepOrderInMemory(order);
|
|
1953
1811
|
}), 'upsertLocalDraftOrders');
|
|
1954
1812
|
case 84:
|
|
1955
1813
|
case "end":
|
|
@@ -2032,9 +1890,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2032
1890
|
}, {
|
|
2033
1891
|
key: "syncOrdersMap",
|
|
2034
1892
|
value: function syncOrdersMap() {
|
|
2035
|
-
var
|
|
1893
|
+
var _this11 = this;
|
|
2036
1894
|
this.store.list = this.store.list.filter(function (order) {
|
|
2037
|
-
return
|
|
1895
|
+
return _this11.shouldKeepOrderInMemory(order);
|
|
2038
1896
|
});
|
|
2039
1897
|
this.store.map.clear();
|
|
2040
1898
|
var _iterator12 = _createForOfIteratorHelper(this.store.list),
|
|
@@ -2090,7 +1948,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2090
1948
|
}, {
|
|
2091
1949
|
key: "getOrderIdentityEntries",
|
|
2092
1950
|
value: function getOrderIdentityEntries(order) {
|
|
2093
|
-
var
|
|
1951
|
+
var _this12 = this;
|
|
2094
1952
|
if (!order) return [];
|
|
2095
1953
|
var record = order;
|
|
2096
1954
|
var candidates = [{
|
|
@@ -2109,8 +1967,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2109
1967
|
var entries = [];
|
|
2110
1968
|
var _loop = function _loop() {
|
|
2111
1969
|
var candidate = _candidates[_i2];
|
|
2112
|
-
if (
|
|
2113
|
-
var key =
|
|
1970
|
+
if (_this12.isBlankIdentityValue(candidate.value)) return 0; // continue
|
|
1971
|
+
var key = _this12.getIdKey(candidate.value);
|
|
2114
1972
|
if (entries.some(function (entry) {
|
|
2115
1973
|
return entry.field === candidate.field && entry.key === key;
|
|
2116
1974
|
})) return 0; // continue
|
|
@@ -2177,7 +2035,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2177
2035
|
}, {
|
|
2178
2036
|
key: "setupOrderSync",
|
|
2179
2037
|
value: function setupOrderSync() {
|
|
2180
|
-
var
|
|
2038
|
+
var _this13 = this;
|
|
2181
2039
|
if (!this.orderDataSource) return;
|
|
2182
2040
|
this.orderDataSource.run({
|
|
2183
2041
|
pubsub: {
|
|
@@ -2185,22 +2043,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2185
2043
|
var _message$id, _message$order_id, _message$type;
|
|
2186
2044
|
console.log('orderDataSource', res);
|
|
2187
2045
|
var pubsubReceivedAt = Date.now();
|
|
2188
|
-
var message =
|
|
2046
|
+
var message = _this13.normalizeOrderSyncMessage(res);
|
|
2189
2047
|
if (!message) return;
|
|
2190
2048
|
message._pubsubReceivedAt = pubsubReceivedAt;
|
|
2191
|
-
|
|
2192
|
-
var throttleMs =
|
|
2193
|
-
var routeInfo =
|
|
2194
|
-
|
|
2049
|
+
_this13.pendingSyncMessages.push(message);
|
|
2050
|
+
var throttleMs = _this13.getOrderSyncThrottleMs();
|
|
2051
|
+
var routeInfo = _this13.resolveSyncMessageRoute(message);
|
|
2052
|
+
_this13.logInfo('orderSync-收到消息并入队', {
|
|
2195
2053
|
id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
|
|
2196
2054
|
order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
|
|
2197
2055
|
type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
|
|
2198
|
-
pendingCount:
|
|
2056
|
+
pendingCount: _this13.pendingSyncMessages.length,
|
|
2199
2057
|
throttleMs: throttleMs,
|
|
2200
2058
|
pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
|
|
2201
2059
|
fullMessage: JSON.stringify(message)
|
|
2202
2060
|
});
|
|
2203
|
-
|
|
2061
|
+
_this13.scheduleOrderSyncThrottle();
|
|
2204
2062
|
}
|
|
2205
2063
|
}
|
|
2206
2064
|
}).catch(function () {
|
|
@@ -2217,7 +2075,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2217
2075
|
}, {
|
|
2218
2076
|
key: "scheduleOrderSyncThrottle",
|
|
2219
2077
|
value: function scheduleOrderSyncThrottle() {
|
|
2220
|
-
var
|
|
2078
|
+
var _this14 = this;
|
|
2221
2079
|
if (this.isProcessingSyncBatch) return;
|
|
2222
2080
|
if (this.isIdlePhase) {
|
|
2223
2081
|
this.isIdlePhase = false;
|
|
@@ -2228,8 +2086,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2228
2086
|
if (this.syncTimer) return;
|
|
2229
2087
|
var throttleMs = this.getOrderSyncThrottleMs();
|
|
2230
2088
|
this.syncTimer = setTimeout(function () {
|
|
2231
|
-
|
|
2232
|
-
void
|
|
2089
|
+
_this14.syncTimer = undefined;
|
|
2090
|
+
void _this14.flushOrderSyncMessagesByThrottle();
|
|
2233
2091
|
}, throttleMs);
|
|
2234
2092
|
}
|
|
2235
2093
|
|
|
@@ -2297,7 +2155,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2297
2155
|
key: "processOrderSyncMessages",
|
|
2298
2156
|
value: (function () {
|
|
2299
2157
|
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
2300
|
-
var
|
|
2158
|
+
var _this15 = this;
|
|
2301
2159
|
var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
|
|
2302
2160
|
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
2303
2161
|
while (1) switch (_context17.prev = _context17.next) {
|
|
@@ -2324,13 +2182,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2324
2182
|
upsertOrders = new Map();
|
|
2325
2183
|
refreshIds = [];
|
|
2326
2184
|
messages.forEach(function (msg, msgIndex) {
|
|
2327
|
-
var routeInfo =
|
|
2185
|
+
var routeInfo = _this15.resolveSyncMessageRoute(msg);
|
|
2328
2186
|
var hasBatchIds = routeInfo.hasBatchIds;
|
|
2329
2187
|
var singleId = routeInfo.singleId;
|
|
2330
2188
|
var hasSingleId = routeInfo.hasSingleId;
|
|
2331
|
-
var normalizedBody =
|
|
2189
|
+
var normalizedBody = _this15.normalizeOrderSyncPayload(msg.body || msg.data);
|
|
2332
2190
|
if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
|
|
2333
|
-
upsertOrders.set(
|
|
2191
|
+
upsertOrders.set(_this15.getIdKey(normalizedBody.order_id), normalizedBody);
|
|
2334
2192
|
return;
|
|
2335
2193
|
}
|
|
2336
2194
|
if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));else if (routeInfo.route === 'httpRefresh.singleId' && singleId !== null) refreshIds.push(singleId);else if (routeInfo.route === 'httpRefresh.relationIds') refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));
|
|
@@ -2468,7 +2326,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2468
2326
|
key: "mergeOrdersToStore",
|
|
2469
2327
|
value: (function () {
|
|
2470
2328
|
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(freshOrders, source) {
|
|
2471
|
-
var
|
|
2329
|
+
var _this16 = this;
|
|
2472
2330
|
var storeOrderCountBefore, normalizedFreshOrders, incomingProductsHaveStableIdentity, _iterator14, _step14, order, id, rawProducts, _incomingProductsHave, allProductsHaveStableIdentity, orderIdKey, uniqueFreshOrders, uniqueFreshCount, patchedOrders, remoteProductMembershipChanges, forceWriteStorageKeys, storageKeyMigrations, mergeActions, existingProductsHaveStableIdentity, updatedList, identityKeyToIndex, index, identityKeys, _iterator15, _step15, key, _iterator16, _step16, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, previousStorageKey, _ref, _existingOrder$order_, _ref2, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, _ref3, _existingOrder$order_2, _ref4, _external_sale_number3, _existingOrder$is_dra, _fresh$is_draft_order, mergedOrder, freshOrderId, incomingProductsAreStable, membershipChange, mergedProductsHaveStableIdentity, adjustedMatchIndex, duplicateIndexes, _iterator17, _step17, _key2, _duplicateIndex, _iterator18, _step18, duplicateIndex, _index, _iterator19, _step19, _key, nextStorageKey, _ref5, _ref6, _mergedOrder$order_id, mergedStorageKey, insertIndex, insertCount, updateCount;
|
|
2473
2331
|
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
2474
2332
|
while (1) switch (_context19.prev = _context19.next) {
|
|
@@ -2529,10 +2387,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2529
2387
|
storageKeyMigrations = [];
|
|
2530
2388
|
mergeActions = {};
|
|
2531
2389
|
existingProductsHaveStableIdentity = this.store.list.map(function (order) {
|
|
2532
|
-
return
|
|
2390
|
+
return _this16.doProductsHaveStableMembershipIdentity(order.products);
|
|
2533
2391
|
});
|
|
2534
2392
|
updatedList = this.store.list.map(function (order) {
|
|
2535
|
-
return
|
|
2393
|
+
return _this16.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
|
|
2536
2394
|
}); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
|
|
2537
2395
|
// 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
|
|
2538
2396
|
// 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
|
|
@@ -2836,7 +2694,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2836
2694
|
}, {
|
|
2837
2695
|
key: "getRemoteProductMembershipChange",
|
|
2838
2696
|
value: function getRemoteProductMembershipChange(existingOrder, mergedOrder, source) {
|
|
2839
|
-
var
|
|
2697
|
+
var _this17 = this,
|
|
2840
2698
|
_mergedOrder$order_id2;
|
|
2841
2699
|
if (!this.isRemoteProductMembershipChangeSource(source)) return null;
|
|
2842
2700
|
var previousProducts = Array.isArray(existingOrder.products) ? existingOrder.products : [];
|
|
@@ -2851,13 +2709,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2851
2709
|
var _loop2 = function _loop2() {
|
|
2852
2710
|
var previousProduct = _step21.value;
|
|
2853
2711
|
var matchedIndex = currentProducts.findIndex(function (currentProduct, index) {
|
|
2854
|
-
return unmatchedCurrentIndexes.has(index) &&
|
|
2712
|
+
return unmatchedCurrentIndexes.has(index) && _this17.isSameProductMembershipItem(previousProduct, currentProduct);
|
|
2855
2713
|
});
|
|
2856
2714
|
if (matchedIndex >= 0) {
|
|
2857
2715
|
unmatchedCurrentIndexes.delete(matchedIndex);
|
|
2858
2716
|
return 1; // continue
|
|
2859
2717
|
}
|
|
2860
|
-
var productKey =
|
|
2718
|
+
var productKey = _this17.getProductMembershipKey(previousProduct);
|
|
2861
2719
|
if (productKey) removedProductKeys.push(productKey);
|
|
2862
2720
|
};
|
|
2863
2721
|
for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
|
|
@@ -2869,7 +2727,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2869
2727
|
_iterator21.f();
|
|
2870
2728
|
}
|
|
2871
2729
|
var addedProductKeys = _toConsumableArray(unmatchedCurrentIndexes).map(function (index) {
|
|
2872
|
-
return
|
|
2730
|
+
return _this17.getProductMembershipKey(currentProducts[index]);
|
|
2873
2731
|
}).filter(Boolean);
|
|
2874
2732
|
if (addedProductKeys.length === 0 && removedProductKeys.length === 0) {
|
|
2875
2733
|
return null;
|
|
@@ -2984,12 +2842,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2984
2842
|
}, {
|
|
2985
2843
|
key: "isOrderLookupMatch",
|
|
2986
2844
|
value: function isOrderLookupMatch(order, lookupKey) {
|
|
2987
|
-
var
|
|
2845
|
+
var _this18 = this;
|
|
2988
2846
|
if (!order || !lookupKey) return false;
|
|
2989
2847
|
var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
|
|
2990
2848
|
return candidates.some(function (value) {
|
|
2991
2849
|
if (value === undefined || value === null || value === '') return false;
|
|
2992
|
-
return
|
|
2850
|
+
return _this18.getIdKey(value) === lookupKey;
|
|
2993
2851
|
});
|
|
2994
2852
|
}
|
|
2995
2853
|
|
|
@@ -3041,10 +2899,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3041
2899
|
}, {
|
|
3042
2900
|
key: "findOrderIndexByIdentity",
|
|
3043
2901
|
value: function findOrderIndexByIdentity(orders, target) {
|
|
3044
|
-
var
|
|
2902
|
+
var _this19 = this;
|
|
3045
2903
|
if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
|
|
3046
2904
|
return orders.findIndex(function (order) {
|
|
3047
|
-
return
|
|
2905
|
+
return _this19.doOrdersShareIdentity(order, target);
|
|
3048
2906
|
});
|
|
3049
2907
|
}
|
|
3050
2908
|
}, {
|
|
@@ -3356,32 +3214,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3356
3214
|
}
|
|
3357
3215
|
|
|
3358
3216
|
/**
|
|
3359
|
-
*
|
|
3360
|
-
*
|
|
3217
|
+
* 当前订单拉取窗口:
|
|
3218
|
+
* - 优先使用 createdAtQuery.sales_time_between(已按营业日边界初始化)
|
|
3219
|
+
* - 无法解析时退化为自然日窗口
|
|
3361
3220
|
*/
|
|
3362
3221
|
}, {
|
|
3363
|
-
key: "
|
|
3364
|
-
value: function
|
|
3222
|
+
key: "getCurrentPullWindow",
|
|
3223
|
+
value: function getCurrentPullWindow() {
|
|
3224
|
+
var _this$store2;
|
|
3365
3225
|
var now = dayjs();
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
var
|
|
3369
|
-
var
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
if (todayBoundary.isValid()) {
|
|
3376
|
-
var _startAt = now.isBefore(todayBoundary) ? todayBoundary.subtract(1, 'day') : todayBoundary;
|
|
3377
|
-
return {
|
|
3378
|
-
startAt: _startAt,
|
|
3379
|
-
endExclusiveAt: _startAt.add(1, 'day')
|
|
3380
|
-
};
|
|
3381
|
-
}
|
|
3226
|
+
var range = (_this$store2 = this.store) === null || _this$store2 === void 0 || (_this$store2 = _this$store2.createdAtQuery) === null || _this$store2 === void 0 ? void 0 : _this$store2.sales_time_between;
|
|
3227
|
+
if (Array.isArray(range) && range.length >= 2) {
|
|
3228
|
+
var _startAt = dayjs(range[0]);
|
|
3229
|
+
var endExclusiveAt = dayjs(range[1]);
|
|
3230
|
+
if (_startAt.isValid() && endExclusiveAt.isValid() && endExclusiveAt.isAfter(_startAt)) {
|
|
3231
|
+
return {
|
|
3232
|
+
startAt: _startAt,
|
|
3233
|
+
endExclusiveAt: endExclusiveAt
|
|
3234
|
+
};
|
|
3382
3235
|
}
|
|
3383
|
-
} catch (_unused6) {
|
|
3384
|
-
// 读取营业日配置失败时按自然日兜底,不影响启动。
|
|
3385
3236
|
}
|
|
3386
3237
|
var startAt = now.startOf('day');
|
|
3387
3238
|
return {
|
|
@@ -3394,47 +3245,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3394
3245
|
value: function hasPulledOrdersToday() {
|
|
3395
3246
|
var lastFullFetchAt = this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY);
|
|
3396
3247
|
if (!lastFullFetchAt) return false;
|
|
3397
|
-
var currentShopId = this.getCurrentShopId();
|
|
3398
|
-
var lastFullFetchShopId = this.getStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY);
|
|
3399
|
-
if (!currentShopId || !lastFullFetchShopId || currentShopId !== lastFullFetchShopId) {
|
|
3400
|
-
return false;
|
|
3401
|
-
}
|
|
3402
3248
|
var parsed = dayjs(lastFullFetchAt);
|
|
3403
3249
|
if (!parsed.isValid()) return false;
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3250
|
+
|
|
3251
|
+
// 按当前拉取窗口判断,而不是自然日判断。
|
|
3252
|
+
// 这样在营业日跨日边界(start_time)场景下也能正确判定是否需要重新拉取。
|
|
3253
|
+
var _this$getCurrentPullW = this.getCurrentPullWindow(),
|
|
3254
|
+
startAt = _this$getCurrentPullW.startAt,
|
|
3255
|
+
endExclusiveAt = _this$getCurrentPullW.endExclusiveAt;
|
|
3407
3256
|
return (parsed.isAfter(startAt) || parsed.isSame(startAt)) && parsed.isBefore(endExclusiveAt);
|
|
3408
3257
|
}
|
|
3409
3258
|
}, {
|
|
3410
3259
|
key: "markOrderPulledAtNow",
|
|
3411
3260
|
value: function markOrderPulledAtNow() {
|
|
3412
|
-
var currentShopId = this.getCurrentShopId();
|
|
3413
|
-
if (!currentShopId) return;
|
|
3414
3261
|
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, dayjs().format('YYYY-MM-DD HH:mm:ss'));
|
|
3415
|
-
this.setStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY, currentShopId);
|
|
3416
|
-
}
|
|
3417
|
-
}, {
|
|
3418
|
-
key: "clearOrderSnapshotMarker",
|
|
3419
|
-
value: function clearOrderSnapshotMarker() {
|
|
3420
|
-
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
|
|
3421
|
-
this.setStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY, '');
|
|
3422
|
-
}
|
|
3423
|
-
}, {
|
|
3424
|
-
key: "getCurrentShopId",
|
|
3425
|
-
value: function getCurrentShopId() {
|
|
3426
|
-
try {
|
|
3427
|
-
var _coreData$core2;
|
|
3428
|
-
var appPlugin = this.core.getPlugin('app');
|
|
3429
|
-
var app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
|
|
3430
|
-
if (!app) return null;
|
|
3431
|
-
var coreData = app.data.store.getStore().getDataByModel('core');
|
|
3432
|
-
var shopId = coreData === null || coreData === void 0 || (_coreData$core2 = coreData.core) === null || _coreData$core2 === void 0 ? void 0 : _coreData$core2.id;
|
|
3433
|
-
if (shopId === undefined || shopId === null || shopId === '') return null;
|
|
3434
|
-
return String(shopId);
|
|
3435
|
-
} catch (_unused7) {
|
|
3436
|
-
return null;
|
|
3437
|
-
}
|
|
3438
3262
|
}
|
|
3439
3263
|
}, {
|
|
3440
3264
|
key: "getStorageItem",
|
|
@@ -3445,7 +3269,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3445
3269
|
if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
|
|
3446
3270
|
return globalThis.localStorage.getItem(key);
|
|
3447
3271
|
}
|
|
3448
|
-
} catch (
|
|
3272
|
+
} catch (_unused6) {
|
|
3449
3273
|
// 忽略存储异常,避免影响主流程
|
|
3450
3274
|
}
|
|
3451
3275
|
return null;
|
|
@@ -3462,7 +3286,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3462
3286
|
if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
|
|
3463
3287
|
globalThis.localStorage.setItem(key, value);
|
|
3464
3288
|
}
|
|
3465
|
-
} catch (
|
|
3289
|
+
} catch (_unused7) {
|
|
3466
3290
|
// 忽略存储异常,避免影响主流程
|
|
3467
3291
|
}
|
|
3468
3292
|
}
|
|
@@ -3470,61 +3294,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3470
3294
|
key: "loadOrdersFromSQLite",
|
|
3471
3295
|
value: function () {
|
|
3472
3296
|
var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
3473
|
-
var
|
|
3474
|
-
var
|
|
3475
|
-
_options$onTiming,
|
|
3476
|
-
loadStartedAt,
|
|
3477
|
-
rawReadStartedAt,
|
|
3478
|
-
orders,
|
|
3479
|
-
sqliteRawReadMs,
|
|
3480
|
-
normalizeStartedAt,
|
|
3481
|
-
normalizedOrders,
|
|
3482
|
-
sqliteNormalizeMs,
|
|
3483
|
-
_args20 = arguments;
|
|
3297
|
+
var _this20 = this;
|
|
3298
|
+
var orders;
|
|
3484
3299
|
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
3485
3300
|
while (1) switch (_context20.prev = _context20.next) {
|
|
3486
3301
|
case 0:
|
|
3487
|
-
options = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {};
|
|
3488
3302
|
if (this.dbManager) {
|
|
3489
|
-
_context20.next =
|
|
3303
|
+
_context20.next = 2;
|
|
3490
3304
|
break;
|
|
3491
3305
|
}
|
|
3492
3306
|
return _context20.abrupt("return", []);
|
|
3493
|
-
case
|
|
3494
|
-
_context20.prev =
|
|
3495
|
-
|
|
3496
|
-
rawReadStartedAt = performance.now();
|
|
3497
|
-
_context20.next = 8;
|
|
3307
|
+
case 2:
|
|
3308
|
+
_context20.prev = 2;
|
|
3309
|
+
_context20.next = 5;
|
|
3498
3310
|
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
3499
|
-
case
|
|
3311
|
+
case 5:
|
|
3500
3312
|
orders = _context20.sent;
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
(_options$onTiming = options.onTiming) === null || _options$onTiming === void 0 || _options$onTiming.call(options, {
|
|
3508
|
-
sqliteRawReadMs: sqliteRawReadMs,
|
|
3509
|
-
sqliteNormalizeMs: sqliteNormalizeMs,
|
|
3510
|
-
sqliteLoadTotalMs: +(performance.now() - loadStartedAt).toFixed(2)
|
|
3511
|
-
});
|
|
3512
|
-
return _context20.abrupt("return", normalizedOrders);
|
|
3513
|
-
case 17:
|
|
3514
|
-
_context20.prev = 17;
|
|
3515
|
-
_context20.t0 = _context20["catch"](3);
|
|
3516
|
-
if (!options.throwOnError) {
|
|
3517
|
-
_context20.next = 21;
|
|
3518
|
-
break;
|
|
3519
|
-
}
|
|
3520
|
-
throw _context20.t0;
|
|
3521
|
-
case 21:
|
|
3313
|
+
return _context20.abrupt("return", (orders || []).map(function (order) {
|
|
3314
|
+
return _this20.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
|
|
3315
|
+
}));
|
|
3316
|
+
case 9:
|
|
3317
|
+
_context20.prev = 9;
|
|
3318
|
+
_context20.t0 = _context20["catch"](2);
|
|
3522
3319
|
return _context20.abrupt("return", []);
|
|
3523
|
-
case
|
|
3320
|
+
case 12:
|
|
3524
3321
|
case "end":
|
|
3525
3322
|
return _context20.stop();
|
|
3526
3323
|
}
|
|
3527
|
-
}, _callee20, this, [[
|
|
3324
|
+
}, _callee20, this, [[2, 9]]);
|
|
3528
3325
|
}));
|
|
3529
3326
|
function loadOrdersFromSQLite() {
|
|
3530
3327
|
return _loadOrdersFromSQLite.apply(this, arguments);
|
|
@@ -3574,9 +3371,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3574
3371
|
}, {
|
|
3575
3372
|
key: "mergeRemoteSnapshotWithPendingOrders",
|
|
3576
3373
|
value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
|
|
3577
|
-
var
|
|
3374
|
+
var _this21 = this;
|
|
3578
3375
|
var merged = remoteOrders.map(function (order) {
|
|
3579
|
-
return
|
|
3376
|
+
return _this21.normalizeRemoteSyncedOrder(order);
|
|
3580
3377
|
});
|
|
3581
3378
|
var _iterator31 = _createForOfIteratorHelper(existingOrders),
|
|
3582
3379
|
_step31;
|
|
@@ -3650,7 +3447,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3650
3447
|
key: "patchOrdersInSQLite",
|
|
3651
3448
|
value: (function () {
|
|
3652
3449
|
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(orders, source) {
|
|
3653
|
-
var
|
|
3450
|
+
var _this22 = this;
|
|
3654
3451
|
var mergeActions,
|
|
3655
3452
|
options,
|
|
3656
3453
|
forceWriteStorageKeys,
|
|
@@ -3694,13 +3491,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3694
3491
|
return migration.to;
|
|
3695
3492
|
}));
|
|
3696
3493
|
ordersSnapshot = cloneDeep(orders).map(function (order) {
|
|
3697
|
-
return
|
|
3494
|
+
return _this22.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
|
|
3698
3495
|
}).map(function (order) {
|
|
3699
|
-
var storageKey =
|
|
3496
|
+
var storageKey = _this22.getOrderStorageKey(order);
|
|
3700
3497
|
if (!storageKey || !migrationTargetStorageKeys.has(storageKey)) return order;
|
|
3701
3498
|
return _objectSpread(_objectSpread({}, order), {}, _defineProperty({}, ORDER_STORAGE_KEY_FIELD, storageKey));
|
|
3702
3499
|
}).filter(function (order) {
|
|
3703
|
-
return
|
|
3500
|
+
return _this22.getOrderStorageKey(order);
|
|
3704
3501
|
});
|
|
3705
3502
|
if (!(ordersSnapshot.length === 0)) {
|
|
3706
3503
|
_context23.next = 13;
|
|
@@ -3723,7 +3520,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3723
3520
|
return _context23.abrupt("return");
|
|
3724
3521
|
case 19:
|
|
3725
3522
|
writtenStorageKeys = new Set(compactedToWrite.map(function (order) {
|
|
3726
|
-
return
|
|
3523
|
+
return _this22.getOrderStorageKey(order);
|
|
3727
3524
|
}).filter(Boolean));
|
|
3728
3525
|
storageKeyMigrations = new Map();
|
|
3729
3526
|
_iterator32 = _createForOfIteratorHelper(options.storageKeyMigrations || []);
|
|
@@ -3771,34 +3568,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3771
3568
|
while (1) switch (_context22.prev = _context22.next) {
|
|
3772
3569
|
case 0:
|
|
3773
3570
|
writeMethod = 'none';
|
|
3774
|
-
|
|
3571
|
+
_this22.logInfo('patchOrdersInSQLite-开始', {
|
|
3775
3572
|
source: source,
|
|
3776
3573
|
count: compactedToWrite.length,
|
|
3777
3574
|
dedupedCount: skipped.length
|
|
3778
3575
|
});
|
|
3779
|
-
if (!(typeof
|
|
3576
|
+
if (!(typeof _this22.dbManager.bulkUpdate === 'function')) {
|
|
3780
3577
|
_context22.next = 8;
|
|
3781
3578
|
break;
|
|
3782
3579
|
}
|
|
3783
3580
|
writeMethod = 'bulkUpdate';
|
|
3784
3581
|
_context22.next = 6;
|
|
3785
|
-
return
|
|
3582
|
+
return _this22.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
|
|
3786
3583
|
case 6:
|
|
3787
3584
|
_context22.next = 37;
|
|
3788
3585
|
break;
|
|
3789
3586
|
case 8:
|
|
3790
|
-
if (!(typeof
|
|
3587
|
+
if (!(typeof _this22.dbManager.bulkAdd === 'function')) {
|
|
3791
3588
|
_context22.next = 14;
|
|
3792
3589
|
break;
|
|
3793
3590
|
}
|
|
3794
3591
|
writeMethod = 'bulkAdd';
|
|
3795
3592
|
_context22.next = 12;
|
|
3796
|
-
return
|
|
3593
|
+
return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
|
|
3797
3594
|
case 12:
|
|
3798
3595
|
_context22.next = 37;
|
|
3799
3596
|
break;
|
|
3800
3597
|
case 14:
|
|
3801
|
-
if (!(typeof
|
|
3598
|
+
if (!(typeof _this22.dbManager.update === 'function')) {
|
|
3802
3599
|
_context22.next = 35;
|
|
3803
3600
|
break;
|
|
3804
3601
|
}
|
|
@@ -3813,7 +3610,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3813
3610
|
}
|
|
3814
3611
|
order = _step33.value;
|
|
3815
3612
|
_context22.next = 23;
|
|
3816
|
-
return
|
|
3613
|
+
return _this22.dbManager.update(INDEXDB_STORE_NAME, order);
|
|
3817
3614
|
case 23:
|
|
3818
3615
|
_context22.next = 19;
|
|
3819
3616
|
break;
|
|
@@ -3838,7 +3635,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3838
3635
|
}
|
|
3839
3636
|
throw new Error('订单 SQLite 数据库不支持写入');
|
|
3840
3637
|
case 37:
|
|
3841
|
-
|
|
3638
|
+
_this22.recordRecentSqliteWrite(source, compactedToWrite);
|
|
3842
3639
|
if (!(writeMethod !== 'none')) {
|
|
3843
3640
|
_context22.next = 84;
|
|
3844
3641
|
break;
|
|
@@ -3854,9 +3651,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3854
3651
|
migration = _step34.value;
|
|
3855
3652
|
_context22.prev = 44;
|
|
3856
3653
|
_context22.next = 47;
|
|
3857
|
-
return
|
|
3654
|
+
return _this22.dbManager.delete(INDEXDB_STORE_NAME, migration.from);
|
|
3858
3655
|
case 47:
|
|
3859
|
-
|
|
3656
|
+
_this22.recentSqliteWriteByStorageKey.delete(migration.from);
|
|
3860
3657
|
_iterator35 = _createForOfIteratorHelper(orders);
|
|
3861
3658
|
_context22.prev = 49;
|
|
3862
3659
|
_iterator35.s();
|
|
@@ -3866,7 +3663,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3866
3663
|
break;
|
|
3867
3664
|
}
|
|
3868
3665
|
_order = _step35.value;
|
|
3869
|
-
if (!(
|
|
3666
|
+
if (!(_this22.getOrderStorageKey(_order) !== migration.to)) {
|
|
3870
3667
|
_context22.next = 55;
|
|
3871
3668
|
break;
|
|
3872
3669
|
}
|
|
@@ -3900,7 +3697,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3900
3697
|
case 71:
|
|
3901
3698
|
_context22.prev = 71;
|
|
3902
3699
|
_context22.t2 = _context22["catch"](44);
|
|
3903
|
-
|
|
3700
|
+
_this22.logError('删除订单旧 SQLite storage key 失败', {
|
|
3904
3701
|
source: source,
|
|
3905
3702
|
order_id: migration.orderId,
|
|
3906
3703
|
oldStorageKey: migration.from,
|
|
@@ -3922,7 +3719,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3922
3719
|
_iterator34.f();
|
|
3923
3720
|
return _context22.finish(81);
|
|
3924
3721
|
case 84:
|
|
3925
|
-
|
|
3722
|
+
_this22.logInfo('patchOrdersInSQLite-完成', {
|
|
3926
3723
|
source: source,
|
|
3927
3724
|
count: compactedToWrite.length,
|
|
3928
3725
|
writeMethod: writeMethod,
|
|
@@ -3971,7 +3768,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3971
3768
|
key: "updateOrderInSQLite",
|
|
3972
3769
|
value: (function () {
|
|
3973
3770
|
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order, source) {
|
|
3974
|
-
var
|
|
3771
|
+
var _this23 = this;
|
|
3975
3772
|
var options,
|
|
3976
3773
|
orderSnapshot,
|
|
3977
3774
|
_orderSnapshot$order_3,
|
|
@@ -4014,40 +3811,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4014
3811
|
while (1) switch (_context24.prev = _context24.next) {
|
|
4015
3812
|
case 0:
|
|
4016
3813
|
writeMethod = 'none';
|
|
4017
|
-
|
|
3814
|
+
_this23.logInfo('updateOrderInSQLite-开始', {
|
|
4018
3815
|
source: source,
|
|
4019
3816
|
orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
|
|
4020
|
-
storageKey:
|
|
3817
|
+
storageKey: _this23.getOrderStorageKey(orderSnapshot)
|
|
4021
3818
|
});
|
|
4022
|
-
if (!(typeof
|
|
3819
|
+
if (!(typeof _this23.dbManager.update === 'function')) {
|
|
4023
3820
|
_context24.next = 8;
|
|
4024
3821
|
break;
|
|
4025
3822
|
}
|
|
4026
3823
|
writeMethod = 'update';
|
|
4027
3824
|
_context24.next = 6;
|
|
4028
|
-
return
|
|
3825
|
+
return _this23.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
|
|
4029
3826
|
case 6:
|
|
4030
3827
|
_context24.next = 22;
|
|
4031
3828
|
break;
|
|
4032
3829
|
case 8:
|
|
4033
|
-
if (!(typeof
|
|
3830
|
+
if (!(typeof _this23.dbManager.bulkUpdate === 'function')) {
|
|
4034
3831
|
_context24.next = 14;
|
|
4035
3832
|
break;
|
|
4036
3833
|
}
|
|
4037
3834
|
writeMethod = 'bulkUpdate';
|
|
4038
3835
|
_context24.next = 12;
|
|
4039
|
-
return
|
|
3836
|
+
return _this23.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
4040
3837
|
case 12:
|
|
4041
3838
|
_context24.next = 22;
|
|
4042
3839
|
break;
|
|
4043
3840
|
case 14:
|
|
4044
|
-
if (!(typeof
|
|
3841
|
+
if (!(typeof _this23.dbManager.bulkAdd === 'function')) {
|
|
4045
3842
|
_context24.next = 20;
|
|
4046
3843
|
break;
|
|
4047
3844
|
}
|
|
4048
3845
|
writeMethod = 'bulkAdd';
|
|
4049
3846
|
_context24.next = 18;
|
|
4050
|
-
return
|
|
3847
|
+
return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
4051
3848
|
case 18:
|
|
4052
3849
|
_context24.next = 22;
|
|
4053
3850
|
break;
|
|
@@ -4058,8 +3855,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4058
3855
|
}
|
|
4059
3856
|
throw new Error('订单 SQLite 数据库不支持写入');
|
|
4060
3857
|
case 22:
|
|
4061
|
-
|
|
4062
|
-
|
|
3858
|
+
_this23.recordRecentSqliteWrite(source, [orderSnapshot]);
|
|
3859
|
+
_this23.logInfo('updateOrderInSQLite-完成', {
|
|
4063
3860
|
source: source,
|
|
4064
3861
|
orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
|
|
4065
3862
|
writeMethod: writeMethod
|
|
@@ -4101,18 +3898,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4101
3898
|
* 用于 SSE 全量拉取与营业日窗口裁剪。
|
|
4102
3899
|
*
|
|
4103
3900
|
* @example
|
|
4104
|
-
*
|
|
3901
|
+
* await this.replaceOrdersSnapshotInSQLite(orderList)
|
|
4105
3902
|
*/
|
|
4106
3903
|
)
|
|
4107
3904
|
}, {
|
|
4108
3905
|
key: "replaceOrdersSnapshotInSQLite",
|
|
4109
3906
|
value: (function () {
|
|
4110
3907
|
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orderList, source) {
|
|
4111
|
-
var
|
|
3908
|
+
var _this24 = this;
|
|
4112
3909
|
var protectedOrdersBeforeRemoteFetch,
|
|
4113
3910
|
remoteSnapshot,
|
|
4114
3911
|
mergedSnapshot,
|
|
4115
|
-
persisted,
|
|
4116
3912
|
_args27 = arguments;
|
|
4117
3913
|
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
4118
3914
|
while (1) switch (_context27.prev = _context27.next) {
|
|
@@ -4122,33 +3918,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4122
3918
|
_context27.next = 3;
|
|
4123
3919
|
break;
|
|
4124
3920
|
}
|
|
4125
|
-
return _context27.abrupt("return", {
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
}), "".concat(source, ".snapshotNoDb")).list,
|
|
4129
|
-
persisted: false
|
|
4130
|
-
});
|
|
3921
|
+
return _context27.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
|
|
3922
|
+
return _this24.normalizeRemoteSyncedOrder(order);
|
|
3923
|
+
}), "".concat(source, ".snapshotNoDb")).list);
|
|
4131
3924
|
case 3:
|
|
4132
3925
|
remoteSnapshot = cloneDeep(orderList).map(function (order) {
|
|
4133
|
-
return
|
|
3926
|
+
return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
|
|
4134
3927
|
});
|
|
4135
3928
|
mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
|
|
4136
|
-
return
|
|
3929
|
+
return _this24.normalizeRemoteSyncedOrder(order);
|
|
4137
3930
|
}), "".concat(source, ".remoteSnapshot")).list;
|
|
4138
|
-
|
|
4139
|
-
_context27.
|
|
4140
|
-
_context27.next = 9;
|
|
3931
|
+
_context27.prev = 5;
|
|
3932
|
+
_context27.next = 8;
|
|
4141
3933
|
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
|
|
4142
3934
|
var existingOrders, protectedLocalOrders, _iterator36, _step36, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
|
|
4143
3935
|
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
4144
3936
|
while (1) switch (_context26.prev = _context26.next) {
|
|
4145
3937
|
case 0:
|
|
4146
|
-
if (!(typeof
|
|
3938
|
+
if (!(typeof _this24.dbManager.getAll === 'function')) {
|
|
4147
3939
|
_context26.next = 6;
|
|
4148
3940
|
break;
|
|
4149
3941
|
}
|
|
4150
3942
|
_context26.next = 3;
|
|
4151
|
-
return
|
|
3943
|
+
return _this24.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
4152
3944
|
case 3:
|
|
4153
3945
|
_context26.t0 = _context26.sent;
|
|
4154
3946
|
_context26.next = 7;
|
|
@@ -4158,9 +3950,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4158
3950
|
case 7:
|
|
4159
3951
|
existingOrders = _context26.t0;
|
|
4160
3952
|
protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
|
|
4161
|
-
return
|
|
3953
|
+
return _this24.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
|
|
4162
3954
|
}).filter(function (order) {
|
|
4163
|
-
return
|
|
3955
|
+
return _this24.shouldProtectLocalOrderFromRemoteSnapshot(order);
|
|
4164
3956
|
});
|
|
4165
3957
|
_iterator36 = _createForOfIteratorHelper(existingOrders || []);
|
|
4166
3958
|
_context26.prev = 10;
|
|
@@ -4171,9 +3963,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4171
3963
|
break;
|
|
4172
3964
|
}
|
|
4173
3965
|
rawCurrentOrder = _step36.value;
|
|
4174
|
-
currentOrder =
|
|
4175
|
-
protectedIndex =
|
|
4176
|
-
currentNeedsProtection =
|
|
3966
|
+
currentOrder = _this24.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
|
|
3967
|
+
protectedIndex = _this24.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
|
|
3968
|
+
currentNeedsProtection = _this24.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
|
|
4177
3969
|
if (!(protectedIndex >= 0)) {
|
|
4178
3970
|
_context26.next = 20;
|
|
4179
3971
|
break;
|
|
@@ -4201,9 +3993,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4201
3993
|
_iterator36.f();
|
|
4202
3994
|
return _context26.finish(28);
|
|
4203
3995
|
case 31:
|
|
4204
|
-
orderListSnapshot =
|
|
4205
|
-
mergedSnapshot =
|
|
4206
|
-
|
|
3996
|
+
orderListSnapshot = _this24.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
|
|
3997
|
+
mergedSnapshot = _this24.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
|
|
3998
|
+
_this24.logInfo('replaceOrdersSnapshotInSQLite-开始', {
|
|
4207
3999
|
source: source,
|
|
4208
4000
|
count: mergedSnapshot.length,
|
|
4209
4001
|
remoteCount: remoteSnapshot.length,
|
|
@@ -4211,10 +4003,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4211
4003
|
protectedLocalOrderCount: protectedLocalOrders.length,
|
|
4212
4004
|
preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
|
|
4213
4005
|
protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
|
|
4214
|
-
return count +
|
|
4006
|
+
return count + _this24.getIdentifiedPendingPayments(order).length;
|
|
4215
4007
|
}, 0),
|
|
4216
4008
|
protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
|
|
4217
|
-
return
|
|
4009
|
+
return _this24.getIdentifiedPendingPayments(order).map(function (payment) {
|
|
4218
4010
|
var _order$order_id5, _external_sale_number5;
|
|
4219
4011
|
return {
|
|
4220
4012
|
order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
|
|
@@ -4225,9 +4017,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4225
4017
|
})
|
|
4226
4018
|
});
|
|
4227
4019
|
_context26.next = 36;
|
|
4228
|
-
return
|
|
4020
|
+
return _this24.dbManager.clear(INDEXDB_STORE_NAME);
|
|
4229
4021
|
case 36:
|
|
4230
|
-
|
|
4022
|
+
_this24.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
|
|
4231
4023
|
count: mergedSnapshot.length
|
|
4232
4024
|
});
|
|
4233
4025
|
if (!(mergedSnapshot.length === 0)) {
|
|
@@ -4237,10 +4029,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4237
4029
|
return _context26.abrupt("return");
|
|
4238
4030
|
case 39:
|
|
4239
4031
|
_context26.next = 41;
|
|
4240
|
-
return
|
|
4032
|
+
return _this24.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
|
|
4241
4033
|
case 41:
|
|
4242
|
-
|
|
4243
|
-
|
|
4034
|
+
_this24.recordRecentSqliteWrite(source, mergedSnapshot);
|
|
4035
|
+
_this24.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
|
|
4244
4036
|
source: source,
|
|
4245
4037
|
count: mergedSnapshot.length
|
|
4246
4038
|
});
|
|
@@ -4250,27 +4042,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4250
4042
|
}
|
|
4251
4043
|
}, _callee26, null, [[10, 25, 28, 31]]);
|
|
4252
4044
|
})));
|
|
4253
|
-
case
|
|
4254
|
-
|
|
4255
|
-
_context27.next = 15;
|
|
4045
|
+
case 8:
|
|
4046
|
+
_context27.next = 13;
|
|
4256
4047
|
break;
|
|
4257
|
-
case
|
|
4258
|
-
_context27.prev =
|
|
4259
|
-
_context27.t0 = _context27["catch"](
|
|
4048
|
+
case 10:
|
|
4049
|
+
_context27.prev = 10;
|
|
4050
|
+
_context27.t0 = _context27["catch"](5);
|
|
4260
4051
|
this.logError('全量保存订单到 SQLite 失败', {
|
|
4261
4052
|
error: _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0),
|
|
4262
4053
|
orderList: remoteSnapshot.length
|
|
4263
4054
|
});
|
|
4264
|
-
case
|
|
4265
|
-
return _context27.abrupt("return",
|
|
4266
|
-
|
|
4267
|
-
persisted: persisted
|
|
4268
|
-
});
|
|
4269
|
-
case 16:
|
|
4055
|
+
case 13:
|
|
4056
|
+
return _context27.abrupt("return", mergedSnapshot);
|
|
4057
|
+
case 14:
|
|
4270
4058
|
case "end":
|
|
4271
4059
|
return _context27.stop();
|
|
4272
4060
|
}
|
|
4273
|
-
}, _callee27, this, [[
|
|
4061
|
+
}, _callee27, this, [[5, 10]]);
|
|
4274
4062
|
}));
|
|
4275
4063
|
function replaceOrdersSnapshotInSQLite(_x20, _x21) {
|
|
4276
4064
|
return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
|
|
@@ -4288,7 +4076,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4288
4076
|
key: "clear",
|
|
4289
4077
|
value: (function () {
|
|
4290
4078
|
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
|
|
4291
|
-
var
|
|
4079
|
+
var _this25 = this;
|
|
4292
4080
|
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
4293
4081
|
while (1) switch (_context29.prev = _context29.next) {
|
|
4294
4082
|
case 0:
|
|
@@ -4304,7 +4092,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4304
4092
|
while (1) switch (_context28.prev = _context28.next) {
|
|
4305
4093
|
case 0:
|
|
4306
4094
|
_context28.next = 2;
|
|
4307
|
-
return
|
|
4095
|
+
return _this25.dbManager.clear(INDEXDB_STORE_NAME);
|
|
4308
4096
|
case 2:
|
|
4309
4097
|
case "end":
|
|
4310
4098
|
return _context28.stop();
|
|
@@ -4312,7 +4100,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4312
4100
|
}, _callee28);
|
|
4313
4101
|
})));
|
|
4314
4102
|
case 5:
|
|
4315
|
-
this.
|
|
4103
|
+
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
|
|
4316
4104
|
this.emitOrdersChanged([], 'clear');
|
|
4317
4105
|
case 7:
|
|
4318
4106
|
case "end":
|