Commit 7375407db5fde7ef95e6bc56b1a12aa609618dc1
1 parent
4ee4435a
feat(静态页面生成): 实现产品列表静态页面生成功能
- 新增静态页面配置和生成逻辑 - 添加 FreeMarker 模板支持 - 实现产品数据动态加载和渲染 - 优化产品价格显示逻辑 - 新增静态资源路径配置
Showing
6 changed files
with
68 additions
and
12 deletions
shop/src/main/java/com/canrd/shop/config/StaticHtmlConfig.java
shop/src/main/java/com/canrd/shop/controller/ProductController.java
1 | 1 | package com.canrd.shop.controller; |
2 | 2 | |
3 | +import cn.hutool.core.collection.CollUtil; | |
3 | 4 | import com.canrd.shop.common.constant.ServerResult; |
5 | +import com.canrd.shop.common.exception.BusinessException; | |
4 | 6 | import com.canrd.shop.common.jsr303.OperateGroup; |
5 | 7 | import com.canrd.shop.config.StaticHtmlConfig; |
8 | +import com.canrd.shop.module.dto.ProductCategoryDO; | |
6 | 9 | import com.canrd.shop.module.dto.ProductDO; |
10 | +import com.canrd.shop.module.dto.ProductFunctionDO; | |
7 | 11 | import com.canrd.shop.module.vo.ProductCategoryQueryVO; |
8 | 12 | import com.canrd.shop.module.vo.ProductQueryVO; |
9 | 13 | import com.canrd.shop.module.vo.ProductVO; |
10 | 14 | import com.canrd.shop.service.ProductCategoryService; |
15 | +import com.canrd.shop.service.ProductFunctionService; | |
11 | 16 | import com.canrd.shop.service.ProductService; |
12 | 17 | import freemarker.template.Configuration; |
13 | 18 | import freemarker.template.Template; |
... | ... | @@ -51,6 +56,9 @@ public class ProductController { |
51 | 56 | @Autowired |
52 | 57 | private ProductCategoryService productCategoryService; |
53 | 58 | |
59 | + @Autowired | |
60 | + private ProductFunctionService productFunctionService; | |
61 | + | |
54 | 62 | /** |
55 | 63 | * 产品分类 |
56 | 64 | * |
... | ... | @@ -85,12 +93,46 @@ public class ProductController { |
85 | 93 | * @return 查询结果 |
86 | 94 | */ |
87 | 95 | @GetMapping("/generateList") |
88 | - public ServerResult generateList(@Validated({OperateGroup.List.class}) ProductQueryVO productQueryVO) throws IOException, TemplateException { | |
96 | + public ServerResult generateList(@Validated({OperateGroup.List.class}) ProductQueryVO productQueryVO | |
97 | + ,@RequestParam(value = "secret",required = true) String secret) | |
98 | + throws IOException, TemplateException { | |
99 | + if (!Objects.equals(secret, staticHtmlConfig.getSecret())){ | |
100 | + return ServerResult.fail("secret error"); | |
101 | + } | |
102 | + if(StringUtils.isNotBlank(productQueryVO.getProductCategoryName())){ | |
103 | + Optional<ProductCategoryDO> productCategoryDOOpt = productCategoryService.lambdaQuery() | |
104 | + .eq(ProductCategoryDO::getName, productQueryVO.getProductCategoryName()) | |
105 | + .oneOpt(); | |
106 | + productQueryVO | |
107 | + .setProductCategoryId(productCategoryDOOpt | |
108 | + .orElseThrow(()-> new BusinessException("productCategoryName not exist")) | |
109 | + .getId()); | |
110 | + } | |
111 | + if(StringUtils.isNotBlank(productQueryVO.getRootProductCategoryName())){ | |
112 | + Optional<ProductCategoryDO> productCategoryDOOpt = productCategoryService.lambdaQuery() | |
113 | + .eq(ProductCategoryDO::getName, productQueryVO.getRootProductCategoryName()) | |
114 | + .oneOpt(); | |
115 | + productQueryVO | |
116 | + .setRootProductCategoryId(productCategoryDOOpt | |
117 | + .orElseThrow(()-> new BusinessException("productCategoryName not exist")) | |
118 | + .getId()); | |
119 | + } | |
120 | + if(StringUtils.isNotBlank(productQueryVO.getProductFunctionName())){ | |
121 | + Optional<ProductFunctionDO> productFunctionDO = productFunctionService.lambdaQuery() | |
122 | + .eq(ProductFunctionDO::getName, productQueryVO.getProductFunctionName()) | |
123 | + .oneOpt(); | |
124 | + productQueryVO | |
125 | + .setProductFunctionId(productFunctionDO.orElseThrow(()-> new BusinessException("productFunctionName not exist")) | |
126 | + .getId()); | |
127 | + } | |
89 | 128 | String path = staticHtmlConfig.getUrl(); |
90 | - String fileName = Optional.ofNullable(productQueryVO.getRootProductCategoryId()).orElse("-")+"_" | |
91 | - +Optional.ofNullable(productQueryVO.getProductCategoryId()).orElse("-")+"_" | |
92 | - +Optional.ofNullable(productQueryVO.getProductFunctionId()).orElse("-")+"_" | |
93 | - +Optional.ofNullable(productQueryVO.getKeyword()).orElse("-").trim(); | |
129 | + String fileName = (StringUtils.isNotBlank(productQueryVO.getRootProductCategoryName())?productQueryVO.getRootProductCategoryName():"-") | |
130 | + +"_" | |
131 | + +(StringUtils.isNotBlank(productQueryVO.getProductCategoryName())?productQueryVO.getProductCategoryName():"-") | |
132 | + +"_" | |
133 | + +(StringUtils.isNotBlank(productQueryVO.getProductFunctionName())?productQueryVO.getProductFunctionName():"-") | |
134 | + +"_" | |
135 | + +(StringUtils.isNotBlank(productQueryVO.getKeyword())?productQueryVO.getKeyword():"-"); | |
94 | 136 | Map res = (Map) productService.listBySimilar(productQueryVO).getData(); |
95 | 137 | List<ProductDO> itemList = (List<ProductDO>) res.get("records"); |
96 | 138 | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/ProductQueryVO.java
... | ... | @@ -45,5 +45,20 @@ public class ProductQueryVO extends BasePageVO implements Serializable { |
45 | 45 | */ |
46 | 46 | private String productFunctionId; |
47 | 47 | |
48 | + /** | |
49 | + * 顶级产品分类 | |
50 | + */ | |
51 | + private String rootProductCategoryName; | |
52 | + | |
53 | + /** | |
54 | + * 产品分类id | |
55 | + */ | |
56 | + private String productCategoryName; | |
57 | + | |
58 | + /** | |
59 | + * 产品功能id | |
60 | + */ | |
61 | + private String productFunctionName; | |
62 | + | |
48 | 63 | } |
49 | 64 | ... | ... |
shop/src/main/resources/application-prod.yml
shop/src/main/resources/application-test.yml
shop/src/main/resources/application.yml