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