@pisell/pisellos 2.2.256 → 2.2.258
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/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +17 -13
- package/dist/modules/Order/index.d.ts +29 -1
- package/dist/modules/Order/index.js +508 -241
- package/dist/modules/Order/types.d.ts +20 -2
- package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
- package/dist/modules/Order/utils.d.ts +4 -0
- package/dist/modules/Order/utils.js +114 -28
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Product/types.d.ts +6 -0
- package/dist/modules/Rules/index.d.ts +3 -3
- package/dist/modules/Rules/index.js +8 -3
- package/dist/modules/Rules/types.d.ts +2 -1
- package/dist/server/index.d.ts +12 -2
- package/dist/server/index.js +1227 -923
- package/dist/server/modules/order/index.d.ts +22 -3
- package/dist/server/modules/order/index.js +397 -314
- package/dist/solution/BaseSales/index.d.ts +16 -2
- package/dist/solution/BaseSales/index.js +484 -314
- package/dist/solution/BaseSales/types.d.ts +1 -0
- package/dist/solution/BaseSales/types.js +2 -1
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +9 -1
- package/dist/solution/BookingTicket/index.js +162 -6
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -1
- package/lib/modules/Order/index.d.ts +29 -1
- package/lib/modules/Order/index.js +340 -57
- package/lib/modules/Order/types.d.ts +20 -2
- package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
- package/lib/modules/Order/utils.d.ts +4 -0
- package/lib/modules/Order/utils.js +84 -2
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/types.d.ts +6 -0
- package/lib/modules/Rules/index.d.ts +3 -3
- package/lib/modules/Rules/index.js +4 -3
- package/lib/modules/Rules/types.d.ts +2 -1
- package/lib/server/index.d.ts +12 -2
- package/lib/server/index.js +218 -12
- package/lib/server/modules/order/index.d.ts +22 -3
- package/lib/server/modules/order/index.js +102 -51
- package/lib/solution/BaseSales/index.d.ts +16 -2
- package/lib/solution/BaseSales/index.js +143 -31
- package/lib/solution/BaseSales/types.d.ts +1 -0
- package/lib/solution/BaseSales/types.js +2 -1
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -5
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +9 -1
- package/lib/solution/BookingTicket/index.js +112 -0
- package/package.json +1 -1
|
@@ -49,6 +49,13 @@ var ORDER_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
|
|
|
49
49
|
/** 视为「业务侧刚写入」的来源,pubsub 回声可跳过 SQLite */
|
|
50
50
|
var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'overwriteExistingOrder', 'markOrderSyncedByExternalSaleNumber']);
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* 合并热路径全表去重自检开关:默认关闭。
|
|
54
|
+
* 开启后每次合并会额外对整张 store 做一次 O(n^2) 重复检测并告警,
|
|
55
|
+
* 仅用于排查增量身份索引是否遗漏了重复订单,不应在生产常开。
|
|
56
|
+
*/
|
|
57
|
+
var ORDER_MERGE_SELF_CHECK = false;
|
|
58
|
+
|
|
52
59
|
/**
|
|
53
60
|
* Order 模块 - 基础框架
|
|
54
61
|
*/
|
|
@@ -68,8 +75,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
68
75
|
_defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
|
|
69
76
|
_defineProperty(_assertThisInitialized(_this), "isProcessingSyncBatch", false);
|
|
70
77
|
_defineProperty(_assertThisInitialized(_this), "isIdlePhase", true);
|
|
71
|
-
// Map<resource_id, OrderId[]> 资源到订单的倒排索引
|
|
72
|
-
_defineProperty(_assertThisInitialized(_this), "resourceIdIndex", new Map());
|
|
73
78
|
_defineProperty(_assertThisInitialized(_this), "logger", void 0);
|
|
74
79
|
// LoggerManager 实例
|
|
75
80
|
_defineProperty(_assertThisInitialized(_this), "storage", void 0);
|
|
@@ -774,17 +779,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
774
779
|
}
|
|
775
780
|
return silentRefresh;
|
|
776
781
|
}())
|
|
777
|
-
}, {
|
|
778
|
-
key: "getOrdersByResourceId",
|
|
779
|
-
value: function getOrdersByResourceId(resourceId) {
|
|
780
|
-
var _this8 = this;
|
|
781
|
-
var ids = this.resourceIdIndex.get(String(resourceId)) || [];
|
|
782
|
-
return ids.map(function (id) {
|
|
783
|
-
return _this8.store.map.get(id);
|
|
784
|
-
}).filter(function (order) {
|
|
785
|
-
return !!order;
|
|
786
|
-
});
|
|
787
|
-
}
|
|
788
782
|
}, {
|
|
789
783
|
key: "normalizeOrderForMemoryList",
|
|
790
784
|
value: function normalizeOrderForMemoryList(order) {
|
|
@@ -808,7 +802,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
808
802
|
key: "overwriteExistingOrder",
|
|
809
803
|
value: (function () {
|
|
810
804
|
var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(fresh) {
|
|
811
|
-
var
|
|
805
|
+
var _this8 = this;
|
|
812
806
|
var orderId, key;
|
|
813
807
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
814
808
|
while (1) switch (_context8.prev = _context8.next) {
|
|
@@ -842,7 +836,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
842
836
|
this.store.list = this.store.list.map(function (order) {
|
|
843
837
|
var id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
844
838
|
if (id === undefined || id === null) return order;
|
|
845
|
-
return
|
|
839
|
+
return _this8.getIdKey(id) === key ? fresh : order;
|
|
846
840
|
});
|
|
847
841
|
this.syncOrdersMap();
|
|
848
842
|
_context8.next = 13;
|
|
@@ -908,7 +902,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
908
902
|
key: "markOrderSyncedByExternalSaleNumber",
|
|
909
903
|
value: function () {
|
|
910
904
|
var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
911
|
-
var
|
|
905
|
+
var _this9 = this,
|
|
912
906
|
_existing$external_sa,
|
|
913
907
|
_nextOrder$order_id;
|
|
914
908
|
var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
|
|
@@ -929,7 +923,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
929
923
|
targetIndex = this.store.list.findIndex(function (order) {
|
|
930
924
|
var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
|
|
931
925
|
if (value === undefined || value === null || value === '') return false;
|
|
932
|
-
return
|
|
926
|
+
return _this9.getIdKey(value) === key;
|
|
933
927
|
});
|
|
934
928
|
if (!(targetIndex < 0)) {
|
|
935
929
|
_context10.next = 9;
|
|
@@ -986,7 +980,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
986
980
|
key: "upsertPendingSyncOrders",
|
|
987
981
|
value: (function () {
|
|
988
982
|
var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(pendingOrders) {
|
|
989
|
-
var pendingMap, memoryPendingMap, _iterator4, _step4, order, storageKey, patchedOrders, mergeActions, updatedList,
|
|
983
|
+
var pendingMap, memoryPendingMap, _iterator4, _step4, order, storageKey, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, _iterator5, _step5, key, _iterator6, _step6, _step6$value, _storageKey, pendingOrder, matchIndex, mergedOrder, insertIndex;
|
|
990
984
|
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
991
985
|
while (1) switch (_context11.prev = _context11.next) {
|
|
992
986
|
case 0:
|
|
@@ -1046,72 +1040,82 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1046
1040
|
});
|
|
1047
1041
|
patchedOrders = _toConsumableArray(pendingMap.values());
|
|
1048
1042
|
mergeActions = {};
|
|
1049
|
-
updatedList = _toConsumableArray(this.store.list);
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1043
|
+
updatedList = _toConsumableArray(this.store.list); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
|
|
1044
|
+
// 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
|
|
1045
|
+
identityKeyToIndex = new Map();
|
|
1046
|
+
for (index = 0; index < updatedList.length; index += 1) {
|
|
1047
|
+
_iterator5 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
|
|
1048
|
+
try {
|
|
1049
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
1050
|
+
key = _step5.value;
|
|
1051
|
+
// 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
|
|
1052
|
+
if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
|
|
1053
|
+
}
|
|
1054
|
+
} catch (err) {
|
|
1055
|
+
_iterator5.e(err);
|
|
1056
|
+
} finally {
|
|
1057
|
+
_iterator5.f();
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
_iterator6 = _createForOfIteratorHelper(memoryPendingMap.entries());
|
|
1061
|
+
_context11.prev = 35;
|
|
1062
|
+
_iterator6.s();
|
|
1063
|
+
case 37:
|
|
1064
|
+
if ((_step6 = _iterator6.n()).done) {
|
|
1065
|
+
_context11.next = 52;
|
|
1056
1066
|
break;
|
|
1057
1067
|
}
|
|
1058
|
-
|
|
1059
|
-
matchIndex = this.
|
|
1060
|
-
if (!(matchIndex
|
|
1061
|
-
_context11.next =
|
|
1068
|
+
_step6$value = _slicedToArray(_step6.value, 2), _storageKey = _step6$value[0], pendingOrder = _step6$value[1];
|
|
1069
|
+
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(pendingOrder));
|
|
1070
|
+
if (!(matchIndex >= 0)) {
|
|
1071
|
+
_context11.next = 46;
|
|
1062
1072
|
break;
|
|
1063
1073
|
}
|
|
1064
|
-
|
|
1065
|
-
case 40:
|
|
1066
|
-
updatedList[matchIndex] = this.mergeOrderRecords(updatedList[matchIndex], pendingOrder, {
|
|
1074
|
+
mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], pendingOrder, {
|
|
1067
1075
|
preferIncomingProducts: true
|
|
1068
1076
|
});
|
|
1069
|
-
|
|
1070
|
-
|
|
1077
|
+
updatedList[matchIndex] = mergedOrder;
|
|
1078
|
+
// 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
|
|
1079
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex);
|
|
1071
1080
|
mergeActions[_storageKey] = 'update';
|
|
1072
|
-
|
|
1073
|
-
_context11.next = 35;
|
|
1074
|
-
break;
|
|
1081
|
+
return _context11.abrupt("continue", 50);
|
|
1075
1082
|
case 46:
|
|
1076
|
-
|
|
1083
|
+
insertIndex = updatedList.length;
|
|
1084
|
+
updatedList.push(pendingOrder);
|
|
1085
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, pendingOrder, insertIndex);
|
|
1086
|
+
mergeActions[_storageKey] = 'insert';
|
|
1087
|
+
case 50:
|
|
1088
|
+
_context11.next = 37;
|
|
1089
|
+
break;
|
|
1090
|
+
case 52:
|
|
1091
|
+
_context11.next = 57;
|
|
1077
1092
|
break;
|
|
1078
|
-
case 48:
|
|
1079
|
-
_context11.prev = 48;
|
|
1080
|
-
_context11.t1 = _context11["catch"](33);
|
|
1081
|
-
_iterator5.e(_context11.t1);
|
|
1082
|
-
case 51:
|
|
1083
|
-
_context11.prev = 51;
|
|
1084
|
-
_iterator5.f();
|
|
1085
|
-
return _context11.finish(51);
|
|
1086
1093
|
case 54:
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
_iterator6.f();
|
|
1098
|
-
}
|
|
1099
|
-
this.store.list = this.compactOrderListByIdentity(updatedList, 'upsertPendingSyncOrders.store').list;
|
|
1094
|
+
_context11.prev = 54;
|
|
1095
|
+
_context11.t1 = _context11["catch"](35);
|
|
1096
|
+
_iterator6.e(_context11.t1);
|
|
1097
|
+
case 57:
|
|
1098
|
+
_context11.prev = 57;
|
|
1099
|
+
_iterator6.f();
|
|
1100
|
+
return _context11.finish(57);
|
|
1101
|
+
case 60:
|
|
1102
|
+
// 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
|
|
1103
|
+
this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
|
|
1100
1104
|
this.syncOrdersMap();
|
|
1101
|
-
_context11.next =
|
|
1105
|
+
_context11.next = 64;
|
|
1102
1106
|
return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions);
|
|
1103
|
-
case
|
|
1107
|
+
case 64:
|
|
1104
1108
|
this.logInfo('upsertPendingSyncOrders-结束', {
|
|
1105
1109
|
count: patchedOrders.length,
|
|
1106
1110
|
storeOrderCountAfter: this.store.list.length
|
|
1107
1111
|
});
|
|
1108
|
-
_context11.next =
|
|
1112
|
+
_context11.next = 67;
|
|
1109
1113
|
return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
|
|
1110
|
-
case
|
|
1114
|
+
case 67:
|
|
1111
1115
|
case "end":
|
|
1112
1116
|
return _context11.stop();
|
|
1113
1117
|
}
|
|
1114
|
-
}, _callee11, this, [[6, 19, 22, 25], [
|
|
1118
|
+
}, _callee11, this, [[6, 19, 22, 25], [35, 54, 57, 60]]);
|
|
1115
1119
|
}));
|
|
1116
1120
|
function upsertPendingSyncOrders(_x7) {
|
|
1117
1121
|
return _upsertPendingSyncOrders.apply(this, arguments);
|
|
@@ -1188,39 +1192,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1188
1192
|
}, {
|
|
1189
1193
|
key: "syncOrdersMap",
|
|
1190
1194
|
value: function syncOrdersMap() {
|
|
1191
|
-
var _this11 = this;
|
|
1192
1195
|
this.store.map.clear();
|
|
1193
|
-
this.resourceIdIndex.clear();
|
|
1194
1196
|
var _iterator7 = _createForOfIteratorHelper(this.store.list),
|
|
1195
1197
|
_step7;
|
|
1196
1198
|
try {
|
|
1197
|
-
var _loop = function _loop() {
|
|
1198
|
-
var order = _step7.value;
|
|
1199
|
-
var primaryIdentity = _this11.getOrderMapKey(order);
|
|
1200
|
-
if (!primaryIdentity) return 1; // continue
|
|
1201
|
-
_this11.store.map.set(primaryIdentity, order);
|
|
1202
|
-
var resourceIds = _this11.extractResourceIds(order);
|
|
1203
|
-
var _iterator8 = _createForOfIteratorHelper(resourceIds),
|
|
1204
|
-
_step8;
|
|
1205
|
-
try {
|
|
1206
|
-
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1207
|
-
var resourceId = _step8.value;
|
|
1208
|
-
var key = String(resourceId);
|
|
1209
|
-
var existing = _this11.resourceIdIndex.get(key) || [];
|
|
1210
|
-
if (existing.some(function (eid) {
|
|
1211
|
-
return _this11.getIdKey(eid) === primaryIdentity;
|
|
1212
|
-
})) continue;
|
|
1213
|
-
existing.push(primaryIdentity);
|
|
1214
|
-
_this11.resourceIdIndex.set(key, existing);
|
|
1215
|
-
}
|
|
1216
|
-
} catch (err) {
|
|
1217
|
-
_iterator8.e(err);
|
|
1218
|
-
} finally {
|
|
1219
|
-
_iterator8.f();
|
|
1220
|
-
}
|
|
1221
|
-
};
|
|
1222
1199
|
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1223
|
-
|
|
1200
|
+
var order = _step7.value;
|
|
1201
|
+
var primaryIdentity = this.getOrderMapKey(order);
|
|
1202
|
+
if (!primaryIdentity) continue;
|
|
1203
|
+
this.store.map.set(primaryIdentity, order);
|
|
1224
1204
|
}
|
|
1225
1205
|
} catch (err) {
|
|
1226
1206
|
_iterator7.e(err);
|
|
@@ -1249,7 +1229,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1249
1229
|
}, {
|
|
1250
1230
|
key: "getOrderIdentityEntries",
|
|
1251
1231
|
value: function getOrderIdentityEntries(order) {
|
|
1252
|
-
var
|
|
1232
|
+
var _this10 = this;
|
|
1253
1233
|
if (!order) return [];
|
|
1254
1234
|
var record = order;
|
|
1255
1235
|
var candidates = [{
|
|
@@ -1266,10 +1246,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1266
1246
|
value: record.shop_order_number
|
|
1267
1247
|
}];
|
|
1268
1248
|
var entries = [];
|
|
1269
|
-
var
|
|
1249
|
+
var _loop = function _loop() {
|
|
1270
1250
|
var candidate = _candidates[_i];
|
|
1271
|
-
if (
|
|
1272
|
-
var key =
|
|
1251
|
+
if (_this10.isBlankIdentityValue(candidate.value)) return 0; // continue
|
|
1252
|
+
var key = _this10.getIdKey(candidate.value);
|
|
1273
1253
|
if (entries.some(function (entry) {
|
|
1274
1254
|
return entry.field === candidate.field && entry.key === key;
|
|
1275
1255
|
})) return 0; // continue
|
|
@@ -1280,7 +1260,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1280
1260
|
},
|
|
1281
1261
|
_ret;
|
|
1282
1262
|
for (var _i = 0, _candidates = candidates; _i < _candidates.length; _i++) {
|
|
1283
|
-
_ret =
|
|
1263
|
+
_ret = _loop();
|
|
1284
1264
|
if (_ret === 0) continue;
|
|
1285
1265
|
}
|
|
1286
1266
|
return entries;
|
|
@@ -1289,39 +1269,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1289
1269
|
key: "getOrderIdentityKeys",
|
|
1290
1270
|
value: function getOrderIdentityKeys(order) {
|
|
1291
1271
|
var keys = [];
|
|
1292
|
-
var
|
|
1293
|
-
|
|
1272
|
+
var _iterator8 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
|
|
1273
|
+
_step8;
|
|
1294
1274
|
try {
|
|
1295
|
-
for (
|
|
1296
|
-
var entry =
|
|
1275
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1276
|
+
var entry = _step8.value;
|
|
1297
1277
|
if (!keys.includes(entry.key)) keys.push(entry.key);
|
|
1298
1278
|
}
|
|
1299
1279
|
} catch (err) {
|
|
1300
|
-
|
|
1280
|
+
_iterator8.e(err);
|
|
1301
1281
|
} finally {
|
|
1302
|
-
|
|
1282
|
+
_iterator8.f();
|
|
1303
1283
|
}
|
|
1304
1284
|
return keys;
|
|
1305
1285
|
}
|
|
1306
|
-
}, {
|
|
1307
|
-
key: "extractResourceIds",
|
|
1308
|
-
value: function extractResourceIds(order) {
|
|
1309
|
-
var ids = new Set();
|
|
1310
|
-
var visitResources = function visitResources(resources) {
|
|
1311
|
-
if (!Array.isArray(resources)) return;
|
|
1312
|
-
resources.forEach(function (resource) {
|
|
1313
|
-
var rid = resource === null || resource === void 0 ? void 0 : resource.relation_id;
|
|
1314
|
-
if (rid !== undefined && rid !== null && rid !== '') ids.add(String(rid));
|
|
1315
|
-
if (Array.isArray(resource === null || resource === void 0 ? void 0 : resource.children)) visitResources(resource.children);
|
|
1316
|
-
});
|
|
1317
|
-
};
|
|
1318
|
-
if (Array.isArray(order === null || order === void 0 ? void 0 : order.bookings)) {
|
|
1319
|
-
order.bookings.forEach(function (booking) {
|
|
1320
|
-
return visitResources((booking === null || booking === void 0 ? void 0 : booking.resources) || []);
|
|
1321
|
-
});
|
|
1322
|
-
}
|
|
1323
|
-
return _toConsumableArray(ids);
|
|
1324
|
-
}
|
|
1325
1286
|
}, {
|
|
1326
1287
|
key: "getOrderDateKey",
|
|
1327
1288
|
value: function getOrderDateKey(order) {
|
|
@@ -1355,7 +1316,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1355
1316
|
}, {
|
|
1356
1317
|
key: "setupOrderSync",
|
|
1357
1318
|
value: function setupOrderSync() {
|
|
1358
|
-
var
|
|
1319
|
+
var _this11 = this;
|
|
1359
1320
|
if (!this.orderDataSource) return;
|
|
1360
1321
|
this.orderDataSource.run({
|
|
1361
1322
|
pubsub: {
|
|
@@ -1363,22 +1324,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1363
1324
|
var _message$id, _message$order_id, _message$type;
|
|
1364
1325
|
console.log('orderDataSource', res);
|
|
1365
1326
|
var pubsubReceivedAt = Date.now();
|
|
1366
|
-
var message =
|
|
1327
|
+
var message = _this11.normalizeOrderSyncMessage(res);
|
|
1367
1328
|
if (!message) return;
|
|
1368
1329
|
message._pubsubReceivedAt = pubsubReceivedAt;
|
|
1369
|
-
|
|
1370
|
-
var throttleMs =
|
|
1371
|
-
var routeInfo =
|
|
1372
|
-
|
|
1330
|
+
_this11.pendingSyncMessages.push(message);
|
|
1331
|
+
var throttleMs = _this11.getOrderSyncThrottleMs();
|
|
1332
|
+
var routeInfo = _this11.resolveSyncMessageRoute(message);
|
|
1333
|
+
_this11.logInfo('orderSync-收到消息并入队', {
|
|
1373
1334
|
id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
|
|
1374
1335
|
order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
|
|
1375
1336
|
type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
|
|
1376
|
-
pendingCount:
|
|
1337
|
+
pendingCount: _this11.pendingSyncMessages.length,
|
|
1377
1338
|
throttleMs: throttleMs,
|
|
1378
1339
|
pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
|
|
1379
1340
|
fullMessage: JSON.stringify(message)
|
|
1380
1341
|
});
|
|
1381
|
-
|
|
1342
|
+
_this11.scheduleOrderSyncThrottle();
|
|
1382
1343
|
}
|
|
1383
1344
|
}
|
|
1384
1345
|
}).catch(function () {
|
|
@@ -1395,7 +1356,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1395
1356
|
}, {
|
|
1396
1357
|
key: "scheduleOrderSyncThrottle",
|
|
1397
1358
|
value: function scheduleOrderSyncThrottle() {
|
|
1398
|
-
var
|
|
1359
|
+
var _this12 = this;
|
|
1399
1360
|
if (this.isProcessingSyncBatch) return;
|
|
1400
1361
|
if (this.isIdlePhase) {
|
|
1401
1362
|
this.isIdlePhase = false;
|
|
@@ -1406,8 +1367,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1406
1367
|
if (this.syncTimer) return;
|
|
1407
1368
|
var throttleMs = this.getOrderSyncThrottleMs();
|
|
1408
1369
|
this.syncTimer = setTimeout(function () {
|
|
1409
|
-
|
|
1410
|
-
void
|
|
1370
|
+
_this12.syncTimer = undefined;
|
|
1371
|
+
void _this12.flushOrderSyncMessagesByThrottle();
|
|
1411
1372
|
}, throttleMs);
|
|
1412
1373
|
}
|
|
1413
1374
|
|
|
@@ -1475,7 +1436,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1475
1436
|
key: "processOrderSyncMessages",
|
|
1476
1437
|
value: (function () {
|
|
1477
1438
|
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
1478
|
-
var
|
|
1439
|
+
var _this13 = this;
|
|
1479
1440
|
var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
|
|
1480
1441
|
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1481
1442
|
while (1) switch (_context14.prev = _context14.next) {
|
|
@@ -1502,13 +1463,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1502
1463
|
upsertOrders = new Map();
|
|
1503
1464
|
refreshIds = [];
|
|
1504
1465
|
messages.forEach(function (msg, msgIndex) {
|
|
1505
|
-
var routeInfo =
|
|
1466
|
+
var routeInfo = _this13.resolveSyncMessageRoute(msg);
|
|
1506
1467
|
var hasBatchIds = routeInfo.hasBatchIds;
|
|
1507
1468
|
var singleId = routeInfo.singleId;
|
|
1508
1469
|
var hasSingleId = routeInfo.hasSingleId;
|
|
1509
|
-
var normalizedBody =
|
|
1470
|
+
var normalizedBody = _this13.normalizeOrderSyncPayload(msg.body || msg.data);
|
|
1510
1471
|
if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
|
|
1511
|
-
upsertOrders.set(
|
|
1472
|
+
upsertOrders.set(_this13.getIdKey(normalizedBody.order_id), normalizedBody);
|
|
1512
1473
|
return;
|
|
1513
1474
|
}
|
|
1514
1475
|
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));
|
|
@@ -1646,94 +1607,137 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1646
1607
|
key: "mergeOrdersToStore",
|
|
1647
1608
|
value: (function () {
|
|
1648
1609
|
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(freshOrders, source) {
|
|
1649
|
-
var normalizedFreshOrders,
|
|
1610
|
+
var storeOrderCountBefore, normalizedFreshOrders, _iterator9, _step9, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator10, _step10, key, _iterator11, _step11, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _ref2, _existingOrder$order_, _ref3, _external_sale_number, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, mergedOrder, insertIndex, insertCount, updateCount;
|
|
1650
1611
|
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1651
1612
|
while (1) switch (_context16.prev = _context16.next) {
|
|
1652
1613
|
case 0:
|
|
1614
|
+
storeOrderCountBefore = this.store.list.length;
|
|
1653
1615
|
this.logInfo('mergeOrdersToStore-开始', {
|
|
1654
1616
|
freshOrderCount: freshOrders.length,
|
|
1655
|
-
storeOrderCountBefore:
|
|
1617
|
+
storeOrderCountBefore: storeOrderCountBefore,
|
|
1656
1618
|
source: source
|
|
1657
1619
|
});
|
|
1658
1620
|
this.logDuplicateOrders("".concat(source, ".beforeMerge"), this.store.list);
|
|
1659
1621
|
normalizedFreshOrders = [];
|
|
1660
|
-
|
|
1661
|
-
_context16.prev =
|
|
1662
|
-
|
|
1663
|
-
case
|
|
1664
|
-
if ((
|
|
1665
|
-
_context16.next =
|
|
1622
|
+
_iterator9 = _createForOfIteratorHelper(freshOrders);
|
|
1623
|
+
_context16.prev = 5;
|
|
1624
|
+
_iterator9.s();
|
|
1625
|
+
case 7:
|
|
1626
|
+
if ((_step9 = _iterator9.n()).done) {
|
|
1627
|
+
_context16.next = 15;
|
|
1666
1628
|
break;
|
|
1667
1629
|
}
|
|
1668
|
-
order =
|
|
1630
|
+
order = _step9.value;
|
|
1669
1631
|
id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
1670
1632
|
if (!(id === undefined || id === null)) {
|
|
1671
|
-
_context16.next =
|
|
1633
|
+
_context16.next = 12;
|
|
1672
1634
|
break;
|
|
1673
1635
|
}
|
|
1674
|
-
return _context16.abrupt("continue",
|
|
1675
|
-
case 11:
|
|
1676
|
-
normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
|
|
1636
|
+
return _context16.abrupt("continue", 13);
|
|
1677
1637
|
case 12:
|
|
1678
|
-
|
|
1638
|
+
normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
|
|
1639
|
+
case 13:
|
|
1640
|
+
_context16.next = 7;
|
|
1679
1641
|
break;
|
|
1680
|
-
case
|
|
1681
|
-
_context16.next =
|
|
1642
|
+
case 15:
|
|
1643
|
+
_context16.next = 20;
|
|
1682
1644
|
break;
|
|
1683
|
-
case
|
|
1684
|
-
_context16.prev =
|
|
1685
|
-
_context16.t0 = _context16["catch"](
|
|
1686
|
-
|
|
1687
|
-
case
|
|
1688
|
-
_context16.prev =
|
|
1689
|
-
|
|
1690
|
-
return _context16.finish(
|
|
1691
|
-
case
|
|
1645
|
+
case 17:
|
|
1646
|
+
_context16.prev = 17;
|
|
1647
|
+
_context16.t0 = _context16["catch"](5);
|
|
1648
|
+
_iterator9.e(_context16.t0);
|
|
1649
|
+
case 20:
|
|
1650
|
+
_context16.prev = 20;
|
|
1651
|
+
_iterator9.f();
|
|
1652
|
+
return _context16.finish(20);
|
|
1653
|
+
case 23:
|
|
1654
|
+
// 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
|
|
1692
1655
|
uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
|
|
1693
1656
|
uniqueFreshCount = uniqueFreshOrders.length;
|
|
1694
1657
|
patchedOrders = [];
|
|
1695
1658
|
mergeActions = {};
|
|
1696
|
-
updatedList = _toConsumableArray(this.store.list);
|
|
1659
|
+
updatedList = _toConsumableArray(this.store.list); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
|
|
1660
|
+
// 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
|
|
1661
|
+
// 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
|
|
1662
|
+
identityKeyToIndex = new Map();
|
|
1663
|
+
for (index = 0; index < updatedList.length; index += 1) {
|
|
1664
|
+
identityKeys = this.getOrderIdentityMatchKeys(updatedList[index]);
|
|
1665
|
+
_iterator10 = _createForOfIteratorHelper(identityKeys);
|
|
1666
|
+
try {
|
|
1667
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
1668
|
+
key = _step10.value;
|
|
1669
|
+
// 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
|
|
1670
|
+
if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
|
|
1671
|
+
}
|
|
1672
|
+
} catch (err) {
|
|
1673
|
+
_iterator10.e(err);
|
|
1674
|
+
} finally {
|
|
1675
|
+
_iterator10.f();
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1697
1678
|
_iterator11 = _createForOfIteratorHelper(uniqueFreshOrders);
|
|
1698
|
-
_context16.prev =
|
|
1679
|
+
_context16.prev = 31;
|
|
1699
1680
|
_iterator11.s();
|
|
1700
|
-
case
|
|
1681
|
+
case 33:
|
|
1701
1682
|
if ((_step11 = _iterator11.n()).done) {
|
|
1702
|
-
_context16.next =
|
|
1683
|
+
_context16.next = 57;
|
|
1703
1684
|
break;
|
|
1704
1685
|
}
|
|
1705
1686
|
fresh = _step11.value;
|
|
1706
|
-
|
|
1687
|
+
freshIdentityKeys = this.getOrderIdentityMatchKeys(fresh);
|
|
1688
|
+
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys);
|
|
1707
1689
|
storageKey = this.getOrderStorageKey(fresh);
|
|
1708
1690
|
mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
|
|
1709
1691
|
if (!(matchIndex >= 0)) {
|
|
1710
|
-
_context16.next =
|
|
1692
|
+
_context16.next = 50;
|
|
1711
1693
|
break;
|
|
1712
1694
|
}
|
|
1713
|
-
|
|
1695
|
+
existingOrder = updatedList[matchIndex];
|
|
1696
|
+
if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
|
|
1697
|
+
_context16.next = 44;
|
|
1698
|
+
break;
|
|
1699
|
+
}
|
|
1700
|
+
this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
|
|
1701
|
+
source: source,
|
|
1702
|
+
order_id: (_ref2 = (_existingOrder$order_ = existingOrder.order_id) !== null && _existingOrder$order_ !== void 0 ? _existingOrder$order_ : fresh.order_id) !== null && _ref2 !== void 0 ? _ref2 : null,
|
|
1703
|
+
external_sale_number: (_ref3 = (_external_sale_number = existingOrder.external_sale_number) !== null && _external_sale_number !== void 0 ? _external_sale_number : fresh.external_sale_number) !== null && _ref3 !== void 0 ? _ref3 : null,
|
|
1704
|
+
local_payment_status: (_existingOrder$paymen = existingOrder.payment_status) !== null && _existingOrder$paymen !== void 0 ? _existingOrder$paymen : null,
|
|
1705
|
+
remote_payment_status: (_fresh$payment_status = fresh.payment_status) !== null && _fresh$payment_status !== void 0 ? _fresh$payment_status : null,
|
|
1706
|
+
local_need_sync: (_existingOrder$need_s = existingOrder.need_sync) !== null && _existingOrder$need_s !== void 0 ? _existingOrder$need_s : null,
|
|
1707
|
+
remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
|
|
1708
|
+
reason: 'protect_pending_sync_order_from_remote_echo'
|
|
1709
|
+
});
|
|
1710
|
+
return _context16.abrupt("continue", 55);
|
|
1711
|
+
case 44:
|
|
1712
|
+
mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
|
|
1714
1713
|
updatedList[matchIndex] = mergedOrder;
|
|
1714
|
+
// 合并后身份字段可能新增(如挂单拿到 order_id),同步登记到索引,
|
|
1715
|
+
// 供同批后续 fresh 命中同一槽位,避免重复插入
|
|
1716
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex);
|
|
1715
1717
|
patchedOrders.push(mergedOrder);
|
|
1716
1718
|
if (mergeKey) mergeActions[mergeKey] = 'update';
|
|
1717
|
-
return _context16.abrupt("continue",
|
|
1718
|
-
case
|
|
1719
|
+
return _context16.abrupt("continue", 55);
|
|
1720
|
+
case 50:
|
|
1721
|
+
insertIndex = updatedList.length;
|
|
1719
1722
|
updatedList.push(fresh);
|
|
1723
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
|
|
1720
1724
|
patchedOrders.push(fresh);
|
|
1721
1725
|
if (mergeKey) mergeActions[mergeKey] = 'insert';
|
|
1722
|
-
case
|
|
1723
|
-
_context16.next =
|
|
1726
|
+
case 55:
|
|
1727
|
+
_context16.next = 33;
|
|
1724
1728
|
break;
|
|
1725
|
-
case
|
|
1726
|
-
_context16.next =
|
|
1729
|
+
case 57:
|
|
1730
|
+
_context16.next = 62;
|
|
1727
1731
|
break;
|
|
1728
|
-
case
|
|
1729
|
-
_context16.prev =
|
|
1730
|
-
_context16.t1 = _context16["catch"](
|
|
1732
|
+
case 59:
|
|
1733
|
+
_context16.prev = 59;
|
|
1734
|
+
_context16.t1 = _context16["catch"](31);
|
|
1731
1735
|
_iterator11.e(_context16.t1);
|
|
1732
|
-
case
|
|
1733
|
-
_context16.prev =
|
|
1736
|
+
case 62:
|
|
1737
|
+
_context16.prev = 62;
|
|
1734
1738
|
_iterator11.f();
|
|
1735
|
-
return _context16.finish(
|
|
1736
|
-
case
|
|
1739
|
+
return _context16.finish(62);
|
|
1740
|
+
case 65:
|
|
1737
1741
|
insertCount = Object.values(mergeActions).filter(function (v) {
|
|
1738
1742
|
return v === 'insert';
|
|
1739
1743
|
}).length;
|
|
@@ -1745,30 +1749,110 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1745
1749
|
updateCount: updateCount,
|
|
1746
1750
|
storeOrderCountAfter: this.store.list.length
|
|
1747
1751
|
});
|
|
1748
|
-
|
|
1752
|
+
// 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;
|
|
1753
|
+
// 仅在自检开关开启时做一次兜底校验。
|
|
1754
|
+
this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
|
|
1749
1755
|
this.syncOrdersMap();
|
|
1750
|
-
_context16.next =
|
|
1756
|
+
_context16.next = 72;
|
|
1751
1757
|
return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
|
|
1752
|
-
case
|
|
1758
|
+
case 72:
|
|
1753
1759
|
this.logInfo('mergeOrdersToStore-结束', {
|
|
1754
1760
|
uniqueFreshCount: uniqueFreshCount,
|
|
1755
1761
|
storeOrderCountAfter: this.store.list.length,
|
|
1756
1762
|
insertCount: insertCount,
|
|
1757
1763
|
updateCount: updateCount
|
|
1758
1764
|
});
|
|
1759
|
-
_context16.next =
|
|
1765
|
+
_context16.next = 75;
|
|
1760
1766
|
return this.emitOrdersChanged(patchedOrders, source);
|
|
1761
|
-
case
|
|
1767
|
+
case 75:
|
|
1762
1768
|
case "end":
|
|
1763
1769
|
return _context16.stop();
|
|
1764
1770
|
}
|
|
1765
|
-
}, _callee16, this, [[
|
|
1771
|
+
}, _callee16, this, [[5, 17, 20, 23], [31, 59, 62, 65]]);
|
|
1766
1772
|
}));
|
|
1767
1773
|
function mergeOrdersToStore(_x9, _x10) {
|
|
1768
1774
|
return _mergeOrdersToStore.apply(this, arguments);
|
|
1769
1775
|
}
|
|
1770
1776
|
return mergeOrdersToStore;
|
|
1771
|
-
}()
|
|
1777
|
+
}()
|
|
1778
|
+
/**
|
|
1779
|
+
* 在身份索引中查找与目标订单共享任一身份键的已存在订单下标。
|
|
1780
|
+
* 返回所有命中键里最小的下标,等价于原 findOrderIndexByIdentity 的「取首个匹配」语义。
|
|
1781
|
+
*
|
|
1782
|
+
* @example
|
|
1783
|
+
* const idx = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys)
|
|
1784
|
+
*/
|
|
1785
|
+
)
|
|
1786
|
+
}, {
|
|
1787
|
+
key: "lookupOrderIndexByIdentityKeys",
|
|
1788
|
+
value: function lookupOrderIndexByIdentityKeys(identityKeyToIndex, identityKeys) {
|
|
1789
|
+
var matchIndex = -1;
|
|
1790
|
+
var _iterator12 = _createForOfIteratorHelper(identityKeys),
|
|
1791
|
+
_step12;
|
|
1792
|
+
try {
|
|
1793
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
1794
|
+
var key = _step12.value;
|
|
1795
|
+
var index = identityKeyToIndex.get(key);
|
|
1796
|
+
if (index === undefined) continue;
|
|
1797
|
+
if (matchIndex < 0 || index < matchIndex) matchIndex = index;
|
|
1798
|
+
}
|
|
1799
|
+
} catch (err) {
|
|
1800
|
+
_iterator12.e(err);
|
|
1801
|
+
} finally {
|
|
1802
|
+
_iterator12.f();
|
|
1803
|
+
}
|
|
1804
|
+
return matchIndex;
|
|
1805
|
+
}
|
|
1806
|
+
}, {
|
|
1807
|
+
key: "isRemoteEchoMergeSource",
|
|
1808
|
+
value: function isRemoteEchoMergeSource(source) {
|
|
1809
|
+
return source === 'pubsub.bodyUpsert' || source === 'pubsub.httpRefresh';
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
/**
|
|
1813
|
+
* 将订单的全部身份键登记到索引并指向其在列表中的下标。
|
|
1814
|
+
* 合并后订单新增的身份字段(如挂单同步后拿到 order_id)也会被登记。
|
|
1815
|
+
*
|
|
1816
|
+
* @example
|
|
1817
|
+
* this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex)
|
|
1818
|
+
*/
|
|
1819
|
+
}, {
|
|
1820
|
+
key: "registerOrderIdentityKeys",
|
|
1821
|
+
value: function registerOrderIdentityKeys(identityKeyToIndex, order, index) {
|
|
1822
|
+
var identityKeys = this.getOrderIdentityMatchKeys(order);
|
|
1823
|
+
var _iterator13 = _createForOfIteratorHelper(identityKeys),
|
|
1824
|
+
_step13;
|
|
1825
|
+
try {
|
|
1826
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
1827
|
+
var key = _step13.value;
|
|
1828
|
+
identityKeyToIndex.set(key, index);
|
|
1829
|
+
}
|
|
1830
|
+
} catch (err) {
|
|
1831
|
+
_iterator13.e(err);
|
|
1832
|
+
} finally {
|
|
1833
|
+
_iterator13.f();
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
/**
|
|
1838
|
+
* 合并热路径去重兜底:默认直接返回原列表(增量索引已保证无重复)。
|
|
1839
|
+
* 仅当 ORDER_MERGE_SELF_CHECK 开启时,额外做一次全表压缩并在发现残留重复时告警。
|
|
1840
|
+
*/
|
|
1841
|
+
}, {
|
|
1842
|
+
key: "runOrderStoreSelfCheck",
|
|
1843
|
+
value: function runOrderStoreSelfCheck(orders, source) {
|
|
1844
|
+
if (!ORDER_MERGE_SELF_CHECK) return orders;
|
|
1845
|
+
var _this$compactOrderLis = this.compactOrderListByIdentity(orders, source),
|
|
1846
|
+
list = _this$compactOrderLis.list,
|
|
1847
|
+
removedCount = _this$compactOrderLis.removedCount;
|
|
1848
|
+
if (removedCount > 0) {
|
|
1849
|
+
this.logWarning('合并自检发现残留重复订单,已压缩', {
|
|
1850
|
+
source: source,
|
|
1851
|
+
removedCount: removedCount
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
return list;
|
|
1855
|
+
}
|
|
1772
1856
|
}, {
|
|
1773
1857
|
key: "normalizeOrderSyncMessage",
|
|
1774
1858
|
value: function normalizeOrderSyncMessage(res) {
|
|
@@ -1801,17 +1885,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1801
1885
|
key: "uniqueOrderIds",
|
|
1802
1886
|
value: function uniqueOrderIds(ids) {
|
|
1803
1887
|
var idMap = new Map();
|
|
1804
|
-
var
|
|
1805
|
-
|
|
1888
|
+
var _iterator14 = _createForOfIteratorHelper(ids),
|
|
1889
|
+
_step14;
|
|
1806
1890
|
try {
|
|
1807
|
-
for (
|
|
1808
|
-
var id =
|
|
1891
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
1892
|
+
var id = _step14.value;
|
|
1809
1893
|
idMap.set(this.getIdKey(id), id);
|
|
1810
1894
|
}
|
|
1811
1895
|
} catch (err) {
|
|
1812
|
-
|
|
1896
|
+
_iterator14.e(err);
|
|
1813
1897
|
} finally {
|
|
1814
|
-
|
|
1898
|
+
_iterator14.f();
|
|
1815
1899
|
}
|
|
1816
1900
|
return _toConsumableArray(idMap.values());
|
|
1817
1901
|
}
|
|
@@ -1823,12 +1907,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1823
1907
|
}, {
|
|
1824
1908
|
key: "isOrderLookupMatch",
|
|
1825
1909
|
value: function isOrderLookupMatch(order, lookupKey) {
|
|
1826
|
-
var
|
|
1910
|
+
var _this14 = this;
|
|
1827
1911
|
if (!order || !lookupKey) return false;
|
|
1828
1912
|
var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
|
|
1829
1913
|
return candidates.some(function (value) {
|
|
1830
1914
|
if (value === undefined || value === null || value === '') return false;
|
|
1831
|
-
return
|
|
1915
|
+
return _this14.getIdKey(value) === lookupKey;
|
|
1832
1916
|
});
|
|
1833
1917
|
}
|
|
1834
1918
|
|
|
@@ -1871,10 +1955,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1871
1955
|
}, {
|
|
1872
1956
|
key: "findOrderIndexByIdentity",
|
|
1873
1957
|
value: function findOrderIndexByIdentity(orders, target) {
|
|
1874
|
-
var
|
|
1958
|
+
var _this15 = this;
|
|
1875
1959
|
if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
|
|
1876
1960
|
return orders.findIndex(function (order) {
|
|
1877
|
-
return
|
|
1961
|
+
return _this15.doOrdersShareIdentity(order, target);
|
|
1878
1962
|
});
|
|
1879
1963
|
}
|
|
1880
1964
|
}, {
|
|
@@ -1923,58 +2007,58 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1923
2007
|
if (secondaryList.length === 0) return preferredList;
|
|
1924
2008
|
if (preferredList.length === 0) return secondaryList;
|
|
1925
2009
|
var seenKeys = new Set();
|
|
1926
|
-
var
|
|
1927
|
-
|
|
2010
|
+
var _iterator15 = _createForOfIteratorHelper(preferredList),
|
|
2011
|
+
_step15;
|
|
1928
2012
|
try {
|
|
1929
|
-
for (
|
|
1930
|
-
var item =
|
|
2013
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
2014
|
+
var item = _step15.value;
|
|
1931
2015
|
var keys = this.getProductIdentityKeys(item);
|
|
1932
|
-
var
|
|
1933
|
-
|
|
2016
|
+
var _iterator17 = _createForOfIteratorHelper(keys),
|
|
2017
|
+
_step17;
|
|
1934
2018
|
try {
|
|
1935
|
-
for (
|
|
1936
|
-
var key =
|
|
2019
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
2020
|
+
var key = _step17.value;
|
|
1937
2021
|
seenKeys.add(key);
|
|
1938
2022
|
}
|
|
1939
2023
|
} catch (err) {
|
|
1940
|
-
|
|
2024
|
+
_iterator17.e(err);
|
|
1941
2025
|
} finally {
|
|
1942
|
-
|
|
2026
|
+
_iterator17.f();
|
|
1943
2027
|
}
|
|
1944
2028
|
}
|
|
1945
2029
|
} catch (err) {
|
|
1946
|
-
|
|
2030
|
+
_iterator15.e(err);
|
|
1947
2031
|
} finally {
|
|
1948
|
-
|
|
2032
|
+
_iterator15.f();
|
|
1949
2033
|
}
|
|
1950
2034
|
var result = _toConsumableArray(preferredList);
|
|
1951
|
-
var
|
|
1952
|
-
|
|
2035
|
+
var _iterator16 = _createForOfIteratorHelper(secondaryList),
|
|
2036
|
+
_step16;
|
|
1953
2037
|
try {
|
|
1954
|
-
for (
|
|
1955
|
-
var _item =
|
|
2038
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
2039
|
+
var _item = _step16.value;
|
|
1956
2040
|
var _keys = this.getProductIdentityKeys(_item);
|
|
1957
2041
|
if (_keys.length === 0 || _keys.some(function (key) {
|
|
1958
2042
|
return seenKeys.has(key);
|
|
1959
2043
|
})) continue;
|
|
1960
|
-
var
|
|
1961
|
-
|
|
2044
|
+
var _iterator18 = _createForOfIteratorHelper(_keys),
|
|
2045
|
+
_step18;
|
|
1962
2046
|
try {
|
|
1963
|
-
for (
|
|
1964
|
-
var _key =
|
|
2047
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
2048
|
+
var _key = _step18.value;
|
|
1965
2049
|
seenKeys.add(_key);
|
|
1966
2050
|
}
|
|
1967
2051
|
} catch (err) {
|
|
1968
|
-
|
|
2052
|
+
_iterator18.e(err);
|
|
1969
2053
|
} finally {
|
|
1970
|
-
|
|
2054
|
+
_iterator18.f();
|
|
1971
2055
|
}
|
|
1972
2056
|
result.push(cloneDeep(_item));
|
|
1973
2057
|
}
|
|
1974
2058
|
} catch (err) {
|
|
1975
|
-
|
|
2059
|
+
_iterator16.e(err);
|
|
1976
2060
|
} finally {
|
|
1977
|
-
|
|
2061
|
+
_iterator16.f();
|
|
1978
2062
|
}
|
|
1979
2063
|
return result;
|
|
1980
2064
|
}
|
|
@@ -2000,29 +2084,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2000
2084
|
}, {
|
|
2001
2085
|
key: "mergeOrderPaymentLists",
|
|
2002
2086
|
value: function mergeOrderPaymentLists(existing, incoming) {
|
|
2003
|
-
var
|
|
2087
|
+
var _this16 = this;
|
|
2004
2088
|
var existingList = Array.isArray(existing) ? existing : [];
|
|
2005
2089
|
var incomingList = Array.isArray(incoming) ? incoming : [];
|
|
2006
2090
|
if (incomingList.length === 0) return cloneDeep(existingList);
|
|
2007
2091
|
if (existingList.length === 0) return cloneDeep(incomingList);
|
|
2008
2092
|
var existingByKey = new Map();
|
|
2009
|
-
var
|
|
2010
|
-
|
|
2093
|
+
var _iterator19 = _createForOfIteratorHelper(existingList),
|
|
2094
|
+
_step19;
|
|
2011
2095
|
try {
|
|
2012
|
-
for (
|
|
2013
|
-
var payment =
|
|
2096
|
+
for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
|
|
2097
|
+
var payment = _step19.value;
|
|
2014
2098
|
var key = this.getPaymentMergeKey(payment);
|
|
2015
2099
|
if (!key) continue;
|
|
2016
2100
|
existingByKey.set(key, payment);
|
|
2017
2101
|
}
|
|
2018
2102
|
} catch (err) {
|
|
2019
|
-
|
|
2103
|
+
_iterator19.e(err);
|
|
2020
2104
|
} finally {
|
|
2021
|
-
|
|
2105
|
+
_iterator19.f();
|
|
2022
2106
|
}
|
|
2023
2107
|
return incomingList.map(function (payment) {
|
|
2024
2108
|
var incomingPayment = payment;
|
|
2025
|
-
var key =
|
|
2109
|
+
var key = _this16.getPaymentMergeKey(incomingPayment);
|
|
2026
2110
|
var existingPayment = key ? existingByKey.get(key) : undefined;
|
|
2027
2111
|
if (!existingPayment) return cloneDeep(incomingPayment);
|
|
2028
2112
|
return _objectSpread(_objectSpread(_objectSpread({}, cloneDeep(existingPayment)), cloneDeep(incomingPayment)), {}, {
|
|
@@ -2079,47 +2163,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2079
2163
|
key: "summarizeDuplicateOrders",
|
|
2080
2164
|
value: function summarizeDuplicateOrders(orders) {
|
|
2081
2165
|
var groups = new Map();
|
|
2082
|
-
var
|
|
2083
|
-
|
|
2166
|
+
var _iterator20 = _createForOfIteratorHelper(orders),
|
|
2167
|
+
_step20;
|
|
2084
2168
|
try {
|
|
2085
|
-
for (
|
|
2086
|
-
var order =
|
|
2087
|
-
var
|
|
2088
|
-
|
|
2169
|
+
for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
|
|
2170
|
+
var order = _step20.value;
|
|
2171
|
+
var _iterator21 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
|
|
2172
|
+
_step21;
|
|
2089
2173
|
try {
|
|
2090
|
-
for (
|
|
2091
|
-
var key =
|
|
2174
|
+
for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
|
|
2175
|
+
var key = _step21.value;
|
|
2092
2176
|
var group = groups.get(key) || [];
|
|
2093
2177
|
group.push(order);
|
|
2094
2178
|
groups.set(key, group);
|
|
2095
2179
|
}
|
|
2096
2180
|
} catch (err) {
|
|
2097
|
-
|
|
2181
|
+
_iterator21.e(err);
|
|
2098
2182
|
} finally {
|
|
2099
|
-
|
|
2183
|
+
_iterator21.f();
|
|
2100
2184
|
}
|
|
2101
2185
|
}
|
|
2102
2186
|
} catch (err) {
|
|
2103
|
-
|
|
2187
|
+
_iterator20.e(err);
|
|
2104
2188
|
} finally {
|
|
2105
|
-
|
|
2189
|
+
_iterator20.f();
|
|
2106
2190
|
}
|
|
2107
|
-
return _toConsumableArray(groups.entries()).filter(function (
|
|
2108
|
-
var _ref3 = _slicedToArray(_ref2, 2),
|
|
2109
|
-
group = _ref3[1];
|
|
2110
|
-
return group.length > 1;
|
|
2111
|
-
}).slice(0, 20).map(function (_ref4) {
|
|
2191
|
+
return _toConsumableArray(groups.entries()).filter(function (_ref4) {
|
|
2112
2192
|
var _ref5 = _slicedToArray(_ref4, 2),
|
|
2113
|
-
key = _ref5[0],
|
|
2114
2193
|
group = _ref5[1];
|
|
2194
|
+
return group.length > 1;
|
|
2195
|
+
}).slice(0, 20).map(function (_ref6) {
|
|
2196
|
+
var _ref7 = _slicedToArray(_ref6, 2),
|
|
2197
|
+
key = _ref7[0],
|
|
2198
|
+
group = _ref7[1];
|
|
2115
2199
|
return {
|
|
2116
2200
|
key: key,
|
|
2117
2201
|
count: group.length,
|
|
2118
2202
|
orders: group.map(function (order) {
|
|
2119
|
-
var _order$order_id2,
|
|
2203
|
+
var _order$order_id2, _external_sale_number2, _shop_order_number, _shop_full_order_numb, _order$need_sync;
|
|
2120
2204
|
return {
|
|
2121
2205
|
order_id: (_order$order_id2 = order.order_id) !== null && _order$order_id2 !== void 0 ? _order$order_id2 : null,
|
|
2122
|
-
external_sale_number: (
|
|
2206
|
+
external_sale_number: (_external_sale_number2 = order.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : null,
|
|
2123
2207
|
shop_order_number: (_shop_order_number = order.shop_order_number) !== null && _shop_order_number !== void 0 ? _shop_order_number : null,
|
|
2124
2208
|
shop_full_order_number: (_shop_full_order_numb = order.shop_full_order_number) !== null && _shop_full_order_numb !== void 0 ? _shop_full_order_numb : null,
|
|
2125
2209
|
need_sync: (_order$need_sync = order.need_sync) !== null && _order$need_sync !== void 0 ? _order$need_sync : null
|
|
@@ -2144,11 +2228,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2144
2228
|
value: function compactOrderListByIdentity(orders, source) {
|
|
2145
2229
|
var list = [];
|
|
2146
2230
|
var removedCount = 0;
|
|
2147
|
-
var
|
|
2148
|
-
|
|
2231
|
+
var _iterator22 = _createForOfIteratorHelper(orders),
|
|
2232
|
+
_step22;
|
|
2149
2233
|
try {
|
|
2150
|
-
for (
|
|
2151
|
-
var order =
|
|
2234
|
+
for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
|
|
2235
|
+
var order = _step22.value;
|
|
2152
2236
|
var matchIndex = this.findOrderIndexByIdentity(list, order);
|
|
2153
2237
|
if (matchIndex < 0) {
|
|
2154
2238
|
list.push(order);
|
|
@@ -2158,9 +2242,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2158
2242
|
removedCount += 1;
|
|
2159
2243
|
}
|
|
2160
2244
|
} catch (err) {
|
|
2161
|
-
|
|
2245
|
+
_iterator22.e(err);
|
|
2162
2246
|
} finally {
|
|
2163
|
-
|
|
2247
|
+
_iterator22.f();
|
|
2164
2248
|
}
|
|
2165
2249
|
if (removedCount > 0) {
|
|
2166
2250
|
this.logWarning('订单列表重复项已压缩', {
|
|
@@ -2306,15 +2390,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2306
2390
|
}, {
|
|
2307
2391
|
key: "mergeRemoteSnapshotWithPendingOrders",
|
|
2308
2392
|
value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
|
|
2309
|
-
var
|
|
2393
|
+
var _this17 = this;
|
|
2310
2394
|
var merged = remoteOrders.map(function (order) {
|
|
2311
|
-
return
|
|
2395
|
+
return _this17.normalizeRemoteSyncedOrder(order);
|
|
2312
2396
|
});
|
|
2313
|
-
var
|
|
2314
|
-
|
|
2397
|
+
var _iterator23 = _createForOfIteratorHelper(existingOrders),
|
|
2398
|
+
_step23;
|
|
2315
2399
|
try {
|
|
2316
|
-
for (
|
|
2317
|
-
var order =
|
|
2400
|
+
for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
|
|
2401
|
+
var order = _step23.value;
|
|
2318
2402
|
if (!this.isPendingSyncOrder(order)) continue;
|
|
2319
2403
|
var matchIndex = this.findOrderIndexByIdentity(merged, order);
|
|
2320
2404
|
if (matchIndex >= 0) {
|
|
@@ -2325,9 +2409,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2325
2409
|
merged.push(order);
|
|
2326
2410
|
}
|
|
2327
2411
|
} catch (err) {
|
|
2328
|
-
|
|
2412
|
+
_iterator23.e(err);
|
|
2329
2413
|
} finally {
|
|
2330
|
-
|
|
2414
|
+
_iterator23.f();
|
|
2331
2415
|
}
|
|
2332
2416
|
return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
|
|
2333
2417
|
}
|
|
@@ -2377,7 +2461,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2377
2461
|
key: "patchOrdersInSQLite",
|
|
2378
2462
|
value: (function () {
|
|
2379
2463
|
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(orders, source) {
|
|
2380
|
-
var
|
|
2464
|
+
var _this18 = this;
|
|
2381
2465
|
var mergeActions,
|
|
2382
2466
|
ordersSnapshot,
|
|
2383
2467
|
_this$filterRedundant2,
|
|
@@ -2396,7 +2480,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2396
2480
|
return _context20.abrupt("return");
|
|
2397
2481
|
case 3:
|
|
2398
2482
|
ordersSnapshot = cloneDeep(orders).filter(function (order) {
|
|
2399
|
-
return
|
|
2483
|
+
return _this18.getOrderStorageKey(order);
|
|
2400
2484
|
});
|
|
2401
2485
|
if (!(ordersSnapshot.length === 0)) {
|
|
2402
2486
|
_context20.next = 6;
|
|
@@ -2421,54 +2505,54 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2421
2505
|
_context20.prev = 12;
|
|
2422
2506
|
_context20.next = 15;
|
|
2423
2507
|
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
|
2424
|
-
var writeMethod,
|
|
2508
|
+
var writeMethod, _iterator24, _step24, order;
|
|
2425
2509
|
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
2426
2510
|
while (1) switch (_context19.prev = _context19.next) {
|
|
2427
2511
|
case 0:
|
|
2428
2512
|
writeMethod = 'none';
|
|
2429
|
-
|
|
2513
|
+
_this18.logInfo('patchOrdersInSQLite-开始', {
|
|
2430
2514
|
source: source,
|
|
2431
2515
|
count: compactedToWrite.length,
|
|
2432
2516
|
dedupedCount: skipped.length
|
|
2433
2517
|
});
|
|
2434
|
-
if (!(typeof
|
|
2518
|
+
if (!(typeof _this18.dbManager.bulkUpdate === 'function')) {
|
|
2435
2519
|
_context19.next = 8;
|
|
2436
2520
|
break;
|
|
2437
2521
|
}
|
|
2438
2522
|
writeMethod = 'bulkUpdate';
|
|
2439
2523
|
_context19.next = 6;
|
|
2440
|
-
return
|
|
2524
|
+
return _this18.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2441
2525
|
case 6:
|
|
2442
2526
|
_context19.next = 33;
|
|
2443
2527
|
break;
|
|
2444
2528
|
case 8:
|
|
2445
|
-
if (!(typeof
|
|
2529
|
+
if (!(typeof _this18.dbManager.bulkAdd === 'function')) {
|
|
2446
2530
|
_context19.next = 14;
|
|
2447
2531
|
break;
|
|
2448
2532
|
}
|
|
2449
2533
|
writeMethod = 'bulkAdd';
|
|
2450
2534
|
_context19.next = 12;
|
|
2451
|
-
return
|
|
2535
|
+
return _this18.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2452
2536
|
case 12:
|
|
2453
2537
|
_context19.next = 33;
|
|
2454
2538
|
break;
|
|
2455
2539
|
case 14:
|
|
2456
|
-
if (!(typeof
|
|
2540
|
+
if (!(typeof _this18.dbManager.update === 'function')) {
|
|
2457
2541
|
_context19.next = 33;
|
|
2458
2542
|
break;
|
|
2459
2543
|
}
|
|
2460
2544
|
writeMethod = 'update';
|
|
2461
|
-
|
|
2545
|
+
_iterator24 = _createForOfIteratorHelper(compactedToWrite);
|
|
2462
2546
|
_context19.prev = 17;
|
|
2463
|
-
|
|
2547
|
+
_iterator24.s();
|
|
2464
2548
|
case 19:
|
|
2465
|
-
if ((
|
|
2549
|
+
if ((_step24 = _iterator24.n()).done) {
|
|
2466
2550
|
_context19.next = 25;
|
|
2467
2551
|
break;
|
|
2468
2552
|
}
|
|
2469
|
-
order =
|
|
2553
|
+
order = _step24.value;
|
|
2470
2554
|
_context19.next = 23;
|
|
2471
|
-
return
|
|
2555
|
+
return _this18.dbManager.update(INDEXDB_STORE_NAME, order);
|
|
2472
2556
|
case 23:
|
|
2473
2557
|
_context19.next = 19;
|
|
2474
2558
|
break;
|
|
@@ -2478,14 +2562,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2478
2562
|
case 27:
|
|
2479
2563
|
_context19.prev = 27;
|
|
2480
2564
|
_context19.t0 = _context19["catch"](17);
|
|
2481
|
-
|
|
2565
|
+
_iterator24.e(_context19.t0);
|
|
2482
2566
|
case 30:
|
|
2483
2567
|
_context19.prev = 30;
|
|
2484
|
-
|
|
2568
|
+
_iterator24.f();
|
|
2485
2569
|
return _context19.finish(30);
|
|
2486
2570
|
case 33:
|
|
2487
|
-
|
|
2488
|
-
|
|
2571
|
+
_this18.recordRecentSqliteWrite(source, compactedToWrite);
|
|
2572
|
+
_this18.logInfo('patchOrdersInSQLite-完成', {
|
|
2489
2573
|
source: source,
|
|
2490
2574
|
count: compactedToWrite.length,
|
|
2491
2575
|
writeMethod: writeMethod,
|
|
@@ -2529,7 +2613,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2529
2613
|
key: "updateOrderInSQLite",
|
|
2530
2614
|
value: (function () {
|
|
2531
2615
|
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(order, source) {
|
|
2532
|
-
var
|
|
2616
|
+
var _this19 = this;
|
|
2533
2617
|
var orderSnapshot, _orderSnapshot$order_3;
|
|
2534
2618
|
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
2535
2619
|
while (1) switch (_context22.prev = _context22.next) {
|
|
@@ -2550,43 +2634,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2550
2634
|
while (1) switch (_context21.prev = _context21.next) {
|
|
2551
2635
|
case 0:
|
|
2552
2636
|
writeMethod = 'none';
|
|
2553
|
-
|
|
2637
|
+
_this19.logInfo('updateOrderInSQLite-开始', {
|
|
2554
2638
|
source: source,
|
|
2555
2639
|
orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
|
|
2556
|
-
storageKey:
|
|
2640
|
+
storageKey: _this19.getOrderStorageKey(orderSnapshot)
|
|
2557
2641
|
});
|
|
2558
|
-
if (!(typeof
|
|
2642
|
+
if (!(typeof _this19.dbManager.update === 'function')) {
|
|
2559
2643
|
_context21.next = 8;
|
|
2560
2644
|
break;
|
|
2561
2645
|
}
|
|
2562
2646
|
writeMethod = 'update';
|
|
2563
2647
|
_context21.next = 6;
|
|
2564
|
-
return
|
|
2648
|
+
return _this19.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
|
|
2565
2649
|
case 6:
|
|
2566
2650
|
_context21.next = 18;
|
|
2567
2651
|
break;
|
|
2568
2652
|
case 8:
|
|
2569
|
-
if (!(typeof
|
|
2653
|
+
if (!(typeof _this19.dbManager.bulkUpdate === 'function')) {
|
|
2570
2654
|
_context21.next = 14;
|
|
2571
2655
|
break;
|
|
2572
2656
|
}
|
|
2573
2657
|
writeMethod = 'bulkUpdate';
|
|
2574
2658
|
_context21.next = 12;
|
|
2575
|
-
return
|
|
2659
|
+
return _this19.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2576
2660
|
case 12:
|
|
2577
2661
|
_context21.next = 18;
|
|
2578
2662
|
break;
|
|
2579
2663
|
case 14:
|
|
2580
|
-
if (!(typeof
|
|
2664
|
+
if (!(typeof _this19.dbManager.bulkAdd === 'function')) {
|
|
2581
2665
|
_context21.next = 18;
|
|
2582
2666
|
break;
|
|
2583
2667
|
}
|
|
2584
2668
|
writeMethod = 'bulkAdd';
|
|
2585
2669
|
_context21.next = 18;
|
|
2586
|
-
return
|
|
2670
|
+
return _this19.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2587
2671
|
case 18:
|
|
2588
|
-
|
|
2589
|
-
|
|
2672
|
+
_this19.recordRecentSqliteWrite(source, [orderSnapshot]);
|
|
2673
|
+
_this19.logInfo('updateOrderInSQLite-完成', {
|
|
2590
2674
|
source: source,
|
|
2591
2675
|
orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
|
|
2592
2676
|
writeMethod: writeMethod
|
|
@@ -2629,7 +2713,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2629
2713
|
key: "replaceOrdersSnapshotInSQLite",
|
|
2630
2714
|
value: (function () {
|
|
2631
2715
|
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orderList, source) {
|
|
2632
|
-
var
|
|
2716
|
+
var _this20 = this;
|
|
2633
2717
|
var remoteSnapshot, mergedSnapshot;
|
|
2634
2718
|
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
2635
2719
|
while (1) switch (_context24.prev = _context24.next) {
|
|
@@ -2639,12 +2723,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2639
2723
|
break;
|
|
2640
2724
|
}
|
|
2641
2725
|
return _context24.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
|
|
2642
|
-
return
|
|
2726
|
+
return _this20.normalizeRemoteSyncedOrder(order);
|
|
2643
2727
|
}), "".concat(source, ".snapshotNoDb")).list);
|
|
2644
2728
|
case 2:
|
|
2645
2729
|
remoteSnapshot = cloneDeep(orderList);
|
|
2646
2730
|
mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
|
|
2647
|
-
return
|
|
2731
|
+
return _this20.normalizeRemoteSyncedOrder(order);
|
|
2648
2732
|
}), "".concat(source, ".remoteSnapshot")).list;
|
|
2649
2733
|
_context24.prev = 4;
|
|
2650
2734
|
_context24.next = 7;
|
|
@@ -2653,12 +2737,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2653
2737
|
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
2654
2738
|
while (1) switch (_context23.prev = _context23.next) {
|
|
2655
2739
|
case 0:
|
|
2656
|
-
if (!(typeof
|
|
2740
|
+
if (!(typeof _this20.dbManager.getAll === 'function')) {
|
|
2657
2741
|
_context23.next = 6;
|
|
2658
2742
|
break;
|
|
2659
2743
|
}
|
|
2660
2744
|
_context23.next = 3;
|
|
2661
|
-
return
|
|
2745
|
+
return _this20.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
2662
2746
|
case 3:
|
|
2663
2747
|
_context23.t0 = _context23.sent;
|
|
2664
2748
|
_context23.next = 7;
|
|
@@ -2667,18 +2751,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2667
2751
|
_context23.t0 = [];
|
|
2668
2752
|
case 7:
|
|
2669
2753
|
existingOrders = _context23.t0;
|
|
2670
|
-
orderListSnapshot =
|
|
2671
|
-
mergedSnapshot =
|
|
2672
|
-
|
|
2754
|
+
orderListSnapshot = _this20.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, existingOrders || []);
|
|
2755
|
+
mergedSnapshot = _this20.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
|
|
2756
|
+
_this20.logInfo('replaceOrdersSnapshotInSQLite-开始', {
|
|
2673
2757
|
source: source,
|
|
2674
2758
|
count: mergedSnapshot.length,
|
|
2675
2759
|
remoteCount: remoteSnapshot.length,
|
|
2676
2760
|
preservedPendingCount: mergedSnapshot.length - remoteSnapshot.length
|
|
2677
2761
|
});
|
|
2678
2762
|
_context23.next = 13;
|
|
2679
|
-
return
|
|
2763
|
+
return _this20.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2680
2764
|
case 13:
|
|
2681
|
-
|
|
2765
|
+
_this20.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
|
|
2682
2766
|
count: mergedSnapshot.length
|
|
2683
2767
|
});
|
|
2684
2768
|
if (!(mergedSnapshot.length === 0)) {
|
|
@@ -2688,10 +2772,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2688
2772
|
return _context23.abrupt("return");
|
|
2689
2773
|
case 16:
|
|
2690
2774
|
_context23.next = 18;
|
|
2691
|
-
return
|
|
2775
|
+
return _this20.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
|
|
2692
2776
|
case 18:
|
|
2693
|
-
|
|
2694
|
-
|
|
2777
|
+
_this20.recordRecentSqliteWrite(source, mergedSnapshot);
|
|
2778
|
+
_this20.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
|
|
2695
2779
|
source: source,
|
|
2696
2780
|
count: mergedSnapshot.length
|
|
2697
2781
|
});
|
|
@@ -2735,34 +2819,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2735
2819
|
key: "clear",
|
|
2736
2820
|
value: (function () {
|
|
2737
2821
|
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
|
|
2738
|
-
var
|
|
2822
|
+
var _this21 = this;
|
|
2739
2823
|
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
2740
2824
|
while (1) switch (_context26.prev = _context26.next) {
|
|
2741
2825
|
case 0:
|
|
2742
2826
|
this.store.list = [];
|
|
2743
2827
|
this.store.map = new Map();
|
|
2744
|
-
this.resourceIdIndex.clear();
|
|
2745
2828
|
if (!this.dbManager) {
|
|
2746
|
-
_context26.next =
|
|
2829
|
+
_context26.next = 5;
|
|
2747
2830
|
break;
|
|
2748
2831
|
}
|
|
2749
|
-
_context26.next =
|
|
2832
|
+
_context26.next = 5;
|
|
2750
2833
|
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
2751
2834
|
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
2752
2835
|
while (1) switch (_context25.prev = _context25.next) {
|
|
2753
2836
|
case 0:
|
|
2754
2837
|
_context25.next = 2;
|
|
2755
|
-
return
|
|
2838
|
+
return _this21.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2756
2839
|
case 2:
|
|
2757
2840
|
case "end":
|
|
2758
2841
|
return _context25.stop();
|
|
2759
2842
|
}
|
|
2760
2843
|
}, _callee25);
|
|
2761
2844
|
})));
|
|
2762
|
-
case
|
|
2845
|
+
case 5:
|
|
2763
2846
|
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
|
|
2764
2847
|
this.emitOrdersChanged([], 'clear');
|
|
2765
|
-
case
|
|
2848
|
+
case 7:
|
|
2766
2849
|
case "end":
|
|
2767
2850
|
return _context26.stop();
|
|
2768
2851
|
}
|