Commit 3989db1b16722e59faa016fdb2729f273c4149b5
1 parent
afbd3382
fix: categoryIds判断是否为空
Showing
1 changed file
with
29 additions
and
28 deletions
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
... | ... | @@ -6,7 +6,6 @@ import com.alibaba.fastjson2.JSON; |
6 | 6 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
7 | 7 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
8 | 8 | import com.baomidou.mybatisplus.core.metadata.IPage; |
9 | -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | |
10 | 9 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
11 | 10 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
12 | 11 | import com.canrd.shop.common.constant.PriceConstants; |
... | ... | @@ -23,6 +22,7 @@ import com.canrd.shop.service.*; |
23 | 22 | import com.google.common.collect.Lists; |
24 | 23 | import com.google.common.collect.Sets; |
25 | 24 | import lombok.extern.slf4j.Slf4j; |
25 | +import org.apache.commons.collections4.CollectionUtils; | |
26 | 26 | import org.apache.commons.lang3.BooleanUtils; |
27 | 27 | import org.apache.ibatis.annotations.Param; |
28 | 28 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -137,36 +137,37 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
137 | 137 | .eq(Productcategoryrelation::getProductId, productQueryVO.getId()) |
138 | 138 | .list(); |
139 | 139 | List<String> categoryIds = productcategoryrelations.stream().map(Productcategoryrelation::getCategoryId).collect(Collectors.toList()); |
140 | - | |
141 | - List<ProductCategoryDO> productCategories = categoryService.lambdaQuery() | |
142 | - .in(ProductCategoryDO::getId, categoryIds) | |
143 | - .eq(ProductCategoryDO::getParentId, "33ba6943c8bf4ca082614f299865341c") | |
144 | - .list(); | |
145 | - ProductCategoryDO firstCategory = productCategories.get(0); | |
146 | - List<ProductCategoryDO> productCategories2 = categoryService.lambdaQuery() | |
147 | - .in(ProductCategoryDO::getId, categoryIds) | |
148 | - .eq(ProductCategoryDO::getParentId, firstCategory.getId()) | |
149 | - .list(); | |
140 | + if (CollectionUtils.isNotEmpty(categoryIds)) { | |
141 | + List<ProductCategoryDO> productCategories = categoryService.lambdaQuery() | |
142 | + .in(ProductCategoryDO::getId, categoryIds) | |
143 | + .eq(ProductCategoryDO::getParentId, "33ba6943c8bf4ca082614f299865341c") | |
144 | + .list(); | |
145 | + ProductCategoryDO firstCategory = productCategories.get(0); | |
146 | + List<ProductCategoryDO> productCategories2 = categoryService.lambdaQuery() | |
147 | + .in(ProductCategoryDO::getId, categoryIds) | |
148 | + .eq(ProductCategoryDO::getParentId, firstCategory.getId()) | |
149 | + .list(); | |
150 | 150 | // ProductCategoryDO secondCategory = productCategories2.get(0); |
151 | - ProductCategoryDO secondCategory = productCategories2.stream() | |
152 | - .filter(category -> !"Not specified".equals(category.getName())) | |
153 | - .findFirst() | |
154 | - .orElse(productCategories2.get(0)); // 如果找不到,使用列表第一个元素 | |
155 | - // 从 functionService 获取 functionId | |
156 | - List<ProductFunctionDO> functions = functionService.getFirstFunction(productVO.getId()); | |
157 | - ProductFunctionDO selectedFunction = null; | |
158 | - if(functions != null && functions.size() > 0) { | |
159 | - selectedFunction = functions.stream() | |
160 | - .filter(function -> !"Not specified".equals(function.getName())) | |
151 | + ProductCategoryDO secondCategory = productCategories2.stream() | |
152 | + .filter(category -> !"Not specified".equals(category.getName())) | |
161 | 153 | .findFirst() |
162 | - .orElse(functions.get(0)); // 如果找不到,使用列表第一个元素 | |
154 | + .orElse(productCategories2.get(0)); // 如果找不到,使用列表第一个元素 | |
155 | + // 从 functionService 获取 functionId | |
156 | + List<ProductFunctionDO> functions = functionService.getFirstFunction(productVO.getId()); | |
157 | + ProductFunctionDO selectedFunction = null; | |
158 | + if (functions != null && functions.size() > 0) { | |
159 | + selectedFunction = functions.stream() | |
160 | + .filter(function -> !"Not specified".equals(function.getName())) | |
161 | + .findFirst() | |
162 | + .orElse(functions.get(0)); // 如果找不到,使用列表第一个元素 | |
163 | + } | |
164 | + ProductCrumbsVO productCrumbsVO = ProductCrumbsVO.builder() | |
165 | + .category1(firstCategory.getName()) // | |
166 | + .category2(secondCategory.getName()) | |
167 | + .function(selectedFunction.getName()) | |
168 | + .build(); | |
169 | + productVO.setProductCrumbsVO(productCrumbsVO); | |
163 | 170 | } |
164 | - ProductCrumbsVO productCrumbsVO = ProductCrumbsVO.builder() | |
165 | - .category1(firstCategory.getName()) // | |
166 | - .category2(secondCategory.getName()) | |
167 | - .function(selectedFunction.getName()) | |
168 | - .build(); | |
169 | - productVO.setProductCrumbsVO(productCrumbsVO); | |
170 | 171 | |
171 | 172 | List<EbCategorysRelation> cateRelations = ebCategorysRelationService.lambdaQuery() |
172 | 173 | .in(EbCategorysRelation::getCategoryId, categoryIds) | ... | ... |