Commit 70b9ec3ef2fb84a82975515d7fc76fdec05bd827
1 parent
91f82d07
商品价格显示修改
Showing
10 changed files
with
98 additions
and
16 deletions
shop/pom.xml
... | ... | @@ -13,6 +13,11 @@ |
13 | 13 | |
14 | 14 | <dependencies> |
15 | 15 | <dependency> |
16 | + <groupId>commons-collections</groupId> | |
17 | + <artifactId>commons-collections</artifactId> | |
18 | + <version>3.2.1</version> | |
19 | + </dependency> | |
20 | + <dependency> | |
16 | 21 | <groupId>org.springframework.boot</groupId> |
17 | 22 | <artifactId>spring-boot-starter-web</artifactId> |
18 | 23 | <!-- <version>2.2.5.RELEASE</version>--> | ... | ... |
shop/src/main/java/com/canrd/shop/common/constant/PriceConstants.java
0 → 100644
shop/src/main/java/com/canrd/shop/common/constant/SwitchControlConstants.java
0 → 100644
1 | +package com.canrd.shop.common.constant; | |
2 | + | |
3 | +/** | |
4 | + * @author zhongnanhuang | |
5 | + * @version 1.0 | |
6 | + * @project canrd-services | |
7 | + * @description | |
8 | + * @date 2024/11/7 16:00:18 | |
9 | + */ | |
10 | +public class SwitchControlConstants { | |
11 | + | |
12 | + public static final String PRODUCT_PRICE_SHOW = "product_price_show"; | |
13 | +} | ... | ... |
shop/src/main/java/com/canrd/shop/controller/ProductController.java
... | ... | @@ -7,11 +7,21 @@ import com.canrd.shop.module.vo.ProductQueryVO; |
7 | 7 | import com.canrd.shop.module.vo.ProductVO; |
8 | 8 | import com.canrd.shop.service.ProductCategoryService; |
9 | 9 | import com.canrd.shop.service.ProductService; |
10 | +import org.apache.commons.collections.Transformer; | |
11 | +import org.apache.commons.collections.functors.ChainedTransformer; | |
12 | +import org.apache.commons.collections.functors.ConstantTransformer; | |
13 | +import org.apache.commons.collections.functors.InvokerTransformer; | |
14 | +import org.apache.commons.collections.keyvalue.TiedMapEntry; | |
15 | +import org.apache.commons.collections.map.LazyMap; | |
10 | 16 | import org.springframework.beans.factory.annotation.Autowired; |
11 | 17 | import org.springframework.validation.annotation.Validated; |
12 | 18 | import org.springframework.web.bind.annotation.*; |
13 | 19 | |
14 | 20 | import javax.annotation.Resource; |
21 | +import java.io.*; | |
22 | +import java.lang.reflect.Field; | |
23 | +import java.util.HashMap; | |
24 | +import java.util.Map; | |
15 | 25 | |
16 | 26 | /** |
17 | 27 | * (Product)表控制层 | ... | ... |
shop/src/main/java/com/canrd/shop/module/dto/ProductDO.java
... | ... | @@ -6,6 +6,7 @@ import lombok.*; |
6 | 6 | import lombok.experimental.SuperBuilder; |
7 | 7 | |
8 | 8 | import java.io.Serializable; |
9 | +import java.math.BigDecimal; | |
9 | 10 | import java.util.Date; |
10 | 11 | |
11 | 12 | /** |
... | ... | @@ -93,7 +94,7 @@ public class ProductDO implements Serializable { |
93 | 94 | |
94 | 95 | private Integer point; |
95 | 96 | |
96 | - private Double price; | |
97 | + private BigDecimal price; | |
97 | 98 | |
98 | 99 | private String productimageliststore; |
99 | 100 | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/ProductVO.java
... | ... | @@ -4,6 +4,7 @@ import lombok.*; |
4 | 4 | import lombok.experimental.SuperBuilder; |
5 | 5 | |
6 | 6 | import java.io.Serializable; |
7 | +import java.math.BigDecimal; | |
7 | 8 | import java.util.Date; |
8 | 9 | import java.util.List; |
9 | 10 | |
... | ... | @@ -92,7 +93,8 @@ public class ProductVO implements Serializable { |
92 | 93 | |
93 | 94 | private Integer point; |
94 | 95 | |
95 | - private Double price; | |
96 | + private BigDecimal price; | |
97 | + private Boolean priceShow; | |
96 | 98 | |
97 | 99 | private String productimageliststore; |
98 | 100 | ... | ... |
shop/src/main/java/com/canrd/shop/module/vo/TickeyTypeVO.java
1 | 1 | package com.canrd.shop.module.vo; |
2 | 2 | |
3 | -import lombok.AllArgsConstructor; | |
4 | -import lombok.Data; | |
5 | -import lombok.EqualsAndHashCode; | |
6 | -import lombok.NoArgsConstructor; | |
7 | -import lombok.ToString; | |
3 | +import lombok.*; | |
8 | 4 | import lombok.experimental.SuperBuilder; |
9 | 5 | |
10 | 6 | import java.math.BigDecimal; |
... | ... | @@ -35,4 +31,13 @@ public class TickeyTypeVO { |
35 | 31 | * 产品价格 |
36 | 32 | */ |
37 | 33 | private BigDecimal price; |
34 | + | |
35 | + @Setter | |
36 | + private Boolean priceShow; | |
37 | + | |
38 | + public Boolean getPriceShow(){ | |
39 | + return price != null; | |
40 | + } | |
41 | + | |
42 | + private String priceUnit; | |
38 | 43 | } | ... | ... |
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
... | ... | @@ -8,7 +8,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage; |
8 | 8 | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
9 | 9 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
10 | 10 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
11 | +import com.canrd.shop.common.constant.PriceConstants; | |
11 | 12 | import com.canrd.shop.common.constant.ServerResult; |
13 | +import com.canrd.shop.common.constant.SwitchControlConstants; | |
12 | 14 | import com.canrd.shop.common.utils.ChatGptUtil; |
13 | 15 | import com.canrd.shop.common.utils.PageUtils; |
14 | 16 | import com.canrd.shop.common.utils.StringUtils; |
... | ... | @@ -22,18 +24,18 @@ import com.canrd.shop.module.dto.TicketTypeDO; |
22 | 24 | import com.canrd.shop.module.vo.ProductAttributeVO; |
23 | 25 | import com.canrd.shop.module.vo.ProductQueryVO; |
24 | 26 | import com.canrd.shop.module.vo.ProductVO; |
25 | -import com.canrd.shop.service.BrandService; | |
26 | -import com.canrd.shop.service.ProductAttributeMapStoreService; | |
27 | -import com.canrd.shop.service.ProductAttributeService; | |
28 | -import com.canrd.shop.service.ProductService; | |
29 | -import com.canrd.shop.service.TicketTypeService; | |
27 | +import com.canrd.shop.module.vo.TickeyTypeVO; | |
28 | +import com.canrd.shop.service.*; | |
30 | 29 | import com.google.common.collect.Lists; |
31 | 30 | import com.google.common.collect.Sets; |
32 | 31 | import lombok.extern.slf4j.Slf4j; |
32 | +import org.apache.commons.lang3.BooleanUtils; | |
33 | 33 | import org.springframework.beans.factory.annotation.Autowired; |
34 | 34 | import org.springframework.stereotype.Service; |
35 | 35 | |
36 | 36 | import java.io.IOException; |
37 | +import java.math.BigDecimal; | |
38 | +import java.math.RoundingMode; | |
37 | 39 | import java.util.*; |
38 | 40 | import java.util.function.Function; |
39 | 41 | import java.util.stream.Collectors; |
... | ... | @@ -70,6 +72,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
70 | 72 | @Autowired |
71 | 73 | private ChatGptUtil chatGptUtil; |
72 | 74 | |
75 | + @Autowired | |
76 | + private ISwitchControlService switchControlService; | |
77 | + | |
73 | 78 | /** |
74 | 79 | * 通过ID查询单条数据 |
75 | 80 | * <p> |
... | ... | @@ -86,6 +91,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
86 | 91 | if (Objects.isNull(productDO)) { |
87 | 92 | return ServerResult.success(null); |
88 | 93 | } |
94 | + | |
89 | 95 | ProductVO productVO = productConverter.convertToProductVO(productDO); |
90 | 96 | if (StringUtils.isNotBlank(productDO.getBrandId())) { |
91 | 97 | BrandDO brandDO = brandService.getById(productDO.getBrandId()); |
... | ... | @@ -109,11 +115,20 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
109 | 115 | }); |
110 | 116 | productVO.setProductAttributeList(productAttributeVOS); |
111 | 117 | } |
112 | - | |
118 | + // 金额处理 | |
119 | + Boolean productPriceShow = switchControlService.getEnabledByName(SwitchControlConstants.PRODUCT_PRICE_SHOW); | |
113 | 120 | List<TicketTypeDO> ticketTypeDOS = ticketTypeService.selectByProductId(productDO.getId()); |
114 | 121 | if(CollectionUtils.isNotEmpty(ticketTypeDOS)){ |
115 | - productVO.setTicketTypes(ticketTypeDOS.stream().map(productConverter::convertToTickeyTypeVO).collect(Collectors.toList())); | |
122 | + List<TickeyTypeVO> typeVOS = ticketTypeDOS.stream().map(productConverter::convertToTickeyTypeVO).collect(Collectors.toList()); | |
123 | + for (TickeyTypeVO typeVO : typeVOS) { | |
124 | + handleProductPriceShow(productPriceShow,typeVO); | |
125 | + } | |
126 | + productVO.setTicketTypes(typeVOS); | |
116 | 127 | } |
128 | + | |
129 | + productVO.setPriceShow(productPriceShow); | |
130 | + | |
131 | + | |
117 | 132 | return ServerResult.success(productVO); |
118 | 133 | } |
119 | 134 | |
... | ... | @@ -220,9 +235,28 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im |
220 | 235 | List<ProductDO> allProductList = Lists.newArrayList(); |
221 | 236 | allProductList.addAll(accurateProducts); |
222 | 237 | allProductList.addAll(similarProductList); |
238 | + | |
223 | 239 | return pager(productQueryVO,allProductList); |
224 | 240 | } |
225 | 241 | |
242 | + private void handleProductPriceShow(Boolean productPriceShow, TickeyTypeVO tickeyTypeVO) { | |
243 | + if (BooleanUtils.isTrue(productPriceShow)) { | |
244 | + BigDecimal price = tickeyTypeVO.getPrice(); | |
245 | + if (price == null) { | |
246 | + return; | |
247 | + } | |
248 | + BigDecimal computedPrice = price | |
249 | + .divide(new BigDecimal("0.7"), 2, RoundingMode.HALF_UP) | |
250 | + .multiply(new BigDecimal("0.148")) | |
251 | + .setScale(2, RoundingMode.HALF_UP); | |
252 | + tickeyTypeVO.setPrice(computedPrice); | |
253 | + tickeyTypeVO.setPriceUnit(PriceConstants.USD); | |
254 | + return; | |
255 | + } | |
256 | + | |
257 | + tickeyTypeVO.setPrice(null); | |
258 | + } | |
259 | + | |
226 | 260 | public ServerResult pager(ProductQueryVO productQueryVO,List<ProductDO> allProductList) { |
227 | 261 | int pageSize = productQueryVO.getPageSize(); |
228 | 262 | int pageNumber = productQueryVO.getPageNo(); | ... | ... |
shop/src/main/resources/application-prod.yml
... | ... | @@ -59,7 +59,7 @@ spring: |
59 | 59 | testOnReturn: true |
60 | 60 | password: 123456 |
61 | 61 | time-between-eviction-runs-millis: 1000 |
62 | - url: jdbc:mysql://47.89.254.121:3306/canrd_overseas?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true | |
62 | + url: jdbc:mysql://localhost:3306/canrd_overseas?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true | |
63 | 63 | username: root |
64 | 64 | |
65 | 65 | ... | ... |