@pisell/pisellos 2.2.80 → 2.2.82

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,7 +1,3 @@
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; }
5
1
  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; } } }; }
6
2
  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); }
7
3
  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; }
@@ -22,12 +18,8 @@ import { MenuModule } from "./modules/menu";
22
18
  import { QuotationModule } from "./modules/quotation";
23
19
  import { ScheduleModuleEx } from "./modules/schedule";
24
20
  import { extractScheduleIdsFromMenus, extractTimePointsFromSchedules } from "./utils/schedule";
25
- import { ProductsHooks } from "./modules/products/types";
26
- import { perfMark } from "./utils/product";
27
21
 
28
22
  // 重新导出类型供外部使用
29
-
30
- /** 商品查询订阅者 */
31
23
  /**
32
24
  * Server 类
33
25
  * 用于注册和管理服务端模块
@@ -54,8 +46,6 @@ var Server = /*#__PURE__*/function () {
54
46
  put: {},
55
47
  remove: {}
56
48
  });
57
- // ---- 商品查询订阅者 ----
58
- _defineProperty(this, "productQuerySubscribers", new Map());
59
49
  // 模块注册表 - 定义所有可用的模块配置
60
50
  _defineProperty(this, "moduleRegistry", {
61
51
  products: {
@@ -99,46 +89,159 @@ var Server = /*#__PURE__*/function () {
99
89
  }
100
90
  });
101
91
  /**
102
- * 处理商品查询请求
103
- * 存储订阅者信息,便于数据变更时推送最新结果
92
+ * 处理商品查询请求(编排 Products、Menu、Schedule 模块)
93
+ * 这是一个业务编排方法,协调多个模块完成复杂的业务需求
104
94
  */
105
95
  _defineProperty(this, "handleProductQuery", /*#__PURE__*/function () {
106
96
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
107
- var url, method, data, config, menu_list_ids, schedule_datetime, schedule_date, _ref3, callback, subscriberId;
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;
108
99
  return _regeneratorRuntime().wrap(function _callee$(_context) {
109
100
  while (1) switch (_context.prev = _context.next) {
110
101
  case 0:
111
102
  url = _ref.url, method = _ref.method, data = _ref.data, config = _ref.config;
112
103
  console.log('[Server] handleProductQuery:', url, method, data, config);
113
104
  menu_list_ids = data.menu_list_ids, schedule_datetime = data.schedule_datetime, schedule_date = data.schedule_date;
114
- _ref3 = config || {}, callback = _ref3.callback, subscriberId = _ref3.subscriberId;
115
- _this.logInfo('handleProductQuery: 开始处理商品查询请求', {
116
- menu_list_ids: menu_list_ids,
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,
117
107
  schedule_datetime: schedule_datetime,
118
- schedule_date: schedule_date
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
+ }
119
153
  });
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
+ });
120
163
 
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
- }
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
130
183
  });
131
- _this.logInfo('handleProductQuery: 已注册订阅者', {
132
- subscriberId: subscriberId,
133
- totalSubscribers: _this.productQuerySubscribers.size
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
134
188
  });
135
189
  }
136
- return _context.abrupt("return", _this.computeProductQueryResult({
137
- menu_list_ids: menu_list_ids,
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,
138
230
  schedule_date: schedule_date,
139
231
  schedule_datetime: schedule_datetime
140
- }));
141
- case 7:
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:
142
245
  case "end":
143
246
  return _context.stop();
144
247
  }
@@ -148,60 +251,33 @@ var Server = /*#__PURE__*/function () {
148
251
  return _ref2.apply(this, arguments);
149
252
  };
150
253
  }());
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
- }());
178
254
  /**
179
255
  * 处理获取日程时间段点的请求
180
256
  * 通过餐牌ID列表获取所有相关日程的时间段点
181
257
  */
182
258
  _defineProperty(this, "handleGetScheduleTimePoints", /*#__PURE__*/function () {
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) {
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) {
188
264
  case 0:
189
- url = _ref7.url, method = _ref7.method, data = _ref7.data, config = _ref7.config;
265
+ url = _ref3.url, method = _ref3.method, data = _ref3.data, config = _ref3.config;
190
266
  console.log('[Server] handleGetScheduleTimePoints:', url, method, data, config);
191
267
  menu_list_ids = data.menu_list_ids;
192
268
  _this.logInfo('handleGetScheduleTimePoints 开始处理', {
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,
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,
194
270
  menu_list_ids: menu_list_ids
195
271
  });
196
272
 
197
273
  // 检查必要的模块是否已注册
198
274
  if (_this.menu) {
199
- _context3.next = 8;
275
+ _context2.next = 8;
200
276
  break;
201
277
  }
202
278
  console.error('[Server] Menu 模块未注册');
203
279
  _this.logError('handleGetScheduleTimePoints: Menu 模块未注册');
204
- return _context3.abrupt("return", {
280
+ return _context2.abrupt("return", {
205
281
  code: 500,
206
282
  message: 'Menu 模块未注册',
207
283
  data: [],
@@ -209,12 +285,12 @@ var Server = /*#__PURE__*/function () {
209
285
  });
210
286
  case 8:
211
287
  if (_this.schedule) {
212
- _context3.next = 12;
288
+ _context2.next = 12;
213
289
  break;
214
290
  }
215
291
  console.error('[Server] Schedule 模块未注册');
216
292
  _this.logError('handleGetScheduleTimePoints: Schedule 模块未注册');
217
- return _context3.abrupt("return", {
293
+ return _context2.abrupt("return", {
218
294
  code: 500,
219
295
  message: 'Schedule 模块未注册',
220
296
  data: [],
@@ -222,22 +298,22 @@ var Server = /*#__PURE__*/function () {
222
298
  });
223
299
  case 12:
224
300
  if (!(!menu_list_ids || !Array.isArray(menu_list_ids) || menu_list_ids.length === 0)) {
225
- _context3.next = 16;
301
+ _context2.next = 16;
226
302
  break;
227
303
  }
228
304
  console.error('[Server] menu_list_ids 参数无效');
229
305
  _this.logWarning('handleGetScheduleTimePoints: menu_list_ids 参数无效', {
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,
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,
231
307
  menu_list_ids: menu_list_ids
232
308
  });
233
- return _context3.abrupt("return", {
309
+ return _context2.abrupt("return", {
234
310
  code: 400,
235
311
  message: 'menu_list_ids 参数无效',
236
312
  data: [],
237
313
  status: false
238
314
  });
239
315
  case 16:
240
- _context3.prev = 16;
316
+ _context2.prev = 16;
241
317
  // 1. 获取餐牌列表
242
318
  menuList = _this.menu.getMenuByIds(menu_list_ids);
243
319
  console.log("[Server] \u627E\u5230 ".concat(menuList.length, " \u4E2A\u9910\u724C"));
@@ -255,13 +331,13 @@ var Server = /*#__PURE__*/function () {
255
331
  scheduleCount: scheduleIds.length
256
332
  });
257
333
  if (!(scheduleIds.length === 0)) {
258
- _context3.next = 26;
334
+ _context2.next = 26;
259
335
  break;
260
336
  }
261
337
  _this.logInfo('handleGetScheduleTimePoints: 没有找到相关日程', {
262
338
  menuListIdsCount: menu_list_ids.length
263
339
  });
264
- return _context3.abrupt("return", {
340
+ return _context2.abrupt("return", {
265
341
  code: 200,
266
342
  message: '没有找到相关日程',
267
343
  data: [],
@@ -285,22 +361,22 @@ var Server = /*#__PURE__*/function () {
285
361
  scheduleCount: scheduleList.length,
286
362
  timePointCount: timePoints.length
287
363
  });
288
- return _context3.abrupt("return", {
364
+ return _context2.abrupt("return", {
289
365
  code: 200,
290
366
  message: '获取成功',
291
367
  data: timePoints,
292
368
  status: true
293
369
  });
294
370
  case 35:
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);
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);
299
375
  _this.logError('handleGetScheduleTimePoints: 获取日程时间点失败', {
300
376
  menuListIdsCount: menu_list_ids.length,
301
377
  error: errorMessage
302
378
  });
303
- return _context3.abrupt("return", {
379
+ return _context2.abrupt("return", {
304
380
  code: 500,
305
381
  message: "\u83B7\u53D6\u5931\u8D25: ".concat(errorMessage),
306
382
  data: [],
@@ -308,19 +384,19 @@ var Server = /*#__PURE__*/function () {
308
384
  });
309
385
  case 41:
310
386
  case "end":
311
- return _context3.stop();
387
+ return _context2.stop();
312
388
  }
313
- }, _callee3, null, [[16, 35]]);
389
+ }, _callee2, null, [[16, 35]]);
314
390
  }));
315
- return function (_x3) {
316
- return _ref8.apply(this, arguments);
391
+ return function (_x2) {
392
+ return _ref4.apply(this, arguments);
317
393
  };
318
394
  }());
319
395
  this.core = core;
320
396
  var appPlugin = core.getPlugin('app');
321
397
  this.app = (appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp()) || null;
322
398
  this.logger = ((_this$app = this.app) === null || _this$app === void 0 ? void 0 : _this$app.logger) || null;
323
- console.log('[Server] Server 初始化', this.core);
399
+ console.log('[Server] Server 初始化');
324
400
  this.logInfo('Server 初始化', {
325
401
  hasApp: !!this.app,
326
402
  hasLogger: !!this.logger
@@ -374,10 +450,10 @@ var Server = /*#__PURE__*/function () {
374
450
  }, {
375
451
  key: "registerModuleWithRoutes",
376
452
  value: (function () {
377
- var _registerModuleWithRoutes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(module, options, moduleName) {
453
+ var _registerModuleWithRoutes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(module, options, moduleName) {
378
454
  var routes;
379
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
380
- while (1) switch (_context4.prev = _context4.next) {
455
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
456
+ while (1) switch (_context3.prev = _context3.next) {
381
457
  case 0:
382
458
  this.logInfo("\u5F00\u59CB\u6CE8\u518C\u6A21\u5757: ".concat(moduleName), {
383
459
  moduleName: moduleName,
@@ -385,7 +461,7 @@ var Server = /*#__PURE__*/function () {
385
461
  });
386
462
 
387
463
  // 注册模块到 Core
388
- _context4.next = 3;
464
+ _context3.next = 3;
389
465
  return this.core.registerModule(module, options);
390
466
  case 3:
391
467
  console.log("[Server] \u2705 ".concat(moduleName, " \u6A21\u5757\u5DF2\u6CE8\u518C"));
@@ -406,11 +482,11 @@ var Server = /*#__PURE__*/function () {
406
482
  }
407
483
  case 6:
408
484
  case "end":
409
- return _context4.stop();
485
+ return _context3.stop();
410
486
  }
411
- }, _callee4, this);
487
+ }, _callee3, this);
412
488
  }));
413
- function registerModuleWithRoutes(_x4, _x5, _x6) {
489
+ function registerModuleWithRoutes(_x3, _x4, _x5) {
414
490
  return _registerModuleWithRoutes.apply(this, arguments);
415
491
  }
416
492
  return registerModuleWithRoutes;
@@ -423,10 +499,10 @@ var Server = /*#__PURE__*/function () {
423
499
  }, {
424
500
  key: "registerModuleByName",
425
501
  value: (function () {
426
- var _registerModuleByName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(moduleConfig) {
502
+ var _registerModuleByName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(moduleConfig) {
427
503
  var moduleName, shouldPreload, customConfig, registryConfig, ModuleClass, moduleInstance, moduleOptions;
428
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
429
- while (1) switch (_context5.prev = _context5.next) {
504
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
505
+ while (1) switch (_context4.prev = _context4.next) {
430
506
  case 0:
431
507
  // 解析配置
432
508
  moduleName = typeof moduleConfig === 'string' ? moduleConfig : moduleConfig.name;
@@ -441,7 +517,7 @@ var Server = /*#__PURE__*/function () {
441
517
  // 查找模块配置
442
518
  registryConfig = this.moduleRegistry[moduleName];
443
519
  if (registryConfig) {
444
- _context5.next = 8;
520
+ _context4.next = 8;
445
521
  break;
446
522
  }
447
523
  this.logError("\u672A\u627E\u5230\u6A21\u5757\u914D\u7F6E: ".concat(moduleName), {
@@ -455,7 +531,7 @@ var Server = /*#__PURE__*/function () {
455
531
  moduleOptions = _objectSpread({
456
532
  store: _objectSpread({}, registryConfig.defaultStore)
457
533
  }, customConfig); // 注册模块和路由
458
- _context5.next = 13;
534
+ _context4.next = 13;
459
535
  return this.registerModuleWithRoutes(moduleInstance, moduleOptions, moduleName.charAt(0).toUpperCase() + moduleName.slice(1));
460
536
  case 13:
461
537
  // 保存模块实例
@@ -465,18 +541,18 @@ var Server = /*#__PURE__*/function () {
465
541
  shouldPreload: shouldPreload,
466
542
  version: registryConfig.version
467
543
  });
468
- return _context5.abrupt("return", {
544
+ return _context4.abrupt("return", {
469
545
  module: moduleInstance,
470
546
  config: registryConfig,
471
547
  shouldPreload: shouldPreload
472
548
  });
473
549
  case 16:
474
550
  case "end":
475
- return _context5.stop();
551
+ return _context4.stop();
476
552
  }
477
- }, _callee5, this);
553
+ }, _callee4, this);
478
554
  }));
479
- function registerModuleByName(_x7) {
555
+ function registerModuleByName(_x6) {
480
556
  return _registerModuleByName.apply(this, arguments);
481
557
  }
482
558
  return registerModuleByName;
@@ -489,10 +565,10 @@ var Server = /*#__PURE__*/function () {
489
565
  }, {
490
566
  key: "registerModules",
491
567
  value: (function () {
492
- var _registerModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(moduleConfigs) {
568
+ var _registerModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(moduleConfigs) {
493
569
  var configs, registeredModules, _iterator, _step, config, configName, result, errorMessage;
494
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
495
- while (1) switch (_context6.prev = _context6.next) {
570
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
571
+ while (1) switch (_context5.prev = _context5.next) {
496
572
  case 0:
497
573
  console.log('[Server] 开始注册模块...');
498
574
 
@@ -504,47 +580,47 @@ var Server = /*#__PURE__*/function () {
504
580
  });
505
581
  registeredModules = [];
506
582
  _iterator = _createForOfIteratorHelper(configs);
507
- _context6.prev = 5;
583
+ _context5.prev = 5;
508
584
  _iterator.s();
509
585
  case 7:
510
586
  if ((_step = _iterator.n()).done) {
511
- _context6.next = 25;
587
+ _context5.next = 25;
512
588
  break;
513
589
  }
514
590
  config = _step.value;
515
591
  configName = typeof config === 'string' ? config : config.name;
516
- _context6.prev = 10;
517
- _context6.next = 13;
592
+ _context5.prev = 10;
593
+ _context5.next = 13;
518
594
  return this.registerModuleByName(config);
519
595
  case 13:
520
- result = _context6.sent;
596
+ result = _context5.sent;
521
597
  registeredModules.push(result);
522
- _context6.next = 23;
598
+ _context5.next = 23;
523
599
  break;
524
600
  case 17:
525
- _context6.prev = 17;
526
- _context6.t0 = _context6["catch"](10);
527
- errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
601
+ _context5.prev = 17;
602
+ _context5.t0 = _context5["catch"](10);
603
+ errorMessage = _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0);
528
604
  this.logError("\u6A21\u5757\u6CE8\u518C\u5931\u8D25: ".concat(configName), {
529
605
  moduleName: configName,
530
606
  error: errorMessage
531
607
  });
532
- console.error("[Server] \u6A21\u5757\u6CE8\u518C\u5931\u8D25:", _context6.t0);
533
- throw _context6.t0;
608
+ console.error("[Server] \u6A21\u5757\u6CE8\u518C\u5931\u8D25:", _context5.t0);
609
+ throw _context5.t0;
534
610
  case 23:
535
- _context6.next = 7;
611
+ _context5.next = 7;
536
612
  break;
537
613
  case 25:
538
- _context6.next = 30;
614
+ _context5.next = 30;
539
615
  break;
540
616
  case 27:
541
- _context6.prev = 27;
542
- _context6.t1 = _context6["catch"](5);
543
- _iterator.e(_context6.t1);
617
+ _context5.prev = 27;
618
+ _context5.t1 = _context5["catch"](5);
619
+ _iterator.e(_context5.t1);
544
620
  case 30:
545
- _context6.prev = 30;
621
+ _context5.prev = 30;
546
622
  _iterator.f();
547
- return _context6.finish(30);
623
+ return _context5.finish(30);
548
624
  case 33:
549
625
  console.log('[Server] ✅ 所有模块注册完成');
550
626
  this.logInfo('所有模块注册完成', {
@@ -554,14 +630,14 @@ var Server = /*#__PURE__*/function () {
554
630
  return m === null || m === void 0 || (_m$config = m.config) === null || _m$config === void 0 ? void 0 : _m$config.name;
555
631
  })
556
632
  });
557
- return _context6.abrupt("return", registeredModules);
633
+ return _context5.abrupt("return", registeredModules);
558
634
  case 36:
559
635
  case "end":
560
- return _context6.stop();
636
+ return _context5.stop();
561
637
  }
562
- }, _callee6, this, [[5, 27, 30, 33], [10, 17]]);
638
+ }, _callee5, this, [[5, 27, 30, 33], [10, 17]]);
563
639
  }));
564
- function registerModules(_x8) {
640
+ function registerModules(_x7) {
565
641
  return _registerModules.apply(this, arguments);
566
642
  }
567
643
  return registerModules;
@@ -574,10 +650,10 @@ var Server = /*#__PURE__*/function () {
574
650
  }, {
575
651
  key: "preloadModulesData",
576
652
  value: (function () {
577
- var _preloadModulesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(registeredModules, options) {
653
+ var _preloadModulesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(registeredModules, options) {
578
654
  var modulesToPreload, preloadResults, _iterator2, _step2, _step2$value, module, config, shouldPreload, startTime, _options$onModuleLoad, _options$onModuleLoad2, duration, _duration, errorMessage, successCount, failCount;
579
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
580
- while (1) switch (_context7.prev = _context7.next) {
655
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
656
+ while (1) switch (_context6.prev = _context6.next) {
581
657
  case 0:
582
658
  console.log('[Server] 开始预加载模块数据...');
583
659
  modulesToPreload = registeredModules.filter(function (m) {
@@ -590,16 +666,16 @@ var Server = /*#__PURE__*/function () {
590
666
  });
591
667
  preloadResults = [];
592
668
  _iterator2 = _createForOfIteratorHelper(registeredModules);
593
- _context7.prev = 5;
669
+ _context6.prev = 5;
594
670
  _iterator2.s();
595
671
  case 7:
596
672
  if ((_step2 = _iterator2.n()).done) {
597
- _context7.next = 40;
673
+ _context6.next = 40;
598
674
  break;
599
675
  }
600
676
  _step2$value = _step2.value, module = _step2$value.module, config = _step2$value.config, shouldPreload = _step2$value.shouldPreload;
601
677
  if (shouldPreload) {
602
- _context7.next = 13;
678
+ _context6.next = 13;
603
679
  break;
604
680
  }
605
681
  console.log("[Server] \u23ED\uFE0F \u8DF3\u8FC7 ".concat(config.name, " \u6A21\u5757\u9884\u52A0\u8F7D"));
@@ -607,19 +683,19 @@ var Server = /*#__PURE__*/function () {
607
683
  moduleName: config.name,
608
684
  reason: 'shouldPreload=false'
609
685
  });
610
- return _context7.abrupt("continue", 38);
686
+ return _context6.abrupt("continue", 38);
611
687
  case 13:
612
688
  if (!(typeof module.preload === 'function')) {
613
- _context7.next = 36;
689
+ _context6.next = 36;
614
690
  break;
615
691
  }
616
692
  startTime = Date.now();
617
- _context7.prev = 15;
693
+ _context6.prev = 15;
618
694
  this.logInfo("\u5F00\u59CB\u9884\u52A0\u8F7D\u6A21\u5757: ".concat(config.name), {
619
695
  moduleName: config.name
620
696
  });
621
697
  options === null || options === void 0 || (_options$onModuleLoad = options.onModuleLoad) === null || _options$onModuleLoad === void 0 || _options$onModuleLoad.call(options, config.name);
622
- _context7.next = 20;
698
+ _context6.next = 20;
623
699
  return module.preload();
624
700
  case 20:
625
701
  options === null || options === void 0 || (_options$onModuleLoad2 = options.onModuleLoadComplete) === null || _options$onModuleLoad2 === void 0 || _options$onModuleLoad2.call(options, config.name);
@@ -633,14 +709,14 @@ var Server = /*#__PURE__*/function () {
633
709
  name: config.name,
634
710
  success: true
635
711
  });
636
- _context7.next = 34;
712
+ _context6.next = 34;
637
713
  break;
638
714
  case 27:
639
- _context7.prev = 27;
640
- _context7.t0 = _context7["catch"](15);
715
+ _context6.prev = 27;
716
+ _context6.t0 = _context6["catch"](15);
641
717
  _duration = Date.now() - startTime;
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);
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);
644
720
  this.logError("\u6A21\u5757\u9884\u52A0\u8F7D\u5931\u8D25: ".concat(config.name), {
645
721
  moduleName: config.name,
646
722
  duration: "".concat(_duration, "ms"),
@@ -652,7 +728,7 @@ var Server = /*#__PURE__*/function () {
652
728
  error: errorMessage
653
729
  });
654
730
  case 34:
655
- _context7.next = 38;
731
+ _context6.next = 38;
656
732
  break;
657
733
  case 36:
658
734
  console.log("[Server] \u26A0\uFE0F ".concat(config.name, " \u6A21\u5757\u672A\u5B9E\u73B0 preload() \u65B9\u6CD5"));
@@ -660,19 +736,19 @@ var Server = /*#__PURE__*/function () {
660
736
  moduleName: config.name
661
737
  });
662
738
  case 38:
663
- _context7.next = 7;
739
+ _context6.next = 7;
664
740
  break;
665
741
  case 40:
666
- _context7.next = 45;
742
+ _context6.next = 45;
667
743
  break;
668
744
  case 42:
669
- _context7.prev = 42;
670
- _context7.t1 = _context7["catch"](5);
671
- _iterator2.e(_context7.t1);
745
+ _context6.prev = 42;
746
+ _context6.t1 = _context6["catch"](5);
747
+ _iterator2.e(_context6.t1);
672
748
  case 45:
673
- _context7.prev = 45;
749
+ _context6.prev = 45;
674
750
  _iterator2.f();
675
- return _context7.finish(45);
751
+ return _context6.finish(45);
676
752
  case 48:
677
753
  successCount = preloadResults.filter(function (r) {
678
754
  return r.success;
@@ -687,11 +763,11 @@ var Server = /*#__PURE__*/function () {
687
763
  });
688
764
  case 52:
689
765
  case "end":
690
- return _context7.stop();
766
+ return _context6.stop();
691
767
  }
692
- }, _callee7, this, [[5, 42, 45, 48], [15, 27]]);
768
+ }, _callee6, this, [[5, 42, 45, 48], [15, 27]]);
693
769
  }));
694
- function preloadModulesData(_x9, _x10) {
770
+ function preloadModulesData(_x8, _x9) {
695
771
  return _preloadModulesData.apply(this, arguments);
696
772
  }
697
773
  return preloadModulesData;
@@ -705,20 +781,19 @@ var Server = /*#__PURE__*/function () {
705
781
  }, {
706
782
  key: "initialize",
707
783
  value: (function () {
708
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(moduleConfigs) {
709
- var _moduleConfigs$length,
710
- _this3 = this;
784
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(moduleConfigs) {
785
+ var _moduleConfigs$length;
711
786
  var autoPreload,
712
787
  options,
713
788
  startTime,
714
789
  registeredModules,
715
790
  duration,
716
- _args8 = arguments;
717
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
718
- while (1) switch (_context8.prev = _context8.next) {
791
+ _args7 = arguments;
792
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
793
+ while (1) switch (_context7.prev = _context7.next) {
719
794
  case 0:
720
- autoPreload = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : true;
721
- options = _args8.length > 2 ? _args8[2] : undefined;
795
+ autoPreload = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : true;
796
+ options = _args7.length > 2 ? _args7[2] : undefined;
722
797
  startTime = Date.now();
723
798
  this.logInfo('Server 初始化开始', {
724
799
  moduleConfigCount: (_moduleConfigs$length = moduleConfigs === null || moduleConfigs === void 0 ? void 0 : moduleConfigs.length) !== null && _moduleConfigs$length !== void 0 ? _moduleConfigs$length : 'all',
@@ -730,41 +805,37 @@ var Server = /*#__PURE__*/function () {
730
805
  this.registerServerRoutes();
731
806
 
732
807
  // 注册模块
733
- _context8.next = 7;
808
+ _context7.next = 7;
734
809
  return this.registerModules(moduleConfigs);
735
810
  case 7:
736
- registeredModules = _context8.sent;
811
+ registeredModules = _context7.sent;
737
812
  if (!autoPreload) {
738
- _context8.next = 13;
813
+ _context7.next = 13;
739
814
  break;
740
815
  }
741
- _context8.next = 11;
816
+ _context7.next = 11;
742
817
  return this.preloadModulesData(registeredModules, options);
743
818
  case 11:
744
- _context8.next = 14;
819
+ _context7.next = 14;
745
820
  break;
746
821
  case 13:
747
822
  this.logInfo('跳过自动预加载', {
748
823
  autoPreload: autoPreload
749
824
  });
750
825
  case 14:
751
- // 监听 ProductsModule 同步完成事件,重新计算并推送查询结果
752
- this.core.effects.on(ProductsHooks.onProductsSyncCompleted, function () {
753
- _this3.recomputeAndNotifyProductQuery();
754
- });
755
826
  duration = Date.now() - startTime;
756
827
  this.logInfo('Server 初始化完成', {
757
828
  duration: "".concat(duration, "ms"),
758
829
  registeredModuleCount: registeredModules.length
759
830
  });
760
- return _context8.abrupt("return", registeredModules);
761
- case 18:
831
+ return _context7.abrupt("return", registeredModules);
832
+ case 17:
762
833
  case "end":
763
- return _context8.stop();
834
+ return _context7.stop();
764
835
  }
765
- }, _callee8, this);
836
+ }, _callee7, this);
766
837
  }));
767
- function initialize(_x11) {
838
+ function initialize(_x10) {
768
839
  return _initialize.apply(this, arguments);
769
840
  }
770
841
  return initialize;
@@ -820,71 +891,17 @@ var Server = /*#__PURE__*/function () {
820
891
  return modules;
821
892
  }
822
893
 
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
- }()
876
894
  /**
877
895
  * 清空所有server模块的IndexedDB缓存
878
896
  * @returns Promise<void>
879
897
  */
880
- )
881
898
  }, {
882
899
  key: "clearAllIndexDB",
883
900
  value: (function () {
884
- var _clearAllIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
901
+ var _clearAllIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
885
902
  var clearTasks, moduleNames, errorMessage;
886
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
887
- while (1) switch (_context10.prev = _context10.next) {
903
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
904
+ while (1) switch (_context8.prev = _context8.next) {
888
905
  case 0:
889
906
  console.log('[Server] 开始清空所有模块的IndexedDB缓存...');
890
907
  this.logInfo('开始清空所有模块的 IndexedDB 缓存');
@@ -907,41 +924,41 @@ var Server = /*#__PURE__*/function () {
907
924
  moduleNames.push('Schedule');
908
925
  }
909
926
  if (!(clearTasks.length === 0)) {
910
- _context10.next = 12;
927
+ _context8.next = 12;
911
928
  break;
912
929
  }
913
930
  console.warn('[Server] 没有找到已注册的模块,无需清空');
914
931
  this.logWarning('没有找到已注册的模块,无需清空 IndexedDB');
915
- return _context10.abrupt("return");
932
+ return _context8.abrupt("return");
916
933
  case 12:
917
934
  this.logInfo('准备清空模块缓存', {
918
935
  moduleNames: moduleNames
919
936
  });
920
- _context10.prev = 13;
921
- _context10.next = 16;
937
+ _context8.prev = 13;
938
+ _context8.next = 16;
922
939
  return Promise.all(clearTasks);
923
940
  case 16:
924
941
  console.log("[Server] \u2705 \u5DF2\u6210\u529F\u6E05\u7A7A\u6240\u6709\u6A21\u5757\u7684IndexedDB\u7F13\u5B58: ".concat(moduleNames.join(', ')));
925
942
  this.logInfo('成功清空所有模块的 IndexedDB 缓存', {
926
943
  moduleNames: moduleNames
927
944
  });
928
- _context10.next = 26;
945
+ _context8.next = 26;
929
946
  break;
930
947
  case 20:
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);
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);
935
952
  this.logError('清空 IndexedDB 缓存时发生错误', {
936
953
  moduleNames: moduleNames,
937
954
  error: errorMessage
938
955
  });
939
- throw _context10.t0;
956
+ throw _context8.t0;
940
957
  case 26:
941
958
  case "end":
942
- return _context10.stop();
959
+ return _context8.stop();
943
960
  }
944
- }, _callee10, this, [[13, 20]]);
961
+ }, _callee8, this, [[13, 20]]);
945
962
  }));
946
963
  function clearAllIndexDB() {
947
964
  return _clearAllIndexDB.apply(this, arguments);
@@ -992,10 +1009,10 @@ var Server = /*#__PURE__*/function () {
992
1009
  }, {
993
1010
  key: "handleRoute",
994
1011
  value: (function () {
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) {
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) {
999
1016
  case 0:
1000
1017
  startTime = Date.now();
1001
1018
  console.log(method, path, params, 'method, path, params');
@@ -1007,7 +1024,7 @@ var Server = /*#__PURE__*/function () {
1007
1024
  });
1008
1025
  handler = this.getRouteHandler(method, path);
1009
1026
  if (handler) {
1010
- _context11.next = 7;
1027
+ _context9.next = 7;
1011
1028
  break;
1012
1029
  }
1013
1030
  this.logError("\u8DEF\u7531\u672A\u627E\u5230: ".concat(method.toUpperCase(), " ").concat(path), {
@@ -1016,11 +1033,11 @@ var Server = /*#__PURE__*/function () {
1016
1033
  });
1017
1034
  throw new Error("Route not found: ".concat(method.toUpperCase(), " ").concat(path));
1018
1035
  case 7:
1019
- _context11.prev = 7;
1020
- _context11.next = 10;
1036
+ _context9.prev = 7;
1037
+ _context9.next = 10;
1021
1038
  return handler(params);
1022
1039
  case 10:
1023
- result = _context11.sent;
1040
+ result = _context9.sent;
1024
1041
  duration = Date.now() - startTime;
1025
1042
  this.logInfo("\u8DEF\u7531\u8BF7\u6C42\u5B8C\u6210: ".concat(method.toUpperCase(), " ").concat(path), {
1026
1043
  method: method.toUpperCase(),
@@ -1029,28 +1046,28 @@ var Server = /*#__PURE__*/function () {
1029
1046
  resultCode: result === null || result === void 0 ? void 0 : result.code,
1030
1047
  resultStatus: result === null || result === void 0 ? void 0 : result.status
1031
1048
  });
1032
- return _context11.abrupt("return", result);
1049
+ return _context9.abrupt("return", result);
1033
1050
  case 16:
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);
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);
1038
1055
  this.logError("\u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), {
1039
1056
  method: method.toUpperCase(),
1040
1057
  path: path,
1041
- duration: "".concat(_duration3, "ms"),
1058
+ duration: "".concat(_duration2, "ms"),
1042
1059
  error: errorMessage,
1043
1060
  data: params.data
1044
1061
  });
1045
- console.error("[Server] \u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), _context11.t0);
1046
- throw _context11.t0;
1062
+ console.error("[Server] \u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), _context9.t0);
1063
+ throw _context9.t0;
1047
1064
  case 23:
1048
1065
  case "end":
1049
- return _context11.stop();
1066
+ return _context9.stop();
1050
1067
  }
1051
- }, _callee11, this, [[7, 16]]);
1068
+ }, _callee9, this, [[7, 16]]);
1052
1069
  }));
1053
- function handleRoute(_x12, _x13, _x14) {
1070
+ function handleRoute(_x11, _x12, _x13) {
1054
1071
  return _handleRoute.apply(this, arguments);
1055
1072
  }
1056
1073
  return handleRoute;
@@ -1062,10 +1079,10 @@ var Server = /*#__PURE__*/function () {
1062
1079
  }, {
1063
1080
  key: "getAllRoutes",
1064
1081
  value: function getAllRoutes() {
1065
- var _this4 = this;
1082
+ var _this3 = this;
1066
1083
  var routes = [];
1067
1084
  ['get', 'post', 'put', 'remove'].forEach(function (method) {
1068
- Object.keys(_this4.router[method]).forEach(function (path) {
1085
+ Object.keys(_this3.router[method]).forEach(function (path) {
1069
1086
  routes.push({
1070
1087
  method: method,
1071
1088
  path: path
@@ -1084,239 +1101,21 @@ var Server = /*#__PURE__*/function () {
1084
1101
  key: "registerServerRoutes",
1085
1102
  value: function registerServerRoutes() {
1086
1103
  console.log('[Server] 注册 Server 层业务路由...');
1104
+
1105
+ // 注册商品查询路由(带餐牌和日程信息)
1087
1106
  this.registerRoutes([{
1088
1107
  method: 'post',
1089
1108
  path: '/shop/product/query',
1090
1109
  handler: this.handleProductQuery.bind(this)
1091
- }, {
1092
- method: 'post',
1093
- path: '/shop/product/query/unsubscribe',
1094
- handler: this.handleUnsubscribeProductQuery.bind(this)
1095
1110
  }, {
1096
1111
  method: 'post',
1097
1112
  path: '/shop/menu/schedule-time-points',
1098
1113
  handler: this.handleGetScheduleTimePoints.bind(this)
1099
1114
  }]);
1100
1115
  }
1101
-
1102
- /**
1103
- * 根据 subscriberId 移除商品查询订阅者
1104
- */
1105
- }, {
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
1116
  }, {
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
- }()
1117
+ key: "filterProductsByMenuConfig",
1118
+ value:
1320
1119
  /**
1321
1120
  * 根据餐牌配置过滤商品
1322
1121
  * @param products 所有商品列表
@@ -1324,10 +1123,7 @@ var Server = /*#__PURE__*/function () {
1324
1123
  * @returns 过滤后的商品列表
1325
1124
  * @private
1326
1125
  */
1327
- )
1328
- }, {
1329
- key: "filterProductsByMenuConfig",
1330
- value: function filterProductsByMenuConfig(products, activeMenuList) {
1126
+ function filterProductsByMenuConfig(products, activeMenuList) {
1331
1127
  // 如果没有生效的餐牌,返回空数组
1332
1128
  if (!activeMenuList || activeMenuList.length === 0) {
1333
1129
  console.log('[Server] 没有生效的餐牌,返回空数组');
@@ -1342,11 +1138,11 @@ var Server = /*#__PURE__*/function () {
1342
1138
  var allowedProductIds = new Set();
1343
1139
  var allowedCollectionIds = new Set();
1344
1140
  var hasProductAll = false;
1345
- var _iterator4 = _createForOfIteratorHelper(activeMenuList),
1346
- _step4;
1141
+ var _iterator3 = _createForOfIteratorHelper(activeMenuList),
1142
+ _step3;
1347
1143
  try {
1348
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1349
- var menu = _step4.value;
1144
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1145
+ var menu = _step3.value;
1350
1146
  var config = menu.partyroom_package;
1351
1147
  if (!config) {
1352
1148
  console.warn('[Server] 餐牌缺少 partyroom_package 配置:', menu);
@@ -1406,9 +1202,9 @@ var Server = /*#__PURE__*/function () {
1406
1202
 
1407
1203
  // 如果有餐牌允许所有商品,返回所有商品
1408
1204
  } catch (err) {
1409
- _iterator4.e(err);
1205
+ _iterator3.e(err);
1410
1206
  } finally {
1411
- _iterator4.f();
1207
+ _iterator3.f();
1412
1208
  }
1413
1209
  if (hasProductAll) {
1414
1210
  this.logInfo('filterProductsByMenuConfig: 返回所有商品(product_all)', {