Commit 97a1d2ed4cf3622eb80efd833a33d3f68c37e1b1

Authored by 曾国涛
1 parent abb8bfd8

feat(product): 添加产品最低价和最高价字段并优化价格显示- 在 ProductDO 中添加 minPrice 和 maxPrice 字段

- 修改 ProductServiceImpl 中的产品列表查询逻辑,计算最低价和最高价
- 更新前端模板,显示产品价格区间
shop/src/main/java/com/canrd/shop/module/dto/ProductDO.java
@@ -140,5 +140,9 @@ public class ProductDO implements Serializable { @@ -140,5 +140,9 @@ public class ProductDO implements Serializable {
140 private Integer ttsTotalSimilar=0; 140 private Integer ttsTotalSimilar=0;
141 @TableField(exist = false) 141 @TableField(exist = false)
142 private List<String> relatedProductIds; 142 private List<String> relatedProductIds;
  143 + @TableField(exist = false)
  144 + private BigDecimal minPrice;
  145 + @TableField(exist = false)
  146 + private BigDecimal maxPrice;
143 147
144 } 148 }
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
@@ -375,6 +375,7 @@ public class ProductServiceImpl extends ServiceImpl&lt;ProductMapper, ProductDO&gt; im @@ -375,6 +375,7 @@ public class ProductServiceImpl extends ServiceImpl&lt;ProductMapper, ProductDO&gt; im
375 }) 375 })
376 .list(); 376 .list();
377 Map<String,BigDecimal> pId2ttMinPriceMap = new HashMap<>(); 377 Map<String,BigDecimal> pId2ttMinPriceMap = new HashMap<>();
  378 + Map<String,BigDecimal> pId3ttMaxPriceMap = new HashMap<>();
378 for (TicketTypeDO ticketTypeDO : tickeyTypeDOList) { 379 for (TicketTypeDO ticketTypeDO : tickeyTypeDOList) {
379 if (Objects.isNull(pId2ttMinPriceMap.get(ticketTypeDO.getProductId()))){ 380 if (Objects.isNull(pId2ttMinPriceMap.get(ticketTypeDO.getProductId()))){
380 pId2ttMinPriceMap.put(ticketTypeDO.getProductId(), ticketTypeDO.getPrice()); 381 pId2ttMinPriceMap.put(ticketTypeDO.getProductId(), ticketTypeDO.getPrice());
@@ -383,25 +384,15 @@ public class ProductServiceImpl extends ServiceImpl&lt;ProductMapper, ProductDO&gt; im @@ -383,25 +384,15 @@ public class ProductServiceImpl extends ServiceImpl&lt;ProductMapper, ProductDO&gt; im
383 pId2ttMinPriceMap.put(ticketTypeDO.getProductId(), ticketTypeDO.getPrice()); 384 pId2ttMinPriceMap.put(ticketTypeDO.getProductId(), ticketTypeDO.getPrice());
384 } 385 }
385 } 386 }
  387 + if (Objects.isNull(pId3ttMaxPriceMap.get(ticketTypeDO.getProductId()))){
  388 + pId3ttMaxPriceMap.put(ticketTypeDO.getProductId(), ticketTypeDO.getPrice());
  389 + }else {
  390 + if (pId3ttMaxPriceMap.get(ticketTypeDO.getProductId()).compareTo(ticketTypeDO.getPrice())<0){
  391 + pId3ttMaxPriceMap.put(ticketTypeDO.getProductId(), ticketTypeDO.getPrice());
  392 + }
  393 + }
386 } 394 }
387 395
388 - /*List<Productcategoryrelation> productcategoryrelations = productCategoryRelationService.lambdaQuery()  
389 - .in(Productcategoryrelation::getProductId, productIds)  
390 - .list();  
391 - List<String> categoryIds = productcategoryrelations.stream().map(Productcategoryrelation::getCategoryId).collect(Collectors.toList());  
392 - Map<String,List<String>> productId2cateIds = productcategoryrelations.stream()  
393 - .collect(Collectors.groupingBy(Productcategoryrelation::getProductId,  
394 - Collectors.mapping(Productcategoryrelation::getCategoryId, Collectors.toList())));  
395 - List<EbCategorysRelation> cateRelations = ebCategorysRelationService.lambdaQuery()  
396 - .in(EbCategorysRelation::getCategoryId, categoryIds)  
397 - .list();  
398 - Map<String,List<EbCategorysRelation>> cateId2relCates = cateRelations.stream()  
399 - .collect(Collectors.groupingBy(EbCategorysRelation::getCategoryId,  
400 - Collectors.mapping(Function.identity(), Collectors.toList())));  
401 - Map<String,List<EbCategorysRelation>> prodId2relCateIds = productId2cateIds.entrySet().stream()  
402 - .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().stream()  
403 - .flatMap(cateId -> Optional.ofNullable(cateId2relCates.get(cateId)).orElse(Collections.emptyList()).stream())  
404 - .collect(Collectors.toList())));*/  
405 records.forEach(product -> { 396 records.forEach(product -> {
406 if (productPriceShow){ 397 if (productPriceShow){
407 if (Objects.nonNull(pId2ttMinPriceMap.get(product.getId()))){ 398 if (Objects.nonNull(pId2ttMinPriceMap.get(product.getId()))){
@@ -411,33 +402,19 @@ public class ProductServiceImpl extends ServiceImpl&lt;ProductMapper, ProductDO&gt; im @@ -411,33 +402,19 @@ public class ProductServiceImpl extends ServiceImpl&lt;ProductMapper, ProductDO&gt; im
411 .setScale(2, RoundingMode.HALF_UP); 402 .setScale(2, RoundingMode.HALF_UP);
412 product.setPrice(computedPrice); 403 product.setPrice(computedPrice);
413 } 404 }
  405 + if (Objects.nonNull(pId3ttMaxPriceMap.get(product.getId()))){
  406 + BigDecimal computedPrice = pId3ttMaxPriceMap.get(product.getId())
  407 + .divide(new BigDecimal("0.7"), 2, RoundingMode.HALF_UP)
  408 + .multiply(new BigDecimal("0.148"))
  409 + .setScale(2, RoundingMode.HALF_UP);
  410 + product.setMaxPrice(computedPrice);
  411 + }
414 } 412 }
415 //将productDO的productimageliststore解析为map 413 //将productDO的productimageliststore解析为map
416 List<Map> maps = JSON.parseArray(product.getProductimageliststore(), Map.class); 414 List<Map> maps = JSON.parseArray(product.getProductimageliststore(), Map.class);
417 Map map = maps.get(0); 415 Map map = maps.get(0);
418 product.setImageFileKey(map.get("fileKey").toString()); 416 product.setImageFileKey(map.get("fileKey").toString());
419 417
420 -  
421 - /*List<EbCategorysRelation> ebCategorysRelations = prodId2relCateIds.get(product.getId());*/  
422 - /*if (CollUtil.isNotEmpty(ebCategorysRelations)){  
423 - Map<String,Integer> relatedCateId2Relevance = ebCategorysRelations.stream()  
424 - .collect(Collectors.toMap(EbCategorysRelation::getRelatedCategoryId, EbCategorysRelation::getRelevance,(a, b) -> a));  
425 - TreeMap<String, Integer> cateId2Relevance = new TreeMap<>(relatedCateId2Relevance);  
426 - StringJoiner orderByJoiner = new StringJoiner(" when "," order by case pc.id when "," else 0 end ");  
427 - cateId2Relevance.forEach((k,v)->orderByJoiner.add("'"+k+"'"+" then "+v));  
428 - QueryWrapper<ProductDO> objectQueryWrapper = new QueryWrapper<ProductDO>()  
429 - .in("pc.id", cateId2Relevance.keySet())  
430 - .select("distinct p.id","pc.id")  
431 - .last(orderByJoiner.toString());  
432 - List<ProductDO> relatedProducts = this  
433 - .list(objectQueryWrapper);  
434 - List<String> relatedProductIds = relatedProducts.stream()  
435 - .map(ProductDO::getId)  
436 - .distinct()  
437 - .limit(10)  
438 - .collect(Collectors.toList());  
439 - product.setRelatedProductIds(relatedProductIds);  
440 - }*/  
441 }); 418 });
442 } 419 }
443 420
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!""} - $${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