Commit 649f145443109437282edebb778190c538b1c7be
1 parent
f22b52e0
fix: 期刊推荐判断是否为空
Showing
1 changed file
with
29 additions
and
7 deletions
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
@@ -213,13 +213,35 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | @@ -213,13 +213,35 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | ||
213 | productVO.setRelatedProductIds(relatedProductIds); | 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 | journals = journals.stream() | 245 | journals = journals.stream() |
224 | .collect(Collectors.toMap( | 246 | .collect(Collectors.toMap( |
225 | Journal::getTitle, | 247 | Journal::getTitle, |