Commit 50f7be99767f647b267129f32fc3b7ebcbe04b27

Authored by YunaiV
1 parent ed34b18d

✨ MALL:简化商评论的 VO 转化,去除无用的接口

Showing 12 changed files with 126 additions and 312 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java
... ... @@ -2,19 +2,18 @@ package cn.iocoder.yudao.module.product.controller.admin.comment;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5 6 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.*;
6   -import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
7 7 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
8 8 import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
9 9 import io.swagger.v3.oas.annotations.Operation;
10 10 import io.swagger.v3.oas.annotations.tags.Tag;
  11 +import jakarta.annotation.Resource;
  12 +import jakarta.validation.Valid;
11 13 import org.springframework.security.access.prepost.PreAuthorize;
12 14 import org.springframework.validation.annotation.Validated;
13 15 import org.springframework.web.bind.annotation.*;
14 16  
15   -import jakarta.annotation.Resource;
16   -import jakarta.validation.Valid;
17   -
18 17 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
19 18 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
20 19  
... ... @@ -32,7 +31,7 @@ public class ProductCommentController {
32 31 @PreAuthorize("@ss.hasPermission('product:comment:query')")
33 32 public CommonResult<PageResult<ProductCommentRespVO>> getCommentPage(@Valid ProductCommentPageReqVO pageVO) {
34 33 PageResult<ProductCommentDO> pageResult = productCommentService.getCommentPage(pageVO);
35   - return success(ProductCommentConvert.INSTANCE.convertPage(pageResult));
  34 + return success(BeanUtils.toBean(pageResult, ProductCommentRespVO.class));
36 35 }
37 36  
38 37 @PutMapping("/update-visible")
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java deleted
1   -package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.Data;
5   -
6   -import jakarta.validation.constraints.NotNull;
7   -import jakarta.validation.constraints.Size;
8   -import java.util.List;
9   -
10   -@Data
11   -public class ProductCommentBaseVO {
12   -
13   - @Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868")
14   - private Long userId;
15   -
16   - @Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292")
17   - private Long orderItemId;
18   -
19   - @Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉")
20   - @NotNull(message = "评价人名称不能为空")
21   - private String userNickname;
22   -
23   - @Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
24   - @NotNull(message = "评价人头像不能为空")
25   - private String userAvatar;
26   -
27   - @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
28   - @NotNull(message = "商品 SKU 编号不能为空")
29   - private Long skuId;
30   -
31   - @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
32   - @NotNull(message = "描述星级不能为空")
33   - private Integer descriptionScores;
34   -
35   - @Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
36   - @NotNull(message = "服务星级分不能为空")
37   - private Integer benefitScores;
38   -
39   - @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快")
40   - @NotNull(message = "评论内容不能为空")
41   - private String content;
42   -
43   - @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]")
44   - @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
45   - private List<String> picUrls;
46   -
47   -}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentCreateReqVO.java
1 1 package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotNull;
  5 +import jakarta.validation.constraints.Size;
4 6 import lombok.Data;
5   -import lombok.EqualsAndHashCode;
6   -import lombok.ToString;
  7 +
  8 +import java.util.List;
7 9  
8 10 @Schema(description = "管理后台 - 商品评价创建 Request VO")
9 11 @Data
10   -@EqualsAndHashCode(callSuper = true)
11   -@ToString(callSuper = true)
12   -public class ProductCommentCreateReqVO extends ProductCommentBaseVO {
  12 +public class ProductCommentCreateReqVO {
  13 +
  14 + @Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868")
  15 + private Long userId;
  16 +
  17 + @Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292")
  18 + private Long orderItemId;
  19 +
  20 + @Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉")
  21 + @NotNull(message = "评价人名称不能为空")
  22 + private String userNickname;
  23 +
  24 + @Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
  25 + @NotNull(message = "评价人头像不能为空")
  26 + private String userAvatar;
  27 +
  28 + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  29 + @NotNull(message = "商品 SKU 编号不能为空")
  30 + private Long skuId;
  31 +
  32 + @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
  33 + @NotNull(message = "描述星级不能为空")
  34 + private Integer descriptionScores;
  35 +
  36 + @Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
  37 + @NotNull(message = "服务星级分不能为空")
  38 + private Integer benefitScores;
  39 +
  40 + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快")
  41 + @NotNull(message = "评论内容不能为空")
  42 + private String content;
  43 +
  44 + @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED,
  45 + example = "[https://www.iocoder.cn/xx.png]")
  46 + @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
  47 + private List<String> picUrls;
13 48  
14 49 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java
... ... @@ -2,32 +2,68 @@ package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
2 2  
3 3 import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSkuSaveReqVO;
4 4 import io.swagger.v3.oas.annotations.media.Schema;
5   -import jakarta.validation.constraints.NotNull;
6 5 import lombok.Data;
7   -import lombok.EqualsAndHashCode;
8   -import lombok.ToString;
9 6  
10 7 import java.time.LocalDateTime;
11 8 import java.util.List;
12 9  
13 10 @Schema(description = "管理后台 - 商品评价 Response VO")
14 11 @Data
15   -@EqualsAndHashCode(callSuper = true)
16   -@ToString(callSuper = true)
17   -public class ProductCommentRespVO extends ProductCommentBaseVO {
  12 +public class ProductCommentRespVO {
18 13  
19 14 @Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24965")
20 15 private Long id;
21 16  
  17 + @Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868")
  18 + private Long userId;
  19 +
  20 + @Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉")
  21 + private String userNickname;
  22 +
  23 + @Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
  24 + private String userAvatar;
22 25 @Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
23 26 private Boolean anonymous;
24 27  
25 28 @Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
26 29 private Long orderId;
27 30  
  31 + @Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292")
  32 + private Long orderItemId;
  33 +
  34 + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖")
  35 + private Long spuId;
  36 +
  37 + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  38 + private Long skuId;
  39 +
  40 + @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
  41 + private String spuName;
  42 +
  43 + @Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg")
  44 + private String skuPicUrl;
  45 +
  46 + @Schema(description = "商品 SKU 规格值数组")
  47 + private List<ProductSkuSaveReqVO.Property> skuProperties;
  48 +
28 49 @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED)
29 50 private Boolean visible;
30 51  
  52 + @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
  53 + private Integer scores;
  54 +
  55 + @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
  56 + private Integer descriptionScores;
  57 +
  58 + @Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
  59 + private Integer benefitScores;
  60 +
  61 + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快")
  62 + private String content;
  63 +
  64 + @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]")
  65 + private List<String> picUrls;
  66 +
31 67 @Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED)
32 68 private Boolean replyStatus;
33 69  
... ... @@ -43,21 +79,4 @@ public class ProductCommentRespVO extends ProductCommentBaseVO {
43 79 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
44 80 private LocalDateTime createTime;
45 81  
46   - @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
47   - private Integer scores;
48   -
49   - @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖")
50   - @NotNull(message = "商品 SPU 编号不能为空")
51   - private Long spuId;
52   -
53   - @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
54   - @NotNull(message = "商品 SPU 名称不能为空")
55   - private String spuName;
56   -
57   - @Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg")
58   - private String skuPicUrl;
59   -
60   - @Schema(description = "商品 SKU 规格值数组")
61   - private List<ProductSkuSaveReqVO.Property> skuProperties;
62   -
63 82 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java
... ... @@ -3,31 +3,21 @@ package cn.iocoder.yudao.module.product.controller.app.comment;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 7 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
7   -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
8 8 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
9   -import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
10 9 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
11 10 import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
12   -import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
13 11 import io.swagger.v3.oas.annotations.Operation;
14   -import io.swagger.v3.oas.annotations.Parameter;
15   -import io.swagger.v3.oas.annotations.Parameters;
16 12 import io.swagger.v3.oas.annotations.tags.Tag;
17   -import org.springframework.context.annotation.Lazy;
  13 +import jakarta.annotation.Resource;
  14 +import jakarta.validation.Valid;
18 15 import org.springframework.validation.annotation.Validated;
19 16 import org.springframework.web.bind.annotation.GetMapping;
20 17 import org.springframework.web.bind.annotation.RequestMapping;
21   -import org.springframework.web.bind.annotation.RequestParam;
22 18 import org.springframework.web.bind.annotation.RestController;
23 19  
24   -import jakarta.annotation.Resource;
25   -import jakarta.validation.Valid;
26   -import java.util.List;
27   -import java.util.Set;
28   -
29 20 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
30   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
31 21  
32 22 @Tag(name = "用户 APP - 商品评价")
33 23 @RestController
... ... @@ -38,43 +28,22 @@ public class AppProductCommentController {
38 28 @Resource
39 29 private ProductCommentService productCommentService;
40 30  
41   - @Resource
42   - @Lazy
43   - private ProductSkuService productSkuService;
44   -
45   - @GetMapping("/list")
46   - @Operation(summary = "获得最近的 n 条商品评价")
47   - @Parameters({
48   - @Parameter(name = "spuId", description = "商品 SPU 编号", required = true, example = "1024"),
49   - @Parameter(name = "count", description = "数量", required = true, example = "10")
50   - })
51   - public CommonResult<List<AppProductCommentRespVO>> getCommentList(
52   - @RequestParam("spuId") Long spuId,
53   - @RequestParam(value = "count", defaultValue = "10") Integer count) {
54   - return success(productCommentService.getCommentList(spuId, count));
55   - }
56   -
57 31 @GetMapping("/page")
58 32 @Operation(summary = "获得商品评价分页")
59 33 public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) {
60 34 // 查询评论分页
61   - PageResult<ProductCommentDO> commentPageResult = productCommentService.getCommentPage(pageVO, Boolean.TRUE);
62   - if (CollUtil.isEmpty(commentPageResult.getList())) {
63   - return success(PageResult.empty(commentPageResult.getTotal()));
  35 + PageResult<ProductCommentDO> pageResult = productCommentService.getCommentPage(pageVO, Boolean.TRUE);
  36 + if (CollUtil.isEmpty(pageResult.getList())) {
  37 + return success(PageResult.empty(pageResult.getTotal()));
64 38 }
65 39  
66 40 // 拼接返回
67   - Set<Long> skuIds = convertSet(commentPageResult.getList(), ProductCommentDO::getSkuId);
68   - PageResult<AppProductCommentRespVO> commentVOPageResult = ProductCommentConvert.INSTANCE.convertPage02(
69   - commentPageResult, productSkuService.getSkuList(skuIds));
70   - return success(commentVOPageResult);
71   - }
72   -
73   - // TODO 芋艿:需要搞下
74   - @GetMapping("/statistics")
75   - @Operation(summary = "获得商品的评价统计")
76   - public CommonResult<AppCommentStatisticsRespVO> getCommentStatistics(@Valid @RequestParam("spuId") Long spuId) {
77   - return success(productCommentService.getCommentStatistics(spuId, Boolean.TRUE));
  41 + pageResult.getList().forEach(item -> {
  42 + if (Boolean.TRUE.equals(item.getAnonymous())) {
  43 + item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
  44 + }
  45 + });
  46 + return success(BeanUtils.toBean(pageResult, AppProductCommentRespVO.class));
78 47 }
79 48  
80 49 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentStatisticsRespVO.java deleted
1   -package cn.iocoder.yudao.module.product.controller.app.comment.vo;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.Data;
5   -import lombok.ToString;
6   -
7   -@Schema(description = "APP - 商品评价页评论分类数统计 Response VO")
8   -@Data
9   -@ToString(callSuper = true)
10   -public class AppCommentStatisticsRespVO {
11   -
12   - @Schema(description = "好评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
13   - private Long goodCount;
14   -
15   - @Schema(description = "中评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
16   - private Long mediocreCount;
17   -
18   - @Schema(description = "差评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
19   - private Long negativeCount;
20   -
21   - @Schema(description = "总平均分", requiredMode = Schema.RequiredMode.REQUIRED, example = "3.55")
22   - private Double scores;
23   -
24   -}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java
... ... @@ -91,7 +91,8 @@ public class AppProductCommentRespVO {
91 91 @NotNull(message = "评论内容不能为空")
92 92 private String content;
93 93  
94   - @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]")
  94 + @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED,
  95 + example = "[https://www.iocoder.cn/xx.png]")
95 96 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
96 97 private List<String> picUrls;
97 98  
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java
1 1 package cn.iocoder.yudao.module.product.convert.comment;
2 2  
3   -import cn.hutool.core.util.ObjectUtil;
4   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
5   -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
  3 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 4 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
7 5 import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
8 6 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
9   -import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO;
10   -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
11   -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
12   -import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
13 7 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
14 8 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
15 9 import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
16 10 import org.mapstruct.Mapper;
17   -import org.mapstruct.Mapping;
18   -import org.mapstruct.Named;
19 11 import org.mapstruct.factory.Mappers;
20 12  
21 13 import java.math.BigDecimal;
22 14 import java.math.RoundingMode;
23   -import java.util.List;
24   -import java.util.Map;
25   -
26   -import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
27 15  
28 16 /**
29 17 * 商品评价 Convert
... ... @@ -35,99 +23,40 @@ public interface ProductCommentConvert {
35 23  
36 24 ProductCommentConvert INSTANCE = Mappers.getMapper(ProductCommentConvert.class);
37 25  
38   - ProductCommentRespVO convert(ProductCommentDO bean);
39   -
40   - @Mapping(target = "scores", expression = "java(calculateOverallScore(goodCount, mediocreCount, negativeCount))")
41   - AppCommentStatisticsRespVO convert(Long goodCount, Long mediocreCount, Long negativeCount);
42   -
43   - @Named("calculateOverallScore")
44   - default double calculateOverallScore(long goodCount, long mediocreCount, long negativeCount) {
45   - return (goodCount * 5 + mediocreCount * 3 + negativeCount) / (double) (goodCount + mediocreCount + negativeCount);
46   - }
47   -
48   - List<ProductCommentRespVO> convertList(List<ProductCommentDO> list);
49   -
50   - PageResult<ProductCommentRespVO> convertPage(PageResult<ProductCommentDO> page);
51   -
52   - PageResult<AppProductCommentRespVO> convertPage01(PageResult<ProductCommentDO> pageResult);
53   -
54   - default PageResult<AppProductCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult,
55   - List<ProductSkuDO> skuList) {
56   - Map<Long, ProductSkuDO> skuMap = CollectionUtils.convertMap(skuList, ProductSkuDO::getId);
57   - PageResult<AppProductCommentRespVO> page = convertPage01(pageResult);
58   - page.getList().forEach(item -> {
59   - // 判断用户是否选择匿名
60   - if (ObjectUtil.equal(item.getAnonymous(), true)) {
61   - item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
62   - }
63   - // 设置 SKU 规格值
64   - findAndThen(skuMap, item.getSkuId(),
65   - sku -> item.setSkuProperties(convertList01(sku.getProperties())));
66   - });
67   - return page;
68   - }
69   -
70   - List<AppProductPropertyValueDetailRespVO> convertList01(List<ProductSkuDO.Property> properties);
71   -
72   - /**
73   - * 计算综合评分
74   - *
75   - * @param descriptionScores 描述星级
76   - * @param benefitScores 服务星级
77   - * @return 综合评分
78   - */
79   - @Named("convertScores")
80   - default Integer convertScores(Integer descriptionScores, Integer benefitScores) {
81   - // 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2
82   - BigDecimal sumScore = new BigDecimal(descriptionScores + benefitScores);
83   - BigDecimal divide = sumScore.divide(BigDecimal.valueOf(2L), 0, RoundingMode.DOWN);
84   - return divide.intValue();
85   - }
86   -
87   - @Mapping(target = "scores",
88   - expression = "java(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()))")
89   - ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO);
90   -
91 26 default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO,
92 27 ProductSpuDO spu, ProductSkuDO sku, MemberUserRespDTO user) {
93   - ProductCommentDO comment = convert(createReqDTO).setReplyStatus(false);
  28 + ProductCommentDO comment = BeanUtils.toBean(createReqDTO, ProductCommentDO.class)
  29 + .setScores(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()));
94 30 if (user != null) {
95   - comment.setUserId(user.getId());
96   - comment.setUserNickname(user.getNickname());
97   - comment.setUserAvatar(user.getAvatar());
  31 + comment.setUserId(user.getId()).setUserNickname(user.getNickname()).setUserAvatar(user.getAvatar());
98 32 }
99 33 if (spu != null) {
100   - comment.setSpuId(spu.getId());
101   - comment.setSpuName(spu.getName());
  34 + comment.setSpuId(spu.getId()).setSpuName(spu.getName());
102 35 }
103 36 if (sku != null) {
104   - comment.setSkuPicUrl(sku.getPicUrl());
105   - comment.setSkuProperties(sku.getProperties());
  37 + comment.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
106 38 }
107 39 return comment;
108 40 }
109 41  
110   - @Mapping(target = "visible", constant = "true")
111   - @Mapping(target = "replyStatus", constant = "false")
112   - @Mapping(target = "userId", constant = "0L")
113   - @Mapping(target = "orderId", constant = "0L")
114   - @Mapping(target = "orderItemId", constant = "0L")
115   - @Mapping(target = "anonymous", expression = "java(Boolean.FALSE)")
116   - @Mapping(target = "scores",
117   - expression = "java(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()))")
118   - ProductCommentDO convert(ProductCommentCreateReqVO createReq);
119   -
120   - List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list);
121   -
122 42 default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu, ProductSkuDO sku) {
123   - ProductCommentDO commentDO = convert(createReq);
  43 + ProductCommentDO comment = BeanUtils.toBean(createReq, ProductCommentDO.class)
  44 + .setVisible(true).setUserId(0L).setAnonymous(false)
  45 + .setScores(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()));
124 46 if (spu != null) {
125   - commentDO.setSpuId(spu.getId()).setSpuName(spu.getName());
  47 + comment.setSpuId(spu.getId()).setSpuName(spu.getName());
126 48 }
127 49 if (sku != null) {
128   - commentDO.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
  50 + comment.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
129 51 }
130   - return commentDO;
  52 + return comment;
  53 + }
  54 +
  55 + default Integer convertScores(Integer descriptionScores, Integer benefitScores) {
  56 + // 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2
  57 + BigDecimal sumScore = new BigDecimal(descriptionScores + benefitScores);
  58 + BigDecimal divide = sumScore.divide(BigDecimal.valueOf(2L), 0, RoundingMode.DOWN);
  59 + return divide.intValue();
131 60 }
132 61  
133 62 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java
... ... @@ -144,13 +144,6 @@ public class ProductSpuDO extends BaseDO {
144 144 * 赠送积分
145 145 */
146 146 private Integer giveIntegral;
147   - /**
148   - * 赠送的优惠劵编号的数组
149   - *
150   - * 对应 CouponTemplateDO 的 id 属性
151   - */
152   - @TableField(typeHandler = JacksonTypeHandler.class)
153   - private List<Long> giveCouponTemplateIds;
154 147  
155 148 // TODO @puhui999:字段估计要改成 brokerageType
156 149 /**
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java
1 1 package cn.iocoder.yudao.module.product.dal.mysql.comment;
2 2  
3 3 import cn.hutool.core.util.ObjectUtil;
4   -import cn.iocoder.yudao.framework.common.pojo.PageParam;
5 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 5 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
7 6 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
... ... @@ -59,21 +58,4 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; {
59 58 .eq(ProductCommentDO::getOrderItemId, orderItemId));
60 59 }
61 60  
62   - default Long selectCountBySpuId(Long spuId, Boolean visible, Integer type) {
63   - LambdaQueryWrapperX<ProductCommentDO> queryWrapper = new LambdaQueryWrapperX<ProductCommentDO>()
64   - .eqIfPresent(ProductCommentDO::getSpuId, spuId)
65   - .eqIfPresent(ProductCommentDO::getVisible, visible);
66   - // 构建评价查询语句
67   - appendTabQuery(queryWrapper, type);
68   - return selectCount(queryWrapper);
69   - }
70   -
71   - default PageResult<ProductCommentDO> selectCommentList(Long spuId, Integer count) {
72   - // 构建分页查询条件
73   - return selectPage(new PageParam().setPageSize(count), new LambdaQueryWrapperX<ProductCommentDO>()
74   - .eqIfPresent(ProductCommentDO::getSpuId, spuId)
75   - .orderByDesc(ProductCommentDO::getCreateTime)
76   - );
77   - }
78   -
79 61 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java
... ... @@ -7,14 +7,10 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen
7 7 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO;
8 8 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO;
9 9 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
10   -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
11   -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
12 10 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
13 11 import org.springframework.stereotype.Service;
14 12 import org.springframework.validation.annotation.Validated;
15 13  
16   -import java.util.List;
17   -
18 14 /**
19 15 * 商品评论 Service 接口
20 16 *
... ... @@ -73,22 +69,4 @@ public interface ProductCommentService {
73 69 */
74 70 PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible);
75 71  
76   - /**
77   - * 获得商品的评价统计
78   - *
79   - * @param spuId spu id
80   - * @param visible 是否可见
81   - * @return 评价统计
82   - */
83   - AppCommentStatisticsRespVO getCommentStatistics(Long spuId, Boolean visible);
84   -
85   - /**
86   - * 得到评论列表
87   - *
88   - * @param spuId 商品 id
89   - * @param count 数量
90   - * @return {@link Object}
91   - */
92   - List<AppProductCommentRespVO> getCommentList(Long spuId, Integer count);
93   -
94 72 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java
... ... @@ -9,8 +9,6 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen
9 9 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO;
10 10 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO;
11 11 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
12   -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
13   -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
14 12 import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
15 13 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
16 14 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
... ... @@ -18,13 +16,12 @@ import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
18 16 import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper;
19 17 import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
20 18 import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
  19 +import jakarta.annotation.Resource;
21 20 import org.springframework.context.annotation.Lazy;
22 21 import org.springframework.stereotype.Service;
23 22 import org.springframework.validation.annotation.Validated;
24 23  
25   -import jakarta.annotation.Resource;
26 24 import java.time.LocalDateTime;
27   -import java.util.List;
28 25  
29 26 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
30 27 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
... ... @@ -54,28 +51,28 @@ public class ProductCommentServiceImpl implements ProductCommentService {
54 51 @Override
55 52 public void createComment(ProductCommentCreateReqVO createReqVO) {
56 53 // 校验 SKU
57   - ProductSkuDO skuDO = validateSku(createReqVO.getSkuId());
  54 + ProductSkuDO sku = validateSku(createReqVO.getSkuId());
58 55 // 校验 SPU
59   - ProductSpuDO spuDO = validateSpu(skuDO.getSpuId());
  56 + ProductSpuDO spu = validateSpu(sku.getSpuId());
60 57  
61 58 // 创建评论
62   - ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqVO, spuDO, skuDO);
  59 + ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqVO, spu, sku);
63 60 productCommentMapper.insert(comment);
64 61 }
65 62  
66 63 @Override
67 64 public Long createComment(ProductCommentCreateReqDTO createReqDTO) {
68 65 // 校验 SKU
69   - ProductSkuDO skuDO = validateSku(createReqDTO.getSkuId());
  66 + ProductSkuDO sku = validateSku(createReqDTO.getSkuId());
70 67 // 校验 SPU
71   - ProductSpuDO spuDO = validateSpu(skuDO.getSpuId());
  68 + ProductSpuDO spu = validateSpu(sku.getSpuId());
72 69 // 校验评论
73 70 validateCommentExists(createReqDTO.getUserId(), createReqDTO.getOrderId());
74 71 // 获取用户详细信息
75 72 MemberUserRespDTO user = memberUserApi.getUser(createReqDTO.getUserId());
76 73  
77 74 // 创建评论
78   - ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqDTO, spuDO, skuDO, user);
  75 + ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqDTO, spu, sku, user);
79 76 productCommentMapper.insert(comment);
80 77 return comment.getId();
81 78 }
... ... @@ -138,23 +135,6 @@ public class ProductCommentServiceImpl implements ProductCommentService {
138 135 }
139 136  
140 137 @Override
141   - public AppCommentStatisticsRespVO getCommentStatistics(Long spuId, Boolean visible) {
142   - return ProductCommentConvert.INSTANCE.convert(
143   - // 查询商品 id = spuId 的所有好评数量
144   - productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.GOOD_COMMENT),
145   - // 查询商品 id = spuId 的所有中评数量
146   - productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.MEDIOCRE_COMMENT),
147   - // 查询商品 id = spuId 的所有差评数量
148   - productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.NEGATIVE_COMMENT)
149   - );
150   - }
151   -
152   - @Override
153   - public List<AppProductCommentRespVO> getCommentList(Long spuId, Integer count) {
154   - return ProductCommentConvert.INSTANCE.convertList02(productCommentMapper.selectCommentList(spuId, count).getList());
155   - }
156   -
157   - @Override
158 138 public PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) {
159 139 return productCommentMapper.selectPage(pageVO, visible);
160 140 }
... ...