@pisell/pisellos 2.2.191 → 2.2.193

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.
Files changed (40) hide show
  1. package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
  2. package/dist/modules/Order/index.d.ts +12 -10
  3. package/dist/modules/Order/index.js +462 -571
  4. package/dist/modules/Order/types.d.ts +5 -5
  5. package/dist/modules/Order/utils.js +3 -3
  6. package/dist/modules/Payment/utils.js +2 -1
  7. package/dist/modules/SalesSummary/utils.js +1 -1
  8. package/dist/server/index.d.ts +8 -1
  9. package/dist/server/index.js +651 -464
  10. package/dist/server/modules/order/index.d.ts +4 -70
  11. package/dist/server/modules/order/index.js +336 -747
  12. package/dist/server/modules/products/index.d.ts +0 -57
  13. package/dist/server/modules/products/index.js +347 -706
  14. package/dist/solution/BaseSales/index.d.ts +2 -1
  15. package/dist/solution/BaseSales/index.js +116 -122
  16. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
  17. package/dist/solution/BookingByStep/index.d.ts +1 -1
  18. package/dist/solution/BookingTicket/index.d.ts +1 -1
  19. package/dist/solution/ScanOrder/index.js +3 -1
  20. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  21. package/lib/model/strategy/adapter/walletPass/utils.js +3 -2
  22. package/lib/modules/Order/index.d.ts +12 -10
  23. package/lib/modules/Order/index.js +94 -118
  24. package/lib/modules/Order/types.d.ts +5 -5
  25. package/lib/modules/Order/utils.js +4 -4
  26. package/lib/modules/Payment/utils.js +2 -1
  27. package/lib/modules/SalesSummary/utils.js +1 -3
  28. package/lib/server/index.d.ts +8 -1
  29. package/lib/server/index.js +143 -24
  30. package/lib/server/modules/order/index.d.ts +4 -70
  31. package/lib/server/modules/order/index.js +31 -391
  32. package/lib/server/modules/products/index.d.ts +0 -57
  33. package/lib/server/modules/products/index.js +0 -333
  34. package/lib/solution/BaseSales/index.d.ts +2 -1
  35. package/lib/solution/BaseSales/index.js +53 -16
  36. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
  37. package/lib/solution/BookingByStep/index.d.ts +1 -1
  38. package/lib/solution/BookingTicket/index.d.ts +1 -1
  39. package/lib/solution/ScanOrder/index.js +3 -1
  40. package/package.json +1 -1
@@ -1,17 +1,13 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
1
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
2
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- 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; } } }; }
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
4
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
5
  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."); }
7
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
7
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ 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
9
  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
10
  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 _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
14
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
11
  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
12
  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
13
  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); }); }; }
@@ -42,11 +38,6 @@ var INDEXDB_STORE_NAME = 'orders';
42
38
  var ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY = 'server_order_last_full_fetch_at';
43
39
  var ORDER_SYNC_THROTTLE_MS_STORAGE_KEY = 'order_sync_throttle_ms';
44
40
  var DEFAULT_ORDER_SYNC_THROTTLE_MS = 2000;
45
- /** window 上挂载的订单流程调试日志 key */
46
- var ORDER_FLOW_LOG_WINDOW_KEY = '__orderModuleFlowLogs';
47
- /** window 上按订单聚合的 SQLite 写入统计 key */
48
- var ORDER_WRITE_STATS_WINDOW_KEY = '__orderModuleWriteStats';
49
- var ORDER_FLOW_LOG_MAX_LENGTH = 1000;
50
41
  /** pubsub 回声写入去重窗口:业务 API 刚写入后,跳过同单 SQLite patch */
51
42
  var ORDER_SQLITE_DEDUPE_MS = 15000;
52
43
  /** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
@@ -54,10 +45,6 @@ var ORDER_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
54
45
  /** 视为「业务侧刚写入」的来源,pubsub 回声可跳过 SQLite */
55
46
  var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'overwriteExistingOrder']);
56
47
 
57
- /** 订单模块流程调试日志条目 */
58
-
59
- /** 单笔订单 SQLite 写入记录 */
60
-
61
48
  /**
62
49
  * Order 模块 - 基础框架
63
50
  */
@@ -83,8 +70,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
83
70
  // LoggerManager 实例
84
71
  _defineProperty(_assertThisInitialized(_this), "storage", void 0);
85
72
  _defineProperty(_assertThisInitialized(_this), "orderSQLiteSaveQueue", Promise.resolve());
86
- /** 全局递增的 SQLite 写入序号,便于日志关联同一次操作 */
87
- _defineProperty(_assertThisInitialized(_this), "orderFlowWriteSeq", 0);
88
73
  /** 按 storageKey 记录最近一次 SQLite 写入来源与时间,用于去重 */
89
74
  _defineProperty(_assertThisInitialized(_this), "recentSqliteWriteByStorageKey", new Map());
90
75
  /** 最近一次 SSE 全量拉取完成时间 */
@@ -151,21 +136,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
151
136
  this.store.list = [];
152
137
  this.store.map = new Map();
153
138
  }
154
- this.initOrderFlowLogs();
155
139
  this.initOrderDataSource();
156
140
  this.setupOrderSync();
157
- this.pushOrderFlowLog('initialize.complete', {
158
- hasDbManager: !!this.dbManager,
159
- hasLogger: !!this.logger,
160
- initialOrderCount: this.store.list.length,
161
- createdAtQuery: this.store.createdAtQuery || null
162
- });
163
141
  this.logInfo('OrderServer模块初始化完成', {
164
142
  hasDbManager: !!this.dbManager,
165
143
  hasLogger: !!this.logger,
166
144
  initialOrderCount: this.store.list.length
167
145
  });
168
- case 12:
146
+ case 10:
169
147
  case "end":
170
148
  return _context.stop();
171
149
  }
@@ -216,171 +194,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
216
194
  } catch (_unused2) {
217
195
  // 日志记录失败不影响主流程
218
196
  }
219
- this.pushOrderFlowLog("error.".concat(title), metadata);
220
- }
221
-
222
- /**
223
- * 初始化 window 上的订单流程调试日志数组及辅助方法。
224
- *
225
- * @example
226
- * window.clearOrderModuleFlowLogs()
227
- * // 操作完成后:
228
- * copy(window.exportOrderModuleFlowLogs?.() || '[]')
229
- */
230
- }, {
231
- key: "initOrderFlowLogs",
232
- value: function initOrderFlowLogs() {
233
- var _this2 = this;
234
- try {
235
- var win = typeof globalThis !== 'undefined' ? globalThis.window : undefined;
236
- if (!win) return;
237
- win[ORDER_FLOW_LOG_WINDOW_KEY] = [];
238
- win[ORDER_WRITE_STATS_WINDOW_KEY] = {};
239
- win.clearOrderModuleFlowLogs = function () {
240
- win[ORDER_FLOW_LOG_WINDOW_KEY] = [];
241
- win[ORDER_WRITE_STATS_WINDOW_KEY] = {};
242
- _this2.orderFlowWriteSeq = 0;
243
- _this2.recentSqliteWriteByStorageKey.clear();
244
- _this2.lastServerFullFetchAtMs = 0;
245
- _this2.pushOrderFlowLog('debug.clear', {});
246
- };
247
- win.exportOrderModuleFlowLogs = function () {
248
- var logs = win[ORDER_FLOW_LOG_WINDOW_KEY] || [];
249
- return JSON.stringify(logs, null, 2);
250
- };
251
- win.exportOrderModuleWriteStats = function () {
252
- var stats = win[ORDER_WRITE_STATS_WINDOW_KEY] || {};
253
- return JSON.stringify(stats, null, 2);
254
- };
255
- win.summarizeOrderModuleWrites = function () {
256
- var topN = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 20;
257
- var stats = win[ORDER_WRITE_STATS_WINDOW_KEY] || {};
258
- return Object.entries(stats).map(function (_ref) {
259
- var _last$orderId;
260
- var _ref2 = _slicedToArray(_ref, 2),
261
- storageKey = _ref2[0],
262
- entries = _ref2[1];
263
- var list = entries || [];
264
- var sources = _toConsumableArray(new Set(list.map(function (item) {
265
- return item.source;
266
- })));
267
- var last = list[list.length - 1];
268
- return {
269
- storageKey: storageKey,
270
- orderId: (_last$orderId = last === null || last === void 0 ? void 0 : last.orderId) !== null && _last$orderId !== void 0 ? _last$orderId : null,
271
- writeCount: list.length,
272
- sources: sources,
273
- lastWriteAt: (last === null || last === void 0 ? void 0 : last.ts) || ''
274
- };
275
- }).sort(function (a, b) {
276
- return b.writeCount - a.writeCount;
277
- }).slice(0, topN);
278
- };
279
- this.pushOrderFlowLog('debug.init', {
280
- logKey: ORDER_FLOW_LOG_WINDOW_KEY,
281
- writeStatsKey: ORDER_WRITE_STATS_WINDOW_KEY,
282
- helpers: ['clearOrderModuleFlowLogs', 'exportOrderModuleFlowLogs', 'exportOrderModuleWriteStats', 'summarizeOrderModuleWrites']
283
- });
284
- } catch (_unused3) {
285
- // window 不可用时忽略
286
- }
287
- }
288
-
289
- /**
290
- * 写入 window 订单流程调试日志。
291
- *
292
- * @example
293
- * this.pushOrderFlowLog('mergeOrdersToStore.start', { count: 3 })
294
- */
295
- }, {
296
- key: "pushOrderFlowLog",
297
- value: function pushOrderFlowLog(step, metadata) {
298
- try {
299
- var win = typeof globalThis !== 'undefined' ? globalThis.window : undefined;
300
- if (!win) return;
301
- if (!Array.isArray(win[ORDER_FLOW_LOG_WINDOW_KEY])) {
302
- win[ORDER_FLOW_LOG_WINDOW_KEY] = [];
303
- }
304
- var entry = {
305
- ts: new Date().toISOString(),
306
- step: step,
307
- metadata: metadata || {}
308
- };
309
- win[ORDER_FLOW_LOG_WINDOW_KEY].push(entry);
310
- var logs = win[ORDER_FLOW_LOG_WINDOW_KEY];
311
- if (logs.length > ORDER_FLOW_LOG_MAX_LENGTH) {
312
- logs.splice(0, logs.length - ORDER_FLOW_LOG_MAX_LENGTH);
313
- }
314
- console.log("[OrderFlow] ".concat(step), metadata || {});
315
- } catch (_unused4) {
316
- // 调试日志失败不影响主流程
317
- }
318
- }
319
-
320
- /** 当前内存 store 快照信息,供流程日志使用 */
321
- }, {
322
- key: "getOrderStoreSnapshot",
323
- value: function getOrderStoreSnapshot() {
324
- return {
325
- storeListCount: this.store.list.length,
326
- storeMapCount: this.store.map.size,
327
- pendingSyncCount: this.pendingSyncMessages.length,
328
- isProcessingSyncBatch: this.isProcessingSyncBatch,
329
- isIdlePhase: this.isIdlePhase
330
- };
331
- }
332
-
333
- /**
334
- * 记录一次 SQLite 写入到 window 统计,用于排查同一订单被多次写入的原因。
335
- *
336
- * @example
337
- * this.trackOrderWrite('upsertOrdersFromRemote', 'bulkUpdate', orders, 'insert')
338
- */
339
- }, {
340
- key: "trackOrderWrite",
341
- value: function trackOrderWrite(source, writeMethod, orders) {
342
- var mergeActions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
343
- var defaultMergeAction = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'update';
344
- this.orderFlowWriteSeq += 1;
345
- var writeSeq = this.orderFlowWriteSeq;
346
- try {
347
- var win = typeof globalThis !== 'undefined' ? globalThis.window : undefined;
348
- if (!win) return writeSeq;
349
- if (!win[ORDER_WRITE_STATS_WINDOW_KEY]) {
350
- win[ORDER_WRITE_STATS_WINDOW_KEY] = {};
351
- }
352
- var stats = win[ORDER_WRITE_STATS_WINDOW_KEY];
353
- var _iterator = _createForOfIteratorHelper(orders),
354
- _step;
355
- try {
356
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
357
- var _order$order_id;
358
- var order = _step.value;
359
- var storageKey = this.getOrderStorageKey(order);
360
- if (!storageKey) continue;
361
- var orderKey = order.order_id !== undefined && order.order_id !== null ? this.getIdKey(order.order_id) : '';
362
- var mergeAction = orderKey && mergeActions[orderKey] || defaultMergeAction;
363
- var entry = {
364
- ts: new Date().toISOString(),
365
- writeSeq: writeSeq,
366
- source: source,
367
- writeMethod: writeMethod,
368
- orderId: (_order$order_id = order.order_id) !== null && _order$order_id !== void 0 ? _order$order_id : null,
369
- storageKey: storageKey,
370
- mergeAction: mergeAction
371
- };
372
- if (!stats[storageKey]) stats[storageKey] = [];
373
- stats[storageKey].push(entry);
374
- }
375
- } catch (err) {
376
- _iterator.e(err);
377
- } finally {
378
- _iterator.f();
379
- }
380
- } catch (_unused5) {
381
- // 统计失败不影响主流程
382
- }
383
- return writeSeq;
384
197
  }
385
198
 
386
199
  /**
@@ -393,11 +206,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
393
206
  key: "recordRecentSqliteWrite",
394
207
  value: function recordRecentSqliteWrite(source, orders) {
395
208
  var now = Date.now();
396
- var _iterator2 = _createForOfIteratorHelper(orders),
397
- _step2;
209
+ var _iterator = _createForOfIteratorHelper(orders),
210
+ _step;
398
211
  try {
399
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
400
- var order = _step2.value;
212
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
213
+ var order = _step.value;
401
214
  var storageKey = this.getOrderStorageKey(order);
402
215
  if (!storageKey) continue;
403
216
  this.recentSqliteWriteByStorageKey.set(storageKey, {
@@ -406,9 +219,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
406
219
  });
407
220
  }
408
221
  } catch (err) {
409
- _iterator2.e(err);
222
+ _iterator.e(err);
410
223
  } finally {
411
- _iterator2.f();
224
+ _iterator.f();
412
225
  }
413
226
  }
414
227
 
@@ -431,11 +244,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
431
244
  var now = Date.now();
432
245
  var toWrite = [];
433
246
  var skipped = [];
434
- var _iterator3 = _createForOfIteratorHelper(orders),
435
- _step3;
247
+ var _iterator2 = _createForOfIteratorHelper(orders),
248
+ _step2;
436
249
  try {
437
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
438
- var order = _step3.value;
250
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
251
+ var order = _step2.value;
439
252
  var storageKey = this.getOrderStorageKey(order);
440
253
  if (!storageKey) {
441
254
  toWrite.push(order);
@@ -451,9 +264,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
451
264
  }
452
265
  var recent = this.recentSqliteWriteByStorageKey.get(storageKey);
453
266
  if (recent && ORDER_BUSINESS_WRITE_SOURCES.has(recent.source) && now - recent.ts < ORDER_SQLITE_DEDUPE_MS) {
454
- var _order$order_id2;
267
+ var _order$order_id;
455
268
  skipped.push({
456
- orderId: (_order$order_id2 = order.order_id) !== null && _order$order_id2 !== void 0 ? _order$order_id2 : null,
269
+ orderId: (_order$order_id = order.order_id) !== null && _order$order_id !== void 0 ? _order$order_id : null,
457
270
  storageKey: storageKey,
458
271
  reason: 'skip_pubsub_echo_after_business_write',
459
272
  lastSource: recent.source,
@@ -464,9 +277,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
464
277
  toWrite.push(order);
465
278
  }
466
279
  } catch (err) {
467
- _iterator3.e(err);
280
+ _iterator2.e(err);
468
281
  } finally {
469
- _iterator3.f();
282
+ _iterator2.f();
470
283
  }
471
284
  return {
472
285
  toWrite: toWrite,
@@ -486,11 +299,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
486
299
  var now = Date.now();
487
300
  var toFetch = [];
488
301
  var skipped = [];
489
- var _iterator4 = _createForOfIteratorHelper(ids),
490
- _step4;
302
+ var _iterator3 = _createForOfIteratorHelper(ids),
303
+ _step3;
491
304
  try {
492
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
493
- var id = _step4.value;
305
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
306
+ var id = _step3.value;
494
307
  var existing = this.getOrderByOrderId(id);
495
308
  if (!existing) {
496
309
  toFetch.push(id);
@@ -509,9 +322,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
509
322
  toFetch.push(id);
510
323
  }
511
324
  } catch (err) {
512
- _iterator4.e(err);
325
+ _iterator3.e(err);
513
326
  } finally {
514
- _iterator4.f();
327
+ _iterator3.f();
515
328
  }
516
329
  return {
517
330
  toFetch: toFetch,
@@ -606,12 +419,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
606
419
  key: "preload",
607
420
  value: function () {
608
421
  var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
609
- var _this3 = this;
422
+ var _this2 = this;
610
423
  var getData;
611
424
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
612
425
  while (1) switch (_context3.prev = _context3.next) {
613
426
  case 0:
614
- this.pushOrderFlowLog('preload.start', this.getOrderStoreSnapshot());
615
427
  // const hasPulledInCurrentWindow = this.hasPulledOrdersToday()
616
428
  // // 仅当缓存属于当前统计窗口时才直接复用,避免跨天/跨营业日窗口继续使用旧数据
617
429
  // if (cachedOrders.length > 0 && hasPulledInCurrentWindow) {
@@ -620,7 +432,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
620
432
  // this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list)
621
433
  // return
622
434
  // }
623
-
624
435
  // if (hasPulledInCurrentWindow) {
625
436
  // this.logInfo('当天已完成全量订单拉取,跳过本次全量拉取', {
626
437
  // lastFullFetchAt: this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY),
@@ -628,45 +439,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
628
439
  // return
629
440
  // }
630
441
  getData = /*#__PURE__*/function () {
631
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
442
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
632
443
  var orders;
633
444
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
634
445
  while (1) switch (_context2.prev = _context2.next) {
635
446
  case 0:
636
447
  _context2.next = 2;
637
- return _this3.loadOrdersByServer();
448
+ return _this2.loadOrdersByServer();
638
449
  case 2:
639
450
  orders = _context2.sent;
640
451
  if (!(orders.length === 0)) {
641
- _context2.next = 6;
452
+ _context2.next = 5;
642
453
  break;
643
454
  }
644
- _this3.pushOrderFlowLog('preload.empty', _this3.getOrderStoreSnapshot());
645
455
  return _context2.abrupt("return");
646
- case 6:
647
- _this3.store.list = cloneDeep(orders);
648
- _this3.syncOrdersMap();
649
- _this3.core.effects.emit(OrderHooks.onOrdersChanged, _this3.store.list);
650
- _this3.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
651
- _this3.pushOrderFlowLog('preload.done', _objectSpread(_objectSpread({}, _this3.getOrderStoreSnapshot()), {}, {
652
- loadedCount: orders.length
653
- }));
654
- case 11:
456
+ case 5:
457
+ _this2.store.list = cloneDeep(orders);
458
+ _this2.syncOrdersMap();
459
+ _this2.core.effects.emit(OrderHooks.onOrdersChanged, _this2.store.list);
460
+ _this2.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
461
+ case 9:
655
462
  case "end":
656
463
  return _context2.stop();
657
464
  }
658
465
  }, _callee2);
659
466
  }));
660
467
  return function getData() {
661
- return _ref3.apply(this, arguments);
468
+ return _ref.apply(this, arguments);
662
469
  };
663
470
  }();
664
471
  getData();
665
- case 3:
472
+ case 2:
666
473
  case "end":
667
474
  return _context3.stop();
668
475
  }
669
- }, _callee3, this);
476
+ }, _callee3);
670
477
  }));
671
478
  function preload() {
672
479
  return _preload.apply(this, arguments);
@@ -684,135 +491,121 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
684
491
  return this.store.map.get(this.getIdKey(id));
685
492
  }
686
493
 
687
- /** 按 order_id 查询(推荐) */
494
+ /** 按 order_id 查询内存订单。 */
688
495
  }, {
689
496
  key: "getOrderByOrderId",
690
497
  value: function getOrderByOrderId(orderId) {
691
498
  return this.store.map.get(this.getIdKey(orderId));
692
499
  }
693
500
  }, {
694
- key: "getLocalOrderByOrderId",
501
+ key: "getLocalOrderByLookup",
695
502
  value: function () {
696
- var _getLocalOrderByOrderId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(orderId) {
697
- var _this4 = this;
698
- var key, memoryOrder, orders, localOrder;
503
+ var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(lookup) {
504
+ var _this3 = this;
505
+ var key, memoryOrderById, memoryOrder, orders, localOrder;
699
506
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
700
507
  while (1) switch (_context4.prev = _context4.next) {
701
508
  case 0:
702
- key = this.getIdKey(orderId);
703
- memoryOrder = this.store.map.get(key);
704
- if (!memoryOrder) {
705
- _context4.next = 5;
509
+ key = this.getIdKey(lookup);
510
+ memoryOrderById = this.store.map.get(key);
511
+ if (!memoryOrderById) {
512
+ _context4.next = 4;
706
513
  break;
707
514
  }
708
- this.pushOrderFlowLog('getLocalOrderByOrderId.hitMemory', {
709
- orderId: orderId,
710
- key: key
515
+ return _context4.abrupt("return", memoryOrderById);
516
+ case 4:
517
+ memoryOrder = this.store.list.find(function (order) {
518
+ return _this3.isOrderLookupMatch(order, key);
711
519
  });
520
+ if (!memoryOrder) {
521
+ _context4.next = 7;
522
+ break;
523
+ }
712
524
  return _context4.abrupt("return", memoryOrder);
713
- case 5:
714
- this.pushOrderFlowLog('getLocalOrderByOrderId.missMemory', {
715
- orderId: orderId,
716
- key: key
717
- });
718
- _context4.next = 8;
525
+ case 7:
526
+ _context4.next = 9;
719
527
  return this.loadOrdersFromSQLite();
720
- case 8:
528
+ case 9:
721
529
  orders = _context4.sent;
722
530
  localOrder = orders.find(function (order) {
723
- var shopOrderNumber = order === null || order === void 0 ? void 0 : order.shop_order_number;
724
- if (shopOrderNumber && _this4.getIdKey(shopOrderNumber) === key) return true;
725
- var id = order === null || order === void 0 ? void 0 : order.order_id;
726
- if (id === undefined || id === null) return false;
727
- return _this4.getIdKey(id) === key;
531
+ return _this3.isOrderLookupMatch(order, key);
728
532
  });
729
533
  if (localOrder) {
730
- _context4.next = 12;
534
+ _context4.next = 13;
731
535
  break;
732
536
  }
733
537
  return _context4.abrupt("return", null);
734
- case 12:
538
+ case 13:
735
539
  this.store.list = orders;
736
540
  this.syncOrdersMap();
737
541
  return _context4.abrupt("return", localOrder);
738
- case 15:
542
+ case 16:
739
543
  case "end":
740
544
  return _context4.stop();
741
545
  }
742
546
  }, _callee4, this);
743
547
  }));
744
- function getLocalOrderByOrderId(_x3) {
745
- return _getLocalOrderByOrderId.apply(this, arguments);
548
+ function getLocalOrderByLookup(_x3) {
549
+ return _getLocalOrderByLookup.apply(this, arguments);
746
550
  }
747
- return getLocalOrderByOrderId;
551
+ return getLocalOrderByLookup;
748
552
  }()
749
553
  }, {
750
554
  key: "loadOrdersByServer",
751
555
  value: function () {
752
556
  var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
753
- var _this$store, _this$store2;
557
+ var _this$store;
754
558
  var orderList, data;
755
559
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
756
560
  while (1) switch (_context5.prev = _context5.next) {
757
561
  case 0:
758
562
  orderList = [];
759
- this.pushOrderFlowLog('loadOrdersByServer.start', _objectSpread(_objectSpread({}, this.getOrderStoreSnapshot()), {}, {
760
- query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null,
761
- hasOrderDataSource: !!this.orderDataSource
762
- }));
763
563
  this.logInfo('loadOrdersByServer-开始', {
764
564
  hasOrderDataSource: !!this.orderDataSource,
765
- query: ((_this$store2 = this.store) === null || _this$store2 === void 0 ? void 0 : _this$store2.createdAtQuery) || null
565
+ query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null
766
566
  });
767
567
  if (!this.orderDataSource) {
768
- _context5.next = 20;
568
+ _context5.next = 17;
769
569
  break;
770
570
  }
771
- _context5.prev = 4;
772
- _context5.next = 7;
571
+ _context5.prev = 3;
572
+ _context5.next = 6;
773
573
  return this.orderDataSource.run({
774
574
  sse: {
775
575
  query: this.store.createdAtQuery
776
576
  }
777
577
  });
778
- case 7:
578
+ case 6:
779
579
  data = _context5.sent;
780
580
  orderList = data || [];
781
- this.pushOrderFlowLog('loadOrdersByServer.sseSuccess', {
782
- count: orderList.length
783
- });
784
581
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
785
582
  count: orderList.length
786
583
  });
787
584
  this.markOrderPulledAtNow();
788
585
  this.lastServerFullFetchAtMs = Date.now();
789
- _context5.next = 20;
586
+ _context5.next = 17;
790
587
  break;
791
- case 15:
792
- _context5.prev = 15;
793
- _context5.t0 = _context5["catch"](4);
588
+ case 13:
589
+ _context5.prev = 13;
590
+ _context5.t0 = _context5["catch"](3);
794
591
  orderList = [];
795
- this.pushOrderFlowLog('loadOrdersByServer.sseFailed', {});
796
592
  this.logInfo('loadOrdersByServer-SSE拉取失败,回退为空数组');
797
- case 20:
798
- _context5.next = 22;
593
+ case 17:
594
+ _context5.next = 19;
799
595
  return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer');
800
- case 22:
801
- this.pushOrderFlowLog('loadOrdersByServer.done', _objectSpread({
802
- count: orderList.length
803
- }, this.getOrderStoreSnapshot()));
596
+ case 19:
804
597
  this.logInfo('loadOrdersByServer-结束', {
805
598
  count: orderList.length
806
599
  });
807
- _context5.next = 26;
600
+ _context5.next = 22;
808
601
  return this.core.effects.emit(OrderHooks.onOrdersLoaded, orderList);
809
- case 26:
602
+ case 22:
810
603
  return _context5.abrupt("return", orderList);
811
- case 27:
604
+ case 23:
812
605
  case "end":
813
606
  return _context5.stop();
814
607
  }
815
- }, _callee5, this, [[4, 15]]);
608
+ }, _callee5, this, [[3, 13]]);
816
609
  }));
817
610
  function loadOrdersByServer() {
818
611
  return _loadOrdersByServer.apply(this, arguments);
@@ -835,65 +628,51 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
835
628
  startTime = Date.now();
836
629
  elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
837
630
  if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
838
- _context6.next = 5;
631
+ _context6.next = 4;
839
632
  break;
840
633
  }
841
- this.pushOrderFlowLog('silentRefresh.skipped', _objectSpread({
842
- elapsedMs: elapsedSinceFullFetch,
843
- minIntervalMs: ORDER_SILENT_REFRESH_MIN_INTERVAL_MS
844
- }, this.getOrderStoreSnapshot()));
845
634
  return _context6.abrupt("return", this.store.list);
846
- case 5:
847
- this.pushOrderFlowLog('silentRefresh.start', _objectSpread(_objectSpread({}, this.getOrderStoreSnapshot()), {}, {
848
- callerHint: 'Server.refreshOrdersInBackground 或其他调用方'
849
- }));
635
+ case 4:
850
636
  this.logInfo('silentRefresh 开始');
851
- _context6.prev = 7;
852
- _context6.next = 10;
637
+ _context6.prev = 5;
638
+ _context6.next = 8;
853
639
  return this.loadOrdersByServer();
854
- case 10:
640
+ case 8:
855
641
  orders = _context6.sent;
856
642
  if (!(orders.length > 0)) {
857
- _context6.next = 21;
643
+ _context6.next = 18;
858
644
  break;
859
645
  }
860
646
  this.store.list = cloneDeep(orders);
861
647
  this.syncOrdersMap();
862
648
  this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
863
- _context6.next = 17;
649
+ _context6.next = 15;
864
650
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
865
- case 17:
866
- this.pushOrderFlowLog('silentRefresh.done', _objectSpread({
867
- orderCount: orders.length,
868
- durationMs: Date.now() - startTime
869
- }, this.getOrderStoreSnapshot()));
651
+ case 15:
870
652
  this.logInfo('silentRefresh 完成', {
871
653
  orderCount: orders.length,
872
654
  duration: "".concat(Date.now() - startTime, "ms")
873
655
  });
874
- _context6.next = 23;
656
+ _context6.next = 19;
875
657
  break;
876
- case 21:
877
- this.pushOrderFlowLog('silentRefresh.empty', {
878
- durationMs: Date.now() - startTime
879
- });
658
+ case 18:
880
659
  this.logInfo('silentRefresh: 服务器未返回数据');
881
- case 23:
660
+ case 19:
882
661
  return _context6.abrupt("return", this.store.list);
883
- case 26:
884
- _context6.prev = 26;
885
- _context6.t0 = _context6["catch"](7);
662
+ case 22:
663
+ _context6.prev = 22;
664
+ _context6.t0 = _context6["catch"](5);
886
665
  errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
887
666
  this.logError('silentRefresh 失败', {
888
667
  duration: "".concat(Date.now() - startTime, "ms"),
889
668
  error: errorMessage
890
669
  });
891
670
  return _context6.abrupt("return", this.store.list);
892
- case 31:
671
+ case 27:
893
672
  case "end":
894
673
  return _context6.stop();
895
674
  }
896
- }, _callee6, this, [[7, 26]]);
675
+ }, _callee6, this, [[5, 22]]);
897
676
  }));
898
677
  function silentRefresh() {
899
678
  return _silentRefresh.apply(this, arguments);
@@ -903,10 +682,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
903
682
  }, {
904
683
  key: "getOrdersByResourceId",
905
684
  value: function getOrdersByResourceId(resourceId) {
906
- var _this5 = this;
685
+ var _this4 = this;
907
686
  var ids = this.resourceIdIndex.get(String(resourceId)) || [];
908
687
  return ids.map(function (id) {
909
- return _this5.store.map.get(id);
688
+ return _this4.store.map.get(id);
910
689
  }).filter(function (order) {
911
690
  return !!order;
912
691
  });
@@ -920,7 +699,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
920
699
  key: "overwriteExistingOrder",
921
700
  value: (function () {
922
701
  var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(fresh) {
923
- var _this6 = this;
702
+ var _this5 = this;
924
703
  var orderId, key;
925
704
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
926
705
  while (1) switch (_context7.prev = _context7.next) {
@@ -947,12 +726,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
947
726
  overwritten: false
948
727
  });
949
728
  case 8:
950
- this.pushOrderFlowLog('overwriteExistingOrder.start', _objectSpread(_objectSpread({
951
- orderId: orderId,
952
- storageKey: this.getOrderStorageKey(fresh)
953
- }, this.getOrderStoreSnapshot()), {}, {
954
- callerHint: 'Server.handleUpdateLocalOrder 本地已存在时'
955
- }));
956
729
  this.logInfo('overwriteExistingOrder-开始覆盖', {
957
730
  orderId: orderId,
958
731
  storeOrderCountBefore: this.store.list.length
@@ -960,26 +733,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
960
733
  this.store.list = this.store.list.map(function (order) {
961
734
  var id = order === null || order === void 0 ? void 0 : order.order_id;
962
735
  if (id === undefined || id === null) return order;
963
- return _this6.getIdKey(id) === key ? fresh : order;
736
+ return _this5.getIdKey(id) === key ? fresh : order;
964
737
  });
965
738
  this.syncOrdersMap();
966
- _context7.next = 14;
739
+ _context7.next = 13;
967
740
  return this.updateOrderInSQLite(fresh, 'overwriteExistingOrder');
968
- case 14:
969
- this.pushOrderFlowLog('overwriteExistingOrder.done', _objectSpread({
970
- orderId: orderId
971
- }, this.getOrderStoreSnapshot()));
741
+ case 13:
972
742
  this.logInfo('overwriteExistingOrder-结束', {
973
743
  orderId: orderId,
974
744
  storeOrderCountAfter: this.store.list.length
975
745
  });
976
- _context7.next = 18;
746
+ _context7.next = 16;
977
747
  return this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
978
- case 18:
748
+ case 16:
979
749
  return _context7.abrupt("return", {
980
750
  overwritten: true
981
751
  });
982
- case 19:
752
+ case 17:
983
753
  case "end":
984
754
  return _context7.stop();
985
755
  }
@@ -1009,21 +779,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1009
779
  this.logInfo('upsertOrdersFromRemote-订单列表为空', {});
1010
780
  return _context8.abrupt("return");
1011
781
  case 3:
1012
- this.pushOrderFlowLog('upsertOrdersFromRemote.start', {
1013
- count: freshOrders.length,
1014
- orderIds: freshOrders.map(function (o) {
1015
- return o.order_id;
1016
- }).filter(function (id) {
1017
- return id !== undefined && id !== null;
1018
- }),
1019
- callerHint: 'Server.handleUpdateLocalOrder / handleOrderSalesDetail / handleUpdateLocalOrdersBatch'
1020
- });
1021
782
  this.logInfo('upsertOrdersFromRemote-开始', {
1022
783
  count: freshOrders.length
1023
784
  });
1024
- _context8.next = 7;
785
+ _context8.next = 6;
1025
786
  return this.mergeOrdersToStore(freshOrders, 'upsertOrdersFromRemote');
1026
- case 7:
787
+ case 6:
1027
788
  case "end":
1028
789
  return _context8.stop();
1029
790
  }
@@ -1104,44 +865,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1104
865
  }, {
1105
866
  key: "syncOrdersMap",
1106
867
  value: function syncOrdersMap() {
1107
- var _this7 = this;
868
+ var _this6 = this;
1108
869
  this.store.map.clear();
1109
870
  this.resourceIdIndex.clear();
1110
- var _iterator5 = _createForOfIteratorHelper(this.store.list),
1111
- _step5;
871
+ var _iterator4 = _createForOfIteratorHelper(this.store.list),
872
+ _step4;
1112
873
  try {
1113
874
  var _loop = function _loop() {
1114
- var order = _step5.value;
875
+ var order = _step4.value;
1115
876
  var id = order.order_id;
1116
877
  if (id === undefined || id === null) return 1; // continue
1117
- _this7.store.map.set(_this7.getIdKey(id), order);
1118
- var resourceIds = _this7.extractResourceIds(order);
1119
- var _iterator6 = _createForOfIteratorHelper(resourceIds),
1120
- _step6;
878
+ _this6.store.map.set(_this6.getIdKey(id), order);
879
+ var resourceIds = _this6.extractResourceIds(order);
880
+ var _iterator5 = _createForOfIteratorHelper(resourceIds),
881
+ _step5;
1121
882
  try {
1122
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1123
- var resourceId = _step6.value;
883
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
884
+ var resourceId = _step5.value;
1124
885
  var key = String(resourceId);
1125
- var existing = _this7.resourceIdIndex.get(key) || [];
886
+ var existing = _this6.resourceIdIndex.get(key) || [];
1126
887
  if (existing.some(function (eid) {
1127
- return _this7.getIdKey(eid) === _this7.getIdKey(id);
888
+ return _this6.getIdKey(eid) === _this6.getIdKey(id);
1128
889
  })) continue;
1129
890
  existing.push(id);
1130
- _this7.resourceIdIndex.set(key, existing);
891
+ _this6.resourceIdIndex.set(key, existing);
1131
892
  }
1132
893
  } catch (err) {
1133
- _iterator6.e(err);
894
+ _iterator5.e(err);
1134
895
  } finally {
1135
- _iterator6.f();
896
+ _iterator5.f();
1136
897
  }
1137
898
  };
1138
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
899
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1139
900
  if (_loop()) continue;
1140
901
  }
1141
902
  } catch (err) {
1142
- _iterator5.e(err);
903
+ _iterator4.e(err);
1143
904
  } finally {
1144
- _iterator5.f();
905
+ _iterator4.f();
1145
906
  }
1146
907
  }
1147
908
  }, {
@@ -1196,38 +957,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1196
957
  }, {
1197
958
  key: "setupOrderSync",
1198
959
  value: function setupOrderSync() {
1199
- var _this8 = this;
960
+ var _this7 = this;
1200
961
  if (!this.orderDataSource) return;
1201
962
  this.orderDataSource.run({
1202
963
  pubsub: {
1203
964
  callback: function callback(res) {
1204
- var _message$id, _message$order_id, _message$type, _message$id2, _message$order_id2, _message$type2;
965
+ var _message$id, _message$order_id, _message$type;
1205
966
  console.log('orderDataSource', res);
1206
967
  var pubsubReceivedAt = Date.now();
1207
- var message = _this8.normalizeOrderSyncMessage(res);
968
+ var message = _this7.normalizeOrderSyncMessage(res);
1208
969
  if (!message) return;
1209
970
  message._pubsubReceivedAt = pubsubReceivedAt;
1210
- _this8.pendingSyncMessages.push(message);
1211
- var throttleMs = _this8.getOrderSyncThrottleMs();
1212
- var routeInfo = _this8.resolveSyncMessageRoute(message);
1213
- _this8.pushOrderFlowLog('orderSync.received', _objectSpread(_objectSpread({
971
+ _this7.pendingSyncMessages.push(message);
972
+ var throttleMs = _this7.getOrderSyncThrottleMs();
973
+ var routeInfo = _this7.resolveSyncMessageRoute(message);
974
+ _this7.logInfo('orderSync-收到消息并入队', {
1214
975
  id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
1215
976
  order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
1216
977
  type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
1217
- pendingCount: _this8.pendingSyncMessages.length,
1218
- throttleMs: throttleMs
1219
- }, routeInfo), {}, {
1220
- duplicateRiskHint: routeInfo.route === 'httpRefresh.batchIds' && routeInfo.hasNormalizedBody ? '有 body 但被 ids 优先,会走 HTTP 重拉' : routeInfo.route === 'bodyUpsert' ? 'body 直写,可能与 upsertOrdersFromRemote 重复' : null
1221
- }));
1222
- _this8.logInfo('orderSync-收到消息并入队', {
1223
- id: (_message$id2 = message.id) !== null && _message$id2 !== void 0 ? _message$id2 : null,
1224
- order_id: (_message$order_id2 = message.order_id) !== null && _message$order_id2 !== void 0 ? _message$order_id2 : null,
1225
- type: (_message$type2 = message.type) !== null && _message$type2 !== void 0 ? _message$type2 : null,
1226
- pendingCount: _this8.pendingSyncMessages.length,
978
+ pendingCount: _this7.pendingSyncMessages.length,
1227
979
  throttleMs: throttleMs,
1228
980
  pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString()
1229
981
  });
1230
- _this8.scheduleOrderSyncThrottle();
982
+ _this7.scheduleOrderSyncThrottle();
1231
983
  }
1232
984
  }
1233
985
  }).catch(function () {
@@ -1244,26 +996,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1244
996
  }, {
1245
997
  key: "scheduleOrderSyncThrottle",
1246
998
  value: function scheduleOrderSyncThrottle() {
1247
- var _this9 = this;
999
+ var _this8 = this;
1248
1000
  if (this.isProcessingSyncBatch) return;
1249
1001
  if (this.isIdlePhase) {
1250
1002
  this.isIdlePhase = false;
1251
- this.pushOrderFlowLog('orderSync.flushImmediate', {
1252
- pendingCount: this.pendingSyncMessages.length
1253
- });
1254
1003
  this.logInfo('orderSync-首条消息立即触发处理');
1255
1004
  void this.flushOrderSyncMessagesByThrottle();
1256
1005
  return;
1257
1006
  }
1258
1007
  if (this.syncTimer) return;
1259
1008
  var throttleMs = this.getOrderSyncThrottleMs();
1260
- this.pushOrderFlowLog('orderSync.flushScheduled', {
1261
- pendingCount: this.pendingSyncMessages.length,
1262
- throttleMs: throttleMs
1263
- });
1264
1009
  this.syncTimer = setTimeout(function () {
1265
- _this9.syncTimer = undefined;
1266
- void _this9.flushOrderSyncMessagesByThrottle();
1010
+ _this8.syncTimer = undefined;
1011
+ void _this8.flushOrderSyncMessagesByThrottle();
1267
1012
  }, throttleMs);
1268
1013
  }
1269
1014
 
@@ -1292,26 +1037,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1292
1037
  return _context10.abrupt("return");
1293
1038
  case 5:
1294
1039
  this.isProcessingSyncBatch = true;
1295
- this.pushOrderFlowLog('orderSync.flushStart', {
1296
- pendingCount: this.pendingSyncMessages.length
1297
- });
1298
- _context10.prev = 7;
1299
- _context10.next = 10;
1040
+ _context10.prev = 6;
1041
+ _context10.next = 9;
1300
1042
  return this.processOrderSyncMessages();
1301
- case 10:
1302
- _context10.prev = 10;
1043
+ case 9:
1044
+ _context10.prev = 9;
1303
1045
  this.isProcessingSyncBatch = false;
1304
1046
  if (this.pendingSyncMessages.length > 0) {
1305
1047
  this.scheduleOrderSyncThrottle();
1306
1048
  } else {
1307
1049
  this.isIdlePhase = true;
1308
1050
  }
1309
- return _context10.finish(10);
1310
- case 14:
1051
+ return _context10.finish(9);
1052
+ case 13:
1311
1053
  case "end":
1312
1054
  return _context10.stop();
1313
1055
  }
1314
- }, _callee10, this, [[7,, 10, 14]]);
1056
+ }, _callee10, this, [[6,, 9, 13]]);
1315
1057
  }));
1316
1058
  function flushOrderSyncMessagesByThrottle() {
1317
1059
  return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
@@ -1334,7 +1076,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1334
1076
  key: "processOrderSyncMessages",
1335
1077
  value: (function () {
1336
1078
  var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1337
- var _this10 = this;
1079
+ var _this9 = this;
1338
1080
  var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
1339
1081
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1340
1082
  while (1) switch (_context11.prev = _context11.next) {
@@ -1348,9 +1090,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1348
1090
  return _context11.abrupt("return");
1349
1091
  case 4:
1350
1092
  batchProcessStartAt = Date.now();
1351
- this.pushOrderFlowLog('processOrderSyncMessages.start', _objectSpread({
1352
- messageCount: messages.length
1353
- }, this.getOrderStoreSnapshot()));
1354
1093
  earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
1355
1094
  var _m$_pubsubReceivedAt;
1356
1095
  return (_m$_pubsubReceivedAt = m._pubsubReceivedAt) !== null && _m$_pubsubReceivedAt !== void 0 ? _m$_pubsubReceivedAt : batchProcessStartAt;
@@ -1364,100 +1103,70 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1364
1103
  upsertOrders = new Map();
1365
1104
  refreshIds = [];
1366
1105
  messages.forEach(function (msg, msgIndex) {
1367
- var routeInfo = _this10.resolveSyncMessageRoute(msg);
1368
- _this10.pushOrderFlowLog('processOrderSyncMessages.messageRoute', _objectSpread({
1369
- msgIndex: msgIndex
1370
- }, routeInfo));
1106
+ var routeInfo = _this9.resolveSyncMessageRoute(msg);
1371
1107
  var hasBatchIds = routeInfo.hasBatchIds;
1372
1108
  var singleId = routeInfo.singleId;
1373
1109
  var hasSingleId = routeInfo.hasSingleId;
1374
- var normalizedBody = _this10.normalizeOrderSyncPayload(msg.body || msg.data);
1110
+ var normalizedBody = _this9.normalizeOrderSyncPayload(msg.body || msg.data);
1375
1111
  if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
1376
- upsertOrders.set(_this10.getIdKey(normalizedBody.order_id), normalizedBody);
1112
+ upsertOrders.set(_this9.getIdKey(normalizedBody.order_id), normalizedBody);
1377
1113
  return;
1378
1114
  }
1379
1115
  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));
1380
1116
  });
1381
1117
  uniqueRefreshIds = this.uniqueOrderIds(refreshIds);
1382
1118
  upsertList = _toConsumableArray(upsertOrders.values());
1383
- this.pushOrderFlowLog('processOrderSyncMessages.deduped', {
1384
- upsertCount: upsertList.length,
1385
- upsertOrderIds: upsertList.map(function (o) {
1386
- return o.order_id;
1387
- }),
1388
- refreshIdCount: uniqueRefreshIds.length,
1389
- refreshIds: uniqueRefreshIds,
1390
- willCallMergeTimes: (upsertList.length > 0 ? 1 : 0) + (uniqueRefreshIds.length > 0 ? 1 : 0)
1391
- });
1392
1119
  this.logInfo('processOrderSyncMessages-去重完成', {
1393
1120
  upsertCount: upsertList.length,
1394
1121
  refreshIdCount: uniqueRefreshIds.length
1395
1122
  });
1396
1123
  if (!(upsertList.length > 0)) {
1397
- _context11.next = 18;
1124
+ _context11.next = 16;
1398
1125
  break;
1399
1126
  }
1400
- _context11.next = 18;
1127
+ _context11.next = 16;
1401
1128
  return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
1402
- case 18:
1129
+ case 16:
1403
1130
  if (!(uniqueRefreshIds.length > 0)) {
1404
- _context11.next = 31;
1131
+ _context11.next = 28;
1405
1132
  break;
1406
1133
  }
1407
1134
  _this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
1408
- if (skipped.length > 0) {
1409
- this.pushOrderFlowLog('processOrderSyncMessages.httpRefreshFiltered', {
1410
- requestedIds: uniqueRefreshIds,
1411
- skippedIds: skipped.map(function (item) {
1412
- return item.orderId;
1413
- }),
1414
- skipped: skipped
1415
- });
1416
- }
1135
+ if (skipped.length > 0) {}
1417
1136
  if (!(toFetch.length > 0)) {
1418
- _context11.next = 31;
1137
+ _context11.next = 28;
1419
1138
  break;
1420
1139
  }
1421
- _context11.next = 24;
1140
+ _context11.next = 22;
1422
1141
  return this.fetchOrdersByHttp(toFetch);
1423
- case 24:
1142
+ case 22:
1424
1143
  freshOrders = _context11.sent;
1425
1144
  if (!(freshOrders.length > 0)) {
1426
- _context11.next = 30;
1145
+ _context11.next = 28;
1427
1146
  break;
1428
1147
  }
1429
- _context11.next = 28;
1148
+ _context11.next = 26;
1430
1149
  return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
1431
- case 28:
1432
- _context11.next = 31;
1150
+ case 26:
1151
+ _context11.next = 28;
1433
1152
  break;
1434
- case 30:
1435
- this.pushOrderFlowLog('processOrderSyncMessages.httpRefreshEmpty', {
1436
- refreshIds: toFetch
1437
- });
1438
- case 31:
1153
+ case 28:
1439
1154
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
1440
- _context11.next = 34;
1155
+ _context11.next = 30;
1441
1156
  break;
1442
1157
  }
1443
- this.pushOrderFlowLog('processOrderSyncMessages.noop', {});
1444
1158
  return _context11.abrupt("return");
1445
- case 34:
1159
+ case 30:
1446
1160
  batchProcessEndAt = Date.now();
1447
- this.pushOrderFlowLog('processOrderSyncMessages.done', _objectSpread({
1448
- upsertCount: upsertList.length,
1449
- refreshIdCount: uniqueRefreshIds.length,
1450
- batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt
1451
- }, this.getOrderStoreSnapshot()));
1452
1161
  this.logInfo('processOrderSyncMessages-结束', {
1453
1162
  upsertCount: upsertList.length,
1454
1163
  refreshIdCount: uniqueRefreshIds.length,
1455
1164
  batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
1456
1165
  totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
1457
1166
  });
1458
- _context11.next = 39;
1167
+ _context11.next = 34;
1459
1168
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1460
- case 39:
1169
+ case 34:
1461
1170
  case "end":
1462
1171
  return _context11.stop();
1463
1172
  }
@@ -1493,27 +1202,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1493
1202
  }
1494
1203
  return _context12.abrupt("return", []);
1495
1204
  case 2:
1496
- this.pushOrderFlowLog('fetchOrdersByHttp.start', {
1497
- ids: ids,
1498
- count: ids.length
1499
- });
1500
- _context12.prev = 3;
1205
+ _context12.prev = 2;
1501
1206
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
1502
- _context12.next = 10;
1207
+ _context12.next = 8;
1503
1208
  break;
1504
1209
  }
1505
- _context12.next = 7;
1210
+ _context12.next = 6;
1506
1211
  return this.orderDataSource.fetchOrdersByIds(ids);
1507
- case 7:
1212
+ case 6:
1508
1213
  _orderList = _context12.sent;
1509
- this.pushOrderFlowLog('fetchOrdersByHttp.done', {
1510
- ids: ids,
1511
- count: (_orderList === null || _orderList === void 0 ? void 0 : _orderList.length) || 0,
1512
- via: 'fetchOrdersByIds'
1513
- });
1514
1214
  return _context12.abrupt("return", _orderList || []);
1515
- case 10:
1516
- _context12.next = 12;
1215
+ case 8:
1216
+ _context12.next = 10;
1517
1217
  return this.orderDataSource.run({
1518
1218
  http: {
1519
1219
  query: {
@@ -1521,26 +1221,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1521
1221
  }
1522
1222
  }
1523
1223
  });
1524
- case 12:
1224
+ case 10:
1525
1225
  orderList = _context12.sent;
1526
- this.pushOrderFlowLog('fetchOrdersByHttp.done', {
1527
- ids: ids,
1528
- count: (orderList === null || orderList === void 0 ? void 0 : orderList.length) || 0,
1529
- via: 'run.http'
1530
- });
1531
1226
  return _context12.abrupt("return", orderList || []);
1532
- case 17:
1533
- _context12.prev = 17;
1534
- _context12.t0 = _context12["catch"](3);
1535
- this.pushOrderFlowLog('fetchOrdersByHttp.failed', {
1536
- ids: ids
1537
- });
1227
+ case 14:
1228
+ _context12.prev = 14;
1229
+ _context12.t0 = _context12["catch"](2);
1538
1230
  return _context12.abrupt("return", []);
1539
- case 21:
1231
+ case 17:
1540
1232
  case "end":
1541
1233
  return _context12.stop();
1542
1234
  }
1543
- }, _callee12, this, [[3, 17]]);
1235
+ }, _callee12, this, [[2, 14]]);
1544
1236
  }));
1545
1237
  function fetchOrdersByHttp(_x6) {
1546
1238
  return _fetchOrdersByHttp.apply(this, arguments);
@@ -1555,74 +1247,65 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1555
1247
  key: "mergeOrdersToStore",
1556
1248
  value: (function () {
1557
1249
  var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(freshOrders, source) {
1558
- var _this11 = this;
1559
- var freshMap, _iterator7, _step7, order, id, uniqueFreshCount, patchedOrders, mergeActions, updatedList, _iterator8, _step8, _order, _id, insertCount, updateCount;
1250
+ var _this10 = this;
1251
+ var freshMap, _iterator6, _step6, order, id, uniqueFreshCount, patchedOrders, mergeActions, updatedList, _iterator7, _step7, _order, _id, insertCount, updateCount;
1560
1252
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1561
1253
  while (1) switch (_context13.prev = _context13.next) {
1562
1254
  case 0:
1563
- this.pushOrderFlowLog('mergeOrdersToStore.start', _objectSpread({
1564
- source: source,
1565
- freshOrderCount: freshOrders.length,
1566
- freshOrderIds: freshOrders.map(function (o) {
1567
- return o.order_id;
1568
- }).filter(function (id) {
1569
- return id !== undefined && id !== null;
1570
- })
1571
- }, this.getOrderStoreSnapshot()));
1572
1255
  this.logInfo('mergeOrdersToStore-开始', {
1573
1256
  freshOrderCount: freshOrders.length,
1574
1257
  storeOrderCountBefore: this.store.list.length
1575
1258
  });
1576
1259
  freshMap = new Map();
1577
- _iterator7 = _createForOfIteratorHelper(freshOrders);
1578
- _context13.prev = 4;
1579
- _iterator7.s();
1580
- case 6:
1581
- if ((_step7 = _iterator7.n()).done) {
1582
- _context13.next = 14;
1260
+ _iterator6 = _createForOfIteratorHelper(freshOrders);
1261
+ _context13.prev = 3;
1262
+ _iterator6.s();
1263
+ case 5:
1264
+ if ((_step6 = _iterator6.n()).done) {
1265
+ _context13.next = 13;
1583
1266
  break;
1584
1267
  }
1585
- order = _step7.value;
1268
+ order = _step6.value;
1586
1269
  id = order === null || order === void 0 ? void 0 : order.order_id;
1587
1270
  if (!(id === undefined || id === null)) {
1588
- _context13.next = 11;
1271
+ _context13.next = 10;
1589
1272
  break;
1590
1273
  }
1591
- return _context13.abrupt("continue", 12);
1592
- case 11:
1274
+ return _context13.abrupt("continue", 11);
1275
+ case 10:
1593
1276
  freshMap.set(this.getIdKey(id), order);
1594
- case 12:
1595
- _context13.next = 6;
1277
+ case 11:
1278
+ _context13.next = 5;
1596
1279
  break;
1597
- case 14:
1598
- _context13.next = 19;
1280
+ case 13:
1281
+ _context13.next = 18;
1599
1282
  break;
1600
- case 16:
1601
- _context13.prev = 16;
1602
- _context13.t0 = _context13["catch"](4);
1603
- _iterator7.e(_context13.t0);
1604
- case 19:
1605
- _context13.prev = 19;
1606
- _iterator7.f();
1607
- return _context13.finish(19);
1608
- case 22:
1283
+ case 15:
1284
+ _context13.prev = 15;
1285
+ _context13.t0 = _context13["catch"](3);
1286
+ _iterator6.e(_context13.t0);
1287
+ case 18:
1288
+ _context13.prev = 18;
1289
+ _iterator6.f();
1290
+ return _context13.finish(18);
1291
+ case 21:
1609
1292
  uniqueFreshCount = freshMap.size;
1610
1293
  patchedOrders = _toConsumableArray(freshMap.values());
1611
1294
  mergeActions = {};
1612
1295
  updatedList = this.store.list.map(function (order) {
1613
1296
  var id = order.order_id;
1614
1297
  if (id === undefined || id === null) return order;
1615
- var key = _this11.getIdKey(id);
1298
+ var key = _this10.getIdKey(id);
1616
1299
  if (!freshMap.has(key)) return order;
1617
1300
  var fresh = freshMap.get(key);
1618
1301
  freshMap.delete(key);
1619
1302
  mergeActions[key] = 'update';
1620
1303
  return fresh;
1621
1304
  });
1622
- _iterator8 = _createForOfIteratorHelper(freshMap.values());
1305
+ _iterator7 = _createForOfIteratorHelper(freshMap.values());
1623
1306
  try {
1624
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1625
- _order = _step8.value;
1307
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1308
+ _order = _step7.value;
1626
1309
  _id = _order.order_id;
1627
1310
  if (_id !== undefined && _id !== null) {
1628
1311
  mergeActions[this.getIdKey(_id)] = 'insert';
@@ -1630,9 +1313,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1630
1313
  updatedList.push(_order);
1631
1314
  }
1632
1315
  } catch (err) {
1633
- _iterator8.e(err);
1316
+ _iterator7.e(err);
1634
1317
  } finally {
1635
- _iterator8.f();
1318
+ _iterator7.f();
1636
1319
  }
1637
1320
  insertCount = Object.values(mergeActions).filter(function (v) {
1638
1321
  return v === 'insert';
@@ -1642,33 +1325,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1642
1325
  }).length;
1643
1326
  this.store.list = updatedList;
1644
1327
  this.syncOrdersMap();
1645
- _context13.next = 34;
1328
+ _context13.next = 33;
1646
1329
  return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
1647
- case 34:
1648
- this.pushOrderFlowLog('mergeOrdersToStore.done', _objectSpread({
1649
- source: source,
1650
- uniqueFreshCount: uniqueFreshCount,
1651
- insertCount: insertCount,
1652
- updateCount: updateCount,
1653
- patchedCount: patchedOrders.length,
1654
- patchedOrderIds: patchedOrders.map(function (o) {
1655
- return o.order_id;
1656
- }),
1657
- patchedStorageKeys: patchedOrders.map(function (o) {
1658
- return _this11.getOrderStorageKey(o);
1659
- }),
1660
- mergeActions: mergeActions
1661
- }, this.getOrderStoreSnapshot()));
1330
+ case 33:
1662
1331
  this.logInfo('mergeOrdersToStore-结束', {
1663
1332
  uniqueFreshCount: uniqueFreshCount,
1664
1333
  storeOrderCountAfter: this.store.list.length
1665
1334
  });
1666
1335
  this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
1667
- case 37:
1336
+ case 35:
1668
1337
  case "end":
1669
1338
  return _context13.stop();
1670
1339
  }
1671
- }, _callee13, this, [[4, 16, 19, 22]]);
1340
+ }, _callee13, this, [[3, 15, 18, 21]]);
1672
1341
  }));
1673
1342
  function mergeOrdersToStore(_x7, _x8) {
1674
1343
  return _mergeOrdersToStore.apply(this, arguments);
@@ -1707,17 +1376,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1707
1376
  key: "uniqueOrderIds",
1708
1377
  value: function uniqueOrderIds(ids) {
1709
1378
  var idMap = new Map();
1710
- var _iterator9 = _createForOfIteratorHelper(ids),
1711
- _step9;
1379
+ var _iterator8 = _createForOfIteratorHelper(ids),
1380
+ _step8;
1712
1381
  try {
1713
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1714
- var id = _step9.value;
1382
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1383
+ var id = _step8.value;
1715
1384
  idMap.set(this.getIdKey(id), id);
1716
1385
  }
1717
1386
  } catch (err) {
1718
- _iterator9.e(err);
1387
+ _iterator8.e(err);
1719
1388
  } finally {
1720
- _iterator9.f();
1389
+ _iterator8.f();
1721
1390
  }
1722
1391
  return _toConsumableArray(idMap.values());
1723
1392
  }
@@ -1726,6 +1395,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1726
1395
  value: function getIdKey(id) {
1727
1396
  return String(id);
1728
1397
  }
1398
+ }, {
1399
+ key: "isOrderLookupMatch",
1400
+ value: function isOrderLookupMatch(order, lookupKey) {
1401
+ var _this11 = this;
1402
+ if (!order || !lookupKey) return false;
1403
+ var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
1404
+ return candidates.some(function (value) {
1405
+ if (value === undefined || value === null || value === '') return false;
1406
+ return _this11.getIdKey(value) === lookupKey;
1407
+ });
1408
+ }
1729
1409
 
1730
1410
  /**
1731
1411
  * 解析订单 SQLite 主键,规则与宿主 OrderDataSource.getOrderStorageKey 一致。
@@ -1756,9 +1436,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1756
1436
  }, {
1757
1437
  key: "getCurrentPullWindow",
1758
1438
  value: function getCurrentPullWindow() {
1759
- var _this$store3;
1439
+ var _this$store2;
1760
1440
  var now = dayjs();
1761
- var range = (_this$store3 = this.store) === null || _this$store3 === void 0 || (_this$store3 = _this$store3.createdAtQuery) === null || _this$store3 === void 0 ? void 0 : _this$store3.sales_time_between;
1441
+ var range = (_this$store2 = this.store) === null || _this$store2 === void 0 || (_this$store2 = _this$store2.createdAtQuery) === null || _this$store2 === void 0 ? void 0 : _this$store2.sales_time_between;
1762
1442
  if (Array.isArray(range) && range.length >= 2) {
1763
1443
  var _startAt = dayjs(range[0]);
1764
1444
  var endExclusiveAt = dayjs(range[1]);
@@ -1804,7 +1484,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1804
1484
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
1805
1485
  return globalThis.localStorage.getItem(key);
1806
1486
  }
1807
- } catch (_unused8) {
1487
+ } catch (_unused5) {
1808
1488
  // 忽略存储异常,避免影响主流程
1809
1489
  }
1810
1490
  return null;
@@ -1821,7 +1501,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1821
1501
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
1822
1502
  globalThis.localStorage.setItem(key, value);
1823
1503
  }
1824
- } catch (_unused9) {
1504
+ } catch (_unused6) {
1825
1505
  // 忽略存储异常,避免影响主流程
1826
1506
  }
1827
1507
  }
@@ -1917,164 +1597,121 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1917
1597
  case 0:
1918
1598
  mergeActions = _args17.length > 2 && _args17[2] !== undefined ? _args17[2] : {};
1919
1599
  if (!(!this.dbManager || orders.length === 0)) {
1920
- _context17.next = 4;
1600
+ _context17.next = 3;
1921
1601
  break;
1922
1602
  }
1923
- this.pushOrderFlowLog('patchOrdersInSQLite.skip', {
1924
- source: source,
1925
- hasDbManager: !!this.dbManager,
1926
- inputCount: orders.length
1927
- });
1928
1603
  return _context17.abrupt("return");
1929
- case 4:
1604
+ case 3:
1930
1605
  ordersSnapshot = cloneDeep(orders).filter(function (order) {
1931
1606
  return _this12.getOrderStorageKey(order);
1932
1607
  });
1933
1608
  if (!(ordersSnapshot.length === 0)) {
1934
- _context17.next = 8;
1609
+ _context17.next = 6;
1935
1610
  break;
1936
1611
  }
1937
- this.pushOrderFlowLog('patchOrdersInSQLite.skipNoStorageKey', {
1938
- source: source,
1939
- inputCount: orders.length
1940
- });
1941
1612
  return _context17.abrupt("return");
1942
- case 8:
1613
+ case 6:
1943
1614
  _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
1944
- if (skipped.length > 0) {
1945
- this.pushOrderFlowLog('patchOrdersInSQLite.dedupeSkipped', {
1946
- source: source,
1947
- skippedCount: skipped.length,
1948
- skipped: skipped
1949
- });
1950
- }
1951
1615
  if (!(toWrite.length === 0)) {
1952
- _context17.next = 13;
1616
+ _context17.next = 9;
1953
1617
  break;
1954
1618
  }
1955
- this.pushOrderFlowLog('patchOrdersInSQLite.skipAllDeduped', {
1956
- source: source,
1957
- inputCount: ordersSnapshot.length,
1958
- skipped: skipped
1959
- });
1960
1619
  return _context17.abrupt("return");
1961
- case 13:
1962
- _context17.prev = 13;
1963
- _context17.next = 16;
1620
+ case 9:
1621
+ _context17.prev = 9;
1622
+ _context17.next = 12;
1964
1623
  return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1965
- var writeMethod, _iterator10, _step10, order, writeSeq;
1624
+ var writeMethod, _iterator9, _step9, order;
1966
1625
  return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1967
1626
  while (1) switch (_context16.prev = _context16.next) {
1968
1627
  case 0:
1969
1628
  writeMethod = 'none';
1970
- _this12.pushOrderFlowLog('patchOrdersInSQLite.start', {
1629
+ _this12.logInfo('patchOrdersInSQLite-开始', {
1971
1630
  source: source,
1972
1631
  count: toWrite.length,
1973
- orderIds: toWrite.map(function (o) {
1974
- return o.order_id;
1975
- }),
1976
- storageKeys: toWrite.map(function (o) {
1977
- return _this12.getOrderStorageKey(o);
1978
- }),
1979
1632
  dedupedCount: skipped.length
1980
1633
  });
1981
- _this12.logInfo('patchOrdersInSQLite-开始', {
1982
- source: source,
1983
- count: toWrite.length
1984
- });
1985
1634
  if (!(typeof _this12.dbManager.bulkUpdate === 'function')) {
1986
- _context16.next = 9;
1635
+ _context16.next = 8;
1987
1636
  break;
1988
1637
  }
1989
1638
  writeMethod = 'bulkUpdate';
1990
- _context16.next = 7;
1639
+ _context16.next = 6;
1991
1640
  return _this12.dbManager.bulkUpdate(INDEXDB_STORE_NAME, toWrite);
1992
- case 7:
1993
- _context16.next = 34;
1641
+ case 6:
1642
+ _context16.next = 33;
1994
1643
  break;
1995
- case 9:
1644
+ case 8:
1996
1645
  if (!(typeof _this12.dbManager.bulkAdd === 'function')) {
1997
- _context16.next = 15;
1646
+ _context16.next = 14;
1998
1647
  break;
1999
1648
  }
2000
1649
  writeMethod = 'bulkAdd';
2001
- _context16.next = 13;
1650
+ _context16.next = 12;
2002
1651
  return _this12.dbManager.bulkAdd(INDEXDB_STORE_NAME, toWrite);
2003
- case 13:
2004
- _context16.next = 34;
1652
+ case 12:
1653
+ _context16.next = 33;
2005
1654
  break;
2006
- case 15:
1655
+ case 14:
2007
1656
  if (!(typeof _this12.dbManager.update === 'function')) {
2008
- _context16.next = 34;
1657
+ _context16.next = 33;
2009
1658
  break;
2010
1659
  }
2011
1660
  writeMethod = 'update';
2012
- _iterator10 = _createForOfIteratorHelper(toWrite);
2013
- _context16.prev = 18;
2014
- _iterator10.s();
2015
- case 20:
2016
- if ((_step10 = _iterator10.n()).done) {
2017
- _context16.next = 26;
1661
+ _iterator9 = _createForOfIteratorHelper(toWrite);
1662
+ _context16.prev = 17;
1663
+ _iterator9.s();
1664
+ case 19:
1665
+ if ((_step9 = _iterator9.n()).done) {
1666
+ _context16.next = 25;
2018
1667
  break;
2019
1668
  }
2020
- order = _step10.value;
2021
- _context16.next = 24;
1669
+ order = _step9.value;
1670
+ _context16.next = 23;
2022
1671
  return _this12.dbManager.update(INDEXDB_STORE_NAME, order);
2023
- case 24:
2024
- _context16.next = 20;
1672
+ case 23:
1673
+ _context16.next = 19;
2025
1674
  break;
2026
- case 26:
2027
- _context16.next = 31;
1675
+ case 25:
1676
+ _context16.next = 30;
2028
1677
  break;
2029
- case 28:
2030
- _context16.prev = 28;
2031
- _context16.t0 = _context16["catch"](18);
2032
- _iterator10.e(_context16.t0);
2033
- case 31:
2034
- _context16.prev = 31;
2035
- _iterator10.f();
2036
- return _context16.finish(31);
2037
- case 34:
2038
- writeSeq = _this12.trackOrderWrite(source, writeMethod, toWrite, mergeActions);
1678
+ case 27:
1679
+ _context16.prev = 27;
1680
+ _context16.t0 = _context16["catch"](17);
1681
+ _iterator9.e(_context16.t0);
1682
+ case 30:
1683
+ _context16.prev = 30;
1684
+ _iterator9.f();
1685
+ return _context16.finish(30);
1686
+ case 33:
2039
1687
  _this12.recordRecentSqliteWrite(source, toWrite);
2040
- _this12.pushOrderFlowLog('patchOrdersInSQLite.done', {
2041
- source: source,
2042
- writeSeq: writeSeq,
2043
- count: toWrite.length,
2044
- writeMethod: writeMethod,
2045
- dedupedCount: skipped.length
2046
- });
2047
1688
  _this12.logInfo('patchOrdersInSQLite-完成', {
2048
1689
  source: source,
2049
1690
  count: toWrite.length,
1691
+ writeMethod: writeMethod,
2050
1692
  dedupedCount: skipped.length
2051
1693
  });
2052
- case 38:
1694
+ case 35:
2053
1695
  case "end":
2054
1696
  return _context16.stop();
2055
1697
  }
2056
- }, _callee16, null, [[18, 28, 31, 34]]);
1698
+ }, _callee16, null, [[17, 27, 30, 33]]);
2057
1699
  })));
2058
- case 16:
2059
- _context17.next = 22;
1700
+ case 12:
1701
+ _context17.next = 17;
2060
1702
  break;
2061
- case 18:
2062
- _context17.prev = 18;
2063
- _context17.t0 = _context17["catch"](13);
2064
- this.pushOrderFlowLog('patchOrdersInSQLite.error', {
2065
- source: source,
2066
- error: _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0),
2067
- orderCount: ordersSnapshot.length
2068
- });
1703
+ case 14:
1704
+ _context17.prev = 14;
1705
+ _context17.t0 = _context17["catch"](9);
2069
1706
  this.logError('增量保存订单到 SQLite 失败', {
2070
1707
  error: _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0),
2071
1708
  orderCount: ordersSnapshot.length
2072
1709
  });
2073
- case 22:
1710
+ case 17:
2074
1711
  case "end":
2075
1712
  return _context17.stop();
2076
1713
  }
2077
- }, _callee17, this, [[13, 18]]);
1714
+ }, _callee17, this, [[9, 14]]);
2078
1715
  }));
2079
1716
  function patchOrdersInSQLite(_x10, _x11) {
2080
1717
  return _patchOrdersInSQLite.apply(this, arguments);
@@ -2093,109 +1730,88 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2093
1730
  value: (function () {
2094
1731
  var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(order, source) {
2095
1732
  var _this13 = this;
2096
- var _order$order_id3, orderSnapshot, _orderSnapshot$order_5, _orderSnapshot$order_6;
1733
+ var orderSnapshot, _orderSnapshot$order_3;
2097
1734
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2098
1735
  while (1) switch (_context19.prev = _context19.next) {
2099
1736
  case 0:
2100
1737
  if (!(!this.dbManager || !this.getOrderStorageKey(order))) {
2101
- _context19.next = 3;
1738
+ _context19.next = 2;
2102
1739
  break;
2103
1740
  }
2104
- this.pushOrderFlowLog('updateOrderInSQLite.skip', {
2105
- source: source,
2106
- hasDbManager: !!this.dbManager,
2107
- orderId: (_order$order_id3 = order === null || order === void 0 ? void 0 : order.order_id) !== null && _order$order_id3 !== void 0 ? _order$order_id3 : null
2108
- });
2109
1741
  return _context19.abrupt("return");
2110
- case 3:
1742
+ case 2:
2111
1743
  orderSnapshot = cloneDeep(order);
2112
- _context19.prev = 4;
2113
- _context19.next = 7;
1744
+ _context19.prev = 3;
1745
+ _context19.next = 6;
2114
1746
  return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
2115
- var _orderSnapshot$order_, _orderSnapshot$order_2, _orderSnapshot$order_3, _orderSnapshot$order_4;
2116
- var writeMethod, writeSeq;
1747
+ var _orderSnapshot$order_, _orderSnapshot$order_2;
1748
+ var writeMethod;
2117
1749
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2118
1750
  while (1) switch (_context18.prev = _context18.next) {
2119
1751
  case 0:
2120
1752
  writeMethod = 'none';
2121
- _this13.pushOrderFlowLog('updateOrderInSQLite.start', {
2122
- source: source,
2123
- orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
2124
- storageKey: _this13.getOrderStorageKey(orderSnapshot)
2125
- });
2126
1753
  _this13.logInfo('updateOrderInSQLite-开始', {
2127
1754
  source: source,
2128
- orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
1755
+ orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
2129
1756
  storageKey: _this13.getOrderStorageKey(orderSnapshot)
2130
1757
  });
2131
1758
  if (!(typeof _this13.dbManager.update === 'function')) {
2132
- _context18.next = 9;
1759
+ _context18.next = 8;
2133
1760
  break;
2134
1761
  }
2135
1762
  writeMethod = 'update';
2136
- _context18.next = 7;
1763
+ _context18.next = 6;
2137
1764
  return _this13.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
2138
- case 7:
2139
- _context18.next = 19;
1765
+ case 6:
1766
+ _context18.next = 18;
2140
1767
  break;
2141
- case 9:
1768
+ case 8:
2142
1769
  if (!(typeof _this13.dbManager.bulkUpdate === 'function')) {
2143
- _context18.next = 15;
1770
+ _context18.next = 14;
2144
1771
  break;
2145
1772
  }
2146
1773
  writeMethod = 'bulkUpdate';
2147
- _context18.next = 13;
1774
+ _context18.next = 12;
2148
1775
  return _this13.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
2149
- case 13:
2150
- _context18.next = 19;
1776
+ case 12:
1777
+ _context18.next = 18;
2151
1778
  break;
2152
- case 15:
1779
+ case 14:
2153
1780
  if (!(typeof _this13.dbManager.bulkAdd === 'function')) {
2154
- _context18.next = 19;
1781
+ _context18.next = 18;
2155
1782
  break;
2156
1783
  }
2157
1784
  writeMethod = 'bulkAdd';
2158
- _context18.next = 19;
1785
+ _context18.next = 18;
2159
1786
  return _this13.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
2160
- case 19:
2161
- writeSeq = _this13.trackOrderWrite(source, writeMethod, [orderSnapshot], {}, 'singleUpdate');
1787
+ case 18:
2162
1788
  _this13.recordRecentSqliteWrite(source, [orderSnapshot]);
2163
- _this13.pushOrderFlowLog('updateOrderInSQLite.done', {
1789
+ _this13.logInfo('updateOrderInSQLite-完成', {
2164
1790
  source: source,
2165
- writeSeq: writeSeq,
2166
- orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null,
2167
- storageKey: _this13.getOrderStorageKey(orderSnapshot),
1791
+ orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
2168
1792
  writeMethod: writeMethod
2169
1793
  });
2170
- _this13.logInfo('updateOrderInSQLite-完成', {
2171
- orderId: (_orderSnapshot$order_4 = orderSnapshot.order_id) !== null && _orderSnapshot$order_4 !== void 0 ? _orderSnapshot$order_4 : null
2172
- });
2173
- case 23:
1794
+ case 20:
2174
1795
  case "end":
2175
1796
  return _context18.stop();
2176
1797
  }
2177
1798
  }, _callee18);
2178
1799
  })));
2179
- case 7:
2180
- _context19.next = 13;
1800
+ case 6:
1801
+ _context19.next = 11;
2181
1802
  break;
2182
- case 9:
2183
- _context19.prev = 9;
2184
- _context19.t0 = _context19["catch"](4);
2185
- this.pushOrderFlowLog('updateOrderInSQLite.error', {
2186
- source: source,
2187
- error: _context19.t0 instanceof Error ? _context19.t0.message : String(_context19.t0),
2188
- orderId: (_orderSnapshot$order_5 = orderSnapshot.order_id) !== null && _orderSnapshot$order_5 !== void 0 ? _orderSnapshot$order_5 : null
2189
- });
1803
+ case 8:
1804
+ _context19.prev = 8;
1805
+ _context19.t0 = _context19["catch"](3);
2190
1806
  this.logError('单条保存订单到 SQLite 失败', {
2191
1807
  error: _context19.t0 instanceof Error ? _context19.t0.message : String(_context19.t0),
2192
- orderId: (_orderSnapshot$order_6 = orderSnapshot.order_id) !== null && _orderSnapshot$order_6 !== void 0 ? _orderSnapshot$order_6 : null
1808
+ orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
2193
1809
  });
2194
- case 13:
1810
+ case 11:
2195
1811
  case "end":
2196
1812
  return _context19.stop();
2197
1813
  }
2198
- }, _callee19, this, [[4, 9]]);
1814
+ }, _callee19, this, [[3, 8]]);
2199
1815
  }));
2200
1816
  function updateOrderInSQLite(_x12, _x13) {
2201
1817
  return _updateOrderInSQLite.apply(this, arguments);
@@ -2219,90 +1835,63 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2219
1835
  while (1) switch (_context21.prev = _context21.next) {
2220
1836
  case 0:
2221
1837
  if (this.dbManager) {
2222
- _context21.next = 3;
1838
+ _context21.next = 2;
2223
1839
  break;
2224
1840
  }
2225
- this.pushOrderFlowLog('replaceOrdersSnapshotInSQLite.skip', {
2226
- source: source,
2227
- count: orderList.length
2228
- });
2229
1841
  return _context21.abrupt("return");
2230
- case 3:
1842
+ case 2:
2231
1843
  orderListSnapshot = cloneDeep(orderList);
2232
- _context21.prev = 4;
2233
- _context21.next = 7;
1844
+ _context21.prev = 3;
1845
+ _context21.next = 6;
2234
1846
  return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2235
- var writeSeq;
2236
1847
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2237
1848
  while (1) switch (_context20.prev = _context20.next) {
2238
1849
  case 0:
2239
- _this14.pushOrderFlowLog('replaceOrdersSnapshotInSQLite.start', {
2240
- source: source,
2241
- count: orderListSnapshot.length
2242
- });
2243
1850
  _this14.logInfo('replaceOrdersSnapshotInSQLite-开始', {
2244
1851
  source: source,
2245
1852
  count: orderListSnapshot.length
2246
1853
  });
2247
- _context20.next = 4;
1854
+ _context20.next = 3;
2248
1855
  return _this14.dbManager.clear(INDEXDB_STORE_NAME);
2249
- case 4:
2250
- _this14.pushOrderFlowLog('replaceOrdersSnapshotInSQLite.cleared', {
2251
- source: source,
2252
- count: orderListSnapshot.length
2253
- });
1856
+ case 3:
2254
1857
  _this14.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
2255
1858
  count: orderListSnapshot.length
2256
1859
  });
2257
1860
  if (!(orderListSnapshot.length === 0)) {
2258
- _context20.next = 9;
1861
+ _context20.next = 6;
2259
1862
  break;
2260
1863
  }
2261
- _this14.pushOrderFlowLog('replaceOrdersSnapshotInSQLite.doneEmpty', {
2262
- source: source
2263
- });
2264
1864
  return _context20.abrupt("return");
2265
- case 9:
2266
- _context20.next = 11;
1865
+ case 6:
1866
+ _context20.next = 8;
2267
1867
  return _this14.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderListSnapshot);
2268
- case 11:
2269
- writeSeq = _this14.trackOrderWrite(source, 'clear+bulkAdd', orderListSnapshot, {}, 'snapshot');
1868
+ case 8:
2270
1869
  _this14.recordRecentSqliteWrite(source, orderListSnapshot);
2271
- _this14.pushOrderFlowLog('replaceOrdersSnapshotInSQLite.done', {
2272
- source: source,
2273
- writeSeq: writeSeq,
2274
- count: orderListSnapshot.length,
2275
- writeMethod: 'clear+bulkAdd'
2276
- });
2277
1870
  _this14.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
1871
+ source: source,
2278
1872
  count: orderListSnapshot.length
2279
1873
  });
2280
- case 15:
1874
+ case 10:
2281
1875
  case "end":
2282
1876
  return _context20.stop();
2283
1877
  }
2284
1878
  }, _callee20);
2285
1879
  })));
2286
- case 7:
2287
- _context21.next = 13;
1880
+ case 6:
1881
+ _context21.next = 11;
2288
1882
  break;
2289
- case 9:
2290
- _context21.prev = 9;
2291
- _context21.t0 = _context21["catch"](4);
2292
- this.pushOrderFlowLog('replaceOrdersSnapshotInSQLite.error', {
2293
- source: source,
2294
- error: _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0),
2295
- orderList: orderListSnapshot.length
2296
- });
1883
+ case 8:
1884
+ _context21.prev = 8;
1885
+ _context21.t0 = _context21["catch"](3);
2297
1886
  this.logError('全量保存订单到 SQLite 失败', {
2298
1887
  error: _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0),
2299
1888
  orderList: orderListSnapshot.length
2300
1889
  });
2301
- case 13:
1890
+ case 11:
2302
1891
  case "end":
2303
1892
  return _context21.stop();
2304
1893
  }
2305
- }, _callee21, this, [[4, 9]]);
1894
+ }, _callee21, this, [[3, 8]]);
2306
1895
  }));
2307
1896
  function replaceOrdersSnapshotInSQLite(_x14, _x15) {
2308
1897
  return _replaceOrdersSnapshotInSQLite.apply(this, arguments);