Commit 21febc887ec08320a7b11ee087f1a6bf05d9a9bb

Authored by 曾国涛
1 parent 752e4956

refactor(shop): 优化期刊推荐功能

- 修改期刊查询逻辑,先按标题去重,再按原始顺序取前 10 条记录
- 替换原有的分页查询方式,提高查询效率和准确性
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
@@ -219,7 +219,18 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im @@ -219,7 +219,18 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
219 List<Long> journalIds = journalCategoryRelations.stream().map(JournalCategoryRelation::getJournalId).collect(Collectors.toList()); 219 List<Long> journalIds = journalCategoryRelations.stream().map(JournalCategoryRelation::getJournalId).collect(Collectors.toList());
220 List<Journal> journals = journalService.lambdaQuery() 220 List<Journal> journals = journalService.lambdaQuery()
221 .in(Journal::getId, journalIds) 221 .in(Journal::getId, journalIds)
222 - .page(new Page<>(1,10)).getRecords(); 222 + .list();
  223 + journals = journals.stream()
  224 + .collect(Collectors.toMap(
  225 + Journal::getTitle,
  226 + journal -> journal,
  227 + (existing, replacement) -> existing,
  228 + LinkedHashMap::new
  229 + ))
  230 + .values()
  231 + .stream()
  232 + .limit(10)
  233 + .collect(Collectors.toList());
223 productVO.setJournals(journals); 234 productVO.setJournals(journals);
224 235
225 productVO.setPriceShow(productPriceShow); 236 productVO.setPriceShow(productPriceShow);