@pisell/pisellos 0.0.480 → 0.0.481
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.
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.js +7 -0
- package/dist/effects/index.d.ts +2 -2
- package/dist/effects/index.js +34 -81
- package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
- package/dist/model/strategy/adapter/walletPass/type.d.ts +9 -2
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +6 -6
- package/dist/model/strategy/adapter/walletPass/utils.js +104 -77
- package/dist/modules/Customer/index.js +1 -1
- package/dist/modules/Discount/index.d.ts +6 -2
- package/dist/modules/Discount/index.js +14 -8
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/index.js +18 -13
- package/dist/modules/Payment/index.d.ts +4 -0
- package/dist/modules/Payment/index.js +774 -649
- package/dist/modules/Payment/walletpass.js +44 -17
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Product/types.d.ts +2 -0
- package/dist/modules/ProductList/index.d.ts +3 -0
- package/dist/modules/ProductList/index.js +9 -7
- package/dist/modules/Rules/index.d.ts +2 -2
- package/dist/modules/Rules/index.js +37 -31
- package/dist/modules/Rules/types.d.ts +2 -2
- package/dist/modules/Schedule/index.d.ts +9 -0
- package/dist/modules/Schedule/index.js +15 -2
- package/dist/plugins/app-types/app/app.d.ts +1 -0
- package/dist/plugins/request.d.ts +2 -0
- package/dist/server/index.d.ts +107 -2
- package/dist/server/index.js +1507 -279
- package/dist/server/modules/index.d.ts +6 -0
- package/dist/server/modules/index.js +7 -0
- package/dist/server/modules/menu/index.d.ts +19 -0
- package/dist/server/modules/menu/index.js +221 -71
- package/dist/server/modules/order/index.d.ts +87 -0
- package/dist/server/modules/order/index.js +916 -0
- package/dist/server/modules/order/types.d.ts +530 -0
- package/dist/server/modules/order/types.js +141 -0
- package/dist/server/modules/order/utils/filterBookings.d.ts +6 -0
- package/dist/server/modules/order/utils/filterBookings.js +350 -0
- package/dist/server/modules/order/utils/filterOrders.d.ts +15 -0
- package/dist/server/modules/order/utils/filterOrders.js +226 -0
- package/dist/server/modules/products/index.d.ts +117 -5
- package/dist/server/modules/products/index.js +1450 -240
- package/dist/server/modules/products/types.d.ts +25 -1
- package/dist/server/modules/products/types.js +3 -0
- package/dist/server/modules/resource/index.d.ts +86 -0
- package/dist/server/modules/resource/index.js +1128 -0
- package/dist/server/modules/resource/types.d.ts +121 -0
- package/dist/server/modules/resource/types.js +47 -0
- package/dist/server/modules/schedule/index.d.ts +19 -0
- package/dist/server/modules/schedule/index.js +229 -68
- package/dist/server/utils/product.d.ts +5 -0
- package/dist/server/utils/product.js +71 -31
- package/dist/solution/BookingTicket/index.d.ts +10 -2
- package/dist/solution/BookingTicket/index.js +41 -28
- package/dist/solution/BookingTicket/utils/scan/index.js +1 -1
- package/dist/solution/Checkout/index.d.ts +1 -0
- package/dist/solution/Checkout/index.js +286 -188
- package/dist/solution/Checkout/utils/index.d.ts +2 -1
- package/dist/solution/Checkout/utils/index.js +6 -4
- package/dist/solution/RegisterAndLogin/config.js +340 -1
- package/dist/solution/Sales/index.d.ts +96 -0
- package/dist/solution/Sales/index.js +566 -0
- package/dist/solution/Sales/types.d.ts +67 -0
- package/dist/solution/Sales/types.js +26 -0
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +35 -22
- package/dist/solution/ShopDiscount/types.d.ts +6 -0
- package/dist/solution/ShopDiscount/utils.d.ts +9 -0
- package/dist/solution/ShopDiscount/utils.js +21 -27
- package/dist/solution/index.d.ts +2 -1
- package/dist/solution/index.js +2 -1
- package/dist/types/index.d.ts +5 -0
- package/lib/core/index.d.ts +3 -2
- package/lib/core/index.js +4 -0
- package/lib/effects/index.d.ts +2 -2
- package/lib/effects/index.js +22 -31
- package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
- package/lib/model/strategy/adapter/walletPass/type.d.ts +9 -2
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +6 -6
- package/lib/model/strategy/adapter/walletPass/utils.js +113 -49
- package/lib/modules/Customer/index.js +1 -1
- package/lib/modules/Discount/index.d.ts +6 -2
- package/lib/modules/Discount/index.js +3 -1
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/index.js +20 -18
- package/lib/modules/Payment/index.d.ts +4 -0
- package/lib/modules/Payment/index.js +134 -66
- package/lib/modules/Payment/walletpass.js +23 -4
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/types.d.ts +2 -0
- package/lib/modules/ProductList/index.d.ts +3 -0
- package/lib/modules/ProductList/index.js +2 -2
- package/lib/modules/Rules/index.d.ts +2 -2
- package/lib/modules/Rules/index.js +69 -73
- package/lib/modules/Rules/types.d.ts +2 -2
- package/lib/modules/Schedule/index.d.ts +9 -0
- package/lib/modules/Schedule/index.js +11 -0
- package/lib/plugins/app-types/app/app.d.ts +1 -0
- package/lib/plugins/request.d.ts +2 -0
- package/lib/server/index.d.ts +107 -2
- package/lib/server/index.js +773 -51
- package/lib/server/modules/index.d.ts +6 -0
- package/lib/server/modules/index.js +16 -2
- package/lib/server/modules/menu/index.d.ts +19 -0
- package/lib/server/modules/menu/index.js +121 -2
- package/lib/server/modules/order/index.d.ts +87 -0
- package/lib/server/modules/order/index.js +543 -0
- package/lib/server/modules/order/types.d.ts +530 -0
- package/lib/server/modules/order/types.js +34 -0
- package/lib/server/modules/order/utils/filterBookings.d.ts +6 -0
- package/lib/server/modules/order/utils/filterBookings.js +320 -0
- package/lib/server/modules/order/utils/filterOrders.d.ts +15 -0
- package/lib/server/modules/order/utils/filterOrders.js +197 -0
- package/lib/server/modules/products/index.d.ts +117 -5
- package/lib/server/modules/products/index.js +799 -62
- package/lib/server/modules/products/types.d.ts +25 -1
- package/lib/server/modules/products/types.js +1 -0
- package/lib/server/modules/resource/index.d.ts +86 -0
- package/lib/server/modules/resource/index.js +557 -0
- package/lib/server/modules/resource/types.d.ts +121 -0
- package/lib/server/modules/resource/types.js +35 -0
- package/lib/server/modules/schedule/index.d.ts +19 -0
- package/lib/server/modules/schedule/index.js +141 -12
- package/lib/server/utils/product.d.ts +5 -0
- package/lib/server/utils/product.js +56 -27
- package/lib/solution/BookingTicket/index.d.ts +10 -2
- package/lib/solution/BookingTicket/index.js +10 -2
- package/lib/solution/BookingTicket/utils/scan/index.js +0 -1
- package/lib/solution/Checkout/index.d.ts +1 -0
- package/lib/solution/Checkout/index.js +399 -331
- package/lib/solution/Checkout/utils/index.d.ts +2 -1
- package/lib/solution/Checkout/utils/index.js +6 -4
- package/lib/solution/RegisterAndLogin/config.js +266 -1
- package/lib/solution/Sales/index.d.ts +96 -0
- package/lib/solution/Sales/index.js +416 -0
- package/lib/solution/Sales/types.d.ts +67 -0
- package/lib/solution/Sales/types.js +35 -0
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +14 -6
- package/lib/solution/ShopDiscount/types.d.ts +6 -0
- package/lib/solution/ShopDiscount/utils.d.ts +9 -0
- package/lib/solution/ShopDiscount/utils.js +6 -10
- package/lib/solution/index.d.ts +2 -1
- package/lib/solution/index.js +4 -2
- package/lib/types/index.d.ts +5 -0
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -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; }
|
|
@@ -13,27 +17,48 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
13
17
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
18
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
15
19
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
|
+
import dayjs from 'dayjs';
|
|
16
21
|
import { ProductsModule } from "./modules/products";
|
|
17
22
|
import { MenuModule } from "./modules/menu";
|
|
18
23
|
import { QuotationModule } from "./modules/quotation";
|
|
19
24
|
import { ScheduleModuleEx } from "./modules/schedule";
|
|
25
|
+
import { ResourceModule } from "./modules/resource";
|
|
20
26
|
import { extractScheduleIdsFromMenus, extractTimePointsFromSchedules } from "./utils/schedule";
|
|
27
|
+
import { ProductsHooks } from "./modules/products/types";
|
|
28
|
+
import { perfMark } from "./utils/product";
|
|
29
|
+
import { OrderModule } from "./modules/order";
|
|
30
|
+
import { OrderHooks } from "./modules/order/types";
|
|
31
|
+
import { filterOrders } from "./modules/order/utils/filterOrders";
|
|
32
|
+
import { filterBookingsFromOrders, sortBookings } from "./modules/order/utils/filterBookings";
|
|
21
33
|
|
|
22
34
|
// 重新导出类型供外部使用
|
|
35
|
+
|
|
36
|
+
/** 商品查询订阅者 */
|
|
37
|
+
|
|
38
|
+
/** 订单列表查询订阅者 */
|
|
39
|
+
|
|
40
|
+
/** 预约列表查询订阅者 */
|
|
23
41
|
/**
|
|
24
42
|
* Server 类
|
|
25
43
|
* 用于注册和管理服务端模块
|
|
26
44
|
*/
|
|
27
45
|
var Server = /*#__PURE__*/function () {
|
|
28
46
|
function Server(core) {
|
|
29
|
-
var _this = this
|
|
47
|
+
var _this = this,
|
|
48
|
+
_this$app;
|
|
30
49
|
_classCallCheck(this, Server);
|
|
31
50
|
_defineProperty(this, "core", void 0);
|
|
51
|
+
_defineProperty(this, "app", void 0);
|
|
52
|
+
// App instance
|
|
53
|
+
_defineProperty(this, "logger", void 0);
|
|
54
|
+
// LoggerManager instance
|
|
32
55
|
// 模块实例
|
|
33
56
|
_defineProperty(this, "products", void 0);
|
|
34
57
|
_defineProperty(this, "menu", void 0);
|
|
35
58
|
_defineProperty(this, "quotation", void 0);
|
|
36
59
|
_defineProperty(this, "schedule", void 0);
|
|
60
|
+
_defineProperty(this, "resource", void 0);
|
|
61
|
+
_defineProperty(this, "order", void 0);
|
|
37
62
|
// 路由注册表
|
|
38
63
|
_defineProperty(this, "router", {
|
|
39
64
|
get: {},
|
|
@@ -41,6 +66,11 @@ var Server = /*#__PURE__*/function () {
|
|
|
41
66
|
put: {},
|
|
42
67
|
remove: {}
|
|
43
68
|
});
|
|
69
|
+
// ---- 商品查询订阅者 ----
|
|
70
|
+
_defineProperty(this, "productQuerySubscribers", new Map());
|
|
71
|
+
// ---- 订单 / 预约列表查询订阅者 ----
|
|
72
|
+
_defineProperty(this, "orderQuerySubscribers", new Map());
|
|
73
|
+
_defineProperty(this, "bookingQuerySubscribers", new Map());
|
|
44
74
|
// 模块注册表 - 定义所有可用的模块配置
|
|
45
75
|
_defineProperty(this, "moduleRegistry", {
|
|
46
76
|
products: {
|
|
@@ -81,116 +111,296 @@ var Server = /*#__PURE__*/function () {
|
|
|
81
111
|
availabilityDateList: [],
|
|
82
112
|
otherProductsIds: []
|
|
83
113
|
}
|
|
114
|
+
},
|
|
115
|
+
order: {
|
|
116
|
+
name: 'order',
|
|
117
|
+
moduleClass: OrderModule,
|
|
118
|
+
moduleName: 'server_order',
|
|
119
|
+
version: '1.0.0',
|
|
120
|
+
defaultStore: {
|
|
121
|
+
list: []
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
resource: {
|
|
125
|
+
name: 'resource',
|
|
126
|
+
moduleClass: ResourceModule,
|
|
127
|
+
moduleName: 'server_resource',
|
|
128
|
+
version: '1.0.0',
|
|
129
|
+
defaultStore: {
|
|
130
|
+
list: [],
|
|
131
|
+
map: new Map(),
|
|
132
|
+
bookings: []
|
|
133
|
+
}
|
|
84
134
|
}
|
|
85
135
|
});
|
|
86
136
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
137
|
+
* 处理商品查询请求
|
|
138
|
+
* 存储订阅者信息,便于数据变更时推送最新结果
|
|
89
139
|
*/
|
|
90
140
|
_defineProperty(this, "handleProductQuery", /*#__PURE__*/function () {
|
|
91
141
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
92
|
-
var url, method, data, config, menu_list_ids, schedule_datetime, schedule_date,
|
|
142
|
+
var url, method, data, config, menu_list_ids, schedule_datetime, schedule_date, _ref3, callback, subscriberId;
|
|
93
143
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
94
144
|
while (1) switch (_context.prev = _context.next) {
|
|
95
145
|
case 0:
|
|
96
146
|
url = _ref.url, method = _ref.method, data = _ref.data, config = _ref.config;
|
|
97
147
|
console.log('[Server] handleProductQuery:', url, method, data, config);
|
|
98
|
-
menu_list_ids = data.menu_list_ids, schedule_datetime = data.schedule_datetime, schedule_date = data.schedule_date;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
148
|
+
menu_list_ids = data.menu_list_ids, schedule_datetime = data.schedule_datetime, schedule_date = data.schedule_date;
|
|
149
|
+
_ref3 = config || {}, callback = _ref3.callback, subscriberId = _ref3.subscriberId;
|
|
150
|
+
_this.logInfo('handleProductQuery: 开始处理商品查询请求', {
|
|
151
|
+
menu_list_ids: menu_list_ids,
|
|
152
|
+
schedule_datetime: schedule_datetime,
|
|
153
|
+
schedule_date: schedule_date
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// 存储订阅者:后续 pubsub 数据变更时可通过 callback 推送最新结果
|
|
157
|
+
if (subscriberId && typeof callback === 'function') {
|
|
158
|
+
_this.productQuerySubscribers.set(subscriberId, {
|
|
159
|
+
callback: callback,
|
|
160
|
+
context: {
|
|
161
|
+
menu_list_ids: menu_list_ids,
|
|
162
|
+
schedule_date: schedule_date,
|
|
163
|
+
schedule_datetime: schedule_datetime
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
_this.logInfo('handleProductQuery: 已注册订阅者', {
|
|
167
|
+
subscriberId: subscriberId,
|
|
168
|
+
totalSubscribers: _this.productQuerySubscribers.size
|
|
169
|
+
});
|
|
102
170
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
171
|
+
return _context.abrupt("return", _this.computeProductQueryResult({
|
|
172
|
+
menu_list_ids: menu_list_ids,
|
|
173
|
+
schedule_date: schedule_date,
|
|
174
|
+
schedule_datetime: schedule_datetime
|
|
175
|
+
}));
|
|
176
|
+
case 7:
|
|
177
|
+
case "end":
|
|
178
|
+
return _context.stop();
|
|
179
|
+
}
|
|
180
|
+
}, _callee);
|
|
181
|
+
}));
|
|
182
|
+
return function (_x) {
|
|
183
|
+
return _ref2.apply(this, arguments);
|
|
184
|
+
};
|
|
185
|
+
}());
|
|
186
|
+
/**
|
|
187
|
+
* 取消商品查询订阅(HTTP 路由入口)
|
|
188
|
+
*/
|
|
189
|
+
_defineProperty(this, "handleUnsubscribeProductQuery", /*#__PURE__*/function () {
|
|
190
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref4) {
|
|
191
|
+
var data, _ref6, subscriberId;
|
|
192
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
193
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
194
|
+
case 0:
|
|
195
|
+
data = _ref4.data;
|
|
196
|
+
_ref6 = data || {}, subscriberId = _ref6.subscriberId;
|
|
197
|
+
_this.removeProductQuerySubscriber(subscriberId);
|
|
198
|
+
return _context2.abrupt("return", {
|
|
199
|
+
code: 200,
|
|
200
|
+
message: 'ok',
|
|
201
|
+
status: true
|
|
110
202
|
});
|
|
111
|
-
case
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
203
|
+
case 4:
|
|
204
|
+
case "end":
|
|
205
|
+
return _context2.stop();
|
|
206
|
+
}
|
|
207
|
+
}, _callee2);
|
|
208
|
+
}));
|
|
209
|
+
return function (_x2) {
|
|
210
|
+
return _ref5.apply(this, arguments);
|
|
211
|
+
};
|
|
212
|
+
}());
|
|
213
|
+
/**
|
|
214
|
+
* 处理订单列表查询
|
|
215
|
+
* 存储订阅者信息,本地计算结果;数据变更时通过 callback 推送
|
|
216
|
+
*/
|
|
217
|
+
_defineProperty(this, "handleOrderList", /*#__PURE__*/function () {
|
|
218
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref7) {
|
|
219
|
+
var url, method, data, config, queryPayload, _ref9, callback, subscriberId;
|
|
220
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
221
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
222
|
+
case 0:
|
|
223
|
+
url = _ref7.url, method = _ref7.method, data = _ref7.data, config = _ref7.config;
|
|
224
|
+
console.log('[Server] handleOrderList:', url, method, data, config);
|
|
225
|
+
queryPayload = data && _typeof(data) === 'object' ? _objectSpread({}, data) : {};
|
|
226
|
+
_ref9 = config || {}, callback = _ref9.callback, subscriberId = _ref9.subscriberId;
|
|
227
|
+
_this.logInfo('handleOrderList: 开始处理订单列表请求', {
|
|
228
|
+
data: queryPayload
|
|
229
|
+
});
|
|
230
|
+
if (subscriberId && typeof callback === 'function') {
|
|
231
|
+
_this.orderQuerySubscribers.set(subscriberId, {
|
|
232
|
+
callback: callback,
|
|
233
|
+
context: queryPayload
|
|
234
|
+
});
|
|
235
|
+
_this.logInfo('handleOrderList: 已注册订阅者', {
|
|
236
|
+
subscriberId: subscriberId,
|
|
237
|
+
totalSubscribers: _this.orderQuerySubscribers.size
|
|
238
|
+
});
|
|
115
239
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
240
|
+
return _context3.abrupt("return", _this.computeOrderQueryResult(queryPayload));
|
|
241
|
+
case 7:
|
|
242
|
+
case "end":
|
|
243
|
+
return _context3.stop();
|
|
244
|
+
}
|
|
245
|
+
}, _callee3);
|
|
246
|
+
}));
|
|
247
|
+
return function (_x3) {
|
|
248
|
+
return _ref8.apply(this, arguments);
|
|
249
|
+
};
|
|
250
|
+
}());
|
|
251
|
+
/**
|
|
252
|
+
* 取消订单列表查询订阅(HTTP 路由入口)
|
|
253
|
+
*/
|
|
254
|
+
_defineProperty(this, "handleUnsubscribeOrderQuery", /*#__PURE__*/function () {
|
|
255
|
+
var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref10) {
|
|
256
|
+
var data, _ref12, subscriberId;
|
|
257
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
258
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
259
|
+
case 0:
|
|
260
|
+
data = _ref10.data;
|
|
261
|
+
_ref12 = data || {}, subscriberId = _ref12.subscriberId;
|
|
262
|
+
if (subscriberId) {
|
|
263
|
+
_this.orderQuerySubscribers.delete(subscriberId);
|
|
264
|
+
_this.logInfo('handleUnsubscribeOrderQuery: 已移除订阅者', {
|
|
265
|
+
subscriberId: subscriberId,
|
|
266
|
+
remaining: _this.orderQuerySubscribers.size
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return _context4.abrupt("return", {
|
|
270
|
+
code: 200,
|
|
271
|
+
message: 'ok',
|
|
272
|
+
status: true
|
|
123
273
|
});
|
|
124
|
-
case
|
|
125
|
-
|
|
126
|
-
|
|
274
|
+
case 4:
|
|
275
|
+
case "end":
|
|
276
|
+
return _context4.stop();
|
|
277
|
+
}
|
|
278
|
+
}, _callee4);
|
|
279
|
+
}));
|
|
280
|
+
return function (_x4) {
|
|
281
|
+
return _ref11.apply(this, arguments);
|
|
282
|
+
};
|
|
283
|
+
}());
|
|
284
|
+
/**
|
|
285
|
+
* 处理预约列表查询
|
|
286
|
+
* 今天:注册订阅者 + 本地数据筛选;非今天:清理订阅者 + 走真实 API
|
|
287
|
+
*/
|
|
288
|
+
_defineProperty(this, "handleBookingList", /*#__PURE__*/function () {
|
|
289
|
+
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref13) {
|
|
290
|
+
var url, method, data, config, queryPayload, _ref15, callback, subscriberId, isToday;
|
|
291
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
292
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
293
|
+
case 0:
|
|
294
|
+
url = _ref13.url, method = _ref13.method, data = _ref13.data, config = _ref13.config;
|
|
295
|
+
console.log('[Server] handleBookingList:', url, method, data, config);
|
|
296
|
+
queryPayload = data && _typeof(data) === 'object' ? _objectSpread({}, data) : {};
|
|
297
|
+
_ref15 = config || {}, callback = _ref15.callback, subscriberId = _ref15.subscriberId;
|
|
298
|
+
isToday = _this.isBookingQueryForToday(queryPayload);
|
|
299
|
+
_this.logInfo('handleBookingList: 开始处理预约列表请求', {
|
|
300
|
+
data: queryPayload,
|
|
301
|
+
isToday: isToday
|
|
302
|
+
});
|
|
303
|
+
if (!isToday) {
|
|
304
|
+
_context5.next = 11;
|
|
127
305
|
break;
|
|
128
306
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
case 12:
|
|
138
|
-
// 生效的餐牌列表
|
|
139
|
-
activeMenuList = []; // 如果有 menu_list_ids,获取对应的餐牌详情
|
|
140
|
-
if (menu_list_ids && Array.isArray(menu_list_ids) && menu_list_ids.length > 0) {
|
|
141
|
-
console.log('[Server] 获取餐牌详情,IDs:', menu_list_ids);
|
|
142
|
-
|
|
143
|
-
// 从 Menu 模块获取餐牌详情
|
|
144
|
-
menuList = _this.menu.getMenuByIds(menu_list_ids);
|
|
145
|
-
activeMenuList = menuList.filter(function (menu) {
|
|
146
|
-
var _this$schedule;
|
|
147
|
-
return ((_this$schedule = _this.schedule) === null || _this$schedule === void 0 ? void 0 : _this$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
|
|
307
|
+
if (subscriberId && typeof callback === 'function') {
|
|
308
|
+
_this.bookingQuerySubscribers.set(subscriberId, {
|
|
309
|
+
callback: callback,
|
|
310
|
+
context: queryPayload
|
|
311
|
+
});
|
|
312
|
+
_this.logInfo('handleBookingList: 已注册订阅者(今天)', {
|
|
313
|
+
subscriberId: subscriberId,
|
|
314
|
+
totalSubscribers: _this.bookingQuerySubscribers.size
|
|
148
315
|
});
|
|
149
316
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
317
|
+
return _context5.abrupt("return", _this.computeBookingQueryResult(queryPayload));
|
|
318
|
+
case 11:
|
|
319
|
+
if (subscriberId) {
|
|
320
|
+
_this.bookingQuerySubscribers.delete(subscriberId);
|
|
321
|
+
_this.logInfo('handleBookingList: 已清理订阅者(非今天)', {
|
|
322
|
+
subscriberId: subscriberId,
|
|
323
|
+
remaining: _this.bookingQuerySubscribers.size
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
return _context5.abrupt("return", _this.fetchBookingListFromAPI(queryPayload));
|
|
327
|
+
case 13:
|
|
328
|
+
case "end":
|
|
329
|
+
return _context5.stop();
|
|
330
|
+
}
|
|
331
|
+
}, _callee5);
|
|
332
|
+
}));
|
|
333
|
+
return function (_x5) {
|
|
334
|
+
return _ref14.apply(this, arguments);
|
|
335
|
+
};
|
|
336
|
+
}());
|
|
337
|
+
/**
|
|
338
|
+
* 处理资源列表查询
|
|
339
|
+
* 转发到资源模块去
|
|
340
|
+
*/
|
|
341
|
+
_defineProperty(this, "handleResourceList", /*#__PURE__*/function () {
|
|
342
|
+
var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref16) {
|
|
343
|
+
var _this$resource;
|
|
344
|
+
var url, method, data, config, list;
|
|
345
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
346
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
347
|
+
case 0:
|
|
348
|
+
url = _ref16.url, method = _ref16.method, data = _ref16.data, config = _ref16.config;
|
|
349
|
+
console.log('[Server] handleResourceList:', url, method, data, config);
|
|
350
|
+
list = (_this$resource = _this.resource) === null || _this$resource === void 0 ? void 0 : _this$resource.getResources({
|
|
351
|
+
skip: (data === null || data === void 0 ? void 0 : data.skip) || 1,
|
|
352
|
+
num: (data === null || data === void 0 ? void 0 : data.num) || 10
|
|
171
353
|
});
|
|
172
|
-
|
|
173
|
-
console.log('[Server] 过滤后商品数量:', filteredProducts.length);
|
|
174
|
-
console.log(filteredProducts, 'filteredProducts');
|
|
175
|
-
|
|
176
|
-
// 返回组合后的数据
|
|
177
|
-
return _context.abrupt("return", {
|
|
354
|
+
return _context6.abrupt("return", {
|
|
178
355
|
code: 200,
|
|
179
356
|
data: {
|
|
180
|
-
list:
|
|
181
|
-
count:
|
|
357
|
+
list: list,
|
|
358
|
+
count: (list === null || list === void 0 ? void 0 : list.length) || 0
|
|
182
359
|
},
|
|
183
360
|
message: '',
|
|
184
361
|
status: true
|
|
185
362
|
});
|
|
186
|
-
case
|
|
363
|
+
case 4:
|
|
187
364
|
case "end":
|
|
188
|
-
return
|
|
365
|
+
return _context6.stop();
|
|
189
366
|
}
|
|
190
|
-
},
|
|
367
|
+
}, _callee6);
|
|
191
368
|
}));
|
|
192
|
-
return function (
|
|
193
|
-
return
|
|
369
|
+
return function (_x6) {
|
|
370
|
+
return _ref17.apply(this, arguments);
|
|
371
|
+
};
|
|
372
|
+
}());
|
|
373
|
+
/**
|
|
374
|
+
* 取消预约列表查询订阅(HTTP 路由入口)
|
|
375
|
+
*/
|
|
376
|
+
_defineProperty(this, "handleUnsubscribeBookingQuery", /*#__PURE__*/function () {
|
|
377
|
+
var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref18) {
|
|
378
|
+
var data, _ref20, subscriberId;
|
|
379
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
380
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
381
|
+
case 0:
|
|
382
|
+
data = _ref18.data;
|
|
383
|
+
_ref20 = data || {}, subscriberId = _ref20.subscriberId;
|
|
384
|
+
if (subscriberId) {
|
|
385
|
+
_this.bookingQuerySubscribers.delete(subscriberId);
|
|
386
|
+
_this.logInfo('handleUnsubscribeBookingQuery: 已移除订阅者', {
|
|
387
|
+
subscriberId: subscriberId,
|
|
388
|
+
remaining: _this.bookingQuerySubscribers.size
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
return _context7.abrupt("return", {
|
|
392
|
+
code: 200,
|
|
393
|
+
message: 'ok',
|
|
394
|
+
status: true
|
|
395
|
+
});
|
|
396
|
+
case 4:
|
|
397
|
+
case "end":
|
|
398
|
+
return _context7.stop();
|
|
399
|
+
}
|
|
400
|
+
}, _callee7);
|
|
401
|
+
}));
|
|
402
|
+
return function (_x7) {
|
|
403
|
+
return _ref19.apply(this, arguments);
|
|
194
404
|
};
|
|
195
405
|
}());
|
|
196
406
|
/**
|
|
@@ -198,104 +408,151 @@ var Server = /*#__PURE__*/function () {
|
|
|
198
408
|
* 通过餐牌ID列表获取所有相关日程的时间段点
|
|
199
409
|
*/
|
|
200
410
|
_defineProperty(this, "handleGetScheduleTimePoints", /*#__PURE__*/function () {
|
|
201
|
-
var
|
|
202
|
-
var
|
|
203
|
-
|
|
204
|
-
|
|
411
|
+
var _ref22 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref21) {
|
|
412
|
+
var _menu_list_ids$length;
|
|
413
|
+
var url, method, data, config, menu_list_ids, _menu_list_ids$length2, menuList, scheduleIds, scheduleList, timePoints, errorMessage;
|
|
414
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
415
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
205
416
|
case 0:
|
|
206
|
-
url =
|
|
417
|
+
url = _ref21.url, method = _ref21.method, data = _ref21.data, config = _ref21.config;
|
|
207
418
|
console.log('[Server] handleGetScheduleTimePoints:', url, method, data, config);
|
|
208
|
-
menu_list_ids = data.menu_list_ids;
|
|
419
|
+
menu_list_ids = data.menu_list_ids;
|
|
420
|
+
_this.logInfo('handleGetScheduleTimePoints 开始处理', {
|
|
421
|
+
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,
|
|
422
|
+
menu_list_ids: menu_list_ids
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
// 检查必要的模块是否已注册
|
|
209
426
|
if (_this.menu) {
|
|
210
|
-
|
|
427
|
+
_context8.next = 8;
|
|
211
428
|
break;
|
|
212
429
|
}
|
|
213
430
|
console.error('[Server] Menu 模块未注册');
|
|
214
|
-
|
|
431
|
+
_this.logError('handleGetScheduleTimePoints: Menu 模块未注册');
|
|
432
|
+
return _context8.abrupt("return", {
|
|
215
433
|
code: 500,
|
|
216
434
|
message: 'Menu 模块未注册',
|
|
217
435
|
data: [],
|
|
218
436
|
status: false
|
|
219
437
|
});
|
|
220
|
-
case
|
|
438
|
+
case 8:
|
|
221
439
|
if (_this.schedule) {
|
|
222
|
-
|
|
440
|
+
_context8.next = 12;
|
|
223
441
|
break;
|
|
224
442
|
}
|
|
225
443
|
console.error('[Server] Schedule 模块未注册');
|
|
226
|
-
|
|
444
|
+
_this.logError('handleGetScheduleTimePoints: Schedule 模块未注册');
|
|
445
|
+
return _context8.abrupt("return", {
|
|
227
446
|
code: 500,
|
|
228
447
|
message: 'Schedule 模块未注册',
|
|
229
448
|
data: [],
|
|
230
449
|
status: false
|
|
231
450
|
});
|
|
232
|
-
case
|
|
451
|
+
case 12:
|
|
233
452
|
if (!(!menu_list_ids || !Array.isArray(menu_list_ids) || menu_list_ids.length === 0)) {
|
|
234
|
-
|
|
453
|
+
_context8.next = 16;
|
|
235
454
|
break;
|
|
236
455
|
}
|
|
237
456
|
console.error('[Server] menu_list_ids 参数无效');
|
|
238
|
-
|
|
457
|
+
_this.logWarning('handleGetScheduleTimePoints: menu_list_ids 参数无效', {
|
|
458
|
+
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,
|
|
459
|
+
menu_list_ids: menu_list_ids
|
|
460
|
+
});
|
|
461
|
+
return _context8.abrupt("return", {
|
|
239
462
|
code: 400,
|
|
240
463
|
message: 'menu_list_ids 参数无效',
|
|
241
464
|
data: [],
|
|
242
465
|
status: false
|
|
243
466
|
});
|
|
244
|
-
case
|
|
245
|
-
|
|
467
|
+
case 16:
|
|
468
|
+
_context8.prev = 16;
|
|
246
469
|
// 1. 获取餐牌列表
|
|
247
470
|
menuList = _this.menu.getMenuByIds(menu_list_ids);
|
|
248
471
|
console.log("[Server] \u627E\u5230 ".concat(menuList.length, " \u4E2A\u9910\u724C"));
|
|
472
|
+
_this.logInfo('handleGetScheduleTimePoints: 获取到餐牌列表', {
|
|
473
|
+
requestedCount: menu_list_ids.length,
|
|
474
|
+
foundCount: menuList.length,
|
|
475
|
+
menu_list_ids: menu_list_ids,
|
|
476
|
+
menuList: menuList
|
|
477
|
+
});
|
|
249
478
|
|
|
250
479
|
// 2. 提取所有的 schedule IDs
|
|
251
480
|
scheduleIds = extractScheduleIdsFromMenus(menuList);
|
|
252
481
|
console.log("[Server] \u63D0\u53D6\u5230 ".concat(scheduleIds.length, " \u4E2A\u65E5\u7A0BID:"), scheduleIds);
|
|
482
|
+
_this.logInfo('handleGetScheduleTimePoints: 提取到日程 IDs', {
|
|
483
|
+
scheduleCount: scheduleIds.length
|
|
484
|
+
});
|
|
253
485
|
if (!(scheduleIds.length === 0)) {
|
|
254
|
-
|
|
486
|
+
_context8.next = 26;
|
|
255
487
|
break;
|
|
256
488
|
}
|
|
257
|
-
|
|
489
|
+
_this.logInfo('handleGetScheduleTimePoints: 没有找到相关日程', {
|
|
490
|
+
menuListIdsCount: menu_list_ids.length
|
|
491
|
+
});
|
|
492
|
+
return _context8.abrupt("return", {
|
|
258
493
|
code: 200,
|
|
259
494
|
message: '没有找到相关日程',
|
|
260
495
|
data: [],
|
|
261
496
|
status: true
|
|
262
497
|
});
|
|
263
|
-
case
|
|
498
|
+
case 26:
|
|
264
499
|
// 3. 获取日程详情
|
|
265
500
|
scheduleList = _this.schedule.getScheduleByIds(scheduleIds);
|
|
266
501
|
console.log("[Server] \u627E\u5230 ".concat(scheduleList.length, " \u4E2A\u65E5\u7A0B"));
|
|
502
|
+
_this.logInfo('handleGetScheduleTimePoints: 获取到日程详情', {
|
|
503
|
+
requestedCount: scheduleIds.length,
|
|
504
|
+
foundCount: scheduleList.length
|
|
505
|
+
});
|
|
267
506
|
|
|
268
507
|
// 4. 提取时间点
|
|
269
508
|
timePoints = extractTimePointsFromSchedules(scheduleList);
|
|
270
509
|
console.log("[Server] \u63D0\u53D6\u5230 ".concat(timePoints.length, " \u4E2A\u65F6\u95F4\u70B9:"), timePoints);
|
|
271
|
-
|
|
510
|
+
_this.logInfo('handleGetScheduleTimePoints 处理完成', {
|
|
511
|
+
menuListIdsCount: menu_list_ids.length,
|
|
512
|
+
menuCount: menuList.length,
|
|
513
|
+
scheduleCount: scheduleList.length,
|
|
514
|
+
timePointCount: timePoints.length
|
|
515
|
+
});
|
|
516
|
+
return _context8.abrupt("return", {
|
|
272
517
|
code: 200,
|
|
273
518
|
message: '获取成功',
|
|
274
519
|
data: timePoints,
|
|
275
520
|
status: true
|
|
276
521
|
});
|
|
277
|
-
case
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
522
|
+
case 35:
|
|
523
|
+
_context8.prev = 35;
|
|
524
|
+
_context8.t0 = _context8["catch"](16);
|
|
525
|
+
errorMessage = _context8.t0 instanceof Error ? _context8.t0.message : '未知错误';
|
|
526
|
+
console.error('[Server] 获取日程时间点失败:', _context8.t0);
|
|
527
|
+
_this.logError('handleGetScheduleTimePoints: 获取日程时间点失败', {
|
|
528
|
+
menuListIdsCount: menu_list_ids.length,
|
|
529
|
+
error: errorMessage
|
|
530
|
+
});
|
|
531
|
+
return _context8.abrupt("return", {
|
|
282
532
|
code: 500,
|
|
283
|
-
message: "\u83B7\u53D6\u5931\u8D25: ".concat(
|
|
533
|
+
message: "\u83B7\u53D6\u5931\u8D25: ".concat(errorMessage),
|
|
284
534
|
data: [],
|
|
285
535
|
status: false
|
|
286
536
|
});
|
|
287
|
-
case
|
|
537
|
+
case 41:
|
|
288
538
|
case "end":
|
|
289
|
-
return
|
|
539
|
+
return _context8.stop();
|
|
290
540
|
}
|
|
291
|
-
},
|
|
541
|
+
}, _callee8, null, [[16, 35]]);
|
|
292
542
|
}));
|
|
293
|
-
return function (
|
|
294
|
-
return
|
|
543
|
+
return function (_x8) {
|
|
544
|
+
return _ref22.apply(this, arguments);
|
|
295
545
|
};
|
|
296
546
|
}());
|
|
297
547
|
this.core = core;
|
|
298
|
-
|
|
548
|
+
var appPlugin = core.getPlugin('app');
|
|
549
|
+
this.app = (appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp()) || null;
|
|
550
|
+
this.logger = ((_this$app = this.app) === null || _this$app === void 0 ? void 0 : _this$app.logger) || null;
|
|
551
|
+
console.log('[Server] Server 初始化', this.core);
|
|
552
|
+
this.logInfo('Server 初始化', {
|
|
553
|
+
hasApp: !!this.app,
|
|
554
|
+
hasLogger: !!this.logger
|
|
555
|
+
});
|
|
299
556
|
}
|
|
300
557
|
|
|
301
558
|
/**
|
|
@@ -312,15 +569,27 @@ var Server = /*#__PURE__*/function () {
|
|
|
312
569
|
handler = route.handler;
|
|
313
570
|
if (!_this2.router[method]) {
|
|
314
571
|
console.warn("[Server] \u4E0D\u652F\u6301\u7684 HTTP \u65B9\u6CD5: ".concat(method));
|
|
572
|
+
_this2.logWarning("\u4E0D\u652F\u6301\u7684 HTTP \u65B9\u6CD5", {
|
|
573
|
+
method: method,
|
|
574
|
+
path: path
|
|
575
|
+
});
|
|
315
576
|
return;
|
|
316
577
|
}
|
|
317
578
|
|
|
318
579
|
// 检查路由是否已存在
|
|
319
580
|
if (_this2.router[method][path]) {
|
|
320
581
|
console.warn("[Server] \u8DEF\u7531\u5DF2\u5B58\u5728\uFF0C\u5C06\u88AB\u8986\u76D6: ".concat(method.toUpperCase(), " ").concat(path));
|
|
582
|
+
_this2.logWarning("\u8DEF\u7531\u5DF2\u5B58\u5728\uFF0C\u5C06\u88AB\u8986\u76D6", {
|
|
583
|
+
method: method,
|
|
584
|
+
path: path
|
|
585
|
+
});
|
|
321
586
|
}
|
|
322
587
|
_this2.router[method][path] = handler;
|
|
323
588
|
console.log("[Server] \uD83D\uDCDD \u6CE8\u518C\u8DEF\u7531: ".concat(method.toUpperCase(), " ").concat(path));
|
|
589
|
+
_this2.logInfo("\u6CE8\u518C\u8DEF\u7531", {
|
|
590
|
+
method: method.toUpperCase(),
|
|
591
|
+
path: path
|
|
592
|
+
});
|
|
324
593
|
});
|
|
325
594
|
}
|
|
326
595
|
|
|
@@ -333,30 +602,43 @@ var Server = /*#__PURE__*/function () {
|
|
|
333
602
|
}, {
|
|
334
603
|
key: "registerModuleWithRoutes",
|
|
335
604
|
value: (function () {
|
|
336
|
-
var _registerModuleWithRoutes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
605
|
+
var _registerModuleWithRoutes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(module, options, moduleName) {
|
|
337
606
|
var routes;
|
|
338
|
-
return _regeneratorRuntime().wrap(function
|
|
339
|
-
while (1) switch (
|
|
607
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
608
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
340
609
|
case 0:
|
|
341
|
-
|
|
610
|
+
this.logInfo("\u5F00\u59CB\u6CE8\u518C\u6A21\u5757: ".concat(moduleName), {
|
|
611
|
+
moduleName: moduleName,
|
|
612
|
+
options: options
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
// 注册模块到 Core
|
|
616
|
+
_context9.next = 3;
|
|
342
617
|
return this.core.registerModule(module, options);
|
|
343
|
-
case
|
|
618
|
+
case 3:
|
|
344
619
|
console.log("[Server] \u2705 ".concat(moduleName, " \u6A21\u5757\u5DF2\u6CE8\u518C"));
|
|
620
|
+
this.logInfo("\u6A21\u5757\u6CE8\u518C\u6210\u529F: ".concat(moduleName), {
|
|
621
|
+
moduleName: moduleName
|
|
622
|
+
});
|
|
345
623
|
|
|
346
624
|
// 自动注册模块的路由
|
|
347
625
|
if (typeof module.getRoutes === 'function') {
|
|
348
626
|
routes = module.getRoutes();
|
|
349
627
|
if (routes && routes.length > 0) {
|
|
350
628
|
this.registerRoutes(routes);
|
|
629
|
+
this.logInfo("\u6A21\u5757\u8DEF\u7531\u5DF2\u6CE8\u518C: ".concat(moduleName), {
|
|
630
|
+
moduleName: moduleName,
|
|
631
|
+
routesCount: routes.length
|
|
632
|
+
});
|
|
351
633
|
}
|
|
352
634
|
}
|
|
353
|
-
case
|
|
635
|
+
case 6:
|
|
354
636
|
case "end":
|
|
355
|
-
return
|
|
637
|
+
return _context9.stop();
|
|
356
638
|
}
|
|
357
|
-
},
|
|
639
|
+
}, _callee9, this);
|
|
358
640
|
}));
|
|
359
|
-
function registerModuleWithRoutes(
|
|
641
|
+
function registerModuleWithRoutes(_x9, _x10, _x11) {
|
|
360
642
|
return _registerModuleWithRoutes.apply(this, arguments);
|
|
361
643
|
}
|
|
362
644
|
return registerModuleWithRoutes;
|
|
@@ -369,45 +651,60 @@ var Server = /*#__PURE__*/function () {
|
|
|
369
651
|
}, {
|
|
370
652
|
key: "registerModuleByName",
|
|
371
653
|
value: (function () {
|
|
372
|
-
var _registerModuleByName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
654
|
+
var _registerModuleByName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(moduleConfig) {
|
|
373
655
|
var moduleName, shouldPreload, customConfig, registryConfig, ModuleClass, moduleInstance, moduleOptions;
|
|
374
|
-
return _regeneratorRuntime().wrap(function
|
|
375
|
-
while (1) switch (
|
|
656
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
657
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
376
658
|
case 0:
|
|
377
659
|
// 解析配置
|
|
378
660
|
moduleName = typeof moduleConfig === 'string' ? moduleConfig : moduleConfig.name;
|
|
379
661
|
shouldPreload = _typeof(moduleConfig) === 'object' ? moduleConfig.preload !== false : true;
|
|
380
|
-
customConfig = _typeof(moduleConfig) === 'object' ? moduleConfig.config : {};
|
|
662
|
+
customConfig = _typeof(moduleConfig) === 'object' ? moduleConfig.config : {};
|
|
663
|
+
this.logInfo("\u89E3\u6790\u6A21\u5757\u914D\u7F6E: ".concat(moduleName), {
|
|
664
|
+
moduleName: moduleName,
|
|
665
|
+
shouldPreload: shouldPreload,
|
|
666
|
+
customConfig: customConfig
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
// 查找模块配置
|
|
381
670
|
registryConfig = this.moduleRegistry[moduleName];
|
|
382
671
|
if (registryConfig) {
|
|
383
|
-
|
|
672
|
+
_context10.next = 8;
|
|
384
673
|
break;
|
|
385
674
|
}
|
|
675
|
+
this.logError("\u672A\u627E\u5230\u6A21\u5757\u914D\u7F6E: ".concat(moduleName), {
|
|
676
|
+
moduleName: moduleName
|
|
677
|
+
});
|
|
386
678
|
throw new Error("[Server] \u672A\u627E\u5230\u6A21\u5757\u914D\u7F6E: ".concat(moduleName));
|
|
387
|
-
case
|
|
679
|
+
case 8:
|
|
388
680
|
// 创建模块实例
|
|
389
681
|
ModuleClass = registryConfig.moduleClass;
|
|
390
682
|
moduleInstance = new ModuleClass(registryConfig.moduleName, registryConfig.version); // 合并配置
|
|
391
683
|
moduleOptions = _objectSpread({
|
|
392
684
|
store: _objectSpread({}, registryConfig.defaultStore)
|
|
393
685
|
}, customConfig); // 注册模块和路由
|
|
394
|
-
|
|
686
|
+
_context10.next = 13;
|
|
395
687
|
return this.registerModuleWithRoutes(moduleInstance, moduleOptions, moduleName.charAt(0).toUpperCase() + moduleName.slice(1));
|
|
396
|
-
case
|
|
688
|
+
case 13:
|
|
397
689
|
// 保存模块实例
|
|
398
690
|
this[moduleName] = moduleInstance;
|
|
399
|
-
|
|
691
|
+
this.logInfo("\u6A21\u5757\u6CE8\u518C\u5B8C\u6210: ".concat(moduleName), {
|
|
692
|
+
moduleName: moduleName,
|
|
693
|
+
shouldPreload: shouldPreload,
|
|
694
|
+
version: registryConfig.version
|
|
695
|
+
});
|
|
696
|
+
return _context10.abrupt("return", {
|
|
400
697
|
module: moduleInstance,
|
|
401
698
|
config: registryConfig,
|
|
402
699
|
shouldPreload: shouldPreload
|
|
403
700
|
});
|
|
404
|
-
case
|
|
701
|
+
case 16:
|
|
405
702
|
case "end":
|
|
406
|
-
return
|
|
703
|
+
return _context10.stop();
|
|
407
704
|
}
|
|
408
|
-
},
|
|
705
|
+
}, _callee10, this);
|
|
409
706
|
}));
|
|
410
|
-
function registerModuleByName(
|
|
707
|
+
function registerModuleByName(_x12) {
|
|
411
708
|
return _registerModuleByName.apply(this, arguments);
|
|
412
709
|
}
|
|
413
710
|
return registerModuleByName;
|
|
@@ -420,62 +717,79 @@ var Server = /*#__PURE__*/function () {
|
|
|
420
717
|
}, {
|
|
421
718
|
key: "registerModules",
|
|
422
719
|
value: (function () {
|
|
423
|
-
var _registerModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
424
|
-
var configs, registeredModules, _iterator, _step, config, result;
|
|
425
|
-
return _regeneratorRuntime().wrap(function
|
|
426
|
-
while (1) switch (
|
|
720
|
+
var _registerModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(moduleConfigs) {
|
|
721
|
+
var configs, registeredModules, _iterator, _step, config, configName, result, errorMessage;
|
|
722
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
723
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
427
724
|
case 0:
|
|
428
725
|
console.log('[Server] 开始注册模块...');
|
|
429
726
|
|
|
430
727
|
// 如果没有指定模块,则注册所有模块
|
|
431
728
|
configs = moduleConfigs || Object.keys(this.moduleRegistry);
|
|
729
|
+
this.logInfo('开始批量注册模块', {
|
|
730
|
+
moduleConfigs: configs,
|
|
731
|
+
totalCount: configs.length
|
|
732
|
+
});
|
|
432
733
|
registeredModules = [];
|
|
433
734
|
_iterator = _createForOfIteratorHelper(configs);
|
|
434
|
-
|
|
735
|
+
_context11.prev = 5;
|
|
435
736
|
_iterator.s();
|
|
436
|
-
case
|
|
737
|
+
case 7:
|
|
437
738
|
if ((_step = _iterator.n()).done) {
|
|
438
|
-
|
|
739
|
+
_context11.next = 25;
|
|
439
740
|
break;
|
|
440
741
|
}
|
|
441
742
|
config = _step.value;
|
|
442
|
-
|
|
443
|
-
|
|
743
|
+
configName = typeof config === 'string' ? config : config.name;
|
|
744
|
+
_context11.prev = 10;
|
|
745
|
+
_context11.next = 13;
|
|
444
746
|
return this.registerModuleByName(config);
|
|
445
|
-
case
|
|
446
|
-
result =
|
|
747
|
+
case 13:
|
|
748
|
+
result = _context11.sent;
|
|
447
749
|
registeredModules.push(result);
|
|
448
|
-
|
|
750
|
+
_context11.next = 23;
|
|
449
751
|
break;
|
|
450
|
-
case
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
752
|
+
case 17:
|
|
753
|
+
_context11.prev = 17;
|
|
754
|
+
_context11.t0 = _context11["catch"](10);
|
|
755
|
+
errorMessage = _context11.t0 instanceof Error ? _context11.t0.message : String(_context11.t0);
|
|
756
|
+
this.logError("\u6A21\u5757\u6CE8\u518C\u5931\u8D25: ".concat(configName), {
|
|
757
|
+
moduleName: configName,
|
|
758
|
+
error: errorMessage
|
|
759
|
+
});
|
|
760
|
+
console.error("[Server] \u6A21\u5757\u6CE8\u518C\u5931\u8D25:", _context11.t0);
|
|
761
|
+
throw _context11.t0;
|
|
762
|
+
case 23:
|
|
763
|
+
_context11.next = 7;
|
|
457
764
|
break;
|
|
458
|
-
case
|
|
459
|
-
|
|
765
|
+
case 25:
|
|
766
|
+
_context11.next = 30;
|
|
460
767
|
break;
|
|
461
|
-
case
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
_iterator.e(
|
|
465
|
-
case
|
|
466
|
-
|
|
768
|
+
case 27:
|
|
769
|
+
_context11.prev = 27;
|
|
770
|
+
_context11.t1 = _context11["catch"](5);
|
|
771
|
+
_iterator.e(_context11.t1);
|
|
772
|
+
case 30:
|
|
773
|
+
_context11.prev = 30;
|
|
467
774
|
_iterator.f();
|
|
468
|
-
return
|
|
469
|
-
case
|
|
775
|
+
return _context11.finish(30);
|
|
776
|
+
case 33:
|
|
470
777
|
console.log('[Server] ✅ 所有模块注册完成');
|
|
471
|
-
|
|
472
|
-
|
|
778
|
+
this.logInfo('所有模块注册完成', {
|
|
779
|
+
registeredCount: registeredModules.length,
|
|
780
|
+
moduleNames: registeredModules.map(function (m) {
|
|
781
|
+
var _m$config;
|
|
782
|
+
return m === null || m === void 0 || (_m$config = m.config) === null || _m$config === void 0 ? void 0 : _m$config.name;
|
|
783
|
+
})
|
|
784
|
+
});
|
|
785
|
+
return _context11.abrupt("return", registeredModules);
|
|
786
|
+
case 36:
|
|
473
787
|
case "end":
|
|
474
|
-
return
|
|
788
|
+
return _context11.stop();
|
|
475
789
|
}
|
|
476
|
-
},
|
|
790
|
+
}, _callee11, this, [[5, 27, 30, 33], [10, 17]]);
|
|
477
791
|
}));
|
|
478
|
-
function registerModules(
|
|
792
|
+
function registerModules(_x13) {
|
|
479
793
|
return _registerModules.apply(this, arguments);
|
|
480
794
|
}
|
|
481
795
|
return registerModules;
|
|
@@ -488,73 +802,124 @@ var Server = /*#__PURE__*/function () {
|
|
|
488
802
|
}, {
|
|
489
803
|
key: "preloadModulesData",
|
|
490
804
|
value: (function () {
|
|
491
|
-
var _preloadModulesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
492
|
-
var _iterator2, _step2, _step2$value, module, config, shouldPreload, _options$onModuleLoad, _options$onModuleLoad2;
|
|
493
|
-
return _regeneratorRuntime().wrap(function
|
|
494
|
-
while (1) switch (
|
|
805
|
+
var _preloadModulesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(registeredModules, options) {
|
|
806
|
+
var modulesToPreload, preloadResults, _iterator2, _step2, _step2$value, module, config, shouldPreload, startTime, _options$onModuleLoad, _options$onModuleLoad2, duration, _duration, errorMessage, successCount, failCount;
|
|
807
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
808
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
495
809
|
case 0:
|
|
496
810
|
console.log('[Server] 开始预加载模块数据...');
|
|
811
|
+
modulesToPreload = registeredModules.filter(function (m) {
|
|
812
|
+
return m.shouldPreload;
|
|
813
|
+
});
|
|
814
|
+
this.logInfo('开始预加载模块数据', {
|
|
815
|
+
totalModules: registeredModules.length,
|
|
816
|
+
preloadCount: modulesToPreload.length,
|
|
817
|
+
modulesToPreload: modulesToPreload
|
|
818
|
+
});
|
|
819
|
+
preloadResults = [];
|
|
497
820
|
_iterator2 = _createForOfIteratorHelper(registeredModules);
|
|
498
|
-
|
|
821
|
+
_context12.prev = 5;
|
|
499
822
|
_iterator2.s();
|
|
500
|
-
case
|
|
823
|
+
case 7:
|
|
501
824
|
if ((_step2 = _iterator2.n()).done) {
|
|
502
|
-
|
|
825
|
+
_context12.next = 40;
|
|
503
826
|
break;
|
|
504
827
|
}
|
|
505
828
|
_step2$value = _step2.value, module = _step2$value.module, config = _step2$value.config, shouldPreload = _step2$value.shouldPreload;
|
|
506
829
|
if (shouldPreload) {
|
|
507
|
-
|
|
830
|
+
_context12.next = 13;
|
|
508
831
|
break;
|
|
509
832
|
}
|
|
510
833
|
console.log("[Server] \u23ED\uFE0F \u8DF3\u8FC7 ".concat(config.name, " \u6A21\u5757\u9884\u52A0\u8F7D"));
|
|
511
|
-
|
|
512
|
-
|
|
834
|
+
this.logInfo("\u8DF3\u8FC7\u6A21\u5757\u9884\u52A0\u8F7D: ".concat(config.name), {
|
|
835
|
+
moduleName: config.name,
|
|
836
|
+
reason: 'shouldPreload=false'
|
|
837
|
+
});
|
|
838
|
+
return _context12.abrupt("continue", 38);
|
|
839
|
+
case 13:
|
|
513
840
|
if (!(typeof module.preload === 'function')) {
|
|
514
|
-
|
|
841
|
+
_context12.next = 36;
|
|
515
842
|
break;
|
|
516
843
|
}
|
|
517
|
-
|
|
844
|
+
startTime = Date.now();
|
|
845
|
+
_context12.prev = 15;
|
|
846
|
+
this.logInfo("\u5F00\u59CB\u9884\u52A0\u8F7D\u6A21\u5757: ".concat(config.name), {
|
|
847
|
+
moduleName: config.name
|
|
848
|
+
});
|
|
518
849
|
options === null || options === void 0 || (_options$onModuleLoad = options.onModuleLoad) === null || _options$onModuleLoad === void 0 || _options$onModuleLoad.call(options, config.name);
|
|
519
|
-
|
|
850
|
+
_context12.next = 20;
|
|
520
851
|
return module.preload();
|
|
521
|
-
case
|
|
852
|
+
case 20:
|
|
522
853
|
options === null || options === void 0 || (_options$onModuleLoad2 = options.onModuleLoadComplete) === null || _options$onModuleLoad2 === void 0 || _options$onModuleLoad2.call(options, config.name);
|
|
854
|
+
duration = Date.now() - startTime;
|
|
523
855
|
console.log("[Server] \u2705 ".concat(config.name, " \u6A21\u5757\u6570\u636E\u5DF2\u9884\u52A0\u8F7D"));
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
856
|
+
this.logInfo("\u6A21\u5757\u9884\u52A0\u8F7D\u6210\u529F: ".concat(config.name), {
|
|
857
|
+
moduleName: config.name,
|
|
858
|
+
duration: "".concat(duration, "ms")
|
|
859
|
+
});
|
|
860
|
+
preloadResults.push({
|
|
861
|
+
name: config.name,
|
|
862
|
+
success: true
|
|
863
|
+
});
|
|
864
|
+
_context12.next = 34;
|
|
532
865
|
break;
|
|
533
|
-
case
|
|
866
|
+
case 27:
|
|
867
|
+
_context12.prev = 27;
|
|
868
|
+
_context12.t0 = _context12["catch"](15);
|
|
869
|
+
_duration = Date.now() - startTime;
|
|
870
|
+
errorMessage = _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0);
|
|
871
|
+
console.error("[Server] \u274C ".concat(config.name, " \u6A21\u5757\u9884\u52A0\u8F7D\u5931\u8D25:"), _context12.t0);
|
|
872
|
+
this.logError("\u6A21\u5757\u9884\u52A0\u8F7D\u5931\u8D25: ".concat(config.name), {
|
|
873
|
+
moduleName: config.name,
|
|
874
|
+
duration: "".concat(_duration, "ms"),
|
|
875
|
+
error: errorMessage
|
|
876
|
+
});
|
|
877
|
+
preloadResults.push({
|
|
878
|
+
name: config.name,
|
|
879
|
+
success: false,
|
|
880
|
+
error: errorMessage
|
|
881
|
+
});
|
|
882
|
+
case 34:
|
|
883
|
+
_context12.next = 38;
|
|
884
|
+
break;
|
|
885
|
+
case 36:
|
|
534
886
|
console.log("[Server] \u26A0\uFE0F ".concat(config.name, " \u6A21\u5757\u672A\u5B9E\u73B0 preload() \u65B9\u6CD5"));
|
|
535
|
-
|
|
536
|
-
|
|
887
|
+
this.logWarning("\u6A21\u5757\u672A\u5B9E\u73B0 preload \u65B9\u6CD5: ".concat(config.name), {
|
|
888
|
+
moduleName: config.name
|
|
889
|
+
});
|
|
890
|
+
case 38:
|
|
891
|
+
_context12.next = 7;
|
|
537
892
|
break;
|
|
538
|
-
case
|
|
539
|
-
|
|
893
|
+
case 40:
|
|
894
|
+
_context12.next = 45;
|
|
540
895
|
break;
|
|
541
|
-
case
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
_iterator2.e(
|
|
545
|
-
case
|
|
546
|
-
|
|
896
|
+
case 42:
|
|
897
|
+
_context12.prev = 42;
|
|
898
|
+
_context12.t1 = _context12["catch"](5);
|
|
899
|
+
_iterator2.e(_context12.t1);
|
|
900
|
+
case 45:
|
|
901
|
+
_context12.prev = 45;
|
|
547
902
|
_iterator2.f();
|
|
548
|
-
return
|
|
549
|
-
case
|
|
903
|
+
return _context12.finish(45);
|
|
904
|
+
case 48:
|
|
905
|
+
successCount = preloadResults.filter(function (r) {
|
|
906
|
+
return r.success;
|
|
907
|
+
}).length;
|
|
908
|
+
failCount = preloadResults.filter(function (r) {
|
|
909
|
+
return !r.success;
|
|
910
|
+
}).length;
|
|
550
911
|
console.log('[Server] ✅ 所有模块数据预加载完成');
|
|
551
|
-
|
|
912
|
+
this.logInfo('所有模块预加载完成', {
|
|
913
|
+
successCount: successCount,
|
|
914
|
+
failCount: failCount
|
|
915
|
+
});
|
|
916
|
+
case 52:
|
|
552
917
|
case "end":
|
|
553
|
-
return
|
|
918
|
+
return _context12.stop();
|
|
554
919
|
}
|
|
555
|
-
},
|
|
920
|
+
}, _callee12, this, [[5, 42, 45, 48], [15, 27]]);
|
|
556
921
|
}));
|
|
557
|
-
function preloadModulesData(
|
|
922
|
+
function preloadModulesData(_x14, _x15) {
|
|
558
923
|
return _preloadModulesData.apply(this, arguments);
|
|
559
924
|
}
|
|
560
925
|
return preloadModulesData;
|
|
@@ -568,39 +933,74 @@ var Server = /*#__PURE__*/function () {
|
|
|
568
933
|
}, {
|
|
569
934
|
key: "initialize",
|
|
570
935
|
value: (function () {
|
|
571
|
-
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
936
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(moduleConfigs) {
|
|
937
|
+
var _moduleConfigs$length,
|
|
938
|
+
_this3 = this;
|
|
572
939
|
var autoPreload,
|
|
573
940
|
options,
|
|
941
|
+
startTime,
|
|
574
942
|
registeredModules,
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
943
|
+
duration,
|
|
944
|
+
_args13 = arguments;
|
|
945
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
946
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
578
947
|
case 0:
|
|
579
|
-
autoPreload =
|
|
580
|
-
options =
|
|
948
|
+
autoPreload = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : true;
|
|
949
|
+
options = _args13.length > 2 ? _args13[2] : undefined;
|
|
950
|
+
startTime = Date.now();
|
|
951
|
+
this.logInfo('Server 初始化开始', {
|
|
952
|
+
moduleConfigCount: (_moduleConfigs$length = moduleConfigs === null || moduleConfigs === void 0 ? void 0 : moduleConfigs.length) !== null && _moduleConfigs$length !== void 0 ? _moduleConfigs$length : 'all',
|
|
953
|
+
autoPreload: autoPreload,
|
|
954
|
+
moduleConfigs: moduleConfigs
|
|
955
|
+
});
|
|
956
|
+
|
|
581
957
|
// 注册 Server 层的业务路由
|
|
582
958
|
this.registerServerRoutes();
|
|
583
959
|
|
|
584
960
|
// 注册模块
|
|
585
|
-
|
|
961
|
+
_context13.next = 7;
|
|
586
962
|
return this.registerModules(moduleConfigs);
|
|
587
|
-
case
|
|
588
|
-
registeredModules =
|
|
963
|
+
case 7:
|
|
964
|
+
registeredModules = _context13.sent;
|
|
589
965
|
if (!autoPreload) {
|
|
590
|
-
|
|
966
|
+
_context13.next = 13;
|
|
591
967
|
break;
|
|
592
968
|
}
|
|
593
|
-
|
|
969
|
+
_context13.next = 11;
|
|
594
970
|
return this.preloadModulesData(registeredModules, options);
|
|
595
|
-
case
|
|
596
|
-
|
|
597
|
-
|
|
971
|
+
case 11:
|
|
972
|
+
_context13.next = 14;
|
|
973
|
+
break;
|
|
974
|
+
case 13:
|
|
975
|
+
this.logInfo('跳过自动预加载', {
|
|
976
|
+
autoPreload: autoPreload
|
|
977
|
+
});
|
|
978
|
+
case 14:
|
|
979
|
+
// 监听 ProductsModule 同步完成事件,重新计算并推送查询结果
|
|
980
|
+
this.core.effects.on(ProductsHooks.onProductsSyncCompleted, function (payload) {
|
|
981
|
+
_this3.recomputeAndNotifyProductQuery({
|
|
982
|
+
changedIds: payload === null || payload === void 0 ? void 0 : payload.changedIds
|
|
983
|
+
});
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
// 订单 / 预约本地数据变更时,向订阅者推送最新列表
|
|
987
|
+
this.core.effects.on(OrderHooks.onOrdersChanged, function () {
|
|
988
|
+
_this3.recomputeAndNotifyOrderQuery();
|
|
989
|
+
_this3.recomputeAndNotifyBookingQuery();
|
|
990
|
+
});
|
|
991
|
+
duration = Date.now() - startTime;
|
|
992
|
+
this.logInfo('Server 初始化完成', {
|
|
993
|
+
duration: "".concat(duration, "ms"),
|
|
994
|
+
registeredModuleCount: registeredModules.length
|
|
995
|
+
});
|
|
996
|
+
return _context13.abrupt("return", registeredModules);
|
|
997
|
+
case 19:
|
|
598
998
|
case "end":
|
|
599
|
-
return
|
|
999
|
+
return _context13.stop();
|
|
600
1000
|
}
|
|
601
|
-
},
|
|
1001
|
+
}, _callee13, this);
|
|
602
1002
|
}));
|
|
603
|
-
function initialize(
|
|
1003
|
+
function initialize(_x16) {
|
|
604
1004
|
return _initialize.apply(this, arguments);
|
|
605
1005
|
}
|
|
606
1006
|
return initialize;
|
|
@@ -653,22 +1053,79 @@ var Server = /*#__PURE__*/function () {
|
|
|
653
1053
|
if (this.menu) modules.push('menu');
|
|
654
1054
|
if (this.quotation) modules.push('quotation');
|
|
655
1055
|
if (this.schedule) modules.push('schedule');
|
|
1056
|
+
if (this.resource) modules.push('resource');
|
|
1057
|
+
if (this.order) modules.push('order');
|
|
656
1058
|
return modules;
|
|
657
1059
|
}
|
|
658
1060
|
|
|
1061
|
+
/**
|
|
1062
|
+
* 后台静默刷新商品数据
|
|
1063
|
+
* 重新拉取全量 SSE 接口,更新本地数据后触发 onProductsSyncCompleted
|
|
1064
|
+
* 不影响当前界面展示,适用于切回前台、定时刷新等场景
|
|
1065
|
+
*/
|
|
1066
|
+
}, {
|
|
1067
|
+
key: "refreshProductsInBackground",
|
|
1068
|
+
value: (function () {
|
|
1069
|
+
var _refreshProductsInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
1070
|
+
var startTime, duration, _duration2, errorMessage;
|
|
1071
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1072
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1073
|
+
case 0:
|
|
1074
|
+
if (this.products) {
|
|
1075
|
+
_context14.next = 3;
|
|
1076
|
+
break;
|
|
1077
|
+
}
|
|
1078
|
+
this.logWarning('refreshProductsInBackground: Products 模块未注册');
|
|
1079
|
+
return _context14.abrupt("return");
|
|
1080
|
+
case 3:
|
|
1081
|
+
this.logInfo('refreshProductsInBackground 开始');
|
|
1082
|
+
startTime = Date.now();
|
|
1083
|
+
_context14.prev = 5;
|
|
1084
|
+
_context14.next = 8;
|
|
1085
|
+
return this.products.silentRefresh();
|
|
1086
|
+
case 8:
|
|
1087
|
+
duration = Date.now() - startTime;
|
|
1088
|
+
this.logInfo('refreshProductsInBackground 完成', {
|
|
1089
|
+
duration: "".concat(duration, "ms")
|
|
1090
|
+
});
|
|
1091
|
+
_context14.next = 18;
|
|
1092
|
+
break;
|
|
1093
|
+
case 12:
|
|
1094
|
+
_context14.prev = 12;
|
|
1095
|
+
_context14.t0 = _context14["catch"](5);
|
|
1096
|
+
_duration2 = Date.now() - startTime;
|
|
1097
|
+
errorMessage = _context14.t0 instanceof Error ? _context14.t0.message : String(_context14.t0);
|
|
1098
|
+
console.error('[Server] refreshProductsInBackground 失败:', _context14.t0);
|
|
1099
|
+
this.logError('refreshProductsInBackground 失败', {
|
|
1100
|
+
duration: "".concat(_duration2, "ms"),
|
|
1101
|
+
error: errorMessage
|
|
1102
|
+
});
|
|
1103
|
+
case 18:
|
|
1104
|
+
case "end":
|
|
1105
|
+
return _context14.stop();
|
|
1106
|
+
}
|
|
1107
|
+
}, _callee14, this, [[5, 12]]);
|
|
1108
|
+
}));
|
|
1109
|
+
function refreshProductsInBackground() {
|
|
1110
|
+
return _refreshProductsInBackground.apply(this, arguments);
|
|
1111
|
+
}
|
|
1112
|
+
return refreshProductsInBackground;
|
|
1113
|
+
}()
|
|
659
1114
|
/**
|
|
660
1115
|
* 清空所有server模块的IndexedDB缓存
|
|
661
1116
|
* @returns Promise<void>
|
|
662
1117
|
*/
|
|
1118
|
+
)
|
|
663
1119
|
}, {
|
|
664
1120
|
key: "clearAllIndexDB",
|
|
665
1121
|
value: (function () {
|
|
666
|
-
var _clearAllIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
667
|
-
var clearTasks, moduleNames;
|
|
668
|
-
return _regeneratorRuntime().wrap(function
|
|
669
|
-
while (1) switch (
|
|
1122
|
+
var _clearAllIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
1123
|
+
var clearTasks, moduleNames, errorMessage;
|
|
1124
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1125
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
670
1126
|
case 0:
|
|
671
1127
|
console.log('[Server] 开始清空所有模块的IndexedDB缓存...');
|
|
1128
|
+
this.logInfo('开始清空所有模块的 IndexedDB 缓存');
|
|
672
1129
|
clearTasks = [];
|
|
673
1130
|
moduleNames = []; // 收集所有模块的清空任务
|
|
674
1131
|
if (this.products) {
|
|
@@ -687,30 +1144,50 @@ var Server = /*#__PURE__*/function () {
|
|
|
687
1144
|
clearTasks.push(this.schedule.clear());
|
|
688
1145
|
moduleNames.push('Schedule');
|
|
689
1146
|
}
|
|
1147
|
+
if (this.resource) {
|
|
1148
|
+
clearTasks.push(this.resource.clear());
|
|
1149
|
+
moduleNames.push('Resource');
|
|
1150
|
+
}
|
|
1151
|
+
if (this.order) {
|
|
1152
|
+
clearTasks.push(this.order.clear());
|
|
1153
|
+
moduleNames.push('Order');
|
|
1154
|
+
}
|
|
690
1155
|
if (!(clearTasks.length === 0)) {
|
|
691
|
-
|
|
1156
|
+
_context15.next = 14;
|
|
692
1157
|
break;
|
|
693
1158
|
}
|
|
694
1159
|
console.warn('[Server] 没有找到已注册的模块,无需清空');
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
1160
|
+
this.logWarning('没有找到已注册的模块,无需清空 IndexedDB');
|
|
1161
|
+
return _context15.abrupt("return");
|
|
1162
|
+
case 14:
|
|
1163
|
+
this.logInfo('准备清空模块缓存', {
|
|
1164
|
+
moduleNames: moduleNames
|
|
1165
|
+
});
|
|
1166
|
+
_context15.prev = 15;
|
|
1167
|
+
_context15.next = 18;
|
|
699
1168
|
return Promise.all(clearTasks);
|
|
700
|
-
case
|
|
1169
|
+
case 18:
|
|
701
1170
|
console.log("[Server] \u2705 \u5DF2\u6210\u529F\u6E05\u7A7A\u6240\u6709\u6A21\u5757\u7684IndexedDB\u7F13\u5B58: ".concat(moduleNames.join(', ')));
|
|
702
|
-
|
|
1171
|
+
this.logInfo('成功清空所有模块的 IndexedDB 缓存', {
|
|
1172
|
+
moduleNames: moduleNames
|
|
1173
|
+
});
|
|
1174
|
+
_context15.next = 28;
|
|
703
1175
|
break;
|
|
704
|
-
case
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
1176
|
+
case 22:
|
|
1177
|
+
_context15.prev = 22;
|
|
1178
|
+
_context15.t0 = _context15["catch"](15);
|
|
1179
|
+
errorMessage = _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0);
|
|
1180
|
+
console.error('[Server] ❌ 清空IndexedDB缓存时发生错误:', _context15.t0);
|
|
1181
|
+
this.logError('清空 IndexedDB 缓存时发生错误', {
|
|
1182
|
+
moduleNames: moduleNames,
|
|
1183
|
+
error: errorMessage
|
|
1184
|
+
});
|
|
1185
|
+
throw _context15.t0;
|
|
1186
|
+
case 28:
|
|
710
1187
|
case "end":
|
|
711
|
-
return
|
|
1188
|
+
return _context15.stop();
|
|
712
1189
|
}
|
|
713
|
-
},
|
|
1190
|
+
}, _callee15, this, [[15, 22]]);
|
|
714
1191
|
}));
|
|
715
1192
|
function clearAllIndexDB() {
|
|
716
1193
|
return _clearAllIndexDB.apply(this, arguments);
|
|
@@ -761,36 +1238,64 @@ var Server = /*#__PURE__*/function () {
|
|
|
761
1238
|
}, {
|
|
762
1239
|
key: "handleRoute",
|
|
763
1240
|
value: (function () {
|
|
764
|
-
var _handleRoute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
765
|
-
var handler;
|
|
766
|
-
return _regeneratorRuntime().wrap(function
|
|
767
|
-
while (1) switch (
|
|
1241
|
+
var _handleRoute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(method, path, params) {
|
|
1242
|
+
var startTime, handler, result, duration, _duration3, errorMessage;
|
|
1243
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1244
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
768
1245
|
case 0:
|
|
769
|
-
|
|
1246
|
+
startTime = Date.now();
|
|
1247
|
+
this.logInfo("\u8DEF\u7531\u8BF7\u6C42\u5F00\u59CB: ".concat(method.toUpperCase(), " ").concat(path), {
|
|
1248
|
+
method: method.toUpperCase(),
|
|
1249
|
+
path: path,
|
|
1250
|
+
url: params.url,
|
|
1251
|
+
data: params.data
|
|
1252
|
+
});
|
|
770
1253
|
handler = this.getRouteHandler(method, path);
|
|
771
1254
|
if (handler) {
|
|
772
|
-
|
|
1255
|
+
_context16.next = 6;
|
|
773
1256
|
break;
|
|
774
1257
|
}
|
|
1258
|
+
this.logError("\u8DEF\u7531\u672A\u627E\u5230: ".concat(method.toUpperCase(), " ").concat(path), {
|
|
1259
|
+
method: method,
|
|
1260
|
+
path: path
|
|
1261
|
+
});
|
|
775
1262
|
throw new Error("Route not found: ".concat(method.toUpperCase(), " ").concat(path));
|
|
776
|
-
case
|
|
777
|
-
|
|
778
|
-
|
|
1263
|
+
case 6:
|
|
1264
|
+
_context16.prev = 6;
|
|
1265
|
+
_context16.next = 9;
|
|
779
1266
|
return handler(params);
|
|
780
|
-
case
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
1267
|
+
case 9:
|
|
1268
|
+
result = _context16.sent;
|
|
1269
|
+
duration = Date.now() - startTime;
|
|
1270
|
+
this.logInfo("\u8DEF\u7531\u8BF7\u6C42\u5B8C\u6210: ".concat(method.toUpperCase(), " ").concat(path), {
|
|
1271
|
+
method: method.toUpperCase(),
|
|
1272
|
+
path: path,
|
|
1273
|
+
duration: "".concat(duration, "ms"),
|
|
1274
|
+
resultCode: result === null || result === void 0 ? void 0 : result.code,
|
|
1275
|
+
resultStatus: result === null || result === void 0 ? void 0 : result.status
|
|
1276
|
+
});
|
|
1277
|
+
return _context16.abrupt("return", result);
|
|
1278
|
+
case 15:
|
|
1279
|
+
_context16.prev = 15;
|
|
1280
|
+
_context16.t0 = _context16["catch"](6);
|
|
1281
|
+
_duration3 = Date.now() - startTime;
|
|
1282
|
+
errorMessage = _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0);
|
|
1283
|
+
this.logError("\u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), {
|
|
1284
|
+
method: method.toUpperCase(),
|
|
1285
|
+
path: path,
|
|
1286
|
+
duration: "".concat(_duration3, "ms"),
|
|
1287
|
+
error: errorMessage,
|
|
1288
|
+
data: params.data
|
|
1289
|
+
});
|
|
1290
|
+
console.error("[Server] \u8DEF\u7531\u5904\u7406\u9519\u8BEF: ".concat(method.toUpperCase(), " ").concat(path), _context16.t0);
|
|
1291
|
+
throw _context16.t0;
|
|
1292
|
+
case 22:
|
|
788
1293
|
case "end":
|
|
789
|
-
return
|
|
1294
|
+
return _context16.stop();
|
|
790
1295
|
}
|
|
791
|
-
},
|
|
1296
|
+
}, _callee16, this, [[6, 15]]);
|
|
792
1297
|
}));
|
|
793
|
-
function handleRoute(
|
|
1298
|
+
function handleRoute(_x17, _x18, _x19) {
|
|
794
1299
|
return _handleRoute.apply(this, arguments);
|
|
795
1300
|
}
|
|
796
1301
|
return handleRoute;
|
|
@@ -802,10 +1307,10 @@ var Server = /*#__PURE__*/function () {
|
|
|
802
1307
|
}, {
|
|
803
1308
|
key: "getAllRoutes",
|
|
804
1309
|
value: function getAllRoutes() {
|
|
805
|
-
var
|
|
1310
|
+
var _this4 = this;
|
|
806
1311
|
var routes = [];
|
|
807
1312
|
['get', 'post', 'put', 'remove'].forEach(function (method) {
|
|
808
|
-
Object.keys(
|
|
1313
|
+
Object.keys(_this4.router[method]).forEach(function (path) {
|
|
809
1314
|
routes.push({
|
|
810
1315
|
method: method,
|
|
811
1316
|
path: path
|
|
@@ -824,21 +1329,635 @@ var Server = /*#__PURE__*/function () {
|
|
|
824
1329
|
key: "registerServerRoutes",
|
|
825
1330
|
value: function registerServerRoutes() {
|
|
826
1331
|
console.log('[Server] 注册 Server 层业务路由...');
|
|
827
|
-
|
|
828
|
-
// 注册商品查询路由(带餐牌和日程信息)
|
|
829
1332
|
this.registerRoutes([{
|
|
830
1333
|
method: 'post',
|
|
831
1334
|
path: '/shop/product/query',
|
|
832
1335
|
handler: this.handleProductQuery.bind(this)
|
|
1336
|
+
}, {
|
|
1337
|
+
method: 'post',
|
|
1338
|
+
path: '/shop/product/query/unsubscribe',
|
|
1339
|
+
handler: this.handleUnsubscribeProductQuery.bind(this)
|
|
833
1340
|
}, {
|
|
834
1341
|
method: 'post',
|
|
835
1342
|
path: '/shop/menu/schedule-time-points',
|
|
836
1343
|
handler: this.handleGetScheduleTimePoints.bind(this)
|
|
1344
|
+
}, {
|
|
1345
|
+
method: 'post',
|
|
1346
|
+
path: '/shop/order/v2/list',
|
|
1347
|
+
handler: this.handleOrderList.bind(this)
|
|
1348
|
+
}, {
|
|
1349
|
+
method: 'post',
|
|
1350
|
+
path: '/shop/order/v2/list/unsubscribe',
|
|
1351
|
+
handler: this.handleUnsubscribeOrderQuery.bind(this)
|
|
1352
|
+
}, {
|
|
1353
|
+
method: 'get',
|
|
1354
|
+
path: '/shop/schedule/booking',
|
|
1355
|
+
handler: this.handleBookingList.bind(this)
|
|
1356
|
+
}, {
|
|
1357
|
+
method: 'get',
|
|
1358
|
+
path: '/shop/schedule/booking/unsubscribe',
|
|
1359
|
+
handler: this.handleUnsubscribeBookingQuery.bind(this)
|
|
1360
|
+
}, {
|
|
1361
|
+
method: 'get',
|
|
1362
|
+
path: '/shop/form/resource/page',
|
|
1363
|
+
handler: this.handleResourceList.bind(this)
|
|
837
1364
|
}]);
|
|
838
1365
|
}
|
|
1366
|
+
|
|
1367
|
+
/**
|
|
1368
|
+
* 根据 subscriberId 移除商品查询订阅者
|
|
1369
|
+
*/
|
|
1370
|
+
}, {
|
|
1371
|
+
key: "removeProductQuerySubscriber",
|
|
1372
|
+
value: function removeProductQuerySubscriber(subscriberId) {
|
|
1373
|
+
if (subscriberId) {
|
|
1374
|
+
this.productQuerySubscribers.delete(subscriberId);
|
|
1375
|
+
this.logInfo('removeProductQuerySubscriber: 已移除订阅者', {
|
|
1376
|
+
subscriberId: subscriberId,
|
|
1377
|
+
remaining: this.productQuerySubscribers.size
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
839
1381
|
}, {
|
|
840
|
-
key: "
|
|
1382
|
+
key: "isBookingQueryForToday",
|
|
841
1383
|
value:
|
|
1384
|
+
/**
|
|
1385
|
+
* 判断预约查询的 sales_time_between 起始日期是否为今天
|
|
1386
|
+
*/
|
|
1387
|
+
function isBookingQueryForToday(data) {
|
|
1388
|
+
var range = data === null || data === void 0 ? void 0 : data.sales_time_between;
|
|
1389
|
+
if (!Array.isArray(range) || range.length < 1) return true;
|
|
1390
|
+
var startDateStr = String(range[0]).split('T')[0].split(' ')[0];
|
|
1391
|
+
var todayStr = dayjs().format('YYYY-MM-DD');
|
|
1392
|
+
return startDateStr === todayStr;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
/**
|
|
1396
|
+
* 非今天的预约查询:通过真实 API 获取数据,再做 flattenOrdersToBookings 拆分
|
|
1397
|
+
*/
|
|
1398
|
+
}, {
|
|
1399
|
+
key: "fetchBookingListFromAPI",
|
|
1400
|
+
value: (function () {
|
|
1401
|
+
var _fetchBookingListFromAPI = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(data) {
|
|
1402
|
+
var _this$app2;
|
|
1403
|
+
var _ref23, _response$data$list, _response$data, response, rawList, list, errorMessage;
|
|
1404
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1405
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1406
|
+
case 0:
|
|
1407
|
+
if ((_this$app2 = this.app) !== null && _this$app2 !== void 0 && _this$app2.request) {
|
|
1408
|
+
_context17.next = 3;
|
|
1409
|
+
break;
|
|
1410
|
+
}
|
|
1411
|
+
this.logError('fetchBookingListFromAPI: app.request 不可用');
|
|
1412
|
+
return _context17.abrupt("return", {
|
|
1413
|
+
code: 500,
|
|
1414
|
+
message: 'app.request 不可用',
|
|
1415
|
+
data: {
|
|
1416
|
+
list: [],
|
|
1417
|
+
count: 0
|
|
1418
|
+
},
|
|
1419
|
+
status: false
|
|
1420
|
+
});
|
|
1421
|
+
case 3:
|
|
1422
|
+
_context17.prev = 3;
|
|
1423
|
+
_context17.next = 6;
|
|
1424
|
+
return this.app.request.get('/shop/order/sales', _objectSpread(_objectSpread({}, data), {}, {
|
|
1425
|
+
form_record_ids: undefined,
|
|
1426
|
+
with: ["all"]
|
|
1427
|
+
}), {
|
|
1428
|
+
isShopApi: true
|
|
1429
|
+
});
|
|
1430
|
+
case 6:
|
|
1431
|
+
response = _context17.sent;
|
|
1432
|
+
rawList = (_ref23 = (_response$data$list = response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list) !== null && _response$data$list !== void 0 ? _response$data$list : response === null || response === void 0 ? void 0 : response.list) !== null && _ref23 !== void 0 ? _ref23 : [];
|
|
1433
|
+
list = filterBookingsFromOrders(rawList, data);
|
|
1434
|
+
this.logInfo('fetchBookingListFromAPI: API 返回并拆分完成', {
|
|
1435
|
+
rawCount: rawList.length,
|
|
1436
|
+
flattenedCount: list.count
|
|
1437
|
+
});
|
|
1438
|
+
return _context17.abrupt("return", {
|
|
1439
|
+
code: 200,
|
|
1440
|
+
data: _objectSpread(_objectSpread({}, response.data), {}, {
|
|
1441
|
+
list: (list === null || list === void 0 ? void 0 : list.list) || []
|
|
1442
|
+
}),
|
|
1443
|
+
message: '',
|
|
1444
|
+
status: true
|
|
1445
|
+
});
|
|
1446
|
+
case 13:
|
|
1447
|
+
_context17.prev = 13;
|
|
1448
|
+
_context17.t0 = _context17["catch"](3);
|
|
1449
|
+
errorMessage = _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0);
|
|
1450
|
+
this.logError('fetchBookingListFromAPI: 请求失败', {
|
|
1451
|
+
error: errorMessage
|
|
1452
|
+
});
|
|
1453
|
+
return _context17.abrupt("return", {
|
|
1454
|
+
code: 500,
|
|
1455
|
+
message: errorMessage,
|
|
1456
|
+
data: {
|
|
1457
|
+
list: [],
|
|
1458
|
+
count: 0
|
|
1459
|
+
},
|
|
1460
|
+
status: false
|
|
1461
|
+
});
|
|
1462
|
+
case 18:
|
|
1463
|
+
case "end":
|
|
1464
|
+
return _context17.stop();
|
|
1465
|
+
}
|
|
1466
|
+
}, _callee17, this, [[3, 13]]);
|
|
1467
|
+
}));
|
|
1468
|
+
function fetchBookingListFromAPI(_x20) {
|
|
1469
|
+
return _fetchBookingListFromAPI.apply(this, arguments);
|
|
1470
|
+
}
|
|
1471
|
+
return fetchBookingListFromAPI;
|
|
1472
|
+
}())
|
|
1473
|
+
}, {
|
|
1474
|
+
key: "computeOrderQueryResult",
|
|
1475
|
+
value: (
|
|
1476
|
+
/**
|
|
1477
|
+
* 订单列表本地计算(编排 Order 模块)
|
|
1478
|
+
* filter 逻辑暂为 mock,仅记录参数
|
|
1479
|
+
*/
|
|
1480
|
+
function () {
|
|
1481
|
+
var _computeOrderQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(data) {
|
|
1482
|
+
var rawList, result;
|
|
1483
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1484
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1485
|
+
case 0:
|
|
1486
|
+
this.logInfo('computeOrderQueryResult: 开始过滤', {
|
|
1487
|
+
data: data
|
|
1488
|
+
});
|
|
1489
|
+
console.log('[Server] computeOrderQueryResult', data);
|
|
1490
|
+
if (this.order) {
|
|
1491
|
+
_context18.next = 5;
|
|
1492
|
+
break;
|
|
1493
|
+
}
|
|
1494
|
+
this.logError('computeOrderQueryResult: Order 模块未注册');
|
|
1495
|
+
return _context18.abrupt("return", {
|
|
1496
|
+
code: 500,
|
|
1497
|
+
message: 'Order 模块未注册',
|
|
1498
|
+
data: {
|
|
1499
|
+
list: [],
|
|
1500
|
+
count: 0
|
|
1501
|
+
},
|
|
1502
|
+
status: false
|
|
1503
|
+
});
|
|
1504
|
+
case 5:
|
|
1505
|
+
rawList = this.order.getOrders();
|
|
1506
|
+
this.logInfo('computeOrderQueryResult: 本地订单数量', {
|
|
1507
|
+
rawCount: rawList.length
|
|
1508
|
+
});
|
|
1509
|
+
|
|
1510
|
+
// 使用 filterOrders 进行过滤、排序、分页
|
|
1511
|
+
result = filterOrders(rawList, data);
|
|
1512
|
+
this.logInfo('computeOrderQueryResult: 过滤结果', {
|
|
1513
|
+
rawCount: rawList.length,
|
|
1514
|
+
filteredCount: result.count,
|
|
1515
|
+
size: result.size,
|
|
1516
|
+
skip: result.skip
|
|
1517
|
+
});
|
|
1518
|
+
return _context18.abrupt("return", {
|
|
1519
|
+
code: 200,
|
|
1520
|
+
data: result,
|
|
1521
|
+
message: '',
|
|
1522
|
+
status: true
|
|
1523
|
+
});
|
|
1524
|
+
case 10:
|
|
1525
|
+
case "end":
|
|
1526
|
+
return _context18.stop();
|
|
1527
|
+
}
|
|
1528
|
+
}, _callee18, this);
|
|
1529
|
+
}));
|
|
1530
|
+
function computeOrderQueryResult(_x21) {
|
|
1531
|
+
return _computeOrderQueryResult.apply(this, arguments);
|
|
1532
|
+
}
|
|
1533
|
+
return computeOrderQueryResult;
|
|
1534
|
+
}()
|
|
1535
|
+
/**
|
|
1536
|
+
* 预约列表本地计算(编排 Order 模块)
|
|
1537
|
+
* 从订单中展开 bookings,再按条件筛选 + 分页
|
|
1538
|
+
*/
|
|
1539
|
+
)
|
|
1540
|
+
}, {
|
|
1541
|
+
key: "computeBookingQueryResult",
|
|
1542
|
+
value: (function () {
|
|
1543
|
+
var _computeBookingQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(data) {
|
|
1544
|
+
var rawOrders, result;
|
|
1545
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1546
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1547
|
+
case 0:
|
|
1548
|
+
if (this.order) {
|
|
1549
|
+
_context19.next = 3;
|
|
1550
|
+
break;
|
|
1551
|
+
}
|
|
1552
|
+
this.logError('computeBookingQueryResult: Order 模块未注册');
|
|
1553
|
+
return _context19.abrupt("return", {
|
|
1554
|
+
code: 500,
|
|
1555
|
+
message: 'Order 模块未注册',
|
|
1556
|
+
data: {
|
|
1557
|
+
list: [],
|
|
1558
|
+
count: 0
|
|
1559
|
+
},
|
|
1560
|
+
status: false
|
|
1561
|
+
});
|
|
1562
|
+
case 3:
|
|
1563
|
+
rawOrders = this.order.getOrders();
|
|
1564
|
+
result = filterBookingsFromOrders(rawOrders, data);
|
|
1565
|
+
result = sortBookings(result, data);
|
|
1566
|
+
this.logInfo('computeBookingQueryResult: 过滤结果', {
|
|
1567
|
+
orderCount: rawOrders.length,
|
|
1568
|
+
filteredCount: result.count,
|
|
1569
|
+
size: result.size,
|
|
1570
|
+
skip: result.skip
|
|
1571
|
+
});
|
|
1572
|
+
return _context19.abrupt("return", {
|
|
1573
|
+
code: 200,
|
|
1574
|
+
data: result,
|
|
1575
|
+
message: '',
|
|
1576
|
+
status: true
|
|
1577
|
+
});
|
|
1578
|
+
case 8:
|
|
1579
|
+
case "end":
|
|
1580
|
+
return _context19.stop();
|
|
1581
|
+
}
|
|
1582
|
+
}, _callee19, this);
|
|
1583
|
+
}));
|
|
1584
|
+
function computeBookingQueryResult(_x22) {
|
|
1585
|
+
return _computeBookingQueryResult.apply(this, arguments);
|
|
1586
|
+
}
|
|
1587
|
+
return computeBookingQueryResult;
|
|
1588
|
+
}()
|
|
1589
|
+
/**
|
|
1590
|
+
* 商品查询的核心计算逻辑(编排 Products、Menu、Schedule 模块)
|
|
1591
|
+
* 供 handleProductQuery 首次返回及 pubsub 变更推送复用
|
|
1592
|
+
* @param context 查询上下文
|
|
1593
|
+
* @param options 可选参数
|
|
1594
|
+
* @param options.changedIds 变更的商品 IDs,用于增量更新价格缓存
|
|
1595
|
+
*/
|
|
1596
|
+
)
|
|
1597
|
+
}, {
|
|
1598
|
+
key: "computeProductQueryResult",
|
|
1599
|
+
value: (function () {
|
|
1600
|
+
var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(context, options) {
|
|
1601
|
+
var _menu_list_ids$length3,
|
|
1602
|
+
_this5 = this;
|
|
1603
|
+
var tTotal, menu_list_ids, schedule_date, schedule_datetime, activeMenuList, tMenu, menuList, tPrice, allProductsWithPrice, tFilter, filteredProducts, tStatus, beforeStatusCount, tSort;
|
|
1604
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1605
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1606
|
+
case 0:
|
|
1607
|
+
tTotal = performance.now();
|
|
1608
|
+
menu_list_ids = context.menu_list_ids, schedule_date = context.schedule_date, schedule_datetime = context.schedule_datetime;
|
|
1609
|
+
this.logInfo('computeProductQueryResult 开始', {
|
|
1610
|
+
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,
|
|
1611
|
+
schedule_datetime: schedule_datetime,
|
|
1612
|
+
schedule_date: schedule_date,
|
|
1613
|
+
changedIds: options === null || options === void 0 ? void 0 : options.changedIds
|
|
1614
|
+
});
|
|
1615
|
+
if (this.products) {
|
|
1616
|
+
_context20.next = 6;
|
|
1617
|
+
break;
|
|
1618
|
+
}
|
|
1619
|
+
this.logError('computeProductQueryResult: Products 模块未注册');
|
|
1620
|
+
return _context20.abrupt("return", {
|
|
1621
|
+
message: 'Products 模块未注册',
|
|
1622
|
+
data: {
|
|
1623
|
+
list: [],
|
|
1624
|
+
count: 0
|
|
1625
|
+
}
|
|
1626
|
+
});
|
|
1627
|
+
case 6:
|
|
1628
|
+
if (this.menu) {
|
|
1629
|
+
_context20.next = 9;
|
|
1630
|
+
break;
|
|
1631
|
+
}
|
|
1632
|
+
this.logError('computeProductQueryResult: Menu 模块未注册');
|
|
1633
|
+
return _context20.abrupt("return", {
|
|
1634
|
+
message: 'Menu 模块未注册',
|
|
1635
|
+
data: {
|
|
1636
|
+
list: [],
|
|
1637
|
+
count: 0
|
|
1638
|
+
}
|
|
1639
|
+
});
|
|
1640
|
+
case 9:
|
|
1641
|
+
if (this.schedule) {
|
|
1642
|
+
_context20.next = 12;
|
|
1643
|
+
break;
|
|
1644
|
+
}
|
|
1645
|
+
this.logError('computeProductQueryResult: Schedule 模块未注册');
|
|
1646
|
+
return _context20.abrupt("return", {
|
|
1647
|
+
message: 'Schedule 模块未注册',
|
|
1648
|
+
data: {
|
|
1649
|
+
list: [],
|
|
1650
|
+
count: 0
|
|
1651
|
+
}
|
|
1652
|
+
});
|
|
1653
|
+
case 12:
|
|
1654
|
+
activeMenuList = [];
|
|
1655
|
+
if (menu_list_ids && Array.isArray(menu_list_ids) && menu_list_ids.length > 0) {
|
|
1656
|
+
tMenu = performance.now();
|
|
1657
|
+
menuList = this.menu.getMenuByIds(menu_list_ids);
|
|
1658
|
+
activeMenuList = menuList.filter(function (menu) {
|
|
1659
|
+
var _this5$schedule;
|
|
1660
|
+
return ((_this5$schedule = _this5.schedule) === null || _this5$schedule === void 0 ? void 0 : _this5$schedule.getDateIsInSchedule(schedule_datetime, menu.schedule)) || false;
|
|
1661
|
+
});
|
|
1662
|
+
perfMark('computeQuery.filterActiveMenu', performance.now() - tMenu, {
|
|
1663
|
+
totalMenu: menuList.length,
|
|
1664
|
+
activeMenu: activeMenuList.length
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
tPrice = performance.now();
|
|
1668
|
+
_context20.next = 17;
|
|
1669
|
+
return this.products.getProductsWithPrice(schedule_date, {
|
|
1670
|
+
scheduleModule: this.getSchedule()
|
|
1671
|
+
}, {
|
|
1672
|
+
changedIds: options === null || options === void 0 ? void 0 : options.changedIds
|
|
1673
|
+
});
|
|
1674
|
+
case 17:
|
|
1675
|
+
allProductsWithPrice = _context20.sent;
|
|
1676
|
+
perfMark('computeQuery.getProductsWithPrice', performance.now() - tPrice, {
|
|
1677
|
+
count: allProductsWithPrice.length
|
|
1678
|
+
});
|
|
1679
|
+
tFilter = performance.now();
|
|
1680
|
+
filteredProducts = this.filterProductsByMenuConfig(allProductsWithPrice, activeMenuList);
|
|
1681
|
+
perfMark('computeQuery.filterByMenu', performance.now() - tFilter, {
|
|
1682
|
+
before: allProductsWithPrice.length,
|
|
1683
|
+
after: filteredProducts.length
|
|
1684
|
+
});
|
|
1685
|
+
tStatus = performance.now();
|
|
1686
|
+
beforeStatusCount = filteredProducts.length;
|
|
1687
|
+
filteredProducts = filteredProducts.filter(function (p) {
|
|
1688
|
+
return ((p === null || p === void 0 ? void 0 : p.status) || "published") === 'published';
|
|
1689
|
+
});
|
|
1690
|
+
perfMark('computeQuery.filterByStatus', performance.now() - tStatus, {
|
|
1691
|
+
before: beforeStatusCount,
|
|
1692
|
+
after: filteredProducts.length
|
|
1693
|
+
});
|
|
1694
|
+
tSort = performance.now();
|
|
1695
|
+
filteredProducts = filteredProducts.sort(function (a, b) {
|
|
1696
|
+
var sortDiff = Number(b.sort) - Number(a.sort);
|
|
1697
|
+
if (sortDiff !== 0) return sortDiff;
|
|
1698
|
+
return (a.title || '').localeCompare(b.title || '');
|
|
1699
|
+
});
|
|
1700
|
+
perfMark('computeQuery.sort', performance.now() - tSort, {
|
|
1701
|
+
count: filteredProducts.length
|
|
1702
|
+
});
|
|
1703
|
+
perfMark('computeProductQueryResult', performance.now() - tTotal, {
|
|
1704
|
+
originalCount: allProductsWithPrice.length,
|
|
1705
|
+
filteredCount: filteredProducts.length,
|
|
1706
|
+
activeMenuCount: activeMenuList.length
|
|
1707
|
+
});
|
|
1708
|
+
this.logInfo('computeProductQueryResult 完成', {
|
|
1709
|
+
originalCount: allProductsWithPrice.length,
|
|
1710
|
+
filteredCount: filteredProducts.length,
|
|
1711
|
+
activeMenuCount: activeMenuList.length
|
|
1712
|
+
});
|
|
1713
|
+
return _context20.abrupt("return", {
|
|
1714
|
+
code: 200,
|
|
1715
|
+
data: {
|
|
1716
|
+
list: filteredProducts,
|
|
1717
|
+
count: filteredProducts.length
|
|
1718
|
+
},
|
|
1719
|
+
message: '',
|
|
1720
|
+
status: true
|
|
1721
|
+
});
|
|
1722
|
+
case 32:
|
|
1723
|
+
case "end":
|
|
1724
|
+
return _context20.stop();
|
|
1725
|
+
}
|
|
1726
|
+
}, _callee20, this);
|
|
1727
|
+
}));
|
|
1728
|
+
function computeProductQueryResult(_x23, _x24) {
|
|
1729
|
+
return _computeProductQueryResult.apply(this, arguments);
|
|
1730
|
+
}
|
|
1731
|
+
return computeProductQueryResult;
|
|
1732
|
+
}()
|
|
1733
|
+
/**
|
|
1734
|
+
* 数据变更后,遍历所有订阅者重新计算查询结果并通过 callback 推送
|
|
1735
|
+
* 由 ProductsModule 的 onProductsSyncCompleted 事件触发
|
|
1736
|
+
* @param options 可选参数
|
|
1737
|
+
* @param options.changedIds 变更的商品 IDs,用于增量更新价格缓存
|
|
1738
|
+
*/
|
|
1739
|
+
)
|
|
1740
|
+
}, {
|
|
1741
|
+
key: "recomputeAndNotifyProductQuery",
|
|
1742
|
+
value: (function () {
|
|
1743
|
+
var _recomputeAndNotifyProductQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(options) {
|
|
1744
|
+
var _iterator3, _step3, _step3$value, subscriberId, subscriber, result, errorMessage;
|
|
1745
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1746
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1747
|
+
case 0:
|
|
1748
|
+
if (!(this.productQuerySubscribers.size === 0)) {
|
|
1749
|
+
_context21.next = 2;
|
|
1750
|
+
break;
|
|
1751
|
+
}
|
|
1752
|
+
return _context21.abrupt("return");
|
|
1753
|
+
case 2:
|
|
1754
|
+
this.logInfo('recomputeAndNotifyProductQuery: 开始推送', {
|
|
1755
|
+
subscriberCount: this.productQuerySubscribers.size,
|
|
1756
|
+
changedIds: options === null || options === void 0 ? void 0 : options.changedIds
|
|
1757
|
+
});
|
|
1758
|
+
_iterator3 = _createForOfIteratorHelper(this.productQuerySubscribers.entries());
|
|
1759
|
+
_context21.prev = 4;
|
|
1760
|
+
_iterator3.s();
|
|
1761
|
+
case 6:
|
|
1762
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
1763
|
+
_context21.next = 22;
|
|
1764
|
+
break;
|
|
1765
|
+
}
|
|
1766
|
+
_step3$value = _slicedToArray(_step3.value, 2), subscriberId = _step3$value[0], subscriber = _step3$value[1];
|
|
1767
|
+
_context21.prev = 8;
|
|
1768
|
+
_context21.next = 11;
|
|
1769
|
+
return this.computeProductQueryResult(subscriber.context, {
|
|
1770
|
+
changedIds: options === null || options === void 0 ? void 0 : options.changedIds
|
|
1771
|
+
});
|
|
1772
|
+
case 11:
|
|
1773
|
+
result = _context21.sent;
|
|
1774
|
+
subscriber.callback(result);
|
|
1775
|
+
this.logInfo('recomputeAndNotifyProductQuery: 已推送', {
|
|
1776
|
+
subscriberId: subscriberId
|
|
1777
|
+
});
|
|
1778
|
+
_context21.next = 20;
|
|
1779
|
+
break;
|
|
1780
|
+
case 16:
|
|
1781
|
+
_context21.prev = 16;
|
|
1782
|
+
_context21.t0 = _context21["catch"](8);
|
|
1783
|
+
errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
|
|
1784
|
+
this.logError('recomputeAndNotifyProductQuery: 推送失败', {
|
|
1785
|
+
subscriberId: subscriberId,
|
|
1786
|
+
error: errorMessage
|
|
1787
|
+
});
|
|
1788
|
+
case 20:
|
|
1789
|
+
_context21.next = 6;
|
|
1790
|
+
break;
|
|
1791
|
+
case 22:
|
|
1792
|
+
_context21.next = 27;
|
|
1793
|
+
break;
|
|
1794
|
+
case 24:
|
|
1795
|
+
_context21.prev = 24;
|
|
1796
|
+
_context21.t1 = _context21["catch"](4);
|
|
1797
|
+
_iterator3.e(_context21.t1);
|
|
1798
|
+
case 27:
|
|
1799
|
+
_context21.prev = 27;
|
|
1800
|
+
_iterator3.f();
|
|
1801
|
+
return _context21.finish(27);
|
|
1802
|
+
case 30:
|
|
1803
|
+
case "end":
|
|
1804
|
+
return _context21.stop();
|
|
1805
|
+
}
|
|
1806
|
+
}, _callee21, this, [[4, 24, 27, 30], [8, 16]]);
|
|
1807
|
+
}));
|
|
1808
|
+
function recomputeAndNotifyProductQuery(_x25) {
|
|
1809
|
+
return _recomputeAndNotifyProductQuery.apply(this, arguments);
|
|
1810
|
+
}
|
|
1811
|
+
return recomputeAndNotifyProductQuery;
|
|
1812
|
+
}()
|
|
1813
|
+
/**
|
|
1814
|
+
* 订单数据变更后,遍历订阅者重新计算并通过 callback 推送
|
|
1815
|
+
*/
|
|
1816
|
+
)
|
|
1817
|
+
}, {
|
|
1818
|
+
key: "recomputeAndNotifyOrderQuery",
|
|
1819
|
+
value: (function () {
|
|
1820
|
+
var _recomputeAndNotifyOrderQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
|
|
1821
|
+
var _iterator4, _step4, _step4$value, subscriberId, subscriber, result, errorMessage;
|
|
1822
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1823
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1824
|
+
case 0:
|
|
1825
|
+
if (!(this.orderQuerySubscribers.size === 0)) {
|
|
1826
|
+
_context22.next = 2;
|
|
1827
|
+
break;
|
|
1828
|
+
}
|
|
1829
|
+
return _context22.abrupt("return");
|
|
1830
|
+
case 2:
|
|
1831
|
+
this.logInfo('recomputeAndNotifyOrderQuery: 开始推送', {
|
|
1832
|
+
subscriberCount: this.orderQuerySubscribers.size
|
|
1833
|
+
});
|
|
1834
|
+
_iterator4 = _createForOfIteratorHelper(this.orderQuerySubscribers.entries());
|
|
1835
|
+
_context22.prev = 4;
|
|
1836
|
+
_iterator4.s();
|
|
1837
|
+
case 6:
|
|
1838
|
+
if ((_step4 = _iterator4.n()).done) {
|
|
1839
|
+
_context22.next = 22;
|
|
1840
|
+
break;
|
|
1841
|
+
}
|
|
1842
|
+
_step4$value = _slicedToArray(_step4.value, 2), subscriberId = _step4$value[0], subscriber = _step4$value[1];
|
|
1843
|
+
_context22.prev = 8;
|
|
1844
|
+
_context22.next = 11;
|
|
1845
|
+
return this.computeOrderQueryResult(subscriber.context);
|
|
1846
|
+
case 11:
|
|
1847
|
+
result = _context22.sent;
|
|
1848
|
+
subscriber.callback(result);
|
|
1849
|
+
this.logInfo('recomputeAndNotifyOrderQuery: 已推送', {
|
|
1850
|
+
subscriberId: subscriberId
|
|
1851
|
+
});
|
|
1852
|
+
_context22.next = 20;
|
|
1853
|
+
break;
|
|
1854
|
+
case 16:
|
|
1855
|
+
_context22.prev = 16;
|
|
1856
|
+
_context22.t0 = _context22["catch"](8);
|
|
1857
|
+
errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0);
|
|
1858
|
+
this.logError('recomputeAndNotifyOrderQuery: 推送失败', {
|
|
1859
|
+
subscriberId: subscriberId,
|
|
1860
|
+
error: errorMessage
|
|
1861
|
+
});
|
|
1862
|
+
case 20:
|
|
1863
|
+
_context22.next = 6;
|
|
1864
|
+
break;
|
|
1865
|
+
case 22:
|
|
1866
|
+
_context22.next = 27;
|
|
1867
|
+
break;
|
|
1868
|
+
case 24:
|
|
1869
|
+
_context22.prev = 24;
|
|
1870
|
+
_context22.t1 = _context22["catch"](4);
|
|
1871
|
+
_iterator4.e(_context22.t1);
|
|
1872
|
+
case 27:
|
|
1873
|
+
_context22.prev = 27;
|
|
1874
|
+
_iterator4.f();
|
|
1875
|
+
return _context22.finish(27);
|
|
1876
|
+
case 30:
|
|
1877
|
+
case "end":
|
|
1878
|
+
return _context22.stop();
|
|
1879
|
+
}
|
|
1880
|
+
}, _callee22, this, [[4, 24, 27, 30], [8, 16]]);
|
|
1881
|
+
}));
|
|
1882
|
+
function recomputeAndNotifyOrderQuery() {
|
|
1883
|
+
return _recomputeAndNotifyOrderQuery.apply(this, arguments);
|
|
1884
|
+
}
|
|
1885
|
+
return recomputeAndNotifyOrderQuery;
|
|
1886
|
+
}()
|
|
1887
|
+
/**
|
|
1888
|
+
* 预约数据变更后,遍历订阅者重新计算并通过 callback 推送
|
|
1889
|
+
*/
|
|
1890
|
+
)
|
|
1891
|
+
}, {
|
|
1892
|
+
key: "recomputeAndNotifyBookingQuery",
|
|
1893
|
+
value: (function () {
|
|
1894
|
+
var _recomputeAndNotifyBookingQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
|
|
1895
|
+
var _iterator5, _step5, _step5$value, subscriberId, subscriber, result, errorMessage;
|
|
1896
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1897
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1898
|
+
case 0:
|
|
1899
|
+
if (!(this.bookingQuerySubscribers.size === 0)) {
|
|
1900
|
+
_context23.next = 2;
|
|
1901
|
+
break;
|
|
1902
|
+
}
|
|
1903
|
+
return _context23.abrupt("return");
|
|
1904
|
+
case 2:
|
|
1905
|
+
this.logInfo('recomputeAndNotifyBookingQuery: 开始推送', {
|
|
1906
|
+
subscriberCount: this.bookingQuerySubscribers.size
|
|
1907
|
+
});
|
|
1908
|
+
_iterator5 = _createForOfIteratorHelper(this.bookingQuerySubscribers.entries());
|
|
1909
|
+
_context23.prev = 4;
|
|
1910
|
+
_iterator5.s();
|
|
1911
|
+
case 6:
|
|
1912
|
+
if ((_step5 = _iterator5.n()).done) {
|
|
1913
|
+
_context23.next = 22;
|
|
1914
|
+
break;
|
|
1915
|
+
}
|
|
1916
|
+
_step5$value = _slicedToArray(_step5.value, 2), subscriberId = _step5$value[0], subscriber = _step5$value[1];
|
|
1917
|
+
_context23.prev = 8;
|
|
1918
|
+
_context23.next = 11;
|
|
1919
|
+
return this.computeBookingQueryResult(subscriber.context);
|
|
1920
|
+
case 11:
|
|
1921
|
+
result = _context23.sent;
|
|
1922
|
+
subscriber.callback(result);
|
|
1923
|
+
this.logInfo('recomputeAndNotifyBookingQuery: 已推送', {
|
|
1924
|
+
subscriberId: subscriberId
|
|
1925
|
+
});
|
|
1926
|
+
_context23.next = 20;
|
|
1927
|
+
break;
|
|
1928
|
+
case 16:
|
|
1929
|
+
_context23.prev = 16;
|
|
1930
|
+
_context23.t0 = _context23["catch"](8);
|
|
1931
|
+
errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
|
|
1932
|
+
this.logError('recomputeAndNotifyBookingQuery: 推送失败', {
|
|
1933
|
+
subscriberId: subscriberId,
|
|
1934
|
+
error: errorMessage
|
|
1935
|
+
});
|
|
1936
|
+
case 20:
|
|
1937
|
+
_context23.next = 6;
|
|
1938
|
+
break;
|
|
1939
|
+
case 22:
|
|
1940
|
+
_context23.next = 27;
|
|
1941
|
+
break;
|
|
1942
|
+
case 24:
|
|
1943
|
+
_context23.prev = 24;
|
|
1944
|
+
_context23.t1 = _context23["catch"](4);
|
|
1945
|
+
_iterator5.e(_context23.t1);
|
|
1946
|
+
case 27:
|
|
1947
|
+
_context23.prev = 27;
|
|
1948
|
+
_iterator5.f();
|
|
1949
|
+
return _context23.finish(27);
|
|
1950
|
+
case 30:
|
|
1951
|
+
case "end":
|
|
1952
|
+
return _context23.stop();
|
|
1953
|
+
}
|
|
1954
|
+
}, _callee23, this, [[4, 24, 27, 30], [8, 16]]);
|
|
1955
|
+
}));
|
|
1956
|
+
function recomputeAndNotifyBookingQuery() {
|
|
1957
|
+
return _recomputeAndNotifyBookingQuery.apply(this, arguments);
|
|
1958
|
+
}
|
|
1959
|
+
return recomputeAndNotifyBookingQuery;
|
|
1960
|
+
}()
|
|
842
1961
|
/**
|
|
843
1962
|
* 根据餐牌配置过滤商品
|
|
844
1963
|
* @param products 所有商品列表
|
|
@@ -846,10 +1965,17 @@ var Server = /*#__PURE__*/function () {
|
|
|
846
1965
|
* @returns 过滤后的商品列表
|
|
847
1966
|
* @private
|
|
848
1967
|
*/
|
|
849
|
-
|
|
1968
|
+
)
|
|
1969
|
+
}, {
|
|
1970
|
+
key: "filterProductsByMenuConfig",
|
|
1971
|
+
value: function filterProductsByMenuConfig(products, activeMenuList) {
|
|
850
1972
|
// 如果没有生效的餐牌,返回空数组
|
|
851
1973
|
if (!activeMenuList || activeMenuList.length === 0) {
|
|
852
1974
|
console.log('[Server] 没有生效的餐牌,返回空数组');
|
|
1975
|
+
this.logInfo('filterProductsByMenuConfig: 没有生效的餐牌,返回空数组', {
|
|
1976
|
+
productCount: products.length,
|
|
1977
|
+
activeMenuCount: 0
|
|
1978
|
+
});
|
|
853
1979
|
return [];
|
|
854
1980
|
}
|
|
855
1981
|
|
|
@@ -857,20 +1983,29 @@ var Server = /*#__PURE__*/function () {
|
|
|
857
1983
|
var allowedProductIds = new Set();
|
|
858
1984
|
var allowedCollectionIds = new Set();
|
|
859
1985
|
var hasProductAll = false;
|
|
860
|
-
var
|
|
861
|
-
|
|
1986
|
+
var _iterator6 = _createForOfIteratorHelper(activeMenuList),
|
|
1987
|
+
_step6;
|
|
862
1988
|
try {
|
|
863
|
-
for (
|
|
864
|
-
var menu =
|
|
1989
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
1990
|
+
var menu = _step6.value;
|
|
865
1991
|
var config = menu.partyroom_package;
|
|
866
1992
|
if (!config) {
|
|
867
1993
|
console.warn('[Server] 餐牌缺少 partyroom_package 配置:', menu);
|
|
1994
|
+
this.logWarning('filterProductsByMenuConfig: 餐牌缺少 partyroom_package 配置', {
|
|
1995
|
+
menuId: menu.form_record_id,
|
|
1996
|
+
menuName: menu.name
|
|
1997
|
+
});
|
|
868
1998
|
continue;
|
|
869
1999
|
}
|
|
870
2000
|
|
|
871
2001
|
// 如果有任何一个餐牌是 product_all,则返回所有商品
|
|
872
2002
|
if (config.type === 'product_all') {
|
|
873
2003
|
console.log('[Server] 餐牌允许所有商品:', menu.name);
|
|
2004
|
+
this.logInfo('filterProductsByMenuConfig: 餐牌允许所有商品', {
|
|
2005
|
+
menuId: menu.form_record_id,
|
|
2006
|
+
menuName: menu.name,
|
|
2007
|
+
configType: config.type
|
|
2008
|
+
});
|
|
874
2009
|
hasProductAll = true;
|
|
875
2010
|
break;
|
|
876
2011
|
}
|
|
@@ -884,6 +2019,12 @@ var Server = /*#__PURE__*/function () {
|
|
|
884
2019
|
return id && allowedProductIds.add(id);
|
|
885
2020
|
});
|
|
886
2021
|
console.log('[Server] 餐牌允许指定商品 (product_ids):', menu.name, productIds);
|
|
2022
|
+
this.logInfo('filterProductsByMenuConfig: 餐牌允许指定商品', {
|
|
2023
|
+
menuId: menu.form_record_id,
|
|
2024
|
+
menuName: menu.name,
|
|
2025
|
+
configType: config.type,
|
|
2026
|
+
productIdsCount: productIds.length
|
|
2027
|
+
});
|
|
887
2028
|
}
|
|
888
2029
|
|
|
889
2030
|
// 如果是 product_collection 类型,从 ProductItemType 中提取 product_collection_id
|
|
@@ -895,26 +2036,45 @@ var Server = /*#__PURE__*/function () {
|
|
|
895
2036
|
return id && allowedCollectionIds.add(id);
|
|
896
2037
|
});
|
|
897
2038
|
console.log('[Server] 餐牌允许商品集合 (product_collection):', menu.name, collectionIds);
|
|
2039
|
+
this.logInfo('filterProductsByMenuConfig: 餐牌允许商品集合', {
|
|
2040
|
+
menuId: menu.form_record_id,
|
|
2041
|
+
menuName: menu.name,
|
|
2042
|
+
configType: config.type,
|
|
2043
|
+
collectionIdsCount: collectionIds.length
|
|
2044
|
+
});
|
|
898
2045
|
}
|
|
899
2046
|
}
|
|
900
2047
|
|
|
901
2048
|
// 如果有餐牌允许所有商品,返回所有商品
|
|
902
2049
|
} catch (err) {
|
|
903
|
-
|
|
2050
|
+
_iterator6.e(err);
|
|
904
2051
|
} finally {
|
|
905
|
-
|
|
2052
|
+
_iterator6.f();
|
|
906
2053
|
}
|
|
907
2054
|
if (hasProductAll) {
|
|
2055
|
+
this.logInfo('filterProductsByMenuConfig: 返回所有商品(product_all)', {
|
|
2056
|
+
productCount: products.length
|
|
2057
|
+
});
|
|
908
2058
|
return products;
|
|
909
2059
|
}
|
|
910
2060
|
|
|
911
2061
|
// 如果没有收集到任何商品 ID 和集合 ID,返回空数组
|
|
912
2062
|
if (allowedProductIds.size === 0 && allowedCollectionIds.size === 0) {
|
|
913
2063
|
console.log('[Server] 没有允许的商品和集合');
|
|
2064
|
+
this.logWarning('filterProductsByMenuConfig: 没有允许的商品和集合', {
|
|
2065
|
+
productCount: products.length,
|
|
2066
|
+
activeMenuCount: activeMenuList.length
|
|
2067
|
+
});
|
|
914
2068
|
return [];
|
|
915
2069
|
}
|
|
916
|
-
|
|
917
|
-
|
|
2070
|
+
var allowedProductIdsArray = Array.from(allowedProductIds);
|
|
2071
|
+
var allowedCollectionIdsArray = Array.from(allowedCollectionIds);
|
|
2072
|
+
console.log('[Server] 允许的商品 IDs:', allowedProductIdsArray);
|
|
2073
|
+
console.log('[Server] 允许的集合 IDs:', allowedCollectionIdsArray);
|
|
2074
|
+
this.logInfo('filterProductsByMenuConfig: 收集到的允许规则', {
|
|
2075
|
+
allowedProductCount: allowedProductIds.size,
|
|
2076
|
+
allowedCollectionCount: allowedCollectionIds.size
|
|
2077
|
+
});
|
|
918
2078
|
|
|
919
2079
|
// 过滤商品
|
|
920
2080
|
var filteredProducts = products.filter(function (product) {
|
|
@@ -935,8 +2095,76 @@ var Server = /*#__PURE__*/function () {
|
|
|
935
2095
|
return false;
|
|
936
2096
|
});
|
|
937
2097
|
console.log('[Server] 过滤结果: 原始 %d 个,过滤后 %d 个', products.length, filteredProducts.length);
|
|
2098
|
+
this.logInfo('filterProductsByMenuConfig: 过滤完成', {
|
|
2099
|
+
originalCount: products.length,
|
|
2100
|
+
filteredCount: filteredProducts.length,
|
|
2101
|
+
removedCount: products.length - filteredProducts.length
|
|
2102
|
+
});
|
|
938
2103
|
return filteredProducts;
|
|
939
2104
|
}
|
|
2105
|
+
|
|
2106
|
+
/**
|
|
2107
|
+
* 记录信息日志
|
|
2108
|
+
* @param title 日志标题
|
|
2109
|
+
* @param metadata 日志元数据
|
|
2110
|
+
*/
|
|
2111
|
+
}, {
|
|
2112
|
+
key: "logInfo",
|
|
2113
|
+
value: function logInfo(title, metadata) {
|
|
2114
|
+
try {
|
|
2115
|
+
if (this.logger) {
|
|
2116
|
+
this.logger.addLog({
|
|
2117
|
+
type: 'info',
|
|
2118
|
+
title: "[Server] ".concat(title),
|
|
2119
|
+
metadata: metadata || {}
|
|
2120
|
+
});
|
|
2121
|
+
}
|
|
2122
|
+
} catch (_unused) {
|
|
2123
|
+
// 日志记录失败不影响主流程
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
/**
|
|
2128
|
+
* 记录警告日志
|
|
2129
|
+
* @param title 日志标题
|
|
2130
|
+
* @param metadata 日志元数据
|
|
2131
|
+
*/
|
|
2132
|
+
}, {
|
|
2133
|
+
key: "logWarning",
|
|
2134
|
+
value: function logWarning(title, metadata) {
|
|
2135
|
+
try {
|
|
2136
|
+
if (this.logger) {
|
|
2137
|
+
this.logger.addLog({
|
|
2138
|
+
type: 'warning',
|
|
2139
|
+
title: "[Server] ".concat(title),
|
|
2140
|
+
metadata: metadata || {}
|
|
2141
|
+
});
|
|
2142
|
+
}
|
|
2143
|
+
} catch (_unused2) {
|
|
2144
|
+
// 日志记录失败不影响主流程
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
/**
|
|
2149
|
+
* 记录错误日志
|
|
2150
|
+
* @param title 日志标题
|
|
2151
|
+
* @param metadata 日志元数据
|
|
2152
|
+
*/
|
|
2153
|
+
}, {
|
|
2154
|
+
key: "logError",
|
|
2155
|
+
value: function logError(title, metadata) {
|
|
2156
|
+
try {
|
|
2157
|
+
if (this.logger) {
|
|
2158
|
+
this.logger.addLog({
|
|
2159
|
+
type: 'error',
|
|
2160
|
+
title: "[Server] ".concat(title),
|
|
2161
|
+
metadata: metadata || {}
|
|
2162
|
+
});
|
|
2163
|
+
}
|
|
2164
|
+
} catch (_unused3) {
|
|
2165
|
+
// 日志记录失败不影响主流程
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
940
2168
|
}]);
|
|
941
2169
|
return Server;
|
|
942
2170
|
}();
|