@pisell/pisellos 2.2.121 → 2.2.123

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.
@@ -1,3 +1,7 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ 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."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
1
5
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
6
  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."); }
3
7
  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; } }
@@ -41,6 +45,8 @@ import { filterBookingsFromOrders, sortBookings } from "./modules/order/utils/fi
41
45
 
42
46
  /** 预约列表查询订阅者 */
43
47
 
48
+ /** 非当天(远端)预约查询订阅者 */
49
+
44
50
  /** 平面图 GET 查询订阅者(列表 / id 详情 / code 详情) */
45
51
  /**
46
52
  * Server 类
@@ -78,6 +84,10 @@ var Server = /*#__PURE__*/function () {
78
84
  // ---- 订单 / 预约列表查询订阅者 ----
79
85
  _defineProperty(this, "orderQuerySubscribers", new Map());
80
86
  _defineProperty(this, "bookingQuerySubscribers", new Map());
87
+ _defineProperty(this, "bookingRemoteQuerySubscribers", new Map());
88
+ _defineProperty(this, "bookingRemoteCache", new Map());
89
+ _defineProperty(this, "BOOKING_REMOTE_CACHE_TTL_MS", 5 * 60 * 1000);
90
+ _defineProperty(this, "BOOKING_REMOTE_CACHE_MAX_ENTRIES", 80);
81
91
  _defineProperty(this, "floorPlanQuerySubscribers", new Map());
82
92
  // 模块注册表 - 定义所有可用的模块配置
83
93
  _defineProperty(this, "moduleRegistry", {
@@ -235,7 +245,7 @@ var Server = /*#__PURE__*/function () {
235
245
  */
236
246
  _defineProperty(this, "handleOrderList", /*#__PURE__*/function () {
237
247
  var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref7) {
238
- var url, method, data, config, queryPayload, _ref9, callback, subscriberId;
248
+ var url, method, data, config, queryPayload, _ref9, callback, subscriberId, useLocal;
239
249
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
240
250
  while (1) switch (_context3.prev = _context3.next) {
241
251
  case 0:
@@ -243,9 +253,15 @@ var Server = /*#__PURE__*/function () {
243
253
  console.log('[Server] handleOrderList:', url, method, data, config);
244
254
  queryPayload = data && _typeof(data) === 'object' ? _objectSpread({}, data) : {};
245
255
  _ref9 = config || {}, callback = _ref9.callback, subscriberId = _ref9.subscriberId;
256
+ useLocal = _this.shouldUseLocalOrderQuery(queryPayload);
246
257
  _this.logInfo('handleOrderList: 开始处理订单列表请求', {
247
- data: queryPayload
258
+ data: queryPayload,
259
+ useLocal: useLocal
248
260
  });
261
+ if (!useLocal) {
262
+ _context3.next = 9;
263
+ break;
264
+ }
249
265
  if (subscriberId && typeof callback === 'function') {
250
266
  _this.orderQuerySubscribers.set(subscriberId, {
251
267
  callback: callback,
@@ -257,7 +273,16 @@ var Server = /*#__PURE__*/function () {
257
273
  });
258
274
  }
259
275
  return _context3.abrupt("return", _this.computeOrderQueryResult(queryPayload));
260
- case 7:
276
+ case 9:
277
+ if (subscriberId) {
278
+ _this.orderQuerySubscribers.delete(subscriberId);
279
+ _this.logInfo('handleOrderList: 已清理订阅者(走远端)', {
280
+ subscriberId: subscriberId,
281
+ remaining: _this.orderQuerySubscribers.size
282
+ });
283
+ }
284
+ return _context3.abrupt("return", _this.fetchOrderListFromAPI(queryPayload));
285
+ case 11:
261
286
  case "end":
262
287
  return _context3.stop();
263
288
  }
@@ -306,7 +331,7 @@ var Server = /*#__PURE__*/function () {
306
331
  */
307
332
  _defineProperty(this, "handleBookingList", /*#__PURE__*/function () {
308
333
  var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref13) {
309
- var url, method, data, config, queryPayload, _ref15, callback, subscriberId, isToday;
334
+ var url, method, data, config, queryPayload, _ref15, callback, subscriberId, useLocal, withFields, requestPayload, cacheKey;
310
335
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
311
336
  while (1) switch (_context5.prev = _context5.next) {
312
337
  case 0:
@@ -314,15 +339,18 @@ var Server = /*#__PURE__*/function () {
314
339
  console.log('[Server] handleBookingList:', url, method, data, config);
315
340
  queryPayload = data && _typeof(data) === 'object' ? _objectSpread({}, data) : {};
316
341
  _ref15 = config || {}, callback = _ref15.callback, subscriberId = _ref15.subscriberId;
317
- isToday = _this.isBookingQueryForToday(queryPayload);
342
+ useLocal = _this.shouldUseLocalBookingQuery(queryPayload);
318
343
  _this.logInfo('handleBookingList: 开始处理预约列表请求', {
319
344
  data: queryPayload,
320
- isToday: isToday
345
+ useLocal: useLocal
321
346
  });
322
- if (!isToday) {
323
- _context5.next = 11;
347
+ if (!useLocal) {
348
+ _context5.next = 12;
324
349
  break;
325
350
  }
351
+ if (subscriberId) {
352
+ _this.bookingRemoteQuerySubscribers.delete(subscriberId);
353
+ }
326
354
  if (subscriberId && typeof callback === 'function') {
327
355
  _this.bookingQuerySubscribers.set(subscriberId, {
328
356
  callback: callback,
@@ -334,16 +362,33 @@ var Server = /*#__PURE__*/function () {
334
362
  });
335
363
  }
336
364
  return _context5.abrupt("return", _this.computeBookingQueryResult(queryPayload));
337
- case 11:
365
+ case 12:
338
366
  if (subscriberId) {
339
367
  _this.bookingQuerySubscribers.delete(subscriberId);
368
+ }
369
+ if (subscriberId && typeof callback === 'function') {
370
+ withFields = _this.resolveBookingSalesWith(queryPayload);
371
+ requestPayload = _this.normalizeBookingRemoteQueryPayload(queryPayload, withFields);
372
+ cacheKey = _this.buildBookingRemoteCacheKey(requestPayload);
373
+ _this.bookingRemoteQuerySubscribers.set(subscriberId, {
374
+ callback: callback,
375
+ context: queryPayload,
376
+ cacheKey: cacheKey
377
+ });
378
+ _this.logInfo('handleBookingList: 已注册订阅者(非今天)', {
379
+ subscriberId: subscriberId,
380
+ cacheKey: cacheKey,
381
+ totalSubscribers: _this.bookingRemoteQuerySubscribers.size
382
+ });
383
+ }
384
+ if (subscriberId) {
340
385
  _this.logInfo('handleBookingList: 已清理订阅者(非今天)', {
341
386
  subscriberId: subscriberId,
342
387
  remaining: _this.bookingQuerySubscribers.size
343
388
  });
344
389
  }
345
390
  return _context5.abrupt("return", _this.fetchBookingListFromAPI(queryPayload));
346
- case 13:
391
+ case 16:
347
392
  case "end":
348
393
  return _context5.stop();
349
394
  }
@@ -470,9 +515,11 @@ var Server = /*#__PURE__*/function () {
470
515
  _ref23 = data || {}, subscriberId = _ref23.subscriberId;
471
516
  if (subscriberId) {
472
517
  _this.bookingQuerySubscribers.delete(subscriberId);
518
+ _this.bookingRemoteQuerySubscribers.delete(subscriberId);
473
519
  _this.logInfo('handleUnsubscribeBookingQuery: 已移除订阅者', {
474
520
  subscriberId: subscriberId,
475
- remaining: _this.bookingQuerySubscribers.size
521
+ remainingLocal: _this.bookingQuerySubscribers.size,
522
+ remainingRemote: _this.bookingRemoteQuerySubscribers.size
476
523
  });
477
524
  }
478
525
  return _context8.abrupt("return", {
@@ -1115,6 +1162,7 @@ var Server = /*#__PURE__*/function () {
1115
1162
  this.core.effects.on(OrderHooks.onOrdersChanged, function () {
1116
1163
  _this3.recomputeAndNotifyOrderQuery();
1117
1164
  _this3.recomputeAndNotifyBookingQuery();
1165
+ _this3.syncBookingRemoteCacheFromOrderChanges();
1118
1166
  });
1119
1167
  duration = Date.now() - startTime;
1120
1168
  this.logInfo('Server 初始化完成', {
@@ -1539,28 +1587,387 @@ var Server = /*#__PURE__*/function () {
1539
1587
  }
1540
1588
  }
1541
1589
  }, {
1542
- key: "isBookingQueryForToday",
1590
+ key: "extractQueryDate",
1543
1591
  value:
1544
1592
  /**
1545
- * 判断预约查询的 sales_time_between 起始日期是否为今天
1593
+ * 从查询值中提取 YYYY-MM-DD 日期串。
1594
+ *
1595
+ * @example
1596
+ * this.extractQueryDate('2026-04-15 09:58:00') // => '2026-04-15'
1546
1597
  */
1547
- function isBookingQueryForToday(data) {
1598
+ function extractQueryDate(raw) {
1599
+ if (raw == null) return null;
1600
+ var date = dayjs(raw);
1601
+ if (date.isValid()) {
1602
+ return date.format('YYYY-MM-DD');
1603
+ }
1604
+ var text = String(raw).trim();
1605
+ if (!text) return null;
1606
+ return text.split('T')[0].split(' ')[0] || null;
1607
+ }
1608
+
1609
+ /**
1610
+ * 判断时间范围是否「开始和结束都不是今天」。
1611
+ *
1612
+ * @example
1613
+ * this.isRangeBothNotToday('2026-04-13', '2026-04-14') // => true
1614
+ */
1615
+ }, {
1616
+ key: "isRangeBothNotToday",
1617
+ value: function isRangeBothNotToday(startRaw, endRaw) {
1618
+ var startDate = this.extractQueryDate(startRaw);
1619
+ var endDate = this.extractQueryDate(endRaw);
1620
+ if (!startDate || !endDate) return false;
1621
+ var today = dayjs().format('YYYY-MM-DD');
1622
+ return startDate !== today && endDate !== today;
1623
+ }
1624
+
1625
+ /**
1626
+ * 订单查询是否走本地:
1627
+ * - 当 start_time 与 end_time 都不是今天时,走远端;
1628
+ * - 其余情况走本地。
1629
+ */
1630
+ }, {
1631
+ key: "shouldUseLocalOrderQuery",
1632
+ value: function shouldUseLocalOrderQuery(data) {
1633
+ return !this.isRangeBothNotToday(data === null || data === void 0 ? void 0 : data.start_time, data === null || data === void 0 ? void 0 : data.end_time);
1634
+ }
1635
+
1636
+ /**
1637
+ * 预约查询是否走本地:
1638
+ * - 当 sales_time_between 的开始和结束都不是今天时,走远端;
1639
+ * - 其余情况走本地。
1640
+ */
1641
+ }, {
1642
+ key: "shouldUseLocalBookingQuery",
1643
+ value: function shouldUseLocalBookingQuery(data) {
1548
1644
  var range = data === null || data === void 0 ? void 0 : data.sales_time_between;
1549
- if (!Array.isArray(range) || range.length < 1) return true;
1550
- var startDateStr = String(range[0]).split('T')[0].split(' ')[0];
1551
- var todayStr = dayjs().format('YYYY-MM-DD');
1552
- return startDateStr === todayStr;
1645
+ if (!Array.isArray(range) || range.length < 2) return true;
1646
+ return !this.isRangeBothNotToday(range[0], range[1]);
1553
1647
  }
1554
1648
 
1555
1649
  /**
1556
- * 非今天的预约查询:通过真实 API 获取数据,再做 flattenOrdersToBookings 拆分
1650
+ * 日历 SSE 精简 with:只拉日历渲染必需的关联字段
1557
1651
  */
1558
1652
  }, {
1559
- key: "fetchBookingListFromAPI",
1653
+ key: "resolveBookingSalesWith",
1654
+ value: function resolveBookingSalesWith(_queryPayload) {
1655
+ return ['bookings:booking_id,start_date,start_time,end_date,end_time,holder,metadata,parent_id,item_type', 'customer:id,display_name,phone', 'products'];
1656
+ }
1657
+
1658
+ /**
1659
+ * 日历 SSE 精简 select:渲染 + filterBookingsFromOrders 所需的主表字段
1660
+ * business_code / payment_status 不直接用于渲染,但 matchOrder 过滤依赖
1661
+ */
1662
+ }, {
1663
+ key: "resolveBookingSalesSelect",
1664
+ value: function resolveBookingSalesSelect() {
1665
+ return 'status,payment_status,business_code,phone,customer_name,schedule_date,created_at,metadata';
1666
+ }
1667
+ }, {
1668
+ key: "normalizeBookingRemoteQueryPayload",
1669
+ value: function normalizeBookingRemoteQueryPayload(data, withFields) {
1670
+ return _objectSpread(_objectSpread({}, data), {}, {
1671
+ form_record_ids: undefined,
1672
+ enable_remote_memory_cache: undefined,
1673
+ with: withFields,
1674
+ select: this.resolveBookingSalesSelect(),
1675
+ chunk_size: 50
1676
+ });
1677
+ }
1678
+
1679
+ /**
1680
+ * 远端预约查询内存缓存开关:默认 false,仅显式 true 才启用。
1681
+ */
1682
+ }, {
1683
+ key: "isBookingRemoteMemoryCacheEnabled",
1684
+ value: function isBookingRemoteMemoryCacheEnabled(queryPayload) {
1685
+ return (queryPayload === null || queryPayload === void 0 ? void 0 : queryPayload.enable_remote_memory_cache) === true;
1686
+ }
1687
+ }, {
1688
+ key: "stableSerialize",
1689
+ value: function stableSerialize(value) {
1690
+ var _this5 = this;
1691
+ if (value === null || value === undefined) return 'null';
1692
+ if (Array.isArray(value)) {
1693
+ return "[".concat(value.map(function (item) {
1694
+ return _this5.stableSerialize(item);
1695
+ }).join(','), "]");
1696
+ }
1697
+ if (_typeof(value) === 'object') {
1698
+ var obj = value;
1699
+ var keys = Object.keys(obj).filter(function (k) {
1700
+ return obj[k] !== undefined;
1701
+ }).sort();
1702
+ return "{".concat(keys.map(function (k) {
1703
+ return "".concat(JSON.stringify(k), ":").concat(_this5.stableSerialize(obj[k]));
1704
+ }).join(','), "}");
1705
+ }
1706
+ return JSON.stringify(value);
1707
+ }
1708
+ }, {
1709
+ key: "buildBookingRemoteCacheKey",
1710
+ value: function buildBookingRemoteCacheKey(payload) {
1711
+ return this.stableSerialize(payload);
1712
+ }
1713
+ }, {
1714
+ key: "parseBookingSalesRangeMeta",
1715
+ value: function parseBookingSalesRangeMeta(payload) {
1716
+ var range = payload === null || payload === void 0 ? void 0 : payload.sales_time_between;
1717
+ if (!Array.isArray(range) || range.length < 2) return null;
1718
+ var startAtMs = dayjs(range[0]).valueOf();
1719
+ var endAtMs = dayjs(range[1]).valueOf();
1720
+ if (!Number.isFinite(startAtMs) || !Number.isFinite(endAtMs)) return null;
1721
+ if (endAtMs <= startAtMs) return null;
1722
+ return {
1723
+ startAtMs: startAtMs,
1724
+ endAtMs: endAtMs
1725
+ };
1726
+ }
1727
+ }, {
1728
+ key: "readBookingRemoteCache",
1729
+ value: function readBookingRemoteCache(cacheKey) {
1730
+ var entry = this.bookingRemoteCache.get(cacheKey);
1731
+ if (!entry) return null;
1732
+ if (entry.stale) {
1733
+ this.bookingRemoteCache.delete(cacheKey);
1734
+ return null;
1735
+ }
1736
+ var now = Date.now();
1737
+ if (now - entry.updatedAt > this.BOOKING_REMOTE_CACHE_TTL_MS) {
1738
+ this.bookingRemoteCache.delete(cacheKey);
1739
+ return null;
1740
+ }
1741
+ return entry;
1742
+ }
1743
+ }, {
1744
+ key: "writeBookingRemoteCache",
1745
+ value: function writeBookingRemoteCache(entry) {
1746
+ this.bookingRemoteCache.set(entry.key, entry);
1747
+ if (this.bookingRemoteCache.size <= this.BOOKING_REMOTE_CACHE_MAX_ENTRIES) {
1748
+ return;
1749
+ }
1750
+ var oldestKey = null;
1751
+ var oldestTime = Number.POSITIVE_INFINITY;
1752
+ var _iterator5 = _createForOfIteratorHelper(this.bookingRemoteCache.entries()),
1753
+ _step5;
1754
+ try {
1755
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1756
+ var _step5$value = _slicedToArray(_step5.value, 2),
1757
+ key = _step5$value[0],
1758
+ cache = _step5$value[1];
1759
+ if (cache.updatedAt < oldestTime) {
1760
+ oldestTime = cache.updatedAt;
1761
+ oldestKey = key;
1762
+ }
1763
+ }
1764
+ } catch (err) {
1765
+ _iterator5.e(err);
1766
+ } finally {
1767
+ _iterator5.f();
1768
+ }
1769
+ if (oldestKey) this.bookingRemoteCache.delete(oldestKey);
1770
+ }
1771
+ }, {
1772
+ key: "toOrderIdKey",
1773
+ value: function toOrderIdKey(order) {
1774
+ if (!order || _typeof(order) !== 'object') return null;
1775
+ var raw = order.order_id;
1776
+ if (raw === undefined || raw === null || raw === '') return null;
1777
+ return String(raw);
1778
+ }
1779
+ }, {
1780
+ key: "markBookingRemoteCacheAllStale",
1781
+ value: function markBookingRemoteCacheAllStale(reason) {
1782
+ if (this.bookingRemoteCache.size === 0) return;
1783
+ var _iterator6 = _createForOfIteratorHelper(this.bookingRemoteCache.values()),
1784
+ _step6;
1785
+ try {
1786
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1787
+ var entry = _step6.value;
1788
+ entry.stale = true;
1789
+ }
1790
+ } catch (err) {
1791
+ _iterator6.e(err);
1792
+ } finally {
1793
+ _iterator6.f();
1794
+ }
1795
+ this.logWarning('bookingRemoteCache: 全量标记失效', {
1796
+ reason: reason,
1797
+ cacheSize: this.bookingRemoteCache.size
1798
+ });
1799
+ }
1800
+ }, {
1801
+ key: "buildBookingResponse",
1802
+ value: function buildBookingResponse(bookingResult, extra) {
1803
+ return {
1804
+ code: 200,
1805
+ data: _objectSpread(_objectSpread({}, extra !== null && extra !== void 0 ? extra : {}), {}, {
1806
+ list: bookingResult.list || [],
1807
+ count: bookingResult.count || 0,
1808
+ size: bookingResult.size || 0,
1809
+ skip: bookingResult.skip || 0
1810
+ }),
1811
+ message: '',
1812
+ status: true
1813
+ };
1814
+ }
1815
+ }, {
1816
+ key: "notifyBookingRemoteSubscribersByCacheKey",
1817
+ value: function notifyBookingRemoteSubscribersByCacheKey(cacheKey, entry, reason) {
1818
+ if (this.bookingRemoteQuerySubscribers.size === 0) return;
1819
+ var _iterator7 = _createForOfIteratorHelper(this.bookingRemoteQuerySubscribers.entries()),
1820
+ _step7;
1821
+ try {
1822
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1823
+ var _step7$value = _slicedToArray(_step7.value, 2),
1824
+ subscriberId = _step7$value[0],
1825
+ subscriber = _step7$value[1];
1826
+ if (subscriber.cacheKey !== cacheKey) continue;
1827
+ try {
1828
+ var callbackStartAt = Date.now();
1829
+ subscriber.callback(this.buildBookingResponse(entry.bookingResult, {
1830
+ cache_hit: true,
1831
+ from_cache_sync: true,
1832
+ sync_reason: reason
1833
+ }));
1834
+ var callbackEndAt = Date.now();
1835
+ this.logInfo('notifyBookingRemoteSubscribersByCacheKey: 已推送', {
1836
+ subscriberId: subscriberId,
1837
+ cacheKey: cacheKey,
1838
+ reason: reason,
1839
+ callbackDurationMs: callbackEndAt - callbackStartAt
1840
+ });
1841
+ } catch (error) {
1842
+ var errMsg = error instanceof Error ? error.message : String(error);
1843
+ this.logError('notifyBookingRemoteSubscribersByCacheKey: 推送失败', {
1844
+ subscriberId: subscriberId,
1845
+ cacheKey: cacheKey,
1846
+ reason: reason,
1847
+ error: errMsg
1848
+ });
1849
+ }
1850
+ }
1851
+ } catch (err) {
1852
+ _iterator7.e(err);
1853
+ } finally {
1854
+ _iterator7.f();
1855
+ }
1856
+ }
1857
+ }, {
1858
+ key: "syncBookingRemoteCacheFromOrderChanges",
1859
+ value: function syncBookingRemoteCacheFromOrderChanges() {
1860
+ var _this$order$getOrders, _this$order, _this$order$getOrders2;
1861
+ if (this.bookingRemoteCache.size === 0) return;
1862
+ var syncStartAt = Date.now();
1863
+ var latestOrders = (_this$order$getOrders = (_this$order = this.order) === null || _this$order === void 0 || (_this$order$getOrders2 = _this$order.getOrders) === null || _this$order$getOrders2 === void 0 ? void 0 : _this$order$getOrders2.call(_this$order)) !== null && _this$order$getOrders !== void 0 ? _this$order$getOrders : [];
1864
+ if (!Array.isArray(latestOrders) || latestOrders.length === 0) {
1865
+ this.markBookingRemoteCacheAllStale('orderStoreEmptyAfterChange');
1866
+ return;
1867
+ }
1868
+ var syncedEntryCount = 0;
1869
+ var _iterator8 = _createForOfIteratorHelper(this.bookingRemoteCache.entries()),
1870
+ _step8;
1871
+ try {
1872
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1873
+ var _step8$value = _slicedToArray(_step8.value, 2),
1874
+ cacheKey = _step8$value[0],
1875
+ entry = _step8$value[1];
1876
+ if (entry.stale) {
1877
+ this.bookingRemoteCache.delete(cacheKey);
1878
+ continue;
1879
+ }
1880
+ try {
1881
+ var queryPayload = entry.queryPayload;
1882
+ var orderMap = new Map();
1883
+ var _iterator9 = _createForOfIteratorHelper(entry.rawOrders),
1884
+ _step9;
1885
+ try {
1886
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1887
+ var order = _step9.value;
1888
+ var key = this.toOrderIdKey(order);
1889
+ if (key) orderMap.set(key, order);
1890
+ }
1891
+ } catch (err) {
1892
+ _iterator9.e(err);
1893
+ } finally {
1894
+ _iterator9.f();
1895
+ }
1896
+ var changed = false;
1897
+ var _iterator10 = _createForOfIteratorHelper(latestOrders),
1898
+ _step10;
1899
+ try {
1900
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1901
+ var latest = _step10.value;
1902
+ var _key = this.toOrderIdKey(latest);
1903
+ if (!_key) continue;
1904
+ if (orderMap.has(_key)) {
1905
+ orderMap.set(_key, latest);
1906
+ changed = true;
1907
+ continue;
1908
+ }
1909
+ orderMap.set(_key, latest);
1910
+ changed = true;
1911
+ }
1912
+ } catch (err) {
1913
+ _iterator10.e(err);
1914
+ } finally {
1915
+ _iterator10.f();
1916
+ }
1917
+ if (!changed) continue;
1918
+ var mergedOrders = _toConsumableArray(orderMap.values());
1919
+ var filterStartAt = Date.now();
1920
+ var bookingResult = sortBookings(filterBookingsFromOrders(mergedOrders, queryPayload), queryPayload);
1921
+ var filterEndAt = Date.now();
1922
+ var nextEntry = _objectSpread(_objectSpread({}, entry), {}, {
1923
+ rawOrders: mergedOrders,
1924
+ bookingResult: bookingResult,
1925
+ updatedAt: Date.now(),
1926
+ stale: false
1927
+ });
1928
+ this.writeBookingRemoteCache(nextEntry);
1929
+ this.notifyBookingRemoteSubscribersByCacheKey(cacheKey, nextEntry, 'orders_changed');
1930
+ syncedEntryCount += 1;
1931
+ this.logInfo('bookingRemoteCache: 单条缓存同步完成', {
1932
+ cacheKey: cacheKey,
1933
+ mergedOrderCount: mergedOrders.length,
1934
+ filteredBookingCount: bookingResult.count,
1935
+ filterDurationMs: filterEndAt - filterStartAt
1936
+ });
1937
+ } catch (error) {
1938
+ var errMsg = error instanceof Error ? error.message : String(error);
1939
+ this.logWarning('bookingRemoteCache: 同步失败并标记失效', {
1940
+ cacheKey: cacheKey,
1941
+ error: errMsg
1942
+ });
1943
+ var current = this.bookingRemoteCache.get(cacheKey);
1944
+ if (current) current.stale = true;
1945
+ }
1946
+ }
1947
+ } catch (err) {
1948
+ _iterator8.e(err);
1949
+ } finally {
1950
+ _iterator8.f();
1951
+ }
1952
+ var syncEndAt = Date.now();
1953
+ if (syncedEntryCount > 0) {
1954
+ this.logInfo('bookingRemoteCache: 已同步 Ably 变更', {
1955
+ syncedEntryCount: syncedEntryCount,
1956
+ cacheSize: this.bookingRemoteCache.size,
1957
+ totalSyncDurationMs: syncEndAt - syncStartAt
1958
+ });
1959
+ }
1960
+ }
1961
+
1962
+ /**
1963
+ * 非本地窗口的订单查询:走真实 API。
1964
+ */
1965
+ }, {
1966
+ key: "fetchOrderListFromAPI",
1560
1967
  value: (function () {
1561
- var _fetchBookingListFromAPI = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(data) {
1968
+ var _fetchOrderListFromAPI = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(data) {
1562
1969
  var _this$app2;
1563
- var _ref26, _response$data$list, _response$data, response, rawList, list, errorMessage;
1970
+ var _response$data, response, payload, list, count, errorMessage;
1564
1971
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1565
1972
  while (1) switch (_context18.prev = _context18.next) {
1566
1973
  case 0:
@@ -1568,7 +1975,7 @@ var Server = /*#__PURE__*/function () {
1568
1975
  _context18.next = 3;
1569
1976
  break;
1570
1977
  }
1571
- this.logError('fetchBookingListFromAPI: app.request 不可用');
1978
+ this.logError('fetchOrderListFromAPI: app.request 不可用');
1572
1979
  return _context18.abrupt("return", {
1573
1980
  code: 500,
1574
1981
  message: 'app.request 不可用',
@@ -1581,24 +1988,19 @@ var Server = /*#__PURE__*/function () {
1581
1988
  case 3:
1582
1989
  _context18.prev = 3;
1583
1990
  _context18.next = 6;
1584
- return this.app.request.get('/shop/order/sales', _objectSpread(_objectSpread({}, data), {}, {
1585
- form_record_ids: undefined,
1586
- with: ["all"]
1587
- }), {
1991
+ return this.app.request.post('/shop/order/v2/list', data, {
1588
1992
  isShopApi: true
1589
1993
  });
1590
1994
  case 6:
1591
1995
  response = _context18.sent;
1592
- rawList = (_ref26 = (_response$data$list = response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list) !== null && _response$data$list !== void 0 ? _response$data$list : response === null || response === void 0 ? void 0 : response.list) !== null && _ref26 !== void 0 ? _ref26 : [];
1593
- list = filterBookingsFromOrders(rawList, data);
1594
- this.logInfo('fetchBookingListFromAPI: API 返回并拆分完成', {
1595
- rawCount: rawList.length,
1596
- flattenedCount: list.count
1597
- });
1996
+ payload = (_response$data = response === null || response === void 0 ? void 0 : response.data) !== null && _response$data !== void 0 ? _response$data : response;
1997
+ list = Array.isArray(payload === null || payload === void 0 ? void 0 : payload.list) ? payload.list : [];
1998
+ count = typeof (payload === null || payload === void 0 ? void 0 : payload.count) === 'number' ? payload.count : list.length;
1598
1999
  return _context18.abrupt("return", {
1599
2000
  code: 200,
1600
- data: _objectSpread(_objectSpread({}, response.data), {}, {
1601
- list: (list === null || list === void 0 ? void 0 : list.list) || []
2001
+ data: _objectSpread(_objectSpread({}, payload), {}, {
2002
+ list: list,
2003
+ count: count
1602
2004
  }),
1603
2005
  message: '',
1604
2006
  status: true
@@ -1607,7 +2009,7 @@ var Server = /*#__PURE__*/function () {
1607
2009
  _context18.prev = 13;
1608
2010
  _context18.t0 = _context18["catch"](3);
1609
2011
  errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
1610
- this.logError('fetchBookingListFromAPI: 请求失败', {
2012
+ this.logError('fetchOrderListFromAPI: 请求失败', {
1611
2013
  error: errorMessage
1612
2014
  });
1613
2015
  return _context18.abrupt("return", {
@@ -1625,7 +2027,135 @@ var Server = /*#__PURE__*/function () {
1625
2027
  }
1626
2028
  }, _callee18, this, [[3, 13]]);
1627
2029
  }));
1628
- function fetchBookingListFromAPI(_x21) {
2030
+ function fetchOrderListFromAPI(_x21) {
2031
+ return _fetchOrderListFromAPI.apply(this, arguments);
2032
+ }
2033
+ return fetchOrderListFromAPI;
2034
+ }()
2035
+ /**
2036
+ * 非今天的预约查询:通过 SSE 流式拉取订单,再做本地 booking 筛选展开
2037
+ */
2038
+ )
2039
+ }, {
2040
+ key: "fetchBookingListFromAPI",
2041
+ value: (function () {
2042
+ var _fetchBookingListFromAPI = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(data) {
2043
+ var memoryCacheEnabled, withFields, requestPayload, cacheKey, cached, rawList, bookingResult, _bookingResult$list, errorMessage;
2044
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2045
+ while (1) switch (_context19.prev = _context19.next) {
2046
+ case 0:
2047
+ if (this.order) {
2048
+ _context19.next = 3;
2049
+ break;
2050
+ }
2051
+ this.logError('fetchBookingListFromAPI: Order 模块不可用');
2052
+ return _context19.abrupt("return", {
2053
+ code: 500,
2054
+ message: 'Order 模块不可用',
2055
+ data: {
2056
+ list: [],
2057
+ count: 0
2058
+ },
2059
+ status: false
2060
+ });
2061
+ case 3:
2062
+ _context19.prev = 3;
2063
+ memoryCacheEnabled = this.isBookingRemoteMemoryCacheEnabled(data);
2064
+ withFields = this.resolveBookingSalesWith(data);
2065
+ requestPayload = this.normalizeBookingRemoteQueryPayload(data, withFields);
2066
+ cacheKey = this.buildBookingRemoteCacheKey(requestPayload);
2067
+ if (!memoryCacheEnabled) {
2068
+ _context19.next = 13;
2069
+ break;
2070
+ }
2071
+ cached = this.readBookingRemoteCache(cacheKey);
2072
+ if (!cached) {
2073
+ _context19.next = 13;
2074
+ break;
2075
+ }
2076
+ this.logInfo('fetchBookingListFromAPI: 命中内存缓存', {
2077
+ cacheKey: cacheKey,
2078
+ listCount: cached.bookingResult.count,
2079
+ withFields: cached.withFields
2080
+ });
2081
+ return _context19.abrupt("return", this.buildBookingResponse(cached.bookingResult, {
2082
+ cache_hit: true
2083
+ }));
2084
+ case 13:
2085
+ _context19.next = 15;
2086
+ return this.order.fetchOrdersBySSE(requestPayload);
2087
+ case 15:
2088
+ rawList = _context19.sent;
2089
+ bookingResult = sortBookings(filterBookingsFromOrders(rawList, data), data); // DEBUG: 挂到 window 上方便排查 SSE → 日历数据丢失问题
2090
+ if (typeof globalThis !== 'undefined') {
2091
+ globalThis.__SSE_BOOKING_DEBUG__ = {
2092
+ ts: new Date().toISOString(),
2093
+ sseRequestPayload: requestPayload,
2094
+ calendarFilters: data,
2095
+ rawOrderCount: rawList.length,
2096
+ rawOrderSample: rawList.slice(0, 2).map(function (o) {
2097
+ var _o$bookings, _o$bookings2, _o$bookings$0$resourc;
2098
+ return {
2099
+ order_id: o === null || o === void 0 ? void 0 : o.order_id,
2100
+ business_code: o === null || o === void 0 ? void 0 : o.business_code,
2101
+ status: o === null || o === void 0 ? void 0 : o.status,
2102
+ payment_status: o === null || o === void 0 ? void 0 : o.payment_status,
2103
+ bookingsCount: o === null || o === void 0 || (_o$bookings = o.bookings) === null || _o$bookings === void 0 ? void 0 : _o$bookings.length,
2104
+ firstBooking: o !== null && o !== void 0 && (_o$bookings2 = o.bookings) !== null && _o$bookings2 !== void 0 && _o$bookings2[0] ? {
2105
+ start_date: o.bookings[0].start_date,
2106
+ start_time: o.bookings[0].start_time,
2107
+ parent_id: o.bookings[0].parent_id,
2108
+ item_type: o.bookings[0].item_type,
2109
+ resourcesCount: (_o$bookings$0$resourc = o.bookings[0].resources) === null || _o$bookings$0$resourc === void 0 ? void 0 : _o$bookings$0$resourc.length
2110
+ } : null
2111
+ };
2112
+ }),
2113
+ filteredBookingCount: bookingResult.count,
2114
+ filteredListLength: (_bookingResult$list = bookingResult.list) === null || _bookingResult$list === void 0 ? void 0 : _bookingResult$list.length
2115
+ };
2116
+ }
2117
+ if (memoryCacheEnabled) {
2118
+ this.writeBookingRemoteCache({
2119
+ key: cacheKey,
2120
+ queryPayload: data,
2121
+ withFields: withFields,
2122
+ rawOrders: Array.isArray(rawList) ? rawList : [],
2123
+ bookingResult: bookingResult,
2124
+ updatedAt: Date.now(),
2125
+ stale: false,
2126
+ rangeMeta: this.parseBookingSalesRangeMeta(requestPayload)
2127
+ });
2128
+ }
2129
+ this.logInfo('fetchBookingListFromAPI: SSE 返回并拆分完成', {
2130
+ rawCount: rawList.length,
2131
+ flattenedCount: bookingResult.count,
2132
+ cacheKey: cacheKey,
2133
+ withFields: withFields
2134
+ });
2135
+ return _context19.abrupt("return", this.buildBookingResponse(bookingResult));
2136
+ case 23:
2137
+ _context19.prev = 23;
2138
+ _context19.t0 = _context19["catch"](3);
2139
+ errorMessage = _context19.t0 instanceof Error ? _context19.t0.message : String(_context19.t0);
2140
+ this.logError('fetchBookingListFromAPI: SSE 请求失败', {
2141
+ error: errorMessage
2142
+ });
2143
+ return _context19.abrupt("return", {
2144
+ code: 500,
2145
+ message: errorMessage,
2146
+ data: {
2147
+ list: [],
2148
+ count: 0
2149
+ },
2150
+ status: false
2151
+ });
2152
+ case 28:
2153
+ case "end":
2154
+ return _context19.stop();
2155
+ }
2156
+ }, _callee19, this, [[3, 23]]);
2157
+ }));
2158
+ function fetchBookingListFromAPI(_x22) {
1629
2159
  return _fetchBookingListFromAPI.apply(this, arguments);
1630
2160
  }
1631
2161
  return fetchBookingListFromAPI;
@@ -1740,24 +2270,24 @@ var Server = /*#__PURE__*/function () {
1740
2270
  }, {
1741
2271
  key: "recomputeAndNotifyFloorPlanQuery",
1742
2272
  value: (function () {
1743
- var _recomputeAndNotifyFloorPlanQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1744
- var _iterator5, _step5, _step5$value, subscriberId, sub, result, errorMessage;
1745
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1746
- while (1) switch (_context19.prev = _context19.next) {
2273
+ var _recomputeAndNotifyFloorPlanQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2274
+ var _iterator11, _step11, _step11$value, subscriberId, sub, result, errorMessage;
2275
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2276
+ while (1) switch (_context20.prev = _context20.next) {
1747
2277
  case 0:
1748
2278
  if (!(this.floorPlanQuerySubscribers.size === 0)) {
1749
- _context19.next = 2;
2279
+ _context20.next = 2;
1750
2280
  break;
1751
2281
  }
1752
- return _context19.abrupt("return");
2282
+ return _context20.abrupt("return");
1753
2283
  case 2:
1754
2284
  this.logInfo('recomputeAndNotifyFloorPlanQuery: 开始推送', {
1755
2285
  subscriberCount: this.floorPlanQuerySubscribers.size
1756
2286
  });
1757
- _iterator5 = _createForOfIteratorHelper(this.floorPlanQuerySubscribers.entries());
2287
+ _iterator11 = _createForOfIteratorHelper(this.floorPlanQuerySubscribers.entries());
1758
2288
  try {
1759
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1760
- _step5$value = _slicedToArray(_step5.value, 2), subscriberId = _step5$value[0], sub = _step5$value[1];
2289
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
2290
+ _step11$value = _slicedToArray(_step11.value, 2), subscriberId = _step11$value[0], sub = _step11$value[1];
1761
2291
  try {
1762
2292
  result = this.computeFloorPlanQueryResult(sub.context);
1763
2293
  sub.callback(result);
@@ -1773,15 +2303,15 @@ var Server = /*#__PURE__*/function () {
1773
2303
  }
1774
2304
  }
1775
2305
  } catch (err) {
1776
- _iterator5.e(err);
2306
+ _iterator11.e(err);
1777
2307
  } finally {
1778
- _iterator5.f();
2308
+ _iterator11.f();
1779
2309
  }
1780
2310
  case 5:
1781
2311
  case "end":
1782
- return _context19.stop();
2312
+ return _context20.stop();
1783
2313
  }
1784
- }, _callee19, this);
2314
+ }, _callee20, this);
1785
2315
  }));
1786
2316
  function recomputeAndNotifyFloorPlanQuery() {
1787
2317
  return _recomputeAndNotifyFloorPlanQuery.apply(this, arguments);
@@ -1811,21 +2341,21 @@ var Server = /*#__PURE__*/function () {
1811
2341
  * filter 逻辑暂为 mock,仅记录参数
1812
2342
  */
1813
2343
  function () {
1814
- var _computeOrderQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(data) {
2344
+ var _computeOrderQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(data) {
1815
2345
  var rawList, result;
1816
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1817
- while (1) switch (_context20.prev = _context20.next) {
2346
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2347
+ while (1) switch (_context21.prev = _context21.next) {
1818
2348
  case 0:
1819
2349
  this.logInfo('computeOrderQueryResult: 开始过滤', {
1820
2350
  data: data
1821
2351
  });
1822
2352
  console.log('[Server] computeOrderQueryResult', data);
1823
2353
  if (this.order) {
1824
- _context20.next = 5;
2354
+ _context21.next = 5;
1825
2355
  break;
1826
2356
  }
1827
2357
  this.logError('computeOrderQueryResult: Order 模块未注册');
1828
- return _context20.abrupt("return", {
2358
+ return _context21.abrupt("return", {
1829
2359
  code: 500,
1830
2360
  message: 'Order 模块未注册',
1831
2361
  data: {
@@ -1848,7 +2378,7 @@ var Server = /*#__PURE__*/function () {
1848
2378
  size: result.size,
1849
2379
  skip: result.skip
1850
2380
  });
1851
- return _context20.abrupt("return", {
2381
+ return _context21.abrupt("return", {
1852
2382
  code: 200,
1853
2383
  data: result,
1854
2384
  message: '',
@@ -1856,11 +2386,11 @@ var Server = /*#__PURE__*/function () {
1856
2386
  });
1857
2387
  case 10:
1858
2388
  case "end":
1859
- return _context20.stop();
2389
+ return _context21.stop();
1860
2390
  }
1861
- }, _callee20, this);
2391
+ }, _callee21, this);
1862
2392
  }));
1863
- function computeOrderQueryResult(_x22) {
2393
+ function computeOrderQueryResult(_x23) {
1864
2394
  return _computeOrderQueryResult.apply(this, arguments);
1865
2395
  }
1866
2396
  return computeOrderQueryResult;
@@ -1873,17 +2403,17 @@ var Server = /*#__PURE__*/function () {
1873
2403
  }, {
1874
2404
  key: "computeBookingQueryResult",
1875
2405
  value: (function () {
1876
- var _computeBookingQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(data) {
2406
+ var _computeBookingQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(data) {
1877
2407
  var rawOrders, result;
1878
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1879
- while (1) switch (_context21.prev = _context21.next) {
2408
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2409
+ while (1) switch (_context22.prev = _context22.next) {
1880
2410
  case 0:
1881
2411
  if (this.order) {
1882
- _context21.next = 3;
2412
+ _context22.next = 3;
1883
2413
  break;
1884
2414
  }
1885
2415
  this.logError('computeBookingQueryResult: Order 模块未注册');
1886
- return _context21.abrupt("return", {
2416
+ return _context22.abrupt("return", {
1887
2417
  code: 500,
1888
2418
  message: 'Order 模块未注册',
1889
2419
  data: {
@@ -1902,7 +2432,7 @@ var Server = /*#__PURE__*/function () {
1902
2432
  size: result.size,
1903
2433
  skip: result.skip
1904
2434
  });
1905
- return _context21.abrupt("return", {
2435
+ return _context22.abrupt("return", {
1906
2436
  code: 200,
1907
2437
  data: result,
1908
2438
  message: '',
@@ -1910,11 +2440,11 @@ var Server = /*#__PURE__*/function () {
1910
2440
  });
1911
2441
  case 8:
1912
2442
  case "end":
1913
- return _context21.stop();
2443
+ return _context22.stop();
1914
2444
  }
1915
- }, _callee21, this);
2445
+ }, _callee22, this);
1916
2446
  }));
1917
- function computeBookingQueryResult(_x23) {
2447
+ function computeBookingQueryResult(_x24) {
1918
2448
  return _computeBookingQueryResult.apply(this, arguments);
1919
2449
  }
1920
2450
  return computeBookingQueryResult;
@@ -1930,12 +2460,12 @@ var Server = /*#__PURE__*/function () {
1930
2460
  }, {
1931
2461
  key: "computeProductQueryResult",
1932
2462
  value: (function () {
1933
- var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(context, options) {
2463
+ var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(context, options) {
1934
2464
  var _menu_list_ids$length3,
1935
- _this5 = this;
2465
+ _this6 = this;
1936
2466
  var tTotal, menu_list_ids, schedule_date, schedule_datetime, activeMenuList, tMenu, menuList, tPrice, allProductsWithPrice, tFilter, filteredProducts, tStatus, beforeStatusCount, tSort;
1937
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1938
- while (1) switch (_context22.prev = _context22.next) {
2467
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2468
+ while (1) switch (_context23.prev = _context23.next) {
1939
2469
  case 0:
1940
2470
  tTotal = performance.now();
1941
2471
  menu_list_ids = context.menu_list_ids, schedule_date = context.schedule_date, schedule_datetime = context.schedule_datetime;
@@ -1946,11 +2476,11 @@ var Server = /*#__PURE__*/function () {
1946
2476
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
1947
2477
  });
1948
2478
  if (this.products) {
1949
- _context22.next = 6;
2479
+ _context23.next = 6;
1950
2480
  break;
1951
2481
  }
1952
2482
  this.logError('computeProductQueryResult: Products 模块未注册');
1953
- return _context22.abrupt("return", {
2483
+ return _context23.abrupt("return", {
1954
2484
  message: 'Products 模块未注册',
1955
2485
  data: {
1956
2486
  list: [],
@@ -1959,11 +2489,11 @@ var Server = /*#__PURE__*/function () {
1959
2489
  });
1960
2490
  case 6:
1961
2491
  if (this.menu) {
1962
- _context22.next = 9;
2492
+ _context23.next = 9;
1963
2493
  break;
1964
2494
  }
1965
2495
  this.logError('computeProductQueryResult: Menu 模块未注册');
1966
- return _context22.abrupt("return", {
2496
+ return _context23.abrupt("return", {
1967
2497
  message: 'Menu 模块未注册',
1968
2498
  data: {
1969
2499
  list: [],
@@ -1972,11 +2502,11 @@ var Server = /*#__PURE__*/function () {
1972
2502
  });
1973
2503
  case 9:
1974
2504
  if (this.schedule) {
1975
- _context22.next = 12;
2505
+ _context23.next = 12;
1976
2506
  break;
1977
2507
  }
1978
2508
  this.logError('computeProductQueryResult: Schedule 模块未注册');
1979
- return _context22.abrupt("return", {
2509
+ return _context23.abrupt("return", {
1980
2510
  message: 'Schedule 模块未注册',
1981
2511
  data: {
1982
2512
  list: [],
@@ -1989,8 +2519,8 @@ var Server = /*#__PURE__*/function () {
1989
2519
  tMenu = performance.now();
1990
2520
  menuList = this.menu.getMenuByIds(menu_list_ids);
1991
2521
  activeMenuList = menuList.filter(function (menu) {
1992
- var _this5$schedule;
1993
- return ((_this5$schedule = _this5.schedule) === null || _this5$schedule === void 0 ? void 0 : _this5$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
2522
+ var _this6$schedule;
2523
+ return ((_this6$schedule = _this6.schedule) === null || _this6$schedule === void 0 ? void 0 : _this6$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
1994
2524
  });
1995
2525
  perfMark('computeQuery.filterActiveMenu', performance.now() - tMenu, {
1996
2526
  totalMenu: menuList.length,
@@ -1998,14 +2528,14 @@ var Server = /*#__PURE__*/function () {
1998
2528
  });
1999
2529
  }
2000
2530
  tPrice = performance.now();
2001
- _context22.next = 17;
2531
+ _context23.next = 17;
2002
2532
  return this.products.getProductsWithPrice(schedule_date, {
2003
2533
  scheduleModule: this.getSchedule()
2004
2534
  }, {
2005
2535
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
2006
2536
  });
2007
2537
  case 17:
2008
- allProductsWithPrice = _context22.sent;
2538
+ allProductsWithPrice = _context23.sent;
2009
2539
  perfMark('computeQuery.getProductsWithPrice', performance.now() - tPrice, {
2010
2540
  count: allProductsWithPrice.length
2011
2541
  });
@@ -2043,7 +2573,7 @@ var Server = /*#__PURE__*/function () {
2043
2573
  filteredCount: filteredProducts.length,
2044
2574
  activeMenuCount: activeMenuList.length
2045
2575
  });
2046
- return _context22.abrupt("return", {
2576
+ return _context23.abrupt("return", {
2047
2577
  code: 200,
2048
2578
  data: {
2049
2579
  list: filteredProducts,
@@ -2054,11 +2584,11 @@ var Server = /*#__PURE__*/function () {
2054
2584
  });
2055
2585
  case 32:
2056
2586
  case "end":
2057
- return _context22.stop();
2587
+ return _context23.stop();
2058
2588
  }
2059
- }, _callee22, this);
2589
+ }, _callee23, this);
2060
2590
  }));
2061
- function computeProductQueryResult(_x24, _x25) {
2591
+ function computeProductQueryResult(_x25, _x26) {
2062
2592
  return _computeProductQueryResult.apply(this, arguments);
2063
2593
  }
2064
2594
  return computeProductQueryResult;
@@ -2073,72 +2603,72 @@ var Server = /*#__PURE__*/function () {
2073
2603
  }, {
2074
2604
  key: "recomputeAndNotifyProductQuery",
2075
2605
  value: (function () {
2076
- var _recomputeAndNotifyProductQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(options) {
2077
- var _iterator6, _step6, _step6$value, subscriberId, subscriber, result, errorMessage;
2078
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2079
- while (1) switch (_context23.prev = _context23.next) {
2606
+ var _recomputeAndNotifyProductQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(options) {
2607
+ var _iterator12, _step12, _step12$value, subscriberId, subscriber, result, errorMessage;
2608
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2609
+ while (1) switch (_context24.prev = _context24.next) {
2080
2610
  case 0:
2081
2611
  if (!(this.productQuerySubscribers.size === 0)) {
2082
- _context23.next = 2;
2612
+ _context24.next = 2;
2083
2613
  break;
2084
2614
  }
2085
- return _context23.abrupt("return");
2615
+ return _context24.abrupt("return");
2086
2616
  case 2:
2087
2617
  this.logInfo('recomputeAndNotifyProductQuery: 开始推送', {
2088
2618
  subscriberCount: this.productQuerySubscribers.size,
2089
2619
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
2090
2620
  });
2091
- _iterator6 = _createForOfIteratorHelper(this.productQuerySubscribers.entries());
2092
- _context23.prev = 4;
2093
- _iterator6.s();
2621
+ _iterator12 = _createForOfIteratorHelper(this.productQuerySubscribers.entries());
2622
+ _context24.prev = 4;
2623
+ _iterator12.s();
2094
2624
  case 6:
2095
- if ((_step6 = _iterator6.n()).done) {
2096
- _context23.next = 22;
2625
+ if ((_step12 = _iterator12.n()).done) {
2626
+ _context24.next = 22;
2097
2627
  break;
2098
2628
  }
2099
- _step6$value = _slicedToArray(_step6.value, 2), subscriberId = _step6$value[0], subscriber = _step6$value[1];
2100
- _context23.prev = 8;
2101
- _context23.next = 11;
2629
+ _step12$value = _slicedToArray(_step12.value, 2), subscriberId = _step12$value[0], subscriber = _step12$value[1];
2630
+ _context24.prev = 8;
2631
+ _context24.next = 11;
2102
2632
  return this.computeProductQueryResult(subscriber.context, {
2103
2633
  changedIds: options === null || options === void 0 ? void 0 : options.changedIds
2104
2634
  });
2105
2635
  case 11:
2106
- result = _context23.sent;
2636
+ result = _context24.sent;
2107
2637
  subscriber.callback(result);
2108
2638
  this.logInfo('recomputeAndNotifyProductQuery: 已推送', {
2109
2639
  subscriberId: subscriberId
2110
2640
  });
2111
- _context23.next = 20;
2641
+ _context24.next = 20;
2112
2642
  break;
2113
2643
  case 16:
2114
- _context23.prev = 16;
2115
- _context23.t0 = _context23["catch"](8);
2116
- errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
2644
+ _context24.prev = 16;
2645
+ _context24.t0 = _context24["catch"](8);
2646
+ errorMessage = _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0);
2117
2647
  this.logError('recomputeAndNotifyProductQuery: 推送失败', {
2118
2648
  subscriberId: subscriberId,
2119
2649
  error: errorMessage
2120
2650
  });
2121
2651
  case 20:
2122
- _context23.next = 6;
2652
+ _context24.next = 6;
2123
2653
  break;
2124
2654
  case 22:
2125
- _context23.next = 27;
2655
+ _context24.next = 27;
2126
2656
  break;
2127
2657
  case 24:
2128
- _context23.prev = 24;
2129
- _context23.t1 = _context23["catch"](4);
2130
- _iterator6.e(_context23.t1);
2658
+ _context24.prev = 24;
2659
+ _context24.t1 = _context24["catch"](4);
2660
+ _iterator12.e(_context24.t1);
2131
2661
  case 27:
2132
- _context23.prev = 27;
2133
- _iterator6.f();
2134
- return _context23.finish(27);
2662
+ _context24.prev = 27;
2663
+ _iterator12.f();
2664
+ return _context24.finish(27);
2135
2665
  case 30:
2136
2666
  case "end":
2137
- return _context23.stop();
2667
+ return _context24.stop();
2138
2668
  }
2139
- }, _callee23, this, [[4, 24, 27, 30], [8, 16]]);
2669
+ }, _callee24, this, [[4, 24, 27, 30], [8, 16]]);
2140
2670
  }));
2141
- function recomputeAndNotifyProductQuery(_x26) {
2671
+ function recomputeAndNotifyProductQuery(_x27) {
2142
2672
  return _recomputeAndNotifyProductQuery.apply(this, arguments);
2143
2673
  }
2144
2674
  return recomputeAndNotifyProductQuery;
@@ -2150,67 +2680,82 @@ var Server = /*#__PURE__*/function () {
2150
2680
  }, {
2151
2681
  key: "recomputeAndNotifyOrderQuery",
2152
2682
  value: (function () {
2153
- var _recomputeAndNotifyOrderQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2154
- var _iterator7, _step7, _step7$value, subscriberId, subscriber, result, errorMessage;
2155
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2156
- while (1) switch (_context24.prev = _context24.next) {
2683
+ var _recomputeAndNotifyOrderQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2684
+ var notifyStartAt, _iterator13, _step13, _step13$value, subscriberId, subscriber, computeStartAt, result, computeEndAt, callbackStartAt, callbackEndAt, errorMessage, notifyEndAt;
2685
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2686
+ while (1) switch (_context25.prev = _context25.next) {
2157
2687
  case 0:
2158
2688
  if (!(this.orderQuerySubscribers.size === 0)) {
2159
- _context24.next = 2;
2689
+ _context25.next = 2;
2160
2690
  break;
2161
2691
  }
2162
- return _context24.abrupt("return");
2692
+ return _context25.abrupt("return");
2163
2693
  case 2:
2694
+ notifyStartAt = Date.now();
2164
2695
  this.logInfo('recomputeAndNotifyOrderQuery: 开始推送', {
2165
- subscriberCount: this.orderQuerySubscribers.size
2696
+ subscriberCount: this.orderQuerySubscribers.size,
2697
+ notifyStartAt: new Date(notifyStartAt).toISOString()
2166
2698
  });
2167
- _iterator7 = _createForOfIteratorHelper(this.orderQuerySubscribers.entries());
2168
- _context24.prev = 4;
2169
- _iterator7.s();
2170
- case 6:
2171
- if ((_step7 = _iterator7.n()).done) {
2172
- _context24.next = 22;
2699
+ _iterator13 = _createForOfIteratorHelper(this.orderQuerySubscribers.entries());
2700
+ _context25.prev = 5;
2701
+ _iterator13.s();
2702
+ case 7:
2703
+ if ((_step13 = _iterator13.n()).done) {
2704
+ _context25.next = 27;
2173
2705
  break;
2174
2706
  }
2175
- _step7$value = _slicedToArray(_step7.value, 2), subscriberId = _step7$value[0], subscriber = _step7$value[1];
2176
- _context24.prev = 8;
2177
- _context24.next = 11;
2707
+ _step13$value = _slicedToArray(_step13.value, 2), subscriberId = _step13$value[0], subscriber = _step13$value[1];
2708
+ _context25.prev = 9;
2709
+ computeStartAt = Date.now();
2710
+ _context25.next = 13;
2178
2711
  return this.computeOrderQueryResult(subscriber.context);
2179
- case 11:
2180
- result = _context24.sent;
2712
+ case 13:
2713
+ result = _context25.sent;
2714
+ computeEndAt = Date.now();
2715
+ callbackStartAt = Date.now();
2181
2716
  subscriber.callback(result);
2717
+ callbackEndAt = Date.now();
2182
2718
  this.logInfo('recomputeAndNotifyOrderQuery: 已推送', {
2183
- subscriberId: subscriberId
2719
+ subscriberId: subscriberId,
2720
+ computeDurationMs: computeEndAt - computeStartAt,
2721
+ callbackDurationMs: callbackEndAt - callbackStartAt,
2722
+ totalDurationMs: callbackEndAt - computeStartAt
2184
2723
  });
2185
- _context24.next = 20;
2724
+ _context25.next = 25;
2186
2725
  break;
2187
- case 16:
2188
- _context24.prev = 16;
2189
- _context24.t0 = _context24["catch"](8);
2190
- errorMessage = _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0);
2726
+ case 21:
2727
+ _context25.prev = 21;
2728
+ _context25.t0 = _context25["catch"](9);
2729
+ errorMessage = _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0);
2191
2730
  this.logError('recomputeAndNotifyOrderQuery: 推送失败', {
2192
2731
  subscriberId: subscriberId,
2193
2732
  error: errorMessage
2194
2733
  });
2195
- case 20:
2196
- _context24.next = 6;
2197
- break;
2198
- case 22:
2199
- _context24.next = 27;
2734
+ case 25:
2735
+ _context25.next = 7;
2200
2736
  break;
2201
- case 24:
2202
- _context24.prev = 24;
2203
- _context24.t1 = _context24["catch"](4);
2204
- _iterator7.e(_context24.t1);
2205
2737
  case 27:
2206
- _context24.prev = 27;
2207
- _iterator7.f();
2208
- return _context24.finish(27);
2209
- case 30:
2738
+ _context25.next = 32;
2739
+ break;
2740
+ case 29:
2741
+ _context25.prev = 29;
2742
+ _context25.t1 = _context25["catch"](5);
2743
+ _iterator13.e(_context25.t1);
2744
+ case 32:
2745
+ _context25.prev = 32;
2746
+ _iterator13.f();
2747
+ return _context25.finish(32);
2748
+ case 35:
2749
+ notifyEndAt = Date.now();
2750
+ this.logInfo('recomputeAndNotifyOrderQuery: 推送完成', {
2751
+ subscriberCount: this.orderQuerySubscribers.size,
2752
+ totalNotifyDurationMs: notifyEndAt - notifyStartAt
2753
+ });
2754
+ case 37:
2210
2755
  case "end":
2211
- return _context24.stop();
2756
+ return _context25.stop();
2212
2757
  }
2213
- }, _callee24, this, [[4, 24, 27, 30], [8, 16]]);
2758
+ }, _callee25, this, [[5, 29, 32, 35], [9, 21]]);
2214
2759
  }));
2215
2760
  function recomputeAndNotifyOrderQuery() {
2216
2761
  return _recomputeAndNotifyOrderQuery.apply(this, arguments);
@@ -2224,67 +2769,67 @@ var Server = /*#__PURE__*/function () {
2224
2769
  }, {
2225
2770
  key: "recomputeAndNotifyBookingQuery",
2226
2771
  value: (function () {
2227
- var _recomputeAndNotifyBookingQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2228
- var _iterator8, _step8, _step8$value, subscriberId, subscriber, result, errorMessage;
2229
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2230
- while (1) switch (_context25.prev = _context25.next) {
2772
+ var _recomputeAndNotifyBookingQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2773
+ var _iterator14, _step14, _step14$value, subscriberId, subscriber, result, errorMessage;
2774
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2775
+ while (1) switch (_context26.prev = _context26.next) {
2231
2776
  case 0:
2232
2777
  if (!(this.bookingQuerySubscribers.size === 0)) {
2233
- _context25.next = 2;
2778
+ _context26.next = 2;
2234
2779
  break;
2235
2780
  }
2236
- return _context25.abrupt("return");
2781
+ return _context26.abrupt("return");
2237
2782
  case 2:
2238
2783
  this.logInfo('recomputeAndNotifyBookingQuery: 开始推送', {
2239
2784
  subscriberCount: this.bookingQuerySubscribers.size
2240
2785
  });
2241
- _iterator8 = _createForOfIteratorHelper(this.bookingQuerySubscribers.entries());
2242
- _context25.prev = 4;
2243
- _iterator8.s();
2786
+ _iterator14 = _createForOfIteratorHelper(this.bookingQuerySubscribers.entries());
2787
+ _context26.prev = 4;
2788
+ _iterator14.s();
2244
2789
  case 6:
2245
- if ((_step8 = _iterator8.n()).done) {
2246
- _context25.next = 22;
2790
+ if ((_step14 = _iterator14.n()).done) {
2791
+ _context26.next = 22;
2247
2792
  break;
2248
2793
  }
2249
- _step8$value = _slicedToArray(_step8.value, 2), subscriberId = _step8$value[0], subscriber = _step8$value[1];
2250
- _context25.prev = 8;
2251
- _context25.next = 11;
2794
+ _step14$value = _slicedToArray(_step14.value, 2), subscriberId = _step14$value[0], subscriber = _step14$value[1];
2795
+ _context26.prev = 8;
2796
+ _context26.next = 11;
2252
2797
  return this.computeBookingQueryResult(subscriber.context);
2253
2798
  case 11:
2254
- result = _context25.sent;
2799
+ result = _context26.sent;
2255
2800
  subscriber.callback(result);
2256
2801
  this.logInfo('recomputeAndNotifyBookingQuery: 已推送', {
2257
2802
  subscriberId: subscriberId
2258
2803
  });
2259
- _context25.next = 20;
2804
+ _context26.next = 20;
2260
2805
  break;
2261
2806
  case 16:
2262
- _context25.prev = 16;
2263
- _context25.t0 = _context25["catch"](8);
2264
- errorMessage = _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0);
2807
+ _context26.prev = 16;
2808
+ _context26.t0 = _context26["catch"](8);
2809
+ errorMessage = _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0);
2265
2810
  this.logError('recomputeAndNotifyBookingQuery: 推送失败', {
2266
2811
  subscriberId: subscriberId,
2267
2812
  error: errorMessage
2268
2813
  });
2269
2814
  case 20:
2270
- _context25.next = 6;
2815
+ _context26.next = 6;
2271
2816
  break;
2272
2817
  case 22:
2273
- _context25.next = 27;
2818
+ _context26.next = 27;
2274
2819
  break;
2275
2820
  case 24:
2276
- _context25.prev = 24;
2277
- _context25.t1 = _context25["catch"](4);
2278
- _iterator8.e(_context25.t1);
2821
+ _context26.prev = 24;
2822
+ _context26.t1 = _context26["catch"](4);
2823
+ _iterator14.e(_context26.t1);
2279
2824
  case 27:
2280
- _context25.prev = 27;
2281
- _iterator8.f();
2282
- return _context25.finish(27);
2825
+ _context26.prev = 27;
2826
+ _iterator14.f();
2827
+ return _context26.finish(27);
2283
2828
  case 30:
2284
2829
  case "end":
2285
- return _context25.stop();
2830
+ return _context26.stop();
2286
2831
  }
2287
- }, _callee25, this, [[4, 24, 27, 30], [8, 16]]);
2832
+ }, _callee26, this, [[4, 24, 27, 30], [8, 16]]);
2288
2833
  }));
2289
2834
  function recomputeAndNotifyBookingQuery() {
2290
2835
  return _recomputeAndNotifyBookingQuery.apply(this, arguments);
@@ -2316,11 +2861,11 @@ var Server = /*#__PURE__*/function () {
2316
2861
  var allowedProductIds = new Set();
2317
2862
  var allowedCollectionIds = new Set();
2318
2863
  var hasProductAll = false;
2319
- var _iterator9 = _createForOfIteratorHelper(activeMenuList),
2320
- _step9;
2864
+ var _iterator15 = _createForOfIteratorHelper(activeMenuList),
2865
+ _step15;
2321
2866
  try {
2322
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
2323
- var menu = _step9.value;
2867
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2868
+ var menu = _step15.value;
2324
2869
  var config = menu.partyroom_package;
2325
2870
  if (!config) {
2326
2871
  console.warn('[Server] 餐牌缺少 partyroom_package 配置:', menu);
@@ -2380,9 +2925,9 @@ var Server = /*#__PURE__*/function () {
2380
2925
 
2381
2926
  // 如果有餐牌允许所有商品,返回所有商品
2382
2927
  } catch (err) {
2383
- _iterator9.e(err);
2928
+ _iterator15.e(err);
2384
2929
  } finally {
2385
- _iterator9.f();
2930
+ _iterator15.f();
2386
2931
  }
2387
2932
  if (hasProductAll) {
2388
2933
  this.logInfo('filterProductsByMenuConfig: 返回所有商品(product_all)', {