Commit 7a48845c9cbbae770f80dbc8da3552305d7c2c0f

Authored by 曾国涛
2 parents 7c9a5a0d 649f1454

Merge remote-tracking branch 'origin/master'

shop/src/main/java/com/canrd/shop/controller/ProductController.java
... ... @@ -144,6 +144,11 @@ public class ProductController {
144 144 return productService.listBySimilar(productQueryVO);
145 145 }
146 146  
  147 + @GetMapping("/hotProducts")
  148 + public ServerResult hotProducts(@Validated({OperateGroup.List.class}) ProductQueryVO productQueryVO) {
  149 + return productService.hotProducts(productQueryVO);
  150 + }
  151 +
147 152 /**
148 153 * 生成静态页面
149 154 *
... ...
shop/src/main/java/com/canrd/shop/service/ProductService.java
... ... @@ -65,4 +65,6 @@ public interface ProductService extends IService<ProductDO> {
65 65 ServerResult categorySearch(ProductQueryVO productQueryVO);
66 66  
67 67 ServerResult chatgpt(ProductQueryVO productQueryVO);
  68 +
  69 + ServerResult hotProducts(ProductQueryVO productQueryVO);
68 70 }
... ...
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
... ... @@ -213,13 +213,35 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
213 213 productVO.setRelatedProductIds(relatedProductIds);
214 214 }
215 215  
216   - List<JournalCategoryRelation> journalCategoryRelations = journalCategoryService.lambdaQuery()
217   - .in(JournalCategoryRelation::getCategoryId, categoryIds)
218   - .list();
219   - List<Long> journalIds = journalCategoryRelations.stream().map(JournalCategoryRelation::getJournalId).collect(Collectors.toList());
220   - List<Journal> journals = journalService.lambdaQuery()
221   - .in(Journal::getId, journalIds)
222   - .list();
  216 +// List<JournalCategoryRelation> journalCategoryRelations = journalCategoryService.lambdaQuery()
  217 +// .in(JournalCategoryRelation::getCategoryId, categoryIds)
  218 +// .list();
  219 +// List<Long> journalIds = journalCategoryRelations.stream().map(JournalCategoryRelation::getJournalId).collect(Collectors.toList());
  220 +// List<Journal> journals = journalService.lambdaQuery()
  221 +// .in(Journal::getId, journalIds)
  222 +// .list();
  223 + List<JournalCategoryRelation> journalCategoryRelations = null;
  224 + if (categoryIds != null && !categoryIds.isEmpty()) {
  225 + // 查询 journalCategoryRelations,仅在 categoryIds 不为空时执行
  226 + journalCategoryRelations = journalCategoryService.lambdaQuery()
  227 + .in(JournalCategoryRelation::getCategoryId, categoryIds)
  228 + .list();
  229 + } else {
  230 + journalCategoryRelations = Collections.emptyList(); // 如果 categoryIds 为空,返回空列表
  231 + }
  232 +
  233 + List<Long> journalIds = journalCategoryRelations.stream()
  234 + .map(JournalCategoryRelation::getJournalId)
  235 + .collect(Collectors.toList());
  236 +
  237 + // 查询 journals,仅在 journalIds 不为空时执行
  238 + List<Journal> journals = Collections.emptyList();
  239 + if (!journalIds.isEmpty()) {
  240 + journals = journalService.lambdaQuery()
  241 + .in(Journal::getId, journalIds)
  242 + .list();
  243 + }
  244 +
223 245 journals = journals.stream()
224 246 .collect(Collectors.toMap(
225 247 Journal::getTitle,
... ... @@ -635,6 +657,18 @@ public class ProductServiceImpl extends ServiceImpl&lt;ProductMapper, ProductDO&gt; im
635 657 return null;
636 658 }
637 659  
  660 + @Override
  661 + public ServerResult hotProducts(ProductQueryVO productQueryVO) {
  662 + QueryWrapper<ProductQueryVO> queryWrapper = new QueryWrapper<>();
  663 + queryWrapper.eq("isHot", true)
  664 + .eq("isMarketable",true); // 条件:isHot = true
  665 +
  666 + Page page = new Page<>(productQueryVO.getPageNo(), productQueryVO.getPageSize());
  667 + IPage<ProductDO> iPage = productMapper.queryAll(page,queryWrapper);
  668 + productQueryVO.setTotal(Long.valueOf(iPage.getTotal()).intValue());
  669 + return ServerResult.success().setData(PageUtils.getPageReturn(iPage.getRecords(), productQueryVO));
  670 + }
  671 +
638 672 private String translateHtmlOneProductFieldByChatGpt2(String source) throws IOException, InterruptedException {
639 673 try{
640 674 Thread.sleep(1000 * 20);
... ...