Commit 11a7fdb96ea1a9af9368a368146b45f27cc8bf2e
1 parent
21febc88
feat(shop): 生成所有产品类别和功能的静态页面
- 新增 generateAllUrl 接口,用于生成所有产品类别和功能的静态页面 - 修改 ProductQueryVO,增加 rootProductCategoryIdIn 字段支持多对顶级分类的查询 - 更新 ProductCagegoryServiceImpl 和 ProductServiceImpl,以支持新的查询方式 - 修复静态页面生成时的产品价格显示问题
Showing
6 changed files
with
68 additions
and
13 deletions
shop/src/main/java/com/canrd/shop/controller/ProductController.java
@@ -12,10 +12,7 @@ import com.canrd.shop.module.dto.ImportProductRelatedJournal; | @@ -12,10 +12,7 @@ import com.canrd.shop.module.dto.ImportProductRelatedJournal; | ||
12 | import com.canrd.shop.module.dto.ProductCategoryDO; | 12 | import com.canrd.shop.module.dto.ProductCategoryDO; |
13 | import com.canrd.shop.module.dto.ProductDO; | 13 | import com.canrd.shop.module.dto.ProductDO; |
14 | import com.canrd.shop.module.dto.ProductFunctionDO; | 14 | import com.canrd.shop.module.dto.ProductFunctionDO; |
15 | -import com.canrd.shop.module.vo.ImportRelatedCategoryVo; | ||
16 | -import com.canrd.shop.module.vo.ProductCategoryQueryVO; | ||
17 | -import com.canrd.shop.module.vo.ProductQueryVO; | ||
18 | -import com.canrd.shop.module.vo.ProductVO; | 15 | +import com.canrd.shop.module.vo.*; |
19 | import com.canrd.shop.service.*; | 16 | import com.canrd.shop.service.*; |
20 | import freemarker.template.Configuration; | 17 | import freemarker.template.Configuration; |
21 | import freemarker.template.Template; | 18 | import freemarker.template.Template; |
@@ -32,6 +29,8 @@ import org.springframework.web.multipart.MultipartFile; | @@ -32,6 +29,8 @@ import org.springframework.web.multipart.MultipartFile; | ||
32 | import javax.annotation.Resource; | 29 | import javax.annotation.Resource; |
33 | import java.io.*; | 30 | import java.io.*; |
34 | import java.util.*; | 31 | import java.util.*; |
32 | +import java.util.stream.Collectors; | ||
33 | +import java.util.stream.Stream; | ||
35 | 34 | ||
36 | /** | 35 | /** |
37 | * (Product)表控制层 | 36 | * (Product)表控制层 |
@@ -81,6 +80,54 @@ public class ProductController { | @@ -81,6 +80,54 @@ public class ProductController { | ||
81 | return productCategoryService.category(productCategoryQueryVO); | 80 | return productCategoryService.category(productCategoryQueryVO); |
82 | } | 81 | } |
83 | 82 | ||
83 | + @GetMapping("/generateAllUrl") | ||
84 | + public ServerResult generateAllUrl(){ | ||
85 | + ProductCategoryQueryVO productCategoryQueryVO = new ProductCategoryQueryVO(); | ||
86 | + ServerResult<ProductCategoryResultVO> category = productCategoryService.category(productCategoryQueryVO); | ||
87 | + ProductCategoryResultVO data = category.getData(); | ||
88 | + List<ProductCategoryDisplayVO> rootCategoryList = data.getRootCategoryList(); | ||
89 | + | ||
90 | + Map<String, ProductCategoryDisplayVO> name2ProductCategoryDisplayVOMap = rootCategoryList.stream() | ||
91 | + .collect(Collectors.toMap(ProductCategoryDisplayVO::getCategoryDisplayName, v -> v)); | ||
92 | + | ||
93 | + List<ProductQueryVO> queries = name2ProductCategoryDisplayVOMap.entrySet().stream() | ||
94 | + .flatMap(entry -> { | ||
95 | + String rootCategoryName = entry.getKey(); | ||
96 | + ProductCategoryDisplayVO categoryDisplay = entry.getValue(); | ||
97 | + List<String> cateNames = categoryDisplay.getList().stream().map(ProductCategoryVO::getName).collect(Collectors.toList()); | ||
98 | + List<String> funNames = Optional.ofNullable(categoryDisplay.getProductFunctions()).orElse(new ArrayList<ProductFunctionVO>()) | ||
99 | + .stream().map(ProductFunctionVO::getName).collect(Collectors.toList()); | ||
100 | + | ||
101 | + return cateNames.stream().flatMap(cateName -> { | ||
102 | + if (CollUtil.isEmpty(funNames)) { | ||
103 | + return Stream.of(ProductQueryVO.builder() | ||
104 | + .rootProductCategoryName(rootCategoryName) | ||
105 | + .productCategoryName(cateName) | ||
106 | + .pageNo(1) | ||
107 | + .pageSize(20) | ||
108 | + .build()); | ||
109 | + } else { | ||
110 | + return funNames.stream().map(funName -> ProductQueryVO.builder() | ||
111 | + .rootProductCategoryName(rootCategoryName) | ||
112 | + .productCategoryName(cateName) | ||
113 | + .productFunctionName(funName) | ||
114 | + .pageNo(1) | ||
115 | + .pageSize(20) | ||
116 | + .build()); | ||
117 | + } | ||
118 | + }); | ||
119 | + }) | ||
120 | + .collect(Collectors.toList()); | ||
121 | + queries.forEach(query -> { | ||
122 | + try { | ||
123 | + generateList(query,"canrd@2024"); | ||
124 | + } catch (IOException | TemplateException e) { | ||
125 | + throw new RuntimeException(e); | ||
126 | + } | ||
127 | + }); | ||
128 | + return ServerResult.success(); | ||
129 | + } | ||
130 | + | ||
84 | @GetMapping("/categorySearch") | 131 | @GetMapping("/categorySearch") |
85 | public ServerResult categorySearch(ProductQueryVO productQueryVO){ | 132 | public ServerResult categorySearch(ProductQueryVO productQueryVO){ |
86 | return productService.categorySearch(productQueryVO); | 133 | return productService.categorySearch(productQueryVO); |
@@ -121,13 +168,12 @@ public class ProductController { | @@ -121,13 +168,12 @@ public class ProductController { | ||
121 | } | 168 | } |
122 | } | 169 | } |
123 | if(StringUtils.isNotBlank(productQueryVO.getRootProductCategoryName())){ | 170 | if(StringUtils.isNotBlank(productQueryVO.getRootProductCategoryName())){ |
124 | - Optional<ProductCategoryDO> productCategoryDOOpt = productCategoryService.lambdaQuery() | 171 | + List<ProductCategoryDO> list = productCategoryService.lambdaQuery() |
125 | .eq(ProductCategoryDO::getName, productQueryVO.getRootProductCategoryName()) | 172 | .eq(ProductCategoryDO::getName, productQueryVO.getRootProductCategoryName()) |
126 | - .oneOpt(); | 173 | + .list(); |
174 | + List<String> collect = list.stream().map(ProductCategoryDO::getId).collect(Collectors.toList()); | ||
127 | productQueryVO | 175 | productQueryVO |
128 | - .setRootProductCategoryId(productCategoryDOOpt | ||
129 | - .orElseThrow(()-> new BusinessException("productCategoryName not exist")) | ||
130 | - .getId()); | 176 | + .setRootProductCategoryIdIn(collect); |
131 | } | 177 | } |
132 | if(StringUtils.isNotBlank(productQueryVO.getProductFunctionName())){ | 178 | if(StringUtils.isNotBlank(productQueryVO.getProductFunctionName())){ |
133 | Optional<ProductFunctionDO> productFunctionDO = productFunctionService.lambdaQuery() | 179 | Optional<ProductFunctionDO> productFunctionDO = productFunctionService.lambdaQuery() |
@@ -140,7 +186,7 @@ public class ProductController { | @@ -140,7 +186,7 @@ public class ProductController { | ||
140 | String path = staticHtmlConfig.getUrl(); | 186 | String path = staticHtmlConfig.getUrl(); |
141 | String fileName = (StringUtils.isNotBlank(productQueryVO.getRootProductCategoryName())?productQueryVO.getRootProductCategoryName():"-") | 187 | String fileName = (StringUtils.isNotBlank(productQueryVO.getRootProductCategoryName())?productQueryVO.getRootProductCategoryName():"-") |
142 | +"_" | 188 | +"_" |
143 | - +(StringUtils.isNotBlank(productQueryVO.getProductCategoryName())?productQueryVO.getProductCategoryName():"-") | 189 | + +(StringUtils.isNotBlank(productQueryVO.getProductCategoryName())?productQueryVO.getProductCategoryName().replace('/','-'):"-") |
144 | +"_" | 190 | +"_" |
145 | +(StringUtils.isNotBlank(productQueryVO.getProductFunctionName())?productQueryVO.getProductFunctionName():"-") | 191 | +(StringUtils.isNotBlank(productQueryVO.getProductFunctionName())?productQueryVO.getProductFunctionName():"-") |
146 | +"_" | 192 | +"_" |
shop/src/main/java/com/canrd/shop/module/vo/ProductQueryVO.java
@@ -36,6 +36,11 @@ public class ProductQueryVO extends BasePageVO implements Serializable { | @@ -36,6 +36,11 @@ public class ProductQueryVO extends BasePageVO implements Serializable { | ||
36 | private String rootProductCategoryId; | 36 | private String rootProductCategoryId; |
37 | 37 | ||
38 | /** | 38 | /** |
39 | + * 顶级产品分类 | ||
40 | + */ | ||
41 | + private List<String> rootProductCategoryIdIn; | ||
42 | + | ||
43 | + /** | ||
39 | * 产品分类id | 44 | * 产品分类id |
40 | */ | 45 | */ |
41 | private String productCategoryId; | 46 | private String productCategoryId; |
shop/src/main/java/com/canrd/shop/service/ProductCategoryService.java
@@ -5,6 +5,7 @@ import com.canrd.shop.common.constant.ServerResult; | @@ -5,6 +5,7 @@ import com.canrd.shop.common.constant.ServerResult; | ||
5 | import com.canrd.shop.module.dto.ProductCategoryDO; | 5 | import com.canrd.shop.module.dto.ProductCategoryDO; |
6 | import com.canrd.shop.module.dto.ProductDO; | 6 | import com.canrd.shop.module.dto.ProductDO; |
7 | import com.canrd.shop.module.vo.ProductCategoryQueryVO; | 7 | import com.canrd.shop.module.vo.ProductCategoryQueryVO; |
8 | +import com.canrd.shop.module.vo.ProductCategoryResultVO; | ||
8 | import com.canrd.shop.module.vo.ProductQueryVO; | 9 | import com.canrd.shop.module.vo.ProductQueryVO; |
9 | 10 | ||
10 | /** | 11 | /** |
@@ -18,6 +19,6 @@ public interface ProductCategoryService extends IService<ProductCategoryDO> { | @@ -18,6 +19,6 @@ public interface ProductCategoryService extends IService<ProductCategoryDO> { | ||
18 | * @param productCategoryQueryVO | 19 | * @param productCategoryQueryVO |
19 | * @return | 20 | * @return |
20 | */ | 21 | */ |
21 | - ServerResult category(ProductCategoryQueryVO productCategoryQueryVO); | 22 | + ServerResult<ProductCategoryResultVO> category(ProductCategoryQueryVO productCategoryQueryVO); |
22 | 23 | ||
23 | } | 24 | } |
shop/src/main/java/com/canrd/shop/service/impl/ProductCagegoryServiceImpl.java
@@ -40,7 +40,7 @@ public class ProductCagegoryServiceImpl extends ServiceImpl<ProductCategoryMappe | @@ -40,7 +40,7 @@ public class ProductCagegoryServiceImpl extends ServiceImpl<ProductCategoryMappe | ||
40 | private ProductFunctionService productFunctionService; | 40 | private ProductFunctionService productFunctionService; |
41 | 41 | ||
42 | @Override | 42 | @Override |
43 | - public ServerResult category(ProductCategoryQueryVO productCategoryQueryVO) { | 43 | + public ServerResult<ProductCategoryResultVO> category(ProductCategoryQueryVO productCategoryQueryVO) { |
44 | List<ProductCategoryDO> productCategoryDOList = this.list(); | 44 | List<ProductCategoryDO> productCategoryDOList = this.list(); |
45 | List<ProductCategoryVO> energyMaterialCategoryList = Lists.newArrayList(); | 45 | List<ProductCategoryVO> energyMaterialCategoryList = Lists.newArrayList(); |
46 | List<ProductCategoryVO> laboratoryConsumables = Lists.newArrayList(); | 46 | List<ProductCategoryVO> laboratoryConsumables = Lists.newArrayList(); |
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
@@ -283,6 +283,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | @@ -283,6 +283,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | ||
283 | queryWapper.eq("pc.id",productQueryVO.getProductCategoryId()); | 283 | queryWapper.eq("pc.id",productQueryVO.getProductCategoryId()); |
284 | }else if (StringUtils.isNotBlank(productQueryVO.getRootProductCategoryId())){ | 284 | }else if (StringUtils.isNotBlank(productQueryVO.getRootProductCategoryId())){ |
285 | queryWapper.eq("pc.id",productQueryVO.getRootProductCategoryId()); | 285 | queryWapper.eq("pc.id",productQueryVO.getRootProductCategoryId()); |
286 | + queryWapper.in(CollUtil.isNotEmpty(productQueryVO.getRootProductCategoryIdIn()),"pc.id",productQueryVO.getRootProductCategoryIdIn()); | ||
286 | } | 287 | } |
287 | if(StringUtils.isNotBlank(productQueryVO.getProductFunctionId())){ | 288 | if(StringUtils.isNotBlank(productQueryVO.getProductFunctionId())){ |
288 | queryWapper.eq("pf.id",productQueryVO.getProductFunctionId()); | 289 | queryWapper.eq("pf.id",productQueryVO.getProductFunctionId()); |
@@ -390,6 +391,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | @@ -390,6 +391,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | ||
390 | queryWapper.eq("pc.id",productQueryVO.getProductCategoryId()); | 391 | queryWapper.eq("pc.id",productQueryVO.getProductCategoryId()); |
391 | }else if (StringUtils.isNotBlank(productQueryVO.getRootProductCategoryId())){ | 392 | }else if (StringUtils.isNotBlank(productQueryVO.getRootProductCategoryId())){ |
392 | queryWapper.eq("pc.id",productQueryVO.getRootProductCategoryId()); | 393 | queryWapper.eq("pc.id",productQueryVO.getRootProductCategoryId()); |
394 | + queryWapper.in(CollUtil.isNotEmpty(productQueryVO.getRootProductCategoryIdIn()),"pc.id",productQueryVO.getRootProductCategoryIdIn()); | ||
395 | + | ||
393 | } | 396 | } |
394 | if(StringUtils.isNotBlank(productQueryVO.getProductFunctionId())){ | 397 | if(StringUtils.isNotBlank(productQueryVO.getProductFunctionId())){ |
395 | queryWapper.eq("pf.id",productQueryVO.getProductFunctionId()); | 398 | queryWapper.eq("pf.id",productQueryVO.getProductFunctionId()); |
shop/src/main/resources/templates/canrud.ftl
@@ -27202,7 +27202,7 @@ | @@ -27202,7 +27202,7 @@ | ||
27202 | </div> | 27202 | </div> |
27203 | <div data-v-f467c4e7="" class="v-card-text tw-text-left font-weight-medium title"> | 27203 | <div data-v-f467c4e7="" class="v-card-text tw-text-left font-weight-medium title"> |
27204 | <!--商品--> | 27204 | <!--商品--> |
27205 | - <h3 data-v-f6bc2735="" style="color: red;"> ${item.price}</h3> | 27205 | + <h3 data-v-f6bc2735="" style="color: red;"> ${item.price!""}</h3> |
27206 | <h4 data-v-f467c4e7="">${item.name}</h4> | 27206 | <h4 data-v-f467c4e7="">${item.name}</h4> |
27207 | </div> | 27207 | </div> |
27208 | <!----><span class="v-card__overlay"></span><span | 27208 | <!----><span class="v-card__overlay"></span><span |