@pisell/pisellos 2.2.89 → 2.2.90

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.
@@ -0,0 +1,9 @@
1
+ // 导出评估器
2
+ export { PromotionEvaluator } from "./evaluator";
3
+
4
+ // 导出适配器
5
+ export { PromotionAdapter } from "./adapter";
6
+ export { default } from "./adapter";
7
+
8
+ // 导出策略配置示例常量
9
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
@@ -154,11 +154,16 @@ declare class Server {
154
154
  /**
155
155
  * 商品查询的核心计算逻辑(编排 Products、Menu、Schedule 模块)
156
156
  * 供 handleProductQuery 首次返回及 pubsub 变更推送复用
157
+ * @param context 查询上下文
158
+ * @param options 可选参数
159
+ * @param options.changedIds 变更的商品 IDs,用于增量更新价格缓存
157
160
  */
158
161
  private computeProductQueryResult;
159
162
  /**
160
163
  * 数据变更后,遍历所有订阅者重新计算查询结果并通过 callback 推送
161
164
  * 由 ProductsModule 的 onProductsSyncCompleted 事件触发
165
+ * @param options 可选参数
166
+ * @param options.changedIds 变更的商品 IDs,用于增量更新价格缓存
162
167
  */
163
168
  private recomputeAndNotifyProductQuery;
164
169
  /**
@@ -749,8 +749,10 @@ var Server = /*#__PURE__*/function () {
749
749
  });
750
750
  case 14:
751
751
  // 监听 ProductsModule 同步完成事件,重新计算并推送查询结果
752
- this.core.effects.on(ProductsHooks.onProductsSyncCompleted, function () {
753
- _this3.recomputeAndNotifyProductQuery();
752
+ this.core.effects.on(ProductsHooks.onProductsSyncCompleted, function (payload) {
753
+ _this3.recomputeAndNotifyProductQuery({
754
+ changedIds: payload === null || payload === void 0 ? void 0 : payload.changedIds
755
+ });
754
756
  });
755
757
  duration = Date.now() - startTime;
756
758
  this.logInfo('Server 初始化完成', {
@@ -1119,9 +1121,12 @@ var Server = /*#__PURE__*/function () {
1119
1121
  /**
1120
1122
  * 商品查询的核心计算逻辑(编排 Products、Menu、Schedule 模块)
1121
1123
  * 供 handleProductQuery 首次返回及 pubsub 变更推送复用
1124
+ * @param context 查询上下文
1125
+ * @param options 可选参数
1126
+ * @param options.changedIds 变更的商品 IDs,用于增量更新价格缓存
1122
1127
  */
1123
1128
  function () {
1124
- var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(context) {
1129
+ var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(context, options) {
1125
1130
  var _menu_list_ids$length3,
1126
1131
  _this5 = this;
1127
1132
  var tTotal, menu_list_ids, schedule_date, schedule_datetime, activeMenuList, tMenu, menuList, tPrice, allProductsWithPrice, tFilter, filteredProducts, tStatus, beforeStatusCount, tSort;
@@ -1133,7 +1138,8 @@ var Server = /*#__PURE__*/function () {
1133
1138
  this.logInfo('computeProductQueryResult 开始', {
1134
1139
  menuListIdsCount: (_menu_list_ids$length3 = menu_list_ids === null || menu_list_ids === void 0 ? void 0 : menu_list_ids.length) !== null && _menu_list_ids$length3 !== void 0 ? _menu_list_ids$length3 : 0,
1135
1140
  schedule_datetime: schedule_datetime,
1136
- schedule_date: schedule_date
1141
+ schedule_date: schedule_date,
1142
+ changedIds: options === null || options === void 0 ? void 0 : options.changedIds
1137
1143
  });
1138
1144
  if (this.products) {
1139
1145
  _context12.next = 6;
@@ -1191,6 +1197,8 @@ var Server = /*#__PURE__*/function () {
1191
1197
  _context12.next = 17;
1192
1198
  return this.products.getProductsWithPrice(schedule_date, {
1193
1199
  scheduleModule: this.getSchedule()
1200
+ }, {
1201
+ changedIds: options === null || options === void 0 ? void 0 : options.changedIds
1194
1202
  });
1195
1203
  case 17:
1196
1204
  allProductsWithPrice = _context12.sent;
@@ -1246,7 +1254,7 @@ var Server = /*#__PURE__*/function () {
1246
1254
  }
1247
1255
  }, _callee12, this);
1248
1256
  }));
1249
- function computeProductQueryResult(_x15) {
1257
+ function computeProductQueryResult(_x15, _x16) {
1250
1258
  return _computeProductQueryResult.apply(this, arguments);
1251
1259
  }
1252
1260
  return computeProductQueryResult;
@@ -1254,12 +1262,14 @@ var Server = /*#__PURE__*/function () {
1254
1262
  /**
1255
1263
  * 数据变更后,遍历所有订阅者重新计算查询结果并通过 callback 推送
1256
1264
  * 由 ProductsModule 的 onProductsSyncCompleted 事件触发
1265
+ * @param options 可选参数
1266
+ * @param options.changedIds 变更的商品 IDs,用于增量更新价格缓存
1257
1267
  */
1258
1268
  )
1259
1269
  }, {
1260
1270
  key: "recomputeAndNotifyProductQuery",
1261
1271
  value: (function () {
1262
- var _recomputeAndNotifyProductQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1272
+ var _recomputeAndNotifyProductQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(options) {
1263
1273
  var _iterator3, _step3, _step3$value, subscriberId, subscriber, result, errorMessage;
1264
1274
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1265
1275
  while (1) switch (_context13.prev = _context13.next) {
@@ -1271,7 +1281,8 @@ var Server = /*#__PURE__*/function () {
1271
1281
  return _context13.abrupt("return");
1272
1282
  case 2:
1273
1283
  this.logInfo('recomputeAndNotifyProductQuery: 开始推送', {
1274
- subscriberCount: this.productQuerySubscribers.size
1284
+ subscriberCount: this.productQuerySubscribers.size,
1285
+ changedIds: options === null || options === void 0 ? void 0 : options.changedIds
1275
1286
  });
1276
1287
  _iterator3 = _createForOfIteratorHelper(this.productQuerySubscribers.entries());
1277
1288
  _context13.prev = 4;
@@ -1284,7 +1295,9 @@ var Server = /*#__PURE__*/function () {
1284
1295
  _step3$value = _slicedToArray(_step3.value, 2), subscriberId = _step3$value[0], subscriber = _step3$value[1];
1285
1296
  _context13.prev = 8;
1286
1297
  _context13.next = 11;
1287
- return this.computeProductQueryResult(subscriber.context);
1298
+ return this.computeProductQueryResult(subscriber.context, {
1299
+ changedIds: options === null || options === void 0 ? void 0 : options.changedIds
1300
+ });
1288
1301
  case 11:
1289
1302
  result = _context13.sent;
1290
1303
  subscriber.callback(result);
@@ -1321,7 +1334,7 @@ var Server = /*#__PURE__*/function () {
1321
1334
  }
1322
1335
  }, _callee13, this, [[4, 24, 27, 30], [8, 16]]);
1323
1336
  }));
1324
- function recomputeAndNotifyProductQuery() {
1337
+ function recomputeAndNotifyProductQuery(_x17) {
1325
1338
  return _recomputeAndNotifyProductQuery.apply(this, arguments);
1326
1339
  }
1327
1340
  return recomputeAndNotifyProductQuery;
@@ -53,14 +53,20 @@ export declare class ProductsModule extends BaseModule implements Module {
53
53
  * 缓存的是已经应用了价格的完整商品列表,避免重复转换
54
54
  * @param schedule_date 日期
55
55
  * @param extraContext 额外的上下文数据(可选,由 Server 层传入)
56
+ * @param options 可选参数
57
+ * @param options.changedIds 变更的商品 IDs,非空时仅对这些商品增量执行 prepare 并更新缓存
56
58
  * @returns 应用了价格的商品列表
57
59
  */
58
- getProductsWithPrice(schedule_date: string, extraContext?: Partial<ProductFormatterContext>): Promise<ProductData[]>;
60
+ getProductsWithPrice(schedule_date: string, extraContext?: Partial<ProductFormatterContext>, options?: {
61
+ changedIds?: number[];
62
+ }): Promise<ProductData[]>;
59
63
  /**
60
64
  * 准备带价格的商品数据(通过格式化器流程处理)
61
65
  * @param schedule_date 日期
62
66
  * @param extraContext 额外的上下文数据(可选)
63
- * @returns 完整处理后的商品列表
67
+ * @param options 可选参数
68
+ * @param options.productIds 指定商品 IDs,仅处理这些商品;不传则处理全量
69
+ * @returns 处理后的商品列表
64
70
  * @private
65
71
  */
66
72
  private prepareProductsWithPrice;
@@ -156,11 +162,6 @@ export declare class ProductsModule extends BaseModule implements Module {
156
162
  * 用于 pubsub 同步 create / update / batch_update 场景
157
163
  */
158
164
  refreshProducts(): Promise<ProductData[]>;
159
- /**
160
- * 指定商品的报价单价格变更时,清除价格缓存
161
- * 后续查询会走完整的 formatter 管道重建缓存
162
- */
163
- updateProductPriceByIds(ids: number[]): Promise<void>;
164
165
  /**
165
166
  * 清空缓存
166
167
  */
@@ -202,14 +203,18 @@ export declare class ProductsModule extends BaseModule implements Module {
202
203
  *
203
204
  * product 模块:
204
205
  * - operation === 'delete' → 本地删除
205
- * - change_types 包含 price → SSE 增量拉取
206
+ * - change_types 包含 price → 仅收集变更 IDs(不拉商品数据)
206
207
  * - 有 body → body 完整数据直接覆盖本地
208
+ * - 其他 → SSE 增量拉取
207
209
  *
208
- * product_collection / product_category / product_quotation
210
+ * product_collection / product_category:
209
211
  * - 按 relation_product_ids SSE 拉取受影响商品
210
212
  *
211
- * 处理完成后清除价格缓存并 emit onProductsSyncCompleted,
212
- * Server 层监听该事件后重新查询,走完整的 formatter 管道重建缓存
213
+ * product_quotation:
214
+ * - 报价单变更影响范围大,直接清除价格缓存走全量重建
215
+ *
216
+ * 处理完成后 emit onProductsSyncCompleted(携带 changedIds),
217
+ * Server 层监听该事件后对变更商品增量执行 prepareProductsWithPrice 并更新缓存
213
218
  */
214
219
  private processProductSyncMessages;
215
220
  /**