@pisell/pisellos 2.2.263 → 2.2.265
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 +26 -0
- package/dist/modules/Order/payment-utils.js +225 -0
- package/dist/modules/Order/types.d.ts +33 -1
- package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
- package/dist/modules/Order/utils.js +8 -5
- 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 +16 -0
- package/dist/server/index.js +1940 -1043
- package/dist/server/modules/order/index.d.ts +49 -4
- package/dist/server/modules/order/index.js +1577 -698
- 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 +653 -340
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +2 -1
- package/dist/solution/Sales/index.d.ts +1 -0
- package/dist/solution/Sales/index.js +10 -2
- 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 +49 -0
- 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 +26 -0
- package/lib/modules/Order/payment-utils.js +224 -0
- package/lib/modules/Order/types.d.ts +33 -1
- package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
- package/lib/modules/Order/utils.js +5 -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 +16 -0
- package/lib/server/index.js +670 -18
- package/lib/server/modules/order/index.d.ts +49 -4
- package/lib/server/modules/order/index.js +657 -66
- 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 +193 -9
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +2 -1
- package/lib/solution/Sales/index.d.ts +1 -0
- package/lib/solution/Sales/index.js +5 -3
- package/lib/utils/payment-number.d.ts +9 -0
- package/lib/utils/payment-number.js +64 -0
- package/package.json +1 -1
|
@@ -7,11 +7,11 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
|
|
|
7
7
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
8
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
9
9
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
10
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
10
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
13
11
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
12
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
15
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
16
16
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
17
17
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -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 { getOrderPaymentIdentityKeys, isIdentifiedPendingOrderPayment, isPendingOrderPayment, 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
|
* 合并热路径全表去重自检开关:默认关闭。
|
|
@@ -56,6 +57,7 @@ var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPen
|
|
|
56
57
|
* 仅用于排查增量身份索引是否遗漏了重复订单,不应在生产常开。
|
|
57
58
|
*/
|
|
58
59
|
var ORDER_MERGE_SELF_CHECK = false;
|
|
60
|
+
var PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER = '__pisell_os_pending_payment_without_unique_number__';
|
|
59
61
|
var ORDER_AUTHORITATIVE_COLLECTION_FIELDS = ['products', 'bookings', 'payments'];
|
|
60
62
|
var ORDER_COLLECTION_KIND_BY_FIELD = {
|
|
61
63
|
products: 'product',
|
|
@@ -138,8 +140,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
138
140
|
key: "initialize",
|
|
139
141
|
value: function () {
|
|
140
142
|
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(core, options) {
|
|
141
|
-
var _options$initialState
|
|
142
|
-
_this3 = this;
|
|
143
|
+
var _options$initialState;
|
|
143
144
|
var appPlugin, app;
|
|
144
145
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
145
146
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -156,9 +157,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
156
157
|
this.updateCreateStore();
|
|
157
158
|
}
|
|
158
159
|
if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
|
|
159
|
-
this.store.list = options.initialState.list
|
|
160
|
-
return _this3.normalizeOrderForMemoryList(order);
|
|
161
|
-
});
|
|
160
|
+
this.store.list = this.normalizeOrdersForMemoryList(options.initialState.list, 'initialState');
|
|
162
161
|
this.syncOrdersMap();
|
|
163
162
|
this.emitOrdersChanged([], 'initialState');
|
|
164
163
|
} else {
|
|
@@ -247,7 +246,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
247
246
|
}, {
|
|
248
247
|
key: "normalizeOrderCollectionsForIngress",
|
|
249
248
|
value: function normalizeOrderCollectionsForIngress(order, source) {
|
|
250
|
-
var
|
|
249
|
+
var sourceOrder = cloneDeep(order);
|
|
250
|
+
var sourceOrderRecord = sourceOrder;
|
|
251
|
+
if (Array.isArray(sourceOrderRecord.payments)) {
|
|
252
|
+
sourceOrderRecord.payments = sourceOrderRecord.payments.map(function (payment) {
|
|
253
|
+
if (!isPendingOrderPayment(payment) || getOrderPaymentIdentityKeys(payment).some(function (key) {
|
|
254
|
+
return key.startsWith('unique_payment_number:');
|
|
255
|
+
})) {
|
|
256
|
+
return payment;
|
|
257
|
+
}
|
|
258
|
+
return _objectSpread(_objectSpread({}, payment), {}, _defineProperty({}, PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER, true));
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
var result = normalizeOrderCollections(sourceOrder);
|
|
262
|
+
var normalizedOrderRecord = result.order;
|
|
263
|
+
if (Array.isArray(normalizedOrderRecord.payments)) {
|
|
264
|
+
normalizedOrderRecord.payments = normalizedOrderRecord.payments.map(function (payment) {
|
|
265
|
+
if (!(payment !== null && payment !== void 0 && payment[PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER])) return payment;
|
|
266
|
+
var nextPayment = _objectSpread({}, payment);
|
|
267
|
+
var metadata = _objectSpread({}, nextPayment.metadata || {});
|
|
268
|
+
delete metadata.unique_payment_number;
|
|
269
|
+
delete nextPayment[PENDING_PAYMENT_WITHOUT_UNIQUE_MARKER];
|
|
270
|
+
nextPayment.metadata = metadata;
|
|
271
|
+
return nextPayment;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
251
274
|
var kinds = ['product', 'booking', 'payment'];
|
|
252
275
|
var hasChanges = kinds.some(function (kind) {
|
|
253
276
|
var stats = result.stats[kind];
|
|
@@ -291,8 +314,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
291
314
|
key: "mergeAuthoritativeOrderCollection",
|
|
292
315
|
value: function mergeAuthoritativeOrderCollection(field, existing, incoming) {
|
|
293
316
|
var uidRemaps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
317
|
+
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
294
318
|
var kind = ORDER_COLLECTION_KIND_BY_FIELD[field];
|
|
295
319
|
var existingItems = Array.isArray(existing) ? existing : [];
|
|
320
|
+
if (field === 'payments' && options.preserveIdentifiedPendingPayments) {
|
|
321
|
+
return mergeOrderPaymentListsByIdentity(existingItems, incoming, {
|
|
322
|
+
preserveUnmatchedExistingWhen: isIdentifiedPendingOrderPayment
|
|
323
|
+
});
|
|
324
|
+
}
|
|
296
325
|
return incoming.map(function (incomingItem) {
|
|
297
326
|
var existingItem = existingItems.find(function (item) {
|
|
298
327
|
return isSameOrderCollectionItem(kind, item, incomingItem);
|
|
@@ -601,62 +630,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
601
630
|
}, {
|
|
602
631
|
key: "preload",
|
|
603
632
|
value: function () {
|
|
604
|
-
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
605
|
-
var
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
633
|
+
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
634
|
+
var orders;
|
|
635
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
636
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
609
637
|
case 0:
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
// if (cachedOrders.length > 0 && hasPulledInCurrentWindow) {
|
|
613
|
-
// this.store.list = cloneDeep(cachedOrders)
|
|
614
|
-
// this.syncOrdersMap()
|
|
615
|
-
// this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list)
|
|
616
|
-
// return
|
|
617
|
-
// }
|
|
618
|
-
// if (hasPulledInCurrentWindow) {
|
|
619
|
-
// this.logInfo('当天已完成全量订单拉取,跳过本次全量拉取', {
|
|
620
|
-
// lastFullFetchAt: this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY),
|
|
621
|
-
// })
|
|
622
|
-
// return
|
|
623
|
-
// }
|
|
624
|
-
getData = /*#__PURE__*/function () {
|
|
625
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
626
|
-
var orders;
|
|
627
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
628
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
629
|
-
case 0:
|
|
630
|
-
_context3.next = 2;
|
|
631
|
-
return _this4.loadOrdersByServer();
|
|
632
|
-
case 2:
|
|
633
|
-
orders = _context3.sent;
|
|
634
|
-
if (!(orders.length === 0)) {
|
|
635
|
-
_context3.next = 5;
|
|
636
|
-
break;
|
|
637
|
-
}
|
|
638
|
-
return _context3.abrupt("return");
|
|
639
|
-
case 5:
|
|
640
|
-
_this4.store.list = cloneDeep(orders);
|
|
641
|
-
_this4.syncOrdersMap();
|
|
642
|
-
_this4.emitOrdersChanged([], 'preload');
|
|
643
|
-
_this4.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
644
|
-
case 9:
|
|
645
|
-
case "end":
|
|
646
|
-
return _context3.stop();
|
|
647
|
-
}
|
|
648
|
-
}, _callee3);
|
|
649
|
-
}));
|
|
650
|
-
return function getData() {
|
|
651
|
-
return _ref.apply(this, arguments);
|
|
652
|
-
};
|
|
653
|
-
}();
|
|
654
|
-
getData();
|
|
638
|
+
_context3.next = 2;
|
|
639
|
+
return this.loadOrdersByServer();
|
|
655
640
|
case 2:
|
|
641
|
+
orders = _context3.sent;
|
|
642
|
+
this.store.list = cloneDeep(orders);
|
|
643
|
+
this.syncOrdersMap();
|
|
644
|
+
_context3.next = 7;
|
|
645
|
+
return this.emitOrdersChanged([], 'preload');
|
|
646
|
+
case 7:
|
|
647
|
+
_context3.next = 9;
|
|
648
|
+
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
649
|
+
case 9:
|
|
656
650
|
case "end":
|
|
657
|
-
return
|
|
651
|
+
return _context3.stop();
|
|
658
652
|
}
|
|
659
|
-
},
|
|
653
|
+
}, _callee3, this);
|
|
660
654
|
}));
|
|
661
655
|
function preload() {
|
|
662
656
|
return _preload.apply(this, arguments);
|
|
@@ -680,67 +674,125 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
680
674
|
value: function getOrderByOrderId(orderId) {
|
|
681
675
|
return this.store.map.get(this.getIdKey(orderId));
|
|
682
676
|
}
|
|
677
|
+
}, {
|
|
678
|
+
key: "buildLocalPaymentOrderLogContext",
|
|
679
|
+
value: function buildLocalPaymentOrderLogContext(order) {
|
|
680
|
+
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;
|
|
681
|
+
if (!order) return {};
|
|
682
|
+
return {
|
|
683
|
+
order_id: (_order$order_id3 = order.order_id) !== null && _order$order_id3 !== void 0 ? _order$order_id3 : null,
|
|
684
|
+
external_sale_number: (_order$external_sale_ = order.external_sale_number) !== null && _order$external_sale_ !== void 0 ? _order$external_sale_ : null,
|
|
685
|
+
order_number: (_order$order_number = order.order_number) !== null && _order$order_number !== void 0 ? _order$order_number : null,
|
|
686
|
+
shop_order_number: (_order$shop_order_num = order.shop_order_number) !== null && _order$shop_order_num !== void 0 ? _order$shop_order_num : null,
|
|
687
|
+
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,
|
|
688
|
+
order_status: (_order$status = order.status) !== null && _order$status !== void 0 ? _order$status : null,
|
|
689
|
+
payment_status: (_order$payment_status = order.payment_status) !== null && _order$payment_status !== void 0 ? _order$payment_status : null,
|
|
690
|
+
is_draft_order: Number(order.is_draft_order || 0),
|
|
691
|
+
need_sync: Number(order.need_sync || 0),
|
|
692
|
+
platform: (_order$platform = order.platform) !== null && _order$platform !== void 0 ? _order$platform : null,
|
|
693
|
+
business_code: (_order$business_code = order.business_code) !== null && _order$business_code !== void 0 ? _order$business_code : null,
|
|
694
|
+
order_sales_channel: (_order$order_sales_ch = order.order_sales_channel) !== null && _order$order_sales_ch !== void 0 ? _order$order_sales_ch : null,
|
|
695
|
+
sales_channel: (_order$sales_channel = order.sales_channel) !== null && _order$sales_channel !== void 0 ? _order$sales_channel : null,
|
|
696
|
+
order_type: (_order$type = order.type) !== null && _order$type !== void 0 ? _order$type : null,
|
|
697
|
+
payments_count: Array.isArray(order.payments) ? order.payments.length : 0
|
|
698
|
+
};
|
|
699
|
+
}
|
|
683
700
|
}, {
|
|
684
701
|
key: "getLocalOrderFromMemoryByLookup",
|
|
685
702
|
value: function getLocalOrderFromMemoryByLookup(lookup) {
|
|
686
|
-
var
|
|
703
|
+
var _this3 = this;
|
|
687
704
|
var key = this.getIdKey(lookup);
|
|
688
705
|
var memoryOrderById = this.store.map.get(key);
|
|
689
706
|
if (memoryOrderById) return memoryOrderById;
|
|
690
707
|
var memoryOrder = this.store.list.find(function (order) {
|
|
691
|
-
return
|
|
708
|
+
return _this3.isOrderLookupMatch(order, key);
|
|
692
709
|
});
|
|
693
710
|
return memoryOrder || null;
|
|
694
711
|
}
|
|
695
712
|
}, {
|
|
696
713
|
key: "getLocalOrderByLookup",
|
|
697
714
|
value: function () {
|
|
698
|
-
var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
699
|
-
var
|
|
700
|
-
var
|
|
701
|
-
|
|
702
|
-
|
|
715
|
+
var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(lookup) {
|
|
716
|
+
var _this4 = this;
|
|
717
|
+
var options,
|
|
718
|
+
key,
|
|
719
|
+
logContext,
|
|
720
|
+
memoryOrderById,
|
|
721
|
+
memoryOrder,
|
|
722
|
+
orders,
|
|
723
|
+
localOrder,
|
|
724
|
+
normalizedOrder,
|
|
725
|
+
_args4 = arguments;
|
|
726
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
727
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
703
728
|
case 0:
|
|
729
|
+
options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
|
|
704
730
|
key = this.getIdKey(lookup);
|
|
731
|
+
logContext = {
|
|
732
|
+
operation_id: options.operationId,
|
|
733
|
+
lookup: key,
|
|
734
|
+
memory_order_count: this.store.list.length
|
|
735
|
+
};
|
|
736
|
+
if (options.operationId) {
|
|
737
|
+
this.logInfo('getLocalOrderByLookup-localPayment-开始', logContext);
|
|
738
|
+
}
|
|
705
739
|
memoryOrderById = this.store.map.get(key);
|
|
706
740
|
if (!memoryOrderById) {
|
|
707
|
-
|
|
741
|
+
_context4.next = 8;
|
|
708
742
|
break;
|
|
709
743
|
}
|
|
710
|
-
|
|
711
|
-
|
|
744
|
+
if (options.operationId) {
|
|
745
|
+
this.logInfo('getLocalOrderByLookup-localPayment-命中内存映射', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrderById)));
|
|
746
|
+
}
|
|
747
|
+
return _context4.abrupt("return", memoryOrderById);
|
|
748
|
+
case 8:
|
|
712
749
|
memoryOrder = this.store.list.find(function (order) {
|
|
713
|
-
return
|
|
750
|
+
return _this4.isOrderLookupMatch(order, key);
|
|
714
751
|
});
|
|
715
752
|
if (!memoryOrder) {
|
|
716
|
-
|
|
753
|
+
_context4.next = 12;
|
|
717
754
|
break;
|
|
718
755
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
756
|
+
if (options.operationId) {
|
|
757
|
+
this.logInfo('getLocalOrderByLookup-localPayment-命中内存列表', _objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(memoryOrder)));
|
|
758
|
+
}
|
|
759
|
+
return _context4.abrupt("return", memoryOrder);
|
|
760
|
+
case 12:
|
|
761
|
+
if (options.operationId) {
|
|
762
|
+
this.logInfo('getLocalOrderByLookup-localPayment-开始读取SQLite', logContext);
|
|
763
|
+
}
|
|
764
|
+
_context4.next = 15;
|
|
722
765
|
return this.loadOrdersFromSQLite();
|
|
723
|
-
case
|
|
724
|
-
orders =
|
|
766
|
+
case 15:
|
|
767
|
+
orders = _context4.sent;
|
|
725
768
|
localOrder = orders.find(function (order) {
|
|
726
|
-
return
|
|
769
|
+
return _this4.isOrderLookupMatch(order, key);
|
|
727
770
|
});
|
|
728
771
|
if (localOrder) {
|
|
729
|
-
|
|
772
|
+
_context4.next = 20;
|
|
730
773
|
break;
|
|
731
774
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
}
|
|
775
|
+
if (options.operationId) {
|
|
776
|
+
this.logWarning('getLocalOrderByLookup-localPayment-SQLite未命中', _objectSpread(_objectSpread({}, logContext), {}, {
|
|
777
|
+
sqlite_order_count: orders.length
|
|
778
|
+
}));
|
|
779
|
+
}
|
|
780
|
+
return _context4.abrupt("return", null);
|
|
781
|
+
case 20:
|
|
782
|
+
this.store.list = this.normalizeOrdersForMemoryList(orders, 'getLocalOrderByLookup.sqliteMemory');
|
|
737
783
|
this.syncOrdersMap();
|
|
738
|
-
|
|
739
|
-
|
|
784
|
+
normalizedOrder = this.normalizeOrderForMemoryList(localOrder);
|
|
785
|
+
if (options.operationId) {
|
|
786
|
+
this.logInfo('getLocalOrderByLookup-localPayment-SQLite命中', _objectSpread(_objectSpread({}, logContext), {}, {
|
|
787
|
+
sqlite_order_count: orders.length
|
|
788
|
+
}, this.buildLocalPaymentOrderLogContext(normalizedOrder)));
|
|
789
|
+
}
|
|
790
|
+
return _context4.abrupt("return", normalizedOrder);
|
|
791
|
+
case 25:
|
|
740
792
|
case "end":
|
|
741
|
-
return
|
|
793
|
+
return _context4.stop();
|
|
742
794
|
}
|
|
743
|
-
},
|
|
795
|
+
}, _callee4, this);
|
|
744
796
|
}));
|
|
745
797
|
function getLocalOrderByLookup(_x3) {
|
|
746
798
|
return _getLocalOrderByLookup.apply(this, arguments);
|
|
@@ -748,66 +800,254 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
748
800
|
return getLocalOrderByLookup;
|
|
749
801
|
}()
|
|
750
802
|
}, {
|
|
751
|
-
key: "
|
|
803
|
+
key: "getLocalPayment",
|
|
804
|
+
value: function () {
|
|
805
|
+
var _getLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
|
|
806
|
+
var logContext, order, payments, match;
|
|
807
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
808
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
809
|
+
case 0:
|
|
810
|
+
logContext = {
|
|
811
|
+
operation_id: params.operationId,
|
|
812
|
+
sale_id: params.saleId,
|
|
813
|
+
payment_number: params.paymentNumber
|
|
814
|
+
};
|
|
815
|
+
this.logInfo('getLocalPayment-开始', logContext);
|
|
816
|
+
_context5.prev = 2;
|
|
817
|
+
_context5.next = 5;
|
|
818
|
+
return this.getLocalOrderByLookup(params.saleId, {
|
|
819
|
+
operationId: params.operationId
|
|
820
|
+
});
|
|
821
|
+
case 5:
|
|
822
|
+
order = _context5.sent;
|
|
823
|
+
if (order) {
|
|
824
|
+
_context5.next = 9;
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
this.logWarning('getLocalPayment-订单未命中', logContext);
|
|
828
|
+
return _context5.abrupt("return", null);
|
|
829
|
+
case 9:
|
|
830
|
+
payments = order.payments || [];
|
|
831
|
+
match = resolveOrderPaymentIdentity(payments, params.paymentNumber, 'compat');
|
|
832
|
+
if (match) {
|
|
833
|
+
_context5.next = 14;
|
|
834
|
+
break;
|
|
835
|
+
}
|
|
836
|
+
this.logWarning('getLocalPayment-支付项未命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
|
|
837
|
+
payments: payments
|
|
838
|
+
}));
|
|
839
|
+
return _context5.abrupt("return", null);
|
|
840
|
+
case 14:
|
|
841
|
+
this.logInfo('getLocalPayment-支付项命中', _objectSpread(_objectSpread(_objectSpread({}, logContext), this.buildLocalPaymentOrderLogContext(order)), {}, {
|
|
842
|
+
matched_by: match.matchedBy,
|
|
843
|
+
payment_index: match.index,
|
|
844
|
+
payment: match.payment
|
|
845
|
+
}));
|
|
846
|
+
return _context5.abrupt("return", {
|
|
847
|
+
order: order,
|
|
848
|
+
payment: match.payment,
|
|
849
|
+
paymentIndex: match.index,
|
|
850
|
+
matchedBy: match.matchedBy
|
|
851
|
+
});
|
|
852
|
+
case 18:
|
|
853
|
+
_context5.prev = 18;
|
|
854
|
+
_context5.t0 = _context5["catch"](2);
|
|
855
|
+
this.logError('getLocalPayment-查询失败', _objectSpread(_objectSpread({}, logContext), {}, {
|
|
856
|
+
error: _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0)
|
|
857
|
+
}));
|
|
858
|
+
throw _context5.t0;
|
|
859
|
+
case 22:
|
|
860
|
+
case "end":
|
|
861
|
+
return _context5.stop();
|
|
862
|
+
}
|
|
863
|
+
}, _callee5, this, [[2, 18]]);
|
|
864
|
+
}));
|
|
865
|
+
function getLocalPayment(_x4) {
|
|
866
|
+
return _getLocalPayment.apply(this, arguments);
|
|
867
|
+
}
|
|
868
|
+
return getLocalPayment;
|
|
869
|
+
}()
|
|
870
|
+
}, {
|
|
871
|
+
key: "updateLocalPayment",
|
|
752
872
|
value: function () {
|
|
753
|
-
var
|
|
754
|
-
var
|
|
755
|
-
_this7 = this;
|
|
756
|
-
var orderList, data, mergedOrders, memoryOrders;
|
|
873
|
+
var _updateLocalPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
|
|
874
|
+
var logContext, found, previousPayment, nextPayment, nextOrder, paymentContext, targetIndex, shouldKeepInMemory, previousList, storageOrder, _storageOrder$order_i, _storageOrder$order_i2, _storageOrder$order_i3;
|
|
757
875
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
758
876
|
while (1) switch (_context6.prev = _context6.next) {
|
|
877
|
+
case 0:
|
|
878
|
+
logContext = {
|
|
879
|
+
operation_id: params.operationId,
|
|
880
|
+
sale_id: params.saleId,
|
|
881
|
+
payment_number: params.paymentNumber,
|
|
882
|
+
incoming_payment_update: params.updates
|
|
883
|
+
};
|
|
884
|
+
this.logInfo('updateLocalPayment-开始', logContext);
|
|
885
|
+
_context6.next = 4;
|
|
886
|
+
return this.getLocalPayment(params);
|
|
887
|
+
case 4:
|
|
888
|
+
found = _context6.sent;
|
|
889
|
+
if (found) {
|
|
890
|
+
_context6.next = 8;
|
|
891
|
+
break;
|
|
892
|
+
}
|
|
893
|
+
this.logWarning('updateLocalPayment-支付项未命中', logContext);
|
|
894
|
+
return _context6.abrupt("return", null);
|
|
895
|
+
case 8:
|
|
896
|
+
previousPayment = cloneDeep(found.payment);
|
|
897
|
+
nextPayment = mergeOrderPaymentRecord(found.payment, _objectSpread(_objectSpread({}, params.updates), {}, {
|
|
898
|
+
updated_at: params.updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
899
|
+
}));
|
|
900
|
+
nextOrder = _objectSpread(_objectSpread({}, found.order), {}, {
|
|
901
|
+
payments: (found.order.payments || []).map(function (payment, index) {
|
|
902
|
+
return index === found.paymentIndex ? nextPayment : payment;
|
|
903
|
+
}),
|
|
904
|
+
updated_at: dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
905
|
+
});
|
|
906
|
+
paymentContext = _objectSpread(_objectSpread(_objectSpread({}, logContext), {}, {
|
|
907
|
+
matched_by: found.matchedBy,
|
|
908
|
+
payment_index: found.paymentIndex
|
|
909
|
+
}, this.buildLocalPaymentOrderLogContext(nextOrder)), {}, {
|
|
910
|
+
previous_payment: previousPayment,
|
|
911
|
+
payment: nextPayment
|
|
912
|
+
});
|
|
913
|
+
this.logInfo('updateLocalPayment-支付项合并完成', paymentContext);
|
|
914
|
+
targetIndex = this.findOrderIndexByIdentity(this.store.list, found.order);
|
|
915
|
+
shouldKeepInMemory = this.shouldKeepOrderInMemory(nextOrder);
|
|
916
|
+
if (!(targetIndex < 0 && shouldKeepInMemory)) {
|
|
917
|
+
_context6.next = 18;
|
|
918
|
+
break;
|
|
919
|
+
}
|
|
920
|
+
this.logError('updateLocalPayment-订单Store索引未命中', paymentContext);
|
|
921
|
+
return _context6.abrupt("return", null);
|
|
922
|
+
case 18:
|
|
923
|
+
previousList = this.store.list;
|
|
924
|
+
this.store.list = shouldKeepInMemory ? this.store.list.map(function (order, index) {
|
|
925
|
+
return index === targetIndex ? nextOrder : order;
|
|
926
|
+
}) : this.store.list.filter(function (_, index) {
|
|
927
|
+
return index !== targetIndex;
|
|
928
|
+
});
|
|
929
|
+
this.syncOrdersMap();
|
|
930
|
+
storageOrder = this.withoutSyntheticDraftOrderId(nextOrder);
|
|
931
|
+
_context6.prev = 22;
|
|
932
|
+
this.logInfo('updateLocalPayment-SQLite写入开始', _objectSpread(_objectSpread({}, paymentContext), {}, {
|
|
933
|
+
storage_order_id: (_storageOrder$order_i = storageOrder.order_id) !== null && _storageOrder$order_i !== void 0 ? _storageOrder$order_i : null
|
|
934
|
+
}));
|
|
935
|
+
_context6.next = 26;
|
|
936
|
+
return this.updateOrderInSQLite(storageOrder, 'updateLocalPayment', {
|
|
937
|
+
throwOnError: true
|
|
938
|
+
});
|
|
939
|
+
case 26:
|
|
940
|
+
this.logInfo('updateLocalPayment-SQLite写入完成', _objectSpread(_objectSpread({}, paymentContext), {}, {
|
|
941
|
+
storage_order_id: (_storageOrder$order_i2 = storageOrder.order_id) !== null && _storageOrder$order_i2 !== void 0 ? _storageOrder$order_i2 : null
|
|
942
|
+
}));
|
|
943
|
+
_context6.next = 35;
|
|
944
|
+
break;
|
|
945
|
+
case 29:
|
|
946
|
+
_context6.prev = 29;
|
|
947
|
+
_context6.t0 = _context6["catch"](22);
|
|
948
|
+
this.store.list = previousList;
|
|
949
|
+
this.syncOrdersMap();
|
|
950
|
+
this.logError('updateLocalPayment-SQLite写入失败并回滚内存', _objectSpread(_objectSpread({}, paymentContext), {}, {
|
|
951
|
+
storage_order_id: (_storageOrder$order_i3 = storageOrder.order_id) !== null && _storageOrder$order_i3 !== void 0 ? _storageOrder$order_i3 : null,
|
|
952
|
+
error: _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0)
|
|
953
|
+
}));
|
|
954
|
+
throw _context6.t0;
|
|
955
|
+
case 35:
|
|
956
|
+
if (!(shouldKeepInMemory || targetIndex >= 0)) {
|
|
957
|
+
_context6.next = 38;
|
|
958
|
+
break;
|
|
959
|
+
}
|
|
960
|
+
_context6.next = 38;
|
|
961
|
+
return this.emitOrdersChanged(shouldKeepInMemory ? [nextOrder] : [], shouldKeepInMemory ? 'updateLocalPayment' : 'updateLocalPayment.sqliteOnlyDraft');
|
|
962
|
+
case 38:
|
|
963
|
+
this.logInfo('updateLocalPayment-变更事件完成', paymentContext);
|
|
964
|
+
return _context6.abrupt("return", {
|
|
965
|
+
order: nextOrder,
|
|
966
|
+
payment: nextPayment,
|
|
967
|
+
previousPayment: previousPayment
|
|
968
|
+
});
|
|
969
|
+
case 40:
|
|
970
|
+
case "end":
|
|
971
|
+
return _context6.stop();
|
|
972
|
+
}
|
|
973
|
+
}, _callee6, this, [[22, 29]]);
|
|
974
|
+
}));
|
|
975
|
+
function updateLocalPayment(_x5) {
|
|
976
|
+
return _updateLocalPayment.apply(this, arguments);
|
|
977
|
+
}
|
|
978
|
+
return updateLocalPayment;
|
|
979
|
+
}()
|
|
980
|
+
}, {
|
|
981
|
+
key: "loadOrdersByServer",
|
|
982
|
+
value: function () {
|
|
983
|
+
var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
984
|
+
var _this5 = this,
|
|
985
|
+
_this$store;
|
|
986
|
+
var orderList, protectedOrdersBeforeRemoteFetch, data, mergedOrders, memoryOrders;
|
|
987
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
988
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
759
989
|
case 0:
|
|
760
990
|
orderList = [];
|
|
991
|
+
_context7.next = 3;
|
|
992
|
+
return this.loadOrdersFromSQLite();
|
|
993
|
+
case 3:
|
|
994
|
+
protectedOrdersBeforeRemoteFetch = _context7.sent.filter(function (order) {
|
|
995
|
+
return _this5.shouldProtectLocalOrderFromRemoteSnapshot(order);
|
|
996
|
+
});
|
|
761
997
|
this.logInfo('loadOrdersByServer-开始', {
|
|
762
998
|
hasOrderDataSource: !!this.orderDataSource,
|
|
763
|
-
query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null
|
|
999
|
+
query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
|
|
1000
|
+
protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
|
|
1001
|
+
protectedPendingPaymentCount: protectedOrdersBeforeRemoteFetch.reduce(function (count, order) {
|
|
1002
|
+
return count + _this5.getIdentifiedPendingPayments(order).length;
|
|
1003
|
+
}, 0)
|
|
764
1004
|
});
|
|
765
1005
|
if (!this.orderDataSource) {
|
|
766
|
-
|
|
1006
|
+
_context7.next = 20;
|
|
767
1007
|
break;
|
|
768
1008
|
}
|
|
769
|
-
|
|
770
|
-
|
|
1009
|
+
_context7.prev = 6;
|
|
1010
|
+
_context7.next = 9;
|
|
771
1011
|
return this.orderDataSource.run({
|
|
772
1012
|
sse: {
|
|
773
1013
|
query: this.store.createdAtQuery
|
|
774
1014
|
}
|
|
775
1015
|
});
|
|
776
|
-
case
|
|
777
|
-
data =
|
|
1016
|
+
case 9:
|
|
1017
|
+
data = _context7.sent;
|
|
778
1018
|
orderList = data || [];
|
|
779
1019
|
this.logInfo('loadOrdersByServer-SSE拉取成功', {
|
|
780
1020
|
count: orderList.length
|
|
781
1021
|
});
|
|
782
1022
|
this.markOrderPulledAtNow();
|
|
783
1023
|
this.lastServerFullFetchAtMs = Date.now();
|
|
784
|
-
|
|
1024
|
+
_context7.next = 20;
|
|
785
1025
|
break;
|
|
786
|
-
case
|
|
787
|
-
|
|
788
|
-
|
|
1026
|
+
case 16:
|
|
1027
|
+
_context7.prev = 16;
|
|
1028
|
+
_context7.t0 = _context7["catch"](6);
|
|
789
1029
|
this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
|
|
790
|
-
return
|
|
791
|
-
case
|
|
792
|
-
|
|
793
|
-
return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer');
|
|
794
|
-
case
|
|
795
|
-
mergedOrders =
|
|
796
|
-
memoryOrders =
|
|
797
|
-
return _this7.normalizeOrderForMemoryList(order);
|
|
798
|
-
});
|
|
1030
|
+
return _context7.abrupt("return", this.store.list);
|
|
1031
|
+
case 20:
|
|
1032
|
+
_context7.next = 22;
|
|
1033
|
+
return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer', protectedOrdersBeforeRemoteFetch);
|
|
1034
|
+
case 22:
|
|
1035
|
+
mergedOrders = _context7.sent;
|
|
1036
|
+
memoryOrders = this.normalizeOrdersForMemoryList(mergedOrders, 'loadOrdersByServer.memory');
|
|
799
1037
|
this.logInfo('loadOrdersByServer-结束', {
|
|
800
|
-
count: memoryOrders.length
|
|
1038
|
+
count: memoryOrders.length,
|
|
1039
|
+
persistedCount: mergedOrders.length,
|
|
1040
|
+
sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
|
|
801
1041
|
});
|
|
802
|
-
|
|
1042
|
+
_context7.next = 27;
|
|
803
1043
|
return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
|
|
804
|
-
case
|
|
805
|
-
return
|
|
806
|
-
case
|
|
1044
|
+
case 27:
|
|
1045
|
+
return _context7.abrupt("return", memoryOrders);
|
|
1046
|
+
case 28:
|
|
807
1047
|
case "end":
|
|
808
|
-
return
|
|
1048
|
+
return _context7.stop();
|
|
809
1049
|
}
|
|
810
|
-
},
|
|
1050
|
+
}, _callee7, this, [[6, 16]]);
|
|
811
1051
|
}));
|
|
812
1052
|
function loadOrdersByServer() {
|
|
813
1053
|
return _loadOrdersByServer.apply(this, arguments);
|
|
@@ -822,61 +1062,54 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
822
1062
|
}, {
|
|
823
1063
|
key: "silentRefresh",
|
|
824
1064
|
value: (function () {
|
|
825
|
-
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1065
|
+
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
826
1066
|
var startTime, elapsedSinceFullFetch, orders, errorMessage;
|
|
827
|
-
return _regeneratorRuntime().wrap(function
|
|
828
|
-
while (1) switch (
|
|
1067
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1068
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
829
1069
|
case 0:
|
|
830
1070
|
startTime = Date.now();
|
|
831
1071
|
elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
|
|
832
1072
|
if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
|
|
833
|
-
|
|
1073
|
+
_context8.next = 4;
|
|
834
1074
|
break;
|
|
835
1075
|
}
|
|
836
|
-
return
|
|
1076
|
+
return _context8.abrupt("return", this.store.list);
|
|
837
1077
|
case 4:
|
|
838
1078
|
this.logInfo('silentRefresh 开始');
|
|
839
|
-
|
|
1079
|
+
_context8.prev = 5;
|
|
840
1080
|
// 刷新前,需要更新当前营业日边界(store.createdAtQuery)
|
|
841
1081
|
this.updateCreateStore();
|
|
842
|
-
|
|
1082
|
+
_context8.next = 9;
|
|
843
1083
|
return this.loadOrdersByServer();
|
|
844
1084
|
case 9:
|
|
845
|
-
orders =
|
|
846
|
-
if (!(orders.length > 0)) {
|
|
847
|
-
_context7.next = 19;
|
|
848
|
-
break;
|
|
849
|
-
}
|
|
1085
|
+
orders = _context8.sent;
|
|
850
1086
|
this.store.list = cloneDeep(orders);
|
|
851
1087
|
this.syncOrdersMap();
|
|
852
|
-
|
|
853
|
-
|
|
1088
|
+
_context8.next = 14;
|
|
1089
|
+
return this.emitOrdersChanged([], 'silentRefresh');
|
|
1090
|
+
case 14:
|
|
1091
|
+
_context8.next = 16;
|
|
854
1092
|
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
855
1093
|
case 16:
|
|
856
1094
|
this.logInfo('silentRefresh 完成', {
|
|
857
1095
|
orderCount: orders.length,
|
|
858
1096
|
duration: "".concat(Date.now() - startTime, "ms")
|
|
859
1097
|
});
|
|
860
|
-
|
|
861
|
-
break;
|
|
862
|
-
case 19:
|
|
863
|
-
this.logInfo('silentRefresh: 服务器未返回数据');
|
|
1098
|
+
return _context8.abrupt("return", this.store.list);
|
|
864
1099
|
case 20:
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
_context7.t0 = _context7["catch"](5);
|
|
869
|
-
errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
|
|
1100
|
+
_context8.prev = 20;
|
|
1101
|
+
_context8.t0 = _context8["catch"](5);
|
|
1102
|
+
errorMessage = _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0);
|
|
870
1103
|
this.logError('silentRefresh 失败', {
|
|
871
1104
|
duration: "".concat(Date.now() - startTime, "ms"),
|
|
872
1105
|
error: errorMessage
|
|
873
1106
|
});
|
|
874
|
-
return
|
|
875
|
-
case
|
|
1107
|
+
return _context8.abrupt("return", this.store.list);
|
|
1108
|
+
case 25:
|
|
876
1109
|
case "end":
|
|
877
|
-
return
|
|
1110
|
+
return _context8.stop();
|
|
878
1111
|
}
|
|
879
|
-
},
|
|
1112
|
+
}, _callee8, this, [[5, 20]]);
|
|
880
1113
|
}));
|
|
881
1114
|
function silentRefresh() {
|
|
882
1115
|
return _silentRefresh.apply(this, arguments);
|
|
@@ -889,6 +1122,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
889
1122
|
var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'normalizeOrderForMemoryList';
|
|
890
1123
|
var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, source);
|
|
891
1124
|
var externalSaleNumber = normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.external_sale_number;
|
|
1125
|
+
if (this.isDraftOrder(normalizedOrder) && !this.hasRealOrderId(normalizedOrder)) {
|
|
1126
|
+
return normalizedOrder;
|
|
1127
|
+
}
|
|
892
1128
|
if ((normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== undefined && (normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== null && (normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== '') {
|
|
893
1129
|
return normalizedOrder;
|
|
894
1130
|
}
|
|
@@ -899,6 +1135,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
899
1135
|
order_id: externalSaleNumber
|
|
900
1136
|
});
|
|
901
1137
|
}
|
|
1138
|
+
}, {
|
|
1139
|
+
key: "normalizeOrdersForMemoryList",
|
|
1140
|
+
value: function normalizeOrdersForMemoryList(orders, source) {
|
|
1141
|
+
var _this6 = this;
|
|
1142
|
+
return orders.map(function (order) {
|
|
1143
|
+
return _this6.normalizeOrderForMemoryList(order, source);
|
|
1144
|
+
}).filter(function (order) {
|
|
1145
|
+
return _this6.shouldKeepOrderInMemory(order);
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
}, {
|
|
1149
|
+
key: "hasRealOrderId",
|
|
1150
|
+
value: function hasRealOrderId(order) {
|
|
1151
|
+
if (!order || this.isBlankIdentityValue(order.order_id)) return false;
|
|
1152
|
+
var externalSaleNumber = order.external_sale_number;
|
|
1153
|
+
return !(this.isDraftOrder(order) && !this.isBlankIdentityValue(externalSaleNumber) && String(order.order_id) === String(externalSaleNumber));
|
|
1154
|
+
}
|
|
1155
|
+
}, {
|
|
1156
|
+
key: "shouldKeepOrderInMemory",
|
|
1157
|
+
value: function shouldKeepOrderInMemory(order) {
|
|
1158
|
+
return !this.isDraftOrder(order) || this.hasRealOrderId(order);
|
|
1159
|
+
}
|
|
1160
|
+
}, {
|
|
1161
|
+
key: "withoutSyntheticDraftOrderId",
|
|
1162
|
+
value: function withoutSyntheticDraftOrderId(order) {
|
|
1163
|
+
var externalSaleNumber = order.external_sale_number;
|
|
1164
|
+
if (Number(order.is_draft_order || 0) !== 1 || order.order_id === undefined || externalSaleNumber === undefined || String(order.order_id) !== String(externalSaleNumber)) {
|
|
1165
|
+
return order;
|
|
1166
|
+
}
|
|
1167
|
+
var next = _objectSpread({}, order);
|
|
1168
|
+
delete next.order_id;
|
|
1169
|
+
return next;
|
|
1170
|
+
}
|
|
902
1171
|
|
|
903
1172
|
/**
|
|
904
1173
|
* 仅覆盖本地已存在的订单;不存在则直接跳过,不落库、不 emit。
|
|
@@ -907,31 +1176,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
907
1176
|
}, {
|
|
908
1177
|
key: "overwriteExistingOrder",
|
|
909
1178
|
value: (function () {
|
|
910
|
-
var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
911
|
-
var
|
|
1179
|
+
var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fresh) {
|
|
1180
|
+
var _this7 = this;
|
|
912
1181
|
var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
|
|
913
|
-
return _regeneratorRuntime().wrap(function
|
|
914
|
-
while (1) switch (
|
|
1182
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1183
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
915
1184
|
case 0:
|
|
916
1185
|
orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
|
|
917
1186
|
if (!(orderId === undefined || orderId === null)) {
|
|
918
|
-
|
|
1187
|
+
_context9.next = 4;
|
|
919
1188
|
break;
|
|
920
1189
|
}
|
|
921
1190
|
this.logError('overwriteExistingOrder-入参缺少 order_id');
|
|
922
|
-
return
|
|
1191
|
+
return _context9.abrupt("return", {
|
|
923
1192
|
overwritten: false
|
|
924
1193
|
});
|
|
925
1194
|
case 4:
|
|
926
1195
|
key = this.getIdKey(orderId);
|
|
927
1196
|
if (this.store.map.has(key)) {
|
|
928
|
-
|
|
1197
|
+
_context9.next = 8;
|
|
929
1198
|
break;
|
|
930
1199
|
}
|
|
931
1200
|
this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
|
|
932
1201
|
orderId: orderId
|
|
933
1202
|
});
|
|
934
|
-
return
|
|
1203
|
+
return _context9.abrupt("return", {
|
|
935
1204
|
overwritten: false
|
|
936
1205
|
});
|
|
937
1206
|
case 8:
|
|
@@ -945,31 +1214,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
945
1214
|
this.store.list = this.store.list.map(function (order) {
|
|
946
1215
|
var id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
947
1216
|
if (id === undefined || id === null) {
|
|
948
|
-
return
|
|
1217
|
+
return _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
|
|
949
1218
|
}
|
|
950
|
-
return
|
|
1219
|
+
return _this7.getIdKey(id) === key ? reconciledFresh : _this7.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
|
|
951
1220
|
});
|
|
952
1221
|
this.syncOrdersMap();
|
|
953
|
-
|
|
1222
|
+
_context9.next = 16;
|
|
954
1223
|
return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
|
|
955
1224
|
case 16:
|
|
956
1225
|
this.logInfo('overwriteExistingOrder-结束', {
|
|
957
1226
|
orderId: orderId,
|
|
958
1227
|
storeOrderCountAfter: this.store.list.length
|
|
959
1228
|
});
|
|
960
|
-
|
|
1229
|
+
_context9.next = 19;
|
|
961
1230
|
return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
|
|
962
1231
|
case 19:
|
|
963
|
-
return
|
|
1232
|
+
return _context9.abrupt("return", {
|
|
964
1233
|
overwritten: true
|
|
965
1234
|
});
|
|
966
1235
|
case 20:
|
|
967
1236
|
case "end":
|
|
968
|
-
return
|
|
1237
|
+
return _context9.stop();
|
|
969
1238
|
}
|
|
970
|
-
},
|
|
1239
|
+
}, _callee9, this);
|
|
971
1240
|
}));
|
|
972
|
-
function overwriteExistingOrder(
|
|
1241
|
+
function overwriteExistingOrder(_x6) {
|
|
973
1242
|
return _overwriteExistingOrder.apply(this, arguments);
|
|
974
1243
|
}
|
|
975
1244
|
return overwriteExistingOrder;
|
|
@@ -982,29 +1251,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
982
1251
|
}, {
|
|
983
1252
|
key: "upsertOrdersFromRemote",
|
|
984
1253
|
value: (function () {
|
|
985
|
-
var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
986
|
-
|
|
987
|
-
|
|
1254
|
+
var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(freshOrders) {
|
|
1255
|
+
var source,
|
|
1256
|
+
_args10 = arguments;
|
|
1257
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1258
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
988
1259
|
case 0:
|
|
1260
|
+
source = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : 'upsertOrdersFromRemote';
|
|
989
1261
|
if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
|
|
990
|
-
|
|
1262
|
+
_context10.next = 4;
|
|
991
1263
|
break;
|
|
992
1264
|
}
|
|
993
1265
|
this.logInfo('upsertOrdersFromRemote-订单列表为空', {});
|
|
994
|
-
return
|
|
995
|
-
case
|
|
1266
|
+
return _context10.abrupt("return");
|
|
1267
|
+
case 4:
|
|
996
1268
|
this.logInfo('upsertOrdersFromRemote-开始', {
|
|
997
|
-
count: freshOrders.length
|
|
1269
|
+
count: freshOrders.length,
|
|
1270
|
+
source: source
|
|
998
1271
|
});
|
|
999
|
-
|
|
1000
|
-
return this.mergeOrdersToStore(freshOrders,
|
|
1001
|
-
case
|
|
1272
|
+
_context10.next = 7;
|
|
1273
|
+
return this.mergeOrdersToStore(freshOrders, source);
|
|
1274
|
+
case 7:
|
|
1002
1275
|
case "end":
|
|
1003
|
-
return
|
|
1276
|
+
return _context10.stop();
|
|
1004
1277
|
}
|
|
1005
|
-
},
|
|
1278
|
+
}, _callee10, this);
|
|
1006
1279
|
}));
|
|
1007
|
-
function upsertOrdersFromRemote(
|
|
1280
|
+
function upsertOrdersFromRemote(_x7) {
|
|
1008
1281
|
return _upsertOrdersFromRemote.apply(this, arguments);
|
|
1009
1282
|
}
|
|
1010
1283
|
return upsertOrdersFromRemote;
|
|
@@ -1012,21 +1285,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1012
1285
|
}, {
|
|
1013
1286
|
key: "markOrderSyncedByExternalSaleNumber",
|
|
1014
1287
|
value: function () {
|
|
1015
|
-
var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1016
|
-
var
|
|
1288
|
+
var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
|
|
1289
|
+
var _this8 = this,
|
|
1017
1290
|
_existing$external_sa,
|
|
1018
1291
|
_nextOrder$order_id;
|
|
1019
1292
|
var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
|
|
1020
|
-
return _regeneratorRuntime().wrap(function
|
|
1021
|
-
while (1) switch (
|
|
1293
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
1294
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
1022
1295
|
case 0:
|
|
1023
1296
|
externalSaleNumber = params.externalSaleNumber;
|
|
1024
1297
|
if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
|
|
1025
|
-
|
|
1298
|
+
_context11.next = 4;
|
|
1026
1299
|
break;
|
|
1027
1300
|
}
|
|
1028
1301
|
this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
|
|
1029
|
-
return
|
|
1302
|
+
return _context11.abrupt("return", {
|
|
1030
1303
|
updated: false
|
|
1031
1304
|
});
|
|
1032
1305
|
case 4:
|
|
@@ -1034,23 +1307,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1034
1307
|
targetIndex = this.store.list.findIndex(function (order) {
|
|
1035
1308
|
var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
|
|
1036
1309
|
if (value === undefined || value === null || value === '') return false;
|
|
1037
|
-
return
|
|
1310
|
+
return _this8.getIdKey(value) === key;
|
|
1038
1311
|
});
|
|
1039
1312
|
if (!(targetIndex < 0)) {
|
|
1040
|
-
|
|
1313
|
+
_context11.next = 9;
|
|
1041
1314
|
break;
|
|
1042
1315
|
}
|
|
1043
1316
|
this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
|
|
1044
1317
|
external_sale_number: externalSaleNumber
|
|
1045
1318
|
});
|
|
1046
|
-
return
|
|
1319
|
+
return _context11.abrupt("return", {
|
|
1047
1320
|
updated: false
|
|
1048
1321
|
});
|
|
1049
1322
|
case 9:
|
|
1050
1323
|
existing = this.store.list[targetIndex];
|
|
1051
1324
|
nextOrder = this.normalizeRemoteSyncedOrder(_objectSpread(_objectSpread(_objectSpread({}, existing), params.patch || {}), {}, {
|
|
1052
1325
|
external_sale_number: (_existing$external_sa = existing.external_sale_number) !== null && _existing$external_sa !== void 0 ? _existing$external_sa : externalSaleNumber,
|
|
1053
|
-
need_sync: 0
|
|
1326
|
+
need_sync: 0,
|
|
1327
|
+
is_draft_order: 0
|
|
1054
1328
|
}));
|
|
1055
1329
|
storageKey = this.getOrderStorageKey(nextOrder) || key;
|
|
1056
1330
|
this.store.list = this.store.list.map(function (order, index) {
|
|
@@ -1058,27 +1332,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1058
1332
|
return nextOrder;
|
|
1059
1333
|
});
|
|
1060
1334
|
this.syncOrdersMap();
|
|
1061
|
-
|
|
1335
|
+
_context11.next = 16;
|
|
1062
1336
|
return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
|
|
1063
1337
|
case 16:
|
|
1064
1338
|
this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
|
|
1065
1339
|
external_sale_number: externalSaleNumber,
|
|
1066
1340
|
order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
|
|
1067
1341
|
});
|
|
1068
|
-
|
|
1342
|
+
_context11.next = 19;
|
|
1069
1343
|
return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
|
|
1070
1344
|
case 19:
|
|
1071
|
-
return
|
|
1345
|
+
return _context11.abrupt("return", {
|
|
1072
1346
|
updated: true,
|
|
1073
1347
|
order: nextOrder
|
|
1074
1348
|
});
|
|
1075
1349
|
case 20:
|
|
1076
1350
|
case "end":
|
|
1077
|
-
return
|
|
1351
|
+
return _context11.stop();
|
|
1078
1352
|
}
|
|
1079
|
-
},
|
|
1353
|
+
}, _callee11, this);
|
|
1080
1354
|
}));
|
|
1081
|
-
function markOrderSyncedByExternalSaleNumber(
|
|
1355
|
+
function markOrderSyncedByExternalSaleNumber(_x8) {
|
|
1082
1356
|
return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
|
|
1083
1357
|
}
|
|
1084
1358
|
return markOrderSyncedByExternalSaleNumber;
|
|
@@ -1090,70 +1364,104 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1090
1364
|
}, {
|
|
1091
1365
|
key: "upsertPendingSyncOrders",
|
|
1092
1366
|
value: (function () {
|
|
1093
|
-
var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1094
|
-
var
|
|
1095
|
-
var
|
|
1096
|
-
|
|
1097
|
-
|
|
1367
|
+
var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(pendingOrders) {
|
|
1368
|
+
var _this9 = this;
|
|
1369
|
+
var options,
|
|
1370
|
+
pendingMap,
|
|
1371
|
+
memoryPendingMap,
|
|
1372
|
+
_iterator5,
|
|
1373
|
+
_step5,
|
|
1374
|
+
order,
|
|
1375
|
+
normalizedOrder,
|
|
1376
|
+
pendingOrder,
|
|
1377
|
+
storageKey,
|
|
1378
|
+
mergeActions,
|
|
1379
|
+
updatedList,
|
|
1380
|
+
identityKeyToIndex,
|
|
1381
|
+
index,
|
|
1382
|
+
_iterator6,
|
|
1383
|
+
_step6,
|
|
1384
|
+
key,
|
|
1385
|
+
_iterator7,
|
|
1386
|
+
_step7,
|
|
1387
|
+
_step7$value,
|
|
1388
|
+
_storageKey,
|
|
1389
|
+
_pendingOrder,
|
|
1390
|
+
matchIndex,
|
|
1391
|
+
existingOrder,
|
|
1392
|
+
mergedOrder,
|
|
1393
|
+
nextOrder,
|
|
1394
|
+
pendingSnapshot,
|
|
1395
|
+
insertIndex,
|
|
1396
|
+
patchedOrders,
|
|
1397
|
+
previousList,
|
|
1398
|
+
_args12 = arguments;
|
|
1399
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1400
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
1098
1401
|
case 0:
|
|
1402
|
+
options = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : {};
|
|
1099
1403
|
if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
|
|
1100
|
-
|
|
1404
|
+
_context12.next = 4;
|
|
1101
1405
|
break;
|
|
1102
1406
|
}
|
|
1103
1407
|
this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
|
|
1104
|
-
return
|
|
1105
|
-
case
|
|
1408
|
+
return _context12.abrupt("return");
|
|
1409
|
+
case 4:
|
|
1106
1410
|
pendingMap = new Map();
|
|
1107
1411
|
memoryPendingMap = new Map();
|
|
1108
1412
|
_iterator5 = _createForOfIteratorHelper(pendingOrders);
|
|
1109
|
-
|
|
1413
|
+
_context12.prev = 7;
|
|
1110
1414
|
_iterator5.s();
|
|
1111
|
-
case
|
|
1415
|
+
case 9:
|
|
1112
1416
|
if ((_step5 = _iterator5.n()).done) {
|
|
1113
|
-
|
|
1417
|
+
_context12.next = 20;
|
|
1114
1418
|
break;
|
|
1115
1419
|
}
|
|
1116
1420
|
order = _step5.value;
|
|
1117
1421
|
normalizedOrder = this.normalizeOrderCollectionsForIngress(order, 'upsertPendingSyncOrders.incoming');
|
|
1118
|
-
|
|
1422
|
+
pendingOrder = _objectSpread(_objectSpread({}, normalizedOrder), {}, {
|
|
1423
|
+
need_sync: 1,
|
|
1424
|
+
is_draft_order: 0
|
|
1425
|
+
});
|
|
1426
|
+
storageKey = this.getOrderStorageKey(pendingOrder);
|
|
1119
1427
|
if (storageKey) {
|
|
1120
|
-
|
|
1428
|
+
_context12.next = 16;
|
|
1121
1429
|
break;
|
|
1122
1430
|
}
|
|
1123
|
-
return
|
|
1124
|
-
case 14:
|
|
1125
|
-
pendingMap.set(storageKey, normalizedOrder);
|
|
1126
|
-
memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(normalizedOrder, 'upsertPendingSyncOrders.memory'));
|
|
1431
|
+
return _context12.abrupt("continue", 18);
|
|
1127
1432
|
case 16:
|
|
1128
|
-
|
|
1129
|
-
|
|
1433
|
+
pendingMap.set(storageKey, pendingOrder);
|
|
1434
|
+
memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(pendingOrder, 'upsertPendingSyncOrders.memory'));
|
|
1130
1435
|
case 18:
|
|
1131
|
-
|
|
1436
|
+
_context12.next = 9;
|
|
1132
1437
|
break;
|
|
1133
1438
|
case 20:
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1439
|
+
_context12.next = 25;
|
|
1440
|
+
break;
|
|
1441
|
+
case 22:
|
|
1442
|
+
_context12.prev = 22;
|
|
1443
|
+
_context12.t0 = _context12["catch"](7);
|
|
1444
|
+
_iterator5.e(_context12.t0);
|
|
1445
|
+
case 25:
|
|
1446
|
+
_context12.prev = 25;
|
|
1139
1447
|
_iterator5.f();
|
|
1140
|
-
return
|
|
1141
|
-
case
|
|
1448
|
+
return _context12.finish(25);
|
|
1449
|
+
case 28:
|
|
1142
1450
|
if (!(pendingMap.size === 0)) {
|
|
1143
|
-
|
|
1451
|
+
_context12.next = 31;
|
|
1144
1452
|
break;
|
|
1145
1453
|
}
|
|
1146
1454
|
this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
|
|
1147
1455
|
count: pendingOrders.length
|
|
1148
1456
|
});
|
|
1149
|
-
return
|
|
1150
|
-
case
|
|
1457
|
+
return _context12.abrupt("return");
|
|
1458
|
+
case 31:
|
|
1151
1459
|
this.logInfo('upsertPendingSyncOrders-开始', {
|
|
1152
1460
|
count: pendingMap.size
|
|
1153
1461
|
});
|
|
1154
1462
|
mergeActions = {};
|
|
1155
1463
|
updatedList = this.store.list.map(function (order) {
|
|
1156
|
-
return
|
|
1464
|
+
return _this9.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
|
|
1157
1465
|
}); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
|
|
1158
1466
|
// 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
|
|
1159
1467
|
identityKeyToIndex = new Map();
|
|
@@ -1172,116 +1480,314 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1172
1480
|
}
|
|
1173
1481
|
}
|
|
1174
1482
|
_iterator7 = _createForOfIteratorHelper(memoryPendingMap.entries());
|
|
1175
|
-
|
|
1483
|
+
_context12.prev = 37;
|
|
1176
1484
|
_iterator7.s();
|
|
1177
|
-
case
|
|
1485
|
+
case 39:
|
|
1178
1486
|
if ((_step7 = _iterator7.n()).done) {
|
|
1179
|
-
|
|
1487
|
+
_context12.next = 58;
|
|
1180
1488
|
break;
|
|
1181
1489
|
}
|
|
1182
|
-
_step7$value = _slicedToArray(_step7.value, 2), _storageKey = _step7$value[0],
|
|
1183
|
-
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(
|
|
1490
|
+
_step7$value = _slicedToArray(_step7.value, 2), _storageKey = _step7$value[0], _pendingOrder = _step7$value[1];
|
|
1491
|
+
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_pendingOrder));
|
|
1184
1492
|
if (!(matchIndex >= 0)) {
|
|
1185
|
-
|
|
1493
|
+
_context12.next = 52;
|
|
1186
1494
|
break;
|
|
1187
1495
|
}
|
|
1188
1496
|
existingOrder = updatedList[matchIndex];
|
|
1189
|
-
mergedOrder = this.mergeOrderRecords(existingOrder,
|
|
1190
|
-
|
|
1497
|
+
mergedOrder = this.mergeOrderRecords(existingOrder, _pendingOrder);
|
|
1498
|
+
nextOrder = _objectSpread(_objectSpread({}, mergedOrder), {}, {
|
|
1499
|
+
need_sync: 1,
|
|
1500
|
+
is_draft_order: 0
|
|
1501
|
+
});
|
|
1502
|
+
updatedList[matchIndex] = nextOrder;
|
|
1191
1503
|
pendingSnapshot = pendingMap.get(_storageKey);
|
|
1192
1504
|
if (pendingSnapshot) {
|
|
1193
1505
|
pendingMap.set(_storageKey, this.reconcileOverwriteOrderCollections(existingOrder, pendingSnapshot));
|
|
1194
1506
|
}
|
|
1195
1507
|
// 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
|
|
1196
|
-
this.registerOrderIdentityKeys(identityKeyToIndex,
|
|
1508
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
|
|
1197
1509
|
mergeActions[_storageKey] = 'update';
|
|
1198
|
-
return
|
|
1199
|
-
case
|
|
1510
|
+
return _context12.abrupt("continue", 56);
|
|
1511
|
+
case 52:
|
|
1200
1512
|
insertIndex = updatedList.length;
|
|
1201
|
-
updatedList.push(
|
|
1202
|
-
this.registerOrderIdentityKeys(identityKeyToIndex,
|
|
1513
|
+
updatedList.push(_pendingOrder);
|
|
1514
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, _pendingOrder, insertIndex);
|
|
1203
1515
|
mergeActions[_storageKey] = 'insert';
|
|
1204
|
-
case
|
|
1205
|
-
|
|
1516
|
+
case 56:
|
|
1517
|
+
_context12.next = 39;
|
|
1206
1518
|
break;
|
|
1207
|
-
case
|
|
1208
|
-
|
|
1519
|
+
case 58:
|
|
1520
|
+
_context12.next = 63;
|
|
1209
1521
|
break;
|
|
1210
|
-
case 57:
|
|
1211
|
-
_context11.prev = 57;
|
|
1212
|
-
_context11.t1 = _context11["catch"](35);
|
|
1213
|
-
_iterator7.e(_context11.t1);
|
|
1214
1522
|
case 60:
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1523
|
+
_context12.prev = 60;
|
|
1524
|
+
_context12.t1 = _context12["catch"](37);
|
|
1525
|
+
_iterator7.e(_context12.t1);
|
|
1218
1526
|
case 63:
|
|
1527
|
+
_context12.prev = 63;
|
|
1528
|
+
_iterator7.f();
|
|
1529
|
+
return _context12.finish(63);
|
|
1530
|
+
case 66:
|
|
1219
1531
|
patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
|
|
1532
|
+
previousList = this.store.list;
|
|
1220
1533
|
this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
|
|
1221
1534
|
this.syncOrdersMap();
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1535
|
+
_context12.prev = 70;
|
|
1536
|
+
_context12.next = 73;
|
|
1537
|
+
return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions, options);
|
|
1538
|
+
case 73:
|
|
1539
|
+
_context12.next = 80;
|
|
1540
|
+
break;
|
|
1541
|
+
case 75:
|
|
1542
|
+
_context12.prev = 75;
|
|
1543
|
+
_context12.t2 = _context12["catch"](70);
|
|
1544
|
+
this.store.list = previousList;
|
|
1545
|
+
this.syncOrdersMap();
|
|
1546
|
+
throw _context12.t2;
|
|
1547
|
+
case 80:
|
|
1225
1548
|
this.logInfo('upsertPendingSyncOrders-结束', {
|
|
1226
1549
|
count: patchedOrders.length,
|
|
1227
1550
|
storeOrderCountAfter: this.store.list.length
|
|
1228
1551
|
});
|
|
1229
|
-
|
|
1552
|
+
_context12.next = 83;
|
|
1230
1553
|
return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
|
|
1231
|
-
case
|
|
1554
|
+
case 83:
|
|
1232
1555
|
case "end":
|
|
1233
|
-
return
|
|
1556
|
+
return _context12.stop();
|
|
1234
1557
|
}
|
|
1235
|
-
},
|
|
1558
|
+
}, _callee12, this, [[7, 22, 25, 28], [37, 60, 63, 66], [70, 75]]);
|
|
1236
1559
|
}));
|
|
1237
|
-
function upsertPendingSyncOrders(
|
|
1560
|
+
function upsertPendingSyncOrders(_x9) {
|
|
1238
1561
|
return _upsertPendingSyncOrders.apply(this, arguments);
|
|
1239
1562
|
}
|
|
1240
1563
|
return upsertPendingSyncOrders;
|
|
1241
1564
|
}()
|
|
1242
1565
|
/**
|
|
1243
|
-
*
|
|
1566
|
+
* 将 POS 草稿订单按 SQLite storage key 落库。
|
|
1567
|
+
* 只有具备真实 order_id 的草稿进入 store;其余草稿仅供本地恢复查询。
|
|
1244
1568
|
*/
|
|
1245
1569
|
)
|
|
1246
1570
|
}, {
|
|
1247
|
-
key: "
|
|
1571
|
+
key: "upsertLocalDraftOrders",
|
|
1248
1572
|
value: (function () {
|
|
1249
|
-
var
|
|
1250
|
-
var
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
while (1) switch (_context12.prev = _context12.next) {
|
|
1573
|
+
var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(draftOrders) {
|
|
1574
|
+
var _this10 = this;
|
|
1575
|
+
var draftMap, memoryDraftMap, _iterator8, _step8, order, draftOrder, storageKey, memoryDraftOrder, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, _iterator9, _step9, key, _iterator10, _step10, _step10$value, _storageKey2, _draftOrder, matchIndex, mergedOrder, nextOrder, insertIndex, previousList, removedLegacyMemoryDraft;
|
|
1576
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1577
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1255
1578
|
case 0:
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
_context12.next = 3;
|
|
1579
|
+
if (draftOrders !== null && draftOrders !== void 0 && draftOrders.length) {
|
|
1580
|
+
_context13.next = 3;
|
|
1259
1581
|
break;
|
|
1260
1582
|
}
|
|
1261
|
-
|
|
1583
|
+
this.logInfo('upsertLocalDraftOrders-订单列表为空', {});
|
|
1584
|
+
return _context13.abrupt("return");
|
|
1262
1585
|
case 3:
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1586
|
+
draftMap = new Map();
|
|
1587
|
+
memoryDraftMap = new Map();
|
|
1588
|
+
_iterator8 = _createForOfIteratorHelper(draftOrders);
|
|
1589
|
+
_context13.prev = 6;
|
|
1590
|
+
_iterator8.s();
|
|
1591
|
+
case 8:
|
|
1592
|
+
if ((_step8 = _iterator8.n()).done) {
|
|
1593
|
+
_context13.next = 19;
|
|
1594
|
+
break;
|
|
1595
|
+
}
|
|
1596
|
+
order = _step8.value;
|
|
1597
|
+
draftOrder = _objectSpread(_objectSpread({}, order), {}, {
|
|
1598
|
+
need_sync: 0,
|
|
1599
|
+
is_draft_order: 1
|
|
1600
|
+
});
|
|
1601
|
+
storageKey = this.getOrderStorageKey(draftOrder);
|
|
1602
|
+
if (storageKey) {
|
|
1603
|
+
_context13.next = 14;
|
|
1604
|
+
break;
|
|
1605
|
+
}
|
|
1606
|
+
return _context13.abrupt("continue", 17);
|
|
1607
|
+
case 14:
|
|
1608
|
+
draftMap.set(storageKey, draftOrder);
|
|
1609
|
+
memoryDraftOrder = this.normalizeOrderForMemoryList(draftOrder);
|
|
1610
|
+
if (this.shouldKeepOrderInMemory(memoryDraftOrder)) {
|
|
1611
|
+
memoryDraftMap.set(storageKey, memoryDraftOrder);
|
|
1612
|
+
}
|
|
1613
|
+
case 17:
|
|
1614
|
+
_context13.next = 8;
|
|
1615
|
+
break;
|
|
1616
|
+
case 19:
|
|
1617
|
+
_context13.next = 24;
|
|
1618
|
+
break;
|
|
1619
|
+
case 21:
|
|
1620
|
+
_context13.prev = 21;
|
|
1621
|
+
_context13.t0 = _context13["catch"](6);
|
|
1622
|
+
_iterator8.e(_context13.t0);
|
|
1623
|
+
case 24:
|
|
1624
|
+
_context13.prev = 24;
|
|
1625
|
+
_iterator8.f();
|
|
1626
|
+
return _context13.finish(24);
|
|
1627
|
+
case 27:
|
|
1628
|
+
if (!(draftMap.size === 0)) {
|
|
1629
|
+
_context13.next = 30;
|
|
1630
|
+
break;
|
|
1631
|
+
}
|
|
1632
|
+
this.logError('upsertLocalDraftOrders-订单缺少可落库标识', {
|
|
1633
|
+
count: draftOrders.length
|
|
1634
|
+
});
|
|
1635
|
+
return _context13.abrupt("return");
|
|
1636
|
+
case 30:
|
|
1637
|
+
this.logInfo('upsertLocalDraftOrders-开始', {
|
|
1638
|
+
count: draftMap.size,
|
|
1639
|
+
memoryDraftCount: memoryDraftMap.size,
|
|
1640
|
+
sqliteOnlyDraftCount: draftMap.size - memoryDraftMap.size
|
|
1641
|
+
});
|
|
1642
|
+
patchedOrders = _toConsumableArray(draftMap.values());
|
|
1643
|
+
mergeActions = {};
|
|
1644
|
+
updatedList = this.store.list.filter(function (order) {
|
|
1645
|
+
return _this10.shouldKeepOrderInMemory(order);
|
|
1646
|
+
});
|
|
1647
|
+
identityKeyToIndex = new Map();
|
|
1648
|
+
for (index = 0; index < updatedList.length; index += 1) {
|
|
1649
|
+
_iterator9 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
|
|
1650
|
+
try {
|
|
1651
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
1652
|
+
key = _step9.value;
|
|
1653
|
+
if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
|
|
1654
|
+
}
|
|
1655
|
+
} catch (err) {
|
|
1656
|
+
_iterator9.e(err);
|
|
1657
|
+
} finally {
|
|
1658
|
+
_iterator9.f();
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
_iterator10 = _createForOfIteratorHelper(memoryDraftMap.entries());
|
|
1662
|
+
_context13.prev = 37;
|
|
1663
|
+
_iterator10.s();
|
|
1664
|
+
case 39:
|
|
1665
|
+
if ((_step10 = _iterator10.n()).done) {
|
|
1666
|
+
_context13.next = 55;
|
|
1667
|
+
break;
|
|
1668
|
+
}
|
|
1669
|
+
_step10$value = _slicedToArray(_step10.value, 2), _storageKey2 = _step10$value[0], _draftOrder = _step10$value[1];
|
|
1670
|
+
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
|
|
1671
|
+
if (!(matchIndex >= 0)) {
|
|
1672
|
+
_context13.next = 49;
|
|
1673
|
+
break;
|
|
1674
|
+
}
|
|
1675
|
+
mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], _draftOrder);
|
|
1676
|
+
nextOrder = _objectSpread(_objectSpread({}, mergedOrder), {}, {
|
|
1677
|
+
need_sync: 0,
|
|
1678
|
+
is_draft_order: 1
|
|
1679
|
+
});
|
|
1680
|
+
updatedList[matchIndex] = nextOrder;
|
|
1681
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
|
|
1682
|
+
mergeActions[_storageKey2] = 'update';
|
|
1683
|
+
return _context13.abrupt("continue", 53);
|
|
1684
|
+
case 49:
|
|
1685
|
+
insertIndex = updatedList.length;
|
|
1686
|
+
updatedList.push(_draftOrder);
|
|
1687
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
|
|
1688
|
+
mergeActions[_storageKey2] = 'insert';
|
|
1689
|
+
case 53:
|
|
1690
|
+
_context13.next = 39;
|
|
1691
|
+
break;
|
|
1692
|
+
case 55:
|
|
1693
|
+
_context13.next = 60;
|
|
1694
|
+
break;
|
|
1695
|
+
case 57:
|
|
1696
|
+
_context13.prev = 57;
|
|
1697
|
+
_context13.t1 = _context13["catch"](37);
|
|
1698
|
+
_iterator10.e(_context13.t1);
|
|
1699
|
+
case 60:
|
|
1700
|
+
_context13.prev = 60;
|
|
1701
|
+
_iterator10.f();
|
|
1702
|
+
return _context13.finish(60);
|
|
1703
|
+
case 63:
|
|
1704
|
+
previousList = this.store.list;
|
|
1705
|
+
this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
|
|
1706
|
+
this.syncOrdersMap();
|
|
1707
|
+
_context13.prev = 66;
|
|
1708
|
+
_context13.next = 69;
|
|
1709
|
+
return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
|
|
1710
|
+
throwOnError: true
|
|
1711
|
+
});
|
|
1712
|
+
case 69:
|
|
1713
|
+
_context13.next = 76;
|
|
1714
|
+
break;
|
|
1715
|
+
case 71:
|
|
1716
|
+
_context13.prev = 71;
|
|
1717
|
+
_context13.t2 = _context13["catch"](66);
|
|
1718
|
+
this.store.list = previousList;
|
|
1719
|
+
this.syncOrdersMap();
|
|
1720
|
+
throw _context13.t2;
|
|
1721
|
+
case 76:
|
|
1722
|
+
this.logInfo('upsertLocalDraftOrders-结束', {
|
|
1723
|
+
count: patchedOrders.length,
|
|
1724
|
+
storeOrderCountAfter: this.store.list.length
|
|
1725
|
+
});
|
|
1726
|
+
removedLegacyMemoryDraft = previousList.some(function (order) {
|
|
1727
|
+
return !_this10.shouldKeepOrderInMemory(order);
|
|
1728
|
+
});
|
|
1729
|
+
if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
|
|
1730
|
+
_context13.next = 81;
|
|
1731
|
+
break;
|
|
1732
|
+
}
|
|
1733
|
+
_context13.next = 81;
|
|
1734
|
+
return this.emitOrdersChanged(patchedOrders.filter(function (order) {
|
|
1735
|
+
return _this10.shouldKeepOrderInMemory(order);
|
|
1736
|
+
}), 'upsertLocalDraftOrders');
|
|
1737
|
+
case 81:
|
|
1738
|
+
case "end":
|
|
1739
|
+
return _context13.stop();
|
|
1740
|
+
}
|
|
1741
|
+
}, _callee13, this, [[6, 21, 24, 27], [37, 57, 60, 63], [66, 71]]);
|
|
1742
|
+
}));
|
|
1743
|
+
function upsertLocalDraftOrders(_x10) {
|
|
1744
|
+
return _upsertLocalDraftOrders.apply(this, arguments);
|
|
1745
|
+
}
|
|
1746
|
+
return upsertLocalDraftOrders;
|
|
1747
|
+
}()
|
|
1748
|
+
/**
|
|
1749
|
+
* 通过 SSE 按自定义 query 拉取订单(支持 select/with 精简字段)
|
|
1750
|
+
*/
|
|
1751
|
+
)
|
|
1752
|
+
}, {
|
|
1753
|
+
key: "fetchOrdersBySSE",
|
|
1754
|
+
value: (function () {
|
|
1755
|
+
var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
1756
|
+
var query,
|
|
1757
|
+
data,
|
|
1758
|
+
_args14 = arguments;
|
|
1759
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1760
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1761
|
+
case 0:
|
|
1762
|
+
query = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
|
|
1763
|
+
if (this.orderDataSource) {
|
|
1764
|
+
_context14.next = 3;
|
|
1765
|
+
break;
|
|
1766
|
+
}
|
|
1767
|
+
return _context14.abrupt("return", []);
|
|
1768
|
+
case 3:
|
|
1769
|
+
_context14.prev = 3;
|
|
1770
|
+
_context14.next = 6;
|
|
1771
|
+
return this.orderDataSource.run({
|
|
1772
|
+
sse: {
|
|
1773
|
+
query: query
|
|
1268
1774
|
}
|
|
1269
1775
|
});
|
|
1270
1776
|
case 6:
|
|
1271
|
-
data =
|
|
1272
|
-
return
|
|
1777
|
+
data = _context14.sent;
|
|
1778
|
+
return _context14.abrupt("return", data || []);
|
|
1273
1779
|
case 10:
|
|
1274
|
-
|
|
1275
|
-
|
|
1780
|
+
_context14.prev = 10;
|
|
1781
|
+
_context14.t0 = _context14["catch"](3);
|
|
1276
1782
|
this.logError('fetchOrdersBySSE-失败', {
|
|
1277
|
-
error:
|
|
1783
|
+
error: _context14.t0 instanceof Error ? _context14.t0.message : String(_context14.t0)
|
|
1278
1784
|
});
|
|
1279
|
-
return
|
|
1785
|
+
return _context14.abrupt("return", []);
|
|
1280
1786
|
case 14:
|
|
1281
1787
|
case "end":
|
|
1282
|
-
return
|
|
1788
|
+
return _context14.stop();
|
|
1283
1789
|
}
|
|
1284
|
-
},
|
|
1790
|
+
}, _callee14, this, [[3, 10]]);
|
|
1285
1791
|
}));
|
|
1286
1792
|
function fetchOrdersBySSE() {
|
|
1287
1793
|
return _fetchOrdersBySSE.apply(this, arguments);
|
|
@@ -1309,20 +1815,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1309
1815
|
}, {
|
|
1310
1816
|
key: "syncOrdersMap",
|
|
1311
1817
|
value: function syncOrdersMap() {
|
|
1818
|
+
var _this11 = this;
|
|
1819
|
+
this.store.list = this.store.list.filter(function (order) {
|
|
1820
|
+
return _this11.shouldKeepOrderInMemory(order);
|
|
1821
|
+
});
|
|
1312
1822
|
this.store.map.clear();
|
|
1313
|
-
var
|
|
1314
|
-
|
|
1823
|
+
var _iterator11 = _createForOfIteratorHelper(this.store.list),
|
|
1824
|
+
_step11;
|
|
1315
1825
|
try {
|
|
1316
|
-
for (
|
|
1317
|
-
var order =
|
|
1826
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
1827
|
+
var order = _step11.value;
|
|
1318
1828
|
var primaryIdentity = this.getOrderMapKey(order);
|
|
1319
1829
|
if (!primaryIdentity) continue;
|
|
1320
1830
|
this.store.map.set(primaryIdentity, order);
|
|
1321
1831
|
}
|
|
1322
1832
|
} catch (err) {
|
|
1323
|
-
|
|
1833
|
+
_iterator11.e(err);
|
|
1324
1834
|
} finally {
|
|
1325
|
-
|
|
1835
|
+
_iterator11.f();
|
|
1326
1836
|
}
|
|
1327
1837
|
}
|
|
1328
1838
|
}, {
|
|
@@ -1346,7 +1856,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1346
1856
|
}, {
|
|
1347
1857
|
key: "getOrderIdentityEntries",
|
|
1348
1858
|
value: function getOrderIdentityEntries(order) {
|
|
1349
|
-
var
|
|
1859
|
+
var _this12 = this;
|
|
1350
1860
|
if (!order) return [];
|
|
1351
1861
|
var record = order;
|
|
1352
1862
|
var candidates = [{
|
|
@@ -1365,8 +1875,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1365
1875
|
var entries = [];
|
|
1366
1876
|
var _loop = function _loop() {
|
|
1367
1877
|
var candidate = _candidates[_i2];
|
|
1368
|
-
if (
|
|
1369
|
-
var key =
|
|
1878
|
+
if (_this12.isBlankIdentityValue(candidate.value)) return 0; // continue
|
|
1879
|
+
var key = _this12.getIdKey(candidate.value);
|
|
1370
1880
|
if (entries.some(function (entry) {
|
|
1371
1881
|
return entry.field === candidate.field && entry.key === key;
|
|
1372
1882
|
})) return 0; // continue
|
|
@@ -1386,17 +1896,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1386
1896
|
key: "getOrderIdentityKeys",
|
|
1387
1897
|
value: function getOrderIdentityKeys(order) {
|
|
1388
1898
|
var keys = [];
|
|
1389
|
-
var
|
|
1390
|
-
|
|
1899
|
+
var _iterator12 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
|
|
1900
|
+
_step12;
|
|
1391
1901
|
try {
|
|
1392
|
-
for (
|
|
1393
|
-
var entry =
|
|
1902
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
1903
|
+
var entry = _step12.value;
|
|
1394
1904
|
if (!keys.includes(entry.key)) keys.push(entry.key);
|
|
1395
1905
|
}
|
|
1396
1906
|
} catch (err) {
|
|
1397
|
-
|
|
1907
|
+
_iterator12.e(err);
|
|
1398
1908
|
} finally {
|
|
1399
|
-
|
|
1909
|
+
_iterator12.f();
|
|
1400
1910
|
}
|
|
1401
1911
|
return keys;
|
|
1402
1912
|
}
|
|
@@ -1433,7 +1943,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1433
1943
|
}, {
|
|
1434
1944
|
key: "setupOrderSync",
|
|
1435
1945
|
value: function setupOrderSync() {
|
|
1436
|
-
var
|
|
1946
|
+
var _this13 = this;
|
|
1437
1947
|
if (!this.orderDataSource) return;
|
|
1438
1948
|
this.orderDataSource.run({
|
|
1439
1949
|
pubsub: {
|
|
@@ -1441,22 +1951,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1441
1951
|
var _message$id, _message$order_id, _message$type;
|
|
1442
1952
|
console.log('orderDataSource', res);
|
|
1443
1953
|
var pubsubReceivedAt = Date.now();
|
|
1444
|
-
var message =
|
|
1954
|
+
var message = _this13.normalizeOrderSyncMessage(res);
|
|
1445
1955
|
if (!message) return;
|
|
1446
1956
|
message._pubsubReceivedAt = pubsubReceivedAt;
|
|
1447
|
-
|
|
1448
|
-
var throttleMs =
|
|
1449
|
-
var routeInfo =
|
|
1450
|
-
|
|
1957
|
+
_this13.pendingSyncMessages.push(message);
|
|
1958
|
+
var throttleMs = _this13.getOrderSyncThrottleMs();
|
|
1959
|
+
var routeInfo = _this13.resolveSyncMessageRoute(message);
|
|
1960
|
+
_this13.logInfo('orderSync-收到消息并入队', {
|
|
1451
1961
|
id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
|
|
1452
1962
|
order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
|
|
1453
1963
|
type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
|
|
1454
|
-
pendingCount:
|
|
1964
|
+
pendingCount: _this13.pendingSyncMessages.length,
|
|
1455
1965
|
throttleMs: throttleMs,
|
|
1456
1966
|
pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
|
|
1457
1967
|
fullMessage: JSON.stringify(message)
|
|
1458
1968
|
});
|
|
1459
|
-
|
|
1969
|
+
_this13.scheduleOrderSyncThrottle();
|
|
1460
1970
|
}
|
|
1461
1971
|
}
|
|
1462
1972
|
}).catch(function () {
|
|
@@ -1473,7 +1983,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1473
1983
|
}, {
|
|
1474
1984
|
key: "scheduleOrderSyncThrottle",
|
|
1475
1985
|
value: function scheduleOrderSyncThrottle() {
|
|
1476
|
-
var
|
|
1986
|
+
var _this14 = this;
|
|
1477
1987
|
if (this.isProcessingSyncBatch) return;
|
|
1478
1988
|
if (this.isIdlePhase) {
|
|
1479
1989
|
this.isIdlePhase = false;
|
|
@@ -1484,8 +1994,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1484
1994
|
if (this.syncTimer) return;
|
|
1485
1995
|
var throttleMs = this.getOrderSyncThrottleMs();
|
|
1486
1996
|
this.syncTimer = setTimeout(function () {
|
|
1487
|
-
|
|
1488
|
-
void
|
|
1997
|
+
_this14.syncTimer = undefined;
|
|
1998
|
+
void _this14.flushOrderSyncMessagesByThrottle();
|
|
1489
1999
|
}, throttleMs);
|
|
1490
2000
|
}
|
|
1491
2001
|
|
|
@@ -1496,41 +2006,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1496
2006
|
}, {
|
|
1497
2007
|
key: "flushOrderSyncMessagesByThrottle",
|
|
1498
2008
|
value: (function () {
|
|
1499
|
-
var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1500
|
-
return _regeneratorRuntime().wrap(function
|
|
1501
|
-
while (1) switch (
|
|
2009
|
+
var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
2010
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
2011
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1502
2012
|
case 0:
|
|
1503
2013
|
if (!this.isProcessingSyncBatch) {
|
|
1504
|
-
|
|
2014
|
+
_context15.next = 2;
|
|
1505
2015
|
break;
|
|
1506
2016
|
}
|
|
1507
|
-
return
|
|
2017
|
+
return _context15.abrupt("return");
|
|
1508
2018
|
case 2:
|
|
1509
2019
|
if (!(this.pendingSyncMessages.length === 0)) {
|
|
1510
|
-
|
|
2020
|
+
_context15.next = 5;
|
|
1511
2021
|
break;
|
|
1512
2022
|
}
|
|
1513
2023
|
this.isIdlePhase = true;
|
|
1514
|
-
return
|
|
2024
|
+
return _context15.abrupt("return");
|
|
1515
2025
|
case 5:
|
|
1516
2026
|
this.isProcessingSyncBatch = true;
|
|
1517
|
-
|
|
1518
|
-
|
|
2027
|
+
_context15.prev = 6;
|
|
2028
|
+
_context15.next = 9;
|
|
1519
2029
|
return this.processOrderSyncMessages();
|
|
1520
2030
|
case 9:
|
|
1521
|
-
|
|
2031
|
+
_context15.prev = 9;
|
|
1522
2032
|
this.isProcessingSyncBatch = false;
|
|
1523
2033
|
if (this.pendingSyncMessages.length > 0) {
|
|
1524
2034
|
this.scheduleOrderSyncThrottle();
|
|
1525
2035
|
} else {
|
|
1526
2036
|
this.isIdlePhase = true;
|
|
1527
2037
|
}
|
|
1528
|
-
return
|
|
2038
|
+
return _context15.finish(9);
|
|
1529
2039
|
case 13:
|
|
1530
2040
|
case "end":
|
|
1531
|
-
return
|
|
2041
|
+
return _context15.stop();
|
|
1532
2042
|
}
|
|
1533
|
-
},
|
|
2043
|
+
}, _callee15, this, [[6,, 9, 13]]);
|
|
1534
2044
|
}));
|
|
1535
2045
|
function flushOrderSyncMessagesByThrottle() {
|
|
1536
2046
|
return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
|
|
@@ -1552,19 +2062,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1552
2062
|
}, {
|
|
1553
2063
|
key: "processOrderSyncMessages",
|
|
1554
2064
|
value: (function () {
|
|
1555
|
-
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1556
|
-
var
|
|
2065
|
+
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
|
|
2066
|
+
var _this15 = this;
|
|
1557
2067
|
var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
|
|
1558
|
-
return _regeneratorRuntime().wrap(function
|
|
1559
|
-
while (1) switch (
|
|
2068
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
2069
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1560
2070
|
case 0:
|
|
1561
2071
|
messages = _toConsumableArray(this.pendingSyncMessages);
|
|
1562
2072
|
this.pendingSyncMessages = [];
|
|
1563
2073
|
if (!(messages.length === 0)) {
|
|
1564
|
-
|
|
2074
|
+
_context16.next = 4;
|
|
1565
2075
|
break;
|
|
1566
2076
|
}
|
|
1567
|
-
return
|
|
2077
|
+
return _context16.abrupt("return");
|
|
1568
2078
|
case 4:
|
|
1569
2079
|
batchProcessStartAt = Date.now();
|
|
1570
2080
|
earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
|
|
@@ -1580,13 +2090,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1580
2090
|
upsertOrders = new Map();
|
|
1581
2091
|
refreshIds = [];
|
|
1582
2092
|
messages.forEach(function (msg, msgIndex) {
|
|
1583
|
-
var routeInfo =
|
|
2093
|
+
var routeInfo = _this15.resolveSyncMessageRoute(msg);
|
|
1584
2094
|
var hasBatchIds = routeInfo.hasBatchIds;
|
|
1585
2095
|
var singleId = routeInfo.singleId;
|
|
1586
2096
|
var hasSingleId = routeInfo.hasSingleId;
|
|
1587
|
-
var normalizedBody =
|
|
2097
|
+
var normalizedBody = _this15.normalizeOrderSyncPayload(msg.body || msg.data);
|
|
1588
2098
|
if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
|
|
1589
|
-
upsertOrders.set(
|
|
2099
|
+
upsertOrders.set(_this15.getIdKey(normalizedBody.order_id), normalizedBody);
|
|
1590
2100
|
return;
|
|
1591
2101
|
}
|
|
1592
2102
|
if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));else if (routeInfo.route === 'httpRefresh.singleId' && singleId !== null) refreshIds.push(singleId);else if (routeInfo.route === 'httpRefresh.relationIds') refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));
|
|
@@ -1598,41 +2108,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1598
2108
|
refreshIdCount: uniqueRefreshIds.length
|
|
1599
2109
|
});
|
|
1600
2110
|
if (!(upsertList.length > 0)) {
|
|
1601
|
-
|
|
2111
|
+
_context16.next = 16;
|
|
1602
2112
|
break;
|
|
1603
2113
|
}
|
|
1604
|
-
|
|
2114
|
+
_context16.next = 16;
|
|
1605
2115
|
return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
|
|
1606
2116
|
case 16:
|
|
1607
2117
|
if (!(uniqueRefreshIds.length > 0)) {
|
|
1608
|
-
|
|
2118
|
+
_context16.next = 28;
|
|
1609
2119
|
break;
|
|
1610
2120
|
}
|
|
1611
2121
|
_this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
|
|
1612
2122
|
if (skipped.length > 0) {}
|
|
1613
2123
|
if (!(toFetch.length > 0)) {
|
|
1614
|
-
|
|
2124
|
+
_context16.next = 28;
|
|
1615
2125
|
break;
|
|
1616
2126
|
}
|
|
1617
|
-
|
|
2127
|
+
_context16.next = 22;
|
|
1618
2128
|
return this.fetchOrdersByHttp(toFetch);
|
|
1619
2129
|
case 22:
|
|
1620
|
-
freshOrders =
|
|
2130
|
+
freshOrders = _context16.sent;
|
|
1621
2131
|
if (!(freshOrders.length > 0)) {
|
|
1622
|
-
|
|
2132
|
+
_context16.next = 28;
|
|
1623
2133
|
break;
|
|
1624
2134
|
}
|
|
1625
|
-
|
|
2135
|
+
_context16.next = 26;
|
|
1626
2136
|
return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
|
|
1627
2137
|
case 26:
|
|
1628
|
-
|
|
2138
|
+
_context16.next = 28;
|
|
1629
2139
|
break;
|
|
1630
2140
|
case 28:
|
|
1631
2141
|
if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
|
|
1632
|
-
|
|
2142
|
+
_context16.next = 30;
|
|
1633
2143
|
break;
|
|
1634
2144
|
}
|
|
1635
|
-
return
|
|
2145
|
+
return _context16.abrupt("return");
|
|
1636
2146
|
case 30:
|
|
1637
2147
|
batchProcessEndAt = Date.now();
|
|
1638
2148
|
this.logInfo('processOrderSyncMessages-结束', {
|
|
@@ -1641,13 +2151,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1641
2151
|
batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
|
|
1642
2152
|
totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
|
|
1643
2153
|
});
|
|
1644
|
-
|
|
2154
|
+
_context16.next = 34;
|
|
1645
2155
|
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
1646
2156
|
case 34:
|
|
1647
2157
|
case "end":
|
|
1648
|
-
return
|
|
2158
|
+
return _context16.stop();
|
|
1649
2159
|
}
|
|
1650
|
-
},
|
|
2160
|
+
}, _callee16, this);
|
|
1651
2161
|
}));
|
|
1652
2162
|
function processOrderSyncMessages() {
|
|
1653
2163
|
return _processOrderSyncMessages.apply(this, arguments);
|
|
@@ -1668,29 +2178,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1668
2178
|
}, {
|
|
1669
2179
|
key: "fetchOrdersByHttp",
|
|
1670
2180
|
value: (function () {
|
|
1671
|
-
var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2181
|
+
var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(ids) {
|
|
1672
2182
|
var _orderList, orderList;
|
|
1673
|
-
return _regeneratorRuntime().wrap(function
|
|
1674
|
-
while (1) switch (
|
|
2183
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
2184
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1675
2185
|
case 0:
|
|
1676
2186
|
if (!(!this.orderDataSource || ids.length === 0)) {
|
|
1677
|
-
|
|
2187
|
+
_context17.next = 2;
|
|
1678
2188
|
break;
|
|
1679
2189
|
}
|
|
1680
|
-
return
|
|
2190
|
+
return _context17.abrupt("return", []);
|
|
1681
2191
|
case 2:
|
|
1682
|
-
|
|
2192
|
+
_context17.prev = 2;
|
|
1683
2193
|
if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
|
|
1684
|
-
|
|
2194
|
+
_context17.next = 8;
|
|
1685
2195
|
break;
|
|
1686
2196
|
}
|
|
1687
|
-
|
|
2197
|
+
_context17.next = 6;
|
|
1688
2198
|
return this.orderDataSource.fetchOrdersByIds(ids);
|
|
1689
2199
|
case 6:
|
|
1690
|
-
_orderList =
|
|
1691
|
-
return
|
|
2200
|
+
_orderList = _context17.sent;
|
|
2201
|
+
return _context17.abrupt("return", _orderList || []);
|
|
1692
2202
|
case 8:
|
|
1693
|
-
|
|
2203
|
+
_context17.next = 10;
|
|
1694
2204
|
return this.orderDataSource.run({
|
|
1695
2205
|
http: {
|
|
1696
2206
|
query: {
|
|
@@ -1699,19 +2209,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1699
2209
|
}
|
|
1700
2210
|
});
|
|
1701
2211
|
case 10:
|
|
1702
|
-
orderList =
|
|
1703
|
-
return
|
|
2212
|
+
orderList = _context17.sent;
|
|
2213
|
+
return _context17.abrupt("return", orderList || []);
|
|
1704
2214
|
case 14:
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
return
|
|
2215
|
+
_context17.prev = 14;
|
|
2216
|
+
_context17.t0 = _context17["catch"](2);
|
|
2217
|
+
return _context17.abrupt("return", []);
|
|
1708
2218
|
case 17:
|
|
1709
2219
|
case "end":
|
|
1710
|
-
return
|
|
2220
|
+
return _context17.stop();
|
|
1711
2221
|
}
|
|
1712
|
-
},
|
|
2222
|
+
}, _callee17, this, [[2, 14]]);
|
|
1713
2223
|
}));
|
|
1714
|
-
function fetchOrdersByHttp(
|
|
2224
|
+
function fetchOrdersByHttp(_x11) {
|
|
1715
2225
|
return _fetchOrdersByHttp.apply(this, arguments);
|
|
1716
2226
|
}
|
|
1717
2227
|
return fetchOrdersByHttp;
|
|
@@ -1723,11 +2233,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1723
2233
|
}, {
|
|
1724
2234
|
key: "mergeOrdersToStore",
|
|
1725
2235
|
value: (function () {
|
|
1726
|
-
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1727
|
-
var
|
|
1728
|
-
var storeOrderCountBefore, normalizedFreshOrders,
|
|
1729
|
-
return _regeneratorRuntime().wrap(function
|
|
1730
|
-
while (1) switch (
|
|
2236
|
+
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(freshOrders, source) {
|
|
2237
|
+
var _this16 = this;
|
|
2238
|
+
var storeOrderCountBefore, normalizedFreshOrders, _iterator13, _step13, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator14, _step14, key, _iterator15, _step15, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _ref, _existingOrder$order_, _ref2, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, _ref3, _existingOrder$order_2, _ref4, _external_sale_number3, _existingOrder$is_dra, _fresh$is_draft_order, mergedOrder, adjustedMatchIndex, duplicateIndexes, _iterator16, _step16, _key2, _duplicateIndex, _iterator17, _step17, duplicateIndex, _index, _iterator18, _step18, _key, insertIndex, insertCount, updateCount;
|
|
2239
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
2240
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1731
2241
|
case 0:
|
|
1732
2242
|
storeOrderCountBefore = this.store.list.length;
|
|
1733
2243
|
this.logInfo('mergeOrdersToStore-开始', {
|
|
@@ -1737,37 +2247,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1737
2247
|
});
|
|
1738
2248
|
this.logDuplicateOrders("".concat(source, ".beforeMerge"), this.store.list);
|
|
1739
2249
|
normalizedFreshOrders = [];
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
2250
|
+
_iterator13 = _createForOfIteratorHelper(freshOrders);
|
|
2251
|
+
_context18.prev = 5;
|
|
2252
|
+
_iterator13.s();
|
|
1743
2253
|
case 7:
|
|
1744
|
-
if ((
|
|
1745
|
-
|
|
2254
|
+
if ((_step13 = _iterator13.n()).done) {
|
|
2255
|
+
_context18.next = 15;
|
|
1746
2256
|
break;
|
|
1747
2257
|
}
|
|
1748
|
-
order =
|
|
2258
|
+
order = _step13.value;
|
|
1749
2259
|
id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
1750
2260
|
if (!(id === undefined || id === null)) {
|
|
1751
|
-
|
|
2261
|
+
_context18.next = 12;
|
|
1752
2262
|
break;
|
|
1753
2263
|
}
|
|
1754
|
-
return
|
|
2264
|
+
return _context18.abrupt("continue", 13);
|
|
1755
2265
|
case 12:
|
|
1756
2266
|
normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
|
|
1757
2267
|
case 13:
|
|
1758
|
-
|
|
2268
|
+
_context18.next = 7;
|
|
1759
2269
|
break;
|
|
1760
2270
|
case 15:
|
|
1761
|
-
|
|
2271
|
+
_context18.next = 20;
|
|
1762
2272
|
break;
|
|
1763
2273
|
case 17:
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
2274
|
+
_context18.prev = 17;
|
|
2275
|
+
_context18.t0 = _context18["catch"](5);
|
|
2276
|
+
_iterator13.e(_context18.t0);
|
|
1767
2277
|
case 20:
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
return
|
|
2278
|
+
_context18.prev = 20;
|
|
2279
|
+
_iterator13.f();
|
|
2280
|
+
return _context18.finish(20);
|
|
1771
2281
|
case 23:
|
|
1772
2282
|
// 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
|
|
1773
2283
|
uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
|
|
@@ -1775,89 +2285,168 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1775
2285
|
patchedOrders = [];
|
|
1776
2286
|
mergeActions = {};
|
|
1777
2287
|
updatedList = this.store.list.map(function (order) {
|
|
1778
|
-
return
|
|
2288
|
+
return _this16.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
|
|
1779
2289
|
}); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
|
|
1780
2290
|
// 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
|
|
1781
2291
|
// 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
|
|
1782
2292
|
identityKeyToIndex = new Map();
|
|
1783
2293
|
for (index = 0; index < updatedList.length; index += 1) {
|
|
1784
2294
|
identityKeys = this.getOrderIdentityMatchKeys(updatedList[index]);
|
|
1785
|
-
|
|
2295
|
+
_iterator14 = _createForOfIteratorHelper(identityKeys);
|
|
1786
2296
|
try {
|
|
1787
|
-
for (
|
|
1788
|
-
key =
|
|
2297
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
2298
|
+
key = _step14.value;
|
|
1789
2299
|
// 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
|
|
1790
2300
|
if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
|
|
1791
2301
|
}
|
|
1792
2302
|
} catch (err) {
|
|
1793
|
-
|
|
2303
|
+
_iterator14.e(err);
|
|
1794
2304
|
} finally {
|
|
1795
|
-
|
|
2305
|
+
_iterator14.f();
|
|
1796
2306
|
}
|
|
1797
2307
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
2308
|
+
_iterator15 = _createForOfIteratorHelper(uniqueFreshOrders);
|
|
2309
|
+
_context18.prev = 31;
|
|
2310
|
+
_iterator15.s();
|
|
1801
2311
|
case 33:
|
|
1802
|
-
if ((
|
|
1803
|
-
|
|
2312
|
+
if ((_step15 = _iterator15.n()).done) {
|
|
2313
|
+
_context18.next = 82;
|
|
1804
2314
|
break;
|
|
1805
2315
|
}
|
|
1806
|
-
fresh =
|
|
2316
|
+
fresh = _step15.value;
|
|
1807
2317
|
freshIdentityKeys = this.getOrderIdentityMatchKeys(fresh);
|
|
1808
2318
|
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys);
|
|
1809
2319
|
storageKey = this.getOrderStorageKey(fresh);
|
|
1810
2320
|
mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
|
|
1811
2321
|
if (!(matchIndex >= 0)) {
|
|
1812
|
-
|
|
2322
|
+
_context18.next = 75;
|
|
1813
2323
|
break;
|
|
1814
2324
|
}
|
|
1815
2325
|
existingOrder = updatedList[matchIndex];
|
|
1816
2326
|
if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
|
|
1817
|
-
|
|
2327
|
+
_context18.next = 44;
|
|
1818
2328
|
break;
|
|
1819
2329
|
}
|
|
1820
2330
|
this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
|
|
1821
2331
|
source: source,
|
|
1822
|
-
order_id: (
|
|
1823
|
-
external_sale_number: (
|
|
2332
|
+
order_id: (_ref = (_existingOrder$order_ = existingOrder.order_id) !== null && _existingOrder$order_ !== void 0 ? _existingOrder$order_ : fresh.order_id) !== null && _ref !== void 0 ? _ref : null,
|
|
2333
|
+
external_sale_number: (_ref2 = (_external_sale_number2 = existingOrder.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : fresh.external_sale_number) !== null && _ref2 !== void 0 ? _ref2 : null,
|
|
1824
2334
|
local_payment_status: (_existingOrder$paymen = existingOrder.payment_status) !== null && _existingOrder$paymen !== void 0 ? _existingOrder$paymen : null,
|
|
1825
2335
|
remote_payment_status: (_fresh$payment_status = fresh.payment_status) !== null && _fresh$payment_status !== void 0 ? _fresh$payment_status : null,
|
|
1826
2336
|
local_need_sync: (_existingOrder$need_s = existingOrder.need_sync) !== null && _existingOrder$need_s !== void 0 ? _existingOrder$need_s : null,
|
|
1827
2337
|
remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
|
|
1828
2338
|
reason: 'protect_pending_sync_order_from_remote_echo'
|
|
1829
2339
|
});
|
|
1830
|
-
return
|
|
2340
|
+
return _context18.abrupt("continue", 80);
|
|
1831
2341
|
case 44:
|
|
2342
|
+
if (!(this.isDraftOrder(existingOrder) && this.shouldProtectDraftOrderFromIncoming(source))) {
|
|
2343
|
+
_context18.next = 47;
|
|
2344
|
+
break;
|
|
2345
|
+
}
|
|
2346
|
+
this.logInfo('mergeOrdersToStore-跳过 draft 订单远端覆盖', {
|
|
2347
|
+
source: source,
|
|
2348
|
+
order_id: (_ref3 = (_existingOrder$order_2 = existingOrder.order_id) !== null && _existingOrder$order_2 !== void 0 ? _existingOrder$order_2 : fresh.order_id) !== null && _ref3 !== void 0 ? _ref3 : null,
|
|
2349
|
+
external_sale_number: (_ref4 = (_external_sale_number3 = existingOrder.external_sale_number) !== null && _external_sale_number3 !== void 0 ? _external_sale_number3 : fresh.external_sale_number) !== null && _ref4 !== void 0 ? _ref4 : null,
|
|
2350
|
+
local_is_draft_order: (_existingOrder$is_dra = existingOrder.is_draft_order) !== null && _existingOrder$is_dra !== void 0 ? _existingOrder$is_dra : null,
|
|
2351
|
+
remote_is_draft_order: (_fresh$is_draft_order = fresh.is_draft_order) !== null && _fresh$is_draft_order !== void 0 ? _fresh$is_draft_order : null,
|
|
2352
|
+
reason: 'protect_draft_order_from_remote_echo'
|
|
2353
|
+
});
|
|
2354
|
+
return _context18.abrupt("continue", 80);
|
|
2355
|
+
case 47:
|
|
1832
2356
|
mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
|
|
1833
|
-
|
|
2357
|
+
adjustedMatchIndex = matchIndex;
|
|
2358
|
+
duplicateIndexes = new Set();
|
|
2359
|
+
_iterator16 = _createForOfIteratorHelper(freshIdentityKeys);
|
|
2360
|
+
_context18.prev = 51;
|
|
2361
|
+
_iterator16.s();
|
|
2362
|
+
case 53:
|
|
2363
|
+
if ((_step16 = _iterator16.n()).done) {
|
|
2364
|
+
_context18.next = 61;
|
|
2365
|
+
break;
|
|
2366
|
+
}
|
|
2367
|
+
_key2 = _step16.value;
|
|
2368
|
+
_duplicateIndex = identityKeyToIndex.get(_key2);
|
|
2369
|
+
if (!(_duplicateIndex === undefined || _duplicateIndex === matchIndex)) {
|
|
2370
|
+
_context18.next = 58;
|
|
2371
|
+
break;
|
|
2372
|
+
}
|
|
2373
|
+
return _context18.abrupt("continue", 59);
|
|
2374
|
+
case 58:
|
|
2375
|
+
duplicateIndexes.add(_duplicateIndex);
|
|
2376
|
+
case 59:
|
|
2377
|
+
_context18.next = 53;
|
|
2378
|
+
break;
|
|
2379
|
+
case 61:
|
|
2380
|
+
_context18.next = 66;
|
|
2381
|
+
break;
|
|
2382
|
+
case 63:
|
|
2383
|
+
_context18.prev = 63;
|
|
2384
|
+
_context18.t1 = _context18["catch"](51);
|
|
2385
|
+
_iterator16.e(_context18.t1);
|
|
2386
|
+
case 66:
|
|
2387
|
+
_context18.prev = 66;
|
|
2388
|
+
_iterator16.f();
|
|
2389
|
+
return _context18.finish(66);
|
|
2390
|
+
case 69:
|
|
2391
|
+
if (duplicateIndexes.size > 0) {
|
|
2392
|
+
_iterator17 = _createForOfIteratorHelper(_toConsumableArray(duplicateIndexes).sort(function (left, right) {
|
|
2393
|
+
return right - left;
|
|
2394
|
+
}));
|
|
2395
|
+
try {
|
|
2396
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
2397
|
+
duplicateIndex = _step17.value;
|
|
2398
|
+
mergedOrder = this.mergeOrderRecords(mergedOrder, updatedList[duplicateIndex]);
|
|
2399
|
+
updatedList.splice(duplicateIndex, 1);
|
|
2400
|
+
if (duplicateIndex < adjustedMatchIndex) adjustedMatchIndex -= 1;
|
|
2401
|
+
}
|
|
2402
|
+
} catch (err) {
|
|
2403
|
+
_iterator17.e(err);
|
|
2404
|
+
} finally {
|
|
2405
|
+
_iterator17.f();
|
|
2406
|
+
}
|
|
2407
|
+
identityKeyToIndex.clear();
|
|
2408
|
+
for (_index = 0; _index < updatedList.length; _index += 1) {
|
|
2409
|
+
_iterator18 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[_index]));
|
|
2410
|
+
try {
|
|
2411
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
2412
|
+
_key = _step18.value;
|
|
2413
|
+
if (!identityKeyToIndex.has(_key)) identityKeyToIndex.set(_key, _index);
|
|
2414
|
+
}
|
|
2415
|
+
} catch (err) {
|
|
2416
|
+
_iterator18.e(err);
|
|
2417
|
+
} finally {
|
|
2418
|
+
_iterator18.f();
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
updatedList[adjustedMatchIndex] = mergedOrder;
|
|
1834
2423
|
// 合并后身份字段可能新增(如挂单拿到 order_id),同步登记到索引,
|
|
1835
2424
|
// 供同批后续 fresh 命中同一槽位,避免重复插入
|
|
1836
|
-
this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder,
|
|
2425
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, adjustedMatchIndex);
|
|
1837
2426
|
patchedOrders.push(mergedOrder);
|
|
1838
2427
|
if (mergeKey) mergeActions[mergeKey] = 'update';
|
|
1839
|
-
return
|
|
1840
|
-
case
|
|
2428
|
+
return _context18.abrupt("continue", 80);
|
|
2429
|
+
case 75:
|
|
1841
2430
|
insertIndex = updatedList.length;
|
|
1842
2431
|
updatedList.push(fresh);
|
|
1843
2432
|
this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
|
|
1844
2433
|
patchedOrders.push(fresh);
|
|
1845
2434
|
if (mergeKey) mergeActions[mergeKey] = 'insert';
|
|
1846
|
-
case
|
|
1847
|
-
|
|
2435
|
+
case 80:
|
|
2436
|
+
_context18.next = 33;
|
|
1848
2437
|
break;
|
|
1849
|
-
case
|
|
1850
|
-
|
|
2438
|
+
case 82:
|
|
2439
|
+
_context18.next = 87;
|
|
1851
2440
|
break;
|
|
1852
|
-
case
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
case
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
return
|
|
1860
|
-
case
|
|
2441
|
+
case 84:
|
|
2442
|
+
_context18.prev = 84;
|
|
2443
|
+
_context18.t2 = _context18["catch"](31);
|
|
2444
|
+
_iterator15.e(_context18.t2);
|
|
2445
|
+
case 87:
|
|
2446
|
+
_context18.prev = 87;
|
|
2447
|
+
_iterator15.f();
|
|
2448
|
+
return _context18.finish(87);
|
|
2449
|
+
case 90:
|
|
1861
2450
|
insertCount = Object.values(mergeActions).filter(function (v) {
|
|
1862
2451
|
return v === 'insert';
|
|
1863
2452
|
}).length;
|
|
@@ -1873,24 +2462,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1873
2462
|
// 仅在自检开关开启时做一次兜底校验。
|
|
1874
2463
|
this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
|
|
1875
2464
|
this.syncOrdersMap();
|
|
1876
|
-
|
|
2465
|
+
_context18.next = 97;
|
|
1877
2466
|
return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
|
|
1878
|
-
case
|
|
2467
|
+
case 97:
|
|
1879
2468
|
this.logInfo('mergeOrdersToStore-结束', {
|
|
1880
2469
|
uniqueFreshCount: uniqueFreshCount,
|
|
1881
2470
|
storeOrderCountAfter: this.store.list.length,
|
|
1882
2471
|
insertCount: insertCount,
|
|
1883
2472
|
updateCount: updateCount
|
|
1884
2473
|
});
|
|
1885
|
-
|
|
2474
|
+
_context18.next = 100;
|
|
1886
2475
|
return this.emitOrdersChanged(patchedOrders, source);
|
|
1887
|
-
case
|
|
2476
|
+
case 100:
|
|
1888
2477
|
case "end":
|
|
1889
|
-
return
|
|
2478
|
+
return _context18.stop();
|
|
1890
2479
|
}
|
|
1891
|
-
},
|
|
2480
|
+
}, _callee18, this, [[5, 17, 20, 23], [31, 84, 87, 90], [51, 63, 66, 69]]);
|
|
1892
2481
|
}));
|
|
1893
|
-
function mergeOrdersToStore(
|
|
2482
|
+
function mergeOrdersToStore(_x12, _x13) {
|
|
1894
2483
|
return _mergeOrdersToStore.apply(this, arguments);
|
|
1895
2484
|
}
|
|
1896
2485
|
return mergeOrdersToStore;
|
|
@@ -1907,19 +2496,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1907
2496
|
key: "lookupOrderIndexByIdentityKeys",
|
|
1908
2497
|
value: function lookupOrderIndexByIdentityKeys(identityKeyToIndex, identityKeys) {
|
|
1909
2498
|
var matchIndex = -1;
|
|
1910
|
-
var
|
|
1911
|
-
|
|
2499
|
+
var _iterator19 = _createForOfIteratorHelper(identityKeys),
|
|
2500
|
+
_step19;
|
|
1912
2501
|
try {
|
|
1913
|
-
for (
|
|
1914
|
-
var key =
|
|
2502
|
+
for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
|
|
2503
|
+
var key = _step19.value;
|
|
1915
2504
|
var index = identityKeyToIndex.get(key);
|
|
1916
2505
|
if (index === undefined) continue;
|
|
1917
2506
|
if (matchIndex < 0 || index < matchIndex) matchIndex = index;
|
|
1918
2507
|
}
|
|
1919
2508
|
} catch (err) {
|
|
1920
|
-
|
|
2509
|
+
_iterator19.e(err);
|
|
1921
2510
|
} finally {
|
|
1922
|
-
|
|
2511
|
+
_iterator19.f();
|
|
1923
2512
|
}
|
|
1924
2513
|
return matchIndex;
|
|
1925
2514
|
}
|
|
@@ -1940,17 +2529,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1940
2529
|
key: "registerOrderIdentityKeys",
|
|
1941
2530
|
value: function registerOrderIdentityKeys(identityKeyToIndex, order, index) {
|
|
1942
2531
|
var identityKeys = this.getOrderIdentityMatchKeys(order);
|
|
1943
|
-
var
|
|
1944
|
-
|
|
2532
|
+
var _iterator20 = _createForOfIteratorHelper(identityKeys),
|
|
2533
|
+
_step20;
|
|
1945
2534
|
try {
|
|
1946
|
-
for (
|
|
1947
|
-
var key =
|
|
2535
|
+
for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
|
|
2536
|
+
var key = _step20.value;
|
|
1948
2537
|
identityKeyToIndex.set(key, index);
|
|
1949
2538
|
}
|
|
1950
2539
|
} catch (err) {
|
|
1951
|
-
|
|
2540
|
+
_iterator20.e(err);
|
|
1952
2541
|
} finally {
|
|
1953
|
-
|
|
2542
|
+
_iterator20.f();
|
|
1954
2543
|
}
|
|
1955
2544
|
}
|
|
1956
2545
|
|
|
@@ -2005,17 +2594,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2005
2594
|
key: "uniqueOrderIds",
|
|
2006
2595
|
value: function uniqueOrderIds(ids) {
|
|
2007
2596
|
var idMap = new Map();
|
|
2008
|
-
var
|
|
2009
|
-
|
|
2597
|
+
var _iterator21 = _createForOfIteratorHelper(ids),
|
|
2598
|
+
_step21;
|
|
2010
2599
|
try {
|
|
2011
|
-
for (
|
|
2012
|
-
var id =
|
|
2600
|
+
for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
|
|
2601
|
+
var id = _step21.value;
|
|
2013
2602
|
idMap.set(this.getIdKey(id), id);
|
|
2014
2603
|
}
|
|
2015
2604
|
} catch (err) {
|
|
2016
|
-
|
|
2605
|
+
_iterator21.e(err);
|
|
2017
2606
|
} finally {
|
|
2018
|
-
|
|
2607
|
+
_iterator21.f();
|
|
2019
2608
|
}
|
|
2020
2609
|
return _toConsumableArray(idMap.values());
|
|
2021
2610
|
}
|
|
@@ -2027,12 +2616,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2027
2616
|
}, {
|
|
2028
2617
|
key: "isOrderLookupMatch",
|
|
2029
2618
|
value: function isOrderLookupMatch(order, lookupKey) {
|
|
2030
|
-
var
|
|
2619
|
+
var _this17 = this;
|
|
2031
2620
|
if (!order || !lookupKey) return false;
|
|
2032
2621
|
var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
|
|
2033
2622
|
return candidates.some(function (value) {
|
|
2034
2623
|
if (value === undefined || value === null || value === '') return false;
|
|
2035
|
-
return
|
|
2624
|
+
return _this17.getIdKey(value) === lookupKey;
|
|
2036
2625
|
});
|
|
2037
2626
|
}
|
|
2038
2627
|
|
|
@@ -2075,10 +2664,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2075
2664
|
}, {
|
|
2076
2665
|
key: "findOrderIndexByIdentity",
|
|
2077
2666
|
value: function findOrderIndexByIdentity(orders, target) {
|
|
2078
|
-
var
|
|
2667
|
+
var _this18 = this;
|
|
2079
2668
|
if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
|
|
2080
2669
|
return orders.findIndex(function (order) {
|
|
2081
|
-
return
|
|
2670
|
+
return _this18.doOrdersShareIdentity(order, target);
|
|
2082
2671
|
});
|
|
2083
2672
|
}
|
|
2084
2673
|
}, {
|
|
@@ -2102,6 +2691,121 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2102
2691
|
if (rightScore >= leftScore) return right;
|
|
2103
2692
|
return left;
|
|
2104
2693
|
}
|
|
2694
|
+
}, {
|
|
2695
|
+
key: "getProductIdentityKeys",
|
|
2696
|
+
value: function getProductIdentityKeys(product) {
|
|
2697
|
+
var _record$metadata;
|
|
2698
|
+
var record = product;
|
|
2699
|
+
if (!record) return [];
|
|
2700
|
+
var keys = [];
|
|
2701
|
+
var metadataUid = (_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.unique_identification_number;
|
|
2702
|
+
if (!this.isBlankIdentityValue(metadataUid)) keys.push("uid:".concat(String(metadataUid)));
|
|
2703
|
+
var topLevelUid = record.unique_identification_number;
|
|
2704
|
+
if (!this.isBlankIdentityValue(topLevelUid)) keys.push("uid:".concat(String(topLevelUid)));
|
|
2705
|
+
var orderDetailId = record.order_detail_id;
|
|
2706
|
+
if (!this.isBlankIdentityValue(orderDetailId)) keys.push("detail:".concat(String(orderDetailId)));
|
|
2707
|
+
var bookingUid = record.booking_uid;
|
|
2708
|
+
if (!this.isBlankIdentityValue(bookingUid)) keys.push("booking:".concat(String(bookingUid)));
|
|
2709
|
+
return keys;
|
|
2710
|
+
}
|
|
2711
|
+
}, {
|
|
2712
|
+
key: "mergeOrderProductLists",
|
|
2713
|
+
value: function mergeOrderProductLists(preferred, secondary) {
|
|
2714
|
+
var preferredList = Array.isArray(preferred) ? preferred : [];
|
|
2715
|
+
var secondaryList = Array.isArray(secondary) ? secondary : [];
|
|
2716
|
+
if (secondaryList.length === 0) return preferredList;
|
|
2717
|
+
if (preferredList.length === 0) return secondaryList;
|
|
2718
|
+
var seenKeys = new Set();
|
|
2719
|
+
var _iterator22 = _createForOfIteratorHelper(preferredList),
|
|
2720
|
+
_step22;
|
|
2721
|
+
try {
|
|
2722
|
+
for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
|
|
2723
|
+
var item = _step22.value;
|
|
2724
|
+
var keys = this.getProductIdentityKeys(item);
|
|
2725
|
+
var _iterator24 = _createForOfIteratorHelper(keys),
|
|
2726
|
+
_step24;
|
|
2727
|
+
try {
|
|
2728
|
+
for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
|
|
2729
|
+
var key = _step24.value;
|
|
2730
|
+
seenKeys.add(key);
|
|
2731
|
+
}
|
|
2732
|
+
} catch (err) {
|
|
2733
|
+
_iterator24.e(err);
|
|
2734
|
+
} finally {
|
|
2735
|
+
_iterator24.f();
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
} catch (err) {
|
|
2739
|
+
_iterator22.e(err);
|
|
2740
|
+
} finally {
|
|
2741
|
+
_iterator22.f();
|
|
2742
|
+
}
|
|
2743
|
+
var result = _toConsumableArray(preferredList);
|
|
2744
|
+
var _iterator23 = _createForOfIteratorHelper(secondaryList),
|
|
2745
|
+
_step23;
|
|
2746
|
+
try {
|
|
2747
|
+
for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
|
|
2748
|
+
var _item = _step23.value;
|
|
2749
|
+
var _keys = this.getProductIdentityKeys(_item);
|
|
2750
|
+
if (_keys.length === 0 || _keys.some(function (key) {
|
|
2751
|
+
return seenKeys.has(key);
|
|
2752
|
+
})) continue;
|
|
2753
|
+
var _iterator25 = _createForOfIteratorHelper(_keys),
|
|
2754
|
+
_step25;
|
|
2755
|
+
try {
|
|
2756
|
+
for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
|
|
2757
|
+
var _key3 = _step25.value;
|
|
2758
|
+
seenKeys.add(_key3);
|
|
2759
|
+
}
|
|
2760
|
+
} catch (err) {
|
|
2761
|
+
_iterator25.e(err);
|
|
2762
|
+
} finally {
|
|
2763
|
+
_iterator25.f();
|
|
2764
|
+
}
|
|
2765
|
+
result.push(cloneDeep(_item));
|
|
2766
|
+
}
|
|
2767
|
+
} catch (err) {
|
|
2768
|
+
_iterator23.e(err);
|
|
2769
|
+
} finally {
|
|
2770
|
+
_iterator23.f();
|
|
2771
|
+
}
|
|
2772
|
+
return result;
|
|
2773
|
+
}
|
|
2774
|
+
}, {
|
|
2775
|
+
key: "mergeOrderPaymentLists",
|
|
2776
|
+
value: function mergeOrderPaymentLists(existing, incoming) {
|
|
2777
|
+
var existingList = Array.isArray(existing) ? existing : [];
|
|
2778
|
+
var incomingList = Array.isArray(incoming) ? incoming : [];
|
|
2779
|
+
if (incomingList.length === 0) return cloneDeep(existingList);
|
|
2780
|
+
return mergeOrderPaymentListsByIdentity(existingList, incomingList);
|
|
2781
|
+
}
|
|
2782
|
+
}, {
|
|
2783
|
+
key: "getIdentifiedPendingPayments",
|
|
2784
|
+
value: function getIdentifiedPendingPayments(order) {
|
|
2785
|
+
var payments = Array.isArray(order === null || order === void 0 ? void 0 : order.payments) ? order.payments : [];
|
|
2786
|
+
return payments.filter(function (payment) {
|
|
2787
|
+
return isIdentifiedPendingOrderPayment(payment);
|
|
2788
|
+
});
|
|
2789
|
+
}
|
|
2790
|
+
}, {
|
|
2791
|
+
key: "shouldProtectLocalOrderFromRemoteSnapshot",
|
|
2792
|
+
value: function shouldProtectLocalOrderFromRemoteSnapshot(order) {
|
|
2793
|
+
return this.isPendingSyncOrder(order) || this.isDraftOrder(order) || this.getIdentifiedPendingPayments(order).length > 0;
|
|
2794
|
+
}
|
|
2795
|
+
}, {
|
|
2796
|
+
key: "getUnmatchedIdentifiedPendingPayments",
|
|
2797
|
+
value: function getUnmatchedIdentifiedPendingPayments(existing, incoming) {
|
|
2798
|
+
var existingPayments = Array.isArray(existing) ? existing : [];
|
|
2799
|
+
var incomingPayments = Array.isArray(incoming) ? incoming : [];
|
|
2800
|
+
var incomingIdentityKeys = new Set(incomingPayments.flatMap(function (payment) {
|
|
2801
|
+
return getOrderPaymentIdentityKeys(payment);
|
|
2802
|
+
}));
|
|
2803
|
+
return existingPayments.filter(function (payment) {
|
|
2804
|
+
return isIdentifiedPendingOrderPayment(payment) && !getOrderPaymentIdentityKeys(payment).some(function (key) {
|
|
2805
|
+
return incomingIdentityKeys.has(key);
|
|
2806
|
+
});
|
|
2807
|
+
});
|
|
2808
|
+
}
|
|
2105
2809
|
}, {
|
|
2106
2810
|
key: "mergeOrderRecords",
|
|
2107
2811
|
value: function mergeOrderRecords(existing, incoming) {
|
|
@@ -2109,7 +2813,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2109
2813
|
var secondary = preferred === existing ? incoming : existing;
|
|
2110
2814
|
var merged = _objectSpread(_objectSpread({}, secondary), preferred);
|
|
2111
2815
|
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'];
|
|
2816
|
+
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
2817
|
var mergedRecord = merged;
|
|
2114
2818
|
var preferredRecord = preferred;
|
|
2115
2819
|
var secondaryRecord = secondary;
|
|
@@ -2139,7 +2843,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2139
2843
|
for (var _i6 = 0, _ORDER_AUTHORITATIVE_2 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i6 < _ORDER_AUTHORITATIVE_2.length; _i6++) {
|
|
2140
2844
|
var _field2 = _ORDER_AUTHORITATIVE_2[_i6];
|
|
2141
2845
|
if (Array.isArray(incomingRecord[_field2])) {
|
|
2142
|
-
|
|
2846
|
+
if (_field2 === 'payments') {
|
|
2847
|
+
var preservedPending = this.getUnmatchedIdentifiedPendingPayments(existingRecord[_field2], incomingRecord[_field2]);
|
|
2848
|
+
if (preservedPending.length > 0) {
|
|
2849
|
+
var _ref5, _existing$order_id, _ref6, _existingRecord$exter;
|
|
2850
|
+
this.logInfo('mergeOrderRecords-保留本地 pending 支付项', {
|
|
2851
|
+
order_id: (_ref5 = (_existing$order_id = existing.order_id) !== null && _existing$order_id !== void 0 ? _existing$order_id : incoming.order_id) !== null && _ref5 !== void 0 ? _ref5 : null,
|
|
2852
|
+
external_sale_number: (_ref6 = (_existingRecord$exter = existingRecord.external_sale_number) !== null && _existingRecord$exter !== void 0 ? _existingRecord$exter : incomingRecord.external_sale_number) !== null && _ref6 !== void 0 ? _ref6 : null,
|
|
2853
|
+
preserved_pending_count: preservedPending.length,
|
|
2854
|
+
preserved_payment_identities: preservedPending.map(function (payment) {
|
|
2855
|
+
return getOrderPaymentIdentityKeys(payment);
|
|
2856
|
+
})
|
|
2857
|
+
});
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
mergedRecord[_field2] = this.mergeAuthoritativeOrderCollection(_field2, existingRecord[_field2], incomingRecord[_field2], childUidRemaps, {
|
|
2861
|
+
preserveIdentifiedPendingPayments: _field2 === 'payments'
|
|
2862
|
+
});
|
|
2143
2863
|
continue;
|
|
2144
2864
|
}
|
|
2145
2865
|
if (Object.prototype.hasOwnProperty.call(existingRecord, _field2)) {
|
|
@@ -2157,50 +2877,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2157
2877
|
key: "summarizeDuplicateOrders",
|
|
2158
2878
|
value: function summarizeDuplicateOrders(orders) {
|
|
2159
2879
|
var groups = new Map();
|
|
2160
|
-
var
|
|
2161
|
-
|
|
2880
|
+
var _iterator26 = _createForOfIteratorHelper(orders),
|
|
2881
|
+
_step26;
|
|
2162
2882
|
try {
|
|
2163
|
-
for (
|
|
2164
|
-
var order =
|
|
2165
|
-
var
|
|
2166
|
-
|
|
2883
|
+
for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
|
|
2884
|
+
var order = _step26.value;
|
|
2885
|
+
var _iterator27 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
|
|
2886
|
+
_step27;
|
|
2167
2887
|
try {
|
|
2168
|
-
for (
|
|
2169
|
-
var key =
|
|
2888
|
+
for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
|
|
2889
|
+
var key = _step27.value;
|
|
2170
2890
|
var group = groups.get(key) || [];
|
|
2171
2891
|
group.push(order);
|
|
2172
2892
|
groups.set(key, group);
|
|
2173
2893
|
}
|
|
2174
2894
|
} catch (err) {
|
|
2175
|
-
|
|
2895
|
+
_iterator27.e(err);
|
|
2176
2896
|
} finally {
|
|
2177
|
-
|
|
2897
|
+
_iterator27.f();
|
|
2178
2898
|
}
|
|
2179
2899
|
}
|
|
2180
2900
|
} catch (err) {
|
|
2181
|
-
|
|
2901
|
+
_iterator26.e(err);
|
|
2182
2902
|
} finally {
|
|
2183
|
-
|
|
2903
|
+
_iterator26.f();
|
|
2184
2904
|
}
|
|
2185
|
-
return _toConsumableArray(groups.entries()).filter(function (
|
|
2186
|
-
var
|
|
2187
|
-
group =
|
|
2905
|
+
return _toConsumableArray(groups.entries()).filter(function (_ref7) {
|
|
2906
|
+
var _ref8 = _slicedToArray(_ref7, 2),
|
|
2907
|
+
group = _ref8[1];
|
|
2188
2908
|
return group.length > 1;
|
|
2189
|
-
}).slice(0, 20).map(function (
|
|
2190
|
-
var
|
|
2191
|
-
key =
|
|
2192
|
-
group =
|
|
2909
|
+
}).slice(0, 20).map(function (_ref9) {
|
|
2910
|
+
var _ref10 = _slicedToArray(_ref9, 2),
|
|
2911
|
+
key = _ref10[0],
|
|
2912
|
+
group = _ref10[1];
|
|
2193
2913
|
return {
|
|
2194
2914
|
key: key,
|
|
2195
2915
|
count: group.length,
|
|
2196
2916
|
orders: group.map(function (order) {
|
|
2197
|
-
var _order$
|
|
2917
|
+
var _order$order_id4, _external_sale_number4, _shop_order_number, _shop_full_order_numb, _order$need_sync, _order$is_draft_order;
|
|
2198
2918
|
return {
|
|
2199
|
-
order_id: (_order$
|
|
2200
|
-
external_sale_number: (
|
|
2919
|
+
order_id: (_order$order_id4 = order.order_id) !== null && _order$order_id4 !== void 0 ? _order$order_id4 : null,
|
|
2920
|
+
external_sale_number: (_external_sale_number4 = order.external_sale_number) !== null && _external_sale_number4 !== void 0 ? _external_sale_number4 : null,
|
|
2201
2921
|
shop_order_number: (_shop_order_number = order.shop_order_number) !== null && _shop_order_number !== void 0 ? _shop_order_number : null,
|
|
2202
2922
|
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
|
|
2923
|
+
need_sync: (_order$need_sync = order.need_sync) !== null && _order$need_sync !== void 0 ? _order$need_sync : null,
|
|
2924
|
+
is_draft_order: (_order$is_draft_order = order.is_draft_order) !== null && _order$is_draft_order !== void 0 ? _order$is_draft_order : null
|
|
2204
2925
|
};
|
|
2205
2926
|
})
|
|
2206
2927
|
};
|
|
@@ -2222,11 +2943,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2222
2943
|
value: function compactOrderListByIdentity(orders, source) {
|
|
2223
2944
|
var list = [];
|
|
2224
2945
|
var removedCount = 0;
|
|
2225
|
-
var
|
|
2226
|
-
|
|
2946
|
+
var _iterator28 = _createForOfIteratorHelper(orders),
|
|
2947
|
+
_step28;
|
|
2227
2948
|
try {
|
|
2228
|
-
for (
|
|
2229
|
-
var order =
|
|
2949
|
+
for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
|
|
2950
|
+
var order = _step28.value;
|
|
2230
2951
|
var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, "".concat(source, ".order"));
|
|
2231
2952
|
var matchIndex = this.findOrderIndexByIdentity(list, normalizedOrder);
|
|
2232
2953
|
if (matchIndex < 0) {
|
|
@@ -2237,9 +2958,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2237
2958
|
removedCount += 1;
|
|
2238
2959
|
}
|
|
2239
2960
|
} catch (err) {
|
|
2240
|
-
|
|
2961
|
+
_iterator28.e(err);
|
|
2241
2962
|
} finally {
|
|
2242
|
-
|
|
2963
|
+
_iterator28.f();
|
|
2243
2964
|
}
|
|
2244
2965
|
if (removedCount > 0) {
|
|
2245
2966
|
this.logWarning('订单列表重复项已压缩', {
|
|
@@ -2337,35 +3058,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2337
3058
|
}, {
|
|
2338
3059
|
key: "loadOrdersFromSQLite",
|
|
2339
3060
|
value: function () {
|
|
2340
|
-
var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2341
|
-
var
|
|
3061
|
+
var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
|
3062
|
+
var _this19 = this;
|
|
2342
3063
|
var orders;
|
|
2343
|
-
return _regeneratorRuntime().wrap(function
|
|
2344
|
-
while (1) switch (
|
|
3064
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
3065
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
2345
3066
|
case 0:
|
|
2346
3067
|
if (this.dbManager) {
|
|
2347
|
-
|
|
3068
|
+
_context19.next = 2;
|
|
2348
3069
|
break;
|
|
2349
3070
|
}
|
|
2350
|
-
return
|
|
3071
|
+
return _context19.abrupt("return", []);
|
|
2351
3072
|
case 2:
|
|
2352
|
-
|
|
2353
|
-
|
|
3073
|
+
_context19.prev = 2;
|
|
3074
|
+
_context19.next = 5;
|
|
2354
3075
|
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
2355
3076
|
case 5:
|
|
2356
|
-
orders =
|
|
2357
|
-
return
|
|
2358
|
-
return
|
|
3077
|
+
orders = _context19.sent;
|
|
3078
|
+
return _context19.abrupt("return", (orders || []).map(function (order) {
|
|
3079
|
+
return _this19.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
|
|
2359
3080
|
}));
|
|
2360
3081
|
case 9:
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
return
|
|
3082
|
+
_context19.prev = 9;
|
|
3083
|
+
_context19.t0 = _context19["catch"](2);
|
|
3084
|
+
return _context19.abrupt("return", []);
|
|
2364
3085
|
case 12:
|
|
2365
3086
|
case "end":
|
|
2366
|
-
return
|
|
3087
|
+
return _context19.stop();
|
|
2367
3088
|
}
|
|
2368
|
-
},
|
|
3089
|
+
}, _callee19, this, [[2, 9]]);
|
|
2369
3090
|
}));
|
|
2370
3091
|
function loadOrdersFromSQLite() {
|
|
2371
3092
|
return _loadOrdersFromSQLite.apply(this, arguments);
|
|
@@ -2377,41 +3098,71 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2377
3098
|
value: function isPendingSyncOrder(order) {
|
|
2378
3099
|
return Number(order === null || order === void 0 ? void 0 : order.need_sync) === 1;
|
|
2379
3100
|
}
|
|
3101
|
+
}, {
|
|
3102
|
+
key: "isDraftOrder",
|
|
3103
|
+
value: function isDraftOrder(order) {
|
|
3104
|
+
return Number(order === null || order === void 0 ? void 0 : order.is_draft_order) === 1;
|
|
3105
|
+
}
|
|
3106
|
+
}, {
|
|
3107
|
+
key: "shouldProtectDraftOrderFromIncoming",
|
|
3108
|
+
value: function shouldProtectDraftOrderFromIncoming(source) {
|
|
3109
|
+
return source !== 'checkoutSync';
|
|
3110
|
+
}
|
|
2380
3111
|
}, {
|
|
2381
3112
|
key: "normalizeRemoteSyncedOrder",
|
|
2382
3113
|
value: function normalizeRemoteSyncedOrder(order) {
|
|
2383
3114
|
var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, 'normalizeRemoteSyncedOrder');
|
|
2384
|
-
if (this.isPendingSyncOrder(normalizedOrder)) return normalizedOrder
|
|
3115
|
+
if (this.isPendingSyncOrder(normalizedOrder)) return _objectSpread(_objectSpread({}, normalizedOrder), {}, {
|
|
3116
|
+
is_draft_order: 0
|
|
3117
|
+
});
|
|
2385
3118
|
return _objectSpread(_objectSpread({}, normalizedOrder), {}, {
|
|
2386
|
-
need_sync: 0
|
|
3119
|
+
need_sync: 0,
|
|
3120
|
+
is_draft_order: 0
|
|
2387
3121
|
});
|
|
2388
3122
|
}
|
|
3123
|
+
}, {
|
|
3124
|
+
key: "mergeRemoteIdentityIntoDraftOrder",
|
|
3125
|
+
value: function mergeRemoteIdentityIntoDraftOrder(draftOrder, remoteOrder) {
|
|
3126
|
+
var merged = _objectSpread({}, this.withoutSyntheticDraftOrderId(draftOrder));
|
|
3127
|
+
var remote = remoteOrder;
|
|
3128
|
+
for (var _i7 = 0, _arr = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number']; _i7 < _arr.length; _i7++) {
|
|
3129
|
+
var field = _arr[_i7];
|
|
3130
|
+
if (this.isBlankIdentityValue(merged[field]) && !this.isBlankIdentityValue(remote[field])) {
|
|
3131
|
+
merged[field] = remote[field];
|
|
3132
|
+
}
|
|
3133
|
+
}
|
|
3134
|
+
return this.normalizeOrderCollectionsForIngress(merged, 'mergeRemoteIdentityIntoDraftOrder');
|
|
3135
|
+
}
|
|
2389
3136
|
}, {
|
|
2390
3137
|
key: "mergeRemoteSnapshotWithPendingOrders",
|
|
2391
3138
|
value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
|
|
2392
|
-
var
|
|
3139
|
+
var _this20 = this;
|
|
2393
3140
|
var merged = remoteOrders.map(function (order) {
|
|
2394
|
-
return
|
|
3141
|
+
return _this20.normalizeRemoteSyncedOrder(order);
|
|
2395
3142
|
});
|
|
2396
|
-
var
|
|
2397
|
-
|
|
3143
|
+
var _iterator29 = _createForOfIteratorHelper(existingOrders),
|
|
3144
|
+
_step29;
|
|
2398
3145
|
try {
|
|
2399
|
-
for (
|
|
2400
|
-
var rawOrder =
|
|
3146
|
+
for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
|
|
3147
|
+
var rawOrder = _step29.value;
|
|
2401
3148
|
var order = this.normalizeOrderCollectionsForIngress(rawOrder, 'mergeRemoteSnapshotWithPendingOrders.existingSQLite');
|
|
2402
|
-
if (!this.
|
|
3149
|
+
if (!this.shouldProtectLocalOrderFromRemoteSnapshot(order)) continue;
|
|
2403
3150
|
var matchIndex = this.findOrderIndexByIdentity(merged, order);
|
|
2404
3151
|
if (matchIndex >= 0) {
|
|
2405
|
-
|
|
3152
|
+
if (this.isDraftOrder(order)) {
|
|
3153
|
+
merged[matchIndex] = this.mergeRemoteIdentityIntoDraftOrder(order, merged[matchIndex]);
|
|
3154
|
+
} else {
|
|
3155
|
+
merged[matchIndex] = this.mergeOrderRecords(order, merged[matchIndex]);
|
|
3156
|
+
}
|
|
2406
3157
|
continue;
|
|
2407
3158
|
}
|
|
2408
3159
|
if (!this.getOrderStorageKey(order)) continue;
|
|
2409
3160
|
merged.push(order);
|
|
2410
3161
|
}
|
|
2411
3162
|
} catch (err) {
|
|
2412
|
-
|
|
3163
|
+
_iterator29.e(err);
|
|
2413
3164
|
} finally {
|
|
2414
|
-
|
|
3165
|
+
_iterator29.f();
|
|
2415
3166
|
}
|
|
2416
3167
|
return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
|
|
2417
3168
|
}
|
|
@@ -2427,10 +3178,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2427
3178
|
}, {
|
|
2428
3179
|
key: "runInOrderSQLiteSaveQueue",
|
|
2429
3180
|
value: (function () {
|
|
2430
|
-
var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3181
|
+
var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(task) {
|
|
2431
3182
|
var queuedTask;
|
|
2432
|
-
return _regeneratorRuntime().wrap(function
|
|
2433
|
-
while (1) switch (
|
|
3183
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
3184
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
2434
3185
|
case 0:
|
|
2435
3186
|
queuedTask = this.orderSQLiteSaveQueue.then(task, task);
|
|
2436
3187
|
this.orderSQLiteSaveQueue = queuedTask.then(function () {
|
|
@@ -2438,14 +3189,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2438
3189
|
}, function () {
|
|
2439
3190
|
return undefined;
|
|
2440
3191
|
});
|
|
2441
|
-
return
|
|
3192
|
+
return _context20.abrupt("return", queuedTask);
|
|
2442
3193
|
case 3:
|
|
2443
3194
|
case "end":
|
|
2444
|
-
return
|
|
3195
|
+
return _context20.stop();
|
|
2445
3196
|
}
|
|
2446
|
-
},
|
|
3197
|
+
}, _callee20, this);
|
|
2447
3198
|
}));
|
|
2448
|
-
function runInOrderSQLiteSaveQueue(
|
|
3199
|
+
function runInOrderSQLiteSaveQueue(_x14) {
|
|
2449
3200
|
return _runInOrderSQLiteSaveQueue.apply(this, arguments);
|
|
2450
3201
|
}
|
|
2451
3202
|
return runInOrderSQLiteSaveQueue;
|
|
@@ -2460,146 +3211,174 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2460
3211
|
}, {
|
|
2461
3212
|
key: "patchOrdersInSQLite",
|
|
2462
3213
|
value: (function () {
|
|
2463
|
-
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2464
|
-
var
|
|
3214
|
+
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(orders, source) {
|
|
3215
|
+
var _this21 = this;
|
|
2465
3216
|
var mergeActions,
|
|
3217
|
+
options,
|
|
2466
3218
|
ordersSnapshot,
|
|
2467
3219
|
_this$filterRedundant2,
|
|
2468
3220
|
toWrite,
|
|
2469
3221
|
skipped,
|
|
2470
3222
|
compactedToWrite,
|
|
2471
|
-
|
|
2472
|
-
return _regeneratorRuntime().wrap(function
|
|
2473
|
-
while (1) switch (
|
|
3223
|
+
_args22 = arguments;
|
|
3224
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
3225
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
2474
3226
|
case 0:
|
|
2475
|
-
mergeActions =
|
|
2476
|
-
|
|
2477
|
-
|
|
3227
|
+
mergeActions = _args22.length > 2 && _args22[2] !== undefined ? _args22[2] : {};
|
|
3228
|
+
options = _args22.length > 3 && _args22[3] !== undefined ? _args22[3] : {};
|
|
3229
|
+
if (!(orders.length === 0)) {
|
|
3230
|
+
_context22.next = 4;
|
|
2478
3231
|
break;
|
|
2479
3232
|
}
|
|
2480
|
-
return
|
|
2481
|
-
case
|
|
3233
|
+
return _context22.abrupt("return");
|
|
3234
|
+
case 4:
|
|
3235
|
+
if (this.dbManager) {
|
|
3236
|
+
_context22.next = 8;
|
|
3237
|
+
break;
|
|
3238
|
+
}
|
|
3239
|
+
if (!options.throwOnError) {
|
|
3240
|
+
_context22.next = 7;
|
|
3241
|
+
break;
|
|
3242
|
+
}
|
|
3243
|
+
throw new Error('订单 SQLite 数据库未初始化');
|
|
3244
|
+
case 7:
|
|
3245
|
+
return _context22.abrupt("return");
|
|
3246
|
+
case 8:
|
|
2482
3247
|
ordersSnapshot = cloneDeep(orders).map(function (order) {
|
|
2483
|
-
return
|
|
3248
|
+
return _this21.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
|
|
2484
3249
|
}).filter(function (order) {
|
|
2485
|
-
return
|
|
3250
|
+
return _this21.getOrderStorageKey(order);
|
|
2486
3251
|
});
|
|
2487
3252
|
if (!(ordersSnapshot.length === 0)) {
|
|
2488
|
-
|
|
3253
|
+
_context22.next = 11;
|
|
2489
3254
|
break;
|
|
2490
3255
|
}
|
|
2491
|
-
return
|
|
2492
|
-
case
|
|
3256
|
+
return _context22.abrupt("return");
|
|
3257
|
+
case 11:
|
|
2493
3258
|
_this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
|
|
2494
3259
|
if (!(toWrite.length === 0)) {
|
|
2495
|
-
|
|
3260
|
+
_context22.next = 14;
|
|
2496
3261
|
break;
|
|
2497
3262
|
}
|
|
2498
|
-
return
|
|
2499
|
-
case
|
|
3263
|
+
return _context22.abrupt("return");
|
|
3264
|
+
case 14:
|
|
2500
3265
|
compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
|
|
2501
3266
|
if (!(compactedToWrite.length === 0)) {
|
|
2502
|
-
|
|
3267
|
+
_context22.next = 17;
|
|
2503
3268
|
break;
|
|
2504
3269
|
}
|
|
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 (
|
|
3270
|
+
return _context22.abrupt("return");
|
|
3271
|
+
case 17:
|
|
3272
|
+
_context22.prev = 17;
|
|
3273
|
+
_context22.next = 20;
|
|
3274
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
|
|
3275
|
+
var writeMethod, _iterator30, _step30, order;
|
|
3276
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
3277
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
2513
3278
|
case 0:
|
|
2514
3279
|
writeMethod = 'none';
|
|
2515
|
-
|
|
3280
|
+
_this21.logInfo('patchOrdersInSQLite-开始', {
|
|
2516
3281
|
source: source,
|
|
2517
3282
|
count: compactedToWrite.length,
|
|
2518
3283
|
dedupedCount: skipped.length
|
|
2519
3284
|
});
|
|
2520
|
-
if (!(typeof
|
|
2521
|
-
|
|
3285
|
+
if (!(typeof _this21.dbManager.bulkUpdate === 'function')) {
|
|
3286
|
+
_context21.next = 8;
|
|
2522
3287
|
break;
|
|
2523
3288
|
}
|
|
2524
3289
|
writeMethod = 'bulkUpdate';
|
|
2525
|
-
|
|
2526
|
-
return
|
|
3290
|
+
_context21.next = 6;
|
|
3291
|
+
return _this21.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2527
3292
|
case 6:
|
|
2528
|
-
|
|
3293
|
+
_context21.next = 37;
|
|
2529
3294
|
break;
|
|
2530
3295
|
case 8:
|
|
2531
|
-
if (!(typeof
|
|
2532
|
-
|
|
3296
|
+
if (!(typeof _this21.dbManager.bulkAdd === 'function')) {
|
|
3297
|
+
_context21.next = 14;
|
|
2533
3298
|
break;
|
|
2534
3299
|
}
|
|
2535
3300
|
writeMethod = 'bulkAdd';
|
|
2536
|
-
|
|
2537
|
-
return
|
|
3301
|
+
_context21.next = 12;
|
|
3302
|
+
return _this21.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2538
3303
|
case 12:
|
|
2539
|
-
|
|
3304
|
+
_context21.next = 37;
|
|
2540
3305
|
break;
|
|
2541
3306
|
case 14:
|
|
2542
|
-
if (!(typeof
|
|
2543
|
-
|
|
3307
|
+
if (!(typeof _this21.dbManager.update === 'function')) {
|
|
3308
|
+
_context21.next = 35;
|
|
2544
3309
|
break;
|
|
2545
3310
|
}
|
|
2546
3311
|
writeMethod = 'update';
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
3312
|
+
_iterator30 = _createForOfIteratorHelper(compactedToWrite);
|
|
3313
|
+
_context21.prev = 17;
|
|
3314
|
+
_iterator30.s();
|
|
2550
3315
|
case 19:
|
|
2551
|
-
if ((
|
|
2552
|
-
|
|
3316
|
+
if ((_step30 = _iterator30.n()).done) {
|
|
3317
|
+
_context21.next = 25;
|
|
2553
3318
|
break;
|
|
2554
3319
|
}
|
|
2555
|
-
order =
|
|
2556
|
-
|
|
2557
|
-
return
|
|
3320
|
+
order = _step30.value;
|
|
3321
|
+
_context21.next = 23;
|
|
3322
|
+
return _this21.dbManager.update(INDEXDB_STORE_NAME, order);
|
|
2558
3323
|
case 23:
|
|
2559
|
-
|
|
3324
|
+
_context21.next = 19;
|
|
2560
3325
|
break;
|
|
2561
3326
|
case 25:
|
|
2562
|
-
|
|
3327
|
+
_context21.next = 30;
|
|
2563
3328
|
break;
|
|
2564
3329
|
case 27:
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
3330
|
+
_context21.prev = 27;
|
|
3331
|
+
_context21.t0 = _context21["catch"](17);
|
|
3332
|
+
_iterator30.e(_context21.t0);
|
|
2568
3333
|
case 30:
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
return
|
|
3334
|
+
_context21.prev = 30;
|
|
3335
|
+
_iterator30.f();
|
|
3336
|
+
return _context21.finish(30);
|
|
2572
3337
|
case 33:
|
|
2573
|
-
|
|
2574
|
-
|
|
3338
|
+
_context21.next = 37;
|
|
3339
|
+
break;
|
|
3340
|
+
case 35:
|
|
3341
|
+
if (!options.throwOnError) {
|
|
3342
|
+
_context21.next = 37;
|
|
3343
|
+
break;
|
|
3344
|
+
}
|
|
3345
|
+
throw new Error('订单 SQLite 数据库不支持写入');
|
|
3346
|
+
case 37:
|
|
3347
|
+
_this21.recordRecentSqliteWrite(source, compactedToWrite);
|
|
3348
|
+
_this21.logInfo('patchOrdersInSQLite-完成', {
|
|
2575
3349
|
source: source,
|
|
2576
3350
|
count: compactedToWrite.length,
|
|
2577
3351
|
writeMethod: writeMethod,
|
|
2578
3352
|
dedupedCount: skipped.length
|
|
2579
3353
|
});
|
|
2580
|
-
case
|
|
3354
|
+
case 39:
|
|
2581
3355
|
case "end":
|
|
2582
|
-
return
|
|
3356
|
+
return _context21.stop();
|
|
2583
3357
|
}
|
|
2584
|
-
},
|
|
3358
|
+
}, _callee21, null, [[17, 27, 30, 33]]);
|
|
2585
3359
|
})));
|
|
2586
|
-
case
|
|
2587
|
-
|
|
3360
|
+
case 20:
|
|
3361
|
+
_context22.next = 27;
|
|
2588
3362
|
break;
|
|
2589
|
-
case
|
|
2590
|
-
|
|
2591
|
-
|
|
3363
|
+
case 22:
|
|
3364
|
+
_context22.prev = 22;
|
|
3365
|
+
_context22.t0 = _context22["catch"](17);
|
|
2592
3366
|
this.logError('增量保存订单到 SQLite 失败', {
|
|
2593
|
-
error:
|
|
3367
|
+
error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0),
|
|
2594
3368
|
orderCount: ordersSnapshot.length
|
|
2595
3369
|
});
|
|
2596
|
-
|
|
3370
|
+
if (!options.throwOnError) {
|
|
3371
|
+
_context22.next = 27;
|
|
3372
|
+
break;
|
|
3373
|
+
}
|
|
3374
|
+
throw _context22.t0;
|
|
3375
|
+
case 27:
|
|
2597
3376
|
case "end":
|
|
2598
|
-
return
|
|
3377
|
+
return _context22.stop();
|
|
2599
3378
|
}
|
|
2600
|
-
},
|
|
3379
|
+
}, _callee22, this, [[17, 22]]);
|
|
2601
3380
|
}));
|
|
2602
|
-
function patchOrdersInSQLite(
|
|
3381
|
+
function patchOrdersInSQLite(_x15, _x16) {
|
|
2603
3382
|
return _patchOrdersInSQLite.apply(this, arguments);
|
|
2604
3383
|
}
|
|
2605
3384
|
return patchOrdersInSQLite;
|
|
@@ -2614,98 +3393,135 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2614
3393
|
}, {
|
|
2615
3394
|
key: "updateOrderInSQLite",
|
|
2616
3395
|
value: (function () {
|
|
2617
|
-
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2618
|
-
var
|
|
2619
|
-
var
|
|
2620
|
-
|
|
2621
|
-
|
|
3396
|
+
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(order, source) {
|
|
3397
|
+
var _this22 = this;
|
|
3398
|
+
var options,
|
|
3399
|
+
orderSnapshot,
|
|
3400
|
+
_orderSnapshot$order_3,
|
|
3401
|
+
_args24 = arguments;
|
|
3402
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
3403
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
2622
3404
|
case 0:
|
|
2623
|
-
|
|
2624
|
-
|
|
3405
|
+
options = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : {};
|
|
3406
|
+
if (this.getOrderStorageKey(order)) {
|
|
3407
|
+
_context24.next = 5;
|
|
2625
3408
|
break;
|
|
2626
3409
|
}
|
|
2627
|
-
|
|
2628
|
-
|
|
3410
|
+
if (!options.throwOnError) {
|
|
3411
|
+
_context24.next = 4;
|
|
3412
|
+
break;
|
|
3413
|
+
}
|
|
3414
|
+
throw new Error('订单缺少可用的 SQLite 存储主键');
|
|
3415
|
+
case 4:
|
|
3416
|
+
return _context24.abrupt("return");
|
|
3417
|
+
case 5:
|
|
3418
|
+
if (this.dbManager) {
|
|
3419
|
+
_context24.next = 9;
|
|
3420
|
+
break;
|
|
3421
|
+
}
|
|
3422
|
+
if (!options.throwOnError) {
|
|
3423
|
+
_context24.next = 8;
|
|
3424
|
+
break;
|
|
3425
|
+
}
|
|
3426
|
+
throw new Error('订单 SQLite 数据库未初始化');
|
|
3427
|
+
case 8:
|
|
3428
|
+
return _context24.abrupt("return");
|
|
3429
|
+
case 9:
|
|
2629
3430
|
orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3431
|
+
_context24.prev = 10;
|
|
3432
|
+
_context24.next = 13;
|
|
3433
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
|
|
2633
3434
|
var _orderSnapshot$order_, _orderSnapshot$order_2;
|
|
2634
3435
|
var writeMethod;
|
|
2635
|
-
return _regeneratorRuntime().wrap(function
|
|
2636
|
-
while (1) switch (
|
|
3436
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
3437
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
2637
3438
|
case 0:
|
|
2638
3439
|
writeMethod = 'none';
|
|
2639
|
-
|
|
3440
|
+
_this22.logInfo('updateOrderInSQLite-开始', {
|
|
2640
3441
|
source: source,
|
|
2641
3442
|
orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
|
|
2642
|
-
storageKey:
|
|
3443
|
+
storageKey: _this22.getOrderStorageKey(orderSnapshot)
|
|
2643
3444
|
});
|
|
2644
|
-
if (!(typeof
|
|
2645
|
-
|
|
3445
|
+
if (!(typeof _this22.dbManager.update === 'function')) {
|
|
3446
|
+
_context23.next = 8;
|
|
2646
3447
|
break;
|
|
2647
3448
|
}
|
|
2648
3449
|
writeMethod = 'update';
|
|
2649
|
-
|
|
2650
|
-
return
|
|
3450
|
+
_context23.next = 6;
|
|
3451
|
+
return _this22.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
|
|
2651
3452
|
case 6:
|
|
2652
|
-
|
|
3453
|
+
_context23.next = 22;
|
|
2653
3454
|
break;
|
|
2654
3455
|
case 8:
|
|
2655
|
-
if (!(typeof
|
|
2656
|
-
|
|
3456
|
+
if (!(typeof _this22.dbManager.bulkUpdate === 'function')) {
|
|
3457
|
+
_context23.next = 14;
|
|
2657
3458
|
break;
|
|
2658
3459
|
}
|
|
2659
3460
|
writeMethod = 'bulkUpdate';
|
|
2660
|
-
|
|
2661
|
-
return
|
|
3461
|
+
_context23.next = 12;
|
|
3462
|
+
return _this22.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2662
3463
|
case 12:
|
|
2663
|
-
|
|
3464
|
+
_context23.next = 22;
|
|
2664
3465
|
break;
|
|
2665
3466
|
case 14:
|
|
2666
|
-
if (!(typeof
|
|
2667
|
-
|
|
3467
|
+
if (!(typeof _this22.dbManager.bulkAdd === 'function')) {
|
|
3468
|
+
_context23.next = 20;
|
|
2668
3469
|
break;
|
|
2669
3470
|
}
|
|
2670
3471
|
writeMethod = 'bulkAdd';
|
|
2671
|
-
|
|
2672
|
-
return
|
|
3472
|
+
_context23.next = 18;
|
|
3473
|
+
return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2673
3474
|
case 18:
|
|
2674
|
-
|
|
2675
|
-
|
|
3475
|
+
_context23.next = 22;
|
|
3476
|
+
break;
|
|
3477
|
+
case 20:
|
|
3478
|
+
if (!options.throwOnError) {
|
|
3479
|
+
_context23.next = 22;
|
|
3480
|
+
break;
|
|
3481
|
+
}
|
|
3482
|
+
throw new Error('订单 SQLite 数据库不支持写入');
|
|
3483
|
+
case 22:
|
|
3484
|
+
_this22.recordRecentSqliteWrite(source, [orderSnapshot]);
|
|
3485
|
+
_this22.logInfo('updateOrderInSQLite-完成', {
|
|
2676
3486
|
source: source,
|
|
2677
3487
|
orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
|
|
2678
3488
|
writeMethod: writeMethod
|
|
2679
3489
|
});
|
|
2680
|
-
case
|
|
3490
|
+
case 24:
|
|
2681
3491
|
case "end":
|
|
2682
|
-
return
|
|
3492
|
+
return _context23.stop();
|
|
2683
3493
|
}
|
|
2684
|
-
},
|
|
3494
|
+
}, _callee23);
|
|
2685
3495
|
})));
|
|
2686
|
-
case
|
|
2687
|
-
|
|
3496
|
+
case 13:
|
|
3497
|
+
_context24.next = 20;
|
|
2688
3498
|
break;
|
|
2689
|
-
case
|
|
2690
|
-
|
|
2691
|
-
|
|
3499
|
+
case 15:
|
|
3500
|
+
_context24.prev = 15;
|
|
3501
|
+
_context24.t0 = _context24["catch"](10);
|
|
2692
3502
|
this.logError('单条保存订单到 SQLite 失败', {
|
|
2693
|
-
error:
|
|
3503
|
+
error: _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0),
|
|
2694
3504
|
orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
|
|
2695
3505
|
});
|
|
2696
|
-
|
|
3506
|
+
if (!options.throwOnError) {
|
|
3507
|
+
_context24.next = 20;
|
|
3508
|
+
break;
|
|
3509
|
+
}
|
|
3510
|
+
throw _context24.t0;
|
|
3511
|
+
case 20:
|
|
2697
3512
|
case "end":
|
|
2698
|
-
return
|
|
3513
|
+
return _context24.stop();
|
|
2699
3514
|
}
|
|
2700
|
-
},
|
|
3515
|
+
}, _callee24, this, [[10, 15]]);
|
|
2701
3516
|
}));
|
|
2702
|
-
function updateOrderInSQLite(
|
|
3517
|
+
function updateOrderInSQLite(_x17, _x18) {
|
|
2703
3518
|
return _updateOrderInSQLite.apply(this, arguments);
|
|
2704
3519
|
}
|
|
2705
3520
|
return updateOrderInSQLite;
|
|
2706
3521
|
}()
|
|
2707
3522
|
/**
|
|
2708
|
-
* 全量快照替换 orders 表(clear + bulkAdd
|
|
3523
|
+
* 全量快照替换 orders 表(clear + bulkAdd),并保留本地 draft / need_sync / pending 支付订单。
|
|
3524
|
+
* 用于 SSE 全量拉取与营业日窗口裁剪。
|
|
2709
3525
|
*
|
|
2710
3526
|
* @example
|
|
2711
3527
|
* await this.replaceOrdersSnapshotInSQLite(orderList)
|
|
@@ -2714,100 +3530,163 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2714
3530
|
}, {
|
|
2715
3531
|
key: "replaceOrdersSnapshotInSQLite",
|
|
2716
3532
|
value: (function () {
|
|
2717
|
-
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2718
|
-
var
|
|
2719
|
-
var
|
|
2720
|
-
|
|
2721
|
-
|
|
3533
|
+
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(orderList, source) {
|
|
3534
|
+
var _this23 = this;
|
|
3535
|
+
var protectedOrdersBeforeRemoteFetch,
|
|
3536
|
+
remoteSnapshot,
|
|
3537
|
+
mergedSnapshot,
|
|
3538
|
+
_args26 = arguments;
|
|
3539
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
3540
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
2722
3541
|
case 0:
|
|
3542
|
+
protectedOrdersBeforeRemoteFetch = _args26.length > 2 && _args26[2] !== undefined ? _args26[2] : [];
|
|
2723
3543
|
if (this.dbManager) {
|
|
2724
|
-
|
|
3544
|
+
_context26.next = 3;
|
|
2725
3545
|
break;
|
|
2726
3546
|
}
|
|
2727
|
-
return
|
|
2728
|
-
return
|
|
3547
|
+
return _context26.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
|
|
3548
|
+
return _this23.normalizeRemoteSyncedOrder(order);
|
|
2729
3549
|
}), "".concat(source, ".snapshotNoDb")).list);
|
|
2730
|
-
case
|
|
3550
|
+
case 3:
|
|
2731
3551
|
remoteSnapshot = cloneDeep(orderList).map(function (order) {
|
|
2732
|
-
return
|
|
3552
|
+
return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
|
|
2733
3553
|
});
|
|
2734
3554
|
mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
|
|
2735
|
-
return
|
|
3555
|
+
return _this23.normalizeRemoteSyncedOrder(order);
|
|
2736
3556
|
}), "".concat(source, ".remoteSnapshot")).list;
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2740
|
-
var existingOrders, orderListSnapshot;
|
|
2741
|
-
return _regeneratorRuntime().wrap(function
|
|
2742
|
-
while (1) switch (
|
|
3557
|
+
_context26.prev = 5;
|
|
3558
|
+
_context26.next = 8;
|
|
3559
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
3560
|
+
var existingOrders, protectedLocalOrders, _iterator31, _step31, rawCurrentOrder, currentOrder, protectedIndex, currentNeedsProtection, orderListSnapshot;
|
|
3561
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
3562
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
2743
3563
|
case 0:
|
|
2744
|
-
if (!(typeof
|
|
2745
|
-
|
|
3564
|
+
if (!(typeof _this23.dbManager.getAll === 'function')) {
|
|
3565
|
+
_context25.next = 6;
|
|
2746
3566
|
break;
|
|
2747
3567
|
}
|
|
2748
|
-
|
|
2749
|
-
return
|
|
3568
|
+
_context25.next = 3;
|
|
3569
|
+
return _this23.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
2750
3570
|
case 3:
|
|
2751
|
-
|
|
2752
|
-
|
|
3571
|
+
_context25.t0 = _context25.sent;
|
|
3572
|
+
_context25.next = 7;
|
|
2753
3573
|
break;
|
|
2754
3574
|
case 6:
|
|
2755
|
-
|
|
3575
|
+
_context25.t0 = [];
|
|
2756
3576
|
case 7:
|
|
2757
|
-
existingOrders =
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
3577
|
+
existingOrders = _context25.t0;
|
|
3578
|
+
protectedLocalOrders = protectedOrdersBeforeRemoteFetch.map(function (order) {
|
|
3579
|
+
return _this23.normalizeOrderCollectionsForIngress(order, "".concat(source, ".protectedBeforeRemoteFetch"));
|
|
3580
|
+
}).filter(function (order) {
|
|
3581
|
+
return _this23.shouldProtectLocalOrderFromRemoteSnapshot(order);
|
|
3582
|
+
});
|
|
3583
|
+
_iterator31 = _createForOfIteratorHelper(existingOrders || []);
|
|
3584
|
+
_context25.prev = 10;
|
|
3585
|
+
_iterator31.s();
|
|
3586
|
+
case 12:
|
|
3587
|
+
if ((_step31 = _iterator31.n()).done) {
|
|
3588
|
+
_context25.next = 23;
|
|
3589
|
+
break;
|
|
3590
|
+
}
|
|
3591
|
+
rawCurrentOrder = _step31.value;
|
|
3592
|
+
currentOrder = _this23.normalizeOrderCollectionsForIngress(rawCurrentOrder, "".concat(source, ".currentSQLite"));
|
|
3593
|
+
protectedIndex = _this23.findOrderIndexByIdentity(protectedLocalOrders, currentOrder);
|
|
3594
|
+
currentNeedsProtection = _this23.shouldProtectLocalOrderFromRemoteSnapshot(currentOrder);
|
|
3595
|
+
if (!(protectedIndex >= 0)) {
|
|
3596
|
+
_context25.next = 20;
|
|
3597
|
+
break;
|
|
3598
|
+
}
|
|
3599
|
+
if (currentNeedsProtection) {
|
|
3600
|
+
protectedLocalOrders[protectedIndex] = currentOrder;
|
|
3601
|
+
} else {
|
|
3602
|
+
protectedLocalOrders.splice(protectedIndex, 1);
|
|
3603
|
+
}
|
|
3604
|
+
return _context25.abrupt("continue", 21);
|
|
3605
|
+
case 20:
|
|
3606
|
+
if (currentNeedsProtection) protectedLocalOrders.push(currentOrder);
|
|
3607
|
+
case 21:
|
|
3608
|
+
_context25.next = 12;
|
|
3609
|
+
break;
|
|
3610
|
+
case 23:
|
|
3611
|
+
_context25.next = 28;
|
|
3612
|
+
break;
|
|
3613
|
+
case 25:
|
|
3614
|
+
_context25.prev = 25;
|
|
3615
|
+
_context25.t1 = _context25["catch"](10);
|
|
3616
|
+
_iterator31.e(_context25.t1);
|
|
3617
|
+
case 28:
|
|
3618
|
+
_context25.prev = 28;
|
|
3619
|
+
_iterator31.f();
|
|
3620
|
+
return _context25.finish(28);
|
|
3621
|
+
case 31:
|
|
3622
|
+
orderListSnapshot = _this23.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, protectedLocalOrders);
|
|
3623
|
+
mergedSnapshot = _this23.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
|
|
3624
|
+
_this23.logInfo('replaceOrdersSnapshotInSQLite-开始', {
|
|
2761
3625
|
source: source,
|
|
2762
3626
|
count: mergedSnapshot.length,
|
|
2763
3627
|
remoteCount: remoteSnapshot.length,
|
|
2764
|
-
|
|
3628
|
+
protectedBeforeRemoteFetchCount: protectedOrdersBeforeRemoteFetch.length,
|
|
3629
|
+
protectedLocalOrderCount: protectedLocalOrders.length,
|
|
3630
|
+
preservedLocalUnsyncedCount: mergedSnapshot.length - remoteSnapshot.length,
|
|
3631
|
+
protectedPendingPaymentCount: protectedLocalOrders.reduce(function (count, order) {
|
|
3632
|
+
return count + _this23.getIdentifiedPendingPayments(order).length;
|
|
3633
|
+
}, 0),
|
|
3634
|
+
protectedPendingPaymentIdentities: protectedLocalOrders.flatMap(function (order) {
|
|
3635
|
+
return _this23.getIdentifiedPendingPayments(order).map(function (payment) {
|
|
3636
|
+
var _order$order_id5, _external_sale_number5;
|
|
3637
|
+
return {
|
|
3638
|
+
order_id: (_order$order_id5 = order.order_id) !== null && _order$order_id5 !== void 0 ? _order$order_id5 : null,
|
|
3639
|
+
external_sale_number: (_external_sale_number5 = order.external_sale_number) !== null && _external_sale_number5 !== void 0 ? _external_sale_number5 : null,
|
|
3640
|
+
payment_identities: getOrderPaymentIdentityKeys(payment)
|
|
3641
|
+
};
|
|
3642
|
+
});
|
|
3643
|
+
})
|
|
2765
3644
|
});
|
|
2766
|
-
|
|
2767
|
-
return
|
|
2768
|
-
case
|
|
2769
|
-
|
|
3645
|
+
_context25.next = 36;
|
|
3646
|
+
return _this23.dbManager.clear(INDEXDB_STORE_NAME);
|
|
3647
|
+
case 36:
|
|
3648
|
+
_this23.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
|
|
2770
3649
|
count: mergedSnapshot.length
|
|
2771
3650
|
});
|
|
2772
3651
|
if (!(mergedSnapshot.length === 0)) {
|
|
2773
|
-
|
|
3652
|
+
_context25.next = 39;
|
|
2774
3653
|
break;
|
|
2775
3654
|
}
|
|
2776
|
-
return
|
|
2777
|
-
case
|
|
2778
|
-
|
|
2779
|
-
return
|
|
2780
|
-
case
|
|
2781
|
-
|
|
2782
|
-
|
|
3655
|
+
return _context25.abrupt("return");
|
|
3656
|
+
case 39:
|
|
3657
|
+
_context25.next = 41;
|
|
3658
|
+
return _this23.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
|
|
3659
|
+
case 41:
|
|
3660
|
+
_this23.recordRecentSqliteWrite(source, mergedSnapshot);
|
|
3661
|
+
_this23.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
|
|
2783
3662
|
source: source,
|
|
2784
3663
|
count: mergedSnapshot.length
|
|
2785
3664
|
});
|
|
2786
|
-
case
|
|
3665
|
+
case 43:
|
|
2787
3666
|
case "end":
|
|
2788
|
-
return
|
|
3667
|
+
return _context25.stop();
|
|
2789
3668
|
}
|
|
2790
|
-
},
|
|
3669
|
+
}, _callee25, null, [[10, 25, 28, 31]]);
|
|
2791
3670
|
})));
|
|
2792
|
-
case
|
|
2793
|
-
|
|
3671
|
+
case 8:
|
|
3672
|
+
_context26.next = 13;
|
|
2794
3673
|
break;
|
|
2795
|
-
case
|
|
2796
|
-
|
|
2797
|
-
|
|
3674
|
+
case 10:
|
|
3675
|
+
_context26.prev = 10;
|
|
3676
|
+
_context26.t0 = _context26["catch"](5);
|
|
2798
3677
|
this.logError('全量保存订单到 SQLite 失败', {
|
|
2799
|
-
error:
|
|
3678
|
+
error: _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0),
|
|
2800
3679
|
orderList: remoteSnapshot.length
|
|
2801
3680
|
});
|
|
2802
|
-
case 12:
|
|
2803
|
-
return _context24.abrupt("return", mergedSnapshot);
|
|
2804
3681
|
case 13:
|
|
3682
|
+
return _context26.abrupt("return", mergedSnapshot);
|
|
3683
|
+
case 14:
|
|
2805
3684
|
case "end":
|
|
2806
|
-
return
|
|
3685
|
+
return _context26.stop();
|
|
2807
3686
|
}
|
|
2808
|
-
},
|
|
3687
|
+
}, _callee26, this, [[5, 10]]);
|
|
2809
3688
|
}));
|
|
2810
|
-
function replaceOrdersSnapshotInSQLite(
|
|
3689
|
+
function replaceOrdersSnapshotInSQLite(_x19, _x20) {
|
|
2811
3690
|
return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
|
|
2812
3691
|
}
|
|
2813
3692
|
return replaceOrdersSnapshotInSQLite;
|
|
@@ -2822,38 +3701,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2822
3701
|
}, {
|
|
2823
3702
|
key: "clear",
|
|
2824
3703
|
value: (function () {
|
|
2825
|
-
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2826
|
-
var
|
|
2827
|
-
return _regeneratorRuntime().wrap(function
|
|
2828
|
-
while (1) switch (
|
|
3704
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
|
|
3705
|
+
var _this24 = this;
|
|
3706
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
3707
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
2829
3708
|
case 0:
|
|
2830
3709
|
this.store.list = [];
|
|
2831
3710
|
this.store.map = new Map();
|
|
2832
3711
|
if (!this.dbManager) {
|
|
2833
|
-
|
|
3712
|
+
_context28.next = 5;
|
|
2834
3713
|
break;
|
|
2835
3714
|
}
|
|
2836
|
-
|
|
2837
|
-
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2838
|
-
return _regeneratorRuntime().wrap(function
|
|
2839
|
-
while (1) switch (
|
|
3715
|
+
_context28.next = 5;
|
|
3716
|
+
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
|
|
3717
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
3718
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
2840
3719
|
case 0:
|
|
2841
|
-
|
|
2842
|
-
return
|
|
3720
|
+
_context27.next = 2;
|
|
3721
|
+
return _this24.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2843
3722
|
case 2:
|
|
2844
3723
|
case "end":
|
|
2845
|
-
return
|
|
3724
|
+
return _context27.stop();
|
|
2846
3725
|
}
|
|
2847
|
-
},
|
|
3726
|
+
}, _callee27);
|
|
2848
3727
|
})));
|
|
2849
3728
|
case 5:
|
|
2850
3729
|
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
|
|
2851
3730
|
this.emitOrdersChanged([], 'clear');
|
|
2852
3731
|
case 7:
|
|
2853
3732
|
case "end":
|
|
2854
|
-
return
|
|
3733
|
+
return _context28.stop();
|
|
2855
3734
|
}
|
|
2856
|
-
},
|
|
3735
|
+
}, _callee28, this);
|
|
2857
3736
|
}));
|
|
2858
3737
|
function clear() {
|
|
2859
3738
|
return _clear.apply(this, arguments);
|