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