@pisell/pisellos 2.2.82 → 2.2.83

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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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
+ 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; } }
4
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1
5
  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; } } }; }
2
6
  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); }
3
7
  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; }
@@ -18,8 +22,12 @@ import { MenuModule } from "./modules/menu";
18
22
  import { QuotationModule } from "./modules/quotation";
19
23
  import { ScheduleModuleEx } from "./modules/schedule";
20
24
  import { extractScheduleIdsFromMenus, extractTimePointsFromSchedules } from "./utils/schedule";
25
+ import { ProductsHooks } from "./modules/products/types";
26
+ import { perfMark } from "./utils/product";
21
27
 
22
28
  // 重新导出类型供外部使用
29
+
30
+ /** 商品查询订阅者 */
23
31
  /**
24
32
  * Server 类
25
33
  * 用于注册和管理服务端模块
@@ -46,6 +54,8 @@ var Server = /*#__PURE__*/function () {
46
54
  put: {},
47
55
  remove: {}
48
56
  });
57
+ // ---- 商品查询订阅者 ----
58
+ _defineProperty(this, "productQuerySubscribers", new Map());
49
59
  // 模块注册表 - 定义所有可用的模块配置
50
60
  _defineProperty(this, "moduleRegistry", {
51
61
  products: {
@@ -89,159 +99,46 @@ var Server = /*#__PURE__*/function () {
89
99
  }
90
100
  });
91
101
  /**
92
- * 处理商品查询请求(编排 Products、Menu、Schedule 模块)
93
- * 这是一个业务编排方法,协调多个模块完成复杂的业务需求
102
+ * 处理商品查询请求
103
+ * 存储订阅者信息,便于数据变更时推送最新结果
94
104
  */
95
105
  _defineProperty(this, "handleProductQuery", /*#__PURE__*/function () {
96
106
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
97
- var _menu_list_ids$length;
98
- var url, method, data, config, menu_list_ids, schedule_datetime, schedule_date, activeMenuList, menuList, _menu_list_ids$length2, allProductsWithPrice, filteredProducts;
107
+ var url, method, data, config, menu_list_ids, schedule_datetime, schedule_date, _ref3, callback, subscriberId;
99
108
  return _regeneratorRuntime().wrap(function _callee$(_context) {
100
109
  while (1) switch (_context.prev = _context.next) {
101
110
  case 0:
102
111
  url = _ref.url, method = _ref.method, data = _ref.data, config = _ref.config;
103
112
  console.log('[Server] handleProductQuery:', url, method, data, config);
104
113
  menu_list_ids = data.menu_list_ids, schedule_datetime = data.schedule_datetime, schedule_date = data.schedule_date;
105
- _this.logInfo('handleProductQuery 开始处理', {
106
- menuListIdsCount: (_menu_list_ids$length = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length !== void 0 ? _menu_list_ids$length : 0,
114
+ _ref3 = config || {}, callback = _ref3.callback, subscriberId = _ref3.subscriberId;
115
+ _this.logInfo('handleProductQuery: 开始处理商品查询请求', {
116
+ menu_list_ids: menu_list_ids,
107
117
  schedule_datetime: schedule_datetime,
108
- schedule_date: schedule_date,
109
- menu_list_ids: menu_list_ids
110
- });
111
-
112
- // 检查必要的模块是否已注册
113
- if (_this.products) {
114
- _context.next = 8;
115
- break;
116
- }
117
- console.error('[Server] Products 模块未注册');
118
- _this.logError('handleProductQuery: Products 模块未注册');
119
- return _context.abrupt("return", {
120
- message: 'Products 模块未注册',
121
- data: {
122
- list: [],
123
- count: 0
124
- }
125
- });
126
- case 8:
127
- if (_this.menu) {
128
- _context.next = 12;
129
- break;
130
- }
131
- console.error('[Server] Menu 模块未注册');
132
- _this.logError('handleProductQuery: Menu 模块未注册');
133
- return _context.abrupt("return", {
134
- message: 'Menu 模块未注册',
135
- data: {
136
- list: [],
137
- count: 0
138
- }
139
- });
140
- case 12:
141
- if (_this.schedule) {
142
- _context.next = 16;
143
- break;
144
- }
145
- console.error('[Server] Schedule 模块未注册');
146
- _this.logError('handleProductQuery: Schedule 模块未注册');
147
- return _context.abrupt("return", {
148
- message: 'Schedule 模块未注册',
149
- data: {
150
- list: [],
151
- count: 0
152
- }
118
+ schedule_date: schedule_date
153
119
  });
154
- case 16:
155
- // 生效的餐牌列表
156
- activeMenuList = []; // 如果有 menu_list_ids,获取对应的餐牌详情
157
- if (menu_list_ids && Array.isArray(menu_list_ids) && menu_list_ids.length > 0) {
158
- console.log('[Server] 获取餐牌详情,IDs:', menu_list_ids);
159
- _this.logInfo('handleProductQuery: 获取餐牌详情', {
160
- menuListIdsCount: menu_list_ids.length,
161
- menu_list_ids: menu_list_ids
162
- });
163
120
 
164
- // Menu 模块获取餐牌详情
165
- menuList = _this.menu.getMenuByIds(menu_list_ids);
166
- _this.logInfo('handleProductQuery: 获取到餐牌列表', {
167
- requestedCount: menu_list_ids.length,
168
- foundCount: menuList.length,
169
- menu_list_ids: menu_list_ids,
170
- menuList: menuList
171
- });
172
- activeMenuList = menuList.filter(function (menu) {
173
- var _this$schedule;
174
- var isInSchedule = ((_this$schedule = _this.schedule) === null || _this$schedule === void 0 ? void 0 : _this$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
175
- return isInSchedule;
176
- });
177
- _this.logInfo('handleProductQuery: 过滤生效餐牌', {
178
- totalMenuCount: menuList.length,
179
- activeMenuCount: activeMenuList.length,
180
- schedule_datetime: schedule_datetime,
181
- menuList: menuList,
182
- activeMenuList: activeMenuList
121
+ // 存储订阅者:后续 pubsub 数据变更时可通过 callback 推送最新结果
122
+ if (subscriberId && typeof callback === 'function') {
123
+ _this.productQuerySubscribers.set(subscriberId, {
124
+ callback: callback,
125
+ context: {
126
+ menu_list_ids: menu_list_ids,
127
+ schedule_date: schedule_date,
128
+ schedule_datetime: schedule_datetime
129
+ }
183
130
  });
184
- } else {
185
- _this.logWarning('handleProductQuery: 未提供有效的 menu_list_ids', {
186
- menuListIdsCount: (_menu_list_ids$length2 = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length2 !== void 0 ? _menu_list_ids$length2 : 0,
187
- menu_list_ids: menu_list_ids
131
+ _this.logInfo('handleProductQuery: 已注册订阅者', {
132
+ subscriberId: subscriberId,
133
+ totalSubscribers: _this.productQuerySubscribers.size
188
134
  });
189
135
  }
190
- console.log(activeMenuList, 'activeMenuList');
191
-
192
- // 获取应用了价格的商品列表(带缓存,同一天直接返回缓存的商品)
193
- // 传入 scheduleList 以便格式化器计算商品的可用时间段
194
- _this.logInfo('handleProductQuery: 开始获取商品列表', {
195
- schedule_date: schedule_date
196
- });
197
- _context.next = 22;
198
- return _this.products.getProductsWithPrice(data.schedule_date, {
199
- scheduleModule: _this.getSchedule()
200
- });
201
- case 22:
202
- allProductsWithPrice = _context.sent;
203
- _this.logInfo('handleProductQuery: 获取到商品列表', {
204
- productCount: allProductsWithPrice.length,
205
- schedule_date: schedule_date
206
- });
207
- console.log(allProductsWithPrice, 'allProductsWithPrice');
208
-
209
- //根据生效的餐牌配置过滤商品
210
- _this.logInfo('handleProductQuery: 开始按餐牌配置过滤商品', {
211
- totalProducts: allProductsWithPrice.length,
212
- activeMenuCount: activeMenuList.length
213
- });
214
- filteredProducts = _this.filterProductsByMenuConfig(allProductsWithPrice, activeMenuList); // 排序:优先使用 sort 排序,如果相同则使用 title 排序
215
- filteredProducts = filteredProducts.sort(function (a, b) {
216
- var sortDiff = Number(b.sort) - Number(a.sort);
217
- if (sortDiff !== 0) {
218
- return sortDiff;
219
- }
220
- // 如果 sort 相同,按 title 字母顺序排序
221
- return (a.title || '').localeCompare(b.title || '');
222
- });
223
- console.log('[Server] 原始商品数量:', allProductsWithPrice.length);
224
- console.log('[Server] 过滤后商品数量:', filteredProducts.length);
225
- console.log(filteredProducts, 'filteredProducts');
226
- _this.logInfo('handleProductQuery 处理完成', {
227
- originalProductCount: allProductsWithPrice.length,
228
- filteredProductCount: filteredProducts.length,
229
- activeMenuCount: activeMenuList.length,
136
+ return _context.abrupt("return", _this.computeProductQueryResult({
137
+ menu_list_ids: menu_list_ids,
230
138
  schedule_date: schedule_date,
231
139
  schedule_datetime: schedule_datetime
232
- });
233
-
234
- // 返回组合后的数据
235
- return _context.abrupt("return", {
236
- code: 200,
237
- data: {
238
- list: filteredProducts,
239
- count: filteredProducts.length
240
- },
241
- message: '',
242
- status: true
243
- });
244
- case 33:
140
+ }));
141
+ case 7:
245
142
  case "end":
246
143
  return _context.stop();
247
144
  }
@@ -251,33 +148,60 @@ var Server = /*#__PURE__*/function () {
251
148
  return _ref2.apply(this, arguments);
252
149
  };
253
150
  }());
151
+ /**
152
+ * 取消商品查询订阅(HTTP 路由入口)
153
+ */
154
+ _defineProperty(this, "handleUnsubscribeProductQuery", /*#__PURE__*/function () {
155
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref4) {
156
+ var data, _ref6, subscriberId;
157
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
158
+ while (1) switch (_context2.prev = _context2.next) {
159
+ case 0:
160
+ data = _ref4.data;
161
+ _ref6 = data || {}, subscriberId = _ref6.subscriberId;
162
+ _this.removeProductQuerySubscriber(subscriberId);
163
+ return _context2.abrupt("return", {
164
+ code: 200,
165
+ message: 'ok',
166
+ status: true
167
+ });
168
+ case 4:
169
+ case "end":
170
+ return _context2.stop();
171
+ }
172
+ }, _callee2);
173
+ }));
174
+ return function (_x2) {
175
+ return _ref5.apply(this, arguments);
176
+ };
177
+ }());
254
178
  /**
255
179
  * 处理获取日程时间段点的请求
256
180
  * 通过餐牌ID列表获取所有相关日程的时间段点
257
181
  */
258
182
  _defineProperty(this, "handleGetScheduleTimePoints", /*#__PURE__*/function () {
259
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref3) {
260
- var _menu_list_ids$length3;
261
- var url, method, data, config, menu_list_ids, _menu_list_ids$length4, menuList, scheduleIds, scheduleList, timePoints, errorMessage;
262
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
263
- while (1) switch (_context2.prev = _context2.next) {
183
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref7) {
184
+ var _menu_list_ids$length;
185
+ var url, method, data, config, menu_list_ids, _menu_list_ids$length2, menuList, scheduleIds, scheduleList, timePoints, errorMessage;
186
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
187
+ while (1) switch (_context3.prev = _context3.next) {
264
188
  case 0:
265
- url = _ref3.url, method = _ref3.method, data = _ref3.data, config = _ref3.config;
189
+ url = _ref7.url, method = _ref7.method, data = _ref7.data, config = _ref7.config;
266
190
  console.log('[Server] handleGetScheduleTimePoints:', url, method, data, config);
267
191
  menu_list_ids = data.menu_list_ids;
268
192
  _this.logInfo('handleGetScheduleTimePoints 开始处理', {
269
- menuListIdsCount: (_menu_list_ids$length3 = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length3 !== void 0 ? _menu_list_ids$length3 : 0,
193
+ menuListIdsCount: (_menu_list_ids$length = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length !== void 0 ? _menu_list_ids$length : 0,
270
194
  menu_list_ids: menu_list_ids
271
195
  });
272
196
 
273
197
  // 检查必要的模块是否已注册
274
198
  if (_this.menu) {
275
- _context2.next = 8;
199
+ _context3.next = 8;
276
200
  break;
277
201
  }
278
202
  console.error('[Server] Menu 模块未注册');
279
203
  _this.logError('handleGetScheduleTimePoints: Menu 模块未注册');
280
- return _context2.abrupt("return", {
204
+ return _context3.abrupt("return", {
281
205
  code: 500,
282
206
  message: 'Menu 模块未注册',
283
207
  data: [],
@@ -285,12 +209,12 @@ var Server = /*#__PURE__*/function () {
285
209
  });
286
210
  case 8:
287
211
  if (_this.schedule) {
288
- _context2.next = 12;
212
+ _context3.next = 12;
289
213
  break;
290
214
  }
291
215
  console.error('[Server] Schedule 模块未注册');
292
216
  _this.logError('handleGetScheduleTimePoints: Schedule 模块未注册');
293
- return _context2.abrupt("return", {
217
+ return _context3.abrupt("return", {
294
218
  code: 500,
295
219
  message: 'Schedule 模块未注册',
296
220
  data: [],
@@ -298,22 +222,22 @@ var Server = /*#__PURE__*/function () {
298
222
  });
299
223
  case 12:
300
224
  if (!(!menu_list_ids || !Array.isArray(menu_list_ids) || menu_list_ids.length === 0)) {
301
- _context2.next = 16;
225
+ _context3.next = 16;
302
226
  break;
303
227
  }
304
228
  console.error('[Server] menu_list_ids 参数无效');
305
229
  _this.logWarning('handleGetScheduleTimePoints: menu_list_ids 参数无效', {
306
- menuListIdsCount: (_menu_list_ids$length4 = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length4 !== void 0 ? _menu_list_ids$length4 : 0,
230
+ menuListIdsCount: (_menu_list_ids$length2 = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length2 !== void 0 ? _menu_list_ids$length2 : 0,
307
231
  menu_list_ids: menu_list_ids
308
232
  });
309
- return _context2.abrupt("return", {
233
+ return _context3.abrupt("return", {
310
234
  code: 400,
311
235
  message: 'menu_list_ids 参数无效',
312
236
  data: [],
313
237
  status: false
314
238
  });
315
239
  case 16:
316
- _context2.prev = 16;
240
+ _context3.prev = 16;
317
241
  // 1. 获取餐牌列表
318
242
  menuList = _this.menu.getMenuByIds(menu_list_ids);
319
243
  console.log("[Server] \u627E\u5230 ".concat(menuList.length, " \u4E2A\u9910\u724C"));
@@ -331,13 +255,13 @@ var Server = /*#__PURE__*/function () {
331
255
  scheduleCount: scheduleIds.length
332
256
  });
333
257
  if (!(scheduleIds.length === 0)) {
334
- _context2.next = 26;
258
+ _context3.next = 26;
335
259
  break;
336
260
  }
337
261
  _this.logInfo('handleGetScheduleTimePoints: 没有找到相关日程', {
338
262
  menuListIdsCount: menu_list_ids.length
339
263
  });
340
- return _context2.abrupt("return", {
264
+ return _context3.abrupt("return", {
341
265
  code: 200,
342
266
  message: '没有找到相关日程',
343
267
  data: [],
@@ -361,22 +285,22 @@ var Server = /*#__PURE__*/function () {
361
285
  scheduleCount: scheduleList.length,
362
286
  timePointCount: timePoints.length
363
287
  });
364
- return _context2.abrupt("return", {
288
+ return _context3.abrupt("return", {
365
289
  code: 200,
366
290
  message: '获取成功',
367
291
  data: timePoints,
368
292
  status: true
369
293
  });
370
294
  case 35:
371
- _context2.prev = 35;
372
- _context2.t0 = _context2["catch"](16);
373
- errorMessage = _context2.t0 instanceof Error ? _context2.t0.message : '未知错误';
374
- console.error('[Server] 获取日程时间点失败:', _context2.t0);
295
+ _context3.prev = 35;
296
+ _context3.t0 = _context3["catch"](16);
297
+ errorMessage = _context3.t0 instanceof Error ? _context3.t0.message : '未知错误';
298
+ console.error('[Server] 获取日程时间点失败:', _context3.t0);
375
299
  _this.logError('handleGetScheduleTimePoints: 获取日程时间点失败', {
376
300
  menuListIdsCount: menu_list_ids.length,
377
301
  error: errorMessage
378
302
  });
379
- return _context2.abrupt("return", {
303
+ return _context3.abrupt("return", {
380
304
  code: 500,
381
305
  message: "\u83B7\u53D6\u5931\u8D25: ".concat(errorMessage),
382
306
  data: [],
@@ -384,19 +308,19 @@ var Server = /*#__PURE__*/function () {
384
308
  });
385
309
  case 41:
386
310
  case "end":
387
- return _context2.stop();
311
+ return _context3.stop();
388
312
  }
389
- }, _callee2, null, [[16, 35]]);
313
+ }, _callee3, null, [[16, 35]]);
390
314
  }));
391
- return function (_x2) {
392
- return _ref4.apply(this, arguments);
315
+ return function (_x3) {
316
+ return _ref8.apply(this, arguments);
393
317
  };
394
318
  }());
395
319
  this.core = core;
396
320
  var appPlugin = core.getPlugin('app');
397
321
  this.app = (appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp()) || null;
398
322
  this.logger = ((_this$app = this.app) === null || _this$app === void 0 ? void 0 : _this$app.logger) || null;
399
- console.log('[Server] Server 初始化');
323
+ console.log('[Server] Server 初始化', this.core);
400
324
  this.logInfo('Server 初始化', {
401
325
  hasApp: !!this.app,
402
326
  hasLogger: !!this.logger
@@ -450,10 +374,10 @@ var Server = /*#__PURE__*/function () {
450
374
  }, {
451
375
  key: "registerModuleWithRoutes",
452
376
  value: (function () {
453
- var _registerModuleWithRoutes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(module, options, moduleName) {
377
+ var _registerModuleWithRoutes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(module, options, moduleName) {
454
378
  var routes;
455
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
456
- while (1) switch (_context3.prev = _context3.next) {
379
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
380
+ while (1) switch (_context4.prev = _context4.next) {
457
381
  case 0:
458
382
  this.logInfo("\u5F00\u59CB\u6CE8\u518C\u6A21\u5757: ".concat(moduleName), {
459
383
  moduleName: moduleName,
@@ -461,7 +385,7 @@ var Server = /*#__PURE__*/function () {
461
385
  });
462
386
 
463
387
  // 注册模块到 Core
464
- _context3.next = 3;
388
+ _context4.next = 3;
465
389
  return this.core.registerModule(module, options);
466
390
  case 3:
467
391
  console.log("[Server] \u2705 ".concat(moduleName, " \u6A21\u5757\u5DF2\u6CE8\u518C"));
@@ -482,11 +406,11 @@ var Server = /*#__PURE__*/function () {
482
406
  }
483
407
  case 6:
484
408
  case "end":
485
- return _context3.stop();
409
+ return _context4.stop();
486
410
  }
487
- }, _callee3, this);
411
+ }, _callee4, this);
488
412
  }));
489
- function registerModuleWithRoutes(_x3, _x4, _x5) {
413
+ function registerModuleWithRoutes(_x4, _x5, _x6) {
490
414
  return _registerModuleWithRoutes.apply(this, arguments);
491
415
  }
492
416
  return registerModuleWithRoutes;
@@ -499,10 +423,10 @@ var Server = /*#__PURE__*/function () {
499
423
  }, {
500
424
  key: "registerModuleByName",
501
425
  value: (function () {
502
- var _registerModuleByName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(moduleConfig) {
426
+ var _registerModuleByName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(moduleConfig) {
503
427
  var moduleName, shouldPreload, customConfig, registryConfig, ModuleClass, moduleInstance, moduleOptions;
504
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
505
- while (1) switch (_context4.prev = _context4.next) {
428
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
429
+ while (1) switch (_context5.prev = _context5.next) {
506
430
  case 0:
507
431
  // 解析配置
508
432
  moduleName = typeof moduleConfig === 'string' ? moduleConfig : moduleConfig.name;
@@ -517,7 +441,7 @@ var Server = /*#__PURE__*/function () {
517
441
  // 查找模块配置
518
442
  registryConfig = this.moduleRegistry[moduleName];
519
443
  if (registryConfig) {
520
- _context4.next = 8;
444
+ _context5.next = 8;
521
445
  break;
522
446
  }
523
447
  this.logError("\u672A\u627E\u5230\u6A21\u5757\u914D\u7F6E: ".concat(moduleName), {
@@ -531,7 +455,7 @@ var Server = /*#__PURE__*/function () {
531
455
  moduleOptions = _objectSpread({
532
456
  store: _objectSpread({}, registryConfig.defaultStore)
533
457
  }, customConfig); // 注册模块和路由
534
- _context4.next = 13;
458
+ _context5.next = 13;
535
459
  return this.registerModuleWithRoutes(moduleInstance, moduleOptions, moduleName.charAt(0).toUpperCase() + moduleName.slice(1));
536
460
  case 13:
537
461
  // 保存模块实例
@@ -541,18 +465,18 @@ var Server = /*#__PURE__*/function () {
541
465
  shouldPreload: shouldPreload,
542
466
  version: registryConfig.version
543
467
  });
544
- return _context4.abrupt("return", {
468
+ return _context5.abrupt("return", {
545
469
  module: moduleInstance,
546
470
  config: registryConfig,
547
471
  shouldPreload: shouldPreload
548
472
  });
549
473
  case 16:
550
474
  case "end":
551
- return _context4.stop();
475
+ return _context5.stop();
552
476
  }
553
- }, _callee4, this);
477
+ }, _callee5, this);
554
478
  }));
555
- function registerModuleByName(_x6) {
479
+ function registerModuleByName(_x7) {
556
480
  return _registerModuleByName.apply(this, arguments);
557
481
  }
558
482
  return registerModuleByName;
@@ -565,10 +489,10 @@ var Server = /*#__PURE__*/function () {
565
489
  }, {
566
490
  key: "registerModules",
567
491
  value: (function () {
568
- var _registerModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(moduleConfigs) {
492
+ var _registerModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(moduleConfigs) {
569
493
  var configs, registeredModules, _iterator, _step, config, configName, result, errorMessage;
570
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
571
- while (1) switch (_context5.prev = _context5.next) {
494
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
495
+ while (1) switch (_context6.prev = _context6.next) {
572
496
  case 0:
573
497
  console.log('[Server] 开始注册模块...');
574
498
 
@@ -580,47 +504,47 @@ var Server = /*#__PURE__*/function () {
580
504
  });
581
505
  registeredModules = [];
582
506
  _iterator = _createForOfIteratorHelper(configs);
583
- _context5.prev = 5;
507
+ _context6.prev = 5;
584
508
  _iterator.s();
585
509
  case 7:
586
510
  if ((_step = _iterator.n()).done) {
587
- _context5.next = 25;
511
+ _context6.next = 25;
588
512
  break;
589
513
  }
590
514
  config = _step.value;
591
515
  configName = typeof config === 'string' ? config : config.name;
592
- _context5.prev = 10;
593
- _context5.next = 13;
516
+ _context6.prev = 10;
517
+ _context6.next = 13;
594
518
  return this.registerModuleByName(config);
595
519
  case 13:
596
- result = _context5.sent;
520
+ result = _context6.sent;
597
521
  registeredModules.push(result);
598
- _context5.next = 23;
522
+ _context6.next = 23;
599
523
  break;
600
524
  case 17:
601
- _context5.prev = 17;
602
- _context5.t0 = _context5["catch"](10);
603
- errorMessage = _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0);
525
+ _context6.prev = 17;
526
+ _context6.t0 = _context6["catch"](10);
527
+ errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
604
528
  this.logError("\u6A21\u5757\u6CE8\u518C\u5931\u8D25: ".concat(configName), {
605
529
  moduleName: configName,
606
530
  error: errorMessage
607
531
  });
608
- console.error("[Server] \u6A21\u5757\u6CE8\u518C\u5931\u8D25:", _context5.t0);
609
- throw _context5.t0;
532
+ console.error("[Server] \u6A21\u5757\u6CE8\u518C\u5931\u8D25:", _context6.t0);
533
+ throw _context6.t0;
610
534
  case 23:
611
- _context5.next = 7;
535
+ _context6.next = 7;
612
536
  break;
613
537
  case 25:
614
- _context5.next = 30;
538
+ _context6.next = 30;
615
539
  break;
616
540
  case 27:
617
- _context5.prev = 27;
618
- _context5.t1 = _context5["catch"](5);
619
- _iterator.e(_context5.t1);
541
+ _context6.prev = 27;
542
+ _context6.t1 = _context6["catch"](5);
543
+ _iterator.e(_context6.t1);
620
544
  case 30:
621
- _context5.prev = 30;
545
+ _context6.prev = 30;
622
546
  _iterator.f();
623
- return _context5.finish(30);
547
+ return _context6.finish(30);
624
548
  case 33:
625
549
  console.log('[Server] ✅ 所有模块注册完成');
626
550
  this.logInfo('所有模块注册完成', {
@@ -630,14 +554,14 @@ var Server = /*#__PURE__*/function () {
630
554
  return m === null || m === void 0 || (_m$config = m.config) === null || _m$config === void 0 ? void 0 : _m$config.name;
631
555
  })
632
556
  });
633
- return _context5.abrupt("return", registeredModules);
557
+ return _context6.abrupt("return", registeredModules);
634
558
  case 36:
635
559
  case "end":
636
- return _context5.stop();
560
+ return _context6.stop();
637
561
  }
638
- }, _callee5, this, [[5, 27, 30, 33], [10, 17]]);
562
+ }, _callee6, this, [[5, 27, 30, 33], [10, 17]]);
639
563
  }));
640
- function registerModules(_x7) {
564
+ function registerModules(_x8) {
641
565
  return _registerModules.apply(this, arguments);
642
566
  }
643
567
  return registerModules;
@@ -650,10 +574,10 @@ var Server = /*#__PURE__*/function () {
650
574
  }, {
651
575
  key: "preloadModulesData",
652
576
  value: (function () {
653
- var _preloadModulesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(registeredModules, options) {
577
+ var _preloadModulesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(registeredModules, options) {
654
578
  var modulesToPreload, preloadResults, _iterator2, _step2, _step2$value, module, config, shouldPreload, startTime, _options$onModuleLoad, _options$onModuleLoad2, duration, _duration, errorMessage, successCount, failCount;
655
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
656
- while (1) switch (_context6.prev = _context6.next) {
579
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
580
+ while (1) switch (_context7.prev = _context7.next) {
657
581
  case 0:
658
582
  console.log('[Server] 开始预加载模块数据...');
659
583
  modulesToPreload = registeredModules.filter(function (m) {
@@ -666,16 +590,16 @@ var Server = /*#__PURE__*/function () {
666
590
  });
667
591
  preloadResults = [];
668
592
  _iterator2 = _createForOfIteratorHelper(registeredModules);
669
- _context6.prev = 5;
593
+ _context7.prev = 5;
670
594
  _iterator2.s();
671
595
  case 7:
672
596
  if ((_step2 = _iterator2.n()).done) {
673
- _context6.next = 40;
597
+ _context7.next = 40;
674
598
  break;
675
599
  }
676
600
  _step2$value = _step2.value, module = _step2$value.module, config = _step2$value.config, shouldPreload = _step2$value.shouldPreload;
677
601
  if (shouldPreload) {
678
- _context6.next = 13;
602
+ _context7.next = 13;
679
603
  break;
680
604
  }
681
605
  console.log("[Server] \u23ED\uFE0F \u8DF3\u8FC7 ".concat(config.name, " \u6A21\u5757\u9884\u52A0\u8F7D"));
@@ -683,19 +607,19 @@ var Server = /*#__PURE__*/function () {
683
607
  moduleName: config.name,
684
608
  reason: 'shouldPreload=false'
685
609
  });
686
- return _context6.abrupt("continue", 38);
610
+ return _context7.abrupt("continue", 38);
687
611
  case 13:
688
612
  if (!(typeof module.preload === 'function')) {
689
- _context6.next = 36;
613
+ _context7.next = 36;
690
614
  break;
691
615
  }
692
616
  startTime = Date.now();
693
- _context6.prev = 15;
617
+ _context7.prev = 15;
694
618
  this.logInfo("\u5F00\u59CB\u9884\u52A0\u8F7D\u6A21\u5757: ".concat(config.name), {
695
619
  moduleName: config.name
696
620
  });
697
621
  options === null || options === void 0 || (_options$onModuleLoad = options.onModuleLoad) === null || _options$onModuleLoad === void 0 || _options$onModuleLoad.call(options, config.name);
698
- _context6.next = 20;
622
+ _context7.next = 20;
699
623
  return module.preload();
700
624
  case 20:
701
625
  options === null || options === void 0 || (_options$onModuleLoad2 = options.onModuleLoadComplete) === null || _options$onModuleLoad2 === void 0 || _options$onModuleLoad2.call(options, config.name);
@@ -709,14 +633,14 @@ var Server = /*#__PURE__*/function () {
709
633
  name: config.name,
710
634
  success: true
711
635
  });
712
- _context6.next = 34;
636
+ _context7.next = 34;
713
637
  break;
714
638
  case 27:
715
- _context6.prev = 27;
716
- _context6.t0 = _context6["catch"](15);
639
+ _context7.prev = 27;
640
+ _context7.t0 = _context7["catch"](15);
717
641
  _duration = Date.now() - startTime;
718
- errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
719
- console.error("[Server] \u274C ".concat(config.name, " \u6A21\u5757\u9884\u52A0\u8F7D\u5931\u8D25:"), _context6.t0);
642
+ errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
643
+ console.error("[Server] \u274C ".concat(config.name, " \u6A21\u5757\u9884\u52A0\u8F7D\u5931\u8D25:"), _context7.t0);
720
644
  this.logError("\u6A21\u5757\u9884\u52A0\u8F7D\u5931\u8D25: ".concat(config.name), {
721
645
  moduleName: config.name,
722
646
  duration: "".concat(_duration, "ms"),
@@ -728,7 +652,7 @@ var Server = /*#__PURE__*/function () {
728
652
  error: errorMessage
729
653
  });
730
654
  case 34:
731
- _context6.next = 38;
655
+ _context7.next = 38;
732
656
  break;
733
657
  case 36:
734
658
  console.log("[Server] \u26A0\uFE0F ".concat(config.name, " \u6A21\u5757\u672A\u5B9E\u73B0 preload() \u65B9\u6CD5"));
@@ -736,19 +660,19 @@ var Server = /*#__PURE__*/function () {
736
660
  moduleName: config.name
737
661
  });
738
662
  case 38:
739
- _context6.next = 7;
663
+ _context7.next = 7;
740
664
  break;
741
665
  case 40:
742
- _context6.next = 45;
666
+ _context7.next = 45;
743
667
  break;
744
668
  case 42:
745
- _context6.prev = 42;
746
- _context6.t1 = _context6["catch"](5);
747
- _iterator2.e(_context6.t1);
669
+ _context7.prev = 42;
670
+ _context7.t1 = _context7["catch"](5);
671
+ _iterator2.e(_context7.t1);
748
672
  case 45:
749
- _context6.prev = 45;
673
+ _context7.prev = 45;
750
674
  _iterator2.f();
751
- return _context6.finish(45);
675
+ return _context7.finish(45);
752
676
  case 48:
753
677
  successCount = preloadResults.filter(function (r) {
754
678
  return r.success;
@@ -763,11 +687,11 @@ var Server = /*#__PURE__*/function () {
763
687
  });
764
688
  case 52:
765
689
  case "end":
766
- return _context6.stop();
690
+ return _context7.stop();
767
691
  }
768
- }, _callee6, this, [[5, 42, 45, 48], [15, 27]]);
692
+ }, _callee7, this, [[5, 42, 45, 48], [15, 27]]);
769
693
  }));
770
- function preloadModulesData(_x8, _x9) {
694
+ function preloadModulesData(_x9, _x10) {
771
695
  return _preloadModulesData.apply(this, arguments);
772
696
  }
773
697
  return preloadModulesData;
@@ -781,19 +705,20 @@ var Server = /*#__PURE__*/function () {
781
705
  }, {
782
706
  key: "initialize",
783
707
  value: (function () {
784
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(moduleConfigs) {
785
- var _moduleConfigs$length;
708
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(moduleConfigs) {
709
+ var _moduleConfigs$length,
710
+ _this3 = this;
786
711
  var autoPreload,
787
712
  options,
788
713
  startTime,
789
714
  registeredModules,
790
715
  duration,
791
- _args7 = arguments;
792
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
793
- while (1) switch (_context7.prev = _context7.next) {
716
+ _args8 = arguments;
717
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
718
+ while (1) switch (_context8.prev = _context8.next) {
794
719
  case 0:
795
- autoPreload = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : true;
796
- options = _args7.length > 2 ? _args7[2] : undefined;
720
+ autoPreload = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : true;
721
+ options = _args8.length > 2 ? _args8[2] : undefined;
797
722
  startTime = Date.now();
798
723
  this.logInfo('Server 初始化开始', {
799
724
  moduleConfigCount: (_moduleConfigs$length = moduleConfigs === null || moduleConfigs === void 0 ? void 0 : moduleConfigs.length) !== null && _moduleConfigs$length !== void 0 ? _moduleConfigs$length : 'all',
@@ -805,37 +730,41 @@ var Server = /*#__PURE__*/function () {
805
730
  this.registerServerRoutes();
806
731
 
807
732
  // 注册模块
808
- _context7.next = 7;
733
+ _context8.next = 7;
809
734
  return this.registerModules(moduleConfigs);
810
735
  case 7:
811
- registeredModules = _context7.sent;
736
+ registeredModules = _context8.sent;
812
737
  if (!autoPreload) {
813
- _context7.next = 13;
738
+ _context8.next = 13;
814
739
  break;
815
740
  }
816
- _context7.next = 11;
741
+ _context8.next = 11;
817
742
  return this.preloadModulesData(registeredModules, options);
818
743
  case 11:
819
- _context7.next = 14;
744
+ _context8.next = 14;
820
745
  break;
821
746
  case 13:
822
747
  this.logInfo('跳过自动预加载', {
823
748
  autoPreload: autoPreload
824
749
  });
825
750
  case 14:
751
+ // 监听 ProductsModule 同步完成事件,重新计算并推送查询结果
752
+ this.core.effects.on(ProductsHooks.onProductsSyncCompleted, function () {
753
+ _this3.recomputeAndNotifyProductQuery();
754
+ });
826
755
  duration = Date.now() - startTime;
827
756
  this.logInfo('Server 初始化完成', {
828
757
  duration: "".concat(duration, "ms"),
829
758
  registeredModuleCount: registeredModules.length
830
759
  });
831
- return _context7.abrupt("return", registeredModules);
832
- case 17:
760
+ return _context8.abrupt("return", registeredModules);
761
+ case 18:
833
762
  case "end":
834
- return _context7.stop();
763
+ return _context8.stop();
835
764
  }
836
- }, _callee7, this);
765
+ }, _callee8, this);
837
766
  }));
838
- function initialize(_x10) {
767
+ function initialize(_x11) {
839
768
  return _initialize.apply(this, arguments);
840
769
  }
841
770
  return initialize;
@@ -891,17 +820,71 @@ var Server = /*#__PURE__*/function () {
891
820
  return modules;
892
821
  }
893
822
 
823
+ /**
824
+ * 后台静默刷新商品数据
825
+ * 重新拉取全量 SSE 接口,更新本地数据后触发 onProductsSyncCompleted
826
+ * 不影响当前界面展示,适用于切回前台、定时刷新等场景
827
+ */
828
+ }, {
829
+ key: "refreshProductsInBackground",
830
+ value: (function () {
831
+ var _refreshProductsInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
832
+ var startTime, duration, _duration2, errorMessage;
833
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
834
+ while (1) switch (_context9.prev = _context9.next) {
835
+ case 0:
836
+ if (this.products) {
837
+ _context9.next = 3;
838
+ break;
839
+ }
840
+ this.logWarning('refreshProductsInBackground: Products 模块未注册');
841
+ return _context9.abrupt("return");
842
+ case 3:
843
+ this.logInfo('refreshProductsInBackground 开始');
844
+ startTime = Date.now();
845
+ _context9.prev = 5;
846
+ _context9.next = 8;
847
+ return this.products.silentRefresh();
848
+ case 8:
849
+ duration = Date.now() - startTime;
850
+ this.logInfo('refreshProductsInBackground 完成', {
851
+ duration: "".concat(duration, "ms")
852
+ });
853
+ _context9.next = 18;
854
+ break;
855
+ case 12:
856
+ _context9.prev = 12;
857
+ _context9.t0 = _context9["catch"](5);
858
+ _duration2 = Date.now() - startTime;
859
+ errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
860
+ console.error('[Server] refreshProductsInBackground 失败:', _context9.t0);
861
+ this.logError('refreshProductsInBackground 失败', {
862
+ duration: "".concat(_duration2, "ms"),
863
+ error: errorMessage
864
+ });
865
+ case 18:
866
+ case "end":
867
+ return _context9.stop();
868
+ }
869
+ }, _callee9, this, [[5, 12]]);
870
+ }));
871
+ function refreshProductsInBackground() {
872
+ return _refreshProductsInBackground.apply(this, arguments);
873
+ }
874
+ return refreshProductsInBackground;
875
+ }()
894
876
  /**
895
877
  * 清空所有server模块的IndexedDB缓存
896
878
  * @returns Promise<void>
897
879
  */
880
+ )
898
881
  }, {
899
882
  key: "clearAllIndexDB",
900
883
  value: (function () {
901
- var _clearAllIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
884
+ var _clearAllIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
902
885
  var clearTasks, moduleNames, errorMessage;
903
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
904
- while (1) switch (_context8.prev = _context8.next) {
886
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
887
+ while (1) switch (_context10.prev = _context10.next) {
905
888
  case 0:
906
889
  console.log('[Server] 开始清空所有模块的IndexedDB缓存...');
907
890
  this.logInfo('开始清空所有模块的 IndexedDB 缓存');
@@ -924,41 +907,41 @@ var Server = /*#__PURE__*/function () {
924
907
  moduleNames.push('Schedule');
925
908
  }
926
909
  if (!(clearTasks.length === 0)) {
927
- _context8.next = 12;
910
+ _context10.next = 12;
928
911
  break;
929
912
  }
930
913
  console.warn('[Server] 没有找到已注册的模块,无需清空');
931
914
  this.logWarning('没有找到已注册的模块,无需清空 IndexedDB');
932
- return _context8.abrupt("return");
915
+ return _context10.abrupt("return");
933
916
  case 12:
934
917
  this.logInfo('准备清空模块缓存', {
935
918
  moduleNames: moduleNames
936
919
  });
937
- _context8.prev = 13;
938
- _context8.next = 16;
920
+ _context10.prev = 13;
921
+ _context10.next = 16;
939
922
  return Promise.all(clearTasks);
940
923
  case 16:
941
924
  console.log("[Server] \u2705 \u5DF2\u6210\u529F\u6E05\u7A7A\u6240\u6709\u6A21\u5757\u7684IndexedDB\u7F13\u5B58: ".concat(moduleNames.join(', ')));
942
925
  this.logInfo('成功清空所有模块的 IndexedDB 缓存', {
943
926
  moduleNames: moduleNames
944
927
  });
945
- _context8.next = 26;
928
+ _context10.next = 26;
946
929
  break;
947
930
  case 20:
948
- _context8.prev = 20;
949
- _context8.t0 = _context8["catch"](13);
950
- errorMessage = _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0);
951
- console.error('[Server] ❌ 清空IndexedDB缓存时发生错误:', _context8.t0);
931
+ _context10.prev = 20;
932
+ _context10.t0 = _context10["catch"](13);
933
+ errorMessage = _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0);
934
+ console.error('[Server] ❌ 清空IndexedDB缓存时发生错误:', _context10.t0);
952
935
  this.logError('清空 IndexedDB 缓存时发生错误', {
953
936
  moduleNames: moduleNames,
954
937
  error: errorMessage
955
938
  });
956
- throw _context8.t0;
939
+ throw _context10.t0;
957
940
  case 26:
958
941
  case "end":
959
- return _context8.stop();
942
+ return _context10.stop();
960
943
  }
961
- }, _callee8, this, [[13, 20]]);
944
+ }, _callee10, this, [[13, 20]]);
962
945
  }));
963
946
  function clearAllIndexDB() {
964
947
  return _clearAllIndexDB.apply(this, arguments);
@@ -1009,10 +992,10 @@ var Server = /*#__PURE__*/function () {
1009
992
  }, {
1010
993
  key: "handleRoute",
1011
994
  value: (function () {
1012
- var _handleRoute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(method, path, params) {
1013
- var startTime, handler, result, duration, _duration2, errorMessage;
1014
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1015
- while (1) switch (_context9.prev = _context9.next) {
995
+ var _handleRoute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(method, path, params) {
996
+ var startTime, handler, result, duration, _duration3, errorMessage;
997
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
998
+ while (1) switch (_context11.prev = _context11.next) {
1016
999
  case 0:
1017
1000
  startTime = Date.now();
1018
1001
  console.log(method, path, params, 'method, path, params');
@@ -1024,7 +1007,7 @@ var Server = /*#__PURE__*/function () {
1024
1007
  });
1025
1008
  handler = this.getRouteHandler(method, path);
1026
1009
  if (handler) {
1027
- _context9.next = 7;
1010
+ _context11.next = 7;
1028
1011
  break;
1029
1012
  }
1030
1013
  this.logError("\u8DEF\u7531\u672A\u627E\u5230: ".concat(method.toUpperCase(), " ").concat(path), {
@@ -1033,11 +1016,11 @@ var Server = /*#__PURE__*/function () {
1033
1016
  });
1034
1017
  throw new Error("Route not found: ".concat(method.toUpperCase(), " ").concat(path));
1035
1018
  case 7:
1036
- _context9.prev = 7;
1037
- _context9.next = 10;
1019
+ _context11.prev = 7;
1020
+ _context11.next = 10;
1038
1021
  return handler(params);
1039
1022
  case 10:
1040
- result = _context9.sent;
1023
+ result = _context11.sent;
1041
1024
  duration = Date.now() - startTime;
1042
1025
  this.logInfo("\u8DEF\u7531\u8BF7\u6C42\u5B8C\u6210: ".concat(method.toUpperCase(), " ").concat(path), {
1043
1026
  method: method.toUpperCase(),
@@ -1046,28 +1029,28 @@ var Server = /*#__PURE__*/function () {
1046
1029
  resultCode: result === null || result === void 0 ? void 0 : result.code,
1047
1030
  resultStatus: result === null || result === void 0 ? void 0 : result.status
1048
1031
  });
1049
- return _context9.abrupt("return", result);
1032
+ return _context11.abrupt("return", result);
1050
1033
  case 16:
1051
- _context9.prev = 16;
1052
- _context9.t0 = _context9["catch"](7);
1053
- _duration2 = Date.now() - startTime;
1054
- errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
1034
+ _context11.prev = 16;
1035
+ _context11.t0 = _context11["catch"](7);
1036
+ _duration3 = Date.now() - startTime;
1037
+ errorMessage = _context11.t0 instanceof Error ? _context11.t0.message : String(_context11.t0);
1055
1038
  this.logError("\u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), {
1056
1039
  method: method.toUpperCase(),
1057
1040
  path: path,
1058
- duration: "".concat(_duration2, "ms"),
1041
+ duration: "".concat(_duration3, "ms"),
1059
1042
  error: errorMessage,
1060
1043
  data: params.data
1061
1044
  });
1062
- console.error("[Server] \u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), _context9.t0);
1063
- throw _context9.t0;
1045
+ console.error("[Server] \u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), _context11.t0);
1046
+ throw _context11.t0;
1064
1047
  case 23:
1065
1048
  case "end":
1066
- return _context9.stop();
1049
+ return _context11.stop();
1067
1050
  }
1068
- }, _callee9, this, [[7, 16]]);
1051
+ }, _callee11, this, [[7, 16]]);
1069
1052
  }));
1070
- function handleRoute(_x11, _x12, _x13) {
1053
+ function handleRoute(_x12, _x13, _x14) {
1071
1054
  return _handleRoute.apply(this, arguments);
1072
1055
  }
1073
1056
  return handleRoute;
@@ -1079,10 +1062,10 @@ var Server = /*#__PURE__*/function () {
1079
1062
  }, {
1080
1063
  key: "getAllRoutes",
1081
1064
  value: function getAllRoutes() {
1082
- var _this3 = this;
1065
+ var _this4 = this;
1083
1066
  var routes = [];
1084
1067
  ['get', 'post', 'put', 'remove'].forEach(function (method) {
1085
- Object.keys(_this3.router[method]).forEach(function (path) {
1068
+ Object.keys(_this4.router[method]).forEach(function (path) {
1086
1069
  routes.push({
1087
1070
  method: method,
1088
1071
  path: path
@@ -1101,21 +1084,239 @@ var Server = /*#__PURE__*/function () {
1101
1084
  key: "registerServerRoutes",
1102
1085
  value: function registerServerRoutes() {
1103
1086
  console.log('[Server] 注册 Server 层业务路由...');
1104
-
1105
- // 注册商品查询路由(带餐牌和日程信息)
1106
1087
  this.registerRoutes([{
1107
1088
  method: 'post',
1108
1089
  path: '/shop/product/query',
1109
1090
  handler: this.handleProductQuery.bind(this)
1091
+ }, {
1092
+ method: 'post',
1093
+ path: '/shop/product/query/unsubscribe',
1094
+ handler: this.handleUnsubscribeProductQuery.bind(this)
1110
1095
  }, {
1111
1096
  method: 'post',
1112
1097
  path: '/shop/menu/schedule-time-points',
1113
1098
  handler: this.handleGetScheduleTimePoints.bind(this)
1114
1099
  }]);
1115
1100
  }
1101
+
1102
+ /**
1103
+ * 根据 subscriberId 移除商品查询订阅者
1104
+ */
1116
1105
  }, {
1117
- key: "filterProductsByMenuConfig",
1118
- value:
1106
+ key: "removeProductQuerySubscriber",
1107
+ value: function removeProductQuerySubscriber(subscriberId) {
1108
+ if (subscriberId) {
1109
+ this.productQuerySubscribers.delete(subscriberId);
1110
+ this.logInfo('removeProductQuerySubscriber: 已移除订阅者', {
1111
+ subscriberId: subscriberId,
1112
+ remaining: this.productQuerySubscribers.size
1113
+ });
1114
+ }
1115
+ }
1116
+ }, {
1117
+ key: "computeProductQueryResult",
1118
+ value: (
1119
+ /**
1120
+ * 商品查询的核心计算逻辑(编排 Products、Menu、Schedule 模块)
1121
+ * 供 handleProductQuery 首次返回及 pubsub 变更推送复用
1122
+ */
1123
+ function () {
1124
+ var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(context) {
1125
+ var _menu_list_ids$length3,
1126
+ _this5 = this;
1127
+ var tTotal, menu_list_ids, schedule_date, schedule_datetime, activeMenuList, tMenu, menuList, tPrice, allProductsWithPrice, tFilter, filteredProducts, tSort;
1128
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1129
+ while (1) switch (_context12.prev = _context12.next) {
1130
+ case 0:
1131
+ tTotal = performance.now();
1132
+ menu_list_ids = context.menu_list_ids, schedule_date = context.schedule_date, schedule_datetime = context.schedule_datetime;
1133
+ this.logInfo('computeProductQueryResult 开始', {
1134
+ menuListIdsCount: (_menu_list_ids$length3 = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length3 !== void 0 ? _menu_list_ids$length3 : 0,
1135
+ schedule_datetime: schedule_datetime,
1136
+ schedule_date: schedule_date
1137
+ });
1138
+ if (this.products) {
1139
+ _context12.next = 6;
1140
+ break;
1141
+ }
1142
+ this.logError('computeProductQueryResult: Products 模块未注册');
1143
+ return _context12.abrupt("return", {
1144
+ message: 'Products 模块未注册',
1145
+ data: {
1146
+ list: [],
1147
+ count: 0
1148
+ }
1149
+ });
1150
+ case 6:
1151
+ if (this.menu) {
1152
+ _context12.next = 9;
1153
+ break;
1154
+ }
1155
+ this.logError('computeProductQueryResult: Menu 模块未注册');
1156
+ return _context12.abrupt("return", {
1157
+ message: 'Menu 模块未注册',
1158
+ data: {
1159
+ list: [],
1160
+ count: 0
1161
+ }
1162
+ });
1163
+ case 9:
1164
+ if (this.schedule) {
1165
+ _context12.next = 12;
1166
+ break;
1167
+ }
1168
+ this.logError('computeProductQueryResult: Schedule 模块未注册');
1169
+ return _context12.abrupt("return", {
1170
+ message: 'Schedule 模块未注册',
1171
+ data: {
1172
+ list: [],
1173
+ count: 0
1174
+ }
1175
+ });
1176
+ case 12:
1177
+ activeMenuList = [];
1178
+ if (menu_list_ids && Array.isArray(menu_list_ids) && menu_list_ids.length > 0) {
1179
+ tMenu = performance.now();
1180
+ menuList = this.menu.getMenuByIds(menu_list_ids);
1181
+ activeMenuList = menuList.filter(function (menu) {
1182
+ var _this5$schedule;
1183
+ return ((_this5$schedule = _this5.schedule) === null || _this5$schedule === void 0 ? void 0 : _this5$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
1184
+ });
1185
+ perfMark('computeQuery.filterActiveMenu', performance.now() - tMenu, {
1186
+ totalMenu: menuList.length,
1187
+ activeMenu: activeMenuList.length
1188
+ });
1189
+ }
1190
+ tPrice = performance.now();
1191
+ _context12.next = 17;
1192
+ return this.products.getProductsWithPrice(schedule_date, {
1193
+ scheduleModule: this.getSchedule()
1194
+ });
1195
+ case 17:
1196
+ allProductsWithPrice = _context12.sent;
1197
+ perfMark('computeQuery.getProductsWithPrice', performance.now() - tPrice, {
1198
+ count: allProductsWithPrice.length
1199
+ });
1200
+ tFilter = performance.now();
1201
+ filteredProducts = this.filterProductsByMenuConfig(allProductsWithPrice, activeMenuList);
1202
+ perfMark('computeQuery.filterByMenu', performance.now() - tFilter, {
1203
+ before: allProductsWithPrice.length,
1204
+ after: filteredProducts.length
1205
+ });
1206
+ tSort = performance.now();
1207
+ filteredProducts = filteredProducts.sort(function (a, b) {
1208
+ var sortDiff = Number(b.sort) - Number(a.sort);
1209
+ if (sortDiff !== 0) return sortDiff;
1210
+ return (a.title || '').localeCompare(b.title || '');
1211
+ });
1212
+ perfMark('computeQuery.sort', performance.now() - tSort, {
1213
+ count: filteredProducts.length
1214
+ });
1215
+ perfMark('computeProductQueryResult', performance.now() - tTotal, {
1216
+ originalCount: allProductsWithPrice.length,
1217
+ filteredCount: filteredProducts.length,
1218
+ activeMenuCount: activeMenuList.length
1219
+ });
1220
+ this.logInfo('computeProductQueryResult 完成', {
1221
+ originalCount: allProductsWithPrice.length,
1222
+ filteredCount: filteredProducts.length,
1223
+ activeMenuCount: activeMenuList.length
1224
+ });
1225
+ return _context12.abrupt("return", {
1226
+ code: 200,
1227
+ data: {
1228
+ list: filteredProducts,
1229
+ count: filteredProducts.length
1230
+ },
1231
+ message: '',
1232
+ status: true
1233
+ });
1234
+ case 28:
1235
+ case "end":
1236
+ return _context12.stop();
1237
+ }
1238
+ }, _callee12, this);
1239
+ }));
1240
+ function computeProductQueryResult(_x15) {
1241
+ return _computeProductQueryResult.apply(this, arguments);
1242
+ }
1243
+ return computeProductQueryResult;
1244
+ }()
1245
+ /**
1246
+ * 数据变更后,遍历所有订阅者重新计算查询结果并通过 callback 推送
1247
+ * 由 ProductsModule 的 onProductsSyncCompleted 事件触发
1248
+ */
1249
+ )
1250
+ }, {
1251
+ key: "recomputeAndNotifyProductQuery",
1252
+ value: (function () {
1253
+ var _recomputeAndNotifyProductQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1254
+ var _iterator3, _step3, _step3$value, subscriberId, subscriber, result, errorMessage;
1255
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1256
+ while (1) switch (_context13.prev = _context13.next) {
1257
+ case 0:
1258
+ if (!(this.productQuerySubscribers.size === 0)) {
1259
+ _context13.next = 2;
1260
+ break;
1261
+ }
1262
+ return _context13.abrupt("return");
1263
+ case 2:
1264
+ this.logInfo('recomputeAndNotifyProductQuery: 开始推送', {
1265
+ subscriberCount: this.productQuerySubscribers.size
1266
+ });
1267
+ _iterator3 = _createForOfIteratorHelper(this.productQuerySubscribers.entries());
1268
+ _context13.prev = 4;
1269
+ _iterator3.s();
1270
+ case 6:
1271
+ if ((_step3 = _iterator3.n()).done) {
1272
+ _context13.next = 22;
1273
+ break;
1274
+ }
1275
+ _step3$value = _slicedToArray(_step3.value, 2), subscriberId = _step3$value[0], subscriber = _step3$value[1];
1276
+ _context13.prev = 8;
1277
+ _context13.next = 11;
1278
+ return this.computeProductQueryResult(subscriber.context);
1279
+ case 11:
1280
+ result = _context13.sent;
1281
+ subscriber.callback(result);
1282
+ this.logInfo('recomputeAndNotifyProductQuery: 已推送', {
1283
+ subscriberId: subscriberId
1284
+ });
1285
+ _context13.next = 20;
1286
+ break;
1287
+ case 16:
1288
+ _context13.prev = 16;
1289
+ _context13.t0 = _context13["catch"](8);
1290
+ errorMessage = _context13.t0 instanceof Error ? _context13.t0.message : String(_context13.t0);
1291
+ this.logError('recomputeAndNotifyProductQuery: 推送失败', {
1292
+ subscriberId: subscriberId,
1293
+ error: errorMessage
1294
+ });
1295
+ case 20:
1296
+ _context13.next = 6;
1297
+ break;
1298
+ case 22:
1299
+ _context13.next = 27;
1300
+ break;
1301
+ case 24:
1302
+ _context13.prev = 24;
1303
+ _context13.t1 = _context13["catch"](4);
1304
+ _iterator3.e(_context13.t1);
1305
+ case 27:
1306
+ _context13.prev = 27;
1307
+ _iterator3.f();
1308
+ return _context13.finish(27);
1309
+ case 30:
1310
+ case "end":
1311
+ return _context13.stop();
1312
+ }
1313
+ }, _callee13, this, [[4, 24, 27, 30], [8, 16]]);
1314
+ }));
1315
+ function recomputeAndNotifyProductQuery() {
1316
+ return _recomputeAndNotifyProductQuery.apply(this, arguments);
1317
+ }
1318
+ return recomputeAndNotifyProductQuery;
1319
+ }()
1119
1320
  /**
1120
1321
  * 根据餐牌配置过滤商品
1121
1322
  * @param products 所有商品列表
@@ -1123,7 +1324,10 @@ var Server = /*#__PURE__*/function () {
1123
1324
  * @returns 过滤后的商品列表
1124
1325
  * @private
1125
1326
  */
1126
- function filterProductsByMenuConfig(products, activeMenuList) {
1327
+ )
1328
+ }, {
1329
+ key: "filterProductsByMenuConfig",
1330
+ value: function filterProductsByMenuConfig(products, activeMenuList) {
1127
1331
  // 如果没有生效的餐牌,返回空数组
1128
1332
  if (!activeMenuList || activeMenuList.length === 0) {
1129
1333
  console.log('[Server] 没有生效的餐牌,返回空数组');
@@ -1138,11 +1342,11 @@ var Server = /*#__PURE__*/function () {
1138
1342
  var allowedProductIds = new Set();
1139
1343
  var allowedCollectionIds = new Set();
1140
1344
  var hasProductAll = false;
1141
- var _iterator3 = _createForOfIteratorHelper(activeMenuList),
1142
- _step3;
1345
+ var _iterator4 = _createForOfIteratorHelper(activeMenuList),
1346
+ _step4;
1143
1347
  try {
1144
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1145
- var menu = _step3.value;
1348
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1349
+ var menu = _step4.value;
1146
1350
  var config = menu.partyroom_package;
1147
1351
  if (!config) {
1148
1352
  console.warn('[Server] 餐牌缺少 partyroom_package 配置:', menu);
@@ -1202,9 +1406,9 @@ var Server = /*#__PURE__*/function () {
1202
1406
 
1203
1407
  // 如果有餐牌允许所有商品,返回所有商品
1204
1408
  } catch (err) {
1205
- _iterator3.e(err);
1409
+ _iterator4.e(err);
1206
1410
  } finally {
1207
- _iterator3.f();
1411
+ _iterator4.f();
1208
1412
  }
1209
1413
  if (hasProductAll) {
1210
1414
  this.logInfo('filterProductsByMenuConfig: 返回所有商品(product_all)', {