@pisell/pisellos 2.3.29 → 2.3.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Order/index.d.ts +27 -8
- package/dist/modules/Order/index.js +736 -473
- package/dist/modules/Order/payment-utils.d.ts +23 -0
- package/dist/modules/Order/payment-utils.js +203 -0
- package/dist/modules/Order/types.d.ts +33 -1
- package/dist/modules/Order/utils.js +4 -4
- package/dist/modules/Payment/index.d.ts +2 -0
- package/dist/modules/Payment/index.js +78 -49
- package/dist/modules/Payment/types.d.ts +26 -24
- package/dist/modules/Payment/types.js +2 -0
- package/dist/server/index.d.ts +14 -0
- package/dist/server/index.js +1850 -1024
- package/dist/server/modules/order/index.d.ts +40 -3
- package/dist/server/modules/order/index.js +1200 -501
- package/dist/server/modules/order/types.d.ts +11 -3
- package/dist/server/modules/order/types.js +1 -1
- package/dist/solution/BaseSales/index.d.ts +33 -3
- package/dist/solution/BaseSales/index.js +609 -322
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +2 -1
- package/dist/utils/payment-number.d.ts +9 -0
- package/dist/utils/payment-number.js +69 -0
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/modules/Order/index.d.ts +27 -8
- package/lib/modules/Order/index.js +180 -60
- package/lib/modules/Order/payment-utils.d.ts +23 -0
- package/lib/modules/Order/payment-utils.js +193 -0
- package/lib/modules/Order/types.d.ts +33 -1
- package/lib/modules/Order/utils.js +2 -3
- package/lib/modules/Payment/index.d.ts +2 -0
- package/lib/modules/Payment/index.js +33 -12
- package/lib/modules/Payment/types.d.ts +26 -24
- package/lib/server/index.d.ts +14 -0
- package/lib/server/index.js +604 -8
- package/lib/server/modules/order/index.d.ts +40 -3
- package/lib/server/modules/order/index.js +434 -31
- package/lib/server/modules/order/types.d.ts +11 -3
- package/lib/solution/BaseSales/index.d.ts +33 -3
- package/lib/solution/BaseSales/index.js +167 -7
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +2 -1
- package/lib/utils/payment-number.d.ts +9 -0
- package/lib/utils/payment-number.js +64 -0
- package/package.json +1 -1
|
@@ -35,6 +35,7 @@ import dayjs from 'dayjs';
|
|
|
35
35
|
import { BaseModule } from "../../../modules/BaseModule";
|
|
36
36
|
import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollections } from "../../../modules/Order/utils/orderCollectionIdentity";
|
|
37
37
|
import { OrderHooks } from "./types";
|
|
38
|
+
import { mergeOrderPaymentListsByIdentity, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "../../../modules/Order/payment-utils";
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* SQLite 存储名称
|
|
@@ -48,7 +49,7 @@ var ORDER_SQLITE_DEDUPE_MS = 15000;
|
|
|
48
49
|
/** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
|
|
49
50
|
var ORDER_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
|
|
50
51
|
/** 视为「业务侧刚写入」的来源,pubsub 回声可跳过 SQLite */
|
|
51
|
-
var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'overwriteExistingOrder', 'markOrderSyncedByExternalSaleNumber']);
|
|
52
|
+
var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'upsertLocalDraftOrders', 'overwriteExistingOrder', 'markOrderSyncedByExternalSaleNumber', 'updateLocalPayment']);
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* 合并热路径全表去重自检开关:默认关闭。
|
|
@@ -680,6 +681,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
680
681
|
value: function getOrderByOrderId(orderId) {
|
|
681
682
|
return this.store.map.get(this.getIdKey(orderId));
|
|
682
683
|
}
|
|
684
|
+
}, {
|
|
685
|
+
key: "buildLocalPaymentOrderLogContext",
|
|
686
|
+
value: function buildLocalPaymentOrderLogContext(order) {
|
|
687
|
+
var _order$order_id3, _order$external_sale_, _order$order_number, _order$shop_order_num, _order$shop_full_orde, _order$status, _order$payment_status, _order$platform, _order$business_code, _order$order_sales_ch, _order$sales_channel, _order$type;
|
|
688
|
+
if (!order) return {};
|
|
689
|
+
return {
|
|
690
|
+
order_id: (_order$order_id3 = order.order_id) !== null && _order$order_id3 !== void 0 ? _order$order_id3 : null,
|
|
691
|
+
external_sale_number: (_order$external_sale_ = order.external_sale_number) !== null && _order$external_sale_ !== void 0 ? _order$external_sale_ : null,
|
|
692
|
+
order_number: (_order$order_number = order.order_number) !== null && _order$order_number !== void 0 ? _order$order_number : null,
|
|
693
|
+
shop_order_number: (_order$shop_order_num = order.shop_order_number) !== null && _order$shop_order_num !== void 0 ? _order$shop_order_num : null,
|
|
694
|
+
shop_full_order_number: (_order$shop_full_orde = order.shop_full_order_number) !== null && _order$shop_full_orde !== void 0 ? _order$shop_full_orde : null,
|
|
695
|
+
order_status: (_order$status = order.status) !== null && _order$status !== void 0 ? _order$status : null,
|
|
696
|
+
payment_status: (_order$payment_status = order.payment_status) !== null && _order$payment_status !== void 0 ? _order$payment_status : null,
|
|
697
|
+
is_draft_order: Number(order.is_draft_order || 0),
|
|
698
|
+
need_sync: Number(order.need_sync || 0),
|
|
699
|
+
platform: (_order$platform = order.platform) !== null && _order$platform !== void 0 ? _order$platform : null,
|
|
700
|
+
business_code: (_order$business_code = order.business_code) !== null && _order$business_code !== void 0 ? _order$business_code : null,
|
|
701
|
+
order_sales_channel: (_order$order_sales_ch = order.order_sales_channel) !== null && _order$order_sales_ch !== void 0 ? _order$order_sales_ch : null,
|
|
702
|
+
sales_channel: (_order$sales_channel = order.sales_channel) !== null && _order$sales_channel !== void 0 ? _order$sales_channel : null,
|
|
703
|
+
order_type: (_order$type = order.type) !== null && _order$type !== void 0 ? _order$type : null,
|
|
704
|
+
payments_count: Array.isArray(order.payments) ? order.payments.length : 0
|
|
705
|
+
};
|
|
706
|
+
}
|
|
683
707
|
}, {
|
|
684
708
|
key: "getLocalOrderFromMemoryByLookup",
|
|
685
709
|
value: function getLocalOrderFromMemoryByLookup(lookup) {
|
|
@@ -697,46 +721,83 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
697
721
|
value: function () {
|
|
698
722
|
var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
|
|
699
723
|
var _this6 = this;
|
|
700
|
-
var
|
|
724
|
+
var options,
|
|
725
|
+
key,
|
|
726
|
+
logContext,
|
|
727
|
+
memoryOrderById,
|
|
728
|
+
memoryOrder,
|
|
729
|
+
orders,
|
|
730
|
+
localOrder,
|
|
731
|
+
normalizedOrder,
|
|
732
|
+
_args5 = arguments;
|
|
701
733
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
702
734
|
while (1) switch (_context5.prev = _context5.next) {
|
|
703
735
|
case 0:
|
|
736
|
+
options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
|
|
704
737
|
key = this.getIdKey(lookup);
|
|
738
|
+
logContext = {
|
|
739
|
+
operation_id: options.operationId,
|
|
740
|
+
lookup: key,
|
|
741
|
+
memory_order_count: this.store.list.length
|
|
742
|
+
};
|
|
743
|
+
if (options.operationId) {
|
|
744
|
+
this.logInfo('getLocalOrderByLookup-localPayment-开始', logContext);
|
|
745
|
+
}
|
|
705
746
|
memoryOrderById = this.store.map.get(key);
|
|
706
747
|
if (!memoryOrderById) {
|
|
707
|
-
_context5.next =
|
|
748
|
+
_context5.next = 8;
|
|
708
749
|
break;
|
|
709
750
|
}
|
|
751
|
+
if (options.operationId) {
|
|
752
|
+
this.logInfo('getLocalOrderByLookup-localPayment-命中内存映射', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrderById)));
|
|
753
|
+
}
|
|
710
754
|
return _context5.abrupt("return", memoryOrderById);
|
|
711
|
-
case
|
|
755
|
+
case 8:
|
|
712
756
|
memoryOrder = this.store.list.find(function (order) {
|
|
713
757
|
return _this6.isOrderLookupMatch(order, key);
|
|
714
758
|
});
|
|
715
759
|
if (!memoryOrder) {
|
|
716
|
-
_context5.next =
|
|
760
|
+
_context5.next = 12;
|
|
717
761
|
break;
|
|
718
762
|
}
|
|
763
|
+
if (options.operationId) {
|
|
764
|
+
this.logInfo('getLocalOrderByLookup-localPayment-命中内存列表', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrder)));
|
|
765
|
+
}
|
|
719
766
|
return _context5.abrupt("return", memoryOrder);
|
|
720
|
-
case
|
|
721
|
-
|
|
767
|
+
case 12:
|
|
768
|
+
if (options.operationId) {
|
|
769
|
+
this.logInfo('getLocalOrderByLookup-localPayment-开始读取SQLite', logContext);
|
|
770
|
+
}
|
|
771
|
+
_context5.next = 15;
|
|
722
772
|
return this.loadOrdersFromSQLite();
|
|
723
|
-
case
|
|
773
|
+
case 15:
|
|
724
774
|
orders = _context5.sent;
|
|
725
775
|
localOrder = orders.find(function (order) {
|
|
726
776
|
return _this6.isOrderLookupMatch(order, key);
|
|
727
777
|
});
|
|
728
778
|
if (localOrder) {
|
|
729
|
-
_context5.next =
|
|
779
|
+
_context5.next = 20;
|
|
730
780
|
break;
|
|
731
781
|
}
|
|
782
|
+
if (options.operationId) {
|
|
783
|
+
this.logWarning('getLocalOrderByLookup-localPayment-SQLite未命中', _objectSpread(_objectSpread({}, logContext), {}, {
|
|
784
|
+
sqlite_order_count: orders.length
|
|
785
|
+
}));
|
|
786
|
+
}
|
|
732
787
|
return _context5.abrupt("return", null);
|
|
733
|
-
case
|
|
788
|
+
case 20:
|
|
734
789
|
this.store.list = orders.map(function (order) {
|
|
735
790
|
return _this6.normalizeOrderForMemoryList(order);
|
|
736
791
|
});
|
|
737
792
|
this.syncOrdersMap();
|
|
738
|
-
|
|
739
|
-
|
|
793
|
+
normalizedOrder = this.normalizeOrderForMemoryList(localOrder);
|
|
794
|
+
if (options.operationId) {
|
|
795
|
+
this.logInfo('getLocalOrderByLookup-localPayment-SQLite命中', _objectSpread(_objectSpread({}, logContext), {}, {
|
|
796
|
+
sqlite_order_count: orders.length
|
|
797
|
+
}, this.buildLocalPaymentOrderLogContext(normalizedOrder)));
|
|
798
|
+
}
|
|
799
|
+
return _context5.abrupt("return", normalizedOrder);
|
|
800
|
+
case 25:
|
|
740
801
|
case "end":
|
|
741
802
|
return _context5.stop();
|
|
742
803
|
}
|
|
@@ -747,15 +808,186 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
747
808
|
}
|
|
748
809
|
return getLocalOrderByLookup;
|
|
749
810
|
}()
|
|
811
|
+
}, {
|
|
812
|
+
key: "getLocalPayment",
|
|
813
|
+
value: function () {
|
|
814
|
+
var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
|
|
815
|
+
var logContext, order, payments, match;
|
|
816
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
817
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
818
|
+
case 0:
|
|
819
|
+
logContext = {
|
|
820
|
+
operation_id: params.operationId,
|
|
821
|
+
sale_id: params.saleId,
|
|
822
|
+
payment_number: params.paymentNumber
|
|
823
|
+
};
|
|
824
|
+
this.logInfo('getLocalPayment-开始', logContext);
|
|
825
|
+
_context6.prev = 2;
|
|
826
|
+
_context6.next = 5;
|
|
827
|
+
return this.getLocalOrderByLookup(params.saleId, {
|
|
828
|
+
operationId: params.operationId
|
|
829
|
+
});
|
|
830
|
+
case 5:
|
|
831
|
+
order = _context6.sent;
|
|
832
|
+
if (order) {
|
|
833
|
+
_context6.next = 9;
|
|
834
|
+
break;
|
|
835
|
+
}
|
|
836
|
+
this.logWarning('getLocalPayment-订单未命中', logContext);
|
|
837
|
+
return _context6.abrupt("return", null);
|
|
838
|
+
case 9:
|
|
839
|
+
payments = order.payments || [];
|
|
840
|
+
match = resolveOrderPaymentIdentity(payments, params.paymentNumber, 'compat');
|
|
841
|
+
if (match) {
|
|
842
|
+
_context6.next = 14;
|
|
843
|
+
break;
|
|
844
|
+
}
|
|
845
|
+
this.logWarning('getLocalPayment-支付项未命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
|
|
846
|
+
payments: payments
|
|
847
|
+
}));
|
|
848
|
+
return _context6.abrupt("return", null);
|
|
849
|
+
case 14:
|
|
850
|
+
this.logInfo('getLocalPayment-支付项命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
|
|
851
|
+
matched_by: match.matchedBy,
|
|
852
|
+
payment_index: match.index,
|
|
853
|
+
payment: match.payment
|
|
854
|
+
}));
|
|
855
|
+
return _context6.abrupt("return", {
|
|
856
|
+
order: order,
|
|
857
|
+
payment: match.payment,
|
|
858
|
+
paymentIndex: match.index,
|
|
859
|
+
matchedBy: match.matchedBy
|
|
860
|
+
});
|
|
861
|
+
case 18:
|
|
862
|
+
_context6.prev = 18;
|
|
863
|
+
_context6.t0 = _context6["catch"](2);
|
|
864
|
+
this.logError('getLocalPayment-查询失败', _objectSpread(_objectSpread({}, logContext), {}, {
|
|
865
|
+
error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
|
|
866
|
+
}));
|
|
867
|
+
throw _context6.t0;
|
|
868
|
+
case 22:
|
|
869
|
+
case "end":
|
|
870
|
+
return _context6.stop();
|
|
871
|
+
}
|
|
872
|
+
}, _callee6, this, [[2, 18]]);
|
|
873
|
+
}));
|
|
874
|
+
function getLocalPayment(_x4) {
|
|
875
|
+
return _getLocalPayment.apply(this, arguments);
|
|
876
|
+
}
|
|
877
|
+
return getLocalPayment;
|
|
878
|
+
}()
|
|
879
|
+
}, {
|
|
880
|
+
key: "updateLocalPayment",
|
|
881
|
+
value: function () {
|
|
882
|
+
var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
|
|
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 _callee7$(_context7) {
|
|
885
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
886
|
+
case 0:
|
|
887
|
+
logContext = {
|
|
888
|
+
operation_id: params.operationId,
|
|
889
|
+
sale_id: params.saleId,
|
|
890
|
+
payment_number: params.paymentNumber,
|
|
891
|
+
incoming_payment_update: params.updates
|
|
892
|
+
};
|
|
893
|
+
this.logInfo('updateLocalPayment-开始', logContext);
|
|
894
|
+
_context7.next = 4;
|
|
895
|
+
return this.getLocalPayment(params);
|
|
896
|
+
case 4:
|
|
897
|
+
found = _context7.sent;
|
|
898
|
+
if (found) {
|
|
899
|
+
_context7.next = 8;
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
this.logWarning('updateLocalPayment-支付项未命中', logContext);
|
|
903
|
+
return _context7.abrupt("return", null);
|
|
904
|
+
case 8:
|
|
905
|
+
previousPayment = cloneDeep(found.payment);
|
|
906
|
+
nextPayment = mergeOrderPaymentRecord(found.payment, _objectSpread(_objectSpread({}, params.updates), {}, {
|
|
907
|
+
updated_at: params.updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
908
|
+
}));
|
|
909
|
+
nextOrder = _objectSpread(_objectSpread({}, found.order), {}, {
|
|
910
|
+
payments: (found.order.payments || []).map(function (payment, index) {
|
|
911
|
+
return index === found.paymentIndex ? nextPayment : payment;
|
|
912
|
+
}),
|
|
913
|
+
updated_at: dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
914
|
+
});
|
|
915
|
+
paymentContext = _objectSpread(_objectSpread(_objectSpread({}, logContext), {}, {
|
|
916
|
+
matched_by: found.matchedBy,
|
|
917
|
+
payment_index: found.paymentIndex
|
|
918
|
+
}, this.buildLocalPaymentOrderLogContext(nextOrder)), {}, {
|
|
919
|
+
previous_payment: previousPayment,
|
|
920
|
+
payment: nextPayment
|
|
921
|
+
});
|
|
922
|
+
this.logInfo('updateLocalPayment-支付项合并完成', paymentContext);
|
|
923
|
+
targetIndex = this.findOrderIndexByIdentity(this.store.list, found.order);
|
|
924
|
+
if (!(targetIndex < 0)) {
|
|
925
|
+
_context7.next = 17;
|
|
926
|
+
break;
|
|
927
|
+
}
|
|
928
|
+
this.logError('updateLocalPayment-订单Store索引未命中', paymentContext);
|
|
929
|
+
return _context7.abrupt("return", null);
|
|
930
|
+
case 17:
|
|
931
|
+
previousList = this.store.list;
|
|
932
|
+
this.store.list = this.store.list.map(function (order, index) {
|
|
933
|
+
return index === targetIndex ? nextOrder : order;
|
|
934
|
+
});
|
|
935
|
+
this.syncOrdersMap();
|
|
936
|
+
storageOrder = this.withoutSyntheticDraftOrderId(nextOrder);
|
|
937
|
+
_context7.prev = 21;
|
|
938
|
+
this.logInfo('updateLocalPayment-SQLite写入开始', _objectSpread(_objectSpread({}, paymentContext), {}, {
|
|
939
|
+
storage_order_id: (_storageOrder$order_i = storageOrder.order_id) !== null && _storageOrder$order_i !== void 0 ? _storageOrder$order_i : null
|
|
940
|
+
}));
|
|
941
|
+
_context7.next = 25;
|
|
942
|
+
return this.updateOrderInSQLite(storageOrder, 'updateLocalPayment', {
|
|
943
|
+
throwOnError: true
|
|
944
|
+
});
|
|
945
|
+
case 25:
|
|
946
|
+
this.logInfo('updateLocalPayment-SQLite写入完成', _objectSpread(_objectSpread({}, paymentContext), {}, {
|
|
947
|
+
storage_order_id: (_storageOrder$order_i2 = storageOrder.order_id) !== null && _storageOrder$order_i2 !== void 0 ? _storageOrder$order_i2 : null
|
|
948
|
+
}));
|
|
949
|
+
_context7.next = 34;
|
|
950
|
+
break;
|
|
951
|
+
case 28:
|
|
952
|
+
_context7.prev = 28;
|
|
953
|
+
_context7.t0 = _context7["catch"](21);
|
|
954
|
+
this.store.list = previousList;
|
|
955
|
+
this.syncOrdersMap();
|
|
956
|
+
this.logError('updateLocalPayment-SQLite写入失败并回滚内存', _objectSpread(_objectSpread({}, paymentContext), {}, {
|
|
957
|
+
storage_order_id: (_storageOrder$order_i3 = storageOrder.order_id) !== null && _storageOrder$order_i3 !== void 0 ? _storageOrder$order_i3 : null,
|
|
958
|
+
error: _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0)
|
|
959
|
+
}));
|
|
960
|
+
throw _context7.t0;
|
|
961
|
+
case 34:
|
|
962
|
+
_context7.next = 36;
|
|
963
|
+
return this.emitOrdersChanged([nextOrder], 'updateLocalPayment');
|
|
964
|
+
case 36:
|
|
965
|
+
this.logInfo('updateLocalPayment-变更事件完成', paymentContext);
|
|
966
|
+
return _context7.abrupt("return", {
|
|
967
|
+
order: nextOrder,
|
|
968
|
+
payment: nextPayment,
|
|
969
|
+
previousPayment: previousPayment
|
|
970
|
+
});
|
|
971
|
+
case 38:
|
|
972
|
+
case "end":
|
|
973
|
+
return _context7.stop();
|
|
974
|
+
}
|
|
975
|
+
}, _callee7, this, [[21, 28]]);
|
|
976
|
+
}));
|
|
977
|
+
function updateLocalPayment(_x5) {
|
|
978
|
+
return _updateLocalPayment.apply(this, arguments);
|
|
979
|
+
}
|
|
980
|
+
return updateLocalPayment;
|
|
981
|
+
}()
|
|
750
982
|
}, {
|
|
751
983
|
key: "loadOrdersByServer",
|
|
752
984
|
value: function () {
|
|
753
|
-
var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
985
|
+
var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
754
986
|
var _this$store,
|
|
755
987
|
_this7 = this;
|
|
756
988
|
var orderList, data, mergedOrders, memoryOrders;
|
|
757
|
-
return _regeneratorRuntime().wrap(function
|
|
758
|
-
while (1) switch (
|
|
989
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
990
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
759
991
|
case 0:
|
|
760
992
|
orderList = [];
|
|
761
993
|
this.logInfo('loadOrdersByServer-开始', {
|
|
@@ -763,51 +995,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
763
995
|
query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null
|
|
764
996
|
});
|
|
765
997
|
if (!this.orderDataSource) {
|
|
766
|
-
|
|
998
|
+
_context8.next = 17;
|
|
767
999
|
break;
|
|
768
1000
|
}
|
|
769
|
-
|
|
770
|
-
|
|
1001
|
+
_context8.prev = 3;
|
|
1002
|
+
_context8.next = 6;
|
|
771
1003
|
return this.orderDataSource.run({
|
|
772
1004
|
sse: {
|
|
773
1005
|
query: this.store.createdAtQuery
|
|
774
1006
|
}
|
|
775
1007
|
});
|
|
776
1008
|
case 6:
|
|
777
|
-
data =
|
|
1009
|
+
data = _context8.sent;
|
|
778
1010
|
orderList = data || [];
|
|
779
1011
|
this.logInfo('loadOrdersByServer-SSE拉取成功', {
|
|
780
1012
|
count: orderList.length
|
|
781
1013
|
});
|
|
782
1014
|
this.markOrderPulledAtNow();
|
|
783
1015
|
this.lastServerFullFetchAtMs = Date.now();
|
|
784
|
-
|
|
1016
|
+
_context8.next = 17;
|
|
785
1017
|
break;
|
|
786
1018
|
case 13:
|
|
787
|
-
|
|
788
|
-
|
|
1019
|
+
_context8.prev = 13;
|
|
1020
|
+
_context8.t0 = _context8["catch"](3);
|
|
789
1021
|
this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
|
|
790
|
-
return
|
|
1022
|
+
return _context8.abrupt("return", this.store.list);
|
|
791
1023
|
case 17:
|
|
792
|
-
|
|
1024
|
+
_context8.next = 19;
|
|
793
1025
|
return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer');
|
|
794
1026
|
case 19:
|
|
795
|
-
mergedOrders =
|
|
1027
|
+
mergedOrders = _context8.sent;
|
|
796
1028
|
memoryOrders = mergedOrders.map(function (order) {
|
|
797
1029
|
return _this7.normalizeOrderForMemoryList(order);
|
|
798
1030
|
});
|
|
799
1031
|
this.logInfo('loadOrdersByServer-结束', {
|
|
800
1032
|
count: memoryOrders.length
|
|
801
1033
|
});
|
|
802
|
-
|
|
1034
|
+
_context8.next = 24;
|
|
803
1035
|
return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
|
|
804
1036
|
case 24:
|
|
805
|
-
return
|
|
1037
|
+
return _context8.abrupt("return", memoryOrders);
|
|
806
1038
|
case 25:
|
|
807
1039
|
case "end":
|
|
808
|
-
return
|
|
1040
|
+
return _context8.stop();
|
|
809
1041
|
}
|
|
810
|
-
},
|
|
1042
|
+
}, _callee8, this, [[3, 13]]);
|
|
811
1043
|
}));
|
|
812
1044
|
function loadOrdersByServer() {
|
|
813
1045
|
return _loadOrdersByServer.apply(this, arguments);
|
|
@@ -822,61 +1054,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
822
1054
|
}, {
|
|
823
1055
|
key: "silentRefresh",
|
|
824
1056
|
value: (function () {
|
|
825
|
-
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1057
|
+
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
826
1058
|
var startTime, elapsedSinceFullFetch, orders, errorMessage;
|
|
827
|
-
return _regeneratorRuntime().wrap(function
|
|
828
|
-
while (1) switch (
|
|
1059
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1060
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
829
1061
|
case 0:
|
|
830
1062
|
startTime = Date.now();
|
|
831
1063
|
elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
|
|
832
1064
|
if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
|
|
833
|
-
|
|
1065
|
+
_context9.next = 4;
|
|
834
1066
|
break;
|
|
835
1067
|
}
|
|
836
|
-
return
|
|
1068
|
+
return _context9.abrupt("return", this.store.list);
|
|
837
1069
|
case 4:
|
|
838
1070
|
this.logInfo('silentRefresh 开始');
|
|
839
|
-
|
|
1071
|
+
_context9.prev = 5;
|
|
840
1072
|
// 刷新前,需要更新当前营业日边界(store.createdAtQuery)
|
|
841
1073
|
this.updateCreateStore();
|
|
842
|
-
|
|
1074
|
+
_context9.next = 9;
|
|
843
1075
|
return this.loadOrdersByServer();
|
|
844
1076
|
case 9:
|
|
845
|
-
orders =
|
|
1077
|
+
orders = _context9.sent;
|
|
846
1078
|
if (!(orders.length > 0)) {
|
|
847
|
-
|
|
1079
|
+
_context9.next = 19;
|
|
848
1080
|
break;
|
|
849
1081
|
}
|
|
850
1082
|
this.store.list = cloneDeep(orders);
|
|
851
1083
|
this.syncOrdersMap();
|
|
852
1084
|
this.emitOrdersChanged([], 'silentRefresh');
|
|
853
|
-
|
|
1085
|
+
_context9.next = 16;
|
|
854
1086
|
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
855
1087
|
case 16:
|
|
856
1088
|
this.logInfo('silentRefresh 完成', {
|
|
857
1089
|
orderCount: orders.length,
|
|
858
1090
|
duration: "".concat(Date.now() - startTime, "ms")
|
|
859
1091
|
});
|
|
860
|
-
|
|
1092
|
+
_context9.next = 20;
|
|
861
1093
|
break;
|
|
862
1094
|
case 19:
|
|
863
1095
|
this.logInfo('silentRefresh: 服务器未返回数据');
|
|
864
1096
|
case 20:
|
|
865
|
-
return
|
|
1097
|
+
return _context9.abrupt("return", this.store.list);
|
|
866
1098
|
case 23:
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
errorMessage =
|
|
1099
|
+
_context9.prev = 23;
|
|
1100
|
+
_context9.t0 = _context9["catch"](5);
|
|
1101
|
+
errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
|
|
870
1102
|
this.logError('silentRefresh 失败', {
|
|
871
1103
|
duration: "".concat(Date.now() - startTime, "ms"),
|
|
872
1104
|
error: errorMessage
|
|
873
1105
|
});
|
|
874
|
-
return
|
|
1106
|
+
return _context9.abrupt("return", this.store.list);
|
|
875
1107
|
case 28:
|
|
876
1108
|
case "end":
|
|
877
|
-
return
|
|
1109
|
+
return _context9.stop();
|
|
878
1110
|
}
|
|
879
|
-
},
|
|
1111
|
+
}, _callee9, this, [[5, 23]]);
|
|
880
1112
|
}));
|
|
881
1113
|
function silentRefresh() {
|
|
882
1114
|
return _silentRefresh.apply(this, arguments);
|
|
@@ -899,6 +1131,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
899
1131
|
order_id: externalSaleNumber
|
|
900
1132
|
});
|
|
901
1133
|
}
|
|
1134
|
+
}, {
|
|
1135
|
+
key: "withoutSyntheticDraftOrderId",
|
|
1136
|
+
value: function withoutSyntheticDraftOrderId(order) {
|
|
1137
|
+
var externalSaleNumber = order.external_sale_number;
|
|
1138
|
+
if (Number(order.is_draft_order || 0) !== 1 || order.order_id === undefined || externalSaleNumber === undefined || String(order.order_id) !== String(externalSaleNumber)) {
|
|
1139
|
+
return order;
|
|
1140
|
+
}
|
|
1141
|
+
var next = _objectSpread({}, order);
|
|
1142
|
+
delete next.order_id;
|
|
1143
|
+
return next;
|
|
1144
|
+
}
|
|
902
1145
|
|
|
903
1146
|
/**
|
|
904
1147
|
* 仅覆盖本地已存在的订单;不存在则直接跳过,不落库、不 emit。
|
|
@@ -907,31 +1150,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
907
1150
|
}, {
|
|
908
1151
|
key: "overwriteExistingOrder",
|
|
909
1152
|
value: (function () {
|
|
910
|
-
var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1153
|
+
var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fresh) {
|
|
911
1154
|
var _this8 = this;
|
|
912
1155
|
var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
|
|
913
|
-
return _regeneratorRuntime().wrap(function
|
|
914
|
-
while (1) switch (
|
|
1156
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1157
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
915
1158
|
case 0:
|
|
916
1159
|
orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
|
|
917
1160
|
if (!(orderId === undefined || orderId === null)) {
|
|
918
|
-
|
|
1161
|
+
_context10.next = 4;
|
|
919
1162
|
break;
|
|
920
1163
|
}
|
|
921
1164
|
this.logError('overwriteExistingOrder-入参缺少 order_id');
|
|
922
|
-
return
|
|
1165
|
+
return _context10.abrupt("return", {
|
|
923
1166
|
overwritten: false
|
|
924
1167
|
});
|
|
925
1168
|
case 4:
|
|
926
1169
|
key = this.getIdKey(orderId);
|
|
927
1170
|
if (this.store.map.has(key)) {
|
|
928
|
-
|
|
1171
|
+
_context10.next = 8;
|
|
929
1172
|
break;
|
|
930
1173
|
}
|
|
931
1174
|
this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
|
|
932
1175
|
orderId: orderId
|
|
933
1176
|
});
|
|
934
|
-
return
|
|
1177
|
+
return _context10.abrupt("return", {
|
|
935
1178
|
overwritten: false
|
|
936
1179
|
});
|
|
937
1180
|
case 8:
|
|
@@ -950,26 +1193,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
950
1193
|
return _this8.getIdKey(id) === key ? reconciledFresh : _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
|
|
951
1194
|
});
|
|
952
1195
|
this.syncOrdersMap();
|
|
953
|
-
|
|
1196
|
+
_context10.next = 16;
|
|
954
1197
|
return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
|
|
955
1198
|
case 16:
|
|
956
1199
|
this.logInfo('overwriteExistingOrder-结束', {
|
|
957
1200
|
orderId: orderId,
|
|
958
1201
|
storeOrderCountAfter: this.store.list.length
|
|
959
1202
|
});
|
|
960
|
-
|
|
1203
|
+
_context10.next = 19;
|
|
961
1204
|
return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
|
|
962
1205
|
case 19:
|
|
963
|
-
return
|
|
1206
|
+
return _context10.abrupt("return", {
|
|
964
1207
|
overwritten: true
|
|
965
1208
|
});
|
|
966
1209
|
case 20:
|
|
967
1210
|
case "end":
|
|
968
|
-
return
|
|
1211
|
+
return _context10.stop();
|
|
969
1212
|
}
|
|
970
|
-
},
|
|
1213
|
+
}, _callee10, this);
|
|
971
1214
|
}));
|
|
972
|
-
function overwriteExistingOrder(
|
|
1215
|
+
function overwriteExistingOrder(_x6) {
|
|
973
1216
|
return _overwriteExistingOrder.apply(this, arguments);
|
|
974
1217
|
}
|
|
975
1218
|
return overwriteExistingOrder;
|
|
@@ -982,29 +1225,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
982
1225
|
}, {
|
|
983
1226
|
key: "upsertOrdersFromRemote",
|
|
984
1227
|
value: (function () {
|
|
985
|
-
var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
986
|
-
|
|
987
|
-
|
|
1228
|
+
var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(freshOrders) {
|
|
1229
|
+
var source,
|
|
1230
|
+
_args11 = arguments;
|
|
1231
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
1232
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
988
1233
|
case 0:
|
|
1234
|
+
source = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : 'upsertOrdersFromRemote';
|
|
989
1235
|
if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
|
|
990
|
-
|
|
1236
|
+
_context11.next = 4;
|
|
991
1237
|
break;
|
|
992
1238
|
}
|
|
993
1239
|
this.logInfo('upsertOrdersFromRemote-订单列表为空', {});
|
|
994
|
-
return
|
|
995
|
-
case
|
|
1240
|
+
return _context11.abrupt("return");
|
|
1241
|
+
case 4:
|
|
996
1242
|
this.logInfo('upsertOrdersFromRemote-开始', {
|
|
997
|
-
count: freshOrders.length
|
|
1243
|
+
count: freshOrders.length,
|
|
1244
|
+
source: source
|
|
998
1245
|
});
|
|
999
|
-
|
|
1000
|
-
return this.mergeOrdersToStore(freshOrders,
|
|
1001
|
-
case
|
|
1246
|
+
_context11.next = 7;
|
|
1247
|
+
return this.mergeOrdersToStore(freshOrders, source);
|
|
1248
|
+
case 7:
|
|
1002
1249
|
case "end":
|
|
1003
|
-
return
|
|
1250
|
+
return _context11.stop();
|
|
1004
1251
|
}
|
|
1005
|
-
},
|
|
1252
|
+
}, _callee11, this);
|
|
1006
1253
|
}));
|
|
1007
|
-
function upsertOrdersFromRemote(
|
|
1254
|
+
function upsertOrdersFromRemote(_x7) {
|
|
1008
1255
|
return _upsertOrdersFromRemote.apply(this, arguments);
|
|
1009
1256
|
}
|
|
1010
1257
|
return upsertOrdersFromRemote;
|
|
@@ -1012,21 +1259,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1012
1259
|
}, {
|
|
1013
1260
|
key: "markOrderSyncedByExternalSaleNumber",
|
|
1014
1261
|
value: function () {
|
|
1015
|
-
var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1262
|
+
var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
|
|
1016
1263
|
var _this9 = this,
|
|
1017
1264
|
_existing$external_sa,
|
|
1018
1265
|
_nextOrder$order_id;
|
|
1019
1266
|
var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
|
|
1020
|
-
return _regeneratorRuntime().wrap(function
|
|
1021
|
-
while (1) switch (
|
|
1267
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1268
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
1022
1269
|
case 0:
|
|
1023
1270
|
externalSaleNumber = params.externalSaleNumber;
|
|
1024
1271
|
if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
|
|
1025
|
-
|
|
1272
|
+
_context12.next = 4;
|
|
1026
1273
|
break;
|
|
1027
1274
|
}
|
|
1028
1275
|
this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
|
|
1029
|
-
return
|
|
1276
|
+
return _context12.abrupt("return", {
|
|
1030
1277
|
updated: false
|
|
1031
1278
|
});
|
|
1032
1279
|
case 4:
|
|
@@ -1037,20 +1284,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1037
1284
|
return _this9.getIdKey(value) === key;
|
|
1038
1285
|
});
|
|
1039
1286
|
if (!(targetIndex < 0)) {
|
|
1040
|
-
|
|
1287
|
+
_context12.next = 9;
|
|
1041
1288
|
break;
|
|
1042
1289
|
}
|
|
1043
1290
|
this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
|
|
1044
1291
|
external_sale_number: externalSaleNumber
|
|
1045
1292
|
});
|
|
1046
|
-
return
|
|
1293
|
+
return _context12.abrupt("return", {
|
|
1047
1294
|
updated: false
|
|
1048
1295
|
});
|
|
1049
1296
|
case 9:
|
|
1050
1297
|
existing = this.store.list[targetIndex];
|
|
1051
1298
|
nextOrder = this.normalizeRemoteSyncedOrder(_objectSpread(_objectSpread(_objectSpread({}, existing), params.patch || {}), {}, {
|
|
1052
1299
|
external_sale_number: (_existing$external_sa = existing.external_sale_number) !== null && _existing$external_sa !== void 0 ? _existing$external_sa : externalSaleNumber,
|
|
1053
|
-
need_sync: 0
|
|
1300
|
+
need_sync: 0,
|
|
1301
|
+
is_draft_order: 0
|
|
1054
1302
|
}));
|
|
1055
1303
|
storageKey = this.getOrderStorageKey(nextOrder) || key;
|
|
1056
1304
|
this.store.list = this.store.list.map(function (order, index) {
|
|
@@ -1058,27 +1306,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1058
1306
|
return nextOrder;
|
|
1059
1307
|
});
|
|
1060
1308
|
this.syncOrdersMap();
|
|
1061
|
-
|
|
1309
|
+
_context12.next = 16;
|
|
1062
1310
|
return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
|
|
1063
1311
|
case 16:
|
|
1064
1312
|
this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
|
|
1065
1313
|
external_sale_number: externalSaleNumber,
|
|
1066
1314
|
order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
|
|
1067
1315
|
});
|
|
1068
|
-
|
|
1316
|
+
_context12.next = 19;
|
|
1069
1317
|
return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
|
|
1070
1318
|
case 19:
|
|
1071
|
-
return
|
|
1319
|
+
return _context12.abrupt("return", {
|
|
1072
1320
|
updated: true,
|
|
1073
1321
|
order: nextOrder
|
|
1074
1322
|
});
|
|
1075
1323
|
case 20:
|
|
1076
1324
|
case "end":
|
|
1077
|
-
return
|
|
1325
|
+
return _context12.stop();
|
|
1078
1326
|
}
|
|
1079
|
-
},
|
|
1327
|
+
}, _callee12, this);
|
|
1080
1328
|
}));
|
|
1081
|
-
function markOrderSyncedByExternalSaleNumber(
|
|
1329
|
+
function markOrderSyncedByExternalSaleNumber(_x8) {
|
|
1082
1330
|
return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
|
|
1083
1331
|
}
|
|
1084
1332
|
return markOrderSyncedByExternalSaleNumber;
|
|
@@ -1090,64 +1338,98 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1090
1338
|
}, {
|
|
1091
1339
|
key: "upsertPendingSyncOrders",
|
|
1092
1340
|
value: (function () {
|
|
1093
|
-
var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1341
|
+
var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(pendingOrders) {
|
|
1094
1342
|
var _this10 = this;
|
|
1095
|
-
var
|
|
1096
|
-
|
|
1097
|
-
|
|
1343
|
+
var options,
|
|
1344
|
+
pendingMap,
|
|
1345
|
+
memoryPendingMap,
|
|
1346
|
+
_iterator5,
|
|
1347
|
+
_step5,
|
|
1348
|
+
order,
|
|
1349
|
+
normalizedOrder,
|
|
1350
|
+
pendingOrder,
|
|
1351
|
+
storageKey,
|
|
1352
|
+
mergeActions,
|
|
1353
|
+
updatedList,
|
|
1354
|
+
identityKeyToIndex,
|
|
1355
|
+
index,
|
|
1356
|
+
_iterator6,
|
|
1357
|
+
_step6,
|
|
1358
|
+
key,
|
|
1359
|
+
_iterator7,
|
|
1360
|
+
_step7,
|
|
1361
|
+
_step7$value,
|
|
1362
|
+
_storageKey,
|
|
1363
|
+
_pendingOrder,
|
|
1364
|
+
matchIndex,
|
|
1365
|
+
existingOrder,
|
|
1366
|
+
mergedOrder,
|
|
1367
|
+
nextOrder,
|
|
1368
|
+
pendingSnapshot,
|
|
1369
|
+
insertIndex,
|
|
1370
|
+
patchedOrders,
|
|
1371
|
+
previousList,
|
|
1372
|
+
_args13 = arguments;
|
|
1373
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1374
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1098
1375
|
case 0:
|
|
1376
|
+
options = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : {};
|
|
1099
1377
|
if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
|
|
1100
|
-
|
|
1378
|
+
_context13.next = 4;
|
|
1101
1379
|
break;
|
|
1102
1380
|
}
|
|
1103
1381
|
this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
|
|
1104
|
-
return
|
|
1105
|
-
case
|
|
1382
|
+
return _context13.abrupt("return");
|
|
1383
|
+
case 4:
|
|
1106
1384
|
pendingMap = new Map();
|
|
1107
1385
|
memoryPendingMap = new Map();
|
|
1108
1386
|
_iterator5 = _createForOfIteratorHelper(pendingOrders);
|
|
1109
|
-
|
|
1387
|
+
_context13.prev = 7;
|
|
1110
1388
|
_iterator5.s();
|
|
1111
|
-
case
|
|
1389
|
+
case 9:
|
|
1112
1390
|
if ((_step5 = _iterator5.n()).done) {
|
|
1113
|
-
|
|
1391
|
+
_context13.next = 20;
|
|
1114
1392
|
break;
|
|
1115
1393
|
}
|
|
1116
1394
|
order = _step5.value;
|
|
1117
1395
|
normalizedOrder = this.normalizeOrderCollectionsForIngress(order, 'upsertPendingSyncOrders.incoming');
|
|
1118
|
-
|
|
1396
|
+
pendingOrder = _objectSpread(_objectSpread({}, normalizedOrder), {}, {
|
|
1397
|
+
need_sync: 1,
|
|
1398
|
+
is_draft_order: 0
|
|
1399
|
+
});
|
|
1400
|
+
storageKey = this.getOrderStorageKey(pendingOrder);
|
|
1119
1401
|
if (storageKey) {
|
|
1120
|
-
|
|
1402
|
+
_context13.next = 16;
|
|
1121
1403
|
break;
|
|
1122
1404
|
}
|
|
1123
|
-
return
|
|
1124
|
-
case 14:
|
|
1125
|
-
pendingMap.set(storageKey, normalizedOrder);
|
|
1126
|
-
memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(normalizedOrder, 'upsertPendingSyncOrders.memory'));
|
|
1405
|
+
return _context13.abrupt("continue", 18);
|
|
1127
1406
|
case 16:
|
|
1128
|
-
|
|
1129
|
-
|
|
1407
|
+
pendingMap.set(storageKey, pendingOrder);
|
|
1408
|
+
memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(pendingOrder, 'upsertPendingSyncOrders.memory'));
|
|
1130
1409
|
case 18:
|
|
1131
|
-
|
|
1410
|
+
_context13.next = 9;
|
|
1132
1411
|
break;
|
|
1133
1412
|
case 20:
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1413
|
+
_context13.next = 25;
|
|
1414
|
+
break;
|
|
1415
|
+
case 22:
|
|
1416
|
+
_context13.prev = 22;
|
|
1417
|
+
_context13.t0 = _context13["catch"](7);
|
|
1418
|
+
_iterator5.e(_context13.t0);
|
|
1419
|
+
case 25:
|
|
1420
|
+
_context13.prev = 25;
|
|
1139
1421
|
_iterator5.f();
|
|
1140
|
-
return
|
|
1141
|
-
case
|
|
1422
|
+
return _context13.finish(25);
|
|
1423
|
+
case 28:
|
|
1142
1424
|
if (!(pendingMap.size === 0)) {
|
|
1143
|
-
|
|
1425
|
+
_context13.next = 31;
|
|
1144
1426
|
break;
|
|
1145
1427
|
}
|
|
1146
1428
|
this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
|
|
1147
1429
|
count: pendingOrders.length
|
|
1148
1430
|
});
|
|
1149
|
-
return
|
|
1150
|
-
case
|
|
1431
|
+
return _context13.abrupt("return");
|
|
1432
|
+
case 31:
|
|
1151
1433
|
this.logInfo('upsertPendingSyncOrders-开始', {
|
|
1152
1434
|
count: pendingMap.size
|
|
1153
1435
|
});
|
|
@@ -1172,73 +1454,241 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1172
1454
|
}
|
|
1173
1455
|
}
|
|
1174
1456
|
_iterator7 = _createForOfIteratorHelper(memoryPendingMap.entries());
|
|
1175
|
-
|
|
1457
|
+
_context13.prev = 37;
|
|
1176
1458
|
_iterator7.s();
|
|
1177
|
-
case
|
|
1459
|
+
case 39:
|
|
1178
1460
|
if ((_step7 = _iterator7.n()).done) {
|
|
1179
|
-
|
|
1461
|
+
_context13.next = 58;
|
|
1180
1462
|
break;
|
|
1181
1463
|
}
|
|
1182
|
-
_step7$value = _slicedToArray(_step7.value, 2), _storageKey = _step7$value[0],
|
|
1183
|
-
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(
|
|
1464
|
+
_step7$value = _slicedToArray(_step7.value, 2), _storageKey = _step7$value[0], _pendingOrder = _step7$value[1];
|
|
1465
|
+
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
|
|
1184
1466
|
if (!(matchIndex >= 0)) {
|
|
1185
|
-
|
|
1467
|
+
_context13.next = 52;
|
|
1186
1468
|
break;
|
|
1187
1469
|
}
|
|
1188
1470
|
existingOrder = updatedList[matchIndex];
|
|
1189
|
-
mergedOrder = this.mergeOrderRecords(existingOrder,
|
|
1190
|
-
|
|
1471
|
+
mergedOrder = this.mergeOrderRecords(existingOrder, _pendingOrder);
|
|
1472
|
+
nextOrder = _objectSpread(_objectSpread({}, mergedOrder), {}, {
|
|
1473
|
+
need_sync: 1,
|
|
1474
|
+
is_draft_order: 0
|
|
1475
|
+
});
|
|
1476
|
+
updatedList[matchIndex] = nextOrder;
|
|
1191
1477
|
pendingSnapshot = pendingMap.get(_storageKey);
|
|
1192
1478
|
if (pendingSnapshot) {
|
|
1193
1479
|
pendingMap.set(_storageKey, this.reconcileOverwriteOrderCollections(existingOrder, pendingSnapshot));
|
|
1194
1480
|
}
|
|
1195
1481
|
// 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
|
|
1196
|
-
this.registerOrderIdentityKeys(identityKeyToIndex,
|
|
1482
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
|
|
1197
1483
|
mergeActions[_storageKey] = 'update';
|
|
1198
|
-
return
|
|
1199
|
-
case
|
|
1484
|
+
return _context13.abrupt("continue", 56);
|
|
1485
|
+
case 52:
|
|
1200
1486
|
insertIndex = updatedList.length;
|
|
1201
|
-
updatedList.push(
|
|
1202
|
-
this.registerOrderIdentityKeys(identityKeyToIndex,
|
|
1487
|
+
updatedList.push(_pendingOrder);
|
|
1488
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
|
|
1203
1489
|
mergeActions[_storageKey] = 'insert';
|
|
1204
|
-
case
|
|
1205
|
-
|
|
1490
|
+
case 56:
|
|
1491
|
+
_context13.next = 39;
|
|
1206
1492
|
break;
|
|
1207
|
-
case
|
|
1208
|
-
|
|
1493
|
+
case 58:
|
|
1494
|
+
_context13.next = 63;
|
|
1209
1495
|
break;
|
|
1210
|
-
case 57:
|
|
1211
|
-
_context11.prev = 57;
|
|
1212
|
-
_context11.t1 = _context11["catch"](35);
|
|
1213
|
-
_iterator7.e(_context11.t1);
|
|
1214
1496
|
case 60:
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1497
|
+
_context13.prev = 60;
|
|
1498
|
+
_context13.t1 = _context13["catch"](37);
|
|
1499
|
+
_iterator7.e(_context13.t1);
|
|
1218
1500
|
case 63:
|
|
1501
|
+
_context13.prev = 63;
|
|
1502
|
+
_iterator7.f();
|
|
1503
|
+
return _context13.finish(63);
|
|
1504
|
+
case 66:
|
|
1219
1505
|
patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
|
|
1506
|
+
previousList = this.store.list;
|
|
1220
1507
|
this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
|
|
1221
1508
|
this.syncOrdersMap();
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1509
|
+
_context13.prev = 70;
|
|
1510
|
+
_context13.next = 73;
|
|
1511
|
+
return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
|
|
1512
|
+
case 73:
|
|
1513
|
+
_context13.next = 80;
|
|
1514
|
+
break;
|
|
1515
|
+
case 75:
|
|
1516
|
+
_context13.prev = 75;
|
|
1517
|
+
_context13.t2 = _context13["catch"](70);
|
|
1518
|
+
this.store.list = previousList;
|
|
1519
|
+
this.syncOrdersMap();
|
|
1520
|
+
throw _context13.t2;
|
|
1521
|
+
case 80:
|
|
1225
1522
|
this.logInfo('upsertPendingSyncOrders-结束', {
|
|
1226
1523
|
count: patchedOrders.length,
|
|
1227
1524
|
storeOrderCountAfter: this.store.list.length
|
|
1228
1525
|
});
|
|
1229
|
-
|
|
1526
|
+
_context13.next = 83;
|
|
1230
1527
|
return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
|
|
1231
|
-
case
|
|
1528
|
+
case 83:
|
|
1232
1529
|
case "end":
|
|
1233
|
-
return
|
|
1530
|
+
return _context13.stop();
|
|
1234
1531
|
}
|
|
1235
|
-
},
|
|
1532
|
+
}, _callee13, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
|
|
1236
1533
|
}));
|
|
1237
|
-
function upsertPendingSyncOrders(
|
|
1534
|
+
function upsertPendingSyncOrders(_x9) {
|
|
1238
1535
|
return _upsertPendingSyncOrders.apply(this, arguments);
|
|
1239
1536
|
}
|
|
1240
1537
|
return upsertPendingSyncOrders;
|
|
1241
1538
|
}()
|
|
1539
|
+
/**
|
|
1540
|
+
* 将 POS 草稿订单按 SQLite storage key 合并进 store 并落库。
|
|
1541
|
+
* 草稿只表示本地可恢复快照,不进入同步队列。
|
|
1542
|
+
*/
|
|
1543
|
+
)
|
|
1544
|
+
}, {
|
|
1545
|
+
key: "upsertLocalDraftOrders",
|
|
1546
|
+
value: (function () {
|
|
1547
|
+
var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(draftOrders) {
|
|
1548
|
+
var draftMap, memoryDraftMap, _iterator8, _step8, order, draftOrder, storageKey, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, _iterator9, _step9, key, _iterator10, _step10, _step10$value, _storageKey2, _draftOrder, matchIndex, mergedOrder, nextOrder, insertIndex;
|
|
1549
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1550
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1551
|
+
case 0:
|
|
1552
|
+
if (draftOrders !== null && draftOrders !== void 0 && draftOrders.length) {
|
|
1553
|
+
_context14.next = 3;
|
|
1554
|
+
break;
|
|
1555
|
+
}
|
|
1556
|
+
this.logInfo('upsertLocalDraftOrders-订单列表为空', {});
|
|
1557
|
+
return _context14.abrupt("return");
|
|
1558
|
+
case 3:
|
|
1559
|
+
draftMap = new Map();
|
|
1560
|
+
memoryDraftMap = new Map();
|
|
1561
|
+
_iterator8 = _createForOfIteratorHelper(draftOrders);
|
|
1562
|
+
_context14.prev = 6;
|
|
1563
|
+
_iterator8.s();
|
|
1564
|
+
case 8:
|
|
1565
|
+
if ((_step8 = _iterator8.n()).done) {
|
|
1566
|
+
_context14.next = 18;
|
|
1567
|
+
break;
|
|
1568
|
+
}
|
|
1569
|
+
order = _step8.value;
|
|
1570
|
+
draftOrder = _objectSpread(_objectSpread({}, order), {}, {
|
|
1571
|
+
need_sync: 0,
|
|
1572
|
+
is_draft_order: 1
|
|
1573
|
+
});
|
|
1574
|
+
storageKey = this.getOrderStorageKey(draftOrder);
|
|
1575
|
+
if (storageKey) {
|
|
1576
|
+
_context14.next = 14;
|
|
1577
|
+
break;
|
|
1578
|
+
}
|
|
1579
|
+
return _context14.abrupt("continue", 16);
|
|
1580
|
+
case 14:
|
|
1581
|
+
draftMap.set(storageKey, draftOrder);
|
|
1582
|
+
memoryDraftMap.set(storageKey, this.normalizeOrderForMemoryList(draftOrder));
|
|
1583
|
+
case 16:
|
|
1584
|
+
_context14.next = 8;
|
|
1585
|
+
break;
|
|
1586
|
+
case 18:
|
|
1587
|
+
_context14.next = 23;
|
|
1588
|
+
break;
|
|
1589
|
+
case 20:
|
|
1590
|
+
_context14.prev = 20;
|
|
1591
|
+
_context14.t0 = _context14["catch"](6);
|
|
1592
|
+
_iterator8.e(_context14.t0);
|
|
1593
|
+
case 23:
|
|
1594
|
+
_context14.prev = 23;
|
|
1595
|
+
_iterator8.f();
|
|
1596
|
+
return _context14.finish(23);
|
|
1597
|
+
case 26:
|
|
1598
|
+
if (!(draftMap.size === 0)) {
|
|
1599
|
+
_context14.next = 29;
|
|
1600
|
+
break;
|
|
1601
|
+
}
|
|
1602
|
+
this.logError('upsertLocalDraftOrders-订单缺少可落库标识', {
|
|
1603
|
+
count: draftOrders.length
|
|
1604
|
+
});
|
|
1605
|
+
return _context14.abrupt("return");
|
|
1606
|
+
case 29:
|
|
1607
|
+
this.logInfo('upsertLocalDraftOrders-开始', {
|
|
1608
|
+
count: draftMap.size
|
|
1609
|
+
});
|
|
1610
|
+
patchedOrders = _toConsumableArray(draftMap.values());
|
|
1611
|
+
mergeActions = {};
|
|
1612
|
+
updatedList = _toConsumableArray(this.store.list);
|
|
1613
|
+
identityKeyToIndex = new Map();
|
|
1614
|
+
for (index = 0; index < updatedList.length; index += 1) {
|
|
1615
|
+
_iterator9 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
|
|
1616
|
+
try {
|
|
1617
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
1618
|
+
key = _step9.value;
|
|
1619
|
+
if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
|
|
1620
|
+
}
|
|
1621
|
+
} catch (err) {
|
|
1622
|
+
_iterator9.e(err);
|
|
1623
|
+
} finally {
|
|
1624
|
+
_iterator9.f();
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
_iterator10 = _createForOfIteratorHelper(memoryDraftMap.entries());
|
|
1628
|
+
_context14.prev = 36;
|
|
1629
|
+
_iterator10.s();
|
|
1630
|
+
case 38:
|
|
1631
|
+
if ((_step10 = _iterator10.n()).done) {
|
|
1632
|
+
_context14.next = 54;
|
|
1633
|
+
break;
|
|
1634
|
+
}
|
|
1635
|
+
_step10$value = _slicedToArray(_step10.value, 2), _storageKey2 = _step10$value[0], _draftOrder = _step10$value[1];
|
|
1636
|
+
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
|
|
1637
|
+
if (!(matchIndex >= 0)) {
|
|
1638
|
+
_context14.next = 48;
|
|
1639
|
+
break;
|
|
1640
|
+
}
|
|
1641
|
+
mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], _draftOrder);
|
|
1642
|
+
nextOrder = _objectSpread(_objectSpread({}, mergedOrder), {}, {
|
|
1643
|
+
need_sync: 0,
|
|
1644
|
+
is_draft_order: 1
|
|
1645
|
+
});
|
|
1646
|
+
updatedList[matchIndex] = nextOrder;
|
|
1647
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
|
|
1648
|
+
mergeActions[_storageKey2] = 'update';
|
|
1649
|
+
return _context14.abrupt("continue", 52);
|
|
1650
|
+
case 48:
|
|
1651
|
+
insertIndex = updatedList.length;
|
|
1652
|
+
updatedList.push(_draftOrder);
|
|
1653
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
|
|
1654
|
+
mergeActions[_storageKey2] = 'insert';
|
|
1655
|
+
case 52:
|
|
1656
|
+
_context14.next = 38;
|
|
1657
|
+
break;
|
|
1658
|
+
case 54:
|
|
1659
|
+
_context14.next = 59;
|
|
1660
|
+
break;
|
|
1661
|
+
case 56:
|
|
1662
|
+
_context14.prev = 56;
|
|
1663
|
+
_context14.t1 = _context14["catch"](36);
|
|
1664
|
+
_iterator10.e(_context14.t1);
|
|
1665
|
+
case 59:
|
|
1666
|
+
_context14.prev = 59;
|
|
1667
|
+
_iterator10.f();
|
|
1668
|
+
return _context14.finish(59);
|
|
1669
|
+
case 62:
|
|
1670
|
+
this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
|
|
1671
|
+
this.syncOrdersMap();
|
|
1672
|
+
_context14.next = 66;
|
|
1673
|
+
return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions);
|
|
1674
|
+
case 66:
|
|
1675
|
+
this.logInfo('upsertLocalDraftOrders-结束', {
|
|
1676
|
+
count: patchedOrders.length,
|
|
1677
|
+
storeOrderCountAfter: this.store.list.length
|
|
1678
|
+
});
|
|
1679
|
+
_context14.next = 69;
|
|
1680
|
+
return this.emitOrdersChanged(patchedOrders, 'upsertLocalDraftOrders');
|
|
1681
|
+
case 69:
|
|
1682
|
+
case "end":
|
|
1683
|
+
return _context14.stop();
|
|
1684
|
+
}
|
|
1685
|
+
}, _callee14, this, [[6, 20, 23, 26], [36, 56, 59, 62]]);
|
|
1686
|
+
}));
|
|
1687
|
+
function upsertLocalDraftOrders(_x10) {
|
|
1688
|
+
return _upsertLocalDraftOrders.apply(this, arguments);
|
|
1689
|
+
}
|
|
1690
|
+
return upsertLocalDraftOrders;
|
|
1691
|
+
}()
|
|
1242
1692
|
/**
|
|
1243
1693
|
* 通过 SSE 按自定义 query 拉取订单(支持 select/with 精简字段)
|
|
1244
1694
|
*/
|
|
@@ -1246,42 +1696,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1246
1696
|
}, {
|
|
1247
1697
|
key: "fetchOrdersBySSE",
|
|
1248
1698
|
value: (function () {
|
|
1249
|
-
var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1699
|
+
var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
1250
1700
|
var query,
|
|
1251
1701
|
data,
|
|
1252
|
-
|
|
1253
|
-
return _regeneratorRuntime().wrap(function
|
|
1254
|
-
while (1) switch (
|
|
1702
|
+
_args15 = arguments;
|
|
1703
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1704
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1255
1705
|
case 0:
|
|
1256
|
-
query =
|
|
1706
|
+
query = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
|
|
1257
1707
|
if (this.orderDataSource) {
|
|
1258
|
-
|
|
1708
|
+
_context15.next = 3;
|
|
1259
1709
|
break;
|
|
1260
1710
|
}
|
|
1261
|
-
return
|
|
1711
|
+
return _context15.abrupt("return", []);
|
|
1262
1712
|
case 3:
|
|
1263
|
-
|
|
1264
|
-
|
|
1713
|
+
_context15.prev = 3;
|
|
1714
|
+
_context15.next = 6;
|
|
1265
1715
|
return this.orderDataSource.run({
|
|
1266
1716
|
sse: {
|
|
1267
1717
|
query: query
|
|
1268
1718
|
}
|
|
1269
1719
|
});
|
|
1270
1720
|
case 6:
|
|
1271
|
-
data =
|
|
1272
|
-
return
|
|
1721
|
+
data = _context15.sent;
|
|
1722
|
+
return _context15.abrupt("return", data || []);
|
|
1273
1723
|
case 10:
|
|
1274
|
-
|
|
1275
|
-
|
|
1724
|
+
_context15.prev = 10;
|
|
1725
|
+
_context15.t0 = _context15["catch"](3);
|
|
1276
1726
|
this.logError('fetchOrdersBySSE-失败', {
|
|
1277
|
-
error:
|
|
1727
|
+
error: _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0)
|
|
1278
1728
|
});
|
|
1279
|
-
return
|
|
1729
|
+
return _context15.abrupt("return", []);
|
|
1280
1730
|
case 14:
|
|
1281
1731
|
case "end":
|
|
1282
|
-
return
|
|
1732
|
+
return _context15.stop();
|
|
1283
1733
|
}
|
|
1284
|
-
},
|
|
1734
|
+
}, _callee15, this, [[3, 10]]);
|
|
1285
1735
|
}));
|
|
1286
1736
|
function fetchOrdersBySSE() {
|
|
1287
1737
|
return _fetchOrdersBySSE.apply(this, arguments);
|
|
@@ -1310,19 +1760,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1310
1760
|
key: "syncOrdersMap",
|
|
1311
1761
|
value: function syncOrdersMap() {
|
|
1312
1762
|
this.store.map.clear();
|
|
1313
|
-
var
|
|
1314
|
-
|
|
1763
|
+
var _iterator11 = _createForOfIteratorHelper(this.store.list),
|
|
1764
|
+
_step11;
|
|
1315
1765
|
try {
|
|
1316
|
-
for (
|
|
1317
|
-
var order =
|
|
1766
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
1767
|
+
var order = _step11.value;
|
|
1318
1768
|
var primaryIdentity = this.getOrderMapKey(order);
|
|
1319
1769
|
if (!primaryIdentity) continue;
|
|
1320
1770
|
this.store.map.set(primaryIdentity, order);
|
|
1321
1771
|
}
|
|
1322
1772
|
} catch (err) {
|
|
1323
|
-
|
|
1773
|
+
_iterator11.e(err);
|
|
1324
1774
|
} finally {
|
|
1325
|
-
|
|
1775
|
+
_iterator11.f();
|
|
1326
1776
|
}
|
|
1327
1777
|
}
|
|
1328
1778
|
}, {
|
|
@@ -1386,17 +1836,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1386
1836
|
key: "getOrderIdentityKeys",
|
|
1387
1837
|
value: function getOrderIdentityKeys(order) {
|
|
1388
1838
|
var keys = [];
|
|
1389
|
-
var
|
|
1390
|
-
|
|
1839
|
+
var _iterator12 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
|
|
1840
|
+
_step12;
|
|
1391
1841
|
try {
|
|
1392
|
-
for (
|
|
1393
|
-
var entry =
|
|
1842
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
1843
|
+
var entry = _step12.value;
|
|
1394
1844
|
if (!keys.includes(entry.key)) keys.push(entry.key);
|
|
1395
1845
|
}
|
|
1396
1846
|
} catch (err) {
|
|
1397
|
-
|
|
1847
|
+
_iterator12.e(err);
|
|
1398
1848
|
} finally {
|
|
1399
|
-
|
|
1849
|
+
_iterator12.f();
|
|
1400
1850
|
}
|
|
1401
1851
|
return keys;
|
|
1402
1852
|
}
|
|
@@ -1496,41 +1946,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1496
1946
|
}, {
|
|
1497
1947
|
key: "flushOrderSyncMessagesByThrottle",
|
|
1498
1948
|
value: (function () {
|
|
1499
|
-
var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1500
|
-
return _regeneratorRuntime().wrap(function
|
|
1501
|
-
while (1) switch (
|
|
1949
|
+
var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
|
|
1950
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1951
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1502
1952
|
case 0:
|
|
1503
1953
|
if (!this.isProcessingSyncBatch) {
|
|
1504
|
-
|
|
1954
|
+
_context16.next = 2;
|
|
1505
1955
|
break;
|
|
1506
1956
|
}
|
|
1507
|
-
return
|
|
1957
|
+
return _context16.abrupt("return");
|
|
1508
1958
|
case 2:
|
|
1509
1959
|
if (!(this.pendingSyncMessages.length === 0)) {
|
|
1510
|
-
|
|
1960
|
+
_context16.next = 5;
|
|
1511
1961
|
break;
|
|
1512
1962
|
}
|
|
1513
1963
|
this.isIdlePhase = true;
|
|
1514
|
-
return
|
|
1964
|
+
return _context16.abrupt("return");
|
|
1515
1965
|
case 5:
|
|
1516
1966
|
this.isProcessingSyncBatch = true;
|
|
1517
|
-
|
|
1518
|
-
|
|
1967
|
+
_context16.prev = 6;
|
|
1968
|
+
_context16.next = 9;
|
|
1519
1969
|
return this.processOrderSyncMessages();
|
|
1520
1970
|
case 9:
|
|
1521
|
-
|
|
1971
|
+
_context16.prev = 9;
|
|
1522
1972
|
this.isProcessingSyncBatch = false;
|
|
1523
1973
|
if (this.pendingSyncMessages.length > 0) {
|
|
1524
1974
|
this.scheduleOrderSyncThrottle();
|
|
1525
1975
|
} else {
|
|
1526
1976
|
this.isIdlePhase = true;
|
|
1527
1977
|
}
|
|
1528
|
-
return
|
|
1978
|
+
return _context16.finish(9);
|
|
1529
1979
|
case 13:
|
|
1530
1980
|
case "end":
|
|
1531
|
-
return
|
|
1981
|
+
return _context16.stop();
|
|
1532
1982
|
}
|
|
1533
|
-
},
|
|
1983
|
+
}, _callee16, this, [[6,, 9, 13]]);
|
|
1534
1984
|
}));
|
|
1535
1985
|
function flushOrderSyncMessagesByThrottle() {
|
|
1536
1986
|
return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
|
|
@@ -1552,19 +2002,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1552
2002
|
}, {
|
|
1553
2003
|
key: "processOrderSyncMessages",
|
|
1554
2004
|
value: (function () {
|
|
1555
|
-
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2005
|
+
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
1556
2006
|
var _this14 = this;
|
|
1557
2007
|
var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
|
|
1558
|
-
return _regeneratorRuntime().wrap(function
|
|
1559
|
-
while (1) switch (
|
|
2008
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
2009
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1560
2010
|
case 0:
|
|
1561
2011
|
messages = _toConsumableArray(this.pendingSyncMessages);
|
|
1562
2012
|
this.pendingSyncMessages = [];
|
|
1563
2013
|
if (!(messages.length === 0)) {
|
|
1564
|
-
|
|
2014
|
+
_context17.next = 4;
|
|
1565
2015
|
break;
|
|
1566
2016
|
}
|
|
1567
|
-
return
|
|
2017
|
+
return _context17.abrupt("return");
|
|
1568
2018
|
case 4:
|
|
1569
2019
|
batchProcessStartAt = Date.now();
|
|
1570
2020
|
earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
|
|
@@ -1598,41 +2048,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1598
2048
|
refreshIdCount: uniqueRefreshIds.length
|
|
1599
2049
|
});
|
|
1600
2050
|
if (!(upsertList.length > 0)) {
|
|
1601
|
-
|
|
2051
|
+
_context17.next = 16;
|
|
1602
2052
|
break;
|
|
1603
2053
|
}
|
|
1604
|
-
|
|
2054
|
+
_context17.next = 16;
|
|
1605
2055
|
return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
|
|
1606
2056
|
case 16:
|
|
1607
2057
|
if (!(uniqueRefreshIds.length > 0)) {
|
|
1608
|
-
|
|
2058
|
+
_context17.next = 28;
|
|
1609
2059
|
break;
|
|
1610
2060
|
}
|
|
1611
2061
|
_this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
|
|
1612
2062
|
if (skipped.length > 0) {}
|
|
1613
2063
|
if (!(toFetch.length > 0)) {
|
|
1614
|
-
|
|
2064
|
+
_context17.next = 28;
|
|
1615
2065
|
break;
|
|
1616
2066
|
}
|
|
1617
|
-
|
|
2067
|
+
_context17.next = 22;
|
|
1618
2068
|
return this.fetchOrdersByHttp(toFetch);
|
|
1619
2069
|
case 22:
|
|
1620
|
-
freshOrders =
|
|
2070
|
+
freshOrders = _context17.sent;
|
|
1621
2071
|
if (!(freshOrders.length > 0)) {
|
|
1622
|
-
|
|
2072
|
+
_context17.next = 28;
|
|
1623
2073
|
break;
|
|
1624
2074
|
}
|
|
1625
|
-
|
|
2075
|
+
_context17.next = 26;
|
|
1626
2076
|
return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
|
|
1627
2077
|
case 26:
|
|
1628
|
-
|
|
2078
|
+
_context17.next = 28;
|
|
1629
2079
|
break;
|
|
1630
2080
|
case 28:
|
|
1631
2081
|
if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
|
|
1632
|
-
|
|
2082
|
+
_context17.next = 30;
|
|
1633
2083
|
break;
|
|
1634
2084
|
}
|
|
1635
|
-
return
|
|
2085
|
+
return _context17.abrupt("return");
|
|
1636
2086
|
case 30:
|
|
1637
2087
|
batchProcessEndAt = Date.now();
|
|
1638
2088
|
this.logInfo('processOrderSyncMessages-结束', {
|
|
@@ -1641,13 +2091,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1641
2091
|
batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
|
|
1642
2092
|
totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
|
|
1643
2093
|
});
|
|
1644
|
-
|
|
2094
|
+
_context17.next = 34;
|
|
1645
2095
|
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
1646
2096
|
case 34:
|
|
1647
2097
|
case "end":
|
|
1648
|
-
return
|
|
2098
|
+
return _context17.stop();
|
|
1649
2099
|
}
|
|
1650
|
-
},
|
|
2100
|
+
}, _callee17, this);
|
|
1651
2101
|
}));
|
|
1652
2102
|
function processOrderSyncMessages() {
|
|
1653
2103
|
return _processOrderSyncMessages.apply(this, arguments);
|
|
@@ -1668,29 +2118,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1668
2118
|
}, {
|
|
1669
2119
|
key: "fetchOrdersByHttp",
|
|
1670
2120
|
value: (function () {
|
|
1671
|
-
var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2121
|
+
var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(ids) {
|
|
1672
2122
|
var _orderList, orderList;
|
|
1673
|
-
return _regeneratorRuntime().wrap(function
|
|
1674
|
-
while (1) switch (
|
|
2123
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
2124
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1675
2125
|
case 0:
|
|
1676
2126
|
if (!(!this.orderDataSource || ids.length === 0)) {
|
|
1677
|
-
|
|
2127
|
+
_context18.next = 2;
|
|
1678
2128
|
break;
|
|
1679
2129
|
}
|
|
1680
|
-
return
|
|
2130
|
+
return _context18.abrupt("return", []);
|
|
1681
2131
|
case 2:
|
|
1682
|
-
|
|
2132
|
+
_context18.prev = 2;
|
|
1683
2133
|
if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
|
|
1684
|
-
|
|
2134
|
+
_context18.next = 8;
|
|
1685
2135
|
break;
|
|
1686
2136
|
}
|
|
1687
|
-
|
|
2137
|
+
_context18.next = 6;
|
|
1688
2138
|
return this.orderDataSource.fetchOrdersByIds(ids);
|
|
1689
2139
|
case 6:
|
|
1690
|
-
_orderList =
|
|
1691
|
-
return
|
|
2140
|
+
_orderList = _context18.sent;
|
|
2141
|
+
return _context18.abrupt("return", _orderList || []);
|
|
1692
2142
|
case 8:
|
|
1693
|
-
|
|
2143
|
+
_context18.next = 10;
|
|
1694
2144
|
return this.orderDataSource.run({
|
|
1695
2145
|
http: {
|
|
1696
2146
|
query: {
|
|
@@ -1699,19 +2149,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1699
2149
|
}
|
|
1700
2150
|
});
|
|
1701
2151
|
case 10:
|
|
1702
|
-
orderList =
|
|
1703
|
-
return
|
|
2152
|
+
orderList = _context18.sent;
|
|
2153
|
+
return _context18.abrupt("return", orderList || []);
|
|
1704
2154
|
case 14:
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
return
|
|
2155
|
+
_context18.prev = 14;
|
|
2156
|
+
_context18.t0 = _context18["catch"](2);
|
|
2157
|
+
return _context18.abrupt("return", []);
|
|
1708
2158
|
case 17:
|
|
1709
2159
|
case "end":
|
|
1710
|
-
return
|
|
2160
|
+
return _context18.stop();
|
|
1711
2161
|
}
|
|
1712
|
-
},
|
|
2162
|
+
}, _callee18, this, [[2, 14]]);
|
|
1713
2163
|
}));
|
|
1714
|
-
function fetchOrdersByHttp(
|
|
2164
|
+
function fetchOrdersByHttp(_x11) {
|
|
1715
2165
|
return _fetchOrdersByHttp.apply(this, arguments);
|
|
1716
2166
|
}
|
|
1717
2167
|
return fetchOrdersByHttp;
|
|
@@ -1723,11 +2173,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1723
2173
|
}, {
|
|
1724
2174
|
key: "mergeOrdersToStore",
|
|
1725
2175
|
value: (function () {
|
|
1726
|
-
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2176
|
+
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(freshOrders, source) {
|
|
1727
2177
|
var _this15 = this;
|
|
1728
|
-
var storeOrderCountBefore, normalizedFreshOrders,
|
|
1729
|
-
return _regeneratorRuntime().wrap(function
|
|
1730
|
-
while (1) switch (
|
|
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, _ref2, _existingOrder$order_, _ref3, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, _ref4, _existingOrder$order_2, _ref5, _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;
|
|
2179
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
2180
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1731
2181
|
case 0:
|
|
1732
2182
|
storeOrderCountBefore = this.store.list.length;
|
|
1733
2183
|
this.logInfo('mergeOrdersToStore-开始', {
|
|
@@ -1737,37 +2187,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1737
2187
|
});
|
|
1738
2188
|
this.logDuplicateOrders("".concat(source, ".beforeMerge"), this.store.list);
|
|
1739
2189
|
normalizedFreshOrders = [];
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
2190
|
+
_iterator13 = _createForOfIteratorHelper(freshOrders);
|
|
2191
|
+
_context19.prev = 5;
|
|
2192
|
+
_iterator13.s();
|
|
1743
2193
|
case 7:
|
|
1744
|
-
if ((
|
|
1745
|
-
|
|
2194
|
+
if ((_step13 = _iterator13.n()).done) {
|
|
2195
|
+
_context19.next = 15;
|
|
1746
2196
|
break;
|
|
1747
2197
|
}
|
|
1748
|
-
order =
|
|
2198
|
+
order = _step13.value;
|
|
1749
2199
|
id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
1750
2200
|
if (!(id === undefined || id === null)) {
|
|
1751
|
-
|
|
2201
|
+
_context19.next = 12;
|
|
1752
2202
|
break;
|
|
1753
2203
|
}
|
|
1754
|
-
return
|
|
2204
|
+
return _context19.abrupt("continue", 13);
|
|
1755
2205
|
case 12:
|
|
1756
2206
|
normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
|
|
1757
2207
|
case 13:
|
|
1758
|
-
|
|
2208
|
+
_context19.next = 7;
|
|
1759
2209
|
break;
|
|
1760
2210
|
case 15:
|
|
1761
|
-
|
|
2211
|
+
_context19.next = 20;
|
|
1762
2212
|
break;
|
|
1763
2213
|
case 17:
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
2214
|
+
_context19.prev = 17;
|
|
2215
|
+
_context19.t0 = _context19["catch"](5);
|
|
2216
|
+
_iterator13.e(_context19.t0);
|
|
1767
2217
|
case 20:
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
return
|
|
2218
|
+
_context19.prev = 20;
|
|
2219
|
+
_iterator13.f();
|
|
2220
|
+
return _context19.finish(20);
|
|
1771
2221
|
case 23:
|
|
1772
2222
|
// 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
|
|
1773
2223
|
uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
|
|
@@ -1782,39 +2232,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1782
2232
|
identityKeyToIndex = new Map();
|
|
1783
2233
|
for (index = 0; index < updatedList.length; index += 1) {
|
|
1784
2234
|
identityKeys = this.getOrderIdentityMatchKeys(updatedList[index]);
|
|
1785
|
-
|
|
2235
|
+
_iterator14 = _createForOfIteratorHelper(identityKeys);
|
|
1786
2236
|
try {
|
|
1787
|
-
for (
|
|
1788
|
-
key =
|
|
2237
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
2238
|
+
key = _step14.value;
|
|
1789
2239
|
// 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
|
|
1790
2240
|
if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
|
|
1791
2241
|
}
|
|
1792
2242
|
} catch (err) {
|
|
1793
|
-
|
|
2243
|
+
_iterator14.e(err);
|
|
1794
2244
|
} finally {
|
|
1795
|
-
|
|
2245
|
+
_iterator14.f();
|
|
1796
2246
|
}
|
|
1797
2247
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
2248
|
+
_iterator15 = _createForOfIteratorHelper(uniqueFreshOrders);
|
|
2249
|
+
_context19.prev = 31;
|
|
2250
|
+
_iterator15.s();
|
|
1801
2251
|
case 33:
|
|
1802
|
-
if ((
|
|
1803
|
-
|
|
2252
|
+
if ((_step15 = _iterator15.n()).done) {
|
|
2253
|
+
_context19.next = 82;
|
|
1804
2254
|
break;
|
|
1805
2255
|
}
|
|
1806
|
-
fresh =
|
|
2256
|
+
fresh = _step15.value;
|
|
1807
2257
|
freshIdentityKeys = this.getOrderIdentityMatchKeys(fresh);
|
|
1808
2258
|
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys);
|
|
1809
2259
|
storageKey = this.getOrderStorageKey(fresh);
|
|
1810
2260
|
mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
|
|
1811
2261
|
if (!(matchIndex >= 0)) {
|
|
1812
|
-
|
|
2262
|
+
_context19.next = 75;
|
|
1813
2263
|
break;
|
|
1814
2264
|
}
|
|
1815
2265
|
existingOrder = updatedList[matchIndex];
|
|
1816
2266
|
if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
|
|
1817
|
-
|
|
2267
|
+
_context19.next = 44;
|
|
1818
2268
|
break;
|
|
1819
2269
|
}
|
|
1820
2270
|
this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
|
|
@@ -1827,37 +2277,116 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1827
2277
|
remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
|
|
1828
2278
|
reason: 'protect_pending_sync_order_from_remote_echo'
|
|
1829
2279
|
});
|
|
1830
|
-
return
|
|
2280
|
+
return _context19.abrupt("continue", 80);
|
|
1831
2281
|
case 44:
|
|
2282
|
+
if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
|
|
2283
|
+
_context19.next = 47;
|
|
2284
|
+
break;
|
|
2285
|
+
}
|
|
2286
|
+
this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
|
|
2287
|
+
source: source,
|
|
2288
|
+
order_id: (_ref4 = (_existingOrder$order_2 = existingOrder.order_id) !== null && _existingOrder$order_2 !== void 0 ? _existingOrder$order_2 : fresh.order_id) !== null && _ref4 !== void 0 ? _ref4 : null,
|
|
2289
|
+
external_sale_number: (_ref5 = (_external_sale_number3 = existingOrder.external_sale_number) !== null && _external_sale_number3 !== void 0 ? _external_sale_number3 : fresh.external_sale_number) !== null && _ref5 !== void 0 ? _ref5 : null,
|
|
2290
|
+
local_is_draft_order: (_existingOrder$is_dra = existingOrder.is_draft_order) !== null && _existingOrder$is_dra !== void 0 ? _existingOrder$is_dra : null,
|
|
2291
|
+
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
|
+
reason: 'protect_draft_order_from_remote_echo'
|
|
2293
|
+
});
|
|
2294
|
+
return _context19.abrupt("continue", 80);
|
|
2295
|
+
case 47:
|
|
1832
2296
|
mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
|
|
1833
|
-
|
|
2297
|
+
adjustedMatchIndex = matchIndex;
|
|
2298
|
+
duplicateIndexes = new Set();
|
|
2299
|
+
_iterator16 = _createForOfIteratorHelper(freshIdentityKeys);
|
|
2300
|
+
_context19.prev = 51;
|
|
2301
|
+
_iterator16.s();
|
|
2302
|
+
case 53:
|
|
2303
|
+
if ((_step16 = _iterator16.n()).done) {
|
|
2304
|
+
_context19.next = 61;
|
|
2305
|
+
break;
|
|
2306
|
+
}
|
|
2307
|
+
_key2 = _step16.value;
|
|
2308
|
+
_duplicateIndex = identityKeyToIndex.get(_key2);
|
|
2309
|
+
if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
|
|
2310
|
+
_context19.next = 58;
|
|
2311
|
+
break;
|
|
2312
|
+
}
|
|
2313
|
+
return _context19.abrupt("continue", 59);
|
|
2314
|
+
case 58:
|
|
2315
|
+
duplicateIndexes.add(_duplicateIndex);
|
|
2316
|
+
case 59:
|
|
2317
|
+
_context19.next = 53;
|
|
2318
|
+
break;
|
|
2319
|
+
case 61:
|
|
2320
|
+
_context19.next = 66;
|
|
2321
|
+
break;
|
|
2322
|
+
case 63:
|
|
2323
|
+
_context19.prev = 63;
|
|
2324
|
+
_context19.t1 = _context19["catch"](51);
|
|
2325
|
+
_iterator16.e(_context19.t1);
|
|
2326
|
+
case 66:
|
|
2327
|
+
_context19.prev = 66;
|
|
2328
|
+
_iterator16.f();
|
|
2329
|
+
return _context19.finish(66);
|
|
2330
|
+
case 69:
|
|
2331
|
+
if (duplicateIndexes.size > 0) {
|
|
2332
|
+
_iterator17 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
|
|
2333
|
+
return right - left;
|
|
2334
|
+
}));
|
|
2335
|
+
try {
|
|
2336
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
2337
|
+
duplicateIndex = _step17.value;
|
|
2338
|
+
mergedOrder = this.mergeOrderRecords(mergedOrder, updatedList[duplicateIndex]);
|
|
2339
|
+
updatedList.splice(duplicateIndex, 1);
|
|
2340
|
+
if (duplicateIndex < adjustedMatchIndex) adjustedMatchIndex -= 1;
|
|
2341
|
+
}
|
|
2342
|
+
} catch (err) {
|
|
2343
|
+
_iterator17.e(err);
|
|
2344
|
+
} finally {
|
|
2345
|
+
_iterator17.f();
|
|
2346
|
+
}
|
|
2347
|
+
identityKeyToIndex.clear();
|
|
2348
|
+
for (_index = 0; _index < updatedList.length; _index += 1) {
|
|
2349
|
+
_iterator18 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[_index]));
|
|
2350
|
+
try {
|
|
2351
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
2352
|
+
_key = _step18.value;
|
|
2353
|
+
if (!identityKeyToIndex.has(_key)) identityKeyToIndex.set(_key, _index);
|
|
2354
|
+
}
|
|
2355
|
+
} catch (err) {
|
|
2356
|
+
_iterator18.e(err);
|
|
2357
|
+
} finally {
|
|
2358
|
+
_iterator18.f();
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
updatedList[adjustedMatchIndex] = mergedOrder;
|
|
1834
2363
|
// 合并后身份字段可能新增(如挂单拿到 order_id),同步登记到索引,
|
|
1835
2364
|
// 供同批后续 fresh 命中同一槽位,避免重复插入
|
|
1836
|
-
this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder,
|
|
2365
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
|
|
1837
2366
|
patchedOrders.push(mergedOrder);
|
|
1838
2367
|
if (mergeKey) mergeActions[mergeKey] = 'update';
|
|
1839
|
-
return
|
|
1840
|
-
case
|
|
2368
|
+
return _context19.abrupt("continue", 80);
|
|
2369
|
+
case 75:
|
|
1841
2370
|
insertIndex = updatedList.length;
|
|
1842
2371
|
updatedList.push(fresh);
|
|
1843
2372
|
this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
|
|
1844
2373
|
patchedOrders.push(fresh);
|
|
1845
2374
|
if (mergeKey) mergeActions[mergeKey] = 'insert';
|
|
1846
|
-
case
|
|
1847
|
-
|
|
2375
|
+
case 80:
|
|
2376
|
+
_context19.next = 33;
|
|
1848
2377
|
break;
|
|
1849
|
-
case
|
|
1850
|
-
|
|
2378
|
+
case 82:
|
|
2379
|
+
_context19.next = 87;
|
|
1851
2380
|
break;
|
|
1852
|
-
case
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
case
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
return
|
|
1860
|
-
case
|
|
2381
|
+
case 84:
|
|
2382
|
+
_context19.prev = 84;
|
|
2383
|
+
_context19.t2 = _context19["catch"](31);
|
|
2384
|
+
_iterator15.e(_context19.t2);
|
|
2385
|
+
case 87:
|
|
2386
|
+
_context19.prev = 87;
|
|
2387
|
+
_iterator15.f();
|
|
2388
|
+
return _context19.finish(87);
|
|
2389
|
+
case 90:
|
|
1861
2390
|
insertCount = Object.values(mergeActions).filter(function (v) {
|
|
1862
2391
|
return v === 'insert';
|
|
1863
2392
|
}).length;
|
|
@@ -1873,24 +2402,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1873
2402
|
// 仅在自检开关开启时做一次兜底校验。
|
|
1874
2403
|
this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
|
|
1875
2404
|
this.syncOrdersMap();
|
|
1876
|
-
|
|
2405
|
+
_context19.next = 97;
|
|
1877
2406
|
return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
|
|
1878
|
-
case
|
|
2407
|
+
case 97:
|
|
1879
2408
|
this.logInfo('mergeOrdersToStore-结束', {
|
|
1880
2409
|
uniqueFreshCount: uniqueFreshCount,
|
|
1881
2410
|
storeOrderCountAfter: this.store.list.length,
|
|
1882
2411
|
insertCount: insertCount,
|
|
1883
2412
|
updateCount: updateCount
|
|
1884
2413
|
});
|
|
1885
|
-
|
|
2414
|
+
_context19.next = 100;
|
|
1886
2415
|
return this.emitOrdersChanged(patchedOrders, source);
|
|
1887
|
-
case
|
|
2416
|
+
case 100:
|
|
1888
2417
|
case "end":
|
|
1889
|
-
return
|
|
2418
|
+
return _context19.stop();
|
|
1890
2419
|
}
|
|
1891
|
-
},
|
|
2420
|
+
}, _callee19, this, [[5, 17, 20, 23], [31, 84, 87, 90], [51, 63, 66, 69]]);
|
|
1892
2421
|
}));
|
|
1893
|
-
function mergeOrdersToStore(
|
|
2422
|
+
function mergeOrdersToStore(_x12, _x13) {
|
|
1894
2423
|
return _mergeOrdersToStore.apply(this, arguments);
|
|
1895
2424
|
}
|
|
1896
2425
|
return mergeOrdersToStore;
|
|
@@ -1907,19 +2436,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1907
2436
|
key: "lookupOrderIndexByIdentityKeys",
|
|
1908
2437
|
value: function lookupOrderIndexByIdentityKeys(identityKeyToIndex, identityKeys) {
|
|
1909
2438
|
var matchIndex = -1;
|
|
1910
|
-
var
|
|
1911
|
-
|
|
2439
|
+
var _iterator19 = _createForOfIteratorHelper(identityKeys),
|
|
2440
|
+
_step19;
|
|
1912
2441
|
try {
|
|
1913
|
-
for (
|
|
1914
|
-
var key =
|
|
2442
|
+
for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
|
|
2443
|
+
var key = _step19.value;
|
|
1915
2444
|
var index = identityKeyToIndex.get(key);
|
|
1916
2445
|
if (index === undefined) continue;
|
|
1917
2446
|
if (matchIndex < 0 || index < matchIndex) matchIndex = index;
|
|
1918
2447
|
}
|
|
1919
2448
|
} catch (err) {
|
|
1920
|
-
|
|
2449
|
+
_iterator19.e(err);
|
|
1921
2450
|
} finally {
|
|
1922
|
-
|
|
2451
|
+
_iterator19.f();
|
|
1923
2452
|
}
|
|
1924
2453
|
return matchIndex;
|
|
1925
2454
|
}
|
|
@@ -1940,17 +2469,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1940
2469
|
key: "registerOrderIdentityKeys",
|
|
1941
2470
|
value: function registerOrderIdentityKeys(identityKeyToIndex, order, index) {
|
|
1942
2471
|
var identityKeys = this.getOrderIdentityMatchKeys(order);
|
|
1943
|
-
var
|
|
1944
|
-
|
|
2472
|
+
var _iterator20 = _createForOfIteratorHelper(identityKeys),
|
|
2473
|
+
_step20;
|
|
1945
2474
|
try {
|
|
1946
|
-
for (
|
|
1947
|
-
var key =
|
|
2475
|
+
for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
|
|
2476
|
+
var key = _step20.value;
|
|
1948
2477
|
identityKeyToIndex.set(key, index);
|
|
1949
2478
|
}
|
|
1950
2479
|
} catch (err) {
|
|
1951
|
-
|
|
2480
|
+
_iterator20.e(err);
|
|
1952
2481
|
} finally {
|
|
1953
|
-
|
|
2482
|
+
_iterator20.f();
|
|
1954
2483
|
}
|
|
1955
2484
|
}
|
|
1956
2485
|
|
|
@@ -2005,17 +2534,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2005
2534
|
key: "uniqueOrderIds",
|
|
2006
2535
|
value: function uniqueOrderIds(ids) {
|
|
2007
2536
|
var idMap = new Map();
|
|
2008
|
-
var
|
|
2009
|
-
|
|
2537
|
+
var _iterator21 = _createForOfIteratorHelper(ids),
|
|
2538
|
+
_step21;
|
|
2010
2539
|
try {
|
|
2011
|
-
for (
|
|
2012
|
-
var id =
|
|
2540
|
+
for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
|
|
2541
|
+
var id = _step21.value;
|
|
2013
2542
|
idMap.set(this.getIdKey(id), id);
|
|
2014
2543
|
}
|
|
2015
2544
|
} catch (err) {
|
|
2016
|
-
|
|
2545
|
+
_iterator21.e(err);
|
|
2017
2546
|
} finally {
|
|
2018
|
-
|
|
2547
|
+
_iterator21.f();
|
|
2019
2548
|
}
|
|
2020
2549
|
return _toConsumableArray(idMap.values());
|
|
2021
2550
|
}
|
|
@@ -2102,6 +2631,94 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2102
2631
|
if (rightScore >= leftScore) return right;
|
|
2103
2632
|
return left;
|
|
2104
2633
|
}
|
|
2634
|
+
}, {
|
|
2635
|
+
key: "getProductIdentityKeys",
|
|
2636
|
+
value: function getProductIdentityKeys(product) {
|
|
2637
|
+
var _record$metadata;
|
|
2638
|
+
var record = product;
|
|
2639
|
+
if (!record) return [];
|
|
2640
|
+
var keys = [];
|
|
2641
|
+
var metadataUid = (_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.unique_identification_number;
|
|
2642
|
+
if (!this.isBlankIdentityValue(metadataUid)) keys.push("uid:".concat(String(metadataUid)));
|
|
2643
|
+
var topLevelUid = record.unique_identification_number;
|
|
2644
|
+
if (!this.isBlankIdentityValue(topLevelUid)) keys.push("uid:".concat(String(topLevelUid)));
|
|
2645
|
+
var orderDetailId = record.order_detail_id;
|
|
2646
|
+
if (!this.isBlankIdentityValue(orderDetailId)) keys.push("detail:".concat(String(orderDetailId)));
|
|
2647
|
+
var bookingUid = record.booking_uid;
|
|
2648
|
+
if (!this.isBlankIdentityValue(bookingUid)) keys.push("booking:".concat(String(bookingUid)));
|
|
2649
|
+
return keys;
|
|
2650
|
+
}
|
|
2651
|
+
}, {
|
|
2652
|
+
key: "mergeOrderProductLists",
|
|
2653
|
+
value: function mergeOrderProductLists(preferred, secondary) {
|
|
2654
|
+
var preferredList = Array.isArray(preferred) ? preferred : [];
|
|
2655
|
+
var secondaryList = Array.isArray(secondary) ? secondary : [];
|
|
2656
|
+
if (secondaryList.length === 0) return preferredList;
|
|
2657
|
+
if (preferredList.length === 0) return secondaryList;
|
|
2658
|
+
var seenKeys = new Set();
|
|
2659
|
+
var _iterator22 = _createForOfIteratorHelper(preferredList),
|
|
2660
|
+
_step22;
|
|
2661
|
+
try {
|
|
2662
|
+
for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
|
|
2663
|
+
var item = _step22.value;
|
|
2664
|
+
var keys = this.getProductIdentityKeys(item);
|
|
2665
|
+
var _iterator24 = _createForOfIteratorHelper(keys),
|
|
2666
|
+
_step24;
|
|
2667
|
+
try {
|
|
2668
|
+
for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
|
|
2669
|
+
var key = _step24.value;
|
|
2670
|
+
seenKeys.add(key);
|
|
2671
|
+
}
|
|
2672
|
+
} catch (err) {
|
|
2673
|
+
_iterator24.e(err);
|
|
2674
|
+
} finally {
|
|
2675
|
+
_iterator24.f();
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
} catch (err) {
|
|
2679
|
+
_iterator22.e(err);
|
|
2680
|
+
} finally {
|
|
2681
|
+
_iterator22.f();
|
|
2682
|
+
}
|
|
2683
|
+
var result = _toConsumableArray(preferredList);
|
|
2684
|
+
var _iterator23 = _createForOfIteratorHelper(secondaryList),
|
|
2685
|
+
_step23;
|
|
2686
|
+
try {
|
|
2687
|
+
for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
|
|
2688
|
+
var _item = _step23.value;
|
|
2689
|
+
var _keys = this.getProductIdentityKeys(_item);
|
|
2690
|
+
if (_keys.length === 0 || _keys.some(function (key) {
|
|
2691
|
+
return seenKeys.has(key);
|
|
2692
|
+
})) continue;
|
|
2693
|
+
var _iterator25 = _createForOfIteratorHelper(_keys),
|
|
2694
|
+
_step25;
|
|
2695
|
+
try {
|
|
2696
|
+
for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
|
|
2697
|
+
var _key3 = _step25.value;
|
|
2698
|
+
seenKeys.add(_key3);
|
|
2699
|
+
}
|
|
2700
|
+
} catch (err) {
|
|
2701
|
+
_iterator25.e(err);
|
|
2702
|
+
} finally {
|
|
2703
|
+
_iterator25.f();
|
|
2704
|
+
}
|
|
2705
|
+
result.push(cloneDeep(_item));
|
|
2706
|
+
}
|
|
2707
|
+
} catch (err) {
|
|
2708
|
+
_iterator23.e(err);
|
|
2709
|
+
} finally {
|
|
2710
|
+
_iterator23.f();
|
|
2711
|
+
}
|
|
2712
|
+
return result;
|
|
2713
|
+
}
|
|
2714
|
+
}, {
|
|
2715
|
+
key: "mergeOrderPaymentLists",
|
|
2716
|
+
value: function mergeOrderPaymentLists(existing, incoming) {
|
|
2717
|
+
var existingList = Array.isArray(existing) ? existing : [];
|
|
2718
|
+
var incomingList = Array.isArray(incoming) ? incoming : [];
|
|
2719
|
+
if (incomingList.length === 0) return cloneDeep(existingList);
|
|
2720
|
+
return mergeOrderPaymentListsByIdentity(existingList, incomingList);
|
|
2721
|
+
}
|
|
2105
2722
|
}, {
|
|
2106
2723
|
key: "mergeOrderRecords",
|
|
2107
2724
|
value: function mergeOrderRecords(existing, incoming) {
|
|
@@ -2109,7 +2726,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2109
2726
|
var secondary = preferred === existing ? incoming : existing;
|
|
2110
2727
|
var merged = _objectSpread(_objectSpread({}, secondary), preferred);
|
|
2111
2728
|
var fieldsToPreserve = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number'];
|
|
2112
|
-
var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'shop_discount', 'summary', 'note', 'customer_id', 'customer_name', 'customer', 'holder', 'contacts_info', 'phone', 'email', 'relation_forms'];
|
|
2729
|
+
var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'shop_discount', 'summary', 'note', 'customer_id', 'customer_name', 'customer', 'holder', 'contacts_info', 'phone', 'email', 'relation_forms', 'is_draft_order'];
|
|
2113
2730
|
var mergedRecord = merged;
|
|
2114
2731
|
var preferredRecord = preferred;
|
|
2115
2732
|
var secondaryRecord = secondary;
|
|
@@ -2157,50 +2774,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2157
2774
|
key: "summarizeDuplicateOrders",
|
|
2158
2775
|
value: function summarizeDuplicateOrders(orders) {
|
|
2159
2776
|
var groups = new Map();
|
|
2160
|
-
var
|
|
2161
|
-
|
|
2777
|
+
var _iterator26 = _createForOfIteratorHelper(orders),
|
|
2778
|
+
_step26;
|
|
2162
2779
|
try {
|
|
2163
|
-
for (
|
|
2164
|
-
var order =
|
|
2165
|
-
var
|
|
2166
|
-
|
|
2780
|
+
for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
|
|
2781
|
+
var order = _step26.value;
|
|
2782
|
+
var _iterator27 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
|
|
2783
|
+
_step27;
|
|
2167
2784
|
try {
|
|
2168
|
-
for (
|
|
2169
|
-
var key =
|
|
2785
|
+
for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
|
|
2786
|
+
var key = _step27.value;
|
|
2170
2787
|
var group = groups.get(key) || [];
|
|
2171
2788
|
group.push(order);
|
|
2172
2789
|
groups.set(key, group);
|
|
2173
2790
|
}
|
|
2174
2791
|
} catch (err) {
|
|
2175
|
-
|
|
2792
|
+
_iterator27.e(err);
|
|
2176
2793
|
} finally {
|
|
2177
|
-
|
|
2794
|
+
_iterator27.f();
|
|
2178
2795
|
}
|
|
2179
2796
|
}
|
|
2180
2797
|
} catch (err) {
|
|
2181
|
-
|
|
2798
|
+
_iterator26.e(err);
|
|
2182
2799
|
} finally {
|
|
2183
|
-
|
|
2800
|
+
_iterator26.f();
|
|
2184
2801
|
}
|
|
2185
|
-
return _toConsumableArray(groups.entries()).filter(function (
|
|
2186
|
-
var _ref5 = _slicedToArray(_ref4, 2),
|
|
2187
|
-
group = _ref5[1];
|
|
2188
|
-
return group.length > 1;
|
|
2189
|
-
}).slice(0, 20).map(function (_ref6) {
|
|
2802
|
+
return _toConsumableArray(groups.entries()).filter(function (_ref6) {
|
|
2190
2803
|
var _ref7 = _slicedToArray(_ref6, 2),
|
|
2191
|
-
key = _ref7[0],
|
|
2192
2804
|
group = _ref7[1];
|
|
2805
|
+
return group.length > 1;
|
|
2806
|
+
}).slice(0, 20).map(function (_ref8) {
|
|
2807
|
+
var _ref9 = _slicedToArray(_ref8, 2),
|
|
2808
|
+
key = _ref9[0],
|
|
2809
|
+
group = _ref9[1];
|
|
2193
2810
|
return {
|
|
2194
2811
|
key: key,
|
|
2195
2812
|
count: group.length,
|
|
2196
2813
|
orders: group.map(function (order) {
|
|
2197
|
-
var _order$
|
|
2814
|
+
var _order$order_id4, _external_sale_number4, _shop_order_number, _shop_full_order_numb, _order$need_sync, _order$is_draft_order;
|
|
2198
2815
|
return {
|
|
2199
|
-
order_id: (_order$
|
|
2200
|
-
external_sale_number: (
|
|
2816
|
+
order_id: (_order$order_id4 = order.order_id) !== null && _order$order_id4 !== void 0 ? _order$order_id4 : null,
|
|
2817
|
+
external_sale_number: (_external_sale_number4 = order.external_sale_number) !== null && _external_sale_number4 !== void 0 ? _external_sale_number4 : null,
|
|
2201
2818
|
shop_order_number: (_shop_order_number = order.shop_order_number) !== null && _shop_order_number !== void 0 ? _shop_order_number : null,
|
|
2202
2819
|
shop_full_order_number: (_shop_full_order_numb = order.shop_full_order_number) !== null && _shop_full_order_numb !== void 0 ? _shop_full_order_numb : null,
|
|
2203
|
-
need_sync: (_order$need_sync = order.need_sync) !== null && _order$need_sync !== void 0 ? _order$need_sync : null
|
|
2820
|
+
need_sync: (_order$need_sync = order.need_sync) !== null && _order$need_sync !== void 0 ? _order$need_sync : null,
|
|
2821
|
+
is_draft_order: (_order$is_draft_order = order.is_draft_order) !== null && _order$is_draft_order !== void 0 ? _order$is_draft_order : null
|
|
2204
2822
|
};
|
|
2205
2823
|
})
|
|
2206
2824
|
};
|
|
@@ -2222,11 +2840,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2222
2840
|
value: function compactOrderListByIdentity(orders, source) {
|
|
2223
2841
|
var list = [];
|
|
2224
2842
|
var removedCount = 0;
|
|
2225
|
-
var
|
|
2226
|
-
|
|
2843
|
+
var _iterator28 = _createForOfIteratorHelper(orders),
|
|
2844
|
+
_step28;
|
|
2227
2845
|
try {
|
|
2228
|
-
for (
|
|
2229
|
-
var order =
|
|
2846
|
+
for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
|
|
2847
|
+
var order = _step28.value;
|
|
2230
2848
|
var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, "".concat(source, ".order"));
|
|
2231
2849
|
var matchIndex = this.findOrderIndexByIdentity(list, normalizedOrder);
|
|
2232
2850
|
if (matchIndex < 0) {
|
|
@@ -2237,9 +2855,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2237
2855
|
removedCount += 1;
|
|
2238
2856
|
}
|
|
2239
2857
|
} catch (err) {
|
|
2240
|
-
|
|
2858
|
+
_iterator28.e(err);
|
|
2241
2859
|
} finally {
|
|
2242
|
-
|
|
2860
|
+
_iterator28.f();
|
|
2243
2861
|
}
|
|
2244
2862
|
if (removedCount > 0) {
|
|
2245
2863
|
this.logWarning('订单列表重复项已压缩', {
|
|
@@ -2337,35 +2955,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2337
2955
|
}, {
|
|
2338
2956
|
key: "loadOrdersFromSQLite",
|
|
2339
2957
|
value: function () {
|
|
2340
|
-
var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2958
|
+
var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
2341
2959
|
var _this18 = this;
|
|
2342
2960
|
var orders;
|
|
2343
|
-
return _regeneratorRuntime().wrap(function
|
|
2344
|
-
while (1) switch (
|
|
2961
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
2962
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
2345
2963
|
case 0:
|
|
2346
2964
|
if (this.dbManager) {
|
|
2347
|
-
|
|
2965
|
+
_context20.next = 2;
|
|
2348
2966
|
break;
|
|
2349
2967
|
}
|
|
2350
|
-
return
|
|
2968
|
+
return _context20.abrupt("return", []);
|
|
2351
2969
|
case 2:
|
|
2352
|
-
|
|
2353
|
-
|
|
2970
|
+
_context20.prev = 2;
|
|
2971
|
+
_context20.next = 5;
|
|
2354
2972
|
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
2355
2973
|
case 5:
|
|
2356
|
-
orders =
|
|
2357
|
-
return
|
|
2974
|
+
orders = _context20.sent;
|
|
2975
|
+
return _context20.abrupt("return", (orders || []).map(function (order) {
|
|
2358
2976
|
return _this18.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
|
|
2359
2977
|
}));
|
|
2360
2978
|
case 9:
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
return
|
|
2979
|
+
_context20.prev = 9;
|
|
2980
|
+
_context20.t0 = _context20["catch"](2);
|
|
2981
|
+
return _context20.abrupt("return", []);
|
|
2364
2982
|
case 12:
|
|
2365
2983
|
case "end":
|
|
2366
|
-
return
|
|
2984
|
+
return _context20.stop();
|
|
2367
2985
|
}
|
|
2368
|
-
},
|
|
2986
|
+
}, _callee20, this, [[2, 9]]);
|
|
2369
2987
|
}));
|
|
2370
2988
|
function loadOrdersFromSQLite() {
|
|
2371
2989
|
return _loadOrdersFromSQLite.apply(this, arguments);
|
|
@@ -2377,13 +2995,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2377
2995
|
value: function isPendingSyncOrder(order) {
|
|
2378
2996
|
return Number(order === null || order === void 0 ? void 0 : order.need_sync) === 1;
|
|
2379
2997
|
}
|
|
2998
|
+
}, {
|
|
2999
|
+
key: "isDraftOrder",
|
|
3000
|
+
value: function isDraftOrder(order) {
|
|
3001
|
+
return Number(order === null || order === void 0 ? void 0 : order.is_draft_order) === 1;
|
|
3002
|
+
}
|
|
3003
|
+
}, {
|
|
3004
|
+
key: "shouldProtectDraftOrderFromIncoming",
|
|
3005
|
+
value: function shouldProtectDraftOrderFromIncoming(source) {
|
|
3006
|
+
return source !== 'checkoutSync';
|
|
3007
|
+
}
|
|
2380
3008
|
}, {
|
|
2381
3009
|
key: "normalizeRemoteSyncedOrder",
|
|
2382
3010
|
value: function normalizeRemoteSyncedOrder(order) {
|
|
2383
3011
|
var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, 'normalizeRemoteSyncedOrder');
|
|
2384
|
-
if (this.isPendingSyncOrder(normalizedOrder)) return normalizedOrder
|
|
3012
|
+
if (this.isPendingSyncOrder(normalizedOrder)) return _objectSpread(_objectSpread({}, normalizedOrder), {}, {
|
|
3013
|
+
is_draft_order: 0
|
|
3014
|
+
});
|
|
2385
3015
|
return _objectSpread(_objectSpread({}, normalizedOrder), {}, {
|
|
2386
|
-
need_sync: 0
|
|
3016
|
+
need_sync: 0,
|
|
3017
|
+
is_draft_order: 0
|
|
2387
3018
|
});
|
|
2388
3019
|
}
|
|
2389
3020
|
}, {
|
|
@@ -2393,25 +3024,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2393
3024
|
var merged = remoteOrders.map(function (order) {
|
|
2394
3025
|
return _this19.normalizeRemoteSyncedOrder(order);
|
|
2395
3026
|
});
|
|
2396
|
-
var
|
|
2397
|
-
|
|
3027
|
+
var _iterator29 = _createForOfIteratorHelper(existingOrders),
|
|
3028
|
+
_step29;
|
|
2398
3029
|
try {
|
|
2399
|
-
for (
|
|
2400
|
-
var rawOrder =
|
|
3030
|
+
for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
|
|
3031
|
+
var rawOrder = _step29.value;
|
|
2401
3032
|
var order = this.normalizeOrderCollectionsForIngress(rawOrder, 'mergeRemoteSnapshotWithPendingOrders.existingSQLite');
|
|
2402
|
-
if (!this.isPendingSyncOrder(order)) continue;
|
|
3033
|
+
if (!this.isPendingSyncOrder(order) && !this.isDraftOrder(order)) continue;
|
|
2403
3034
|
var matchIndex = this.findOrderIndexByIdentity(merged, order);
|
|
2404
3035
|
if (matchIndex >= 0) {
|
|
2405
|
-
|
|
3036
|
+
if (this.isDraftOrder(order)) {
|
|
3037
|
+
merged[matchIndex] = order;
|
|
3038
|
+
} else {
|
|
3039
|
+
merged[matchIndex] = this.mergeOrderRecords(order, merged[matchIndex]);
|
|
3040
|
+
}
|
|
2406
3041
|
continue;
|
|
2407
3042
|
}
|
|
2408
3043
|
if (!this.getOrderStorageKey(order)) continue;
|
|
2409
3044
|
merged.push(order);
|
|
2410
3045
|
}
|
|
2411
3046
|
} catch (err) {
|
|
2412
|
-
|
|
3047
|
+
_iterator29.e(err);
|
|
2413
3048
|
} finally {
|
|
2414
|
-
|
|
3049
|
+
_iterator29.f();
|
|
2415
3050
|
}
|
|
2416
3051
|
return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
|
|
2417
3052
|
}
|
|
@@ -2427,10 +3062,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2427
3062
|
}, {
|
|
2428
3063
|
key: "runInOrderSQLiteSaveQueue",
|
|
2429
3064
|
value: (function () {
|
|
2430
|
-
var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3065
|
+
var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(task) {
|
|
2431
3066
|
var queuedTask;
|
|
2432
|
-
return _regeneratorRuntime().wrap(function
|
|
2433
|
-
while (1) switch (
|
|
3067
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
3068
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
2434
3069
|
case 0:
|
|
2435
3070
|
queuedTask = this.orderSQLiteSaveQueue.then(task, task);
|
|
2436
3071
|
this.orderSQLiteSaveQueue = queuedTask.then(function () {
|
|
@@ -2438,14 +3073,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2438
3073
|
}, function () {
|
|
2439
3074
|
return undefined;
|
|
2440
3075
|
});
|
|
2441
|
-
return
|
|
3076
|
+
return _context21.abrupt("return", queuedTask);
|
|
2442
3077
|
case 3:
|
|
2443
3078
|
case "end":
|
|
2444
|
-
return
|
|
3079
|
+
return _context21.stop();
|
|
2445
3080
|
}
|
|
2446
|
-
},
|
|
3081
|
+
}, _callee21, this);
|
|
2447
3082
|
}));
|
|
2448
|
-
function runInOrderSQLiteSaveQueue(
|
|
3083
|
+
function runInOrderSQLiteSaveQueue(_x14) {
|
|
2449
3084
|
return _runInOrderSQLiteSaveQueue.apply(this, arguments);
|
|
2450
3085
|
}
|
|
2451
3086
|
return runInOrderSQLiteSaveQueue;
|
|
@@ -2460,56 +3095,70 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2460
3095
|
}, {
|
|
2461
3096
|
key: "patchOrdersInSQLite",
|
|
2462
3097
|
value: (function () {
|
|
2463
|
-
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3098
|
+
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(orders, source) {
|
|
2464
3099
|
var _this20 = this;
|
|
2465
3100
|
var mergeActions,
|
|
3101
|
+
options,
|
|
2466
3102
|
ordersSnapshot,
|
|
2467
3103
|
_this$filterRedundant2,
|
|
2468
3104
|
toWrite,
|
|
2469
3105
|
skipped,
|
|
2470
3106
|
compactedToWrite,
|
|
2471
|
-
|
|
2472
|
-
return _regeneratorRuntime().wrap(function
|
|
2473
|
-
while (1) switch (
|
|
3107
|
+
_args23 = arguments;
|
|
3108
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
3109
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
2474
3110
|
case 0:
|
|
2475
|
-
mergeActions =
|
|
2476
|
-
|
|
2477
|
-
|
|
3111
|
+
mergeActions = _args23.length > 2 && _args23[2] !== undefined ? _args23[2] : {};
|
|
3112
|
+
options = _args23.length > 3 && _args23[3] !== undefined ? _args23[3] : {};
|
|
3113
|
+
if (!(orders.length === 0)) {
|
|
3114
|
+
_context23.next = 4;
|
|
2478
3115
|
break;
|
|
2479
3116
|
}
|
|
2480
|
-
return
|
|
2481
|
-
case
|
|
3117
|
+
return _context23.abrupt("return");
|
|
3118
|
+
case 4:
|
|
3119
|
+
if (this.dbManager) {
|
|
3120
|
+
_context23.next = 8;
|
|
3121
|
+
break;
|
|
3122
|
+
}
|
|
3123
|
+
if (!options.throwOnError) {
|
|
3124
|
+
_context23.next = 7;
|
|
3125
|
+
break;
|
|
3126
|
+
}
|
|
3127
|
+
throw new Error('订单 SQLite 数据库未初始化');
|
|
3128
|
+
case 7:
|
|
3129
|
+
return _context23.abrupt("return");
|
|
3130
|
+
case 8:
|
|
2482
3131
|
ordersSnapshot = cloneDeep(orders).map(function (order) {
|
|
2483
3132
|
return _this20.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
|
|
2484
3133
|
}).filter(function (order) {
|
|
2485
3134
|
return _this20.getOrderStorageKey(order);
|
|
2486
3135
|
});
|
|
2487
3136
|
if (!(ordersSnapshot.length === 0)) {
|
|
2488
|
-
|
|
3137
|
+
_context23.next = 11;
|
|
2489
3138
|
break;
|
|
2490
3139
|
}
|
|
2491
|
-
return
|
|
2492
|
-
case
|
|
3140
|
+
return _context23.abrupt("return");
|
|
3141
|
+
case 11:
|
|
2493
3142
|
_this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
|
|
2494
3143
|
if (!(toWrite.length === 0)) {
|
|
2495
|
-
|
|
3144
|
+
_context23.next = 14;
|
|
2496
3145
|
break;
|
|
2497
3146
|
}
|
|
2498
|
-
return
|
|
2499
|
-
case
|
|
3147
|
+
return _context23.abrupt("return");
|
|
3148
|
+
case 14:
|
|
2500
3149
|
compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
|
|
2501
3150
|
if (!(compactedToWrite.length === 0)) {
|
|
2502
|
-
|
|
3151
|
+
_context23.next = 17;
|
|
2503
3152
|
break;
|
|
2504
3153
|
}
|
|
2505
|
-
return
|
|
2506
|
-
case
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2510
|
-
var writeMethod,
|
|
2511
|
-
return _regeneratorRuntime().wrap(function
|
|
2512
|
-
while (1) switch (
|
|
3154
|
+
return _context23.abrupt("return");
|
|
3155
|
+
case 17:
|
|
3156
|
+
_context23.prev = 17;
|
|
3157
|
+
_context23.next = 20;
|
|
3158
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
|
|
3159
|
+
var writeMethod, _iterator30, _step30, order;
|
|
3160
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
3161
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
2513
3162
|
case 0:
|
|
2514
3163
|
writeMethod = 'none';
|
|
2515
3164
|
_this20.logInfo('patchOrdersInSQLite-开始', {
|
|
@@ -2518,58 +3167,67 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2518
3167
|
dedupedCount: skipped.length
|
|
2519
3168
|
});
|
|
2520
3169
|
if (!(typeof _this20.dbManager.bulkUpdate === 'function')) {
|
|
2521
|
-
|
|
3170
|
+
_context22.next = 8;
|
|
2522
3171
|
break;
|
|
2523
3172
|
}
|
|
2524
3173
|
writeMethod = 'bulkUpdate';
|
|
2525
|
-
|
|
3174
|
+
_context22.next = 6;
|
|
2526
3175
|
return _this20.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2527
3176
|
case 6:
|
|
2528
|
-
|
|
3177
|
+
_context22.next = 37;
|
|
2529
3178
|
break;
|
|
2530
3179
|
case 8:
|
|
2531
3180
|
if (!(typeof _this20.dbManager.bulkAdd === 'function')) {
|
|
2532
|
-
|
|
3181
|
+
_context22.next = 14;
|
|
2533
3182
|
break;
|
|
2534
3183
|
}
|
|
2535
3184
|
writeMethod = 'bulkAdd';
|
|
2536
|
-
|
|
3185
|
+
_context22.next = 12;
|
|
2537
3186
|
return _this20.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2538
3187
|
case 12:
|
|
2539
|
-
|
|
3188
|
+
_context22.next = 37;
|
|
2540
3189
|
break;
|
|
2541
3190
|
case 14:
|
|
2542
3191
|
if (!(typeof _this20.dbManager.update === 'function')) {
|
|
2543
|
-
|
|
3192
|
+
_context22.next = 35;
|
|
2544
3193
|
break;
|
|
2545
3194
|
}
|
|
2546
3195
|
writeMethod = 'update';
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
3196
|
+
_iterator30 = _createForOfIteratorHelper(compactedToWrite);
|
|
3197
|
+
_context22.prev = 17;
|
|
3198
|
+
_iterator30.s();
|
|
2550
3199
|
case 19:
|
|
2551
|
-
if ((
|
|
2552
|
-
|
|
3200
|
+
if ((_step30 = _iterator30.n()).done) {
|
|
3201
|
+
_context22.next = 25;
|
|
2553
3202
|
break;
|
|
2554
3203
|
}
|
|
2555
|
-
order =
|
|
2556
|
-
|
|
3204
|
+
order = _step30.value;
|
|
3205
|
+
_context22.next = 23;
|
|
2557
3206
|
return _this20.dbManager.update(INDEXDB_STORE_NAME, order);
|
|
2558
3207
|
case 23:
|
|
2559
|
-
|
|
3208
|
+
_context22.next = 19;
|
|
2560
3209
|
break;
|
|
2561
3210
|
case 25:
|
|
2562
|
-
|
|
3211
|
+
_context22.next = 30;
|
|
2563
3212
|
break;
|
|
2564
3213
|
case 27:
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
3214
|
+
_context22.prev = 27;
|
|
3215
|
+
_context22.t0 = _context22["catch"](17);
|
|
3216
|
+
_iterator30.e(_context22.t0);
|
|
2568
3217
|
case 30:
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
return
|
|
3218
|
+
_context22.prev = 30;
|
|
3219
|
+
_iterator30.f();
|
|
3220
|
+
return _context22.finish(30);
|
|
2572
3221
|
case 33:
|
|
3222
|
+
_context22.next = 37;
|
|
3223
|
+
break;
|
|
3224
|
+
case 35:
|
|
3225
|
+
if (!options.throwOnError) {
|
|
3226
|
+
_context22.next = 37;
|
|
3227
|
+
break;
|
|
3228
|
+
}
|
|
3229
|
+
throw new Error('订单 SQLite 数据库不支持写入');
|
|
3230
|
+
case 37:
|
|
2573
3231
|
_this20.recordRecentSqliteWrite(source, compactedToWrite);
|
|
2574
3232
|
_this20.logInfo('patchOrdersInSQLite-完成', {
|
|
2575
3233
|
source: source,
|
|
@@ -2577,29 +3235,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2577
3235
|
writeMethod: writeMethod,
|
|
2578
3236
|
dedupedCount: skipped.length
|
|
2579
3237
|
});
|
|
2580
|
-
case
|
|
3238
|
+
case 39:
|
|
2581
3239
|
case "end":
|
|
2582
|
-
return
|
|
3240
|
+
return _context22.stop();
|
|
2583
3241
|
}
|
|
2584
|
-
},
|
|
3242
|
+
}, _callee22, null, [[17, 27, 30, 33]]);
|
|
2585
3243
|
})));
|
|
2586
|
-
case
|
|
2587
|
-
|
|
3244
|
+
case 20:
|
|
3245
|
+
_context23.next = 27;
|
|
2588
3246
|
break;
|
|
2589
|
-
case
|
|
2590
|
-
|
|
2591
|
-
|
|
3247
|
+
case 22:
|
|
3248
|
+
_context23.prev = 22;
|
|
3249
|
+
_context23.t0 = _context23["catch"](17);
|
|
2592
3250
|
this.logError('增量保存订单到 SQLite 失败', {
|
|
2593
|
-
error:
|
|
3251
|
+
error: _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0),
|
|
2594
3252
|
orderCount: ordersSnapshot.length
|
|
2595
3253
|
});
|
|
2596
|
-
|
|
3254
|
+
if (!options.throwOnError) {
|
|
3255
|
+
_context23.next = 27;
|
|
3256
|
+
break;
|
|
3257
|
+
}
|
|
3258
|
+
throw _context23.t0;
|
|
3259
|
+
case 27:
|
|
2597
3260
|
case "end":
|
|
2598
|
-
return
|
|
3261
|
+
return _context23.stop();
|
|
2599
3262
|
}
|
|
2600
|
-
},
|
|
3263
|
+
}, _callee23, this, [[17, 22]]);
|
|
2601
3264
|
}));
|
|
2602
|
-
function patchOrdersInSQLite(
|
|
3265
|
+
function patchOrdersInSQLite(_x15, _x16) {
|
|
2603
3266
|
return _patchOrdersInSQLite.apply(this, arguments);
|
|
2604
3267
|
}
|
|
2605
3268
|
return patchOrdersInSQLite;
|
|
@@ -2614,26 +3277,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2614
3277
|
}, {
|
|
2615
3278
|
key: "updateOrderInSQLite",
|
|
2616
3279
|
value: (function () {
|
|
2617
|
-
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3280
|
+
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order, source) {
|
|
2618
3281
|
var _this21 = this;
|
|
2619
|
-
var
|
|
2620
|
-
|
|
2621
|
-
|
|
3282
|
+
var options,
|
|
3283
|
+
orderSnapshot,
|
|
3284
|
+
_orderSnapshot$order_3,
|
|
3285
|
+
_args25 = arguments;
|
|
3286
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
3287
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
2622
3288
|
case 0:
|
|
2623
|
-
|
|
2624
|
-
|
|
3289
|
+
options = _args25.length > 2 && _args25[2] !== undefined ? _args25[2] : {};
|
|
3290
|
+
if (this.getOrderStorageKey(order)) {
|
|
3291
|
+
_context25.next = 5;
|
|
2625
3292
|
break;
|
|
2626
3293
|
}
|
|
2627
|
-
|
|
2628
|
-
|
|
3294
|
+
if (!options.throwOnError) {
|
|
3295
|
+
_context25.next = 4;
|
|
3296
|
+
break;
|
|
3297
|
+
}
|
|
3298
|
+
throw new Error('订单缺少可用的 SQLite 存储主键');
|
|
3299
|
+
case 4:
|
|
3300
|
+
return _context25.abrupt("return");
|
|
3301
|
+
case 5:
|
|
3302
|
+
if (this.dbManager) {
|
|
3303
|
+
_context25.next = 9;
|
|
3304
|
+
break;
|
|
3305
|
+
}
|
|
3306
|
+
if (!options.throwOnError) {
|
|
3307
|
+
_context25.next = 8;
|
|
3308
|
+
break;
|
|
3309
|
+
}
|
|
3310
|
+
throw new Error('订单 SQLite 数据库未初始化');
|
|
3311
|
+
case 8:
|
|
3312
|
+
return _context25.abrupt("return");
|
|
3313
|
+
case 9:
|
|
2629
3314
|
orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3315
|
+
_context25.prev = 10;
|
|
3316
|
+
_context25.next = 13;
|
|
3317
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
|
|
2633
3318
|
var _orderSnapshot$order_, _orderSnapshot$order_2;
|
|
2634
3319
|
var writeMethod;
|
|
2635
|
-
return _regeneratorRuntime().wrap(function
|
|
2636
|
-
while (1) switch (
|
|
3320
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
3321
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
2637
3322
|
case 0:
|
|
2638
3323
|
writeMethod = 'none';
|
|
2639
3324
|
_this21.logInfo('updateOrderInSQLite-开始', {
|
|
@@ -2642,64 +3327,78 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2642
3327
|
storageKey: _this21.getOrderStorageKey(orderSnapshot)
|
|
2643
3328
|
});
|
|
2644
3329
|
if (!(typeof _this21.dbManager.update === 'function')) {
|
|
2645
|
-
|
|
3330
|
+
_context24.next = 8;
|
|
2646
3331
|
break;
|
|
2647
3332
|
}
|
|
2648
3333
|
writeMethod = 'update';
|
|
2649
|
-
|
|
3334
|
+
_context24.next = 6;
|
|
2650
3335
|
return _this21.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
|
|
2651
3336
|
case 6:
|
|
2652
|
-
|
|
3337
|
+
_context24.next = 22;
|
|
2653
3338
|
break;
|
|
2654
3339
|
case 8:
|
|
2655
3340
|
if (!(typeof _this21.dbManager.bulkUpdate === 'function')) {
|
|
2656
|
-
|
|
3341
|
+
_context24.next = 14;
|
|
2657
3342
|
break;
|
|
2658
3343
|
}
|
|
2659
3344
|
writeMethod = 'bulkUpdate';
|
|
2660
|
-
|
|
3345
|
+
_context24.next = 12;
|
|
2661
3346
|
return _this21.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2662
3347
|
case 12:
|
|
2663
|
-
|
|
3348
|
+
_context24.next = 22;
|
|
2664
3349
|
break;
|
|
2665
3350
|
case 14:
|
|
2666
3351
|
if (!(typeof _this21.dbManager.bulkAdd === 'function')) {
|
|
2667
|
-
|
|
3352
|
+
_context24.next = 20;
|
|
2668
3353
|
break;
|
|
2669
3354
|
}
|
|
2670
3355
|
writeMethod = 'bulkAdd';
|
|
2671
|
-
|
|
3356
|
+
_context24.next = 18;
|
|
2672
3357
|
return _this21.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2673
3358
|
case 18:
|
|
3359
|
+
_context24.next = 22;
|
|
3360
|
+
break;
|
|
3361
|
+
case 20:
|
|
3362
|
+
if (!options.throwOnError) {
|
|
3363
|
+
_context24.next = 22;
|
|
3364
|
+
break;
|
|
3365
|
+
}
|
|
3366
|
+
throw new Error('订单 SQLite 数据库不支持写入');
|
|
3367
|
+
case 22:
|
|
2674
3368
|
_this21.recordRecentSqliteWrite(source, [orderSnapshot]);
|
|
2675
3369
|
_this21.logInfo('updateOrderInSQLite-完成', {
|
|
2676
3370
|
source: source,
|
|
2677
3371
|
orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
|
|
2678
3372
|
writeMethod: writeMethod
|
|
2679
3373
|
});
|
|
2680
|
-
case
|
|
3374
|
+
case 24:
|
|
2681
3375
|
case "end":
|
|
2682
|
-
return
|
|
3376
|
+
return _context24.stop();
|
|
2683
3377
|
}
|
|
2684
|
-
},
|
|
3378
|
+
}, _callee24);
|
|
2685
3379
|
})));
|
|
2686
|
-
case
|
|
2687
|
-
|
|
3380
|
+
case 13:
|
|
3381
|
+
_context25.next = 20;
|
|
2688
3382
|
break;
|
|
2689
|
-
case
|
|
2690
|
-
|
|
2691
|
-
|
|
3383
|
+
case 15:
|
|
3384
|
+
_context25.prev = 15;
|
|
3385
|
+
_context25.t0 = _context25["catch"](10);
|
|
2692
3386
|
this.logError('单条保存订单到 SQLite 失败', {
|
|
2693
|
-
error:
|
|
3387
|
+
error: _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0),
|
|
2694
3388
|
orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
|
|
2695
3389
|
});
|
|
2696
|
-
|
|
3390
|
+
if (!options.throwOnError) {
|
|
3391
|
+
_context25.next = 20;
|
|
3392
|
+
break;
|
|
3393
|
+
}
|
|
3394
|
+
throw _context25.t0;
|
|
3395
|
+
case 20:
|
|
2697
3396
|
case "end":
|
|
2698
|
-
return
|
|
3397
|
+
return _context25.stop();
|
|
2699
3398
|
}
|
|
2700
|
-
},
|
|
3399
|
+
}, _callee25, this, [[10, 15]]);
|
|
2701
3400
|
}));
|
|
2702
|
-
function updateOrderInSQLite(
|
|
3401
|
+
function updateOrderInSQLite(_x17, _x18) {
|
|
2703
3402
|
return _updateOrderInSQLite.apply(this, arguments);
|
|
2704
3403
|
}
|
|
2705
3404
|
return updateOrderInSQLite;
|
|
@@ -2714,17 +3413,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2714
3413
|
}, {
|
|
2715
3414
|
key: "replaceOrdersSnapshotInSQLite",
|
|
2716
3415
|
value: (function () {
|
|
2717
|
-
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3416
|
+
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(orderList, source) {
|
|
2718
3417
|
var _this22 = this;
|
|
2719
3418
|
var remoteSnapshot, mergedSnapshot;
|
|
2720
|
-
return _regeneratorRuntime().wrap(function
|
|
2721
|
-
while (1) switch (
|
|
3419
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
3420
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
2722
3421
|
case 0:
|
|
2723
3422
|
if (this.dbManager) {
|
|
2724
|
-
|
|
3423
|
+
_context27.next = 2;
|
|
2725
3424
|
break;
|
|
2726
3425
|
}
|
|
2727
|
-
return
|
|
3426
|
+
return _context27.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
|
|
2728
3427
|
return _this22.normalizeRemoteSyncedOrder(order);
|
|
2729
3428
|
}), "".concat(source, ".snapshotNoDb")).list);
|
|
2730
3429
|
case 2:
|
|
@@ -2734,48 +3433,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2734
3433
|
mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
|
|
2735
3434
|
return _this22.normalizeRemoteSyncedOrder(order);
|
|
2736
3435
|
}), "".concat(source, ".remoteSnapshot")).list;
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3436
|
+
_context27.prev = 4;
|
|
3437
|
+
_context27.next = 7;
|
|
3438
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
|
|
2740
3439
|
var existingOrders, orderListSnapshot;
|
|
2741
|
-
return _regeneratorRuntime().wrap(function
|
|
2742
|
-
while (1) switch (
|
|
3440
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
3441
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
2743
3442
|
case 0:
|
|
2744
3443
|
if (!(typeof _this22.dbManager.getAll === 'function')) {
|
|
2745
|
-
|
|
3444
|
+
_context26.next = 6;
|
|
2746
3445
|
break;
|
|
2747
3446
|
}
|
|
2748
|
-
|
|
3447
|
+
_context26.next = 3;
|
|
2749
3448
|
return _this22.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
2750
3449
|
case 3:
|
|
2751
|
-
|
|
2752
|
-
|
|
3450
|
+
_context26.t0 = _context26.sent;
|
|
3451
|
+
_context26.next = 7;
|
|
2753
3452
|
break;
|
|
2754
3453
|
case 6:
|
|
2755
|
-
|
|
3454
|
+
_context26.t0 = [];
|
|
2756
3455
|
case 7:
|
|
2757
|
-
existingOrders =
|
|
3456
|
+
existingOrders = _context26.t0;
|
|
2758
3457
|
orderListSnapshot = _this22.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, existingOrders || []);
|
|
2759
3458
|
mergedSnapshot = _this22.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
|
|
2760
3459
|
_this22.logInfo('replaceOrdersSnapshotInSQLite-开始', {
|
|
2761
3460
|
source: source,
|
|
2762
3461
|
count: mergedSnapshot.length,
|
|
2763
3462
|
remoteCount: remoteSnapshot.length,
|
|
2764
|
-
|
|
3463
|
+
preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length
|
|
2765
3464
|
});
|
|
2766
|
-
|
|
3465
|
+
_context26.next = 13;
|
|
2767
3466
|
return _this22.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2768
3467
|
case 13:
|
|
2769
3468
|
_this22.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
|
|
2770
3469
|
count: mergedSnapshot.length
|
|
2771
3470
|
});
|
|
2772
3471
|
if (!(mergedSnapshot.length === 0)) {
|
|
2773
|
-
|
|
3472
|
+
_context26.next = 16;
|
|
2774
3473
|
break;
|
|
2775
3474
|
}
|
|
2776
|
-
return
|
|
3475
|
+
return _context26.abrupt("return");
|
|
2777
3476
|
case 16:
|
|
2778
|
-
|
|
3477
|
+
_context26.next = 18;
|
|
2779
3478
|
return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
|
|
2780
3479
|
case 18:
|
|
2781
3480
|
_this22.recordRecentSqliteWrite(source, mergedSnapshot);
|
|
@@ -2785,29 +3484,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2785
3484
|
});
|
|
2786
3485
|
case 20:
|
|
2787
3486
|
case "end":
|
|
2788
|
-
return
|
|
3487
|
+
return _context26.stop();
|
|
2789
3488
|
}
|
|
2790
|
-
},
|
|
3489
|
+
}, _callee26);
|
|
2791
3490
|
})));
|
|
2792
3491
|
case 7:
|
|
2793
|
-
|
|
3492
|
+
_context27.next = 12;
|
|
2794
3493
|
break;
|
|
2795
3494
|
case 9:
|
|
2796
|
-
|
|
2797
|
-
|
|
3495
|
+
_context27.prev = 9;
|
|
3496
|
+
_context27.t0 = _context27["catch"](4);
|
|
2798
3497
|
this.logError('全量保存订单到 SQLite 失败', {
|
|
2799
|
-
error:
|
|
3498
|
+
error: _context27.t0 instanceof Error ? _context27.t0.message : String(_context27.t0),
|
|
2800
3499
|
orderList: remoteSnapshot.length
|
|
2801
3500
|
});
|
|
2802
3501
|
case 12:
|
|
2803
|
-
return
|
|
3502
|
+
return _context27.abrupt("return", mergedSnapshot);
|
|
2804
3503
|
case 13:
|
|
2805
3504
|
case "end":
|
|
2806
|
-
return
|
|
3505
|
+
return _context27.stop();
|
|
2807
3506
|
}
|
|
2808
|
-
},
|
|
3507
|
+
}, _callee27, this, [[4, 9]]);
|
|
2809
3508
|
}));
|
|
2810
|
-
function replaceOrdersSnapshotInSQLite(
|
|
3509
|
+
function replaceOrdersSnapshotInSQLite(_x19, _x20) {
|
|
2811
3510
|
return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
|
|
2812
3511
|
}
|
|
2813
3512
|
return replaceOrdersSnapshotInSQLite;
|
|
@@ -2822,38 +3521,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2822
3521
|
}, {
|
|
2823
3522
|
key: "clear",
|
|
2824
3523
|
value: (function () {
|
|
2825
|
-
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3524
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
|
|
2826
3525
|
var _this23 = this;
|
|
2827
|
-
return _regeneratorRuntime().wrap(function
|
|
2828
|
-
while (1) switch (
|
|
3526
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
3527
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
2829
3528
|
case 0:
|
|
2830
3529
|
this.store.list = [];
|
|
2831
3530
|
this.store.map = new Map();
|
|
2832
3531
|
if (!this.dbManager) {
|
|
2833
|
-
|
|
3532
|
+
_context29.next = 5;
|
|
2834
3533
|
break;
|
|
2835
3534
|
}
|
|
2836
|
-
|
|
2837
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2838
|
-
return _regeneratorRuntime().wrap(function
|
|
2839
|
-
while (1) switch (
|
|
3535
|
+
_context29.next = 5;
|
|
3536
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
|
|
3537
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
3538
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
2840
3539
|
case 0:
|
|
2841
|
-
|
|
3540
|
+
_context28.next = 2;
|
|
2842
3541
|
return _this23.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2843
3542
|
case 2:
|
|
2844
3543
|
case "end":
|
|
2845
|
-
return
|
|
3544
|
+
return _context28.stop();
|
|
2846
3545
|
}
|
|
2847
|
-
},
|
|
3546
|
+
}, _callee28);
|
|
2848
3547
|
})));
|
|
2849
3548
|
case 5:
|
|
2850
3549
|
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
|
|
2851
3550
|
this.emitOrdersChanged([], 'clear');
|
|
2852
3551
|
case 7:
|
|
2853
3552
|
case "end":
|
|
2854
|
-
return
|
|
3553
|
+
return _context29.stop();
|
|
2855
3554
|
}
|
|
2856
|
-
},
|
|
3555
|
+
}, _callee29, this);
|
|
2857
3556
|
}));
|
|
2858
3557
|
function clear() {
|
|
2859
3558
|
return _clear.apply(this, arguments);
|