@pisell/pisellos 2.3.30 → 2.3.32
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 +50 -0
- package/dist/model/strategy/adapter/dataVariant/adapter.js +167 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +780 -0
- package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
- package/dist/model/strategy/adapter/dataVariant/examples.js +277 -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 +148 -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/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/Discount/index.d.ts +5 -2
- package/dist/modules/Discount/index.js +30 -7
- package/dist/modules/Discount/types.d.ts +4 -0
- package/dist/modules/Order/index.d.ts +2 -1
- package/dist/modules/Order/index.js +25 -11
- package/dist/modules/Order/types.d.ts +2 -0
- 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/server/index.d.ts +50 -0
- package/dist/server/index.js +1095 -849
- package/dist/server/modules/order/index.d.ts +8 -3
- package/dist/server/modules/order/index.js +765 -675
- package/dist/server/modules/products/index.d.ts +26 -7
- package/dist/server/modules/products/index.js +167 -76
- package/dist/server/modules/products/types.d.ts +14 -0
- package/dist/solution/BaseSales/index.d.ts +2 -0
- package/dist/solution/BaseSales/index.js +23 -13
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/types.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +15 -14
- package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
- package/lib/model/strategy/adapter/dataVariant/adapter.js +149 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +583 -0
- package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
- package/lib/model/strategy/adapter/dataVariant/examples.js +293 -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 +148 -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 +0 -49
- package/lib/modules/Discount/index.d.ts +5 -2
- package/lib/modules/Discount/index.js +23 -3
- package/lib/modules/Discount/types.d.ts +4 -0
- package/lib/modules/Order/index.d.ts +2 -1
- package/lib/modules/Order/index.js +13 -1
- package/lib/modules/Order/types.d.ts +2 -0
- 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/server/index.d.ts +50 -0
- package/lib/server/index.js +206 -29
- package/lib/server/modules/order/index.d.ts +8 -3
- package/lib/server/modules/order/index.js +152 -43
- package/lib/server/modules/products/index.d.ts +26 -7
- package/lib/server/modules/products/index.js +114 -35
- package/lib/server/modules/products/types.d.ts +14 -0
- package/lib/solution/BaseSales/index.d.ts +2 -0
- package/lib/solution/BaseSales/index.js +12 -3
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/types.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +2 -1
- package/package.json +1 -1
|
@@ -139,8 +139,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
139
139
|
key: "initialize",
|
|
140
140
|
value: function () {
|
|
141
141
|
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(core, options) {
|
|
142
|
-
var _options$initialState
|
|
143
|
-
_this3 = this;
|
|
142
|
+
var _options$initialState;
|
|
144
143
|
var appPlugin, app;
|
|
145
144
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
146
145
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -157,9 +156,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
157
156
|
this.updateCreateStore();
|
|
158
157
|
}
|
|
159
158
|
if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
|
|
160
|
-
this.store.list = options.initialState.list
|
|
161
|
-
return _this3.normalizeOrderForMemoryList(order);
|
|
162
|
-
});
|
|
159
|
+
this.store.list = this.normalizeOrdersForMemoryList(options.initialState.list, 'initialState');
|
|
163
160
|
this.syncOrdersMap();
|
|
164
161
|
this.emitOrdersChanged([], 'initialState');
|
|
165
162
|
} else {
|
|
@@ -602,62 +599,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
602
599
|
}, {
|
|
603
600
|
key: "preload",
|
|
604
601
|
value: function () {
|
|
605
|
-
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
606
|
-
var
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
602
|
+
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
603
|
+
var orders;
|
|
604
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
605
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
610
606
|
case 0:
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
// if (cachedOrders.length > 0 && hasPulledInCurrentWindow) {
|
|
614
|
-
// this.store.list = cloneDeep(cachedOrders)
|
|
615
|
-
// this.syncOrdersMap()
|
|
616
|
-
// this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list)
|
|
617
|
-
// return
|
|
618
|
-
// }
|
|
619
|
-
// if (hasPulledInCurrentWindow) {
|
|
620
|
-
// this.logInfo('当天已完成全量订单拉取,跳过本次全量拉取', {
|
|
621
|
-
// lastFullFetchAt: this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY),
|
|
622
|
-
// })
|
|
623
|
-
// return
|
|
624
|
-
// }
|
|
625
|
-
getData = /*#__PURE__*/function () {
|
|
626
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
627
|
-
var orders;
|
|
628
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
629
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
630
|
-
case 0:
|
|
631
|
-
_context3.next = 2;
|
|
632
|
-
return _this4.loadOrdersByServer();
|
|
633
|
-
case 2:
|
|
634
|
-
orders = _context3.sent;
|
|
635
|
-
if (!(orders.length === 0)) {
|
|
636
|
-
_context3.next = 5;
|
|
637
|
-
break;
|
|
638
|
-
}
|
|
639
|
-
return _context3.abrupt("return");
|
|
640
|
-
case 5:
|
|
641
|
-
_this4.store.list = cloneDeep(orders);
|
|
642
|
-
_this4.syncOrdersMap();
|
|
643
|
-
_this4.emitOrdersChanged([], 'preload');
|
|
644
|
-
_this4.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
645
|
-
case 9:
|
|
646
|
-
case "end":
|
|
647
|
-
return _context3.stop();
|
|
648
|
-
}
|
|
649
|
-
}, _callee3);
|
|
650
|
-
}));
|
|
651
|
-
return function getData() {
|
|
652
|
-
return _ref.apply(this, arguments);
|
|
653
|
-
};
|
|
654
|
-
}();
|
|
655
|
-
getData();
|
|
607
|
+
_context3.next = 2;
|
|
608
|
+
return this.loadOrdersByServer();
|
|
656
609
|
case 2:
|
|
610
|
+
orders = _context3.sent;
|
|
611
|
+
this.store.list = cloneDeep(orders);
|
|
612
|
+
this.syncOrdersMap();
|
|
613
|
+
_context3.next = 7;
|
|
614
|
+
return this.emitOrdersChanged([], 'preload');
|
|
615
|
+
case 7:
|
|
616
|
+
_context3.next = 9;
|
|
617
|
+
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
618
|
+
case 9:
|
|
657
619
|
case "end":
|
|
658
|
-
return
|
|
620
|
+
return _context3.stop();
|
|
659
621
|
}
|
|
660
|
-
},
|
|
622
|
+
}, _callee3, this);
|
|
661
623
|
}));
|
|
662
624
|
function preload() {
|
|
663
625
|
return _preload.apply(this, arguments);
|
|
@@ -707,20 +669,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
707
669
|
}, {
|
|
708
670
|
key: "getLocalOrderFromMemoryByLookup",
|
|
709
671
|
value: function getLocalOrderFromMemoryByLookup(lookup) {
|
|
710
|
-
var
|
|
672
|
+
var _this3 = this;
|
|
711
673
|
var key = this.getIdKey(lookup);
|
|
712
674
|
var memoryOrderById = this.store.map.get(key);
|
|
713
675
|
if (memoryOrderById) return memoryOrderById;
|
|
714
676
|
var memoryOrder = this.store.list.find(function (order) {
|
|
715
|
-
return
|
|
677
|
+
return _this3.isOrderLookupMatch(order, key);
|
|
716
678
|
});
|
|
717
679
|
return memoryOrder || null;
|
|
718
680
|
}
|
|
719
681
|
}, {
|
|
720
682
|
key: "getLocalOrderByLookup",
|
|
721
683
|
value: function () {
|
|
722
|
-
var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
723
|
-
var
|
|
684
|
+
var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(lookup) {
|
|
685
|
+
var _this4 = this;
|
|
724
686
|
var options,
|
|
725
687
|
key,
|
|
726
688
|
logContext,
|
|
@@ -729,11 +691,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
729
691
|
orders,
|
|
730
692
|
localOrder,
|
|
731
693
|
normalizedOrder,
|
|
732
|
-
|
|
733
|
-
return _regeneratorRuntime().wrap(function
|
|
734
|
-
while (1) switch (
|
|
694
|
+
_args4 = arguments;
|
|
695
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
696
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
735
697
|
case 0:
|
|
736
|
-
options =
|
|
698
|
+
options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
|
|
737
699
|
key = this.getIdKey(lookup);
|
|
738
700
|
logContext = {
|
|
739
701
|
operation_id: options.operationId,
|
|
@@ -745,38 +707,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
745
707
|
}
|
|
746
708
|
memoryOrderById = this.store.map.get(key);
|
|
747
709
|
if (!memoryOrderById) {
|
|
748
|
-
|
|
710
|
+
_context4.next = 8;
|
|
749
711
|
break;
|
|
750
712
|
}
|
|
751
713
|
if (options.operationId) {
|
|
752
714
|
this.logInfo('getLocalOrderByLookup-localPayment-命中内存映射', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrderById)));
|
|
753
715
|
}
|
|
754
|
-
return
|
|
716
|
+
return _context4.abrupt("return", memoryOrderById);
|
|
755
717
|
case 8:
|
|
756
718
|
memoryOrder = this.store.list.find(function (order) {
|
|
757
|
-
return
|
|
719
|
+
return _this4.isOrderLookupMatch(order, key);
|
|
758
720
|
});
|
|
759
721
|
if (!memoryOrder) {
|
|
760
|
-
|
|
722
|
+
_context4.next = 12;
|
|
761
723
|
break;
|
|
762
724
|
}
|
|
763
725
|
if (options.operationId) {
|
|
764
726
|
this.logInfo('getLocalOrderByLookup-localPayment-命中内存列表', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrder)));
|
|
765
727
|
}
|
|
766
|
-
return
|
|
728
|
+
return _context4.abrupt("return", memoryOrder);
|
|
767
729
|
case 12:
|
|
768
730
|
if (options.operationId) {
|
|
769
731
|
this.logInfo('getLocalOrderByLookup-localPayment-开始读取SQLite', logContext);
|
|
770
732
|
}
|
|
771
|
-
|
|
733
|
+
_context4.next = 15;
|
|
772
734
|
return this.loadOrdersFromSQLite();
|
|
773
735
|
case 15:
|
|
774
|
-
orders =
|
|
736
|
+
orders = _context4.sent;
|
|
775
737
|
localOrder = orders.find(function (order) {
|
|
776
|
-
return
|
|
738
|
+
return _this4.isOrderLookupMatch(order, key);
|
|
777
739
|
});
|
|
778
740
|
if (localOrder) {
|
|
779
|
-
|
|
741
|
+
_context4.next = 20;
|
|
780
742
|
break;
|
|
781
743
|
}
|
|
782
744
|
if (options.operationId) {
|
|
@@ -784,11 +746,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
784
746
|
sqlite_order_count: orders.length
|
|
785
747
|
}));
|
|
786
748
|
}
|
|
787
|
-
return
|
|
749
|
+
return _context4.abrupt("return", null);
|
|
788
750
|
case 20:
|
|
789
|
-
this.store.list =
|
|
790
|
-
return _this6.normalizeOrderForMemoryList(order);
|
|
791
|
-
});
|
|
751
|
+
this.store.list = this.normalizeOrdersForMemoryList(orders, 'getLocalOrderByLookup.sqliteMemory');
|
|
792
752
|
this.syncOrdersMap();
|
|
793
753
|
normalizedOrder = this.normalizeOrderForMemoryList(localOrder);
|
|
794
754
|
if (options.operationId) {
|
|
@@ -796,12 +756,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
796
756
|
sqlite_order_count: orders.length
|
|
797
757
|
}, this.buildLocalPaymentOrderLogContext(normalizedOrder)));
|
|
798
758
|
}
|
|
799
|
-
return
|
|
759
|
+
return _context4.abrupt("return", normalizedOrder);
|
|
800
760
|
case 25:
|
|
801
761
|
case "end":
|
|
802
|
-
return
|
|
762
|
+
return _context4.stop();
|
|
803
763
|
}
|
|
804
|
-
},
|
|
764
|
+
}, _callee4, this);
|
|
805
765
|
}));
|
|
806
766
|
function getLocalOrderByLookup(_x3) {
|
|
807
767
|
return _getLocalOrderByLookup.apply(this, arguments);
|
|
@@ -811,10 +771,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
811
771
|
}, {
|
|
812
772
|
key: "getLocalPayment",
|
|
813
773
|
value: function () {
|
|
814
|
-
var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
774
|
+
var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
|
|
815
775
|
var logContext, order, payments, match;
|
|
816
|
-
return _regeneratorRuntime().wrap(function
|
|
817
|
-
while (1) switch (
|
|
776
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
777
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
818
778
|
case 0:
|
|
819
779
|
logContext = {
|
|
820
780
|
operation_id: params.operationId,
|
|
@@ -822,54 +782,54 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
822
782
|
payment_number: params.paymentNumber
|
|
823
783
|
};
|
|
824
784
|
this.logInfo('getLocalPayment-开始', logContext);
|
|
825
|
-
|
|
826
|
-
|
|
785
|
+
_context5.prev = 2;
|
|
786
|
+
_context5.next = 5;
|
|
827
787
|
return this.getLocalOrderByLookup(params.saleId, {
|
|
828
788
|
operationId: params.operationId
|
|
829
789
|
});
|
|
830
790
|
case 5:
|
|
831
|
-
order =
|
|
791
|
+
order = _context5.sent;
|
|
832
792
|
if (order) {
|
|
833
|
-
|
|
793
|
+
_context5.next = 9;
|
|
834
794
|
break;
|
|
835
795
|
}
|
|
836
796
|
this.logWarning('getLocalPayment-订单未命中', logContext);
|
|
837
|
-
return
|
|
797
|
+
return _context5.abrupt("return", null);
|
|
838
798
|
case 9:
|
|
839
799
|
payments = order.payments || [];
|
|
840
800
|
match = resolveOrderPaymentIdentity(payments, params.paymentNumber, 'compat');
|
|
841
801
|
if (match) {
|
|
842
|
-
|
|
802
|
+
_context5.next = 14;
|
|
843
803
|
break;
|
|
844
804
|
}
|
|
845
805
|
this.logWarning('getLocalPayment-支付项未命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
|
|
846
806
|
payments: payments
|
|
847
807
|
}));
|
|
848
|
-
return
|
|
808
|
+
return _context5.abrupt("return", null);
|
|
849
809
|
case 14:
|
|
850
810
|
this.logInfo('getLocalPayment-支付项命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
|
|
851
811
|
matched_by: match.matchedBy,
|
|
852
812
|
payment_index: match.index,
|
|
853
813
|
payment: match.payment
|
|
854
814
|
}));
|
|
855
|
-
return
|
|
815
|
+
return _context5.abrupt("return", {
|
|
856
816
|
order: order,
|
|
857
817
|
payment: match.payment,
|
|
858
818
|
paymentIndex: match.index,
|
|
859
819
|
matchedBy: match.matchedBy
|
|
860
820
|
});
|
|
861
821
|
case 18:
|
|
862
|
-
|
|
863
|
-
|
|
822
|
+
_context5.prev = 18;
|
|
823
|
+
_context5.t0 = _context5["catch"](2);
|
|
864
824
|
this.logError('getLocalPayment-查询失败', _objectSpread(_objectSpread({}, logContext), {}, {
|
|
865
|
-
error:
|
|
825
|
+
error: _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0)
|
|
866
826
|
}));
|
|
867
|
-
throw
|
|
827
|
+
throw _context5.t0;
|
|
868
828
|
case 22:
|
|
869
829
|
case "end":
|
|
870
|
-
return
|
|
830
|
+
return _context5.stop();
|
|
871
831
|
}
|
|
872
|
-
},
|
|
832
|
+
}, _callee5, this, [[2, 18]]);
|
|
873
833
|
}));
|
|
874
834
|
function getLocalPayment(_x4) {
|
|
875
835
|
return _getLocalPayment.apply(this, arguments);
|
|
@@ -879,10 +839,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
879
839
|
}, {
|
|
880
840
|
key: "updateLocalPayment",
|
|
881
841
|
value: function () {
|
|
882
|
-
var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
883
|
-
var logContext, found, previousPayment, nextPayment, nextOrder, paymentContext, targetIndex, previousList, storageOrder, _storageOrder$order_i, _storageOrder$order_i2, _storageOrder$order_i3;
|
|
884
|
-
return _regeneratorRuntime().wrap(function
|
|
885
|
-
while (1) switch (
|
|
842
|
+
var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
|
|
843
|
+
var logContext, found, previousPayment, nextPayment, nextOrder, paymentContext, targetIndex, shouldKeepInMemory, previousList, storageOrder, _storageOrder$order_i, _storageOrder$order_i2, _storageOrder$order_i3;
|
|
844
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
845
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
886
846
|
case 0:
|
|
887
847
|
logContext = {
|
|
888
848
|
operation_id: params.operationId,
|
|
@@ -891,16 +851,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
891
851
|
incoming_payment_update: params.updates
|
|
892
852
|
};
|
|
893
853
|
this.logInfo('updateLocalPayment-开始', logContext);
|
|
894
|
-
|
|
854
|
+
_context6.next = 4;
|
|
895
855
|
return this.getLocalPayment(params);
|
|
896
856
|
case 4:
|
|
897
|
-
found =
|
|
857
|
+
found = _context6.sent;
|
|
898
858
|
if (found) {
|
|
899
|
-
|
|
859
|
+
_context6.next = 8;
|
|
900
860
|
break;
|
|
901
861
|
}
|
|
902
862
|
this.logWarning('updateLocalPayment-支付项未命中', logContext);
|
|
903
|
-
return
|
|
863
|
+
return _context6.abrupt("return", null);
|
|
904
864
|
case 8:
|
|
905
865
|
previousPayment = cloneDeep(found.payment);
|
|
906
866
|
nextPayment = mergeOrderPaymentRecord(found.payment, _objectSpread(_objectSpread({}, params.updates), {}, {
|
|
@@ -921,58 +881,65 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
921
881
|
});
|
|
922
882
|
this.logInfo('updateLocalPayment-支付项合并完成', paymentContext);
|
|
923
883
|
targetIndex = this.findOrderIndexByIdentity(this.store.list, found.order);
|
|
924
|
-
|
|
925
|
-
|
|
884
|
+
shouldKeepInMemory = this.shouldKeepOrderInMemory(nextOrder);
|
|
885
|
+
if (!(targetIndex < 0 && shouldKeepInMemory)) {
|
|
886
|
+
_context6.next = 18;
|
|
926
887
|
break;
|
|
927
888
|
}
|
|
928
889
|
this.logError('updateLocalPayment-订单Store索引未命中', paymentContext);
|
|
929
|
-
return
|
|
930
|
-
case
|
|
890
|
+
return _context6.abrupt("return", null);
|
|
891
|
+
case 18:
|
|
931
892
|
previousList = this.store.list;
|
|
932
|
-
this.store.list = this.store.list.map(function (order, index) {
|
|
893
|
+
this.store.list = shouldKeepInMemory ? this.store.list.map(function (order, index) {
|
|
933
894
|
return index === targetIndex ? nextOrder : order;
|
|
895
|
+
}) : this.store.list.filter(function (_, index) {
|
|
896
|
+
return index !== targetIndex;
|
|
934
897
|
});
|
|
935
898
|
this.syncOrdersMap();
|
|
936
899
|
storageOrder = this.withoutSyntheticDraftOrderId(nextOrder);
|
|
937
|
-
|
|
900
|
+
_context6.prev = 22;
|
|
938
901
|
this.logInfo('updateLocalPayment-SQLite写入开始', _objectSpread(_objectSpread({}, paymentContext), {}, {
|
|
939
902
|
storage_order_id: (_storageOrder$order_i = storageOrder.order_id) !== null && _storageOrder$order_i !== void 0 ? _storageOrder$order_i : null
|
|
940
903
|
}));
|
|
941
|
-
|
|
904
|
+
_context6.next = 26;
|
|
942
905
|
return this.updateOrderInSQLite(storageOrder, 'updateLocalPayment', {
|
|
943
906
|
throwOnError: true
|
|
944
907
|
});
|
|
945
|
-
case
|
|
908
|
+
case 26:
|
|
946
909
|
this.logInfo('updateLocalPayment-SQLite写入完成', _objectSpread(_objectSpread({}, paymentContext), {}, {
|
|
947
910
|
storage_order_id: (_storageOrder$order_i2 = storageOrder.order_id) !== null && _storageOrder$order_i2 !== void 0 ? _storageOrder$order_i2 : null
|
|
948
911
|
}));
|
|
949
|
-
|
|
912
|
+
_context6.next = 35;
|
|
950
913
|
break;
|
|
951
|
-
case
|
|
952
|
-
|
|
953
|
-
|
|
914
|
+
case 29:
|
|
915
|
+
_context6.prev = 29;
|
|
916
|
+
_context6.t0 = _context6["catch"](22);
|
|
954
917
|
this.store.list = previousList;
|
|
955
918
|
this.syncOrdersMap();
|
|
956
919
|
this.logError('updateLocalPayment-SQLite写入失败并回滚内存', _objectSpread(_objectSpread({}, paymentContext), {}, {
|
|
957
920
|
storage_order_id: (_storageOrder$order_i3 = storageOrder.order_id) !== null && _storageOrder$order_i3 !== void 0 ? _storageOrder$order_i3 : null,
|
|
958
|
-
error:
|
|
921
|
+
error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
|
|
959
922
|
}));
|
|
960
|
-
throw
|
|
961
|
-
case
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
923
|
+
throw _context6.t0;
|
|
924
|
+
case 35:
|
|
925
|
+
if (!(shouldKeepInMemory || targetIndex >= 0)) {
|
|
926
|
+
_context6.next = 38;
|
|
927
|
+
break;
|
|
928
|
+
}
|
|
929
|
+
_context6.next = 38;
|
|
930
|
+
return this.emitOrdersChanged(shouldKeepInMemory ? [nextOrder] : [], shouldKeepInMemory ? 'updateLocalPayment' : 'updateLocalPayment.sqliteOnlyDraft');
|
|
931
|
+
case 38:
|
|
965
932
|
this.logInfo('updateLocalPayment-变更事件完成', paymentContext);
|
|
966
|
-
return
|
|
933
|
+
return _context6.abrupt("return", {
|
|
967
934
|
order: nextOrder,
|
|
968
935
|
payment: nextPayment,
|
|
969
936
|
previousPayment: previousPayment
|
|
970
937
|
});
|
|
971
|
-
case
|
|
938
|
+
case 40:
|
|
972
939
|
case "end":
|
|
973
|
-
return
|
|
940
|
+
return _context6.stop();
|
|
974
941
|
}
|
|
975
|
-
},
|
|
942
|
+
}, _callee6, this, [[22, 29]]);
|
|
976
943
|
}));
|
|
977
944
|
function updateLocalPayment(_x5) {
|
|
978
945
|
return _updateLocalPayment.apply(this, arguments);
|
|
@@ -982,64 +949,71 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
982
949
|
}, {
|
|
983
950
|
key: "loadOrdersByServer",
|
|
984
951
|
value: function () {
|
|
985
|
-
var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
986
|
-
var
|
|
987
|
-
|
|
988
|
-
var orderList, data, mergedOrders, memoryOrders;
|
|
989
|
-
return _regeneratorRuntime().wrap(function
|
|
990
|
-
while (1) switch (
|
|
952
|
+
var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
953
|
+
var _this5 = this,
|
|
954
|
+
_this$store;
|
|
955
|
+
var orderList, protectedOrdersBeforeRemoteFetch, data, mergedOrders, memoryOrders;
|
|
956
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
957
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
991
958
|
case 0:
|
|
992
959
|
orderList = [];
|
|
960
|
+
_context7.next = 3;
|
|
961
|
+
return this.loadOrdersFromSQLite();
|
|
962
|
+
case 3:
|
|
963
|
+
protectedOrdersBeforeRemoteFetch = _context7.sent.filter(function (order) {
|
|
964
|
+
return _this5.isPendingSyncOrder(order) || _this5.isDraftOrder(order);
|
|
965
|
+
});
|
|
993
966
|
this.logInfo('loadOrdersByServer-开始', {
|
|
994
967
|
hasOrderDataSource: !!this.orderDataSource,
|
|
995
|
-
query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null
|
|
968
|
+
query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
|
|
969
|
+
protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length
|
|
996
970
|
});
|
|
997
971
|
if (!this.orderDataSource) {
|
|
998
|
-
|
|
972
|
+
_context7.next = 20;
|
|
999
973
|
break;
|
|
1000
974
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
975
|
+
_context7.prev = 6;
|
|
976
|
+
_context7.next = 9;
|
|
1003
977
|
return this.orderDataSource.run({
|
|
1004
978
|
sse: {
|
|
1005
979
|
query: this.store.createdAtQuery
|
|
1006
980
|
}
|
|
1007
981
|
});
|
|
1008
|
-
case
|
|
1009
|
-
data =
|
|
982
|
+
case 9:
|
|
983
|
+
data = _context7.sent;
|
|
1010
984
|
orderList = data || [];
|
|
1011
985
|
this.logInfo('loadOrdersByServer-SSE拉取成功', {
|
|
1012
986
|
count: orderList.length
|
|
1013
987
|
});
|
|
1014
988
|
this.markOrderPulledAtNow();
|
|
1015
989
|
this.lastServerFullFetchAtMs = Date.now();
|
|
1016
|
-
|
|
990
|
+
_context7.next = 20;
|
|
1017
991
|
break;
|
|
1018
|
-
case
|
|
1019
|
-
|
|
1020
|
-
|
|
992
|
+
case 16:
|
|
993
|
+
_context7.prev = 16;
|
|
994
|
+
_context7.t0 = _context7["catch"](6);
|
|
1021
995
|
this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
|
|
1022
|
-
return
|
|
1023
|
-
case
|
|
1024
|
-
|
|
1025
|
-
return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer');
|
|
1026
|
-
case
|
|
1027
|
-
mergedOrders =
|
|
1028
|
-
memoryOrders =
|
|
1029
|
-
return _this7.normalizeOrderForMemoryList(order);
|
|
1030
|
-
});
|
|
996
|
+
return _context7.abrupt("return", this.store.list);
|
|
997
|
+
case 20:
|
|
998
|
+
_context7.next = 22;
|
|
999
|
+
return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
|
|
1000
|
+
case 22:
|
|
1001
|
+
mergedOrders = _context7.sent;
|
|
1002
|
+
memoryOrders = this.normalizeOrdersForMemoryList(mergedOrders, 'loadOrdersByServer.memory');
|
|
1031
1003
|
this.logInfo('loadOrdersByServer-结束', {
|
|
1032
|
-
count: memoryOrders.length
|
|
1004
|
+
count: memoryOrders.length,
|
|
1005
|
+
persistedCount: mergedOrders.length,
|
|
1006
|
+
sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
|
|
1033
1007
|
});
|
|
1034
|
-
|
|
1008
|
+
_context7.next = 27;
|
|
1035
1009
|
return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
|
|
1036
|
-
case
|
|
1037
|
-
return
|
|
1038
|
-
case
|
|
1010
|
+
case 27:
|
|
1011
|
+
return _context7.abrupt("return", memoryOrders);
|
|
1012
|
+
case 28:
|
|
1039
1013
|
case "end":
|
|
1040
|
-
return
|
|
1014
|
+
return _context7.stop();
|
|
1041
1015
|
}
|
|
1042
|
-
},
|
|
1016
|
+
}, _callee7, this, [[6, 16]]);
|
|
1043
1017
|
}));
|
|
1044
1018
|
function loadOrdersByServer() {
|
|
1045
1019
|
return _loadOrdersByServer.apply(this, arguments);
|
|
@@ -1054,61 +1028,54 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1054
1028
|
}, {
|
|
1055
1029
|
key: "silentRefresh",
|
|
1056
1030
|
value: (function () {
|
|
1057
|
-
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1031
|
+
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
1058
1032
|
var startTime, elapsedSinceFullFetch, orders, errorMessage;
|
|
1059
|
-
return _regeneratorRuntime().wrap(function
|
|
1060
|
-
while (1) switch (
|
|
1033
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1034
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
1061
1035
|
case 0:
|
|
1062
1036
|
startTime = Date.now();
|
|
1063
1037
|
elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
|
|
1064
1038
|
if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
|
|
1065
|
-
|
|
1039
|
+
_context8.next = 4;
|
|
1066
1040
|
break;
|
|
1067
1041
|
}
|
|
1068
|
-
return
|
|
1042
|
+
return _context8.abrupt("return", this.store.list);
|
|
1069
1043
|
case 4:
|
|
1070
1044
|
this.logInfo('silentRefresh 开始');
|
|
1071
|
-
|
|
1045
|
+
_context8.prev = 5;
|
|
1072
1046
|
// 刷新前,需要更新当前营业日边界(store.createdAtQuery)
|
|
1073
1047
|
this.updateCreateStore();
|
|
1074
|
-
|
|
1048
|
+
_context8.next = 9;
|
|
1075
1049
|
return this.loadOrdersByServer();
|
|
1076
1050
|
case 9:
|
|
1077
|
-
orders =
|
|
1078
|
-
if (!(orders.length > 0)) {
|
|
1079
|
-
_context9.next = 19;
|
|
1080
|
-
break;
|
|
1081
|
-
}
|
|
1051
|
+
orders = _context8.sent;
|
|
1082
1052
|
this.store.list = cloneDeep(orders);
|
|
1083
1053
|
this.syncOrdersMap();
|
|
1084
|
-
|
|
1085
|
-
|
|
1054
|
+
_context8.next = 14;
|
|
1055
|
+
return this.emitOrdersChanged([], 'silentRefresh');
|
|
1056
|
+
case 14:
|
|
1057
|
+
_context8.next = 16;
|
|
1086
1058
|
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
1087
1059
|
case 16:
|
|
1088
1060
|
this.logInfo('silentRefresh 完成', {
|
|
1089
1061
|
orderCount: orders.length,
|
|
1090
1062
|
duration: "".concat(Date.now() - startTime, "ms")
|
|
1091
1063
|
});
|
|
1092
|
-
|
|
1093
|
-
break;
|
|
1094
|
-
case 19:
|
|
1095
|
-
this.logInfo('silentRefresh: 服务器未返回数据');
|
|
1064
|
+
return _context8.abrupt("return", this.store.list);
|
|
1096
1065
|
case 20:
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
_context9.t0 = _context9["catch"](5);
|
|
1101
|
-
errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
|
|
1066
|
+
_context8.prev = 20;
|
|
1067
|
+
_context8.t0 = _context8["catch"](5);
|
|
1068
|
+
errorMessage = _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0);
|
|
1102
1069
|
this.logError('silentRefresh 失败', {
|
|
1103
1070
|
duration: "".concat(Date.now() - startTime, "ms"),
|
|
1104
1071
|
error: errorMessage
|
|
1105
1072
|
});
|
|
1106
|
-
return
|
|
1107
|
-
case
|
|
1073
|
+
return _context8.abrupt("return", this.store.list);
|
|
1074
|
+
case 25:
|
|
1108
1075
|
case "end":
|
|
1109
|
-
return
|
|
1076
|
+
return _context8.stop();
|
|
1110
1077
|
}
|
|
1111
|
-
},
|
|
1078
|
+
}, _callee8, this, [[5, 20]]);
|
|
1112
1079
|
}));
|
|
1113
1080
|
function silentRefresh() {
|
|
1114
1081
|
return _silentRefresh.apply(this, arguments);
|
|
@@ -1121,6 +1088,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1121
1088
|
var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'normalizeOrderForMemoryList';
|
|
1122
1089
|
var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, source);
|
|
1123
1090
|
var externalSaleNumber = normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.external_sale_number;
|
|
1091
|
+
if (this.isDraftOrder(normalizedOrder) && !this.hasRealOrderId(normalizedOrder)) {
|
|
1092
|
+
return normalizedOrder;
|
|
1093
|
+
}
|
|
1124
1094
|
if ((normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== undefined && (normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== null && (normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== '') {
|
|
1125
1095
|
return normalizedOrder;
|
|
1126
1096
|
}
|
|
@@ -1131,6 +1101,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1131
1101
|
order_id: externalSaleNumber
|
|
1132
1102
|
});
|
|
1133
1103
|
}
|
|
1104
|
+
}, {
|
|
1105
|
+
key: "normalizeOrdersForMemoryList",
|
|
1106
|
+
value: function normalizeOrdersForMemoryList(orders, source) {
|
|
1107
|
+
var _this6 = this;
|
|
1108
|
+
return orders.map(function (order) {
|
|
1109
|
+
return _this6.normalizeOrderForMemoryList(order, source);
|
|
1110
|
+
}).filter(function (order) {
|
|
1111
|
+
return _this6.shouldKeepOrderInMemory(order);
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
}, {
|
|
1115
|
+
key: "hasRealOrderId",
|
|
1116
|
+
value: function hasRealOrderId(order) {
|
|
1117
|
+
if (!order || this.isBlankIdentityValue(order.order_id)) return false;
|
|
1118
|
+
var externalSaleNumber = order.external_sale_number;
|
|
1119
|
+
return !(this.isDraftOrder(order) && !this.isBlankIdentityValue(externalSaleNumber) && String(order.order_id) === String(externalSaleNumber));
|
|
1120
|
+
}
|
|
1121
|
+
}, {
|
|
1122
|
+
key: "shouldKeepOrderInMemory",
|
|
1123
|
+
value: function shouldKeepOrderInMemory(order) {
|
|
1124
|
+
return !this.isDraftOrder(order) || this.hasRealOrderId(order);
|
|
1125
|
+
}
|
|
1134
1126
|
}, {
|
|
1135
1127
|
key: "withoutSyntheticDraftOrderId",
|
|
1136
1128
|
value: function withoutSyntheticDraftOrderId(order) {
|
|
@@ -1150,31 +1142,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1150
1142
|
}, {
|
|
1151
1143
|
key: "overwriteExistingOrder",
|
|
1152
1144
|
value: (function () {
|
|
1153
|
-
var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1154
|
-
var
|
|
1145
|
+
var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fresh) {
|
|
1146
|
+
var _this7 = this;
|
|
1155
1147
|
var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
|
|
1156
|
-
return _regeneratorRuntime().wrap(function
|
|
1157
|
-
while (1) switch (
|
|
1148
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1149
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1158
1150
|
case 0:
|
|
1159
1151
|
orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
|
|
1160
1152
|
if (!(orderId === undefined || orderId === null)) {
|
|
1161
|
-
|
|
1153
|
+
_context9.next = 4;
|
|
1162
1154
|
break;
|
|
1163
1155
|
}
|
|
1164
1156
|
this.logError('overwriteExistingOrder-入参缺少 order_id');
|
|
1165
|
-
return
|
|
1157
|
+
return _context9.abrupt("return", {
|
|
1166
1158
|
overwritten: false
|
|
1167
1159
|
});
|
|
1168
1160
|
case 4:
|
|
1169
1161
|
key = this.getIdKey(orderId);
|
|
1170
1162
|
if (this.store.map.has(key)) {
|
|
1171
|
-
|
|
1163
|
+
_context9.next = 8;
|
|
1172
1164
|
break;
|
|
1173
1165
|
}
|
|
1174
1166
|
this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
|
|
1175
1167
|
orderId: orderId
|
|
1176
1168
|
});
|
|
1177
|
-
return
|
|
1169
|
+
return _context9.abrupt("return", {
|
|
1178
1170
|
overwritten: false
|
|
1179
1171
|
});
|
|
1180
1172
|
case 8:
|
|
@@ -1188,29 +1180,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1188
1180
|
this.store.list = this.store.list.map(function (order) {
|
|
1189
1181
|
var id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
1190
1182
|
if (id === undefined || id === null) {
|
|
1191
|
-
return
|
|
1183
|
+
return _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
|
|
1192
1184
|
}
|
|
1193
|
-
return
|
|
1185
|
+
return _this7.getIdKey(id) === key ? reconciledFresh : _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
|
|
1194
1186
|
});
|
|
1195
1187
|
this.syncOrdersMap();
|
|
1196
|
-
|
|
1188
|
+
_context9.next = 16;
|
|
1197
1189
|
return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
|
|
1198
1190
|
case 16:
|
|
1199
1191
|
this.logInfo('overwriteExistingOrder-结束', {
|
|
1200
1192
|
orderId: orderId,
|
|
1201
1193
|
storeOrderCountAfter: this.store.list.length
|
|
1202
1194
|
});
|
|
1203
|
-
|
|
1195
|
+
_context9.next = 19;
|
|
1204
1196
|
return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
|
|
1205
1197
|
case 19:
|
|
1206
|
-
return
|
|
1198
|
+
return _context9.abrupt("return", {
|
|
1207
1199
|
overwritten: true
|
|
1208
1200
|
});
|
|
1209
1201
|
case 20:
|
|
1210
1202
|
case "end":
|
|
1211
|
-
return
|
|
1203
|
+
return _context9.stop();
|
|
1212
1204
|
}
|
|
1213
|
-
},
|
|
1205
|
+
}, _callee9, this);
|
|
1214
1206
|
}));
|
|
1215
1207
|
function overwriteExistingOrder(_x6) {
|
|
1216
1208
|
return _overwriteExistingOrder.apply(this, arguments);
|
|
@@ -1225,31 +1217,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1225
1217
|
}, {
|
|
1226
1218
|
key: "upsertOrdersFromRemote",
|
|
1227
1219
|
value: (function () {
|
|
1228
|
-
var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1220
|
+
var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(freshOrders) {
|
|
1229
1221
|
var source,
|
|
1230
|
-
|
|
1231
|
-
return _regeneratorRuntime().wrap(function
|
|
1232
|
-
while (1) switch (
|
|
1222
|
+
_args10 = arguments;
|
|
1223
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1224
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1233
1225
|
case 0:
|
|
1234
|
-
source =
|
|
1226
|
+
source = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : 'upsertOrdersFromRemote';
|
|
1235
1227
|
if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
|
|
1236
|
-
|
|
1228
|
+
_context10.next = 4;
|
|
1237
1229
|
break;
|
|
1238
1230
|
}
|
|
1239
1231
|
this.logInfo('upsertOrdersFromRemote-订单列表为空', {});
|
|
1240
|
-
return
|
|
1232
|
+
return _context10.abrupt("return");
|
|
1241
1233
|
case 4:
|
|
1242
1234
|
this.logInfo('upsertOrdersFromRemote-开始', {
|
|
1243
1235
|
count: freshOrders.length,
|
|
1244
1236
|
source: source
|
|
1245
1237
|
});
|
|
1246
|
-
|
|
1238
|
+
_context10.next = 7;
|
|
1247
1239
|
return this.mergeOrdersToStore(freshOrders, source);
|
|
1248
1240
|
case 7:
|
|
1249
1241
|
case "end":
|
|
1250
|
-
return
|
|
1242
|
+
return _context10.stop();
|
|
1251
1243
|
}
|
|
1252
|
-
},
|
|
1244
|
+
}, _callee10, this);
|
|
1253
1245
|
}));
|
|
1254
1246
|
function upsertOrdersFromRemote(_x7) {
|
|
1255
1247
|
return _upsertOrdersFromRemote.apply(this, arguments);
|
|
@@ -1259,21 +1251,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1259
1251
|
}, {
|
|
1260
1252
|
key: "markOrderSyncedByExternalSaleNumber",
|
|
1261
1253
|
value: function () {
|
|
1262
|
-
var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1263
|
-
var
|
|
1254
|
+
var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
|
|
1255
|
+
var _this8 = this,
|
|
1264
1256
|
_existing$external_sa,
|
|
1265
1257
|
_nextOrder$order_id;
|
|
1266
1258
|
var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
|
|
1267
|
-
return _regeneratorRuntime().wrap(function
|
|
1268
|
-
while (1) switch (
|
|
1259
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
1260
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
1269
1261
|
case 0:
|
|
1270
1262
|
externalSaleNumber = params.externalSaleNumber;
|
|
1271
1263
|
if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
|
|
1272
|
-
|
|
1264
|
+
_context11.next = 4;
|
|
1273
1265
|
break;
|
|
1274
1266
|
}
|
|
1275
1267
|
this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
|
|
1276
|
-
return
|
|
1268
|
+
return _context11.abrupt("return", {
|
|
1277
1269
|
updated: false
|
|
1278
1270
|
});
|
|
1279
1271
|
case 4:
|
|
@@ -1281,16 +1273,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1281
1273
|
targetIndex = this.store.list.findIndex(function (order) {
|
|
1282
1274
|
var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
|
|
1283
1275
|
if (value === undefined || value === null || value === '') return false;
|
|
1284
|
-
return
|
|
1276
|
+
return _this8.getIdKey(value) === key;
|
|
1285
1277
|
});
|
|
1286
1278
|
if (!(targetIndex < 0)) {
|
|
1287
|
-
|
|
1279
|
+
_context11.next = 9;
|
|
1288
1280
|
break;
|
|
1289
1281
|
}
|
|
1290
1282
|
this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
|
|
1291
1283
|
external_sale_number: externalSaleNumber
|
|
1292
1284
|
});
|
|
1293
|
-
return
|
|
1285
|
+
return _context11.abrupt("return", {
|
|
1294
1286
|
updated: false
|
|
1295
1287
|
});
|
|
1296
1288
|
case 9:
|
|
@@ -1306,25 +1298,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1306
1298
|
return nextOrder;
|
|
1307
1299
|
});
|
|
1308
1300
|
this.syncOrdersMap();
|
|
1309
|
-
|
|
1301
|
+
_context11.next = 16;
|
|
1310
1302
|
return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
|
|
1311
1303
|
case 16:
|
|
1312
1304
|
this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
|
|
1313
1305
|
external_sale_number: externalSaleNumber,
|
|
1314
1306
|
order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
|
|
1315
1307
|
});
|
|
1316
|
-
|
|
1308
|
+
_context11.next = 19;
|
|
1317
1309
|
return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
|
|
1318
1310
|
case 19:
|
|
1319
|
-
return
|
|
1311
|
+
return _context11.abrupt("return", {
|
|
1320
1312
|
updated: true,
|
|
1321
1313
|
order: nextOrder
|
|
1322
1314
|
});
|
|
1323
1315
|
case 20:
|
|
1324
1316
|
case "end":
|
|
1325
|
-
return
|
|
1317
|
+
return _context11.stop();
|
|
1326
1318
|
}
|
|
1327
|
-
},
|
|
1319
|
+
}, _callee11, this);
|
|
1328
1320
|
}));
|
|
1329
1321
|
function markOrderSyncedByExternalSaleNumber(_x8) {
|
|
1330
1322
|
return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
|
|
@@ -1338,8 +1330,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1338
1330
|
}, {
|
|
1339
1331
|
key: "upsertPendingSyncOrders",
|
|
1340
1332
|
value: (function () {
|
|
1341
|
-
var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1342
|
-
var
|
|
1333
|
+
var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(pendingOrders) {
|
|
1334
|
+
var _this9 = this;
|
|
1343
1335
|
var options,
|
|
1344
1336
|
pendingMap,
|
|
1345
1337
|
memoryPendingMap,
|
|
@@ -1369,26 +1361,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1369
1361
|
insertIndex,
|
|
1370
1362
|
patchedOrders,
|
|
1371
1363
|
previousList,
|
|
1372
|
-
|
|
1373
|
-
return _regeneratorRuntime().wrap(function
|
|
1374
|
-
while (1) switch (
|
|
1364
|
+
_args12 = arguments;
|
|
1365
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1366
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
1375
1367
|
case 0:
|
|
1376
|
-
options =
|
|
1368
|
+
options = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : {};
|
|
1377
1369
|
if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
|
|
1378
|
-
|
|
1370
|
+
_context12.next = 4;
|
|
1379
1371
|
break;
|
|
1380
1372
|
}
|
|
1381
1373
|
this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
|
|
1382
|
-
return
|
|
1374
|
+
return _context12.abrupt("return");
|
|
1383
1375
|
case 4:
|
|
1384
1376
|
pendingMap = new Map();
|
|
1385
1377
|
memoryPendingMap = new Map();
|
|
1386
1378
|
_iterator5 = _createForOfIteratorHelper(pendingOrders);
|
|
1387
|
-
|
|
1379
|
+
_context12.prev = 7;
|
|
1388
1380
|
_iterator5.s();
|
|
1389
1381
|
case 9:
|
|
1390
1382
|
if ((_step5 = _iterator5.n()).done) {
|
|
1391
|
-
|
|
1383
|
+
_context12.next = 20;
|
|
1392
1384
|
break;
|
|
1393
1385
|
}
|
|
1394
1386
|
order = _step5.value;
|
|
@@ -1399,43 +1391,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1399
1391
|
});
|
|
1400
1392
|
storageKey = this.getOrderStorageKey(pendingOrder);
|
|
1401
1393
|
if (storageKey) {
|
|
1402
|
-
|
|
1394
|
+
_context12.next = 16;
|
|
1403
1395
|
break;
|
|
1404
1396
|
}
|
|
1405
|
-
return
|
|
1397
|
+
return _context12.abrupt("continue", 18);
|
|
1406
1398
|
case 16:
|
|
1407
1399
|
pendingMap.set(storageKey, pendingOrder);
|
|
1408
1400
|
memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(pendingOrder, 'upsertPendingSyncOrders.memory'));
|
|
1409
1401
|
case 18:
|
|
1410
|
-
|
|
1402
|
+
_context12.next = 9;
|
|
1411
1403
|
break;
|
|
1412
1404
|
case 20:
|
|
1413
|
-
|
|
1405
|
+
_context12.next = 25;
|
|
1414
1406
|
break;
|
|
1415
1407
|
case 22:
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
_iterator5.e(
|
|
1408
|
+
_context12.prev = 22;
|
|
1409
|
+
_context12.t0 = _context12["catch"](7);
|
|
1410
|
+
_iterator5.e(_context12.t0);
|
|
1419
1411
|
case 25:
|
|
1420
|
-
|
|
1412
|
+
_context12.prev = 25;
|
|
1421
1413
|
_iterator5.f();
|
|
1422
|
-
return
|
|
1414
|
+
return _context12.finish(25);
|
|
1423
1415
|
case 28:
|
|
1424
1416
|
if (!(pendingMap.size === 0)) {
|
|
1425
|
-
|
|
1417
|
+
_context12.next = 31;
|
|
1426
1418
|
break;
|
|
1427
1419
|
}
|
|
1428
1420
|
this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
|
|
1429
1421
|
count: pendingOrders.length
|
|
1430
1422
|
});
|
|
1431
|
-
return
|
|
1423
|
+
return _context12.abrupt("return");
|
|
1432
1424
|
case 31:
|
|
1433
1425
|
this.logInfo('upsertPendingSyncOrders-开始', {
|
|
1434
1426
|
count: pendingMap.size
|
|
1435
1427
|
});
|
|
1436
1428
|
mergeActions = {};
|
|
1437
1429
|
updatedList = this.store.list.map(function (order) {
|
|
1438
|
-
return
|
|
1430
|
+
return _this9.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
|
|
1439
1431
|
}); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
|
|
1440
1432
|
// 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
|
|
1441
1433
|
identityKeyToIndex = new Map();
|
|
@@ -1454,17 +1446,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1454
1446
|
}
|
|
1455
1447
|
}
|
|
1456
1448
|
_iterator7 = _createForOfIteratorHelper(memoryPendingMap.entries());
|
|
1457
|
-
|
|
1449
|
+
_context12.prev = 37;
|
|
1458
1450
|
_iterator7.s();
|
|
1459
1451
|
case 39:
|
|
1460
1452
|
if ((_step7 = _iterator7.n()).done) {
|
|
1461
|
-
|
|
1453
|
+
_context12.next = 58;
|
|
1462
1454
|
break;
|
|
1463
1455
|
}
|
|
1464
1456
|
_step7$value = _slicedToArray(_step7.value, 2), _storageKey = _step7$value[0], _pendingOrder = _step7$value[1];
|
|
1465
1457
|
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
|
|
1466
1458
|
if (!(matchIndex >= 0)) {
|
|
1467
|
-
|
|
1459
|
+
_context12.next = 52;
|
|
1468
1460
|
break;
|
|
1469
1461
|
}
|
|
1470
1462
|
existingOrder = updatedList[matchIndex];
|
|
@@ -1481,55 +1473,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1481
1473
|
// 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
|
|
1482
1474
|
this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
|
|
1483
1475
|
mergeActions[_storageKey] = 'update';
|
|
1484
|
-
return
|
|
1476
|
+
return _context12.abrupt("continue", 56);
|
|
1485
1477
|
case 52:
|
|
1486
1478
|
insertIndex = updatedList.length;
|
|
1487
1479
|
updatedList.push(_pendingOrder);
|
|
1488
1480
|
this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
|
|
1489
1481
|
mergeActions[_storageKey] = 'insert';
|
|
1490
1482
|
case 56:
|
|
1491
|
-
|
|
1483
|
+
_context12.next = 39;
|
|
1492
1484
|
break;
|
|
1493
1485
|
case 58:
|
|
1494
|
-
|
|
1486
|
+
_context12.next = 63;
|
|
1495
1487
|
break;
|
|
1496
1488
|
case 60:
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
_iterator7.e(
|
|
1489
|
+
_context12.prev = 60;
|
|
1490
|
+
_context12.t1 = _context12["catch"](37);
|
|
1491
|
+
_iterator7.e(_context12.t1);
|
|
1500
1492
|
case 63:
|
|
1501
|
-
|
|
1493
|
+
_context12.prev = 63;
|
|
1502
1494
|
_iterator7.f();
|
|
1503
|
-
return
|
|
1495
|
+
return _context12.finish(63);
|
|
1504
1496
|
case 66:
|
|
1505
1497
|
patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
|
|
1506
1498
|
previousList = this.store.list;
|
|
1507
1499
|
this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
|
|
1508
1500
|
this.syncOrdersMap();
|
|
1509
|
-
|
|
1510
|
-
|
|
1501
|
+
_context12.prev = 70;
|
|
1502
|
+
_context12.next = 73;
|
|
1511
1503
|
return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
|
|
1512
1504
|
case 73:
|
|
1513
|
-
|
|
1505
|
+
_context12.next = 80;
|
|
1514
1506
|
break;
|
|
1515
1507
|
case 75:
|
|
1516
|
-
|
|
1517
|
-
|
|
1508
|
+
_context12.prev = 75;
|
|
1509
|
+
_context12.t2 = _context12["catch"](70);
|
|
1518
1510
|
this.store.list = previousList;
|
|
1519
1511
|
this.syncOrdersMap();
|
|
1520
|
-
throw
|
|
1512
|
+
throw _context12.t2;
|
|
1521
1513
|
case 80:
|
|
1522
1514
|
this.logInfo('upsertPendingSyncOrders-结束', {
|
|
1523
1515
|
count: patchedOrders.length,
|
|
1524
1516
|
storeOrderCountAfter: this.store.list.length
|
|
1525
1517
|
});
|
|
1526
|
-
|
|
1518
|
+
_context12.next = 83;
|
|
1527
1519
|
return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
|
|
1528
1520
|
case 83:
|
|
1529
1521
|
case "end":
|
|
1530
|
-
return
|
|
1522
|
+
return _context12.stop();
|
|
1531
1523
|
}
|
|
1532
|
-
},
|
|
1524
|
+
}, _callee12, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
|
|
1533
1525
|
}));
|
|
1534
1526
|
function upsertPendingSyncOrders(_x9) {
|
|
1535
1527
|
return _upsertPendingSyncOrders.apply(this, arguments);
|
|
@@ -1537,33 +1529,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1537
1529
|
return upsertPendingSyncOrders;
|
|
1538
1530
|
}()
|
|
1539
1531
|
/**
|
|
1540
|
-
* 将 POS 草稿订单按 SQLite storage key
|
|
1541
|
-
*
|
|
1532
|
+
* 将 POS 草稿订单按 SQLite storage key 落库。
|
|
1533
|
+
* 只有具备真实 order_id 的草稿进入 store;其余草稿仅供本地恢复查询。
|
|
1542
1534
|
*/
|
|
1543
1535
|
)
|
|
1544
1536
|
}, {
|
|
1545
1537
|
key: "upsertLocalDraftOrders",
|
|
1546
1538
|
value: (function () {
|
|
1547
|
-
var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1548
|
-
var
|
|
1549
|
-
|
|
1550
|
-
|
|
1539
|
+
var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(draftOrders) {
|
|
1540
|
+
var _this10 = this;
|
|
1541
|
+
var draftMap, memoryDraftMap, _iterator8, _step8, order, draftOrder, storageKey, memoryDraftOrder, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, _iterator9, _step9, key, _iterator10, _step10, _step10$value, _storageKey2, _draftOrder, matchIndex, mergedOrder, nextOrder, insertIndex, previousList, removedLegacyMemoryDraft;
|
|
1542
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1543
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1551
1544
|
case 0:
|
|
1552
1545
|
if (draftOrders !== null && draftOrders !== void 0 && draftOrders.length) {
|
|
1553
|
-
|
|
1546
|
+
_context13.next = 3;
|
|
1554
1547
|
break;
|
|
1555
1548
|
}
|
|
1556
1549
|
this.logInfo('upsertLocalDraftOrders-订单列表为空', {});
|
|
1557
|
-
return
|
|
1550
|
+
return _context13.abrupt("return");
|
|
1558
1551
|
case 3:
|
|
1559
1552
|
draftMap = new Map();
|
|
1560
1553
|
memoryDraftMap = new Map();
|
|
1561
1554
|
_iterator8 = _createForOfIteratorHelper(draftOrders);
|
|
1562
|
-
|
|
1555
|
+
_context13.prev = 6;
|
|
1563
1556
|
_iterator8.s();
|
|
1564
1557
|
case 8:
|
|
1565
1558
|
if ((_step8 = _iterator8.n()).done) {
|
|
1566
|
-
|
|
1559
|
+
_context13.next = 19;
|
|
1567
1560
|
break;
|
|
1568
1561
|
}
|
|
1569
1562
|
order = _step8.value;
|
|
@@ -1573,43 +1566,50 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1573
1566
|
});
|
|
1574
1567
|
storageKey = this.getOrderStorageKey(draftOrder);
|
|
1575
1568
|
if (storageKey) {
|
|
1576
|
-
|
|
1569
|
+
_context13.next = 14;
|
|
1577
1570
|
break;
|
|
1578
1571
|
}
|
|
1579
|
-
return
|
|
1572
|
+
return _context13.abrupt("continue", 17);
|
|
1580
1573
|
case 14:
|
|
1581
1574
|
draftMap.set(storageKey, draftOrder);
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1575
|
+
memoryDraftOrder = this.normalizeOrderForMemoryList(draftOrder);
|
|
1576
|
+
if (this.shouldKeepOrderInMemory(memoryDraftOrder)) {
|
|
1577
|
+
memoryDraftMap.set(storageKey, memoryDraftOrder);
|
|
1578
|
+
}
|
|
1579
|
+
case 17:
|
|
1580
|
+
_context13.next = 8;
|
|
1585
1581
|
break;
|
|
1586
|
-
case
|
|
1587
|
-
|
|
1582
|
+
case 19:
|
|
1583
|
+
_context13.next = 24;
|
|
1588
1584
|
break;
|
|
1589
|
-
case
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
_iterator8.e(
|
|
1593
|
-
case
|
|
1594
|
-
|
|
1585
|
+
case 21:
|
|
1586
|
+
_context13.prev = 21;
|
|
1587
|
+
_context13.t0 = _context13["catch"](6);
|
|
1588
|
+
_iterator8.e(_context13.t0);
|
|
1589
|
+
case 24:
|
|
1590
|
+
_context13.prev = 24;
|
|
1595
1591
|
_iterator8.f();
|
|
1596
|
-
return
|
|
1597
|
-
case
|
|
1592
|
+
return _context13.finish(24);
|
|
1593
|
+
case 27:
|
|
1598
1594
|
if (!(draftMap.size === 0)) {
|
|
1599
|
-
|
|
1595
|
+
_context13.next = 30;
|
|
1600
1596
|
break;
|
|
1601
1597
|
}
|
|
1602
1598
|
this.logError('upsertLocalDraftOrders-订单缺少可落库标识', {
|
|
1603
1599
|
count: draftOrders.length
|
|
1604
1600
|
});
|
|
1605
|
-
return
|
|
1606
|
-
case
|
|
1601
|
+
return _context13.abrupt("return");
|
|
1602
|
+
case 30:
|
|
1607
1603
|
this.logInfo('upsertLocalDraftOrders-开始', {
|
|
1608
|
-
count: draftMap.size
|
|
1604
|
+
count: draftMap.size,
|
|
1605
|
+
memoryDraftCount: memoryDraftMap.size,
|
|
1606
|
+
sqliteOnlyDraftCount: draftMap.size - memoryDraftMap.size
|
|
1609
1607
|
});
|
|
1610
1608
|
patchedOrders = _toConsumableArray(draftMap.values());
|
|
1611
1609
|
mergeActions = {};
|
|
1612
|
-
updatedList =
|
|
1610
|
+
updatedList = this.store.list.filter(function (order) {
|
|
1611
|
+
return _this10.shouldKeepOrderInMemory(order);
|
|
1612
|
+
});
|
|
1613
1613
|
identityKeyToIndex = new Map();
|
|
1614
1614
|
for (index = 0; index < updatedList.length; index += 1) {
|
|
1615
1615
|
_iterator9 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
|
|
@@ -1625,17 +1625,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1625
1625
|
}
|
|
1626
1626
|
}
|
|
1627
1627
|
_iterator10 = _createForOfIteratorHelper(memoryDraftMap.entries());
|
|
1628
|
-
|
|
1628
|
+
_context13.prev = 37;
|
|
1629
1629
|
_iterator10.s();
|
|
1630
|
-
case
|
|
1630
|
+
case 39:
|
|
1631
1631
|
if ((_step10 = _iterator10.n()).done) {
|
|
1632
|
-
|
|
1632
|
+
_context13.next = 55;
|
|
1633
1633
|
break;
|
|
1634
1634
|
}
|
|
1635
1635
|
_step10$value = _slicedToArray(_step10.value, 2), _storageKey2 = _step10$value[0], _draftOrder = _step10$value[1];
|
|
1636
1636
|
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
|
|
1637
1637
|
if (!(matchIndex >= 0)) {
|
|
1638
|
-
|
|
1638
|
+
_context13.next = 49;
|
|
1639
1639
|
break;
|
|
1640
1640
|
}
|
|
1641
1641
|
mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], _draftOrder);
|
|
@@ -1646,43 +1646,65 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1646
1646
|
updatedList[matchIndex] = nextOrder;
|
|
1647
1647
|
this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
|
|
1648
1648
|
mergeActions[_storageKey2] = 'update';
|
|
1649
|
-
return
|
|
1650
|
-
case
|
|
1649
|
+
return _context13.abrupt("continue", 53);
|
|
1650
|
+
case 49:
|
|
1651
1651
|
insertIndex = updatedList.length;
|
|
1652
1652
|
updatedList.push(_draftOrder);
|
|
1653
1653
|
this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
|
|
1654
1654
|
mergeActions[_storageKey2] = 'insert';
|
|
1655
|
-
case
|
|
1656
|
-
|
|
1655
|
+
case 53:
|
|
1656
|
+
_context13.next = 39;
|
|
1657
1657
|
break;
|
|
1658
|
-
case
|
|
1659
|
-
|
|
1658
|
+
case 55:
|
|
1659
|
+
_context13.next = 60;
|
|
1660
1660
|
break;
|
|
1661
|
-
case
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
_iterator10.e(
|
|
1665
|
-
case
|
|
1666
|
-
|
|
1661
|
+
case 57:
|
|
1662
|
+
_context13.prev = 57;
|
|
1663
|
+
_context13.t1 = _context13["catch"](37);
|
|
1664
|
+
_iterator10.e(_context13.t1);
|
|
1665
|
+
case 60:
|
|
1666
|
+
_context13.prev = 60;
|
|
1667
1667
|
_iterator10.f();
|
|
1668
|
-
return
|
|
1669
|
-
case
|
|
1668
|
+
return _context13.finish(60);
|
|
1669
|
+
case 63:
|
|
1670
|
+
previousList = this.store.list;
|
|
1670
1671
|
this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
|
|
1671
1672
|
this.syncOrdersMap();
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1673
|
+
_context13.prev = 66;
|
|
1674
|
+
_context13.next = 69;
|
|
1675
|
+
return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
|
|
1676
|
+
throwOnError: true
|
|
1677
|
+
});
|
|
1678
|
+
case 69:
|
|
1679
|
+
_context13.next = 76;
|
|
1680
|
+
break;
|
|
1681
|
+
case 71:
|
|
1682
|
+
_context13.prev = 71;
|
|
1683
|
+
_context13.t2 = _context13["catch"](66);
|
|
1684
|
+
this.store.list = previousList;
|
|
1685
|
+
this.syncOrdersMap();
|
|
1686
|
+
throw _context13.t2;
|
|
1687
|
+
case 76:
|
|
1675
1688
|
this.logInfo('upsertLocalDraftOrders-结束', {
|
|
1676
1689
|
count: patchedOrders.length,
|
|
1677
1690
|
storeOrderCountAfter: this.store.list.length
|
|
1678
1691
|
});
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1692
|
+
removedLegacyMemoryDraft = previousList.some(function (order) {
|
|
1693
|
+
return !_this10.shouldKeepOrderInMemory(order);
|
|
1694
|
+
});
|
|
1695
|
+
if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
|
|
1696
|
+
_context13.next = 81;
|
|
1697
|
+
break;
|
|
1698
|
+
}
|
|
1699
|
+
_context13.next = 81;
|
|
1700
|
+
return this.emitOrdersChanged(patchedOrders.filter(function (order) {
|
|
1701
|
+
return _this10.shouldKeepOrderInMemory(order);
|
|
1702
|
+
}), 'upsertLocalDraftOrders');
|
|
1703
|
+
case 81:
|
|
1682
1704
|
case "end":
|
|
1683
|
-
return
|
|
1705
|
+
return _context13.stop();
|
|
1684
1706
|
}
|
|
1685
|
-
},
|
|
1707
|
+
}, _callee13, this, [[6, 21, 24, 27], [37, 57, 60, 63], [66, 71]]);
|
|
1686
1708
|
}));
|
|
1687
1709
|
function upsertLocalDraftOrders(_x10) {
|
|
1688
1710
|
return _upsertLocalDraftOrders.apply(this, arguments);
|
|
@@ -1696,42 +1718,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1696
1718
|
}, {
|
|
1697
1719
|
key: "fetchOrdersBySSE",
|
|
1698
1720
|
value: (function () {
|
|
1699
|
-
var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1721
|
+
var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
1700
1722
|
var query,
|
|
1701
1723
|
data,
|
|
1702
|
-
|
|
1703
|
-
return _regeneratorRuntime().wrap(function
|
|
1704
|
-
while (1) switch (
|
|
1724
|
+
_args14 = arguments;
|
|
1725
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1726
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1705
1727
|
case 0:
|
|
1706
|
-
query =
|
|
1728
|
+
query = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
|
|
1707
1729
|
if (this.orderDataSource) {
|
|
1708
|
-
|
|
1730
|
+
_context14.next = 3;
|
|
1709
1731
|
break;
|
|
1710
1732
|
}
|
|
1711
|
-
return
|
|
1733
|
+
return _context14.abrupt("return", []);
|
|
1712
1734
|
case 3:
|
|
1713
|
-
|
|
1714
|
-
|
|
1735
|
+
_context14.prev = 3;
|
|
1736
|
+
_context14.next = 6;
|
|
1715
1737
|
return this.orderDataSource.run({
|
|
1716
1738
|
sse: {
|
|
1717
1739
|
query: query
|
|
1718
1740
|
}
|
|
1719
1741
|
});
|
|
1720
1742
|
case 6:
|
|
1721
|
-
data =
|
|
1722
|
-
return
|
|
1743
|
+
data = _context14.sent;
|
|
1744
|
+
return _context14.abrupt("return", data || []);
|
|
1723
1745
|
case 10:
|
|
1724
|
-
|
|
1725
|
-
|
|
1746
|
+
_context14.prev = 10;
|
|
1747
|
+
_context14.t0 = _context14["catch"](3);
|
|
1726
1748
|
this.logError('fetchOrdersBySSE-失败', {
|
|
1727
|
-
error:
|
|
1749
|
+
error: _context14.t0 instanceof Error ? _context14.t0.message : String(_context14.t0)
|
|
1728
1750
|
});
|
|
1729
|
-
return
|
|
1751
|
+
return _context14.abrupt("return", []);
|
|
1730
1752
|
case 14:
|
|
1731
1753
|
case "end":
|
|
1732
|
-
return
|
|
1754
|
+
return _context14.stop();
|
|
1733
1755
|
}
|
|
1734
|
-
},
|
|
1756
|
+
}, _callee14, this, [[3, 10]]);
|
|
1735
1757
|
}));
|
|
1736
1758
|
function fetchOrdersBySSE() {
|
|
1737
1759
|
return _fetchOrdersBySSE.apply(this, arguments);
|
|
@@ -1759,6 +1781,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1759
1781
|
}, {
|
|
1760
1782
|
key: "syncOrdersMap",
|
|
1761
1783
|
value: function syncOrdersMap() {
|
|
1784
|
+
var _this11 = this;
|
|
1785
|
+
this.store.list = this.store.list.filter(function (order) {
|
|
1786
|
+
return _this11.shouldKeepOrderInMemory(order);
|
|
1787
|
+
});
|
|
1762
1788
|
this.store.map.clear();
|
|
1763
1789
|
var _iterator11 = _createForOfIteratorHelper(this.store.list),
|
|
1764
1790
|
_step11;
|
|
@@ -1796,7 +1822,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1796
1822
|
}, {
|
|
1797
1823
|
key: "getOrderIdentityEntries",
|
|
1798
1824
|
value: function getOrderIdentityEntries(order) {
|
|
1799
|
-
var
|
|
1825
|
+
var _this12 = this;
|
|
1800
1826
|
if (!order) return [];
|
|
1801
1827
|
var record = order;
|
|
1802
1828
|
var candidates = [{
|
|
@@ -1815,8 +1841,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1815
1841
|
var entries = [];
|
|
1816
1842
|
var _loop = function _loop() {
|
|
1817
1843
|
var candidate = _candidates[_i2];
|
|
1818
|
-
if (
|
|
1819
|
-
var key =
|
|
1844
|
+
if (_this12.isBlankIdentityValue(candidate.value)) return 0; // continue
|
|
1845
|
+
var key = _this12.getIdKey(candidate.value);
|
|
1820
1846
|
if (entries.some(function (entry) {
|
|
1821
1847
|
return entry.field === candidate.field && entry.key === key;
|
|
1822
1848
|
})) return 0; // continue
|
|
@@ -1883,7 +1909,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1883
1909
|
}, {
|
|
1884
1910
|
key: "setupOrderSync",
|
|
1885
1911
|
value: function setupOrderSync() {
|
|
1886
|
-
var
|
|
1912
|
+
var _this13 = this;
|
|
1887
1913
|
if (!this.orderDataSource) return;
|
|
1888
1914
|
this.orderDataSource.run({
|
|
1889
1915
|
pubsub: {
|
|
@@ -1891,22 +1917,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1891
1917
|
var _message$id, _message$order_id, _message$type;
|
|
1892
1918
|
console.log('orderDataSource', res);
|
|
1893
1919
|
var pubsubReceivedAt = Date.now();
|
|
1894
|
-
var message =
|
|
1920
|
+
var message = _this13.normalizeOrderSyncMessage(res);
|
|
1895
1921
|
if (!message) return;
|
|
1896
1922
|
message._pubsubReceivedAt = pubsubReceivedAt;
|
|
1897
|
-
|
|
1898
|
-
var throttleMs =
|
|
1899
|
-
var routeInfo =
|
|
1900
|
-
|
|
1923
|
+
_this13.pendingSyncMessages.push(message);
|
|
1924
|
+
var throttleMs = _this13.getOrderSyncThrottleMs();
|
|
1925
|
+
var routeInfo = _this13.resolveSyncMessageRoute(message);
|
|
1926
|
+
_this13.logInfo('orderSync-收到消息并入队', {
|
|
1901
1927
|
id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
|
|
1902
1928
|
order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
|
|
1903
1929
|
type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
|
|
1904
|
-
pendingCount:
|
|
1930
|
+
pendingCount: _this13.pendingSyncMessages.length,
|
|
1905
1931
|
throttleMs: throttleMs,
|
|
1906
1932
|
pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
|
|
1907
1933
|
fullMessage: JSON.stringify(message)
|
|
1908
1934
|
});
|
|
1909
|
-
|
|
1935
|
+
_this13.scheduleOrderSyncThrottle();
|
|
1910
1936
|
}
|
|
1911
1937
|
}
|
|
1912
1938
|
}).catch(function () {
|
|
@@ -1923,7 +1949,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1923
1949
|
}, {
|
|
1924
1950
|
key: "scheduleOrderSyncThrottle",
|
|
1925
1951
|
value: function scheduleOrderSyncThrottle() {
|
|
1926
|
-
var
|
|
1952
|
+
var _this14 = this;
|
|
1927
1953
|
if (this.isProcessingSyncBatch) return;
|
|
1928
1954
|
if (this.isIdlePhase) {
|
|
1929
1955
|
this.isIdlePhase = false;
|
|
@@ -1934,8 +1960,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1934
1960
|
if (this.syncTimer) return;
|
|
1935
1961
|
var throttleMs = this.getOrderSyncThrottleMs();
|
|
1936
1962
|
this.syncTimer = setTimeout(function () {
|
|
1937
|
-
|
|
1938
|
-
void
|
|
1963
|
+
_this14.syncTimer = undefined;
|
|
1964
|
+
void _this14.flushOrderSyncMessagesByThrottle();
|
|
1939
1965
|
}, throttleMs);
|
|
1940
1966
|
}
|
|
1941
1967
|
|
|
@@ -1946,41 +1972,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1946
1972
|
}, {
|
|
1947
1973
|
key: "flushOrderSyncMessagesByThrottle",
|
|
1948
1974
|
value: (function () {
|
|
1949
|
-
var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1950
|
-
return _regeneratorRuntime().wrap(function
|
|
1951
|
-
while (1) switch (
|
|
1975
|
+
var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
1976
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1977
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1952
1978
|
case 0:
|
|
1953
1979
|
if (!this.isProcessingSyncBatch) {
|
|
1954
|
-
|
|
1980
|
+
_context15.next = 2;
|
|
1955
1981
|
break;
|
|
1956
1982
|
}
|
|
1957
|
-
return
|
|
1983
|
+
return _context15.abrupt("return");
|
|
1958
1984
|
case 2:
|
|
1959
1985
|
if (!(this.pendingSyncMessages.length === 0)) {
|
|
1960
|
-
|
|
1986
|
+
_context15.next = 5;
|
|
1961
1987
|
break;
|
|
1962
1988
|
}
|
|
1963
1989
|
this.isIdlePhase = true;
|
|
1964
|
-
return
|
|
1990
|
+
return _context15.abrupt("return");
|
|
1965
1991
|
case 5:
|
|
1966
1992
|
this.isProcessingSyncBatch = true;
|
|
1967
|
-
|
|
1968
|
-
|
|
1993
|
+
_context15.prev = 6;
|
|
1994
|
+
_context15.next = 9;
|
|
1969
1995
|
return this.processOrderSyncMessages();
|
|
1970
1996
|
case 9:
|
|
1971
|
-
|
|
1997
|
+
_context15.prev = 9;
|
|
1972
1998
|
this.isProcessingSyncBatch = false;
|
|
1973
1999
|
if (this.pendingSyncMessages.length > 0) {
|
|
1974
2000
|
this.scheduleOrderSyncThrottle();
|
|
1975
2001
|
} else {
|
|
1976
2002
|
this.isIdlePhase = true;
|
|
1977
2003
|
}
|
|
1978
|
-
return
|
|
2004
|
+
return _context15.finish(9);
|
|
1979
2005
|
case 13:
|
|
1980
2006
|
case "end":
|
|
1981
|
-
return
|
|
2007
|
+
return _context15.stop();
|
|
1982
2008
|
}
|
|
1983
|
-
},
|
|
2009
|
+
}, _callee15, this, [[6,, 9, 13]]);
|
|
1984
2010
|
}));
|
|
1985
2011
|
function flushOrderSyncMessagesByThrottle() {
|
|
1986
2012
|
return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
|
|
@@ -2002,19 +2028,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2002
2028
|
}, {
|
|
2003
2029
|
key: "processOrderSyncMessages",
|
|
2004
2030
|
value: (function () {
|
|
2005
|
-
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2006
|
-
var
|
|
2031
|
+
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
|
|
2032
|
+
var _this15 = this;
|
|
2007
2033
|
var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
|
|
2008
|
-
return _regeneratorRuntime().wrap(function
|
|
2009
|
-
while (1) switch (
|
|
2034
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
2035
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
2010
2036
|
case 0:
|
|
2011
2037
|
messages = _toConsumableArray(this.pendingSyncMessages);
|
|
2012
2038
|
this.pendingSyncMessages = [];
|
|
2013
2039
|
if (!(messages.length === 0)) {
|
|
2014
|
-
|
|
2040
|
+
_context16.next = 4;
|
|
2015
2041
|
break;
|
|
2016
2042
|
}
|
|
2017
|
-
return
|
|
2043
|
+
return _context16.abrupt("return");
|
|
2018
2044
|
case 4:
|
|
2019
2045
|
batchProcessStartAt = Date.now();
|
|
2020
2046
|
earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
|
|
@@ -2030,13 +2056,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2030
2056
|
upsertOrders = new Map();
|
|
2031
2057
|
refreshIds = [];
|
|
2032
2058
|
messages.forEach(function (msg, msgIndex) {
|
|
2033
|
-
var routeInfo =
|
|
2059
|
+
var routeInfo = _this15.resolveSyncMessageRoute(msg);
|
|
2034
2060
|
var hasBatchIds = routeInfo.hasBatchIds;
|
|
2035
2061
|
var singleId = routeInfo.singleId;
|
|
2036
2062
|
var hasSingleId = routeInfo.hasSingleId;
|
|
2037
|
-
var normalizedBody =
|
|
2063
|
+
var normalizedBody = _this15.normalizeOrderSyncPayload(msg.body || msg.data);
|
|
2038
2064
|
if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
|
|
2039
|
-
upsertOrders.set(
|
|
2065
|
+
upsertOrders.set(_this15.getIdKey(normalizedBody.order_id), normalizedBody);
|
|
2040
2066
|
return;
|
|
2041
2067
|
}
|
|
2042
2068
|
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));
|
|
@@ -2048,41 +2074,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2048
2074
|
refreshIdCount: uniqueRefreshIds.length
|
|
2049
2075
|
});
|
|
2050
2076
|
if (!(upsertList.length > 0)) {
|
|
2051
|
-
|
|
2077
|
+
_context16.next = 16;
|
|
2052
2078
|
break;
|
|
2053
2079
|
}
|
|
2054
|
-
|
|
2080
|
+
_context16.next = 16;
|
|
2055
2081
|
return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
|
|
2056
2082
|
case 16:
|
|
2057
2083
|
if (!(uniqueRefreshIds.length > 0)) {
|
|
2058
|
-
|
|
2084
|
+
_context16.next = 28;
|
|
2059
2085
|
break;
|
|
2060
2086
|
}
|
|
2061
2087
|
_this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
|
|
2062
2088
|
if (skipped.length > 0) {}
|
|
2063
2089
|
if (!(toFetch.length > 0)) {
|
|
2064
|
-
|
|
2090
|
+
_context16.next = 28;
|
|
2065
2091
|
break;
|
|
2066
2092
|
}
|
|
2067
|
-
|
|
2093
|
+
_context16.next = 22;
|
|
2068
2094
|
return this.fetchOrdersByHttp(toFetch);
|
|
2069
2095
|
case 22:
|
|
2070
|
-
freshOrders =
|
|
2096
|
+
freshOrders = _context16.sent;
|
|
2071
2097
|
if (!(freshOrders.length > 0)) {
|
|
2072
|
-
|
|
2098
|
+
_context16.next = 28;
|
|
2073
2099
|
break;
|
|
2074
2100
|
}
|
|
2075
|
-
|
|
2101
|
+
_context16.next = 26;
|
|
2076
2102
|
return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
|
|
2077
2103
|
case 26:
|
|
2078
|
-
|
|
2104
|
+
_context16.next = 28;
|
|
2079
2105
|
break;
|
|
2080
2106
|
case 28:
|
|
2081
2107
|
if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
|
|
2082
|
-
|
|
2108
|
+
_context16.next = 30;
|
|
2083
2109
|
break;
|
|
2084
2110
|
}
|
|
2085
|
-
return
|
|
2111
|
+
return _context16.abrupt("return");
|
|
2086
2112
|
case 30:
|
|
2087
2113
|
batchProcessEndAt = Date.now();
|
|
2088
2114
|
this.logInfo('processOrderSyncMessages-结束', {
|
|
@@ -2091,13 +2117,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2091
2117
|
batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
|
|
2092
2118
|
totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
|
|
2093
2119
|
});
|
|
2094
|
-
|
|
2120
|
+
_context16.next = 34;
|
|
2095
2121
|
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
2096
2122
|
case 34:
|
|
2097
2123
|
case "end":
|
|
2098
|
-
return
|
|
2124
|
+
return _context16.stop();
|
|
2099
2125
|
}
|
|
2100
|
-
},
|
|
2126
|
+
}, _callee16, this);
|
|
2101
2127
|
}));
|
|
2102
2128
|
function processOrderSyncMessages() {
|
|
2103
2129
|
return _processOrderSyncMessages.apply(this, arguments);
|
|
@@ -2118,29 +2144,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2118
2144
|
}, {
|
|
2119
2145
|
key: "fetchOrdersByHttp",
|
|
2120
2146
|
value: (function () {
|
|
2121
|
-
var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2147
|
+
var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(ids) {
|
|
2122
2148
|
var _orderList, orderList;
|
|
2123
|
-
return _regeneratorRuntime().wrap(function
|
|
2124
|
-
while (1) switch (
|
|
2149
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
2150
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
2125
2151
|
case 0:
|
|
2126
2152
|
if (!(!this.orderDataSource || ids.length === 0)) {
|
|
2127
|
-
|
|
2153
|
+
_context17.next = 2;
|
|
2128
2154
|
break;
|
|
2129
2155
|
}
|
|
2130
|
-
return
|
|
2156
|
+
return _context17.abrupt("return", []);
|
|
2131
2157
|
case 2:
|
|
2132
|
-
|
|
2158
|
+
_context17.prev = 2;
|
|
2133
2159
|
if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
|
|
2134
|
-
|
|
2160
|
+
_context17.next = 8;
|
|
2135
2161
|
break;
|
|
2136
2162
|
}
|
|
2137
|
-
|
|
2163
|
+
_context17.next = 6;
|
|
2138
2164
|
return this.orderDataSource.fetchOrdersByIds(ids);
|
|
2139
2165
|
case 6:
|
|
2140
|
-
_orderList =
|
|
2141
|
-
return
|
|
2166
|
+
_orderList = _context17.sent;
|
|
2167
|
+
return _context17.abrupt("return", _orderList || []);
|
|
2142
2168
|
case 8:
|
|
2143
|
-
|
|
2169
|
+
_context17.next = 10;
|
|
2144
2170
|
return this.orderDataSource.run({
|
|
2145
2171
|
http: {
|
|
2146
2172
|
query: {
|
|
@@ -2149,17 +2175,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2149
2175
|
}
|
|
2150
2176
|
});
|
|
2151
2177
|
case 10:
|
|
2152
|
-
orderList =
|
|
2153
|
-
return
|
|
2178
|
+
orderList = _context17.sent;
|
|
2179
|
+
return _context17.abrupt("return", orderList || []);
|
|
2154
2180
|
case 14:
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
return
|
|
2181
|
+
_context17.prev = 14;
|
|
2182
|
+
_context17.t0 = _context17["catch"](2);
|
|
2183
|
+
return _context17.abrupt("return", []);
|
|
2158
2184
|
case 17:
|
|
2159
2185
|
case "end":
|
|
2160
|
-
return
|
|
2186
|
+
return _context17.stop();
|
|
2161
2187
|
}
|
|
2162
|
-
},
|
|
2188
|
+
}, _callee17, this, [[2, 14]]);
|
|
2163
2189
|
}));
|
|
2164
2190
|
function fetchOrdersByHttp(_x11) {
|
|
2165
2191
|
return _fetchOrdersByHttp.apply(this, arguments);
|
|
@@ -2173,11 +2199,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2173
2199
|
}, {
|
|
2174
2200
|
key: "mergeOrdersToStore",
|
|
2175
2201
|
value: (function () {
|
|
2176
|
-
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2177
|
-
var
|
|
2178
|
-
var storeOrderCountBefore, normalizedFreshOrders, _iterator13, _step13, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator14, _step14, key, _iterator15, _step15, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder,
|
|
2179
|
-
return _regeneratorRuntime().wrap(function
|
|
2180
|
-
while (1) switch (
|
|
2202
|
+
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(freshOrders, source) {
|
|
2203
|
+
var _this16 = this;
|
|
2204
|
+
var storeOrderCountBefore, normalizedFreshOrders, _iterator13, _step13, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator14, _step14, key, _iterator15, _step15, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _ref, _existingOrder$order_, _ref2, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, _ref3, _existingOrder$order_2, _ref4, _external_sale_number3, _existingOrder$is_dra, _fresh$is_draft_order, mergedOrder, adjustedMatchIndex, duplicateIndexes, _iterator16, _step16, _key2, _duplicateIndex, _iterator17, _step17, duplicateIndex, _index, _iterator18, _step18, _key, insertIndex, insertCount, updateCount;
|
|
2205
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
2206
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
2181
2207
|
case 0:
|
|
2182
2208
|
storeOrderCountBefore = this.store.list.length;
|
|
2183
2209
|
this.logInfo('mergeOrdersToStore-开始', {
|
|
@@ -2188,36 +2214,36 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2188
2214
|
this.logDuplicateOrders("".concat(source, ".beforeMerge"), this.store.list);
|
|
2189
2215
|
normalizedFreshOrders = [];
|
|
2190
2216
|
_iterator13 = _createForOfIteratorHelper(freshOrders);
|
|
2191
|
-
|
|
2217
|
+
_context18.prev = 5;
|
|
2192
2218
|
_iterator13.s();
|
|
2193
2219
|
case 7:
|
|
2194
2220
|
if ((_step13 = _iterator13.n()).done) {
|
|
2195
|
-
|
|
2221
|
+
_context18.next = 15;
|
|
2196
2222
|
break;
|
|
2197
2223
|
}
|
|
2198
2224
|
order = _step13.value;
|
|
2199
2225
|
id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
2200
2226
|
if (!(id === undefined || id === null)) {
|
|
2201
|
-
|
|
2227
|
+
_context18.next = 12;
|
|
2202
2228
|
break;
|
|
2203
2229
|
}
|
|
2204
|
-
return
|
|
2230
|
+
return _context18.abrupt("continue", 13);
|
|
2205
2231
|
case 12:
|
|
2206
2232
|
normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
|
|
2207
2233
|
case 13:
|
|
2208
|
-
|
|
2234
|
+
_context18.next = 7;
|
|
2209
2235
|
break;
|
|
2210
2236
|
case 15:
|
|
2211
|
-
|
|
2237
|
+
_context18.next = 20;
|
|
2212
2238
|
break;
|
|
2213
2239
|
case 17:
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
_iterator13.e(
|
|
2240
|
+
_context18.prev = 17;
|
|
2241
|
+
_context18.t0 = _context18["catch"](5);
|
|
2242
|
+
_iterator13.e(_context18.t0);
|
|
2217
2243
|
case 20:
|
|
2218
|
-
|
|
2244
|
+
_context18.prev = 20;
|
|
2219
2245
|
_iterator13.f();
|
|
2220
|
-
return
|
|
2246
|
+
return _context18.finish(20);
|
|
2221
2247
|
case 23:
|
|
2222
2248
|
// 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
|
|
2223
2249
|
uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
|
|
@@ -2225,7 +2251,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2225
2251
|
patchedOrders = [];
|
|
2226
2252
|
mergeActions = {};
|
|
2227
2253
|
updatedList = this.store.list.map(function (order) {
|
|
2228
|
-
return
|
|
2254
|
+
return _this16.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
|
|
2229
2255
|
}); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
|
|
2230
2256
|
// 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
|
|
2231
2257
|
// 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
|
|
@@ -2246,11 +2272,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2246
2272
|
}
|
|
2247
2273
|
}
|
|
2248
2274
|
_iterator15 = _createForOfIteratorHelper(uniqueFreshOrders);
|
|
2249
|
-
|
|
2275
|
+
_context18.prev = 31;
|
|
2250
2276
|
_iterator15.s();
|
|
2251
2277
|
case 33:
|
|
2252
2278
|
if ((_step15 = _iterator15.n()).done) {
|
|
2253
|
-
|
|
2279
|
+
_context18.next = 82;
|
|
2254
2280
|
break;
|
|
2255
2281
|
}
|
|
2256
2282
|
fresh = _step15.value;
|
|
@@ -2259,74 +2285,74 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2259
2285
|
storageKey = this.getOrderStorageKey(fresh);
|
|
2260
2286
|
mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
|
|
2261
2287
|
if (!(matchIndex >= 0)) {
|
|
2262
|
-
|
|
2288
|
+
_context18.next = 75;
|
|
2263
2289
|
break;
|
|
2264
2290
|
}
|
|
2265
2291
|
existingOrder = updatedList[matchIndex];
|
|
2266
2292
|
if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
|
|
2267
|
-
|
|
2293
|
+
_context18.next = 44;
|
|
2268
2294
|
break;
|
|
2269
2295
|
}
|
|
2270
2296
|
this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
|
|
2271
2297
|
source: source,
|
|
2272
|
-
order_id: (
|
|
2273
|
-
external_sale_number: (
|
|
2298
|
+
order_id: (_ref = (_existingOrder$order_ = existingOrder.order_id) !== null && _existingOrder$order_ !== void 0 ? _existingOrder$order_ : fresh.order_id) !== null && _ref !== void 0 ? _ref : null,
|
|
2299
|
+
external_sale_number: (_ref2 = (_external_sale_number2 = existingOrder.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : fresh.external_sale_number) !== null && _ref2 !== void 0 ? _ref2 : null,
|
|
2274
2300
|
local_payment_status: (_existingOrder$paymen = existingOrder.payment_status) !== null && _existingOrder$paymen !== void 0 ? _existingOrder$paymen : null,
|
|
2275
2301
|
remote_payment_status: (_fresh$payment_status = fresh.payment_status) !== null && _fresh$payment_status !== void 0 ? _fresh$payment_status : null,
|
|
2276
2302
|
local_need_sync: (_existingOrder$need_s = existingOrder.need_sync) !== null && _existingOrder$need_s !== void 0 ? _existingOrder$need_s : null,
|
|
2277
2303
|
remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
|
|
2278
2304
|
reason: 'protect_pending_sync_order_from_remote_echo'
|
|
2279
2305
|
});
|
|
2280
|
-
return
|
|
2306
|
+
return _context18.abrupt("continue", 80);
|
|
2281
2307
|
case 44:
|
|
2282
2308
|
if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
|
|
2283
|
-
|
|
2309
|
+
_context18.next = 47;
|
|
2284
2310
|
break;
|
|
2285
2311
|
}
|
|
2286
2312
|
this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
|
|
2287
2313
|
source: source,
|
|
2288
|
-
order_id: (
|
|
2289
|
-
external_sale_number: (
|
|
2314
|
+
order_id: (_ref3 = (_existingOrder$order_2 = existingOrder.order_id) !== null && _existingOrder$order_2 !== void 0 ? _existingOrder$order_2 : fresh.order_id) !== null && _ref3 !== void 0 ? _ref3 : null,
|
|
2315
|
+
external_sale_number: (_ref4 = (_external_sale_number3 = existingOrder.external_sale_number) !== null && _external_sale_number3 !== void 0 ? _external_sale_number3 : fresh.external_sale_number) !== null && _ref4 !== void 0 ? _ref4 : null,
|
|
2290
2316
|
local_is_draft_order: (_existingOrder$is_dra = existingOrder.is_draft_order) !== null && _existingOrder$is_dra !== void 0 ? _existingOrder$is_dra : null,
|
|
2291
2317
|
remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
|
|
2292
2318
|
reason: 'protect_draft_order_from_remote_echo'
|
|
2293
2319
|
});
|
|
2294
|
-
return
|
|
2320
|
+
return _context18.abrupt("continue", 80);
|
|
2295
2321
|
case 47:
|
|
2296
2322
|
mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
|
|
2297
2323
|
adjustedMatchIndex = matchIndex;
|
|
2298
2324
|
duplicateIndexes = new Set();
|
|
2299
2325
|
_iterator16 = _createForOfIteratorHelper(freshIdentityKeys);
|
|
2300
|
-
|
|
2326
|
+
_context18.prev = 51;
|
|
2301
2327
|
_iterator16.s();
|
|
2302
2328
|
case 53:
|
|
2303
2329
|
if ((_step16 = _iterator16.n()).done) {
|
|
2304
|
-
|
|
2330
|
+
_context18.next = 61;
|
|
2305
2331
|
break;
|
|
2306
2332
|
}
|
|
2307
2333
|
_key2 = _step16.value;
|
|
2308
2334
|
_duplicateIndex = identityKeyToIndex.get(_key2);
|
|
2309
2335
|
if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
|
|
2310
|
-
|
|
2336
|
+
_context18.next = 58;
|
|
2311
2337
|
break;
|
|
2312
2338
|
}
|
|
2313
|
-
return
|
|
2339
|
+
return _context18.abrupt("continue", 59);
|
|
2314
2340
|
case 58:
|
|
2315
2341
|
duplicateIndexes.add(_duplicateIndex);
|
|
2316
2342
|
case 59:
|
|
2317
|
-
|
|
2343
|
+
_context18.next = 53;
|
|
2318
2344
|
break;
|
|
2319
2345
|
case 61:
|
|
2320
|
-
|
|
2346
|
+
_context18.next = 66;
|
|
2321
2347
|
break;
|
|
2322
2348
|
case 63:
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
_iterator16.e(
|
|
2349
|
+
_context18.prev = 63;
|
|
2350
|
+
_context18.t1 = _context18["catch"](51);
|
|
2351
|
+
_iterator16.e(_context18.t1);
|
|
2326
2352
|
case 66:
|
|
2327
|
-
|
|
2353
|
+
_context18.prev = 66;
|
|
2328
2354
|
_iterator16.f();
|
|
2329
|
-
return
|
|
2355
|
+
return _context18.finish(66);
|
|
2330
2356
|
case 69:
|
|
2331
2357
|
if (duplicateIndexes.size > 0) {
|
|
2332
2358
|
_iterator17 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
|
|
@@ -2365,7 +2391,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2365
2391
|
this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
|
|
2366
2392
|
patchedOrders.push(mergedOrder);
|
|
2367
2393
|
if (mergeKey) mergeActions[mergeKey] = 'update';
|
|
2368
|
-
return
|
|
2394
|
+
return _context18.abrupt("continue", 80);
|
|
2369
2395
|
case 75:
|
|
2370
2396
|
insertIndex = updatedList.length;
|
|
2371
2397
|
updatedList.push(fresh);
|
|
@@ -2373,19 +2399,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2373
2399
|
patchedOrders.push(fresh);
|
|
2374
2400
|
if (mergeKey) mergeActions[mergeKey] = 'insert';
|
|
2375
2401
|
case 80:
|
|
2376
|
-
|
|
2402
|
+
_context18.next = 33;
|
|
2377
2403
|
break;
|
|
2378
2404
|
case 82:
|
|
2379
|
-
|
|
2405
|
+
_context18.next = 87;
|
|
2380
2406
|
break;
|
|
2381
2407
|
case 84:
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
_iterator15.e(
|
|
2408
|
+
_context18.prev = 84;
|
|
2409
|
+
_context18.t2 = _context18["catch"](31);
|
|
2410
|
+
_iterator15.e(_context18.t2);
|
|
2385
2411
|
case 87:
|
|
2386
|
-
|
|
2412
|
+
_context18.prev = 87;
|
|
2387
2413
|
_iterator15.f();
|
|
2388
|
-
return
|
|
2414
|
+
return _context18.finish(87);
|
|
2389
2415
|
case 90:
|
|
2390
2416
|
insertCount = Object.values(mergeActions).filter(function (v) {
|
|
2391
2417
|
return v === 'insert';
|
|
@@ -2402,7 +2428,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2402
2428
|
// 仅在自检开关开启时做一次兜底校验。
|
|
2403
2429
|
this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
|
|
2404
2430
|
this.syncOrdersMap();
|
|
2405
|
-
|
|
2431
|
+
_context18.next = 97;
|
|
2406
2432
|
return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
|
|
2407
2433
|
case 97:
|
|
2408
2434
|
this.logInfo('mergeOrdersToStore-结束', {
|
|
@@ -2411,13 +2437,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2411
2437
|
insertCount: insertCount,
|
|
2412
2438
|
updateCount: updateCount
|
|
2413
2439
|
});
|
|
2414
|
-
|
|
2440
|
+
_context18.next = 100;
|
|
2415
2441
|
return this.emitOrdersChanged(patchedOrders, source);
|
|
2416
2442
|
case 100:
|
|
2417
2443
|
case "end":
|
|
2418
|
-
return
|
|
2444
|
+
return _context18.stop();
|
|
2419
2445
|
}
|
|
2420
|
-
},
|
|
2446
|
+
}, _callee18, this, [[5, 17, 20, 23], [31, 84, 87, 90], [51, 63, 66, 69]]);
|
|
2421
2447
|
}));
|
|
2422
2448
|
function mergeOrdersToStore(_x12, _x13) {
|
|
2423
2449
|
return _mergeOrdersToStore.apply(this, arguments);
|
|
@@ -2556,12 +2582,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2556
2582
|
}, {
|
|
2557
2583
|
key: "isOrderLookupMatch",
|
|
2558
2584
|
value: function isOrderLookupMatch(order, lookupKey) {
|
|
2559
|
-
var
|
|
2585
|
+
var _this17 = this;
|
|
2560
2586
|
if (!order || !lookupKey) return false;
|
|
2561
2587
|
var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
|
|
2562
2588
|
return candidates.some(function (value) {
|
|
2563
2589
|
if (value === undefined || value === null || value === '') return false;
|
|
2564
|
-
return
|
|
2590
|
+
return _this17.getIdKey(value) === lookupKey;
|
|
2565
2591
|
});
|
|
2566
2592
|
}
|
|
2567
2593
|
|
|
@@ -2604,10 +2630,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2604
2630
|
}, {
|
|
2605
2631
|
key: "findOrderIndexByIdentity",
|
|
2606
2632
|
value: function findOrderIndexByIdentity(orders, target) {
|
|
2607
|
-
var
|
|
2633
|
+
var _this18 = this;
|
|
2608
2634
|
if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
|
|
2609
2635
|
return orders.findIndex(function (order) {
|
|
2610
|
-
return
|
|
2636
|
+
return _this18.doOrdersShareIdentity(order, target);
|
|
2611
2637
|
});
|
|
2612
2638
|
}
|
|
2613
2639
|
}, {
|
|
@@ -2799,14 +2825,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2799
2825
|
} finally {
|
|
2800
2826
|
_iterator26.f();
|
|
2801
2827
|
}
|
|
2802
|
-
return _toConsumableArray(groups.entries()).filter(function (
|
|
2803
|
-
var
|
|
2804
|
-
group =
|
|
2828
|
+
return _toConsumableArray(groups.entries()).filter(function (_ref5) {
|
|
2829
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
2830
|
+
group = _ref6[1];
|
|
2805
2831
|
return group.length > 1;
|
|
2806
|
-
}).slice(0, 20).map(function (
|
|
2807
|
-
var
|
|
2808
|
-
key =
|
|
2809
|
-
group =
|
|
2832
|
+
}).slice(0, 20).map(function (_ref7) {
|
|
2833
|
+
var _ref8 = _slicedToArray(_ref7, 2),
|
|
2834
|
+
key = _ref8[0],
|
|
2835
|
+
group = _ref8[1];
|
|
2810
2836
|
return {
|
|
2811
2837
|
key: key,
|
|
2812
2838
|
count: group.length,
|
|
@@ -2955,35 +2981,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2955
2981
|
}, {
|
|
2956
2982
|
key: "loadOrdersFromSQLite",
|
|
2957
2983
|
value: function () {
|
|
2958
|
-
var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2959
|
-
var
|
|
2984
|
+
var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
|
2985
|
+
var _this19 = this;
|
|
2960
2986
|
var orders;
|
|
2961
|
-
return _regeneratorRuntime().wrap(function
|
|
2962
|
-
while (1) switch (
|
|
2987
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
2988
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
2963
2989
|
case 0:
|
|
2964
2990
|
if (this.dbManager) {
|
|
2965
|
-
|
|
2991
|
+
_context19.next = 2;
|
|
2966
2992
|
break;
|
|
2967
2993
|
}
|
|
2968
|
-
return
|
|
2994
|
+
return _context19.abrupt("return", []);
|
|
2969
2995
|
case 2:
|
|
2970
|
-
|
|
2971
|
-
|
|
2996
|
+
_context19.prev = 2;
|
|
2997
|
+
_context19.next = 5;
|
|
2972
2998
|
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
2973
2999
|
case 5:
|
|
2974
|
-
orders =
|
|
2975
|
-
return
|
|
2976
|
-
return
|
|
3000
|
+
orders = _context19.sent;
|
|
3001
|
+
return _context19.abrupt("return", (orders || []).map(function (order) {
|
|
3002
|
+
return _this19.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
|
|
2977
3003
|
}));
|
|
2978
3004
|
case 9:
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
return
|
|
3005
|
+
_context19.prev = 9;
|
|
3006
|
+
_context19.t0 = _context19["catch"](2);
|
|
3007
|
+
return _context19.abrupt("return", []);
|
|
2982
3008
|
case 12:
|
|
2983
3009
|
case "end":
|
|
2984
|
-
return
|
|
3010
|
+
return _context19.stop();
|
|
2985
3011
|
}
|
|
2986
|
-
},
|
|
3012
|
+
}, _callee19, this, [[2, 9]]);
|
|
2987
3013
|
}));
|
|
2988
3014
|
function loadOrdersFromSQLite() {
|
|
2989
3015
|
return _loadOrdersFromSQLite.apply(this, arguments);
|
|
@@ -3017,12 +3043,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3017
3043
|
is_draft_order: 0
|
|
3018
3044
|
});
|
|
3019
3045
|
}
|
|
3046
|
+
}, {
|
|
3047
|
+
key: "mergeRemoteIdentityIntoDraftOrder",
|
|
3048
|
+
value: function mergeRemoteIdentityIntoDraftOrder(draftOrder, remoteOrder) {
|
|
3049
|
+
var merged = _objectSpread({}, this.withoutSyntheticDraftOrderId(draftOrder));
|
|
3050
|
+
var remote = remoteOrder;
|
|
3051
|
+
for (var _i7 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i7 < _arr.length; _i7++) {
|
|
3052
|
+
var field = _arr[_i7];
|
|
3053
|
+
if (this.isBlankIdentityValue(merged[field]) && !this.isBlankIdentityValue(remote[field])) {
|
|
3054
|
+
merged[field] = remote[field];
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
return this.normalizeOrderCollectionsForIngress(merged, 'mergeRemoteIdentityIntoDraftOrder');
|
|
3058
|
+
}
|
|
3020
3059
|
}, {
|
|
3021
3060
|
key: "mergeRemoteSnapshotWithPendingOrders",
|
|
3022
3061
|
value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
|
|
3023
|
-
var
|
|
3062
|
+
var _this20 = this;
|
|
3024
3063
|
var merged = remoteOrders.map(function (order) {
|
|
3025
|
-
return
|
|
3064
|
+
return _this20.normalizeRemoteSyncedOrder(order);
|
|
3026
3065
|
});
|
|
3027
3066
|
var _iterator29 = _createForOfIteratorHelper(existingOrders),
|
|
3028
3067
|
_step29;
|
|
@@ -3034,7 +3073,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3034
3073
|
var matchIndex = this.findOrderIndexByIdentity(merged, order);
|
|
3035
3074
|
if (matchIndex >= 0) {
|
|
3036
3075
|
if (this.isDraftOrder(order)) {
|
|
3037
|
-
merged[matchIndex] = order;
|
|
3076
|
+
merged[matchIndex] = this.mergeRemoteIdentityIntoDraftOrder(order, merged[matchIndex]);
|
|
3038
3077
|
} else {
|
|
3039
3078
|
merged[matchIndex] = this.mergeOrderRecords(order, merged[matchIndex]);
|
|
3040
3079
|
}
|
|
@@ -3062,10 +3101,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3062
3101
|
}, {
|
|
3063
3102
|
key: "runInOrderSQLiteSaveQueue",
|
|
3064
3103
|
value: (function () {
|
|
3065
|
-
var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3104
|
+
var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(task) {
|
|
3066
3105
|
var queuedTask;
|
|
3067
|
-
return _regeneratorRuntime().wrap(function
|
|
3068
|
-
while (1) switch (
|
|
3106
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
3107
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
3069
3108
|
case 0:
|
|
3070
3109
|
queuedTask = this.orderSQLiteSaveQueue.then(task, task);
|
|
3071
3110
|
this.orderSQLiteSaveQueue = queuedTask.then(function () {
|
|
@@ -3073,12 +3112,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3073
3112
|
}, function () {
|
|
3074
3113
|
return undefined;
|
|
3075
3114
|
});
|
|
3076
|
-
return
|
|
3115
|
+
return _context20.abrupt("return", queuedTask);
|
|
3077
3116
|
case 3:
|
|
3078
3117
|
case "end":
|
|
3079
|
-
return
|
|
3118
|
+
return _context20.stop();
|
|
3080
3119
|
}
|
|
3081
|
-
},
|
|
3120
|
+
}, _callee20, this);
|
|
3082
3121
|
}));
|
|
3083
3122
|
function runInOrderSQLiteSaveQueue(_x14) {
|
|
3084
3123
|
return _runInOrderSQLiteSaveQueue.apply(this, arguments);
|
|
@@ -3095,8 +3134,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3095
3134
|
}, {
|
|
3096
3135
|
key: "patchOrdersInSQLite",
|
|
3097
3136
|
value: (function () {
|
|
3098
|
-
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3099
|
-
var
|
|
3137
|
+
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orders, source) {
|
|
3138
|
+
var _this21 = this;
|
|
3100
3139
|
var mergeActions,
|
|
3101
3140
|
options,
|
|
3102
3141
|
ordersSnapshot,
|
|
@@ -3104,132 +3143,132 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3104
3143
|
toWrite,
|
|
3105
3144
|
skipped,
|
|
3106
3145
|
compactedToWrite,
|
|
3107
|
-
|
|
3108
|
-
return _regeneratorRuntime().wrap(function
|
|
3109
|
-
while (1) switch (
|
|
3146
|
+
_args22 = arguments;
|
|
3147
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
3148
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
3110
3149
|
case 0:
|
|
3111
|
-
mergeActions =
|
|
3112
|
-
options =
|
|
3150
|
+
mergeActions = _args22.length > 2 && _args22[2] !== undefined ? _args22[2] : {};
|
|
3151
|
+
options = _args22.length > 3 && _args22[3] !== undefined ? _args22[3] : {};
|
|
3113
3152
|
if (!(orders.length === 0)) {
|
|
3114
|
-
|
|
3153
|
+
_context22.next = 4;
|
|
3115
3154
|
break;
|
|
3116
3155
|
}
|
|
3117
|
-
return
|
|
3156
|
+
return _context22.abrupt("return");
|
|
3118
3157
|
case 4:
|
|
3119
3158
|
if (this.dbManager) {
|
|
3120
|
-
|
|
3159
|
+
_context22.next = 8;
|
|
3121
3160
|
break;
|
|
3122
3161
|
}
|
|
3123
3162
|
if (!options.throwOnError) {
|
|
3124
|
-
|
|
3163
|
+
_context22.next = 7;
|
|
3125
3164
|
break;
|
|
3126
3165
|
}
|
|
3127
3166
|
throw new Error('订单 SQLite 数据库未初始化');
|
|
3128
3167
|
case 7:
|
|
3129
|
-
return
|
|
3168
|
+
return _context22.abrupt("return");
|
|
3130
3169
|
case 8:
|
|
3131
3170
|
ordersSnapshot = cloneDeep(orders).map(function (order) {
|
|
3132
|
-
return
|
|
3171
|
+
return _this21.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
|
|
3133
3172
|
}).filter(function (order) {
|
|
3134
|
-
return
|
|
3173
|
+
return _this21.getOrderStorageKey(order);
|
|
3135
3174
|
});
|
|
3136
3175
|
if (!(ordersSnapshot.length === 0)) {
|
|
3137
|
-
|
|
3176
|
+
_context22.next = 11;
|
|
3138
3177
|
break;
|
|
3139
3178
|
}
|
|
3140
|
-
return
|
|
3179
|
+
return _context22.abrupt("return");
|
|
3141
3180
|
case 11:
|
|
3142
3181
|
_this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
|
|
3143
3182
|
if (!(toWrite.length === 0)) {
|
|
3144
|
-
|
|
3183
|
+
_context22.next = 14;
|
|
3145
3184
|
break;
|
|
3146
3185
|
}
|
|
3147
|
-
return
|
|
3186
|
+
return _context22.abrupt("return");
|
|
3148
3187
|
case 14:
|
|
3149
3188
|
compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
|
|
3150
3189
|
if (!(compactedToWrite.length === 0)) {
|
|
3151
|
-
|
|
3190
|
+
_context22.next = 17;
|
|
3152
3191
|
break;
|
|
3153
3192
|
}
|
|
3154
|
-
return
|
|
3193
|
+
return _context22.abrupt("return");
|
|
3155
3194
|
case 17:
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3195
|
+
_context22.prev = 17;
|
|
3196
|
+
_context22.next = 20;
|
|
3197
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
|
|
3159
3198
|
var writeMethod, _iterator30, _step30, order;
|
|
3160
|
-
return _regeneratorRuntime().wrap(function
|
|
3161
|
-
while (1) switch (
|
|
3199
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
3200
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
3162
3201
|
case 0:
|
|
3163
3202
|
writeMethod = 'none';
|
|
3164
|
-
|
|
3203
|
+
_this21.logInfo('patchOrdersInSQLite-开始', {
|
|
3165
3204
|
source: source,
|
|
3166
3205
|
count: compactedToWrite.length,
|
|
3167
3206
|
dedupedCount: skipped.length
|
|
3168
3207
|
});
|
|
3169
|
-
if (!(typeof
|
|
3170
|
-
|
|
3208
|
+
if (!(typeof _this21.dbManager.bulkUpdate === 'function')) {
|
|
3209
|
+
_context21.next = 8;
|
|
3171
3210
|
break;
|
|
3172
3211
|
}
|
|
3173
3212
|
writeMethod = 'bulkUpdate';
|
|
3174
|
-
|
|
3175
|
-
return
|
|
3213
|
+
_context21.next = 6;
|
|
3214
|
+
return _this21.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
|
|
3176
3215
|
case 6:
|
|
3177
|
-
|
|
3216
|
+
_context21.next = 37;
|
|
3178
3217
|
break;
|
|
3179
3218
|
case 8:
|
|
3180
|
-
if (!(typeof
|
|
3181
|
-
|
|
3219
|
+
if (!(typeof _this21.dbManager.bulkAdd === 'function')) {
|
|
3220
|
+
_context21.next = 14;
|
|
3182
3221
|
break;
|
|
3183
3222
|
}
|
|
3184
3223
|
writeMethod = 'bulkAdd';
|
|
3185
|
-
|
|
3186
|
-
return
|
|
3224
|
+
_context21.next = 12;
|
|
3225
|
+
return _this21.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
|
|
3187
3226
|
case 12:
|
|
3188
|
-
|
|
3227
|
+
_context21.next = 37;
|
|
3189
3228
|
break;
|
|
3190
3229
|
case 14:
|
|
3191
|
-
if (!(typeof
|
|
3192
|
-
|
|
3230
|
+
if (!(typeof _this21.dbManager.update === 'function')) {
|
|
3231
|
+
_context21.next = 35;
|
|
3193
3232
|
break;
|
|
3194
3233
|
}
|
|
3195
3234
|
writeMethod = 'update';
|
|
3196
3235
|
_iterator30 = _createForOfIteratorHelper(compactedToWrite);
|
|
3197
|
-
|
|
3236
|
+
_context21.prev = 17;
|
|
3198
3237
|
_iterator30.s();
|
|
3199
3238
|
case 19:
|
|
3200
3239
|
if ((_step30 = _iterator30.n()).done) {
|
|
3201
|
-
|
|
3240
|
+
_context21.next = 25;
|
|
3202
3241
|
break;
|
|
3203
3242
|
}
|
|
3204
3243
|
order = _step30.value;
|
|
3205
|
-
|
|
3206
|
-
return
|
|
3244
|
+
_context21.next = 23;
|
|
3245
|
+
return _this21.dbManager.update(INDEXDB_STORE_NAME, order);
|
|
3207
3246
|
case 23:
|
|
3208
|
-
|
|
3247
|
+
_context21.next = 19;
|
|
3209
3248
|
break;
|
|
3210
3249
|
case 25:
|
|
3211
|
-
|
|
3250
|
+
_context21.next = 30;
|
|
3212
3251
|
break;
|
|
3213
3252
|
case 27:
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
_iterator30.e(
|
|
3253
|
+
_context21.prev = 27;
|
|
3254
|
+
_context21.t0 = _context21["catch"](17);
|
|
3255
|
+
_iterator30.e(_context21.t0);
|
|
3217
3256
|
case 30:
|
|
3218
|
-
|
|
3257
|
+
_context21.prev = 30;
|
|
3219
3258
|
_iterator30.f();
|
|
3220
|
-
return
|
|
3259
|
+
return _context21.finish(30);
|
|
3221
3260
|
case 33:
|
|
3222
|
-
|
|
3261
|
+
_context21.next = 37;
|
|
3223
3262
|
break;
|
|
3224
3263
|
case 35:
|
|
3225
3264
|
if (!options.throwOnError) {
|
|
3226
|
-
|
|
3265
|
+
_context21.next = 37;
|
|
3227
3266
|
break;
|
|
3228
3267
|
}
|
|
3229
3268
|
throw new Error('订单 SQLite 数据库不支持写入');
|
|
3230
3269
|
case 37:
|
|
3231
|
-
|
|
3232
|
-
|
|
3270
|
+
_this21.recordRecentSqliteWrite(source, compactedToWrite);
|
|
3271
|
+
_this21.logInfo('patchOrdersInSQLite-完成', {
|
|
3233
3272
|
source: source,
|
|
3234
3273
|
count: compactedToWrite.length,
|
|
3235
3274
|
writeMethod: writeMethod,
|
|
@@ -3237,30 +3276,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3237
3276
|
});
|
|
3238
3277
|
case 39:
|
|
3239
3278
|
case "end":
|
|
3240
|
-
return
|
|
3279
|
+
return _context21.stop();
|
|
3241
3280
|
}
|
|
3242
|
-
},
|
|
3281
|
+
}, _callee21, null, [[17, 27, 30, 33]]);
|
|
3243
3282
|
})));
|
|
3244
3283
|
case 20:
|
|
3245
|
-
|
|
3284
|
+
_context22.next = 27;
|
|
3246
3285
|
break;
|
|
3247
3286
|
case 22:
|
|
3248
|
-
|
|
3249
|
-
|
|
3287
|
+
_context22.prev = 22;
|
|
3288
|
+
_context22.t0 = _context22["catch"](17);
|
|
3250
3289
|
this.logError('增量保存订单到 SQLite 失败', {
|
|
3251
|
-
error:
|
|
3290
|
+
error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0),
|
|
3252
3291
|
orderCount: ordersSnapshot.length
|
|
3253
3292
|
});
|
|
3254
3293
|
if (!options.throwOnError) {
|
|
3255
|
-
|
|
3294
|
+
_context22.next = 27;
|
|
3256
3295
|
break;
|
|
3257
3296
|
}
|
|
3258
|
-
throw
|
|
3297
|
+
throw _context22.t0;
|
|
3259
3298
|
case 27:
|
|
3260
3299
|
case "end":
|
|
3261
|
-
return
|
|
3300
|
+
return _context22.stop();
|
|
3262
3301
|
}
|
|
3263
|
-
},
|
|
3302
|
+
}, _callee22, this, [[17, 22]]);
|
|
3264
3303
|
}));
|
|
3265
3304
|
function patchOrdersInSQLite(_x15, _x16) {
|
|
3266
3305
|
return _patchOrdersInSQLite.apply(this, arguments);
|
|
@@ -3277,126 +3316,126 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3277
3316
|
}, {
|
|
3278
3317
|
key: "updateOrderInSQLite",
|
|
3279
3318
|
value: (function () {
|
|
3280
|
-
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3281
|
-
var
|
|
3319
|
+
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(order, source) {
|
|
3320
|
+
var _this22 = this;
|
|
3282
3321
|
var options,
|
|
3283
3322
|
orderSnapshot,
|
|
3284
3323
|
_orderSnapshot$order_3,
|
|
3285
|
-
|
|
3286
|
-
return _regeneratorRuntime().wrap(function
|
|
3287
|
-
while (1) switch (
|
|
3324
|
+
_args24 = arguments;
|
|
3325
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
3326
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
3288
3327
|
case 0:
|
|
3289
|
-
options =
|
|
3328
|
+
options = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : {};
|
|
3290
3329
|
if (this.getOrderStorageKey(order)) {
|
|
3291
|
-
|
|
3330
|
+
_context24.next = 5;
|
|
3292
3331
|
break;
|
|
3293
3332
|
}
|
|
3294
3333
|
if (!options.throwOnError) {
|
|
3295
|
-
|
|
3334
|
+
_context24.next = 4;
|
|
3296
3335
|
break;
|
|
3297
3336
|
}
|
|
3298
3337
|
throw new Error('订单缺少可用的 SQLite 存储主键');
|
|
3299
3338
|
case 4:
|
|
3300
|
-
return
|
|
3339
|
+
return _context24.abrupt("return");
|
|
3301
3340
|
case 5:
|
|
3302
3341
|
if (this.dbManager) {
|
|
3303
|
-
|
|
3342
|
+
_context24.next = 9;
|
|
3304
3343
|
break;
|
|
3305
3344
|
}
|
|
3306
3345
|
if (!options.throwOnError) {
|
|
3307
|
-
|
|
3346
|
+
_context24.next = 8;
|
|
3308
3347
|
break;
|
|
3309
3348
|
}
|
|
3310
3349
|
throw new Error('订单 SQLite 数据库未初始化');
|
|
3311
3350
|
case 8:
|
|
3312
|
-
return
|
|
3351
|
+
return _context24.abrupt("return");
|
|
3313
3352
|
case 9:
|
|
3314
3353
|
orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3354
|
+
_context24.prev = 10;
|
|
3355
|
+
_context24.next = 13;
|
|
3356
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
|
|
3318
3357
|
var _orderSnapshot$order_, _orderSnapshot$order_2;
|
|
3319
3358
|
var writeMethod;
|
|
3320
|
-
return _regeneratorRuntime().wrap(function
|
|
3321
|
-
while (1) switch (
|
|
3359
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
3360
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
3322
3361
|
case 0:
|
|
3323
3362
|
writeMethod = 'none';
|
|
3324
|
-
|
|
3363
|
+
_this22.logInfo('updateOrderInSQLite-开始', {
|
|
3325
3364
|
source: source,
|
|
3326
3365
|
orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
|
|
3327
|
-
storageKey:
|
|
3366
|
+
storageKey: _this22.getOrderStorageKey(orderSnapshot)
|
|
3328
3367
|
});
|
|
3329
|
-
if (!(typeof
|
|
3330
|
-
|
|
3368
|
+
if (!(typeof _this22.dbManager.update === 'function')) {
|
|
3369
|
+
_context23.next = 8;
|
|
3331
3370
|
break;
|
|
3332
3371
|
}
|
|
3333
3372
|
writeMethod = 'update';
|
|
3334
|
-
|
|
3335
|
-
return
|
|
3373
|
+
_context23.next = 6;
|
|
3374
|
+
return _this22.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
|
|
3336
3375
|
case 6:
|
|
3337
|
-
|
|
3376
|
+
_context23.next = 22;
|
|
3338
3377
|
break;
|
|
3339
3378
|
case 8:
|
|
3340
|
-
if (!(typeof
|
|
3341
|
-
|
|
3379
|
+
if (!(typeof _this22.dbManager.bulkUpdate === 'function')) {
|
|
3380
|
+
_context23.next = 14;
|
|
3342
3381
|
break;
|
|
3343
3382
|
}
|
|
3344
3383
|
writeMethod = 'bulkUpdate';
|
|
3345
|
-
|
|
3346
|
-
return
|
|
3384
|
+
_context23.next = 12;
|
|
3385
|
+
return _this22.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
3347
3386
|
case 12:
|
|
3348
|
-
|
|
3387
|
+
_context23.next = 22;
|
|
3349
3388
|
break;
|
|
3350
3389
|
case 14:
|
|
3351
|
-
if (!(typeof
|
|
3352
|
-
|
|
3390
|
+
if (!(typeof _this22.dbManager.bulkAdd === 'function')) {
|
|
3391
|
+
_context23.next = 20;
|
|
3353
3392
|
break;
|
|
3354
3393
|
}
|
|
3355
3394
|
writeMethod = 'bulkAdd';
|
|
3356
|
-
|
|
3357
|
-
return
|
|
3395
|
+
_context23.next = 18;
|
|
3396
|
+
return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
3358
3397
|
case 18:
|
|
3359
|
-
|
|
3398
|
+
_context23.next = 22;
|
|
3360
3399
|
break;
|
|
3361
3400
|
case 20:
|
|
3362
3401
|
if (!options.throwOnError) {
|
|
3363
|
-
|
|
3402
|
+
_context23.next = 22;
|
|
3364
3403
|
break;
|
|
3365
3404
|
}
|
|
3366
3405
|
throw new Error('订单 SQLite 数据库不支持写入');
|
|
3367
3406
|
case 22:
|
|
3368
|
-
|
|
3369
|
-
|
|
3407
|
+
_this22.recordRecentSqliteWrite(source, [orderSnapshot]);
|
|
3408
|
+
_this22.logInfo('updateOrderInSQLite-完成', {
|
|
3370
3409
|
source: source,
|
|
3371
3410
|
orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
|
|
3372
3411
|
writeMethod: writeMethod
|
|
3373
3412
|
});
|
|
3374
3413
|
case 24:
|
|
3375
3414
|
case "end":
|
|
3376
|
-
return
|
|
3415
|
+
return _context23.stop();
|
|
3377
3416
|
}
|
|
3378
|
-
},
|
|
3417
|
+
}, _callee23);
|
|
3379
3418
|
})));
|
|
3380
3419
|
case 13:
|
|
3381
|
-
|
|
3420
|
+
_context24.next = 20;
|
|
3382
3421
|
break;
|
|
3383
3422
|
case 15:
|
|
3384
|
-
|
|
3385
|
-
|
|
3423
|
+
_context24.prev = 15;
|
|
3424
|
+
_context24.t0 = _context24["catch"](10);
|
|
3386
3425
|
this.logError('单条保存订单到 SQLite 失败', {
|
|
3387
|
-
error:
|
|
3426
|
+
error: _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0),
|
|
3388
3427
|
orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
|
|
3389
3428
|
});
|
|
3390
3429
|
if (!options.throwOnError) {
|
|
3391
|
-
|
|
3430
|
+
_context24.next = 20;
|
|
3392
3431
|
break;
|
|
3393
3432
|
}
|
|
3394
|
-
throw
|
|
3433
|
+
throw _context24.t0;
|
|
3395
3434
|
case 20:
|
|
3396
3435
|
case "end":
|
|
3397
|
-
return
|
|
3436
|
+
return _context24.stop();
|
|
3398
3437
|
}
|
|
3399
|
-
},
|
|
3438
|
+
}, _callee24, this, [[10, 15]]);
|
|
3400
3439
|
}));
|
|
3401
3440
|
function updateOrderInSQLite(_x17, _x18) {
|
|
3402
3441
|
return _updateOrderInSQLite.apply(this, arguments);
|
|
@@ -3404,7 +3443,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3404
3443
|
return updateOrderInSQLite;
|
|
3405
3444
|
}()
|
|
3406
3445
|
/**
|
|
3407
|
-
* 全量快照替换 orders 表(clear + bulkAdd
|
|
3446
|
+
* 全量快照替换 orders 表(clear + bulkAdd),并保留本地 draft / need_sync 订单。
|
|
3447
|
+
* 用于 SSE 全量拉取与营业日窗口裁剪。
|
|
3408
3448
|
*
|
|
3409
3449
|
* @example
|
|
3410
3450
|
* await this.replaceOrdersSnapshotInSQLite(orderList)
|
|
@@ -3413,98 +3453,148 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3413
3453
|
}, {
|
|
3414
3454
|
key: "replaceOrdersSnapshotInSQLite",
|
|
3415
3455
|
value: (function () {
|
|
3416
|
-
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3417
|
-
var
|
|
3418
|
-
var
|
|
3419
|
-
|
|
3420
|
-
|
|
3456
|
+
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(orderList, source) {
|
|
3457
|
+
var _this23 = this;
|
|
3458
|
+
var protectedOrdersBeforeRemoteFetch,
|
|
3459
|
+
remoteSnapshot,
|
|
3460
|
+
mergedSnapshot,
|
|
3461
|
+
_args26 = arguments;
|
|
3462
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
3463
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
3421
3464
|
case 0:
|
|
3465
|
+
protectedOrdersBeforeRemoteFetch = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : [];
|
|
3422
3466
|
if (this.dbManager) {
|
|
3423
|
-
|
|
3467
|
+
_context26.next = 3;
|
|
3424
3468
|
break;
|
|
3425
3469
|
}
|
|
3426
|
-
return
|
|
3427
|
-
return
|
|
3470
|
+
return _context26.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
|
|
3471
|
+
return _this23.normalizeRemoteSyncedOrder(order);
|
|
3428
3472
|
}), "".concat(source, ".snapshotNoDb")).list);
|
|
3429
|
-
case
|
|
3473
|
+
case 3:
|
|
3430
3474
|
remoteSnapshot = cloneDeep(orderList).map(function (order) {
|
|
3431
|
-
return
|
|
3475
|
+
return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
|
|
3432
3476
|
});
|
|
3433
3477
|
mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
|
|
3434
|
-
return
|
|
3478
|
+
return _this23.normalizeRemoteSyncedOrder(order);
|
|
3435
3479
|
}), "".concat(source, ".remoteSnapshot")).list;
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3439
|
-
var existingOrders, orderListSnapshot;
|
|
3440
|
-
return _regeneratorRuntime().wrap(function
|
|
3441
|
-
while (1) switch (
|
|
3480
|
+
_context26.prev = 5;
|
|
3481
|
+
_context26.next = 8;
|
|
3482
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
3483
|
+
var existingOrders, protectedLocalOrders, _iterator31, _step31, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
|
|
3484
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
3485
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
3442
3486
|
case 0:
|
|
3443
|
-
if (!(typeof
|
|
3444
|
-
|
|
3487
|
+
if (!(typeof _this23.dbManager.getAll === 'function')) {
|
|
3488
|
+
_context25.next = 6;
|
|
3445
3489
|
break;
|
|
3446
3490
|
}
|
|
3447
|
-
|
|
3448
|
-
return
|
|
3491
|
+
_context25.next = 3;
|
|
3492
|
+
return _this23.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
3449
3493
|
case 3:
|
|
3450
|
-
|
|
3451
|
-
|
|
3494
|
+
_context25.t0 = _context25.sent;
|
|
3495
|
+
_context25.next = 7;
|
|
3452
3496
|
break;
|
|
3453
3497
|
case 6:
|
|
3454
|
-
|
|
3498
|
+
_context25.t0 = [];
|
|
3455
3499
|
case 7:
|
|
3456
|
-
existingOrders =
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3500
|
+
existingOrders = _context25.t0;
|
|
3501
|
+
protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
|
|
3502
|
+
return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
|
|
3503
|
+
}).filter(function (order) {
|
|
3504
|
+
return _this23.isPendingSyncOrder(order) || _this23.isDraftOrder(order);
|
|
3505
|
+
});
|
|
3506
|
+
_iterator31 = _createForOfIteratorHelper(existingOrders || []);
|
|
3507
|
+
_context25.prev = 10;
|
|
3508
|
+
_iterator31.s();
|
|
3509
|
+
case 12:
|
|
3510
|
+
if ((_step31 = _iterator31.n()).done) {
|
|
3511
|
+
_context25.next = 23;
|
|
3512
|
+
break;
|
|
3513
|
+
}
|
|
3514
|
+
rawCurrentOrder = _step31.value;
|
|
3515
|
+
currentOrder = _this23.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
|
|
3516
|
+
protectedIndex = _this23.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
|
|
3517
|
+
currentNeedsProtection = _this23.isPendingSyncOrder(currentOrder) || _this23.isDraftOrder(currentOrder);
|
|
3518
|
+
if (!(protectedIndex >= 0)) {
|
|
3519
|
+
_context25.next = 20;
|
|
3520
|
+
break;
|
|
3521
|
+
}
|
|
3522
|
+
if (currentNeedsProtection) {
|
|
3523
|
+
protectedLocalOrders[protectedIndex] = currentOrder;
|
|
3524
|
+
} else {
|
|
3525
|
+
protectedLocalOrders.splice(protectedIndex, 1);
|
|
3526
|
+
}
|
|
3527
|
+
return _context25.abrupt("continue", 21);
|
|
3528
|
+
case 20:
|
|
3529
|
+
if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
|
|
3530
|
+
case 21:
|
|
3531
|
+
_context25.next = 12;
|
|
3532
|
+
break;
|
|
3533
|
+
case 23:
|
|
3534
|
+
_context25.next = 28;
|
|
3535
|
+
break;
|
|
3536
|
+
case 25:
|
|
3537
|
+
_context25.prev = 25;
|
|
3538
|
+
_context25.t1 = _context25["catch"](10);
|
|
3539
|
+
_iterator31.e(_context25.t1);
|
|
3540
|
+
case 28:
|
|
3541
|
+
_context25.prev = 28;
|
|
3542
|
+
_iterator31.f();
|
|
3543
|
+
return _context25.finish(28);
|
|
3544
|
+
case 31:
|
|
3545
|
+
orderListSnapshot = _this23.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
|
|
3546
|
+
mergedSnapshot = _this23.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
|
|
3547
|
+
_this23.logInfo('replaceOrdersSnapshotInSQLite-开始', {
|
|
3460
3548
|
source: source,
|
|
3461
3549
|
count: mergedSnapshot.length,
|
|
3462
3550
|
remoteCount: remoteSnapshot.length,
|
|
3551
|
+
protectedBeforeRemoteFetchCount: protectedOrdersBeforeRemoteFetch.length,
|
|
3552
|
+
protectedLocalOrderCount: protectedLocalOrders.length,
|
|
3463
3553
|
preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length
|
|
3464
3554
|
});
|
|
3465
|
-
|
|
3466
|
-
return
|
|
3467
|
-
case
|
|
3468
|
-
|
|
3555
|
+
_context25.next = 36;
|
|
3556
|
+
return _this23.dbManager.clear(INDEXDB_STORE_NAME);
|
|
3557
|
+
case 36:
|
|
3558
|
+
_this23.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
|
|
3469
3559
|
count: mergedSnapshot.length
|
|
3470
3560
|
});
|
|
3471
3561
|
if (!(mergedSnapshot.length === 0)) {
|
|
3472
|
-
|
|
3562
|
+
_context25.next = 39;
|
|
3473
3563
|
break;
|
|
3474
3564
|
}
|
|
3475
|
-
return
|
|
3476
|
-
case
|
|
3477
|
-
|
|
3478
|
-
return
|
|
3479
|
-
case
|
|
3480
|
-
|
|
3481
|
-
|
|
3565
|
+
return _context25.abrupt("return");
|
|
3566
|
+
case 39:
|
|
3567
|
+
_context25.next = 41;
|
|
3568
|
+
return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
|
|
3569
|
+
case 41:
|
|
3570
|
+
_this23.recordRecentSqliteWrite(source, mergedSnapshot);
|
|
3571
|
+
_this23.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
|
|
3482
3572
|
source: source,
|
|
3483
3573
|
count: mergedSnapshot.length
|
|
3484
3574
|
});
|
|
3485
|
-
case
|
|
3575
|
+
case 43:
|
|
3486
3576
|
case "end":
|
|
3487
|
-
return
|
|
3577
|
+
return _context25.stop();
|
|
3488
3578
|
}
|
|
3489
|
-
},
|
|
3579
|
+
}, _callee25, null, [[10, 25, 28, 31]]);
|
|
3490
3580
|
})));
|
|
3491
|
-
case
|
|
3492
|
-
|
|
3581
|
+
case 8:
|
|
3582
|
+
_context26.next = 13;
|
|
3493
3583
|
break;
|
|
3494
|
-
case
|
|
3495
|
-
|
|
3496
|
-
|
|
3584
|
+
case 10:
|
|
3585
|
+
_context26.prev = 10;
|
|
3586
|
+
_context26.t0 = _context26["catch"](5);
|
|
3497
3587
|
this.logError('全量保存订单到 SQLite 失败', {
|
|
3498
|
-
error:
|
|
3588
|
+
error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0),
|
|
3499
3589
|
orderList: remoteSnapshot.length
|
|
3500
3590
|
});
|
|
3501
|
-
case 12:
|
|
3502
|
-
return _context27.abrupt("return", mergedSnapshot);
|
|
3503
3591
|
case 13:
|
|
3592
|
+
return _context26.abrupt("return", mergedSnapshot);
|
|
3593
|
+
case 14:
|
|
3504
3594
|
case "end":
|
|
3505
|
-
return
|
|
3595
|
+
return _context26.stop();
|
|
3506
3596
|
}
|
|
3507
|
-
},
|
|
3597
|
+
}, _callee26, this, [[5, 10]]);
|
|
3508
3598
|
}));
|
|
3509
3599
|
function replaceOrdersSnapshotInSQLite(_x19, _x20) {
|
|
3510
3600
|
return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
|
|
@@ -3521,38 +3611,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3521
3611
|
}, {
|
|
3522
3612
|
key: "clear",
|
|
3523
3613
|
value: (function () {
|
|
3524
|
-
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3525
|
-
var
|
|
3526
|
-
return _regeneratorRuntime().wrap(function
|
|
3527
|
-
while (1) switch (
|
|
3614
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
|
|
3615
|
+
var _this24 = this;
|
|
3616
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
3617
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
3528
3618
|
case 0:
|
|
3529
3619
|
this.store.list = [];
|
|
3530
3620
|
this.store.map = new Map();
|
|
3531
3621
|
if (!this.dbManager) {
|
|
3532
|
-
|
|
3622
|
+
_context28.next = 5;
|
|
3533
3623
|
break;
|
|
3534
3624
|
}
|
|
3535
|
-
|
|
3536
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3537
|
-
return _regeneratorRuntime().wrap(function
|
|
3538
|
-
while (1) switch (
|
|
3625
|
+
_context28.next = 5;
|
|
3626
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
|
|
3627
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
3628
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
3539
3629
|
case 0:
|
|
3540
|
-
|
|
3541
|
-
return
|
|
3630
|
+
_context27.next = 2;
|
|
3631
|
+
return _this24.dbManager.clear(INDEXDB_STORE_NAME);
|
|
3542
3632
|
case 2:
|
|
3543
3633
|
case "end":
|
|
3544
|
-
return
|
|
3634
|
+
return _context27.stop();
|
|
3545
3635
|
}
|
|
3546
|
-
},
|
|
3636
|
+
}, _callee27);
|
|
3547
3637
|
})));
|
|
3548
3638
|
case 5:
|
|
3549
3639
|
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
|
|
3550
3640
|
this.emitOrdersChanged([], 'clear');
|
|
3551
3641
|
case 7:
|
|
3552
3642
|
case "end":
|
|
3553
|
-
return
|
|
3643
|
+
return _context28.stop();
|
|
3554
3644
|
}
|
|
3555
|
-
},
|
|
3645
|
+
}, _callee28, this);
|
|
3556
3646
|
}));
|
|
3557
3647
|
function clear() {
|
|
3558
3648
|
return _clear.apply(this, arguments);
|