@pisell/pisellos 2.2.84 → 2.2.86

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.
@@ -157,8 +157,8 @@ export declare class ProductsModule extends BaseModule implements Module {
157
157
  */
158
158
  refreshProducts(): Promise<ProductData[]>;
159
159
  /**
160
- * 局部更新指定商品的报价单价格
161
- * 遍历所有已缓存的日期,为目标商品重新获取价格并覆盖到缓存中
160
+ * 指定商品的报价单价格变更时,清除价格缓存
161
+ * 后续查询会走完整的 formatter 管道重建缓存
162
162
  */
163
163
  updateProductPriceByIds(ids: number[]): Promise<void>;
164
164
  /**
@@ -202,15 +202,14 @@ export declare class ProductsModule extends BaseModule implements Module {
202
202
  *
203
203
  * product 模块:
204
204
  * - operation === 'delete' → 本地删除
205
- * - change_types 包含 price → SSE 增量拉取 + 刷新报价单价格缓存
205
+ * - change_types 包含 price → SSE 增量拉取
206
206
  * - 有 body → body 完整数据直接覆盖本地
207
-
208
207
  *
209
208
  * product_collection / product_category / product_quotation:
210
209
  * - 按 relation_product_ids SSE 拉取受影响商品
211
- * - product_quotation 额外刷新报价单价格缓存
212
210
  *
213
- * 处理完成后 emit onProductsSyncCompleted 通知 Server 层
211
+ * 处理完成后清除价格缓存并 emit onProductsSyncCompleted
212
+ * Server 层监听该事件后重新查询,走完整的 formatter 管道重建缓存
214
213
  */
215
214
  private processProductSyncMessages;
216
215
  /**
@@ -221,7 +220,8 @@ export declare class ProductsModule extends BaseModule implements Module {
221
220
  /**
222
221
  * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
223
222
  * 已存在的 → 直接替换;不存在的 → 追加
224
- * 同时更新 Map 缓存、IndexDB,清空价格缓存,触发 onProductsChanged
223
+ * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
224
+ * 价格缓存由 processProductSyncMessages 末尾统一清除
225
225
  */
226
226
  private applyBodyUpdatesToStore;
227
227
  /**
@@ -230,16 +230,6 @@ export declare class ProductsModule extends BaseModule implements Module {
230
230
  * 同时更新 store.map、IndexDB,触发 onProductsChanged
231
231
  */
232
232
  private mergeProductsToStore;
233
- /**
234
- * 增量更新价格缓存中变更的商品
235
- * 对每个已缓存的日期 key:替换/追加最新商品数据,重新拉取这些 ID 的价格并应用
236
- */
237
- private updatePriceCacheForProducts;
238
- /**
239
- * 全量重新拉取报价单价格并重建价格缓存
240
- * 遍历当前已缓存的所有日期 key,对每个日期重新调用 loadProductsPrice
241
- */
242
- private refreshAllPriceCache;
243
233
  /**
244
234
  * 静默全量刷新:后台重新拉取全量 SSE 数据并更新本地
245
235
  * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
@@ -1013,76 +1013,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1013
1013
  return refreshProducts;
1014
1014
  }()
1015
1015
  /**
1016
- * 局部更新指定商品的报价单价格
1017
- * 遍历所有已缓存的日期,为目标商品重新获取价格并覆盖到缓存中
1016
+ * 指定商品的报价单价格变更时,清除价格缓存
1017
+ * 后续查询会走完整的 formatter 管道重建缓存
1018
1018
  */
1019
1019
  )
1020
1020
  }, {
1021
1021
  key: "updateProductPriceByIds",
1022
1022
  value: (function () {
1023
1023
  var _updateProductPriceByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(ids) {
1024
- var _iterator4, _step4, _step4$value, dateKey, cachedProducts, priceData, updatedProducts, errorMessage;
1025
1024
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1026
1025
  while (1) switch (_context13.prev = _context13.next) {
1027
1026
  case 0:
1028
- this.logInfo('updateProductPriceByIds', {
1027
+ this.logInfo('updateProductPriceByIds: 清除价格缓存', {
1029
1028
  ids: ids
1030
1029
  });
1031
- _iterator4 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1032
- _context13.prev = 2;
1033
- _iterator4.s();
1034
- case 4:
1035
- if ((_step4 = _iterator4.n()).done) {
1036
- _context13.next = 19;
1037
- break;
1038
- }
1039
- _step4$value = _slicedToArray(_step4.value, 2), dateKey = _step4$value[0], cachedProducts = _step4$value[1];
1040
- _context13.prev = 6;
1041
- _context13.next = 9;
1042
- return this.loadProductsPrice({
1043
- ids: ids,
1044
- schedule_date: dateKey
1045
- });
1046
- case 9:
1047
- priceData = _context13.sent;
1048
- if (priceData && priceData.length > 0) {
1049
- updatedProducts = applyPriceDataToProducts(cachedProducts, priceData);
1050
- this.productsPriceCache.set(dateKey, updatedProducts);
1051
- this.logInfo('updateProductPriceByIds: 缓存已更新', {
1052
- dateKey: dateKey,
1053
- priceDataCount: priceData.length
1054
- });
1055
- }
1056
- _context13.next = 17;
1057
- break;
1058
- case 13:
1059
- _context13.prev = 13;
1060
- _context13.t0 = _context13["catch"](6);
1061
- errorMessage = _context13.t0 instanceof Error ? _context13.t0.message : String(_context13.t0);
1062
- this.logError('updateProductPriceByIds: 失败', {
1063
- dateKey: dateKey,
1064
- ids: ids,
1065
- error: errorMessage
1066
- });
1067
- case 17:
1068
- _context13.next = 4;
1069
- break;
1070
- case 19:
1071
- _context13.next = 24;
1072
- break;
1073
- case 21:
1074
- _context13.prev = 21;
1075
- _context13.t1 = _context13["catch"](2);
1076
- _iterator4.e(_context13.t1);
1077
- case 24:
1078
- _context13.prev = 24;
1079
- _iterator4.f();
1080
- return _context13.finish(24);
1081
- case 27:
1030
+ this.clearPriceCache();
1031
+ case 2:
1082
1032
  case "end":
1083
1033
  return _context13.stop();
1084
1034
  }
1085
- }, _callee13, this, [[2, 21, 24, 27], [6, 13]]);
1035
+ }, _callee13, this);
1086
1036
  }));
1087
1037
  function updateProductPriceByIds(_x14) {
1088
1038
  return _updateProductPriceByIds.apply(this, arguments);
@@ -1267,17 +1217,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1267
1217
  value: function syncProductsMap() {
1268
1218
  var t0 = performance.now();
1269
1219
  this.store.map.clear();
1270
- var _iterator5 = _createForOfIteratorHelper(this.store.list),
1271
- _step5;
1220
+ var _iterator4 = _createForOfIteratorHelper(this.store.list),
1221
+ _step4;
1272
1222
  try {
1273
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1274
- var product = _step5.value;
1223
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1224
+ var product = _step4.value;
1275
1225
  this.store.map.set(product.id, product);
1276
1226
  }
1277
1227
  } catch (err) {
1278
- _iterator5.e(err);
1228
+ _iterator4.e(err);
1279
1229
  } finally {
1280
- _iterator5.f();
1230
+ _iterator4.f();
1281
1231
  }
1282
1232
  perfMark('syncProductsMap', performance.now() - t0, {
1283
1233
  count: this.store.map.size
@@ -1472,20 +1422,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1472
1422
  *
1473
1423
  * product 模块:
1474
1424
  * - operation === 'delete' → 本地删除
1475
- * - change_types 包含 price → SSE 增量拉取 + 刷新报价单价格缓存
1425
+ * - change_types 包含 price → SSE 增量拉取
1476
1426
  * - 有 body → body 完整数据直接覆盖本地
1477
- *
1427
+ *
1478
1428
  * product_collection / product_category / product_quotation:
1479
1429
  * - 按 relation_product_ids SSE 拉取受影响商品
1480
- * - product_quotation 额外刷新报价单价格缓存
1481
1430
  *
1482
- * 处理完成后 emit onProductsSyncCompleted 通知 Server 层
1431
+ * 处理完成后清除价格缓存并 emit onProductsSyncCompleted
1432
+ * Server 层监听该事件后重新查询,走完整的 formatter 管道重建缓存
1483
1433
  */
1484
1434
  }, {
1485
1435
  key: "processProductSyncMessages",
1486
1436
  value: (function () {
1487
1437
  var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
1488
- var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, _iterator6, _step6, msg, channelKey, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _msg$relation_product, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, freshProducts, sseHandledSet, remainingPriceIds;
1438
+ var messages, deleteIds, bodyUpdates, sseRefreshIds, _iterator5, _step5, msg, channelKey, _msg$change_types, _msg$ids2, _msg$ids, ids, _msg$relation_product, bodyId, _msg$relation_product2, uniqueDeleteIds, uniqueSSEIds, freshProducts;
1489
1439
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1490
1440
  while (1) switch (_context18.prev = _context18.next) {
1491
1441
  case 0:
@@ -1503,152 +1453,134 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1503
1453
  deleteIds = [];
1504
1454
  bodyUpdates = new Map();
1505
1455
  sseRefreshIds = [];
1506
- priceRefreshIds = [];
1507
- _iterator6 = _createForOfIteratorHelper(messages);
1508
- _context18.prev = 10;
1509
- _iterator6.s();
1510
- case 12:
1511
- if ((_step6 = _iterator6.n()).done) {
1512
- _context18.next = 34;
1456
+ _iterator5 = _createForOfIteratorHelper(messages);
1457
+ _context18.prev = 9;
1458
+ _iterator5.s();
1459
+ case 11:
1460
+ if ((_step5 = _iterator5.n()).done) {
1461
+ _context18.next = 33;
1513
1462
  break;
1514
1463
  }
1515
- msg = _step6.value;
1464
+ msg = _step5.value;
1516
1465
  channelKey = msg._channelKey || msg.module || 'product';
1517
1466
  if (!(channelKey === 'product')) {
1518
- _context18.next = 31;
1467
+ _context18.next = 30;
1519
1468
  break;
1520
1469
  }
1521
1470
  if (!(msg.operation === 'delete' || msg.action === 'delete')) {
1522
- _context18.next = 19;
1471
+ _context18.next = 18;
1523
1472
  break;
1524
1473
  }
1525
1474
  if ((_msg$ids = msg.ids) !== null && _msg$ids !== void 0 && _msg$ids.length) deleteIds.push.apply(deleteIds, _toConsumableArray(msg.ids));else if (msg.id) deleteIds.push(msg.id);
1526
- return _context18.abrupt("continue", 32);
1527
- case 19:
1475
+ return _context18.abrupt("continue", 31);
1476
+ case 18:
1528
1477
  if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
1529
- _context18.next = 24;
1478
+ _context18.next = 22;
1530
1479
  break;
1531
1480
  }
1532
1481
  ids = msg.ids || (msg.id ? [msg.id] : []);
1533
1482
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(ids));
1534
- priceRefreshIds.push.apply(priceRefreshIds, _toConsumableArray(ids));
1535
- return _context18.abrupt("continue", 32);
1536
- case 24:
1483
+ return _context18.abrupt("continue", 31);
1484
+ case 22:
1537
1485
  if (!msg.body) {
1538
- _context18.next = 28;
1486
+ _context18.next = 27;
1539
1487
  break;
1540
1488
  }
1541
1489
  bodyId = msg.body.id || msg.id;
1542
1490
  if (bodyId) bodyUpdates.set(bodyId, msg.body);
1543
- return _context18.abrupt("continue", 32);
1544
- case 28:
1491
+ if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
1492
+ sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
1493
+ }
1494
+ return _context18.abrupt("continue", 31);
1495
+ case 27:
1545
1496
  // 5. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
1546
1497
  if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
1547
1498
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.ids));
1548
1499
  } else if (msg.id) {
1549
1500
  sseRefreshIds.push(msg.id);
1550
1501
  }
1551
- _context18.next = 32;
1502
+ _context18.next = 31;
1552
1503
  break;
1553
- case 31:
1504
+ case 30:
1554
1505
  if (['product_collection', 'product_category', 'product_quotation'].includes(channelKey)) {
1555
- if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
1506
+ if ((_msg$relation_product2 = msg.relation_product_ids) !== null && _msg$relation_product2 !== void 0 && _msg$relation_product2.length) {
1556
1507
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
1557
- if (channelKey === 'product_quotation') {
1558
- this.clearPriceCache();
1559
- priceRefreshIds.push.apply(priceRefreshIds, _toConsumableArray(msg.relation_product_ids));
1560
- }
1561
1508
  }
1562
1509
  }
1563
- case 32:
1564
- _context18.next = 12;
1510
+ case 31:
1511
+ _context18.next = 11;
1565
1512
  break;
1566
- case 34:
1567
- _context18.next = 39;
1513
+ case 33:
1514
+ _context18.next = 38;
1568
1515
  break;
1569
- case 36:
1570
- _context18.prev = 36;
1571
- _context18.t0 = _context18["catch"](10);
1572
- _iterator6.e(_context18.t0);
1573
- case 39:
1574
- _context18.prev = 39;
1575
- _iterator6.f();
1576
- return _context18.finish(39);
1577
- case 42:
1516
+ case 35:
1517
+ _context18.prev = 35;
1518
+ _context18.t0 = _context18["catch"](9);
1519
+ _iterator5.e(_context18.t0);
1520
+ case 38:
1521
+ _context18.prev = 38;
1522
+ _iterator5.f();
1523
+ return _context18.finish(38);
1524
+ case 41:
1578
1525
  uniqueDeleteIds = _toConsumableArray(new Set(deleteIds));
1579
- uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds));
1580
- uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)); // 1. 处理删除
1526
+ uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds)); // 1. 处理删除
1581
1527
  if (!(uniqueDeleteIds.length > 0)) {
1582
- _context18.next = 48;
1528
+ _context18.next = 46;
1583
1529
  break;
1584
1530
  }
1585
- _context18.next = 48;
1531
+ _context18.next = 46;
1586
1532
  return this.removeProductsByIds(uniqueDeleteIds);
1587
- case 48:
1533
+ case 46:
1588
1534
  if (!(bodyUpdates.size > 0)) {
1589
- _context18.next = 51;
1535
+ _context18.next = 49;
1590
1536
  break;
1591
1537
  }
1592
- _context18.next = 51;
1538
+ _context18.next = 49;
1593
1539
  return this.applyBodyUpdatesToStore(bodyUpdates);
1594
- case 51:
1540
+ case 49:
1595
1541
  if (!(uniqueSSEIds.length > 0)) {
1596
- _context18.next = 61;
1542
+ _context18.next = 57;
1597
1543
  break;
1598
1544
  }
1599
- _context18.next = 54;
1545
+ _context18.next = 52;
1600
1546
  return this.fetchProductsBySSE(uniqueSSEIds);
1601
- case 54:
1547
+ case 52:
1602
1548
  freshProducts = _context18.sent;
1603
1549
  if (!(freshProducts.length > 0)) {
1604
- _context18.next = 60;
1550
+ _context18.next = 56;
1605
1551
  break;
1606
1552
  }
1607
- _context18.next = 58;
1553
+ _context18.next = 56;
1608
1554
  return this.mergeProductsToStore(freshProducts);
1609
- case 58:
1610
- _context18.next = 60;
1611
- return this.updatePriceCacheForProducts(freshProducts);
1612
- case 60:
1555
+ case 56:
1613
1556
  this.logInfo('processProductSyncMessages: SSE 增量更新完成', {
1614
1557
  requestedCount: uniqueSSEIds.length,
1615
1558
  receivedCount: freshProducts.length
1616
1559
  });
1617
- case 61:
1618
- // 4. 处理报价单价格刷新(排除已被第3步 SSE 处理过的 id,避免重复请求)
1619
- sseHandledSet = new Set(uniqueSSEIds);
1620
- remainingPriceIds = uniquePriceIds.filter(function (id) {
1621
- return !sseHandledSet.has(id);
1622
- });
1623
- if (!(remainingPriceIds.length > 0)) {
1624
- _context18.next = 66;
1625
- break;
1626
- }
1627
- _context18.next = 66;
1628
- return this.updateProductPriceByIds(remainingPriceIds);
1629
- case 66:
1560
+ case 57:
1630
1561
  this.logInfo('processProductSyncMessages: 处理完成', {
1631
1562
  deleteCount: uniqueDeleteIds.length,
1632
1563
  bodyUpdateCount: bodyUpdates.size,
1633
- sseRefreshCount: uniqueSSEIds.length,
1634
- priceRefreshCount: uniquePriceIds.length
1564
+ sseRefreshCount: uniqueSSEIds.length
1635
1565
  });
1636
1566
 
1637
1567
  // 如果都没有变更,则不触发 onProductsSyncCompleted
1638
- if (!(uniqueDeleteIds.length === 0 && bodyUpdates.size === 0 && uniqueSSEIds.length === 0 && uniquePriceIds.length === 0)) {
1639
- _context18.next = 70;
1568
+ if (!(uniqueDeleteIds.length === 0 && bodyUpdates.size === 0 && uniqueSSEIds.length === 0)) {
1569
+ _context18.next = 61;
1640
1570
  break;
1641
1571
  }
1642
1572
  this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
1643
1573
  return _context18.abrupt("return");
1644
- case 70:
1645
- _context18.next = 72;
1574
+ case 61:
1575
+ // 清除价格缓存,让后续查询走完整的 formatter 管道重建(含 detailValueFormatter)
1576
+ this.clearPriceCache();
1577
+ _context18.next = 64;
1646
1578
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
1647
- case 72:
1579
+ case 64:
1648
1580
  case "end":
1649
1581
  return _context18.stop();
1650
1582
  }
1651
- }, _callee18, this, [[10, 36, 39, 42]]);
1583
+ }, _callee18, this, [[9, 35, 38, 41]]);
1652
1584
  }));
1653
1585
  function processProductSyncMessages() {
1654
1586
  return _processProductSyncMessages.apply(this, arguments);
@@ -1725,14 +1657,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1725
1657
  /**
1726
1658
  * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
1727
1659
  * 已存在的 → 直接替换;不存在的 → 追加
1728
- * 同时更新 Map 缓存、IndexDB,清空价格缓存,触发 onProductsChanged
1660
+ * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
1661
+ * 价格缓存由 processProductSyncMessages 末尾统一清除
1729
1662
  */
1730
1663
  )
1731
1664
  }, {
1732
1665
  key: "applyBodyUpdatesToStore",
1733
1666
  value: (function () {
1734
1667
  var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(bodyUpdates) {
1735
- var updatedCount, newCount, appliedIds, _iterator7, _step7, _step7$value, id, body;
1668
+ var updatedCount, newCount, appliedIds, _iterator6, _step6, _step6$value, id, body;
1736
1669
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1737
1670
  while (1) switch (_context20.prev = _context20.next) {
1738
1671
  case 0:
@@ -1750,34 +1683,31 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1750
1683
  }
1751
1684
  return p;
1752
1685
  });
1753
- _iterator7 = _createForOfIteratorHelper(bodyUpdates);
1686
+ _iterator6 = _createForOfIteratorHelper(bodyUpdates);
1754
1687
  try {
1755
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1756
- _step7$value = _slicedToArray(_step7.value, 2), id = _step7$value[0], body = _step7$value[1];
1688
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1689
+ _step6$value = _slicedToArray(_step6.value, 2), id = _step6$value[0], body = _step6$value[1];
1757
1690
  if (!appliedIds.has(id)) {
1758
1691
  this.store.list.push(body);
1759
1692
  newCount++;
1760
1693
  }
1761
1694
  }
1762
1695
  } catch (err) {
1763
- _iterator7.e(err);
1696
+ _iterator6.e(err);
1764
1697
  } finally {
1765
- _iterator7.f();
1698
+ _iterator6.f();
1766
1699
  }
1767
1700
  this.syncProductsMap();
1768
1701
  _context20.next = 10;
1769
1702
  return this.saveProductsToIndexDB(this.store.list);
1770
1703
  case 10:
1771
- _context20.next = 12;
1772
- return this.updatePriceCacheForProducts(_toConsumableArray(bodyUpdates.values()));
1773
- case 12:
1774
1704
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1775
1705
  this.logInfo('applyBodyUpdatesToStore: 完成', {
1776
1706
  updatedCount: updatedCount,
1777
1707
  newCount: newCount,
1778
1708
  totalCount: this.store.list.length
1779
1709
  });
1780
- case 14:
1710
+ case 12:
1781
1711
  case "end":
1782
1712
  return _context20.stop();
1783
1713
  }
@@ -1798,21 +1728,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1798
1728
  key: "mergeProductsToStore",
1799
1729
  value: (function () {
1800
1730
  var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(freshProducts) {
1801
- var freshMap, _iterator8, _step8, p, updatedList, newCount, _iterator9, _step9, _p, updatedCount;
1731
+ var freshMap, _iterator7, _step7, p, updatedList, newCount, _iterator8, _step8, _p, updatedCount;
1802
1732
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1803
1733
  while (1) switch (_context21.prev = _context21.next) {
1804
1734
  case 0:
1805
1735
  freshMap = new Map();
1806
- _iterator8 = _createForOfIteratorHelper(freshProducts);
1736
+ _iterator7 = _createForOfIteratorHelper(freshProducts);
1807
1737
  try {
1808
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1809
- p = _step8.value;
1738
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1739
+ p = _step7.value;
1810
1740
  freshMap.set(p.id, p);
1811
1741
  }
1812
1742
  } catch (err) {
1813
- _iterator8.e(err);
1743
+ _iterator7.e(err);
1814
1744
  } finally {
1815
- _iterator8.f();
1745
+ _iterator7.f();
1816
1746
  }
1817
1747
  updatedList = this.store.list.map(function (p) {
1818
1748
  if (freshMap.has(p.id)) {
@@ -1823,16 +1753,16 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1823
1753
  return p;
1824
1754
  }); // freshMap 中剩余的是新商品(create 场景)
1825
1755
  newCount = freshMap.size;
1826
- _iterator9 = _createForOfIteratorHelper(freshMap.values());
1756
+ _iterator8 = _createForOfIteratorHelper(freshMap.values());
1827
1757
  try {
1828
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1829
- _p = _step9.value;
1758
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1759
+ _p = _step8.value;
1830
1760
  updatedList.push(_p);
1831
1761
  }
1832
1762
  } catch (err) {
1833
- _iterator9.e(err);
1763
+ _iterator8.e(err);
1834
1764
  } finally {
1835
- _iterator9.f();
1765
+ _iterator8.f();
1836
1766
  }
1837
1767
  updatedCount = freshProducts.length - newCount;
1838
1768
  this.store.list = updatedList;
@@ -1857,208 +1787,6 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1857
1787
  }
1858
1788
  return mergeProductsToStore;
1859
1789
  }()
1860
- /**
1861
- * 增量更新价格缓存中变更的商品
1862
- * 对每个已缓存的日期 key:替换/追加最新商品数据,重新拉取这些 ID 的价格并应用
1863
- */
1864
- )
1865
- }, {
1866
- key: "updatePriceCacheForProducts",
1867
- value: (function () {
1868
- var _updatePriceCacheForProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(freshProducts) {
1869
- var freshIds, freshMap, _iterator10, _step10, p, _iterator11, _step11, _step11$value, dateKey, cachedProducts, updatedList, existingIds, _iterator12, _step12, _p2, priceData, result, errorMessage;
1870
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1871
- while (1) switch (_context22.prev = _context22.next) {
1872
- case 0:
1873
- if (!(this.productsPriceCache.size === 0)) {
1874
- _context22.next = 2;
1875
- break;
1876
- }
1877
- return _context22.abrupt("return");
1878
- case 2:
1879
- freshIds = freshProducts.map(function (p) {
1880
- return p.id;
1881
- });
1882
- freshMap = new Map();
1883
- _iterator10 = _createForOfIteratorHelper(freshProducts);
1884
- try {
1885
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1886
- p = _step10.value;
1887
- freshMap.set(p.id, p);
1888
- }
1889
- } catch (err) {
1890
- _iterator10.e(err);
1891
- } finally {
1892
- _iterator10.f();
1893
- }
1894
- this.logInfo('updatePriceCacheForProducts: 开始', {
1895
- freshIds: freshIds,
1896
- cachedDateCount: this.productsPriceCache.size
1897
- });
1898
- _iterator11 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1899
- _context22.prev = 8;
1900
- _iterator11.s();
1901
- case 10:
1902
- if ((_step11 = _iterator11.n()).done) {
1903
- _context22.next = 31;
1904
- break;
1905
- }
1906
- _step11$value = _slicedToArray(_step11.value, 2), dateKey = _step11$value[0], cachedProducts = _step11$value[1];
1907
- _context22.prev = 12;
1908
- // 1. 替换已有商品 / 收集新增商品
1909
- updatedList = cachedProducts.map(function (p) {
1910
- var fresh = freshMap.get(p.id);
1911
- return fresh ? _objectSpread({}, fresh) : p;
1912
- }); // 追加新增商品(缓存中不存在的 ID)
1913
- existingIds = new Set(cachedProducts.map(function (p) {
1914
- return p.id;
1915
- }));
1916
- _iterator12 = _createForOfIteratorHelper(freshProducts);
1917
- try {
1918
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1919
- _p2 = _step12.value;
1920
- if (!existingIds.has(_p2.id)) {
1921
- updatedList.push(_objectSpread({}, _p2));
1922
- }
1923
- }
1924
-
1925
- // 2. 拉取这些 ID 的最新价格并应用
1926
- } catch (err) {
1927
- _iterator12.e(err);
1928
- } finally {
1929
- _iterator12.f();
1930
- }
1931
- _context22.next = 19;
1932
- return this.loadProductsPrice({
1933
- ids: freshIds,
1934
- schedule_date: dateKey
1935
- });
1936
- case 19:
1937
- priceData = _context22.sent;
1938
- result = priceData && priceData.length > 0 ? applyPriceDataToProducts(updatedList, priceData) : updatedList;
1939
- this.productsPriceCache.set(dateKey, result);
1940
- this.logInfo('updatePriceCacheForProducts: 日期缓存已更新', {
1941
- dateKey: dateKey,
1942
- updatedIds: freshIds
1943
- });
1944
- _context22.next = 29;
1945
- break;
1946
- case 25:
1947
- _context22.prev = 25;
1948
- _context22.t0 = _context22["catch"](12);
1949
- errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0);
1950
- this.logError('updatePriceCacheForProducts: 失败', {
1951
- dateKey: dateKey,
1952
- error: errorMessage
1953
- });
1954
- case 29:
1955
- _context22.next = 10;
1956
- break;
1957
- case 31:
1958
- _context22.next = 36;
1959
- break;
1960
- case 33:
1961
- _context22.prev = 33;
1962
- _context22.t1 = _context22["catch"](8);
1963
- _iterator11.e(_context22.t1);
1964
- case 36:
1965
- _context22.prev = 36;
1966
- _iterator11.f();
1967
- return _context22.finish(36);
1968
- case 39:
1969
- case "end":
1970
- return _context22.stop();
1971
- }
1972
- }, _callee22, this, [[8, 33, 36, 39], [12, 25]]);
1973
- }));
1974
- function updatePriceCacheForProducts(_x19) {
1975
- return _updatePriceCacheForProducts.apply(this, arguments);
1976
- }
1977
- return updatePriceCacheForProducts;
1978
- }()
1979
- /**
1980
- * 全量重新拉取报价单价格并重建价格缓存
1981
- * 遍历当前已缓存的所有日期 key,对每个日期重新调用 loadProductsPrice
1982
- */
1983
- )
1984
- }, {
1985
- key: "refreshAllPriceCache",
1986
- value: (function () {
1987
- var _refreshAllPriceCache = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1988
- var allProducts, ids, dateKeys, _i, _dateKeys, dateKey, priceData, updatedProducts, errorMessage;
1989
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1990
- while (1) switch (_context23.prev = _context23.next) {
1991
- case 0:
1992
- allProducts = this.getProductsRef();
1993
- if (!(allProducts.length === 0)) {
1994
- _context23.next = 3;
1995
- break;
1996
- }
1997
- return _context23.abrupt("return");
1998
- case 3:
1999
- ids = allProducts.map(function (p) {
2000
- return p.id;
2001
- }); // 先快照当前已缓存的日期 key,再清空缓存
2002
- dateKeys = Array.from(this.productsPriceCache.keys());
2003
- this.clearPriceCache();
2004
- if (!(dateKeys.length === 0)) {
2005
- _context23.next = 9;
2006
- break;
2007
- }
2008
- this.logInfo('refreshAllPriceCache: 无已缓存日期,跳过');
2009
- return _context23.abrupt("return");
2010
- case 9:
2011
- this.logInfo('refreshAllPriceCache: 开始重新拉取', {
2012
- dateKeys: dateKeys,
2013
- productCount: ids.length
2014
- });
2015
- _i = 0, _dateKeys = dateKeys;
2016
- case 11:
2017
- if (!(_i < _dateKeys.length)) {
2018
- _context23.next = 28;
2019
- break;
2020
- }
2021
- dateKey = _dateKeys[_i];
2022
- _context23.prev = 13;
2023
- _context23.next = 16;
2024
- return this.loadProductsPrice({
2025
- ids: ids,
2026
- schedule_date: dateKey
2027
- });
2028
- case 16:
2029
- priceData = _context23.sent;
2030
- if (priceData && priceData.length > 0) {
2031
- updatedProducts = applyPriceDataToProducts(allProducts, priceData);
2032
- this.productsPriceCache.set(dateKey, updatedProducts);
2033
- }
2034
- this.logInfo('refreshAllPriceCache: 日期缓存已更新', {
2035
- dateKey: dateKey
2036
- });
2037
- _context23.next = 25;
2038
- break;
2039
- case 21:
2040
- _context23.prev = 21;
2041
- _context23.t0 = _context23["catch"](13);
2042
- errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
2043
- this.logError('refreshAllPriceCache: 失败', {
2044
- dateKey: dateKey,
2045
- error: errorMessage
2046
- });
2047
- case 25:
2048
- _i++;
2049
- _context23.next = 11;
2050
- break;
2051
- case 28:
2052
- case "end":
2053
- return _context23.stop();
2054
- }
2055
- }, _callee23, this, [[13, 21]]);
2056
- }));
2057
- function refreshAllPriceCache() {
2058
- return _refreshAllPriceCache.apply(this, arguments);
2059
- }
2060
- return refreshAllPriceCache;
2061
- }()
2062
1790
  /**
2063
1791
  * 静默全量刷新:后台重新拉取全量 SSE 数据并更新本地
2064
1792
  * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
@@ -2068,34 +1796,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2068
1796
  }, {
2069
1797
  key: "silentRefresh",
2070
1798
  value: (function () {
2071
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1799
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
2072
1800
  var t0, products, errorMessage;
2073
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2074
- while (1) switch (_context24.prev = _context24.next) {
1801
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1802
+ while (1) switch (_context22.prev = _context22.next) {
2075
1803
  case 0:
2076
1804
  t0 = performance.now();
2077
1805
  this.logInfo('silentRefresh 开始');
2078
- _context24.prev = 2;
2079
- _context24.next = 5;
1806
+ _context22.prev = 2;
1807
+ _context22.next = 5;
2080
1808
  return this.loadProductsByServer();
2081
1809
  case 5:
2082
- products = _context24.sent;
1810
+ products = _context22.sent;
2083
1811
  if (!(products && products.length > 0)) {
2084
- _context24.next = 16;
1812
+ _context22.next = 16;
2085
1813
  break;
2086
1814
  }
2087
1815
  this.store.list = products;
2088
1816
  this.syncProductsMap();
2089
1817
  this.clearPriceCache();
2090
1818
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2091
- _context24.next = 13;
1819
+ _context22.next = 13;
2092
1820
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
2093
1821
  case 13:
2094
1822
  this.logInfo('silentRefresh 完成', {
2095
1823
  productCount: products.length,
2096
1824
  duration: "".concat(Math.round(performance.now() - t0), "ms")
2097
1825
  });
2098
- _context24.next = 17;
1826
+ _context22.next = 17;
2099
1827
  break;
2100
1828
  case 16:
2101
1829
  this.logWarning('silentRefresh: 服务器未返回数据');
@@ -2103,21 +1831,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2103
1831
  perfMark('silentRefresh', performance.now() - t0, {
2104
1832
  count: this.store.list.length
2105
1833
  });
2106
- return _context24.abrupt("return", this.store.list);
1834
+ return _context22.abrupt("return", this.store.list);
2107
1835
  case 21:
2108
- _context24.prev = 21;
2109
- _context24.t0 = _context24["catch"](2);
2110
- errorMessage = _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0);
1836
+ _context22.prev = 21;
1837
+ _context22.t0 = _context22["catch"](2);
1838
+ errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0);
2111
1839
  this.logError('silentRefresh 失败', {
2112
1840
  duration: "".concat(Math.round(performance.now() - t0), "ms"),
2113
1841
  error: errorMessage
2114
1842
  });
2115
- return _context24.abrupt("return", this.store.list);
1843
+ return _context22.abrupt("return", this.store.list);
2116
1844
  case 26:
2117
1845
  case "end":
2118
- return _context24.stop();
1846
+ return _context22.stop();
2119
1847
  }
2120
- }, _callee24, this, [[2, 21]]);
1848
+ }, _callee22, this, [[2, 21]]);
2121
1849
  }));
2122
1850
  function silentRefresh() {
2123
1851
  return _silentRefresh.apply(this, arguments);
@@ -0,0 +1,49 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/model/strategy/adapter/promotion/index.ts
30
+ var promotion_exports = {};
31
+ __export(promotion_exports, {
32
+ BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
+ PromotionAdapter: () => import_adapter.PromotionAdapter,
34
+ PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
+ X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
+ default: () => import_adapter2.default
37
+ });
38
+ module.exports = __toCommonJS(promotion_exports);
39
+ var import_evaluator = require("./evaluator");
40
+ var import_adapter = require("./adapter");
41
+ var import_adapter2 = __toESM(require("./adapter"));
42
+ var import_examples = require("./examples");
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ BUY_X_GET_Y_FREE_STRATEGY,
46
+ PromotionAdapter,
47
+ PromotionEvaluator,
48
+ X_ITEMS_FOR_Y_PRICE_STRATEGY
49
+ });
@@ -157,8 +157,8 @@ export declare class ProductsModule extends BaseModule implements Module {
157
157
  */
158
158
  refreshProducts(): Promise<ProductData[]>;
159
159
  /**
160
- * 局部更新指定商品的报价单价格
161
- * 遍历所有已缓存的日期,为目标商品重新获取价格并覆盖到缓存中
160
+ * 指定商品的报价单价格变更时,清除价格缓存
161
+ * 后续查询会走完整的 formatter 管道重建缓存
162
162
  */
163
163
  updateProductPriceByIds(ids: number[]): Promise<void>;
164
164
  /**
@@ -202,15 +202,14 @@ export declare class ProductsModule extends BaseModule implements Module {
202
202
  *
203
203
  * product 模块:
204
204
  * - operation === 'delete' → 本地删除
205
- * - change_types 包含 price → SSE 增量拉取 + 刷新报价单价格缓存
205
+ * - change_types 包含 price → SSE 增量拉取
206
206
  * - 有 body → body 完整数据直接覆盖本地
207
-
208
207
  *
209
208
  * product_collection / product_category / product_quotation:
210
209
  * - 按 relation_product_ids SSE 拉取受影响商品
211
- * - product_quotation 额外刷新报价单价格缓存
212
210
  *
213
- * 处理完成后 emit onProductsSyncCompleted 通知 Server 层
211
+ * 处理完成后清除价格缓存并 emit onProductsSyncCompleted
212
+ * Server 层监听该事件后重新查询,走完整的 formatter 管道重建缓存
214
213
  */
215
214
  private processProductSyncMessages;
216
215
  /**
@@ -221,7 +220,8 @@ export declare class ProductsModule extends BaseModule implements Module {
221
220
  /**
222
221
  * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
223
222
  * 已存在的 → 直接替换;不存在的 → 追加
224
- * 同时更新 Map 缓存、IndexDB,清空价格缓存,触发 onProductsChanged
223
+ * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
224
+ * 价格缓存由 processProductSyncMessages 末尾统一清除
225
225
  */
226
226
  private applyBodyUpdatesToStore;
227
227
  /**
@@ -230,16 +230,6 @@ export declare class ProductsModule extends BaseModule implements Module {
230
230
  * 同时更新 store.map、IndexDB,触发 onProductsChanged
231
231
  */
232
232
  private mergeProductsToStore;
233
- /**
234
- * 增量更新价格缓存中变更的商品
235
- * 对每个已缓存的日期 key:替换/追加最新商品数据,重新拉取这些 ID 的价格并应用
236
- */
237
- private updatePriceCacheForProducts;
238
- /**
239
- * 全量重新拉取报价单价格并重建价格缓存
240
- * 遍历当前已缓存的所有日期 key,对每个日期重新调用 loadProductsPrice
241
- */
242
- private refreshAllPriceCache;
243
233
  /**
244
234
  * 静默全量刷新:后台重新拉取全量 SSE 数据并更新本地
245
235
  * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
@@ -605,27 +605,12 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
605
605
  return this.store.list;
606
606
  }
607
607
  /**
608
- * 局部更新指定商品的报价单价格
609
- * 遍历所有已缓存的日期,为目标商品重新获取价格并覆盖到缓存中
608
+ * 指定商品的报价单价格变更时,清除价格缓存
609
+ * 后续查询会走完整的 formatter 管道重建缓存
610
610
  */
611
611
  async updateProductPriceByIds(ids) {
612
- this.logInfo("updateProductPriceByIds", { ids });
613
- for (const [dateKey, cachedProducts] of this.productsPriceCache.entries()) {
614
- try {
615
- const priceData = await this.loadProductsPrice({
616
- ids,
617
- schedule_date: dateKey
618
- });
619
- if (priceData && priceData.length > 0) {
620
- const updatedProducts = (0, import_product.applyPriceDataToProducts)(cachedProducts, priceData);
621
- this.productsPriceCache.set(dateKey, updatedProducts);
622
- this.logInfo("updateProductPriceByIds: 缓存已更新", { dateKey, priceDataCount: priceData.length });
623
- }
624
- } catch (error) {
625
- const errorMessage = error instanceof Error ? error.message : String(error);
626
- this.logError("updateProductPriceByIds: 失败", { dateKey, ids, error: errorMessage });
627
- }
628
- }
612
+ this.logInfo("updateProductPriceByIds: 清除价格缓存", { ids });
613
+ this.clearPriceCache();
629
614
  }
630
615
  /**
631
616
  * 清空缓存
@@ -849,22 +834,21 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
849
834
  this.logInfo("setupProductSync: pubsub 订阅已建立");
850
835
  }
851
836
  /**
852
- * 处理防抖后的同步消息批次
853
- *
854
- * product 模块:
855
- * - operation === 'delete' → 本地删除
856
- * - change_types 包含 price → SSE 增量拉取 + 刷新报价单价格缓存
857
- * - 有 body → body 完整数据直接覆盖本地
858
-
859
- *
860
- * product_collection / product_category / product_quotation:
861
- * - 按 relation_product_ids SSE 拉取受影响商品
862
- * - product_quotation 额外刷新报价单价格缓存
863
- *
864
- * 处理完成后 emit onProductsSyncCompleted 通知 Server 层
865
- */
837
+ * 处理防抖后的同步消息批次
838
+ *
839
+ * product 模块:
840
+ * - operation === 'delete' → 本地删除
841
+ * - change_types 包含 price → SSE 增量拉取
842
+ * - 有 body → body 完整数据直接覆盖本地
843
+ *
844
+ * product_collection / product_category / product_quotation:
845
+ * - relation_product_ids SSE 拉取受影响商品
846
+ *
847
+ * 处理完成后清除价格缓存并 emit onProductsSyncCompleted,
848
+ * Server 层监听该事件后重新查询,走完整的 formatter 管道重建缓存
849
+ */
866
850
  async processProductSyncMessages() {
867
- var _a, _b, _c, _d;
851
+ var _a, _b, _c, _d, _e;
868
852
  const messages = [...this.pendingSyncMessages];
869
853
  this.pendingSyncMessages = [];
870
854
  if (messages.length === 0)
@@ -873,7 +857,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
873
857
  const deleteIds = [];
874
858
  const bodyUpdates = /* @__PURE__ */ new Map();
875
859
  const sseRefreshIds = [];
876
- const priceRefreshIds = [];
877
860
  for (const msg of messages) {
878
861
  const channelKey = msg._channelKey || msg.module || "product";
879
862
  if (channelKey === "product") {
@@ -887,33 +870,30 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
887
870
  if ((_b = msg.change_types) == null ? void 0 : _b.includes("price")) {
888
871
  const ids = msg.ids || (msg.id ? [msg.id] : []);
889
872
  sseRefreshIds.push(...ids);
890
- priceRefreshIds.push(...ids);
891
873
  continue;
892
874
  }
893
875
  if (msg.body) {
894
876
  const bodyId = msg.body.id || msg.id;
895
877
  if (bodyId)
896
878
  bodyUpdates.set(bodyId, msg.body);
879
+ if ((_c = msg.relation_product_ids) == null ? void 0 : _c.length) {
880
+ sseRefreshIds.push(...msg.relation_product_ids);
881
+ }
897
882
  continue;
898
883
  }
899
- if ((_c = msg.ids) == null ? void 0 : _c.length) {
884
+ if ((_d = msg.ids) == null ? void 0 : _d.length) {
900
885
  sseRefreshIds.push(...msg.ids);
901
886
  } else if (msg.id) {
902
887
  sseRefreshIds.push(msg.id);
903
888
  }
904
889
  } else if (["product_collection", "product_category", "product_quotation"].includes(channelKey)) {
905
- if ((_d = msg.relation_product_ids) == null ? void 0 : _d.length) {
890
+ if ((_e = msg.relation_product_ids) == null ? void 0 : _e.length) {
906
891
  sseRefreshIds.push(...msg.relation_product_ids);
907
- if (channelKey === "product_quotation") {
908
- this.clearPriceCache();
909
- priceRefreshIds.push(...msg.relation_product_ids);
910
- }
911
892
  }
912
893
  }
913
894
  }
914
895
  const uniqueDeleteIds = [...new Set(deleteIds)];
915
896
  const uniqueSSEIds = [...new Set(sseRefreshIds)];
916
- const uniquePriceIds = [...new Set(priceRefreshIds)];
917
897
  if (uniqueDeleteIds.length > 0) {
918
898
  await this.removeProductsByIds(uniqueDeleteIds);
919
899
  }
@@ -924,28 +904,22 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
924
904
  const freshProducts = await this.fetchProductsBySSE(uniqueSSEIds);
925
905
  if (freshProducts.length > 0) {
926
906
  await this.mergeProductsToStore(freshProducts);
927
- await this.updatePriceCacheForProducts(freshProducts);
928
907
  }
929
908
  this.logInfo("processProductSyncMessages: SSE 增量更新完成", {
930
909
  requestedCount: uniqueSSEIds.length,
931
910
  receivedCount: freshProducts.length
932
911
  });
933
912
  }
934
- const sseHandledSet = new Set(uniqueSSEIds);
935
- const remainingPriceIds = uniquePriceIds.filter((id) => !sseHandledSet.has(id));
936
- if (remainingPriceIds.length > 0) {
937
- await this.updateProductPriceByIds(remainingPriceIds);
938
- }
939
913
  this.logInfo("processProductSyncMessages: 处理完成", {
940
914
  deleteCount: uniqueDeleteIds.length,
941
915
  bodyUpdateCount: bodyUpdates.size,
942
- sseRefreshCount: uniqueSSEIds.length,
943
- priceRefreshCount: uniquePriceIds.length
916
+ sseRefreshCount: uniqueSSEIds.length
944
917
  });
945
- if (uniqueDeleteIds.length === 0 && bodyUpdates.size === 0 && uniqueSSEIds.length === 0 && uniquePriceIds.length === 0) {
918
+ if (uniqueDeleteIds.length === 0 && bodyUpdates.size === 0 && uniqueSSEIds.length === 0) {
946
919
  this.logInfo("processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted");
947
920
  return;
948
921
  }
922
+ this.clearPriceCache();
949
923
  await this.core.effects.emit(import_types.ProductsHooks.onProductsSyncCompleted, null);
950
924
  }
951
925
  /**
@@ -980,7 +954,8 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
980
954
  /**
981
955
  * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
982
956
  * 已存在的 → 直接替换;不存在的 → 追加
983
- * 同时更新 Map 缓存、IndexDB,清空价格缓存,触发 onProductsChanged
957
+ * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
958
+ * 价格缓存由 processProductSyncMessages 末尾统一清除
984
959
  */
985
960
  async applyBodyUpdatesToStore(bodyUpdates) {
986
961
  this.logInfo("applyBodyUpdatesToStore: 开始", { count: bodyUpdates.size });
@@ -1003,7 +978,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1003
978
  }
1004
979
  this.syncProductsMap();
1005
980
  await this.saveProductsToIndexDB(this.store.list);
1006
- await this.updatePriceCacheForProducts([...bodyUpdates.values()]);
1007
981
  this.core.effects.emit(import_types.ProductsHooks.onProductsChanged, this.store.list);
1008
982
  this.logInfo("applyBodyUpdatesToStore: 完成", {
1009
983
  updatedCount,
@@ -1044,80 +1018,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1044
1018
  });
1045
1019
  this.core.effects.emit(import_types.ProductsHooks.onProductsChanged, this.store.list);
1046
1020
  }
1047
- /**
1048
- * 增量更新价格缓存中变更的商品
1049
- * 对每个已缓存的日期 key:替换/追加最新商品数据,重新拉取这些 ID 的价格并应用
1050
- */
1051
- async updatePriceCacheForProducts(freshProducts) {
1052
- if (this.productsPriceCache.size === 0)
1053
- return;
1054
- const freshIds = freshProducts.map((p) => p.id);
1055
- const freshMap = /* @__PURE__ */ new Map();
1056
- for (const p of freshProducts) {
1057
- freshMap.set(p.id, p);
1058
- }
1059
- this.logInfo("updatePriceCacheForProducts: 开始", {
1060
- freshIds,
1061
- cachedDateCount: this.productsPriceCache.size
1062
- });
1063
- for (const [dateKey, cachedProducts] of this.productsPriceCache.entries()) {
1064
- try {
1065
- const updatedList = cachedProducts.map((p) => {
1066
- const fresh = freshMap.get(p.id);
1067
- return fresh ? { ...fresh } : p;
1068
- });
1069
- const existingIds = new Set(cachedProducts.map((p) => p.id));
1070
- for (const p of freshProducts) {
1071
- if (!existingIds.has(p.id)) {
1072
- updatedList.push({ ...p });
1073
- }
1074
- }
1075
- const priceData = await this.loadProductsPrice({
1076
- ids: freshIds,
1077
- schedule_date: dateKey
1078
- });
1079
- const result = priceData && priceData.length > 0 ? (0, import_product.applyPriceDataToProducts)(updatedList, priceData) : updatedList;
1080
- this.productsPriceCache.set(dateKey, result);
1081
- this.logInfo("updatePriceCacheForProducts: 日期缓存已更新", {
1082
- dateKey,
1083
- updatedIds: freshIds
1084
- });
1085
- } catch (error) {
1086
- const errorMessage = error instanceof Error ? error.message : String(error);
1087
- this.logError("updatePriceCacheForProducts: 失败", { dateKey, error: errorMessage });
1088
- }
1089
- }
1090
- }
1091
- /**
1092
- * 全量重新拉取报价单价格并重建价格缓存
1093
- * 遍历当前已缓存的所有日期 key,对每个日期重新调用 loadProductsPrice
1094
- */
1095
- async refreshAllPriceCache() {
1096
- const allProducts = this.getProductsRef();
1097
- if (allProducts.length === 0)
1098
- return;
1099
- const ids = allProducts.map((p) => p.id);
1100
- const dateKeys = Array.from(this.productsPriceCache.keys());
1101
- this.clearPriceCache();
1102
- if (dateKeys.length === 0) {
1103
- this.logInfo("refreshAllPriceCache: 无已缓存日期,跳过");
1104
- return;
1105
- }
1106
- this.logInfo("refreshAllPriceCache: 开始重新拉取", { dateKeys, productCount: ids.length });
1107
- for (const dateKey of dateKeys) {
1108
- try {
1109
- const priceData = await this.loadProductsPrice({ ids, schedule_date: dateKey });
1110
- if (priceData && priceData.length > 0) {
1111
- const updatedProducts = (0, import_product.applyPriceDataToProducts)(allProducts, priceData);
1112
- this.productsPriceCache.set(dateKey, updatedProducts);
1113
- }
1114
- this.logInfo("refreshAllPriceCache: 日期缓存已更新", { dateKey });
1115
- } catch (error) {
1116
- const errorMessage = error instanceof Error ? error.message : String(error);
1117
- this.logError("refreshAllPriceCache: 失败", { dateKey, error: errorMessage });
1118
- }
1119
- }
1120
- }
1121
1021
  /**
1122
1022
  * 静默全量刷新:后台重新拉取全量 SSE 数据并更新本地
1123
1023
  * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.84",
4
+ "version": "2.2.86",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",