@pisell/pisellos 2.2.209 → 2.2.211
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/modules/BookingContext/index.d.ts +13 -2
- package/dist/modules/BookingContext/index.js +198 -68
- package/dist/modules/Order/index.d.ts +1 -0
- package/dist/modules/Order/index.js +62 -28
- package/dist/modules/Order/types.d.ts +4 -1
- package/dist/modules/Order/utils.d.ts +1 -0
- package/dist/modules/Order/utils.js +11 -6
- package/dist/modules/Quotation/index.js +2 -1
- package/dist/modules/SalesSummary/index.d.ts +1 -0
- package/dist/modules/SalesSummary/index.js +29 -15
- package/dist/modules/SurchargeList/index.d.ts +16 -0
- package/dist/modules/SurchargeList/index.js +162 -0
- package/dist/modules/SurchargeList/types.d.ts +11 -0
- package/dist/modules/SurchargeList/types.js +1 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +1076 -916
- package/dist/server/modules/order/index.d.ts +9 -0
- package/dist/server/modules/order/index.js +557 -411
- package/dist/server/modules/order/utils/filterOrders.js +3 -2
- package/dist/server/test.json +713 -0
- package/dist/server/utils/small-ticket.d.ts +1 -1
- package/dist/server/utils/small-ticket.js +1 -1
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingTicket/index.js +24 -22
- package/lib/modules/BookingContext/index.d.ts +13 -2
- package/lib/modules/BookingContext/index.js +99 -28
- package/lib/modules/Order/index.d.ts +1 -0
- package/lib/modules/Order/index.js +12 -1
- package/lib/modules/Order/types.d.ts +4 -1
- package/lib/modules/Order/utils.d.ts +1 -0
- package/lib/modules/Order/utils.js +10 -3
- package/lib/modules/Quotation/index.js +1 -1
- package/lib/modules/SalesSummary/index.d.ts +1 -0
- package/lib/modules/SalesSummary/index.js +11 -1
- package/lib/modules/SurchargeList/index.d.ts +16 -0
- package/lib/modules/SurchargeList/index.js +89 -0
- package/lib/modules/SurchargeList/types.d.ts +11 -0
- package/lib/modules/SurchargeList/types.js +17 -0
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +2 -0
- package/lib/server/index.d.ts +8 -0
- package/lib/server/index.js +136 -21
- package/lib/server/modules/order/index.d.ts +9 -0
- package/lib/server/modules/order/index.js +107 -19
- package/lib/server/modules/order/utils/filterOrders.js +3 -2
- package/lib/server/test.json +713 -0
- package/lib/server/utils/small-ticket.d.ts +1 -1
- package/lib/server/utils/small-ticket.js +1 -35
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingTicket/index.js +14 -9
- package/package.json +1 -1
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
2
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
5
3
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -9,6 +7,8 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
|
|
|
9
7
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
8
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
9
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
12
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
13
13
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
14
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
@@ -47,7 +47,7 @@ var ORDER_SQLITE_DEDUPE_MS = 15000;
|
|
|
47
47
|
/** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
|
|
48
48
|
var ORDER_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
|
|
49
49
|
/** 视为「业务侧刚写入」的来源,pubsub 回声可跳过 SQLite */
|
|
50
|
-
var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'overwriteExistingOrder']);
|
|
50
|
+
var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'overwriteExistingOrder', 'markOrderSyncedByExternalSaleNumber']);
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Order 模块 - 基础框架
|
|
@@ -91,6 +91,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
91
91
|
key: "emitOrdersChanged",
|
|
92
92
|
value: (function () {
|
|
93
93
|
var _emitOrdersChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
94
|
+
var _this2 = this;
|
|
94
95
|
var changedOrders,
|
|
95
96
|
source,
|
|
96
97
|
payload,
|
|
@@ -102,7 +103,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
102
103
|
source = _args.length > 1 ? _args[1] : undefined;
|
|
103
104
|
payload = {
|
|
104
105
|
list: this.store.list,
|
|
105
|
-
changedOrders: changedOrders
|
|
106
|
+
changedOrders: changedOrders.map(function (order) {
|
|
107
|
+
return _this2.normalizeOrderForMemoryList(order);
|
|
108
|
+
}),
|
|
106
109
|
source: source
|
|
107
110
|
};
|
|
108
111
|
_context.next = 5;
|
|
@@ -122,7 +125,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
122
125
|
key: "initialize",
|
|
123
126
|
value: function () {
|
|
124
127
|
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(core, options) {
|
|
125
|
-
var _options$initialState
|
|
128
|
+
var _options$initialState,
|
|
129
|
+
_this3 = this;
|
|
126
130
|
var appPlugin, app, _this$store$createdAt, coreData, today, operatingDayBoundary, boundaryTime, boundaryStart, isAfterBoundary, queryStart, queryEnd;
|
|
127
131
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
128
132
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -171,7 +175,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
|
|
174
|
-
this.store.list = options.initialState.list
|
|
178
|
+
this.store.list = options.initialState.list.map(function (order) {
|
|
179
|
+
return _this3.normalizeOrderForMemoryList(order);
|
|
180
|
+
});
|
|
175
181
|
this.syncOrdersMap();
|
|
176
182
|
this.emitOrdersChanged([], 'initialState');
|
|
177
183
|
} else {
|
|
@@ -461,7 +467,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
461
467
|
key: "preload",
|
|
462
468
|
value: function () {
|
|
463
469
|
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
464
|
-
var
|
|
470
|
+
var _this4 = this;
|
|
465
471
|
var getData;
|
|
466
472
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
467
473
|
while (1) switch (_context4.prev = _context4.next) {
|
|
@@ -487,7 +493,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
487
493
|
while (1) switch (_context3.prev = _context3.next) {
|
|
488
494
|
case 0:
|
|
489
495
|
_context3.next = 2;
|
|
490
|
-
return
|
|
496
|
+
return _this4.loadOrdersByServer();
|
|
491
497
|
case 2:
|
|
492
498
|
orders = _context3.sent;
|
|
493
499
|
if (!(orders.length === 0)) {
|
|
@@ -496,10 +502,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
496
502
|
}
|
|
497
503
|
return _context3.abrupt("return");
|
|
498
504
|
case 5:
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
505
|
+
_this4.store.list = cloneDeep(orders);
|
|
506
|
+
_this4.syncOrdersMap();
|
|
507
|
+
_this4.emitOrdersChanged([], 'preload');
|
|
508
|
+
_this4.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
503
509
|
case 9:
|
|
504
510
|
case "end":
|
|
505
511
|
return _context3.stop();
|
|
@@ -543,7 +549,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
543
549
|
key: "getLocalOrderByLookup",
|
|
544
550
|
value: function () {
|
|
545
551
|
var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
|
|
546
|
-
var
|
|
552
|
+
var _this5 = this;
|
|
547
553
|
var key, memoryOrderById, memoryOrder, orders, localOrder;
|
|
548
554
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
549
555
|
while (1) switch (_context5.prev = _context5.next) {
|
|
@@ -557,7 +563,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
557
563
|
return _context5.abrupt("return", memoryOrderById);
|
|
558
564
|
case 4:
|
|
559
565
|
memoryOrder = this.store.list.find(function (order) {
|
|
560
|
-
return
|
|
566
|
+
return _this5.isOrderLookupMatch(order, key);
|
|
561
567
|
});
|
|
562
568
|
if (!memoryOrder) {
|
|
563
569
|
_context5.next = 7;
|
|
@@ -570,7 +576,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
570
576
|
case 9:
|
|
571
577
|
orders = _context5.sent;
|
|
572
578
|
localOrder = orders.find(function (order) {
|
|
573
|
-
return
|
|
579
|
+
return _this5.isOrderLookupMatch(order, key);
|
|
574
580
|
});
|
|
575
581
|
if (localOrder) {
|
|
576
582
|
_context5.next = 13;
|
|
@@ -578,9 +584,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
578
584
|
}
|
|
579
585
|
return _context5.abrupt("return", null);
|
|
580
586
|
case 13:
|
|
581
|
-
this.store.list = orders
|
|
587
|
+
this.store.list = orders.map(function (order) {
|
|
588
|
+
return _this5.normalizeOrderForMemoryList(order);
|
|
589
|
+
});
|
|
582
590
|
this.syncOrdersMap();
|
|
583
|
-
return _context5.abrupt("return", localOrder);
|
|
591
|
+
return _context5.abrupt("return", this.normalizeOrderForMemoryList(localOrder));
|
|
584
592
|
case 16:
|
|
585
593
|
case "end":
|
|
586
594
|
return _context5.stop();
|
|
@@ -596,8 +604,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
596
604
|
key: "loadOrdersByServer",
|
|
597
605
|
value: function () {
|
|
598
606
|
var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
599
|
-
var _this$store
|
|
600
|
-
|
|
607
|
+
var _this$store,
|
|
608
|
+
_this6 = this;
|
|
609
|
+
var orderList, data, mergedOrders, memoryOrders;
|
|
601
610
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
602
611
|
while (1) switch (_context6.prev = _context6.next) {
|
|
603
612
|
case 0:
|
|
@@ -630,20 +639,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
630
639
|
case 13:
|
|
631
640
|
_context6.prev = 13;
|
|
632
641
|
_context6.t0 = _context6["catch"](3);
|
|
633
|
-
|
|
634
|
-
this.
|
|
642
|
+
this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
|
|
643
|
+
return _context6.abrupt("return", this.store.list);
|
|
635
644
|
case 17:
|
|
636
645
|
_context6.next = 19;
|
|
637
646
|
return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer');
|
|
638
647
|
case 19:
|
|
648
|
+
mergedOrders = _context6.sent;
|
|
649
|
+
memoryOrders = mergedOrders.map(function (order) {
|
|
650
|
+
return _this6.normalizeOrderForMemoryList(order);
|
|
651
|
+
});
|
|
639
652
|
this.logInfo('loadOrdersByServer-结束', {
|
|
640
|
-
count:
|
|
653
|
+
count: memoryOrders.length
|
|
641
654
|
});
|
|
642
|
-
_context6.next =
|
|
643
|
-
return this.core.effects.emit(OrderHooks.onOrdersLoaded,
|
|
644
|
-
case
|
|
645
|
-
return _context6.abrupt("return",
|
|
646
|
-
case
|
|
655
|
+
_context6.next = 24;
|
|
656
|
+
return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
|
|
657
|
+
case 24:
|
|
658
|
+
return _context6.abrupt("return", memoryOrders);
|
|
659
|
+
case 25:
|
|
647
660
|
case "end":
|
|
648
661
|
return _context6.stop();
|
|
649
662
|
}
|
|
@@ -724,14 +737,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
724
737
|
}, {
|
|
725
738
|
key: "getOrdersByResourceId",
|
|
726
739
|
value: function getOrdersByResourceId(resourceId) {
|
|
727
|
-
var
|
|
740
|
+
var _this7 = this;
|
|
728
741
|
var ids = this.resourceIdIndex.get(String(resourceId)) || [];
|
|
729
742
|
return ids.map(function (id) {
|
|
730
|
-
return
|
|
743
|
+
return _this7.store.map.get(id);
|
|
731
744
|
}).filter(function (order) {
|
|
732
745
|
return !!order;
|
|
733
746
|
});
|
|
734
747
|
}
|
|
748
|
+
}, {
|
|
749
|
+
key: "normalizeOrderForMemoryList",
|
|
750
|
+
value: function normalizeOrderForMemoryList(order) {
|
|
751
|
+
var externalSaleNumber = order === null || order === void 0 ? void 0 : order.external_sale_number;
|
|
752
|
+
if ((order === null || order === void 0 ? void 0 : order.order_id) !== undefined && (order === null || order === void 0 ? void 0 : order.order_id) !== null && (order === null || order === void 0 ? void 0 : order.order_id) !== '') {
|
|
753
|
+
return order;
|
|
754
|
+
}
|
|
755
|
+
if (externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '') {
|
|
756
|
+
return order;
|
|
757
|
+
}
|
|
758
|
+
return _objectSpread(_objectSpread({}, order), {}, {
|
|
759
|
+
order_id: externalSaleNumber
|
|
760
|
+
});
|
|
761
|
+
}
|
|
735
762
|
|
|
736
763
|
/**
|
|
737
764
|
* 仅覆盖本地已存在的订单;不存在则直接跳过,不落库、不 emit。
|
|
@@ -741,7 +768,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
741
768
|
key: "overwriteExistingOrder",
|
|
742
769
|
value: (function () {
|
|
743
770
|
var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(fresh) {
|
|
744
|
-
var
|
|
771
|
+
var _this8 = this;
|
|
745
772
|
var orderId, key;
|
|
746
773
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
747
774
|
while (1) switch (_context8.prev = _context8.next) {
|
|
@@ -775,7 +802,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
775
802
|
this.store.list = this.store.list.map(function (order) {
|
|
776
803
|
var id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
777
804
|
if (id === undefined || id === null) return order;
|
|
778
|
-
return
|
|
805
|
+
return _this8.getIdKey(id) === key ? fresh : order;
|
|
779
806
|
});
|
|
780
807
|
this.syncOrdersMap();
|
|
781
808
|
_context8.next = 13;
|
|
@@ -836,84 +863,160 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
836
863
|
return _upsertOrdersFromRemote.apply(this, arguments);
|
|
837
864
|
}
|
|
838
865
|
return upsertOrdersFromRemote;
|
|
866
|
+
}())
|
|
867
|
+
}, {
|
|
868
|
+
key: "markOrderSyncedByExternalSaleNumber",
|
|
869
|
+
value: function () {
|
|
870
|
+
var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
871
|
+
var _this9 = this,
|
|
872
|
+
_existing$external_sa,
|
|
873
|
+
_nextOrder$order_id;
|
|
874
|
+
var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
|
|
875
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
876
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
877
|
+
case 0:
|
|
878
|
+
externalSaleNumber = params.externalSaleNumber;
|
|
879
|
+
if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
|
|
880
|
+
_context10.next = 4;
|
|
881
|
+
break;
|
|
882
|
+
}
|
|
883
|
+
this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
|
|
884
|
+
return _context10.abrupt("return", {
|
|
885
|
+
updated: false
|
|
886
|
+
});
|
|
887
|
+
case 4:
|
|
888
|
+
key = this.getIdKey(externalSaleNumber);
|
|
889
|
+
targetIndex = this.store.list.findIndex(function (order) {
|
|
890
|
+
var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
|
|
891
|
+
if (value === undefined || value === null || value === '') return false;
|
|
892
|
+
return _this9.getIdKey(value) === key;
|
|
893
|
+
});
|
|
894
|
+
if (!(targetIndex < 0)) {
|
|
895
|
+
_context10.next = 9;
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
|
|
899
|
+
external_sale_number: externalSaleNumber
|
|
900
|
+
});
|
|
901
|
+
return _context10.abrupt("return", {
|
|
902
|
+
updated: false
|
|
903
|
+
});
|
|
904
|
+
case 9:
|
|
905
|
+
existing = this.store.list[targetIndex];
|
|
906
|
+
nextOrder = this.normalizeRemoteSyncedOrder(_objectSpread(_objectSpread(_objectSpread({}, existing), params.patch || {}), {}, {
|
|
907
|
+
external_sale_number: (_existing$external_sa = existing.external_sale_number) !== null && _existing$external_sa !== void 0 ? _existing$external_sa : externalSaleNumber,
|
|
908
|
+
need_sync: 0
|
|
909
|
+
}));
|
|
910
|
+
storageKey = this.getOrderStorageKey(nextOrder) || key;
|
|
911
|
+
this.store.list = this.store.list.map(function (order, index) {
|
|
912
|
+
if (index !== targetIndex) return order;
|
|
913
|
+
return nextOrder;
|
|
914
|
+
});
|
|
915
|
+
this.syncOrdersMap();
|
|
916
|
+
_context10.next = 16;
|
|
917
|
+
return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
|
|
918
|
+
case 16:
|
|
919
|
+
this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
|
|
920
|
+
external_sale_number: externalSaleNumber,
|
|
921
|
+
order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
|
|
922
|
+
});
|
|
923
|
+
_context10.next = 19;
|
|
924
|
+
return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
|
|
925
|
+
case 19:
|
|
926
|
+
return _context10.abrupt("return", {
|
|
927
|
+
updated: true,
|
|
928
|
+
order: nextOrder
|
|
929
|
+
});
|
|
930
|
+
case 20:
|
|
931
|
+
case "end":
|
|
932
|
+
return _context10.stop();
|
|
933
|
+
}
|
|
934
|
+
}, _callee10, this);
|
|
935
|
+
}));
|
|
936
|
+
function markOrderSyncedByExternalSaleNumber(_x6) {
|
|
937
|
+
return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
|
|
938
|
+
}
|
|
939
|
+
return markOrderSyncedByExternalSaleNumber;
|
|
839
940
|
}()
|
|
840
941
|
/**
|
|
841
942
|
* 将本地待同步订单按 SQLite storage key 合并进 store 并落库。
|
|
842
943
|
* checkout 离线兜底可能没有 order_id,但通常会有 external_sale_number。
|
|
843
944
|
*/
|
|
844
|
-
)
|
|
845
945
|
}, {
|
|
846
946
|
key: "upsertPendingSyncOrders",
|
|
847
947
|
value: (function () {
|
|
848
|
-
var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
849
|
-
var
|
|
850
|
-
var pendingMap, _iterator4, _step4, order, storageKey, patchedOrders, mergeActions, updatedList, _iterator5, _step5, _step5$value, _storageKey, _order;
|
|
851
|
-
return _regeneratorRuntime().wrap(function
|
|
852
|
-
while (1) switch (
|
|
948
|
+
var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(pendingOrders) {
|
|
949
|
+
var _this10 = this;
|
|
950
|
+
var pendingMap, memoryPendingMap, _iterator4, _step4, order, storageKey, patchedOrders, mergeActions, updatedList, _iterator5, _step5, _step5$value, _storageKey, _order;
|
|
951
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
952
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
853
953
|
case 0:
|
|
854
954
|
if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
|
|
855
|
-
|
|
955
|
+
_context11.next = 3;
|
|
856
956
|
break;
|
|
857
957
|
}
|
|
858
958
|
this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
|
|
859
|
-
return
|
|
959
|
+
return _context11.abrupt("return");
|
|
860
960
|
case 3:
|
|
861
961
|
pendingMap = new Map();
|
|
962
|
+
memoryPendingMap = new Map();
|
|
862
963
|
_iterator4 = _createForOfIteratorHelper(pendingOrders);
|
|
863
|
-
|
|
964
|
+
_context11.prev = 6;
|
|
864
965
|
_iterator4.s();
|
|
865
|
-
case
|
|
966
|
+
case 8:
|
|
866
967
|
if ((_step4 = _iterator4.n()).done) {
|
|
867
|
-
|
|
968
|
+
_context11.next = 17;
|
|
868
969
|
break;
|
|
869
970
|
}
|
|
870
971
|
order = _step4.value;
|
|
871
972
|
storageKey = this.getOrderStorageKey(order);
|
|
872
973
|
if (storageKey) {
|
|
873
|
-
|
|
974
|
+
_context11.next = 13;
|
|
874
975
|
break;
|
|
875
976
|
}
|
|
876
|
-
return
|
|
877
|
-
case 12:
|
|
878
|
-
pendingMap.set(storageKey, order);
|
|
977
|
+
return _context11.abrupt("continue", 15);
|
|
879
978
|
case 13:
|
|
880
|
-
|
|
881
|
-
|
|
979
|
+
pendingMap.set(storageKey, order);
|
|
980
|
+
memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(order));
|
|
882
981
|
case 15:
|
|
883
|
-
|
|
982
|
+
_context11.next = 8;
|
|
884
983
|
break;
|
|
885
984
|
case 17:
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
985
|
+
_context11.next = 22;
|
|
986
|
+
break;
|
|
987
|
+
case 19:
|
|
988
|
+
_context11.prev = 19;
|
|
989
|
+
_context11.t0 = _context11["catch"](6);
|
|
990
|
+
_iterator4.e(_context11.t0);
|
|
991
|
+
case 22:
|
|
992
|
+
_context11.prev = 22;
|
|
891
993
|
_iterator4.f();
|
|
892
|
-
return
|
|
893
|
-
case
|
|
994
|
+
return _context11.finish(22);
|
|
995
|
+
case 25:
|
|
894
996
|
if (!(pendingMap.size === 0)) {
|
|
895
|
-
|
|
997
|
+
_context11.next = 28;
|
|
896
998
|
break;
|
|
897
999
|
}
|
|
898
1000
|
this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
|
|
899
1001
|
count: pendingOrders.length
|
|
900
1002
|
});
|
|
901
|
-
return
|
|
902
|
-
case
|
|
1003
|
+
return _context11.abrupt("return");
|
|
1004
|
+
case 28:
|
|
903
1005
|
this.logInfo('upsertPendingSyncOrders-开始', {
|
|
904
1006
|
count: pendingMap.size
|
|
905
1007
|
});
|
|
906
1008
|
patchedOrders = _toConsumableArray(pendingMap.values());
|
|
907
1009
|
mergeActions = {};
|
|
908
1010
|
updatedList = this.store.list.map(function (order) {
|
|
909
|
-
var storageKey =
|
|
1011
|
+
var storageKey = _this10.getOrderStorageKey(order);
|
|
910
1012
|
if (!storageKey || !pendingMap.has(storageKey)) return order;
|
|
911
|
-
var pendingOrder =
|
|
1013
|
+
var pendingOrder = memoryPendingMap.get(storageKey);
|
|
912
1014
|
pendingMap.delete(storageKey);
|
|
1015
|
+
memoryPendingMap.delete(storageKey);
|
|
913
1016
|
mergeActions[storageKey] = 'update';
|
|
914
1017
|
return pendingOrder;
|
|
915
1018
|
});
|
|
916
|
-
_iterator5 = _createForOfIteratorHelper(
|
|
1019
|
+
_iterator5 = _createForOfIteratorHelper(memoryPendingMap.entries());
|
|
917
1020
|
try {
|
|
918
1021
|
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
919
1022
|
_step5$value = _slicedToArray(_step5.value, 2), _storageKey = _step5$value[0], _order = _step5$value[1];
|
|
@@ -927,21 +1030,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
927
1030
|
}
|
|
928
1031
|
this.store.list = updatedList;
|
|
929
1032
|
this.syncOrdersMap();
|
|
930
|
-
|
|
1033
|
+
_context11.next = 38;
|
|
931
1034
|
return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions);
|
|
932
|
-
case
|
|
1035
|
+
case 38:
|
|
933
1036
|
this.logInfo('upsertPendingSyncOrders-结束', {
|
|
934
1037
|
count: patchedOrders.length,
|
|
935
1038
|
storeOrderCountAfter: this.store.list.length
|
|
936
1039
|
});
|
|
937
1040
|
this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
|
|
938
|
-
|
|
1041
|
+
_context11.next = 42;
|
|
1042
|
+
return this.core.effects.emit(OrderHooks.onOrdersChanged, {
|
|
1043
|
+
list: this.store.list,
|
|
1044
|
+
changedOrders: patchedOrders.map(function (order) {
|
|
1045
|
+
return _this10.normalizeOrderForMemoryList(order);
|
|
1046
|
+
}),
|
|
1047
|
+
source: 'upsertPendingSyncOrders'
|
|
1048
|
+
});
|
|
1049
|
+
case 42:
|
|
939
1050
|
case "end":
|
|
940
|
-
return
|
|
1051
|
+
return _context11.stop();
|
|
941
1052
|
}
|
|
942
|
-
},
|
|
1053
|
+
}, _callee11, this, [[6, 19, 22, 25]]);
|
|
943
1054
|
}));
|
|
944
|
-
function upsertPendingSyncOrders(
|
|
1055
|
+
function upsertPendingSyncOrders(_x7) {
|
|
945
1056
|
return _upsertPendingSyncOrders.apply(this, arguments);
|
|
946
1057
|
}
|
|
947
1058
|
return upsertPendingSyncOrders;
|
|
@@ -953,42 +1064,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
953
1064
|
}, {
|
|
954
1065
|
key: "fetchOrdersBySSE",
|
|
955
1066
|
value: (function () {
|
|
956
|
-
var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1067
|
+
var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
957
1068
|
var query,
|
|
958
1069
|
data,
|
|
959
|
-
|
|
960
|
-
return _regeneratorRuntime().wrap(function
|
|
961
|
-
while (1) switch (
|
|
1070
|
+
_args12 = arguments;
|
|
1071
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1072
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
962
1073
|
case 0:
|
|
963
|
-
query =
|
|
1074
|
+
query = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
|
|
964
1075
|
if (this.orderDataSource) {
|
|
965
|
-
|
|
1076
|
+
_context12.next = 3;
|
|
966
1077
|
break;
|
|
967
1078
|
}
|
|
968
|
-
return
|
|
1079
|
+
return _context12.abrupt("return", []);
|
|
969
1080
|
case 3:
|
|
970
|
-
|
|
971
|
-
|
|
1081
|
+
_context12.prev = 3;
|
|
1082
|
+
_context12.next = 6;
|
|
972
1083
|
return this.orderDataSource.run({
|
|
973
1084
|
sse: {
|
|
974
1085
|
query: query
|
|
975
1086
|
}
|
|
976
1087
|
});
|
|
977
1088
|
case 6:
|
|
978
|
-
data =
|
|
979
|
-
return
|
|
1089
|
+
data = _context12.sent;
|
|
1090
|
+
return _context12.abrupt("return", data || []);
|
|
980
1091
|
case 10:
|
|
981
|
-
|
|
982
|
-
|
|
1092
|
+
_context12.prev = 10;
|
|
1093
|
+
_context12.t0 = _context12["catch"](3);
|
|
983
1094
|
this.logError('fetchOrdersBySSE-失败', {
|
|
984
|
-
error:
|
|
1095
|
+
error: _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0)
|
|
985
1096
|
});
|
|
986
|
-
return
|
|
1097
|
+
return _context12.abrupt("return", []);
|
|
987
1098
|
case 14:
|
|
988
1099
|
case "end":
|
|
989
|
-
return
|
|
1100
|
+
return _context12.stop();
|
|
990
1101
|
}
|
|
991
|
-
},
|
|
1102
|
+
}, _callee12, this, [[3, 10]]);
|
|
992
1103
|
}));
|
|
993
1104
|
function fetchOrdersBySSE() {
|
|
994
1105
|
return _fetchOrdersBySSE.apply(this, arguments);
|
|
@@ -1016,7 +1127,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1016
1127
|
}, {
|
|
1017
1128
|
key: "syncOrdersMap",
|
|
1018
1129
|
value: function syncOrdersMap() {
|
|
1019
|
-
var
|
|
1130
|
+
var _this11 = this;
|
|
1020
1131
|
this.store.map.clear();
|
|
1021
1132
|
this.resourceIdIndex.clear();
|
|
1022
1133
|
var _iterator6 = _createForOfIteratorHelper(this.store.list),
|
|
@@ -1024,27 +1135,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1024
1135
|
try {
|
|
1025
1136
|
var _loop = function _loop() {
|
|
1026
1137
|
var order = _step6.value;
|
|
1027
|
-
var
|
|
1028
|
-
if (
|
|
1029
|
-
|
|
1030
|
-
var resourceIds = _this7.extractResourceIds(order);
|
|
1031
|
-
var _iterator7 = _createForOfIteratorHelper(resourceIds),
|
|
1138
|
+
var identityKeys = _this11.getOrderIdentityKeys(order);
|
|
1139
|
+
if (identityKeys.length === 0) return 1; // continue
|
|
1140
|
+
var _iterator7 = _createForOfIteratorHelper(identityKeys),
|
|
1032
1141
|
_step7;
|
|
1033
1142
|
try {
|
|
1034
1143
|
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1035
|
-
var
|
|
1144
|
+
var identityKey = _step7.value;
|
|
1145
|
+
_this11.store.map.set(identityKey, order);
|
|
1146
|
+
}
|
|
1147
|
+
} catch (err) {
|
|
1148
|
+
_iterator7.e(err);
|
|
1149
|
+
} finally {
|
|
1150
|
+
_iterator7.f();
|
|
1151
|
+
}
|
|
1152
|
+
var resourceIds = _this11.extractResourceIds(order);
|
|
1153
|
+
var primaryIdentity = identityKeys[0];
|
|
1154
|
+
var _iterator8 = _createForOfIteratorHelper(resourceIds),
|
|
1155
|
+
_step8;
|
|
1156
|
+
try {
|
|
1157
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1158
|
+
var resourceId = _step8.value;
|
|
1036
1159
|
var key = String(resourceId);
|
|
1037
|
-
var existing =
|
|
1160
|
+
var existing = _this11.resourceIdIndex.get(key) || [];
|
|
1038
1161
|
if (existing.some(function (eid) {
|
|
1039
|
-
return
|
|
1162
|
+
return _this11.getIdKey(eid) === primaryIdentity;
|
|
1040
1163
|
})) continue;
|
|
1041
|
-
existing.push(
|
|
1042
|
-
|
|
1164
|
+
existing.push(primaryIdentity);
|
|
1165
|
+
_this11.resourceIdIndex.set(key, existing);
|
|
1043
1166
|
}
|
|
1044
1167
|
} catch (err) {
|
|
1045
|
-
|
|
1168
|
+
_iterator8.e(err);
|
|
1046
1169
|
} finally {
|
|
1047
|
-
|
|
1170
|
+
_iterator8.f();
|
|
1048
1171
|
}
|
|
1049
1172
|
};
|
|
1050
1173
|
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
@@ -1056,6 +1179,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1056
1179
|
_iterator6.f();
|
|
1057
1180
|
}
|
|
1058
1181
|
}
|
|
1182
|
+
}, {
|
|
1183
|
+
key: "getOrderIdentityKeys",
|
|
1184
|
+
value: function getOrderIdentityKeys(order) {
|
|
1185
|
+
var keys = [];
|
|
1186
|
+
var id = order.order_id;
|
|
1187
|
+
if (id !== undefined && id !== null && id !== '') {
|
|
1188
|
+
keys.push(this.getIdKey(id));
|
|
1189
|
+
}
|
|
1190
|
+
var externalSaleNumber = order === null || order === void 0 ? void 0 : order.external_sale_number;
|
|
1191
|
+
if (externalSaleNumber !== undefined && externalSaleNumber !== null && externalSaleNumber !== '') {
|
|
1192
|
+
var externalKey = this.getIdKey(externalSaleNumber);
|
|
1193
|
+
if (!keys.includes(externalKey)) keys.push(externalKey);
|
|
1194
|
+
}
|
|
1195
|
+
return keys;
|
|
1196
|
+
}
|
|
1059
1197
|
}, {
|
|
1060
1198
|
key: "extractResourceIds",
|
|
1061
1199
|
value: function extractResourceIds(order) {
|
|
@@ -1108,7 +1246,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1108
1246
|
}, {
|
|
1109
1247
|
key: "setupOrderSync",
|
|
1110
1248
|
value: function setupOrderSync() {
|
|
1111
|
-
var
|
|
1249
|
+
var _this12 = this;
|
|
1112
1250
|
if (!this.orderDataSource) return;
|
|
1113
1251
|
this.orderDataSource.run({
|
|
1114
1252
|
pubsub: {
|
|
@@ -1116,21 +1254,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1116
1254
|
var _message$id, _message$order_id, _message$type;
|
|
1117
1255
|
console.log('orderDataSource', res);
|
|
1118
1256
|
var pubsubReceivedAt = Date.now();
|
|
1119
|
-
var message =
|
|
1257
|
+
var message = _this12.normalizeOrderSyncMessage(res);
|
|
1120
1258
|
if (!message) return;
|
|
1121
1259
|
message._pubsubReceivedAt = pubsubReceivedAt;
|
|
1122
|
-
|
|
1123
|
-
var throttleMs =
|
|
1124
|
-
var routeInfo =
|
|
1125
|
-
|
|
1260
|
+
_this12.pendingSyncMessages.push(message);
|
|
1261
|
+
var throttleMs = _this12.getOrderSyncThrottleMs();
|
|
1262
|
+
var routeInfo = _this12.resolveSyncMessageRoute(message);
|
|
1263
|
+
_this12.logInfo('orderSync-收到消息并入队', {
|
|
1126
1264
|
id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
|
|
1127
1265
|
order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
|
|
1128
1266
|
type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
|
|
1129
|
-
pendingCount:
|
|
1267
|
+
pendingCount: _this12.pendingSyncMessages.length,
|
|
1130
1268
|
throttleMs: throttleMs,
|
|
1131
1269
|
pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString()
|
|
1132
1270
|
});
|
|
1133
|
-
|
|
1271
|
+
_this12.scheduleOrderSyncThrottle();
|
|
1134
1272
|
}
|
|
1135
1273
|
}
|
|
1136
1274
|
}).catch(function () {
|
|
@@ -1147,7 +1285,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1147
1285
|
}, {
|
|
1148
1286
|
key: "scheduleOrderSyncThrottle",
|
|
1149
1287
|
value: function scheduleOrderSyncThrottle() {
|
|
1150
|
-
var
|
|
1288
|
+
var _this13 = this;
|
|
1151
1289
|
if (this.isProcessingSyncBatch) return;
|
|
1152
1290
|
if (this.isIdlePhase) {
|
|
1153
1291
|
this.isIdlePhase = false;
|
|
@@ -1158,8 +1296,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1158
1296
|
if (this.syncTimer) return;
|
|
1159
1297
|
var throttleMs = this.getOrderSyncThrottleMs();
|
|
1160
1298
|
this.syncTimer = setTimeout(function () {
|
|
1161
|
-
|
|
1162
|
-
void
|
|
1299
|
+
_this13.syncTimer = undefined;
|
|
1300
|
+
void _this13.flushOrderSyncMessagesByThrottle();
|
|
1163
1301
|
}, throttleMs);
|
|
1164
1302
|
}
|
|
1165
1303
|
|
|
@@ -1170,41 +1308,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1170
1308
|
}, {
|
|
1171
1309
|
key: "flushOrderSyncMessagesByThrottle",
|
|
1172
1310
|
value: (function () {
|
|
1173
|
-
var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1174
|
-
return _regeneratorRuntime().wrap(function
|
|
1175
|
-
while (1) switch (
|
|
1311
|
+
var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
1312
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1313
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1176
1314
|
case 0:
|
|
1177
1315
|
if (!this.isProcessingSyncBatch) {
|
|
1178
|
-
|
|
1316
|
+
_context13.next = 2;
|
|
1179
1317
|
break;
|
|
1180
1318
|
}
|
|
1181
|
-
return
|
|
1319
|
+
return _context13.abrupt("return");
|
|
1182
1320
|
case 2:
|
|
1183
1321
|
if (!(this.pendingSyncMessages.length === 0)) {
|
|
1184
|
-
|
|
1322
|
+
_context13.next = 5;
|
|
1185
1323
|
break;
|
|
1186
1324
|
}
|
|
1187
1325
|
this.isIdlePhase = true;
|
|
1188
|
-
return
|
|
1326
|
+
return _context13.abrupt("return");
|
|
1189
1327
|
case 5:
|
|
1190
1328
|
this.isProcessingSyncBatch = true;
|
|
1191
|
-
|
|
1192
|
-
|
|
1329
|
+
_context13.prev = 6;
|
|
1330
|
+
_context13.next = 9;
|
|
1193
1331
|
return this.processOrderSyncMessages();
|
|
1194
1332
|
case 9:
|
|
1195
|
-
|
|
1333
|
+
_context13.prev = 9;
|
|
1196
1334
|
this.isProcessingSyncBatch = false;
|
|
1197
1335
|
if (this.pendingSyncMessages.length > 0) {
|
|
1198
1336
|
this.scheduleOrderSyncThrottle();
|
|
1199
1337
|
} else {
|
|
1200
1338
|
this.isIdlePhase = true;
|
|
1201
1339
|
}
|
|
1202
|
-
return
|
|
1340
|
+
return _context13.finish(9);
|
|
1203
1341
|
case 13:
|
|
1204
1342
|
case "end":
|
|
1205
|
-
return
|
|
1343
|
+
return _context13.stop();
|
|
1206
1344
|
}
|
|
1207
|
-
},
|
|
1345
|
+
}, _callee13, this, [[6,, 9, 13]]);
|
|
1208
1346
|
}));
|
|
1209
1347
|
function flushOrderSyncMessagesByThrottle() {
|
|
1210
1348
|
return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
|
|
@@ -1226,19 +1364,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1226
1364
|
}, {
|
|
1227
1365
|
key: "processOrderSyncMessages",
|
|
1228
1366
|
value: (function () {
|
|
1229
|
-
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1230
|
-
var
|
|
1367
|
+
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
1368
|
+
var _this14 = this;
|
|
1231
1369
|
var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
|
|
1232
|
-
return _regeneratorRuntime().wrap(function
|
|
1233
|
-
while (1) switch (
|
|
1370
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1371
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1234
1372
|
case 0:
|
|
1235
1373
|
messages = _toConsumableArray(this.pendingSyncMessages);
|
|
1236
1374
|
this.pendingSyncMessages = [];
|
|
1237
1375
|
if (!(messages.length === 0)) {
|
|
1238
|
-
|
|
1376
|
+
_context14.next = 4;
|
|
1239
1377
|
break;
|
|
1240
1378
|
}
|
|
1241
|
-
return
|
|
1379
|
+
return _context14.abrupt("return");
|
|
1242
1380
|
case 4:
|
|
1243
1381
|
batchProcessStartAt = Date.now();
|
|
1244
1382
|
earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
|
|
@@ -1254,13 +1392,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1254
1392
|
upsertOrders = new Map();
|
|
1255
1393
|
refreshIds = [];
|
|
1256
1394
|
messages.forEach(function (msg, msgIndex) {
|
|
1257
|
-
var routeInfo =
|
|
1395
|
+
var routeInfo = _this14.resolveSyncMessageRoute(msg);
|
|
1258
1396
|
var hasBatchIds = routeInfo.hasBatchIds;
|
|
1259
1397
|
var singleId = routeInfo.singleId;
|
|
1260
1398
|
var hasSingleId = routeInfo.hasSingleId;
|
|
1261
|
-
var normalizedBody =
|
|
1399
|
+
var normalizedBody = _this14.normalizeOrderSyncPayload(msg.body || msg.data);
|
|
1262
1400
|
if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
|
|
1263
|
-
upsertOrders.set(
|
|
1401
|
+
upsertOrders.set(_this14.getIdKey(normalizedBody.order_id), normalizedBody);
|
|
1264
1402
|
return;
|
|
1265
1403
|
}
|
|
1266
1404
|
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));
|
|
@@ -1272,41 +1410,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1272
1410
|
refreshIdCount: uniqueRefreshIds.length
|
|
1273
1411
|
});
|
|
1274
1412
|
if (!(upsertList.length > 0)) {
|
|
1275
|
-
|
|
1413
|
+
_context14.next = 16;
|
|
1276
1414
|
break;
|
|
1277
1415
|
}
|
|
1278
|
-
|
|
1416
|
+
_context14.next = 16;
|
|
1279
1417
|
return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
|
|
1280
1418
|
case 16:
|
|
1281
1419
|
if (!(uniqueRefreshIds.length > 0)) {
|
|
1282
|
-
|
|
1420
|
+
_context14.next = 28;
|
|
1283
1421
|
break;
|
|
1284
1422
|
}
|
|
1285
1423
|
_this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
|
|
1286
1424
|
if (skipped.length > 0) {}
|
|
1287
1425
|
if (!(toFetch.length > 0)) {
|
|
1288
|
-
|
|
1426
|
+
_context14.next = 28;
|
|
1289
1427
|
break;
|
|
1290
1428
|
}
|
|
1291
|
-
|
|
1429
|
+
_context14.next = 22;
|
|
1292
1430
|
return this.fetchOrdersByHttp(toFetch);
|
|
1293
1431
|
case 22:
|
|
1294
|
-
freshOrders =
|
|
1432
|
+
freshOrders = _context14.sent;
|
|
1295
1433
|
if (!(freshOrders.length > 0)) {
|
|
1296
|
-
|
|
1434
|
+
_context14.next = 28;
|
|
1297
1435
|
break;
|
|
1298
1436
|
}
|
|
1299
|
-
|
|
1437
|
+
_context14.next = 26;
|
|
1300
1438
|
return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
|
|
1301
1439
|
case 26:
|
|
1302
|
-
|
|
1440
|
+
_context14.next = 28;
|
|
1303
1441
|
break;
|
|
1304
1442
|
case 28:
|
|
1305
1443
|
if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
|
|
1306
|
-
|
|
1444
|
+
_context14.next = 30;
|
|
1307
1445
|
break;
|
|
1308
1446
|
}
|
|
1309
|
-
return
|
|
1447
|
+
return _context14.abrupt("return");
|
|
1310
1448
|
case 30:
|
|
1311
1449
|
batchProcessEndAt = Date.now();
|
|
1312
1450
|
this.logInfo('processOrderSyncMessages-结束', {
|
|
@@ -1315,13 +1453,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1315
1453
|
batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
|
|
1316
1454
|
totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
|
|
1317
1455
|
});
|
|
1318
|
-
|
|
1456
|
+
_context14.next = 34;
|
|
1319
1457
|
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
1320
1458
|
case 34:
|
|
1321
1459
|
case "end":
|
|
1322
|
-
return
|
|
1460
|
+
return _context14.stop();
|
|
1323
1461
|
}
|
|
1324
|
-
},
|
|
1462
|
+
}, _callee14, this);
|
|
1325
1463
|
}));
|
|
1326
1464
|
function processOrderSyncMessages() {
|
|
1327
1465
|
return _processOrderSyncMessages.apply(this, arguments);
|
|
@@ -1342,29 +1480,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1342
1480
|
}, {
|
|
1343
1481
|
key: "fetchOrdersByHttp",
|
|
1344
1482
|
value: (function () {
|
|
1345
|
-
var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1483
|
+
var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(ids) {
|
|
1346
1484
|
var _orderList, orderList;
|
|
1347
|
-
return _regeneratorRuntime().wrap(function
|
|
1348
|
-
while (1) switch (
|
|
1485
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1486
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1349
1487
|
case 0:
|
|
1350
1488
|
if (!(!this.orderDataSource || ids.length === 0)) {
|
|
1351
|
-
|
|
1489
|
+
_context15.next = 2;
|
|
1352
1490
|
break;
|
|
1353
1491
|
}
|
|
1354
|
-
return
|
|
1492
|
+
return _context15.abrupt("return", []);
|
|
1355
1493
|
case 2:
|
|
1356
|
-
|
|
1494
|
+
_context15.prev = 2;
|
|
1357
1495
|
if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
|
|
1358
|
-
|
|
1496
|
+
_context15.next = 8;
|
|
1359
1497
|
break;
|
|
1360
1498
|
}
|
|
1361
|
-
|
|
1499
|
+
_context15.next = 6;
|
|
1362
1500
|
return this.orderDataSource.fetchOrdersByIds(ids);
|
|
1363
1501
|
case 6:
|
|
1364
|
-
_orderList =
|
|
1365
|
-
return
|
|
1502
|
+
_orderList = _context15.sent;
|
|
1503
|
+
return _context15.abrupt("return", _orderList || []);
|
|
1366
1504
|
case 8:
|
|
1367
|
-
|
|
1505
|
+
_context15.next = 10;
|
|
1368
1506
|
return this.orderDataSource.run({
|
|
1369
1507
|
http: {
|
|
1370
1508
|
query: {
|
|
@@ -1373,19 +1511,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1373
1511
|
}
|
|
1374
1512
|
});
|
|
1375
1513
|
case 10:
|
|
1376
|
-
orderList =
|
|
1377
|
-
return
|
|
1514
|
+
orderList = _context15.sent;
|
|
1515
|
+
return _context15.abrupt("return", orderList || []);
|
|
1378
1516
|
case 14:
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
return
|
|
1517
|
+
_context15.prev = 14;
|
|
1518
|
+
_context15.t0 = _context15["catch"](2);
|
|
1519
|
+
return _context15.abrupt("return", []);
|
|
1382
1520
|
case 17:
|
|
1383
1521
|
case "end":
|
|
1384
|
-
return
|
|
1522
|
+
return _context15.stop();
|
|
1385
1523
|
}
|
|
1386
|
-
},
|
|
1524
|
+
}, _callee15, this, [[2, 14]]);
|
|
1387
1525
|
}));
|
|
1388
|
-
function fetchOrdersByHttp(
|
|
1526
|
+
function fetchOrdersByHttp(_x8) {
|
|
1389
1527
|
return _fetchOrdersByHttp.apply(this, arguments);
|
|
1390
1528
|
}
|
|
1391
1529
|
return fetchOrdersByHttp;
|
|
@@ -1397,94 +1535,94 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1397
1535
|
}, {
|
|
1398
1536
|
key: "mergeOrdersToStore",
|
|
1399
1537
|
value: (function () {
|
|
1400
|
-
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1401
|
-
var
|
|
1402
|
-
var freshMap,
|
|
1403
|
-
return _regeneratorRuntime().wrap(function
|
|
1404
|
-
while (1) switch (
|
|
1538
|
+
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(freshOrders, source) {
|
|
1539
|
+
var _this15 = this;
|
|
1540
|
+
var freshMap, _iterator9, _step9, order, id, freshStorageKeyMap, _iterator10, _step10, _order2, storageKey, uniqueFreshCount, patchedOrders, mergeActions, updatedList, _iterator11, _step11, _order3, _id, insertCount, updateCount;
|
|
1541
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1542
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1405
1543
|
case 0:
|
|
1406
1544
|
this.logInfo('mergeOrdersToStore-开始', {
|
|
1407
1545
|
freshOrderCount: freshOrders.length,
|
|
1408
1546
|
storeOrderCountBefore: this.store.list.length
|
|
1409
1547
|
});
|
|
1410
1548
|
freshMap = new Map();
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1549
|
+
_iterator9 = _createForOfIteratorHelper(freshOrders);
|
|
1550
|
+
_context16.prev = 3;
|
|
1551
|
+
_iterator9.s();
|
|
1414
1552
|
case 5:
|
|
1415
|
-
if ((
|
|
1416
|
-
|
|
1553
|
+
if ((_step9 = _iterator9.n()).done) {
|
|
1554
|
+
_context16.next = 13;
|
|
1417
1555
|
break;
|
|
1418
1556
|
}
|
|
1419
|
-
order =
|
|
1557
|
+
order = _step9.value;
|
|
1420
1558
|
id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
1421
1559
|
if (!(id === undefined || id === null)) {
|
|
1422
|
-
|
|
1560
|
+
_context16.next = 10;
|
|
1423
1561
|
break;
|
|
1424
1562
|
}
|
|
1425
|
-
return
|
|
1563
|
+
return _context16.abrupt("continue", 11);
|
|
1426
1564
|
case 10:
|
|
1427
1565
|
freshMap.set(this.getIdKey(id), this.normalizeRemoteSyncedOrder(order));
|
|
1428
1566
|
case 11:
|
|
1429
|
-
|
|
1567
|
+
_context16.next = 5;
|
|
1430
1568
|
break;
|
|
1431
1569
|
case 13:
|
|
1432
|
-
|
|
1570
|
+
_context16.next = 18;
|
|
1433
1571
|
break;
|
|
1434
1572
|
case 15:
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1573
|
+
_context16.prev = 15;
|
|
1574
|
+
_context16.t0 = _context16["catch"](3);
|
|
1575
|
+
_iterator9.e(_context16.t0);
|
|
1438
1576
|
case 18:
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
return
|
|
1577
|
+
_context16.prev = 18;
|
|
1578
|
+
_iterator9.f();
|
|
1579
|
+
return _context16.finish(18);
|
|
1442
1580
|
case 21:
|
|
1443
1581
|
freshStorageKeyMap = new Map();
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1582
|
+
_iterator10 = _createForOfIteratorHelper(freshMap.values());
|
|
1583
|
+
_context16.prev = 23;
|
|
1584
|
+
_iterator10.s();
|
|
1447
1585
|
case 25:
|
|
1448
|
-
if ((
|
|
1449
|
-
|
|
1586
|
+
if ((_step10 = _iterator10.n()).done) {
|
|
1587
|
+
_context16.next = 33;
|
|
1450
1588
|
break;
|
|
1451
1589
|
}
|
|
1452
|
-
_order2 =
|
|
1590
|
+
_order2 = _step10.value;
|
|
1453
1591
|
storageKey = this.getOrderStorageKey(_order2);
|
|
1454
1592
|
if (storageKey) {
|
|
1455
|
-
|
|
1593
|
+
_context16.next = 30;
|
|
1456
1594
|
break;
|
|
1457
1595
|
}
|
|
1458
|
-
return
|
|
1596
|
+
return _context16.abrupt("continue", 31);
|
|
1459
1597
|
case 30:
|
|
1460
1598
|
freshStorageKeyMap.set(storageKey, _order2);
|
|
1461
1599
|
case 31:
|
|
1462
|
-
|
|
1600
|
+
_context16.next = 25;
|
|
1463
1601
|
break;
|
|
1464
1602
|
case 33:
|
|
1465
|
-
|
|
1603
|
+
_context16.next = 38;
|
|
1466
1604
|
break;
|
|
1467
1605
|
case 35:
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1606
|
+
_context16.prev = 35;
|
|
1607
|
+
_context16.t1 = _context16["catch"](23);
|
|
1608
|
+
_iterator10.e(_context16.t1);
|
|
1471
1609
|
case 38:
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
return
|
|
1610
|
+
_context16.prev = 38;
|
|
1611
|
+
_iterator10.f();
|
|
1612
|
+
return _context16.finish(38);
|
|
1475
1613
|
case 41:
|
|
1476
1614
|
uniqueFreshCount = freshMap.size;
|
|
1477
1615
|
patchedOrders = _toConsumableArray(freshMap.values());
|
|
1478
1616
|
mergeActions = {};
|
|
1479
1617
|
updatedList = this.store.list.map(function (order) {
|
|
1480
|
-
var storageKey =
|
|
1618
|
+
var storageKey = _this15.getOrderStorageKey(order);
|
|
1481
1619
|
if (storageKey && freshStorageKeyMap.has(storageKey)) {
|
|
1482
1620
|
var _fresh = freshStorageKeyMap.get(storageKey);
|
|
1483
1621
|
freshStorageKeyMap.delete(storageKey);
|
|
1484
1622
|
var freshId = _fresh.order_id;
|
|
1485
1623
|
if (freshId !== undefined && freshId !== null) {
|
|
1486
|
-
freshMap.delete(
|
|
1487
|
-
mergeActions[
|
|
1624
|
+
freshMap.delete(_this15.getIdKey(freshId));
|
|
1625
|
+
mergeActions[_this15.getIdKey(freshId)] = 'update';
|
|
1488
1626
|
} else {
|
|
1489
1627
|
mergeActions[storageKey] = 'update';
|
|
1490
1628
|
}
|
|
@@ -1492,17 +1630,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1492
1630
|
}
|
|
1493
1631
|
var id = order.order_id;
|
|
1494
1632
|
if (id === undefined || id === null) return order;
|
|
1495
|
-
var key =
|
|
1633
|
+
var key = _this15.getIdKey(id);
|
|
1496
1634
|
if (!freshMap.has(key)) return order;
|
|
1497
1635
|
var fresh = freshMap.get(key);
|
|
1498
1636
|
freshMap.delete(key);
|
|
1499
1637
|
mergeActions[key] = 'update';
|
|
1500
1638
|
return fresh;
|
|
1501
1639
|
});
|
|
1502
|
-
|
|
1640
|
+
_iterator11 = _createForOfIteratorHelper(freshMap.values());
|
|
1503
1641
|
try {
|
|
1504
|
-
for (
|
|
1505
|
-
_order3 =
|
|
1642
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
1643
|
+
_order3 = _step11.value;
|
|
1506
1644
|
_id = _order3.order_id;
|
|
1507
1645
|
if (_id !== undefined && _id !== null) {
|
|
1508
1646
|
mergeActions[this.getIdKey(_id)] = 'insert';
|
|
@@ -1510,9 +1648,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1510
1648
|
updatedList.push(_order3);
|
|
1511
1649
|
}
|
|
1512
1650
|
} catch (err) {
|
|
1513
|
-
|
|
1651
|
+
_iterator11.e(err);
|
|
1514
1652
|
} finally {
|
|
1515
|
-
|
|
1653
|
+
_iterator11.f();
|
|
1516
1654
|
}
|
|
1517
1655
|
insertCount = Object.values(mergeActions).filter(function (v) {
|
|
1518
1656
|
return v === 'insert';
|
|
@@ -1522,7 +1660,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1522
1660
|
}).length;
|
|
1523
1661
|
this.store.list = updatedList;
|
|
1524
1662
|
this.syncOrdersMap();
|
|
1525
|
-
|
|
1663
|
+
_context16.next = 53;
|
|
1526
1664
|
return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
|
|
1527
1665
|
case 53:
|
|
1528
1666
|
this.logInfo('mergeOrdersToStore-结束', {
|
|
@@ -1532,11 +1670,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1532
1670
|
this.emitOrdersChanged(patchedOrders, source);
|
|
1533
1671
|
case 55:
|
|
1534
1672
|
case "end":
|
|
1535
|
-
return
|
|
1673
|
+
return _context16.stop();
|
|
1536
1674
|
}
|
|
1537
|
-
},
|
|
1675
|
+
}, _callee16, this, [[3, 15, 18, 21], [23, 35, 38, 41]]);
|
|
1538
1676
|
}));
|
|
1539
|
-
function mergeOrdersToStore(
|
|
1677
|
+
function mergeOrdersToStore(_x9, _x10) {
|
|
1540
1678
|
return _mergeOrdersToStore.apply(this, arguments);
|
|
1541
1679
|
}
|
|
1542
1680
|
return mergeOrdersToStore;
|
|
@@ -1573,17 +1711,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1573
1711
|
key: "uniqueOrderIds",
|
|
1574
1712
|
value: function uniqueOrderIds(ids) {
|
|
1575
1713
|
var idMap = new Map();
|
|
1576
|
-
var
|
|
1577
|
-
|
|
1714
|
+
var _iterator12 = _createForOfIteratorHelper(ids),
|
|
1715
|
+
_step12;
|
|
1578
1716
|
try {
|
|
1579
|
-
for (
|
|
1580
|
-
var id =
|
|
1717
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
1718
|
+
var id = _step12.value;
|
|
1581
1719
|
idMap.set(this.getIdKey(id), id);
|
|
1582
1720
|
}
|
|
1583
1721
|
} catch (err) {
|
|
1584
|
-
|
|
1722
|
+
_iterator12.e(err);
|
|
1585
1723
|
} finally {
|
|
1586
|
-
|
|
1724
|
+
_iterator12.f();
|
|
1587
1725
|
}
|
|
1588
1726
|
return _toConsumableArray(idMap.values());
|
|
1589
1727
|
}
|
|
@@ -1595,12 +1733,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1595
1733
|
}, {
|
|
1596
1734
|
key: "isOrderLookupMatch",
|
|
1597
1735
|
value: function isOrderLookupMatch(order, lookupKey) {
|
|
1598
|
-
var
|
|
1736
|
+
var _this16 = this;
|
|
1599
1737
|
if (!order || !lookupKey) return false;
|
|
1600
1738
|
var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
|
|
1601
1739
|
return candidates.some(function (value) {
|
|
1602
1740
|
if (value === undefined || value === null || value === '') return false;
|
|
1603
|
-
return
|
|
1741
|
+
return _this16.getIdKey(value) === lookupKey;
|
|
1604
1742
|
});
|
|
1605
1743
|
}
|
|
1606
1744
|
|
|
@@ -1705,32 +1843,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1705
1843
|
}, {
|
|
1706
1844
|
key: "loadOrdersFromSQLite",
|
|
1707
1845
|
value: function () {
|
|
1708
|
-
var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1846
|
+
var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
1709
1847
|
var orders;
|
|
1710
|
-
return _regeneratorRuntime().wrap(function
|
|
1711
|
-
while (1) switch (
|
|
1848
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1849
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1712
1850
|
case 0:
|
|
1713
1851
|
if (this.dbManager) {
|
|
1714
|
-
|
|
1852
|
+
_context17.next = 2;
|
|
1715
1853
|
break;
|
|
1716
1854
|
}
|
|
1717
|
-
return
|
|
1855
|
+
return _context17.abrupt("return", []);
|
|
1718
1856
|
case 2:
|
|
1719
|
-
|
|
1720
|
-
|
|
1857
|
+
_context17.prev = 2;
|
|
1858
|
+
_context17.next = 5;
|
|
1721
1859
|
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
1722
1860
|
case 5:
|
|
1723
|
-
orders =
|
|
1724
|
-
return
|
|
1861
|
+
orders = _context17.sent;
|
|
1862
|
+
return _context17.abrupt("return", orders || []);
|
|
1725
1863
|
case 9:
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
return
|
|
1864
|
+
_context17.prev = 9;
|
|
1865
|
+
_context17.t0 = _context17["catch"](2);
|
|
1866
|
+
return _context17.abrupt("return", []);
|
|
1729
1867
|
case 12:
|
|
1730
1868
|
case "end":
|
|
1731
|
-
return
|
|
1869
|
+
return _context17.stop();
|
|
1732
1870
|
}
|
|
1733
|
-
},
|
|
1871
|
+
}, _callee17, this, [[2, 9]]);
|
|
1734
1872
|
}));
|
|
1735
1873
|
function loadOrdersFromSQLite() {
|
|
1736
1874
|
return _loadOrdersFromSQLite.apply(this, arguments);
|
|
@@ -1753,18 +1891,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1753
1891
|
}, {
|
|
1754
1892
|
key: "mergeRemoteSnapshotWithPendingOrders",
|
|
1755
1893
|
value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
|
|
1756
|
-
var
|
|
1894
|
+
var _this17 = this;
|
|
1757
1895
|
var merged = remoteOrders.map(function (order) {
|
|
1758
|
-
return
|
|
1896
|
+
return _this17.normalizeRemoteSyncedOrder(order);
|
|
1759
1897
|
});
|
|
1760
1898
|
var remoteStorageKeys = new Set(merged.map(function (order) {
|
|
1761
|
-
return
|
|
1899
|
+
return _this17.getOrderStorageKey(order);
|
|
1762
1900
|
}).filter(Boolean));
|
|
1763
|
-
var
|
|
1764
|
-
|
|
1901
|
+
var _iterator13 = _createForOfIteratorHelper(existingOrders),
|
|
1902
|
+
_step13;
|
|
1765
1903
|
try {
|
|
1766
|
-
for (
|
|
1767
|
-
var order =
|
|
1904
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
1905
|
+
var order = _step13.value;
|
|
1768
1906
|
if (!this.isPendingSyncOrder(order)) continue;
|
|
1769
1907
|
var storageKey = this.getOrderStorageKey(order);
|
|
1770
1908
|
if (!storageKey || remoteStorageKeys.has(storageKey)) continue;
|
|
@@ -1772,9 +1910,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1772
1910
|
remoteStorageKeys.add(storageKey);
|
|
1773
1911
|
}
|
|
1774
1912
|
} catch (err) {
|
|
1775
|
-
|
|
1913
|
+
_iterator13.e(err);
|
|
1776
1914
|
} finally {
|
|
1777
|
-
|
|
1915
|
+
_iterator13.f();
|
|
1778
1916
|
}
|
|
1779
1917
|
return merged;
|
|
1780
1918
|
}
|
|
@@ -1790,10 +1928,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1790
1928
|
}, {
|
|
1791
1929
|
key: "runInOrderSQLiteSaveQueue",
|
|
1792
1930
|
value: (function () {
|
|
1793
|
-
var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1931
|
+
var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(task) {
|
|
1794
1932
|
var queuedTask;
|
|
1795
|
-
return _regeneratorRuntime().wrap(function
|
|
1796
|
-
while (1) switch (
|
|
1933
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1934
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1797
1935
|
case 0:
|
|
1798
1936
|
queuedTask = this.orderSQLiteSaveQueue.then(task, task);
|
|
1799
1937
|
this.orderSQLiteSaveQueue = queuedTask.then(function () {
|
|
@@ -1801,14 +1939,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1801
1939
|
}, function () {
|
|
1802
1940
|
return undefined;
|
|
1803
1941
|
});
|
|
1804
|
-
return
|
|
1942
|
+
return _context18.abrupt("return", queuedTask);
|
|
1805
1943
|
case 3:
|
|
1806
1944
|
case "end":
|
|
1807
|
-
return
|
|
1945
|
+
return _context18.stop();
|
|
1808
1946
|
}
|
|
1809
|
-
},
|
|
1947
|
+
}, _callee18, this);
|
|
1810
1948
|
}));
|
|
1811
|
-
function runInOrderSQLiteSaveQueue(
|
|
1949
|
+
function runInOrderSQLiteSaveQueue(_x11) {
|
|
1812
1950
|
return _runInOrderSQLiteSaveQueue.apply(this, arguments);
|
|
1813
1951
|
}
|
|
1814
1952
|
return runInOrderSQLiteSaveQueue;
|
|
@@ -1823,108 +1961,108 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1823
1961
|
}, {
|
|
1824
1962
|
key: "patchOrdersInSQLite",
|
|
1825
1963
|
value: (function () {
|
|
1826
|
-
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1827
|
-
var
|
|
1964
|
+
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(orders, source) {
|
|
1965
|
+
var _this18 = this;
|
|
1828
1966
|
var mergeActions,
|
|
1829
1967
|
ordersSnapshot,
|
|
1830
1968
|
_this$filterRedundant2,
|
|
1831
1969
|
toWrite,
|
|
1832
1970
|
skipped,
|
|
1833
|
-
|
|
1834
|
-
return _regeneratorRuntime().wrap(function
|
|
1835
|
-
while (1) switch (
|
|
1971
|
+
_args20 = arguments;
|
|
1972
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1973
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1836
1974
|
case 0:
|
|
1837
|
-
mergeActions =
|
|
1975
|
+
mergeActions = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : {};
|
|
1838
1976
|
if (!(!this.dbManager || orders.length === 0)) {
|
|
1839
|
-
|
|
1977
|
+
_context20.next = 3;
|
|
1840
1978
|
break;
|
|
1841
1979
|
}
|
|
1842
|
-
return
|
|
1980
|
+
return _context20.abrupt("return");
|
|
1843
1981
|
case 3:
|
|
1844
1982
|
ordersSnapshot = cloneDeep(orders).filter(function (order) {
|
|
1845
|
-
return
|
|
1983
|
+
return _this18.getOrderStorageKey(order);
|
|
1846
1984
|
});
|
|
1847
1985
|
if (!(ordersSnapshot.length === 0)) {
|
|
1848
|
-
|
|
1986
|
+
_context20.next = 6;
|
|
1849
1987
|
break;
|
|
1850
1988
|
}
|
|
1851
|
-
return
|
|
1989
|
+
return _context20.abrupt("return");
|
|
1852
1990
|
case 6:
|
|
1853
1991
|
_this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
|
|
1854
1992
|
if (!(toWrite.length === 0)) {
|
|
1855
|
-
|
|
1993
|
+
_context20.next = 9;
|
|
1856
1994
|
break;
|
|
1857
1995
|
}
|
|
1858
|
-
return
|
|
1996
|
+
return _context20.abrupt("return");
|
|
1859
1997
|
case 9:
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1863
|
-
var writeMethod,
|
|
1864
|
-
return _regeneratorRuntime().wrap(function
|
|
1865
|
-
while (1) switch (
|
|
1998
|
+
_context20.prev = 9;
|
|
1999
|
+
_context20.next = 12;
|
|
2000
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
|
2001
|
+
var writeMethod, _iterator14, _step14, order;
|
|
2002
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
2003
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1866
2004
|
case 0:
|
|
1867
2005
|
writeMethod = 'none';
|
|
1868
|
-
|
|
2006
|
+
_this18.logInfo('patchOrdersInSQLite-开始', {
|
|
1869
2007
|
source: source,
|
|
1870
2008
|
count: toWrite.length,
|
|
1871
2009
|
dedupedCount: skipped.length
|
|
1872
2010
|
});
|
|
1873
|
-
if (!(typeof
|
|
1874
|
-
|
|
2011
|
+
if (!(typeof _this18.dbManager.bulkUpdate === 'function')) {
|
|
2012
|
+
_context19.next = 8;
|
|
1875
2013
|
break;
|
|
1876
2014
|
}
|
|
1877
2015
|
writeMethod = 'bulkUpdate';
|
|
1878
|
-
|
|
1879
|
-
return
|
|
2016
|
+
_context19.next = 6;
|
|
2017
|
+
return _this18.dbManager.bulkUpdate(INDEXDB_STORE_NAME, toWrite);
|
|
1880
2018
|
case 6:
|
|
1881
|
-
|
|
2019
|
+
_context19.next = 33;
|
|
1882
2020
|
break;
|
|
1883
2021
|
case 8:
|
|
1884
|
-
if (!(typeof
|
|
1885
|
-
|
|
2022
|
+
if (!(typeof _this18.dbManager.bulkAdd === 'function')) {
|
|
2023
|
+
_context19.next = 14;
|
|
1886
2024
|
break;
|
|
1887
2025
|
}
|
|
1888
2026
|
writeMethod = 'bulkAdd';
|
|
1889
|
-
|
|
1890
|
-
return
|
|
2027
|
+
_context19.next = 12;
|
|
2028
|
+
return _this18.dbManager.bulkAdd(INDEXDB_STORE_NAME, toWrite);
|
|
1891
2029
|
case 12:
|
|
1892
|
-
|
|
2030
|
+
_context19.next = 33;
|
|
1893
2031
|
break;
|
|
1894
2032
|
case 14:
|
|
1895
|
-
if (!(typeof
|
|
1896
|
-
|
|
2033
|
+
if (!(typeof _this18.dbManager.update === 'function')) {
|
|
2034
|
+
_context19.next = 33;
|
|
1897
2035
|
break;
|
|
1898
2036
|
}
|
|
1899
2037
|
writeMethod = 'update';
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
2038
|
+
_iterator14 = _createForOfIteratorHelper(toWrite);
|
|
2039
|
+
_context19.prev = 17;
|
|
2040
|
+
_iterator14.s();
|
|
1903
2041
|
case 19:
|
|
1904
|
-
if ((
|
|
1905
|
-
|
|
2042
|
+
if ((_step14 = _iterator14.n()).done) {
|
|
2043
|
+
_context19.next = 25;
|
|
1906
2044
|
break;
|
|
1907
2045
|
}
|
|
1908
|
-
order =
|
|
1909
|
-
|
|
1910
|
-
return
|
|
2046
|
+
order = _step14.value;
|
|
2047
|
+
_context19.next = 23;
|
|
2048
|
+
return _this18.dbManager.update(INDEXDB_STORE_NAME, order);
|
|
1911
2049
|
case 23:
|
|
1912
|
-
|
|
2050
|
+
_context19.next = 19;
|
|
1913
2051
|
break;
|
|
1914
2052
|
case 25:
|
|
1915
|
-
|
|
2053
|
+
_context19.next = 30;
|
|
1916
2054
|
break;
|
|
1917
2055
|
case 27:
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
2056
|
+
_context19.prev = 27;
|
|
2057
|
+
_context19.t0 = _context19["catch"](17);
|
|
2058
|
+
_iterator14.e(_context19.t0);
|
|
1921
2059
|
case 30:
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
return
|
|
2060
|
+
_context19.prev = 30;
|
|
2061
|
+
_iterator14.f();
|
|
2062
|
+
return _context19.finish(30);
|
|
1925
2063
|
case 33:
|
|
1926
|
-
|
|
1927
|
-
|
|
2064
|
+
_this18.recordRecentSqliteWrite(source, toWrite);
|
|
2065
|
+
_this18.logInfo('patchOrdersInSQLite-完成', {
|
|
1928
2066
|
source: source,
|
|
1929
2067
|
count: toWrite.length,
|
|
1930
2068
|
writeMethod: writeMethod,
|
|
@@ -1932,27 +2070,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1932
2070
|
});
|
|
1933
2071
|
case 35:
|
|
1934
2072
|
case "end":
|
|
1935
|
-
return
|
|
2073
|
+
return _context19.stop();
|
|
1936
2074
|
}
|
|
1937
|
-
},
|
|
2075
|
+
}, _callee19, null, [[17, 27, 30, 33]]);
|
|
1938
2076
|
})));
|
|
1939
2077
|
case 12:
|
|
1940
|
-
|
|
2078
|
+
_context20.next = 17;
|
|
1941
2079
|
break;
|
|
1942
2080
|
case 14:
|
|
1943
|
-
|
|
1944
|
-
|
|
2081
|
+
_context20.prev = 14;
|
|
2082
|
+
_context20.t0 = _context20["catch"](9);
|
|
1945
2083
|
this.logError('增量保存订单到 SQLite 失败', {
|
|
1946
|
-
error:
|
|
2084
|
+
error: _context20.t0 instanceof Error ? _context20.t0.message : String(_context20.t0),
|
|
1947
2085
|
orderCount: ordersSnapshot.length
|
|
1948
2086
|
});
|
|
1949
2087
|
case 17:
|
|
1950
2088
|
case "end":
|
|
1951
|
-
return
|
|
2089
|
+
return _context20.stop();
|
|
1952
2090
|
}
|
|
1953
|
-
},
|
|
2091
|
+
}, _callee20, this, [[9, 14]]);
|
|
1954
2092
|
}));
|
|
1955
|
-
function patchOrdersInSQLite(
|
|
2093
|
+
function patchOrdersInSQLite(_x12, _x13) {
|
|
1956
2094
|
return _patchOrdersInSQLite.apply(this, arguments);
|
|
1957
2095
|
}
|
|
1958
2096
|
return patchOrdersInSQLite;
|
|
@@ -1967,92 +2105,92 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1967
2105
|
}, {
|
|
1968
2106
|
key: "updateOrderInSQLite",
|
|
1969
2107
|
value: (function () {
|
|
1970
|
-
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1971
|
-
var
|
|
2108
|
+
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(order, source) {
|
|
2109
|
+
var _this19 = this;
|
|
1972
2110
|
var orderSnapshot, _orderSnapshot$order_3;
|
|
1973
|
-
return _regeneratorRuntime().wrap(function
|
|
1974
|
-
while (1) switch (
|
|
2111
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
2112
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1975
2113
|
case 0:
|
|
1976
2114
|
if (!(!this.dbManager || !this.getOrderStorageKey(order))) {
|
|
1977
|
-
|
|
2115
|
+
_context22.next = 2;
|
|
1978
2116
|
break;
|
|
1979
2117
|
}
|
|
1980
|
-
return
|
|
2118
|
+
return _context22.abrupt("return");
|
|
1981
2119
|
case 2:
|
|
1982
2120
|
orderSnapshot = cloneDeep(order);
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2121
|
+
_context22.prev = 3;
|
|
2122
|
+
_context22.next = 6;
|
|
2123
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
|
|
1986
2124
|
var _orderSnapshot$order_, _orderSnapshot$order_2;
|
|
1987
2125
|
var writeMethod;
|
|
1988
|
-
return _regeneratorRuntime().wrap(function
|
|
1989
|
-
while (1) switch (
|
|
2126
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
2127
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1990
2128
|
case 0:
|
|
1991
2129
|
writeMethod = 'none';
|
|
1992
|
-
|
|
2130
|
+
_this19.logInfo('updateOrderInSQLite-开始', {
|
|
1993
2131
|
source: source,
|
|
1994
2132
|
orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
|
|
1995
|
-
storageKey:
|
|
2133
|
+
storageKey: _this19.getOrderStorageKey(orderSnapshot)
|
|
1996
2134
|
});
|
|
1997
|
-
if (!(typeof
|
|
1998
|
-
|
|
2135
|
+
if (!(typeof _this19.dbManager.update === 'function')) {
|
|
2136
|
+
_context21.next = 8;
|
|
1999
2137
|
break;
|
|
2000
2138
|
}
|
|
2001
2139
|
writeMethod = 'update';
|
|
2002
|
-
|
|
2003
|
-
return
|
|
2140
|
+
_context21.next = 6;
|
|
2141
|
+
return _this19.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
|
|
2004
2142
|
case 6:
|
|
2005
|
-
|
|
2143
|
+
_context21.next = 18;
|
|
2006
2144
|
break;
|
|
2007
2145
|
case 8:
|
|
2008
|
-
if (!(typeof
|
|
2009
|
-
|
|
2146
|
+
if (!(typeof _this19.dbManager.bulkUpdate === 'function')) {
|
|
2147
|
+
_context21.next = 14;
|
|
2010
2148
|
break;
|
|
2011
2149
|
}
|
|
2012
2150
|
writeMethod = 'bulkUpdate';
|
|
2013
|
-
|
|
2014
|
-
return
|
|
2151
|
+
_context21.next = 12;
|
|
2152
|
+
return _this19.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2015
2153
|
case 12:
|
|
2016
|
-
|
|
2154
|
+
_context21.next = 18;
|
|
2017
2155
|
break;
|
|
2018
2156
|
case 14:
|
|
2019
|
-
if (!(typeof
|
|
2020
|
-
|
|
2157
|
+
if (!(typeof _this19.dbManager.bulkAdd === 'function')) {
|
|
2158
|
+
_context21.next = 18;
|
|
2021
2159
|
break;
|
|
2022
2160
|
}
|
|
2023
2161
|
writeMethod = 'bulkAdd';
|
|
2024
|
-
|
|
2025
|
-
return
|
|
2162
|
+
_context21.next = 18;
|
|
2163
|
+
return _this19.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2026
2164
|
case 18:
|
|
2027
|
-
|
|
2028
|
-
|
|
2165
|
+
_this19.recordRecentSqliteWrite(source, [orderSnapshot]);
|
|
2166
|
+
_this19.logInfo('updateOrderInSQLite-完成', {
|
|
2029
2167
|
source: source,
|
|
2030
2168
|
orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
|
|
2031
2169
|
writeMethod: writeMethod
|
|
2032
2170
|
});
|
|
2033
2171
|
case 20:
|
|
2034
2172
|
case "end":
|
|
2035
|
-
return
|
|
2173
|
+
return _context21.stop();
|
|
2036
2174
|
}
|
|
2037
|
-
},
|
|
2175
|
+
}, _callee21);
|
|
2038
2176
|
})));
|
|
2039
2177
|
case 6:
|
|
2040
|
-
|
|
2178
|
+
_context22.next = 11;
|
|
2041
2179
|
break;
|
|
2042
2180
|
case 8:
|
|
2043
|
-
|
|
2044
|
-
|
|
2181
|
+
_context22.prev = 8;
|
|
2182
|
+
_context22.t0 = _context22["catch"](3);
|
|
2045
2183
|
this.logError('单条保存订单到 SQLite 失败', {
|
|
2046
|
-
error:
|
|
2184
|
+
error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0),
|
|
2047
2185
|
orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
|
|
2048
2186
|
});
|
|
2049
2187
|
case 11:
|
|
2050
2188
|
case "end":
|
|
2051
|
-
return
|
|
2189
|
+
return _context22.stop();
|
|
2052
2190
|
}
|
|
2053
|
-
},
|
|
2191
|
+
}, _callee22, this, [[3, 8]]);
|
|
2054
2192
|
}));
|
|
2055
|
-
function updateOrderInSQLite(
|
|
2193
|
+
function updateOrderInSQLite(_x14, _x15) {
|
|
2056
2194
|
return _updateOrderInSQLite.apply(this, arguments);
|
|
2057
2195
|
}
|
|
2058
2196
|
return updateOrderInSQLite;
|
|
@@ -2067,90 +2205,98 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2067
2205
|
}, {
|
|
2068
2206
|
key: "replaceOrdersSnapshotInSQLite",
|
|
2069
2207
|
value: (function () {
|
|
2070
|
-
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2071
|
-
var
|
|
2072
|
-
var remoteSnapshot;
|
|
2073
|
-
return _regeneratorRuntime().wrap(function
|
|
2074
|
-
while (1) switch (
|
|
2208
|
+
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orderList, source) {
|
|
2209
|
+
var _this20 = this;
|
|
2210
|
+
var remoteSnapshot, mergedSnapshot;
|
|
2211
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
2212
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
2075
2213
|
case 0:
|
|
2076
2214
|
if (this.dbManager) {
|
|
2077
|
-
|
|
2215
|
+
_context24.next = 2;
|
|
2078
2216
|
break;
|
|
2079
2217
|
}
|
|
2080
|
-
return
|
|
2218
|
+
return _context24.abrupt("return", orderList.map(function (order) {
|
|
2219
|
+
return _this20.normalizeRemoteSyncedOrder(order);
|
|
2220
|
+
}));
|
|
2081
2221
|
case 2:
|
|
2082
2222
|
remoteSnapshot = cloneDeep(orderList);
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2223
|
+
mergedSnapshot = remoteSnapshot.map(function (order) {
|
|
2224
|
+
return _this20.normalizeRemoteSyncedOrder(order);
|
|
2225
|
+
});
|
|
2226
|
+
_context24.prev = 4;
|
|
2227
|
+
_context24.next = 7;
|
|
2228
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
|
|
2086
2229
|
var existingOrders, orderListSnapshot;
|
|
2087
|
-
return _regeneratorRuntime().wrap(function
|
|
2088
|
-
while (1) switch (
|
|
2230
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
2231
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
2089
2232
|
case 0:
|
|
2090
|
-
if (!(typeof
|
|
2091
|
-
|
|
2233
|
+
if (!(typeof _this20.dbManager.getAll === 'function')) {
|
|
2234
|
+
_context23.next = 6;
|
|
2092
2235
|
break;
|
|
2093
2236
|
}
|
|
2094
|
-
|
|
2095
|
-
return
|
|
2237
|
+
_context23.next = 3;
|
|
2238
|
+
return _this20.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
2096
2239
|
case 3:
|
|
2097
|
-
|
|
2098
|
-
|
|
2240
|
+
_context23.t0 = _context23.sent;
|
|
2241
|
+
_context23.next = 7;
|
|
2099
2242
|
break;
|
|
2100
2243
|
case 6:
|
|
2101
|
-
|
|
2244
|
+
_context23.t0 = [];
|
|
2102
2245
|
case 7:
|
|
2103
|
-
existingOrders =
|
|
2104
|
-
orderListSnapshot =
|
|
2105
|
-
|
|
2246
|
+
existingOrders = _context23.t0;
|
|
2247
|
+
orderListSnapshot = _this20.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, existingOrders || []);
|
|
2248
|
+
mergedSnapshot = orderListSnapshot;
|
|
2249
|
+
_this20.logInfo('replaceOrdersSnapshotInSQLite-开始', {
|
|
2106
2250
|
source: source,
|
|
2107
2251
|
count: orderListSnapshot.length,
|
|
2108
2252
|
remoteCount: remoteSnapshot.length,
|
|
2109
2253
|
preservedPendingCount: orderListSnapshot.length - remoteSnapshot.length
|
|
2110
2254
|
});
|
|
2111
|
-
|
|
2112
|
-
return
|
|
2113
|
-
case
|
|
2114
|
-
|
|
2255
|
+
_context23.next = 13;
|
|
2256
|
+
return _this20.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2257
|
+
case 13:
|
|
2258
|
+
_this20.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
|
|
2115
2259
|
count: orderListSnapshot.length
|
|
2116
2260
|
});
|
|
2117
2261
|
if (!(orderListSnapshot.length === 0)) {
|
|
2118
|
-
|
|
2262
|
+
_context23.next = 16;
|
|
2119
2263
|
break;
|
|
2120
2264
|
}
|
|
2121
|
-
return
|
|
2122
|
-
case
|
|
2123
|
-
|
|
2124
|
-
return
|
|
2125
|
-
case
|
|
2126
|
-
|
|
2127
|
-
|
|
2265
|
+
return _context23.abrupt("return");
|
|
2266
|
+
case 16:
|
|
2267
|
+
_context23.next = 18;
|
|
2268
|
+
return _this20.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderListSnapshot);
|
|
2269
|
+
case 18:
|
|
2270
|
+
_this20.recordRecentSqliteWrite(source, orderListSnapshot);
|
|
2271
|
+
_this20.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
|
|
2128
2272
|
source: source,
|
|
2129
2273
|
count: orderListSnapshot.length
|
|
2130
2274
|
});
|
|
2131
|
-
case
|
|
2275
|
+
case 20:
|
|
2132
2276
|
case "end":
|
|
2133
|
-
return
|
|
2277
|
+
return _context23.stop();
|
|
2134
2278
|
}
|
|
2135
|
-
},
|
|
2279
|
+
}, _callee23);
|
|
2136
2280
|
})));
|
|
2137
|
-
case
|
|
2138
|
-
|
|
2281
|
+
case 7:
|
|
2282
|
+
_context24.next = 12;
|
|
2139
2283
|
break;
|
|
2140
|
-
case
|
|
2141
|
-
|
|
2142
|
-
|
|
2284
|
+
case 9:
|
|
2285
|
+
_context24.prev = 9;
|
|
2286
|
+
_context24.t0 = _context24["catch"](4);
|
|
2143
2287
|
this.logError('全量保存订单到 SQLite 失败', {
|
|
2144
|
-
error:
|
|
2288
|
+
error: _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0),
|
|
2145
2289
|
orderList: remoteSnapshot.length
|
|
2146
2290
|
});
|
|
2147
|
-
case
|
|
2291
|
+
case 12:
|
|
2292
|
+
return _context24.abrupt("return", mergedSnapshot);
|
|
2293
|
+
case 13:
|
|
2148
2294
|
case "end":
|
|
2149
|
-
return
|
|
2295
|
+
return _context24.stop();
|
|
2150
2296
|
}
|
|
2151
|
-
},
|
|
2297
|
+
}, _callee24, this, [[4, 9]]);
|
|
2152
2298
|
}));
|
|
2153
|
-
function replaceOrdersSnapshotInSQLite(
|
|
2299
|
+
function replaceOrdersSnapshotInSQLite(_x16, _x17) {
|
|
2154
2300
|
return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
|
|
2155
2301
|
}
|
|
2156
2302
|
return replaceOrdersSnapshotInSQLite;
|
|
@@ -2165,39 +2311,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2165
2311
|
}, {
|
|
2166
2312
|
key: "clear",
|
|
2167
2313
|
value: (function () {
|
|
2168
|
-
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2169
|
-
var
|
|
2170
|
-
return _regeneratorRuntime().wrap(function
|
|
2171
|
-
while (1) switch (
|
|
2314
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
|
|
2315
|
+
var _this21 = this;
|
|
2316
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
2317
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
2172
2318
|
case 0:
|
|
2173
2319
|
this.store.list = [];
|
|
2174
2320
|
this.store.map = new Map();
|
|
2175
2321
|
this.resourceIdIndex.clear();
|
|
2176
2322
|
if (!this.dbManager) {
|
|
2177
|
-
|
|
2323
|
+
_context26.next = 6;
|
|
2178
2324
|
break;
|
|
2179
2325
|
}
|
|
2180
|
-
|
|
2181
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2182
|
-
return _regeneratorRuntime().wrap(function
|
|
2183
|
-
while (1) switch (
|
|
2326
|
+
_context26.next = 6;
|
|
2327
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
2328
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
2329
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
2184
2330
|
case 0:
|
|
2185
|
-
|
|
2186
|
-
return
|
|
2331
|
+
_context25.next = 2;
|
|
2332
|
+
return _this21.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2187
2333
|
case 2:
|
|
2188
2334
|
case "end":
|
|
2189
|
-
return
|
|
2335
|
+
return _context25.stop();
|
|
2190
2336
|
}
|
|
2191
|
-
},
|
|
2337
|
+
}, _callee25);
|
|
2192
2338
|
})));
|
|
2193
2339
|
case 6:
|
|
2194
2340
|
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
|
|
2195
2341
|
this.emitOrdersChanged([], 'clear');
|
|
2196
2342
|
case 8:
|
|
2197
2343
|
case "end":
|
|
2198
|
-
return
|
|
2344
|
+
return _context26.stop();
|
|
2199
2345
|
}
|
|
2200
|
-
},
|
|
2346
|
+
}, _callee26, this);
|
|
2201
2347
|
}));
|
|
2202
2348
|
function clear() {
|
|
2203
2349
|
return _clear.apply(this, arguments);
|