@pisell/pisellos 2.2.92 → 2.2.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/core/index.d.ts +0 -1
  2. package/dist/core/index.js +0 -7
  3. package/dist/plugins/app-types/app/app.d.ts +1 -0
  4. package/dist/server/index.d.ts +55 -5
  5. package/dist/server/index.js +832 -236
  6. package/dist/server/modules/index.d.ts +6 -0
  7. package/dist/server/modules/index.js +7 -0
  8. package/dist/server/modules/order/index.d.ts +87 -0
  9. package/dist/server/modules/order/index.js +916 -0
  10. package/dist/server/modules/order/types.d.ts +530 -0
  11. package/dist/server/modules/order/types.js +141 -0
  12. package/dist/server/modules/order/utils/filterBookings.d.ts +6 -0
  13. package/dist/server/modules/order/utils/filterBookings.js +350 -0
  14. package/dist/server/modules/order/utils/filterOrders.d.ts +15 -0
  15. package/dist/server/modules/order/utils/filterOrders.js +226 -0
  16. package/dist/server/modules/products/index.d.ts +24 -19
  17. package/dist/server/modules/products/index.js +600 -429
  18. package/dist/server/modules/products/types.d.ts +0 -1
  19. package/dist/server/modules/resource/index.d.ts +88 -0
  20. package/dist/server/modules/resource/index.js +1202 -0
  21. package/dist/server/modules/resource/types.d.ts +121 -0
  22. package/dist/server/modules/resource/types.js +47 -0
  23. package/dist/server/utils/product.d.ts +0 -4
  24. package/dist/server/utils/product.js +0 -34
  25. package/dist/solution/Sales/index.d.ts +96 -0
  26. package/dist/solution/Sales/index.js +510 -0
  27. package/dist/solution/Sales/types.d.ts +65 -0
  28. package/dist/solution/Sales/types.js +26 -0
  29. package/dist/solution/index.d.ts +1 -0
  30. package/dist/solution/index.js +2 -1
  31. package/dist/types/index.d.ts +0 -2
  32. package/lib/core/index.d.ts +0 -1
  33. package/lib/core/index.js +0 -4
  34. package/lib/plugins/app-types/app/app.d.ts +1 -0
  35. package/lib/server/index.d.ts +55 -5
  36. package/lib/server/index.js +350 -28
  37. package/lib/server/modules/index.d.ts +6 -0
  38. package/lib/server/modules/index.js +16 -2
  39. package/lib/server/modules/order/index.d.ts +87 -0
  40. package/lib/server/modules/order/index.js +543 -0
  41. package/lib/server/modules/order/types.d.ts +530 -0
  42. package/lib/server/modules/order/types.js +34 -0
  43. package/lib/server/modules/order/utils/filterBookings.d.ts +6 -0
  44. package/lib/server/modules/order/utils/filterBookings.js +320 -0
  45. package/lib/server/modules/order/utils/filterOrders.d.ts +15 -0
  46. package/lib/server/modules/order/utils/filterOrders.js +197 -0
  47. package/lib/server/modules/products/index.d.ts +24 -19
  48. package/lib/server/modules/products/index.js +150 -151
  49. package/lib/server/modules/products/types.d.ts +0 -1
  50. package/lib/server/modules/resource/index.d.ts +88 -0
  51. package/lib/server/modules/resource/index.js +571 -0
  52. package/lib/server/modules/resource/types.d.ts +121 -0
  53. package/lib/server/modules/resource/types.js +35 -0
  54. package/lib/server/utils/product.d.ts +0 -4
  55. package/lib/server/utils/product.js +0 -27
  56. package/lib/solution/Sales/index.d.ts +96 -0
  57. package/lib/solution/Sales/index.js +358 -0
  58. package/lib/solution/Sales/types.d.ts +65 -0
  59. package/lib/solution/Sales/types.js +35 -0
  60. package/lib/solution/index.d.ts +1 -0
  61. package/lib/solution/index.js +3 -1
  62. package/lib/types/index.d.ts +0 -2
  63. package/package.json +1 -1
package/lib/core/index.js CHANGED
@@ -235,10 +235,6 @@ var PisellOSCore = class {
235
235
  this.plugins.clear();
236
236
  this.log("PisellOS 核心已销毁");
237
237
  }
238
- setContext(ctx) {
239
- this.context = { ...this.context, ...ctx };
240
- this.log(`上下文已更新: ${JSON.stringify(Object.keys(ctx))}`);
241
- }
242
238
  /**
243
239
  * 验证上下文参数
244
240
  */
@@ -63,6 +63,7 @@ declare class App {
63
63
  pubsub: import("../pubsub").PubSub;
64
64
  tasksManager: TasksManager;
65
65
  dbManager: IndexDBManager | null;
66
+ sqlite: any;
66
67
  constants: {
67
68
  channel: string;
68
69
  [key: string]: string;
@@ -2,8 +2,10 @@ import { ProductsModule } from './modules/products';
2
2
  import { MenuModule } from './modules/menu';
3
3
  import { QuotationModule } from './modules/quotation';
4
4
  import { ScheduleModuleEx } from './modules/schedule';
5
+ import { ResourceModule } from './modules/resource';
5
6
  import { PisellCore, ServerModuleConfig, InitializeServerOptions } from '../types';
6
7
  import type { RouteHandler, HttpMethod, RouteDefinition, Router, ModuleRegistryConfig, RequestSetting } from './types';
8
+ import { OrderModule } from './modules/order';
7
9
  export type { RouteHandler, HttpMethod, RouteDefinition, Router, ModuleRegistryConfig, };
8
10
  /**
9
11
  * Server 类
@@ -17,8 +19,12 @@ declare class Server {
17
19
  menu?: MenuModule;
18
20
  quotation?: QuotationModule;
19
21
  schedule?: ScheduleModuleEx;
22
+ resource?: ResourceModule;
23
+ order?: OrderModule;
20
24
  router: Router;
21
25
  private productQuerySubscribers;
26
+ private orderQuerySubscribers;
27
+ private bookingQuerySubscribers;
22
28
  private moduleRegistry;
23
29
  constructor(core: PisellCore);
24
30
  /**
@@ -151,21 +157,65 @@ declare class Server {
151
157
  * 取消商品查询订阅(HTTP 路由入口)
152
158
  */
153
159
  private handleUnsubscribeProductQuery;
160
+ /**
161
+ * 处理订单列表查询
162
+ * 存储订阅者信息,本地计算结果;数据变更时通过 callback 推送
163
+ */
164
+ private handleOrderList;
165
+ /**
166
+ * 取消订单列表查询订阅(HTTP 路由入口)
167
+ */
168
+ private handleUnsubscribeOrderQuery;
169
+ /**
170
+ * 判断预约查询的 es_start_datetime_between 起始日期是否为今天
171
+ */
172
+ private isBookingQueryForToday;
173
+ /**
174
+ * 非今天的预约查询:通过真实 API 获取数据,再做 flattenOrdersToBookings 拆分
175
+ */
176
+ private fetchBookingListFromAPI;
177
+ /**
178
+ * 处理预约列表查询
179
+ * 今天:注册订阅者 + 本地数据筛选;非今天:清理订阅者 + 走真实 API
180
+ */
181
+ private handleBookingList;
182
+ /**
183
+ * 处理资源列表查询
184
+ * 转发到资源模块去
185
+ */
186
+ private handleResourceList;
187
+ /**
188
+ * 取消预约列表查询订阅(HTTP 路由入口)
189
+ */
190
+ private handleUnsubscribeBookingQuery;
191
+ /**
192
+ * 订单列表本地计算(编排 Order 模块)
193
+ * filter 逻辑暂为 mock,仅记录参数
194
+ */
195
+ private computeOrderQueryResult;
196
+ /**
197
+ * 预约列表本地计算(编排 Order 模块)
198
+ * 从订单中展开 bookings,再按条件筛选 + 分页
199
+ */
200
+ private computeBookingQueryResult;
154
201
  /**
155
202
  * 商品查询的核心计算逻辑(编排 Products、Menu、Schedule 模块)
156
203
  * 供 handleProductQuery 首次返回及 pubsub 变更推送复用
157
- * @param context 查询上下文
158
- * @param options 可选参数
159
- * @param options.changedIds 变更的商品 IDs,用于增量更新价格缓存
160
204
  */
161
205
  private computeProductQueryResult;
162
206
  /**
163
207
  * 数据变更后,遍历所有订阅者重新计算查询结果并通过 callback 推送
164
208
  * 由 ProductsModule 的 onProductsSyncCompleted 事件触发
165
- * @param options 可选参数
166
- * @param options.changedIds 变更的商品 IDs,用于增量更新价格缓存
167
209
  */
168
210
  private recomputeAndNotifyProductQuery;
211
+ /**
212
+ * 订单数据变更后,遍历订阅者重新计算并通过 callback 推送
213
+ */
214
+ private recomputeAndNotifyOrderQuery;
215
+ /**
216
+ * 预约数据变更后,遍历订阅者重新计算并通过 callback 推送
217
+ */
218
+ private recomputeAndNotifyBookingQuery;
169
219
  /**
170
220
  * 根据餐牌配置过滤商品
171
221
  * @param products 所有商品列表
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  return to;
16
18
  };
17
19
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/server/index.ts
@@ -23,13 +33,19 @@ __export(server_exports, {
23
33
  default: () => server_default
24
34
  });
25
35
  module.exports = __toCommonJS(server_exports);
36
+ var import_dayjs = __toESM(require("dayjs"));
26
37
  var import_products = require("./modules/products");
27
38
  var import_menu = require("./modules/menu");
28
39
  var import_quotation = require("./modules/quotation");
29
40
  var import_schedule = require("./modules/schedule");
41
+ var import_resource = require("./modules/resource");
30
42
  var import_schedule2 = require("./utils/schedule");
31
43
  var import_types = require("./modules/products/types");
32
44
  var import_product = require("./utils/product");
45
+ var import_order = require("./modules/order");
46
+ var import_types2 = require("./modules/order/types");
47
+ var import_filterOrders = require("./modules/order/utils/filterOrders");
48
+ var import_filterBookings = require("./modules/order/utils/filterBookings");
33
49
  __reExport(server_exports, require("./modules"), module.exports);
34
50
  var Server = class {
35
51
  constructor(core) {
@@ -42,6 +58,9 @@ var Server = class {
42
58
  };
43
59
  // ---- 商品查询订阅者 ----
44
60
  this.productQuerySubscribers = /* @__PURE__ */ new Map();
61
+ // ---- 订单 / 预约列表查询订阅者 ----
62
+ this.orderQuerySubscribers = /* @__PURE__ */ new Map();
63
+ this.bookingQuerySubscribers = /* @__PURE__ */ new Map();
45
64
  // 模块注册表 - 定义所有可用的模块配置
46
65
  this.moduleRegistry = {
47
66
  products: {
@@ -82,6 +101,26 @@ var Server = class {
82
101
  availabilityDateList: [],
83
102
  otherProductsIds: []
84
103
  }
104
+ },
105
+ order: {
106
+ name: "order",
107
+ moduleClass: import_order.OrderModule,
108
+ moduleName: "server_order",
109
+ version: "1.0.0",
110
+ defaultStore: {
111
+ list: []
112
+ }
113
+ },
114
+ resource: {
115
+ name: "resource",
116
+ moduleClass: import_resource.ResourceModule,
117
+ moduleName: "server_resource",
118
+ version: "1.0.0",
119
+ defaultStore: {
120
+ list: [],
121
+ map: /* @__PURE__ */ new Map(),
122
+ bookings: []
123
+ }
85
124
  }
86
125
  };
87
126
  /**
@@ -117,6 +156,109 @@ var Server = class {
117
156
  this.removeProductQuerySubscriber(subscriberId);
118
157
  return { code: 200, message: "ok", status: true };
119
158
  };
159
+ /**
160
+ * 处理订单列表查询
161
+ * 存储订阅者信息,本地计算结果;数据变更时通过 callback 推送
162
+ */
163
+ this.handleOrderList = async ({ url, method, data, config }) => {
164
+ console.log("[Server] handleOrderList:", url, method, data, config);
165
+ const queryPayload = data && typeof data === "object" ? { ...data } : {};
166
+ const { callback, subscriberId } = config || {};
167
+ this.logInfo("handleOrderList: 开始处理订单列表请求", { data: queryPayload });
168
+ if (subscriberId && typeof callback === "function") {
169
+ this.orderQuerySubscribers.set(subscriberId, {
170
+ callback,
171
+ context: queryPayload
172
+ });
173
+ this.logInfo("handleOrderList: 已注册订阅者", {
174
+ subscriberId,
175
+ totalSubscribers: this.orderQuerySubscribers.size
176
+ });
177
+ }
178
+ return this.computeOrderQueryResult(queryPayload);
179
+ };
180
+ /**
181
+ * 取消订单列表查询订阅(HTTP 路由入口)
182
+ */
183
+ this.handleUnsubscribeOrderQuery = async ({ data }) => {
184
+ const { subscriberId } = data || {};
185
+ if (subscriberId) {
186
+ this.orderQuerySubscribers.delete(subscriberId);
187
+ this.logInfo("handleUnsubscribeOrderQuery: 已移除订阅者", {
188
+ subscriberId,
189
+ remaining: this.orderQuerySubscribers.size
190
+ });
191
+ }
192
+ return { code: 200, message: "ok", status: true };
193
+ };
194
+ /**
195
+ * 处理预约列表查询
196
+ * 今天:注册订阅者 + 本地数据筛选;非今天:清理订阅者 + 走真实 API
197
+ */
198
+ this.handleBookingList = async ({ url, method, data, config }) => {
199
+ console.log("[Server] handleBookingList:", url, method, data, config);
200
+ const queryPayload = data && typeof data === "object" ? { ...data } : {};
201
+ const { callback, subscriberId } = config || {};
202
+ const isToday = this.isBookingQueryForToday(queryPayload);
203
+ this.logInfo("handleBookingList: 开始处理预约列表请求", {
204
+ data: queryPayload,
205
+ isToday
206
+ });
207
+ if (isToday) {
208
+ if (subscriberId && typeof callback === "function") {
209
+ this.bookingQuerySubscribers.set(subscriberId, {
210
+ callback,
211
+ context: queryPayload
212
+ });
213
+ this.logInfo("handleBookingList: 已注册订阅者(今天)", {
214
+ subscriberId,
215
+ totalSubscribers: this.bookingQuerySubscribers.size
216
+ });
217
+ }
218
+ return this.computeBookingQueryResult(queryPayload);
219
+ } else {
220
+ if (subscriberId) {
221
+ this.bookingQuerySubscribers.delete(subscriberId);
222
+ this.logInfo("handleBookingList: 已清理订阅者(非今天)", {
223
+ subscriberId,
224
+ remaining: this.bookingQuerySubscribers.size
225
+ });
226
+ }
227
+ return this.fetchBookingListFromAPI(queryPayload);
228
+ }
229
+ };
230
+ /**
231
+ * 处理资源列表查询
232
+ * 转发到资源模块去
233
+ */
234
+ this.handleResourceList = async ({ url, method, data, config }) => {
235
+ var _a;
236
+ console.log("[Server] handleResourceList:", url, method, data, config);
237
+ const list = (_a = this.resource) == null ? void 0 : _a.getResources({
238
+ skip: (data == null ? void 0 : data.skip) || 1,
239
+ num: (data == null ? void 0 : data.num) || 10
240
+ });
241
+ return {
242
+ code: 200,
243
+ data: { list, count: (list == null ? void 0 : list.length) || 0 },
244
+ message: "",
245
+ status: true
246
+ };
247
+ };
248
+ /**
249
+ * 取消预约列表查询订阅(HTTP 路由入口)
250
+ */
251
+ this.handleUnsubscribeBookingQuery = async ({ data }) => {
252
+ const { subscriberId } = data || {};
253
+ if (subscriberId) {
254
+ this.bookingQuerySubscribers.delete(subscriberId);
255
+ this.logInfo("handleUnsubscribeBookingQuery: 已移除订阅者", {
256
+ subscriberId,
257
+ remaining: this.bookingQuerySubscribers.size
258
+ });
259
+ }
260
+ return { code: 200, message: "ok", status: true };
261
+ };
120
262
  /**
121
263
  * 处理获取日程时间段点的请求
122
264
  * 通过餐牌ID列表获取所有相关日程的时间段点
@@ -415,10 +557,12 @@ var Server = class {
415
557
  } else {
416
558
  this.logInfo("跳过自动预加载", { autoPreload });
417
559
  }
418
- this.core.effects.on(import_types.ProductsHooks.onProductsSyncCompleted, (payload) => {
419
- this.recomputeAndNotifyProductQuery({
420
- changedIds: payload == null ? void 0 : payload.changedIds
421
- });
560
+ this.core.effects.on(import_types.ProductsHooks.onProductsSyncCompleted, () => {
561
+ this.recomputeAndNotifyProductQuery();
562
+ });
563
+ this.core.effects.on(import_types2.OrderHooks.onOrdersChanged, () => {
564
+ this.recomputeAndNotifyOrderQuery();
565
+ this.recomputeAndNotifyBookingQuery();
422
566
  });
423
567
  const duration = Date.now() - startTime;
424
568
  this.logInfo("Server 初始化完成", {
@@ -464,6 +608,10 @@ var Server = class {
464
608
  modules.push("quotation");
465
609
  if (this.schedule)
466
610
  modules.push("schedule");
611
+ if (this.resource)
612
+ modules.push("resource");
613
+ if (this.order)
614
+ modules.push("order");
467
615
  return modules;
468
616
  }
469
617
  /**
@@ -517,6 +665,14 @@ var Server = class {
517
665
  clearTasks.push(this.schedule.clear());
518
666
  moduleNames.push("Schedule");
519
667
  }
668
+ if (this.resource) {
669
+ clearTasks.push(this.resource.clear());
670
+ moduleNames.push("Resource");
671
+ }
672
+ if (this.order) {
673
+ clearTasks.push(this.order.clear());
674
+ moduleNames.push("Order");
675
+ }
520
676
  if (clearTasks.length === 0) {
521
677
  console.warn("[Server] 没有找到已注册的模块,无需清空");
522
678
  this.logWarning("没有找到已注册的模块,无需清空 IndexedDB");
@@ -567,7 +723,6 @@ var Server = class {
567
723
  */
568
724
  async handleRoute(method, path, params) {
569
725
  const startTime = Date.now();
570
- console.log(method, path, params, "method, path, params");
571
726
  this.logInfo(`路由请求开始: ${method.toUpperCase()} ${path}`, {
572
727
  method: method.toUpperCase(),
573
728
  path,
@@ -638,6 +793,31 @@ var Server = class {
638
793
  method: "post",
639
794
  path: "/shop/menu/schedule-time-points",
640
795
  handler: this.handleGetScheduleTimePoints.bind(this)
796
+ },
797
+ {
798
+ method: "post",
799
+ path: "/shop/order/v2/list",
800
+ handler: this.handleOrderList.bind(this)
801
+ },
802
+ {
803
+ method: "post",
804
+ path: "/shop/order/v2/list/unsubscribe",
805
+ handler: this.handleUnsubscribeOrderQuery.bind(this)
806
+ },
807
+ {
808
+ method: "get",
809
+ path: "/shop/schedule/booking",
810
+ handler: this.handleBookingList.bind(this)
811
+ },
812
+ {
813
+ method: "get",
814
+ path: "/shop/schedule/booking/unsubscribe",
815
+ handler: this.handleUnsubscribeBookingQuery.bind(this)
816
+ },
817
+ {
818
+ method: "get",
819
+ path: "/shop/form/resource/page",
820
+ handler: this.handleResourceList.bind(this)
641
821
  }
642
822
  ]);
643
823
  }
@@ -653,21 +833,131 @@ var Server = class {
653
833
  });
654
834
  }
655
835
  }
836
+ /**
837
+ * 判断预约查询的 es_start_datetime_between 起始日期是否为今天
838
+ */
839
+ isBookingQueryForToday(data) {
840
+ const range = data == null ? void 0 : data.es_start_datetime_between;
841
+ if (!Array.isArray(range) || range.length < 1)
842
+ return true;
843
+ const startDateStr = String(range[0]).split("T")[0].split(" ")[0];
844
+ const todayStr = (0, import_dayjs.default)().format("YYYY-MM-DD");
845
+ return startDateStr === todayStr;
846
+ }
847
+ /**
848
+ * 非今天的预约查询:通过真实 API 获取数据,再做 flattenOrdersToBookings 拆分
849
+ */
850
+ async fetchBookingListFromAPI(data) {
851
+ var _a, _b;
852
+ if (!((_a = this.app) == null ? void 0 : _a.request)) {
853
+ this.logError("fetchBookingListFromAPI: app.request 不可用");
854
+ return {
855
+ code: 500,
856
+ message: "app.request 不可用",
857
+ data: { list: [], count: 0 },
858
+ status: false
859
+ };
860
+ }
861
+ try {
862
+ const response = await this.app.request.get("/shop/order/sales", { ...data, with: ["all"] }, {
863
+ isShopApi: true
864
+ });
865
+ const rawList = ((_b = response == null ? void 0 : response.data) == null ? void 0 : _b.list) ?? (response == null ? void 0 : response.list) ?? [];
866
+ const list = (0, import_filterBookings.flattenOrdersToBookings)(rawList);
867
+ this.logInfo("fetchBookingListFromAPI: API 返回并拆分完成", {
868
+ rawCount: rawList.length,
869
+ flattenedCount: list.length
870
+ });
871
+ return {
872
+ code: 200,
873
+ data: { ...response.data, list },
874
+ message: "",
875
+ status: true
876
+ };
877
+ } catch (error) {
878
+ const errorMessage = error instanceof Error ? error.message : String(error);
879
+ this.logError("fetchBookingListFromAPI: 请求失败", { error: errorMessage });
880
+ return {
881
+ code: 500,
882
+ message: errorMessage,
883
+ data: { list: [], count: 0 },
884
+ status: false
885
+ };
886
+ }
887
+ }
888
+ /**
889
+ * 订单列表本地计算(编排 Order 模块)
890
+ * filter 逻辑暂为 mock,仅记录参数
891
+ */
892
+ async computeOrderQueryResult(data) {
893
+ this.logInfo("computeOrderQueryResult: 开始过滤", { data });
894
+ console.log("[Server] computeOrderQueryResult", data);
895
+ if (!this.order) {
896
+ this.logError("computeOrderQueryResult: Order 模块未注册");
897
+ return {
898
+ code: 500,
899
+ message: "Order 模块未注册",
900
+ data: { list: [], count: 0 },
901
+ status: false
902
+ };
903
+ }
904
+ const rawList = this.order.getOrders();
905
+ this.logInfo("computeOrderQueryResult: 本地订单数量", { rawCount: rawList.length });
906
+ const result = (0, import_filterOrders.filterOrders)(rawList, data);
907
+ this.logInfo("computeOrderQueryResult: 过滤结果", {
908
+ rawCount: rawList.length,
909
+ filteredCount: result.count,
910
+ size: result.size,
911
+ skip: result.skip
912
+ });
913
+ return {
914
+ code: 200,
915
+ data: result,
916
+ message: "",
917
+ status: true
918
+ };
919
+ }
920
+ /**
921
+ * 预约列表本地计算(编排 Order 模块)
922
+ * 从订单中展开 bookings,再按条件筛选 + 分页
923
+ */
924
+ async computeBookingQueryResult(data) {
925
+ if (!this.order) {
926
+ this.logError("computeBookingQueryResult: Order 模块未注册");
927
+ return {
928
+ code: 500,
929
+ message: "Order 模块未注册",
930
+ data: { list: [], count: 0 },
931
+ status: false
932
+ };
933
+ }
934
+ const rawOrders = this.order.getOrders();
935
+ let result = (0, import_filterBookings.filterBookingsFromOrders)(rawOrders, data);
936
+ result = (0, import_filterBookings.sortBookings)(result, data);
937
+ this.logInfo("computeBookingQueryResult: 过滤结果", {
938
+ orderCount: rawOrders.length,
939
+ filteredCount: result.count,
940
+ size: result.size,
941
+ skip: result.skip
942
+ });
943
+ return {
944
+ code: 200,
945
+ data: result,
946
+ message: "",
947
+ status: true
948
+ };
949
+ }
656
950
  /**
657
951
  * 商品查询的核心计算逻辑(编排 Products、Menu、Schedule 模块)
658
952
  * 供 handleProductQuery 首次返回及 pubsub 变更推送复用
659
- * @param context 查询上下文
660
- * @param options 可选参数
661
- * @param options.changedIds 变更的商品 IDs,用于增量更新价格缓存
662
953
  */
663
- async computeProductQueryResult(context, options) {
954
+ async computeProductQueryResult(context) {
664
955
  const tTotal = performance.now();
665
956
  const { menu_list_ids, schedule_date, schedule_datetime } = context;
666
957
  this.logInfo("computeProductQueryResult 开始", {
667
958
  menuListIdsCount: (menu_list_ids == null ? void 0 : menu_list_ids.length) ?? 0,
668
959
  schedule_datetime,
669
- schedule_date,
670
- changedIds: options == null ? void 0 : options.changedIds
960
+ schedule_date
671
961
  });
672
962
  if (!this.products) {
673
963
  this.logError("computeProductQueryResult: Products 模块未注册");
@@ -697,8 +987,6 @@ var Server = class {
697
987
  const tPrice = performance.now();
698
988
  const allProductsWithPrice = await this.products.getProductsWithPrice(schedule_date, {
699
989
  scheduleModule: this.getSchedule()
700
- }, {
701
- changedIds: options == null ? void 0 : options.changedIds
702
990
  });
703
991
  (0, import_product.perfMark)("computeQuery.getProductsWithPrice", performance.now() - tPrice, {
704
992
  count: allProductsWithPrice.length
@@ -709,13 +997,6 @@ var Server = class {
709
997
  before: allProductsWithPrice.length,
710
998
  after: filteredProducts.length
711
999
  });
712
- const tStatus = performance.now();
713
- const beforeStatusCount = filteredProducts.length;
714
- filteredProducts = filteredProducts.filter((p) => ((p == null ? void 0 : p.status) || "published") === "published");
715
- (0, import_product.perfMark)("computeQuery.filterByStatus", performance.now() - tStatus, {
716
- before: beforeStatusCount,
717
- after: filteredProducts.length
718
- });
719
1000
  const tSort = performance.now();
720
1001
  filteredProducts = filteredProducts.sort((a, b) => {
721
1002
  const sortDiff = Number(b.sort) - Number(a.sort);
@@ -744,21 +1025,16 @@ var Server = class {
744
1025
  /**
745
1026
  * 数据变更后,遍历所有订阅者重新计算查询结果并通过 callback 推送
746
1027
  * 由 ProductsModule 的 onProductsSyncCompleted 事件触发
747
- * @param options 可选参数
748
- * @param options.changedIds 变更的商品 IDs,用于增量更新价格缓存
749
1028
  */
750
- async recomputeAndNotifyProductQuery(options) {
1029
+ async recomputeAndNotifyProductQuery() {
751
1030
  if (this.productQuerySubscribers.size === 0)
752
1031
  return;
753
1032
  this.logInfo("recomputeAndNotifyProductQuery: 开始推送", {
754
- subscriberCount: this.productQuerySubscribers.size,
755
- changedIds: options == null ? void 0 : options.changedIds
1033
+ subscriberCount: this.productQuerySubscribers.size
756
1034
  });
757
1035
  for (const [subscriberId, subscriber] of this.productQuerySubscribers.entries()) {
758
1036
  try {
759
- const result = await this.computeProductQueryResult(subscriber.context, {
760
- changedIds: options == null ? void 0 : options.changedIds
761
- });
1037
+ const result = await this.computeProductQueryResult(subscriber.context);
762
1038
  subscriber.callback(result);
763
1039
  this.logInfo("recomputeAndNotifyProductQuery: 已推送", { subscriberId });
764
1040
  } catch (error) {
@@ -770,6 +1046,52 @@ var Server = class {
770
1046
  }
771
1047
  }
772
1048
  }
1049
+ /**
1050
+ * 订单数据变更后,遍历订阅者重新计算并通过 callback 推送
1051
+ */
1052
+ async recomputeAndNotifyOrderQuery() {
1053
+ if (this.orderQuerySubscribers.size === 0)
1054
+ return;
1055
+ this.logInfo("recomputeAndNotifyOrderQuery: 开始推送", {
1056
+ subscriberCount: this.orderQuerySubscribers.size
1057
+ });
1058
+ for (const [subscriberId, subscriber] of this.orderQuerySubscribers.entries()) {
1059
+ try {
1060
+ const result = await this.computeOrderQueryResult(subscriber.context);
1061
+ subscriber.callback(result);
1062
+ this.logInfo("recomputeAndNotifyOrderQuery: 已推送", { subscriberId });
1063
+ } catch (error) {
1064
+ const errorMessage = error instanceof Error ? error.message : String(error);
1065
+ this.logError("recomputeAndNotifyOrderQuery: 推送失败", {
1066
+ subscriberId,
1067
+ error: errorMessage
1068
+ });
1069
+ }
1070
+ }
1071
+ }
1072
+ /**
1073
+ * 预约数据变更后,遍历订阅者重新计算并通过 callback 推送
1074
+ */
1075
+ async recomputeAndNotifyBookingQuery() {
1076
+ if (this.bookingQuerySubscribers.size === 0)
1077
+ return;
1078
+ this.logInfo("recomputeAndNotifyBookingQuery: 开始推送", {
1079
+ subscriberCount: this.bookingQuerySubscribers.size
1080
+ });
1081
+ for (const [subscriberId, subscriber] of this.bookingQuerySubscribers.entries()) {
1082
+ try {
1083
+ const result = await this.computeBookingQueryResult(subscriber.context);
1084
+ subscriber.callback(result);
1085
+ this.logInfo("recomputeAndNotifyBookingQuery: 已推送", { subscriberId });
1086
+ } catch (error) {
1087
+ const errorMessage = error instanceof Error ? error.message : String(error);
1088
+ this.logError("recomputeAndNotifyBookingQuery: 推送失败", {
1089
+ subscriberId,
1090
+ error: errorMessage
1091
+ });
1092
+ }
1093
+ }
1094
+ }
773
1095
  /**
774
1096
  * 根据餐牌配置过滤商品
775
1097
  * @param products 所有商品列表
@@ -13,4 +13,10 @@ export type { QuotationState, QuotationData, QuotationProductPrice } from './quo
13
13
  export { QuotationHooks } from './quotation/types';
14
14
  export { ScheduleModuleEx } from './schedule';
15
15
  export type { ScheduleState, ScheduleItem } from './schedule/types';
16
+ export { OrderModule } from './order';
17
+ export type { OrderState, OrderData, OrderId, OrderSummary, OrderBookingItem, OrderProductLineItem, OrderPaymentItem, OrderSurchargeItem, OrderProductDiscountItem, OrderWithoutBookings, BookingData, OrderFilters, BookingFilters, OrderFilterResult, BookingFilterResult, OrderModulePagedResult, } from './order/types';
18
+ export { OrderHooks } from './order/types';
19
+ export { ResourceModule, resourceModule } from './resource';
20
+ export type { ResourceState, ResourceData, ResourceId, ResourceBooking, ResourcePageQuery, ResourcePageResult, QueryOptions, ScheduleEventResource, } from './resource';
21
+ export { ResourceHooks } from './resource';
16
22
  export type { RouteHandler, HttpMethod, RouteDefinition, Router, ModuleRegistryConfig, } from '../types';
@@ -21,11 +21,16 @@ var modules_exports = {};
21
21
  __export(modules_exports, {
22
22
  MenuHooks: () => import_types2.MenuHooks,
23
23
  MenuModule: () => import_menu.MenuModule,
24
+ OrderHooks: () => import_types4.OrderHooks,
25
+ OrderModule: () => import_order.OrderModule,
24
26
  ProductsHooks: () => import_types.ProductsHooks,
25
27
  ProductsModule: () => import_products.ProductsModule,
26
28
  QuotationHooks: () => import_types3.QuotationHooks,
27
29
  QuotationModule: () => import_quotation.QuotationModule,
28
- ScheduleModuleEx: () => import_schedule.ScheduleModuleEx
30
+ ResourceHooks: () => import_resource2.ResourceHooks,
31
+ ResourceModule: () => import_resource.ResourceModule,
32
+ ScheduleModuleEx: () => import_schedule.ScheduleModuleEx,
33
+ resourceModule: () => import_resource.resourceModule
29
34
  });
30
35
  module.exports = __toCommonJS(modules_exports);
31
36
  var import_products = require("./products");
@@ -35,13 +40,22 @@ var import_types2 = require("./menu/types");
35
40
  var import_quotation = require("./quotation");
36
41
  var import_types3 = require("./quotation/types");
37
42
  var import_schedule = require("./schedule");
43
+ var import_order = require("./order");
44
+ var import_types4 = require("./order/types");
45
+ var import_resource = require("./resource");
46
+ var import_resource2 = require("./resource");
38
47
  // Annotate the CommonJS export names for ESM import in node:
39
48
  0 && (module.exports = {
40
49
  MenuHooks,
41
50
  MenuModule,
51
+ OrderHooks,
52
+ OrderModule,
42
53
  ProductsHooks,
43
54
  ProductsModule,
44
55
  QuotationHooks,
45
56
  QuotationModule,
46
- ScheduleModuleEx
57
+ ResourceHooks,
58
+ ResourceModule,
59
+ ScheduleModuleEx,
60
+ resourceModule
47
61
  });