Commit 8452b2d7495e77a89d7b8ce5710fbdac071385d9
1 parent
2d4b3f38
优化商品分类查询及静态页面生成
Showing
2 changed files
with
17 additions
and
8 deletions
shop/src/main/java/com/canrd/shop/controller/ProductController.java
... | ... | @@ -109,13 +109,14 @@ public class ProductController { |
109 | 109 | return ServerResult.fail("secret error"); |
110 | 110 | } |
111 | 111 | if(StringUtils.isNotBlank(productQueryVO.getProductCategoryName())){ |
112 | - Optional<ProductCategoryDO> productCategoryDOOpt = productCategoryService.lambdaQuery() | |
112 | + List<ProductCategoryDO> productCategoryDList = productCategoryService.lambdaQuery() | |
113 | 113 | .eq(ProductCategoryDO::getName, productQueryVO.getProductCategoryName()) |
114 | - .oneOpt(); | |
115 | - productQueryVO | |
116 | - .setProductCategoryId(productCategoryDOOpt | |
117 | - .orElseThrow(()-> new BusinessException("productCategoryName not exist")) | |
118 | - .getId()); | |
114 | + .list(); | |
115 | + if (CollUtil.isNotEmpty(productCategoryDList)){ | |
116 | + productQueryVO.setProductCategoryId(productCategoryDList.get(0).getId()); | |
117 | + }else { | |
118 | + throw new BusinessException("productCategoryName not exist"); | |
119 | + } | |
119 | 120 | } |
120 | 121 | if(StringUtils.isNotBlank(productQueryVO.getRootProductCategoryName())){ |
121 | 122 | Optional<ProductCategoryDO> productCategoryDOOpt = productCategoryService.lambdaQuery() |
... | ... | @@ -167,7 +168,7 @@ public class ProductController { |
167 | 168 | } |
168 | 169 | |
169 | 170 | System.out.println("文件已成功保存到 " + outputFile.getAbsolutePath()); |
170 | - return ServerResult.success(fileName); | |
171 | + return ServerResult.success(fileName+".html"); | |
171 | 172 | } |
172 | 173 | |
173 | 174 | /** | ... | ... |
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
... | ... | @@ -168,7 +168,15 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
168 | 168 | private void suppleProducts(List<ProductDO> records) { |
169 | 169 | Boolean productPriceShow = switchControlService.getEnabledByName(SwitchControlConstants.PRODUCT_PRICE_SHOW); |
170 | 170 | List<String> productIds = records.stream().map(ProductDO::getId).collect(Collectors.toList()); |
171 | - List<TicketTypeDO> tickeyTypeDOList = ticketTypeService.lambdaQuery().in(TicketTypeDO::getProductId, productIds).list(); | |
171 | + List<TicketTypeDO> tickeyTypeDOList = ticketTypeService.lambdaQuery() | |
172 | + .func(wrapper -> { | |
173 | + if (CollUtil.isEmpty(productIds)){ | |
174 | + wrapper.apply("1!=1"); | |
175 | + }else { | |
176 | + wrapper.in(TicketTypeDO::getProductId, productIds); | |
177 | + } | |
178 | + }) | |
179 | + .list(); | |
172 | 180 | Map<String,BigDecimal> pId2ttMinPriceMap = new HashMap<>(); |
173 | 181 | for (TicketTypeDO ticketTypeDO : tickeyTypeDOList) { |
174 | 182 | if (Objects.isNull(pId2ttMinPriceMap.get(ticketTypeDO.getProductId()))){ | ... | ... |