Commit 1e1a22c256ea736ece7135a96b4430aaaab80464

Authored by YunaiV
1 parent 84b365a7

mall + product:评论的 review

Showing 17 changed files with 70 additions and 175 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java
... ... @@ -35,6 +35,7 @@ public class ProductCommentController {
35 35 return success(ProductCommentConvert.INSTANCE.convertPage(pageResult));
36 36 }
37 37  
  38 + // TODO @puhui999:update-visible
38 39 @PutMapping("/update/visible")
39 40 @Operation(summary = "显示 / 隐藏评论")
40 41 @PreAuthorize("@ss.hasPermission('product:comment:update')")
... ... @@ -55,6 +56,7 @@ public class ProductCommentController {
55 56 @Operation(summary = "添加自评")
56 57 @PreAuthorize("@ss.hasPermission('product:comment:update')")
57 58 public CommonResult<Boolean> createComment(@Valid @RequestBody ProductCommentCreateReqVO createReqVO) {
  59 + // TODO @puhui999:不用 ProductCommentConvert.INSTANCE.convert(createReqVO) 哈;多写一个 create 方法即可;
58 60 productCommentService.createComment(ProductCommentConvert.INSTANCE.convert(createReqVO), Boolean.TRUE);
59 61 return success(true);
60 62 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java
... ... @@ -10,6 +10,8 @@ import java.util.List;
10 10 @Data
11 11 public class ProductCommentBaseVO {
12 12  
  13 + // TODO @puhui999:把 example 补充下
  14 +
13 15 @Schema(description = "评价人名称", required = true, example = "张三")
14 16 @NotNull(message = "评价人名称不能为空")
15 17 private String userNickname;
... ... @@ -18,34 +20,30 @@ public class ProductCommentBaseVO {
18 20 @NotNull(message = "评价人头像不能为空")
19 21 private String userAvatar;
20 22  
21   - @Schema(description = "商品SPU编号", required = true, example = "29502")
22   - @NotNull(message = "商品SPU编号不能为空")
  23 + @Schema(description = "商品 SPU 编号", required = true, example = "29502")
  24 + @NotNull(message = "商品 SPU 编号不能为空")
23 25 private Long spuId;
24 26  
25   - @Schema(description = "商品SPU名称", required = true, example = "赵六")
26   - @NotNull(message = "商品SPU名称不能为空")
  27 + @Schema(description = "商品 SPU 名称", required = true, example = "赵六")
  28 + @NotNull(message = "商品 SPU 名称不能为空")
27 29 private String spuName;
28 30  
29   - @Schema(description = "商品SKU编号", required = true, example = "3082")
30   - @NotNull(message = "商品SKU编号不能为空")
  31 + @Schema(description = "商品 SKU 编号", required = true, example = "3082")
  32 + @NotNull(message = "商品 SKU 编号不能为空")
31 33 private Long skuId;
32 34  
33 35 @Schema(description = "评分星级 1-5分", required = true)
34   - @NotNull(message = "评分星级 1-5分不能为空")
  36 + @NotNull(message = "评分星级不能为空")
35 37 private Integer scores;
36 38  
37 39 @Schema(description = "描述星级 1-5分", required = true)
38   - @NotNull(message = "描述星级 1-5分不能为空")
  40 + @NotNull(message = "描述星级不能为空")
39 41 private Integer descriptionScores;
40 42  
41 43 @Schema(description = "服务星级 1-5分", required = true)
42   - @NotNull(message = "服务星级 1-5分不能为空")
  44 + @NotNull(message = "服务星级分不能为空")
43 45 private Integer benefitScores;
44 46  
45   - @Schema(description = "配送星级 1-5分", required = true)
46   - @NotNull(message = "配送星级 1-5分不能为空")
47   - private Integer deliveryScores;
48   -
49 47 @Schema(description = "评论内容", required = true)
50 48 @NotNull(message = "评论内容不能为空")
51 49 private String content;
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyVO.java
... ... @@ -4,8 +4,10 @@ import io.swagger.v3.oas.annotations.media.Schema;
4 4 import lombok.Data;
5 5 import lombok.ToString;
6 6  
  7 +import javax.validation.constraints.NotEmpty;
7 8 import javax.validation.constraints.NotNull;
8 9  
  10 +// TODO @puhui999:ReqVO
9 11 @Schema(description = "管理后台 - 商品评价可见修改 Request VO")
10 12 @Data
11 13 @ToString(callSuper = true)
... ... @@ -16,7 +18,7 @@ public class ProductCommentReplyVO {
16 18 private Long id;
17 19  
18 20 @Schema(description = "商家回复内容", required = true, example = "谢谢亲")
19   - @NotNull(message = "商家回复内容不能为空")
  21 + @NotEmpty(message = "商家回复内容不能为空")
20 22 private String replyContent;
21 23  
22 24 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java
... ... @@ -6,7 +6,6 @@ import lombok.EqualsAndHashCode;
6 6 import lombok.ToString;
7 7  
8 8 import java.time.LocalDateTime;
9   -import java.util.List;
10 9  
11 10 @Schema(description = "管理后台 - 商品评价 Response VO")
12 11 @Data
... ... @@ -33,7 +32,7 @@ public class ProductCommentRespVO extends ProductCommentBaseVO {
33 32 private Boolean visible;
34 33  
35 34 @Schema(description = "商家是否回复:[1:回复 0:未回复]", required = true)
36   - private Boolean replied;
  35 + private Boolean replyStatus;
37 36  
38 37 @Schema(description = "回复管理员编号", example = "22212")
39 38 private Long replyUserId;
... ... @@ -44,15 +43,6 @@ public class ProductCommentRespVO extends ProductCommentBaseVO {
44 43 @Schema(description = "商家回复时间")
45 44 private LocalDateTime replyTime;
46 45  
47   - @Schema(description = "追加评价内容")
48   - private String additionalContent;
49   -
50   - @Schema(description = "追评评价图片地址数组,以逗号分隔最多上传9张")
51   - private List<String> additionalPicUrls;
52   -
53   - @Schema(description = "追加评价时间")
54   - private LocalDateTime additionalTime;
55   -
56 46 @Schema(description = "创建时间", required = true)
57 47 private LocalDateTime createTime;
58 48  
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentUpdateVisibleReqVO.java
... ... @@ -15,7 +15,7 @@ public class ProductCommentUpdateVisibleReqVO {
15 15 @NotNull(message = "评价编号不能为空")
16 16 private Long id;
17 17  
18   - @Schema(description = "是否可见 true:显示 false:隐藏", required = true, example = "false")
  18 + @Schema(description = "是否可见", required = true, example = "false")
19 19 @NotNull(message = "是否可见不能为空")
20 20 private Boolean visible;
21 21  
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java
... ... @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
6 6 import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
7   -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO;
8 7 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentCreateReqVO;
9 8 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
10 9 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO;
... ... @@ -22,6 +21,7 @@ import java.util.Map;
22 21 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
23 22 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
24 23  
  24 +// TODO @puhui999:AppCommentController =》 AppProductCommentController
25 25 @Tag(name = "用户 APP - 商品评价")
26 26 @RestController
27 27 @RequestMapping("/product/comment")
... ... @@ -40,8 +40,9 @@ public class AppCommentController {
40 40 return success(productCommentService.getCommentPage(pageVO, Boolean.TRUE));
41 41 }
42 42  
  43 + // TODO @puhui999:方法名改成 getCommentStatistics?然后搞个对应的 vo?想了下,这样更优雅
43 44 @GetMapping("/get-count")
44   - @Operation(summary = "获得商品评价分页 tab count")
  45 + @Operation(summary = "获得商品的评价统计") // TODO @puhui999:@RequestParam 哈,针对 spuId
45 46 public CommonResult<Map<String, Long>> getCommentPage(@Valid Long spuId) {
46 47 return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE));
47 48 }
... ... @@ -50,18 +51,10 @@ public class AppCommentController {
50 51 @Operation(summary = "创建商品评价")
51 52 public CommonResult<Boolean> createComment(@RequestBody AppCommentCreateReqVO createReqVO) {
52 53 // TODO: 2023/3/20 要不要判断订单、商品是否存在
  54 + // TODO @ouhui999:这个接口,搞到交易那比较合适;
53 55 MemberUserRespDTO user = memberUserApi.getUser(getLoginUserId());
54 56 productCommentService.createComment(ProductCommentConvert.INSTANCE.convert(user, createReqVO), Boolean.FALSE);
55 57 return success(true);
56 58 }
57 59  
58   - @PostMapping(value = "/additional")
59   - @Operation(summary = "追加评论")
60   - public CommonResult<Boolean> additionalComment(@RequestBody AppCommentAdditionalReqVO createReqVO) {
61   - // 查询会员
62   - MemberUserRespDTO user = memberUserApi.getUser(getLoginUserId());
63   - productCommentService.additionalComment(user, createReqVO);
64   - return success(true);
65   - }
66   -
67 60 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentAdditionalReqVO.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   -import javax.validation.constraints.NotNull;
8   -import javax.validation.constraints.Size;
9   -import java.util.List;
10   -
11   -@Schema(description = "用户APP - 商品追加评价创建 Request VO")
12   -@Data
13   -@ToString(callSuper = true)
14   -public class AppCommentAdditionalReqVO {
15   -
16   - @Schema(description = "评论编号", required = true)
17   - @NotNull(message = "评论编号不能为空")
18   - private Long id;
19   -
20   - @Schema(description = "追加评价内容", required = true)
21   - @NotNull(message = "追加评价内容不能为空")
22   - private String additionalContent;
23   -
24   - @Schema(description = "追评评价图片地址数组,以逗号分隔最多上传9张", required = true)
25   - @Size(max = 9, message = "追评评价图片地址数组长度不能超过9张")
26   - private List<String> additionalPicUrls;
27   -
28   -}
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentBaseVO.java
... ... @@ -7,6 +7,7 @@ import javax.validation.constraints.NotNull;
7 7 import javax.validation.constraints.Size;
8 8 import java.util.List;
9 9  
  10 +// TODO @puhui999:把 Product 前缀给补下哈
10 11 @Data
11 12 public class AppCommentBaseVO {
12 13  
... ... @@ -34,10 +35,6 @@ public class AppCommentBaseVO {
34 35 @NotNull(message = "服务星级 1-5分不能为空")
35 36 private Integer benefitScores;
36 37  
37   - @Schema(description = "配送星级 1-5分", required = true)
38   - @NotNull(message = "配送星级 1-5分不能为空")
39   - private Integer deliveryScores;
40   -
41 38 @Schema(description = "评论内容", required = true)
42 39 @NotNull(message = "评论内容不能为空")
43 40 private String content;
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentCreateReqVO.java
... ... @@ -7,16 +7,19 @@ import lombok.ToString;
7 7  
8 8 import javax.validation.constraints.NotNull;
9 9  
  10 +// TODO @puhui999:不应该继承 AppCommentCreateReqVO
10 11 @Schema(description = "用户APP - 商品评价创建 Request VO")
11 12 @Data
12 13 @EqualsAndHashCode(callSuper = true)
13 14 @ToString(callSuper = true)
14 15 public class AppCommentCreateReqVO extends AppCommentBaseVO {
15 16  
16   - @Schema(description = "是否匿名 true:是 false:否", required = true, example = "true")
  17 + @Schema(description = "是否匿名", required = true, example = "true")
17 18 @NotNull(message = "是否匿名不能为空")
18 19 private Boolean anonymous;
19 20  
  21 + // TODO @puhui999:不应该传递 orderId
  22 +
20 23 @Schema(description = "交易订单编号", required = true, example = "12312")
21 24 @NotNull(message = "交易订单编号不能为空")
22 25 private Long orderId;
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java
... ... @@ -14,6 +14,7 @@ import javax.validation.constraints.NotNull;
14 14 @ToString(callSuper = true)
15 15 public class AppCommentPageReqVO extends PageParam {
16 16  
  17 + // TODO @puhui999:不传递就是 all;
17 18 /**
18 19 * 所有
19 20 */
... ... @@ -24,11 +25,13 @@ public class AppCommentPageReqVO extends PageParam {
24 25 */
25 26 public static final String ALL_COUNT = "allCount";
26 27  
  28 + // TODO @puhui999:good 好评;
27 29 /**
28 30 * 好评
29 31 */
30 32 public static final Integer FAVOURABLE_COMMENT = 1;
31 33  
  34 + // TODO @puhui999:medium 中评;然后 mediumCount 就好啦;
32 35 /**
33 36 * 好评数量 key
34 37 */
... ... @@ -54,6 +57,7 @@ public class AppCommentPageReqVO extends PageParam {
54 57 */
55 58 public static final String NEGATIVE_COMMENT_COUNT = "negativeCommentCount";
56 59  
  60 + // TODO @puhui999:这个挪到 DO 那没问题的哈;NICKNAME_ANONYMOUS
57 61 /**
58 62 * 默认匿名昵称
59 63 */
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java
... ... @@ -14,7 +14,9 @@ import java.util.List;
14 14 @ToString(callSuper = true)
15 15 public class AppCommentRespVO extends AppCommentBaseVO {
16 16  
17   - @Schema(description = "评价人 用户编号", required = true, example = "15721")
  17 + // TODO puhui999:把 example 也补充下哈
  18 +
  19 + @Schema(description = "评价人的用户编号", required = true, example = "15721")
18 20 private Long userId;
19 21  
20 22 @Schema(description = "评价人名称", required = true, example = "张三")
... ... @@ -36,7 +38,7 @@ public class AppCommentRespVO extends AppCommentBaseVO {
36 38 private Long orderItemId;
37 39  
38 40 @Schema(description = "商家是否回复", required = true)
39   - private Boolean replied;
  41 + private Boolean replyStatus;
40 42  
41 43 @Schema(description = "回复管理员编号", example = "22212")
42 44 private Long replyUserId;
... ... @@ -61,4 +63,5 @@ public class AppCommentRespVO extends AppCommentBaseVO {
61 63  
62 64 @Schema(description = "最终评分", required = true)
63 65 private Integer finalScore;
  66 +
64 67 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java
... ... @@ -30,6 +30,7 @@ public interface ProductCommentConvert {
30 30  
31 31 PageResult<AppCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult);
32 32  
  33 + // TODO @puhui999:用 mapstruct 的映射
33 34 default ProductCommentDO convert(MemberUserRespDTO user, AppCommentCreateReqVO createReqVO) {
34 35 ProductCommentDO productComment = new ProductCommentDO();
35 36 productComment.setUserId(user.getId());
... ... @@ -44,12 +45,12 @@ public interface ProductCommentConvert {
44 45 productComment.setScores(createReqVO.getScores());
45 46 productComment.setDescriptionScores(createReqVO.getDescriptionScores());
46 47 productComment.setBenefitScores(createReqVO.getBenefitScores());
47   - productComment.setDeliveryScores(createReqVO.getDeliveryScores());
48 48 productComment.setContent(createReqVO.getContent());
49 49 productComment.setPicUrls(createReqVO.getPicUrls());
50 50 return productComment;
51 51 }
52 52  
  53 + // TODO @puhui999:用 mapstruct 的映射
53 54 default ProductCommentDO convert(ProductCommentCreateReqVO createReq) {
54 55 ProductCommentDO productComment = new ProductCommentDO();
55 56 productComment.setUserId(0L);
... ... @@ -64,7 +65,6 @@ public interface ProductCommentConvert {
64 65 productComment.setScores(createReq.getScores());
65 66 productComment.setDescriptionScores(createReq.getDescriptionScores());
66 67 productComment.setBenefitScores(createReq.getBenefitScores());
67   - productComment.setDeliveryScores(createReq.getDeliveryScores());
68 68 productComment.setContent(createReq.getContent());
69 69 productComment.setPicUrls(createReq.getPicUrls());
70 70 return productComment;
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java
... ... @@ -36,20 +36,18 @@ public class ProductCommentDO extends BaseDO {
36 36  
37 37 /**
38 38 * 评价人 用户编号
  39 + *
39 40 * 关联 MemberUserDO 的 id 编号
40 41 */
41 42 private Long userId;
42   -
43 43 /**
44 44 * 评价人名称
45 45 */
46 46 private String userNickname;
47   -
48 47 /**
49 48 * 评价人头像
50 49 */
51 50 private String userAvatar;
52   -
53 51 /**
54 52 * 是否匿名
55 53 */
... ... @@ -57,12 +55,13 @@ public class ProductCommentDO extends BaseDO {
57 55  
58 56 /**
59 57 * 交易订单编号
  58 + *
60 59 * 关联 TradeOrderDO 的 id 编号
61 60 */
62 61 private Long orderId;
63   -
64 62 /**
65 63 * 交易订单项编号
  64 + *
66 65 * 关联 TradeOrderItemDO 的 id 编号
67 66 */
68 67 private Long orderItemId;
... ... @@ -72,53 +71,46 @@ public class ProductCommentDO extends BaseDO {
72 71 * 关联 {@link ProductSpuDO#getId()}
73 72 */
74 73 private Long spuId;
75   -
76 74 /**
77 75 * 商品 SPU 名称
78 76 */
79 77 private String spuName;
80   -
81 78 /**
82 79 * 商品 SKU 编号
  80 + *
83 81 * 关联 {@link ProductSkuDO#getId()}
84 82 */
85 83 private Long skuId;
86 84  
87 85 /**
88 86 * 是否可见
89   - * true:显示 false:隐藏
  87 + *
  88 + * true:显示
  89 + * false:隐藏
90 90 */
91 91 private Boolean visible;
92   -
93 92 /**
94 93 * 评分星级
  94 + *
95 95 * 1-5分
96 96 */
97 97 private Integer scores;
98   -
99 98 /**
100 99 * 描述星级
  100 + *
101 101 * 1-5 星
102 102 */
103 103 private Integer descriptionScores;
104   -
105 104 /**
106 105 * 服务星级
  106 + *
107 107 * 1-5 星
108 108 */
109 109 private Integer benefitScores;
110   -
111   - /**
112   - * 配送星级
113   - * 1-5 星
114   - */
115   - private Integer deliveryScores;
116   -
117 110 /**
118 111 * 评论内容
119 112 */
120 113 private String content;
121   -
122 114 /**
123 115 * 评论图片地址数组
124 116 */
... ... @@ -128,38 +120,19 @@ public class ProductCommentDO extends BaseDO {
128 120 /**
129 121 * 商家是否回复
130 122 */
131   - private Boolean replied;
132   -
  123 + private Boolean replyStatus;
133 124 /**
134 125 * 回复管理员编号
135 126 * 关联 AdminUserDO 的 id 编号
136 127 */
137 128 private Long replyUserId;
138   -
139 129 /**
140 130 * 商家回复内容
141 131 */
142 132 private String replyContent;
143   -
144 133 /**
145 134 * 商家回复时间
146 135 */
147 136 private LocalDateTime replyTime;
148 137  
149   - /**
150   - * 追加评价内容
151   - */
152   - private String additionalContent;
153   -
154   - /**
155   - * 追评评价图片地址数组
156   - */
157   - @TableField(typeHandler = JacksonTypeHandler.class)
158   - private List<String> additionalPicUrls;
159   -
160   - /**
161   - * 追加评价时间
162   - */
163   - private LocalDateTime additionalTime;
164   -
165 138 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java
... ... @@ -7,7 +7,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
7 7 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
8 8 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
9 9 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO;
10   -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO;
11 10 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
12 11 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
13 12 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
... ... @@ -15,12 +14,6 @@ import org.apache.ibatis.annotations.Mapper;
15 14  
16 15 import java.time.LocalDateTime;
17 16  
18   -
19   -/**
20   - * 商品评论 Mapper
21   - *
22   - * @author wangzhs
23   - */
24 17 @Mapper
25 18 public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
26 19  
... ... @@ -37,19 +30,16 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; {
37 30  
38 31 // TODO 芋艿:在看看这块
39 32 static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> queryWrapper, Integer type) {
40   - // 构建好评查询语句
  33 + // 构建好评查询语句:好评计算 (商品评分星级+服务评分星级) >= 8
41 34 if (ObjectUtil.equal(type, AppCommentPageReqVO.FAVOURABLE_COMMENT)) {
42   - // 好评计算 (商品评分星级+服务评分星级) >= 8
43 35 queryWrapper.apply("(scores + benefit_scores) >= 8");
44 36 }
45   - // 构建中评查询语句
  37 + // 构建中评查询语句:中评计算 (商品评分星级+服务评分星级) > 4 且 (商品评分星级+服务评分星级) < 8
46 38 if (ObjectUtil.equal(type, AppCommentPageReqVO.MEDIOCRE_COMMENT)) {
47   - // 中评计算 (商品评分星级+服务评分星级) > 4 且 (商品评分星级+服务评分星级) < 8
48 39 queryWrapper.apply("(scores + benefit_scores) > 4 and (scores + benefit_scores) < 8");
49 40 }
50   - // 构建差评查询语句
  41 + // 构建差评查询语句:差评计算 (商品评分星级+服务评分星级) <= 4
51 42 if (ObjectUtil.equal(type, AppCommentPageReqVO.NEGATIVE_COMMENT)) {
52   - // 差评计算 (商品评分星级+服务评分星级) <= 4
53 43 queryWrapper.apply("(scores + benefit_scores) <= 4");
54 44 }
55 45 }
... ... @@ -74,7 +64,7 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; {
74 64  
75 65 default void commentReply(ProductCommentReplyVO replyVO, Long loginUserId) {
76 66 LambdaUpdateWrapper<ProductCommentDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<ProductCommentDO>()
77   - .set(ProductCommentDO::getReplied, Boolean.TRUE)
  67 + .set(ProductCommentDO::getReplyStatus, Boolean.TRUE)
78 68 .set(ProductCommentDO::getReplyTime, LocalDateTime.now())
79 69 .set(ProductCommentDO::getReplyUserId, loginUserId)
80 70 .set(ProductCommentDO::getReplyContent, replyVO.getReplyContent())
... ... @@ -82,6 +72,7 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; {
82 72 update(null, lambdaUpdateWrapper);
83 73 }
84 74  
  75 + // TODO @puhui999:使用 select 替代 find
85 76 default ProductCommentDO findByUserIdAndOrderIdAndSpuId(Long userId, Long orderId, Long spuId) {
86 77 return selectOne(new LambdaQueryWrapperX<ProductCommentDO>()
87 78 .eq(ProductCommentDO::getUserId, userId)
... ... @@ -89,15 +80,7 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; {
89 80 .eq(ProductCommentDO::getSpuId, spuId));
90 81 }
91 82  
92   - default void additionalComment(AppCommentAdditionalReqVO createReqVO) {
93   - LambdaUpdateWrapper<ProductCommentDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<ProductCommentDO>()
94   - .set(ProductCommentDO::getAdditionalTime, LocalDateTime.now())
95   - .set(ProductCommentDO::getAdditionalPicUrls, createReqVO.getAdditionalPicUrls(), "javaType=List,jdbcType=VARCHAR,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler")
96   - .set(ProductCommentDO::getAdditionalContent, createReqVO.getAdditionalContent())
97   - .eq(ProductCommentDO::getId, createReqVO.getId());
98   - update(null, lambdaUpdateWrapper);
99   - }
100   -
  83 + // TODO @puhui999:selectCountBySpuId 即可
101 84 default Long selectTabCount(Long spuId, Boolean visible, Integer type) {
102 85 LambdaQueryWrapperX<ProductCommentDO> queryWrapper = new LambdaQueryWrapperX<ProductCommentDO>()
103 86 .eqIfPresent(ProductCommentDO::getSpuId, spuId)
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java
1 1 package cn.iocoder.yudao.module.product.service.comment;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
5 4 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
6 5 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO;
7 6 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO;
8   -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO;
9 7 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
10 8 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO;
11 9 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
... ... @@ -38,11 +36,12 @@ public interface ProductCommentService {
38 36 */
39 37 void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO);
40 38  
  39 + // TODO @puhui999:replyComment
41 40 /**
42 41 * 商家回复
43 42 *
44 43 * @param replyVO 商家回复
45   - * @param loginUserId 管理后台商家登陆人ID
  44 + * @param loginUserId 管理后台商家登陆人 ID
46 45 */
47 46 void commentReply(ProductCommentReplyVO replyVO, Long loginUserId);
48 47  
... ... @@ -64,19 +63,12 @@ public interface ProductCommentService {
64 63 void createComment(ProductCommentDO productComment, Boolean system);
65 64  
66 65 /**
67   - * 追加商品评论
68   - *
69   - * @param user 用户相关信息
70   - * @param createReqVO 创建实体
71   - */
72   - void additionalComment(MemberUserRespDTO user, AppCommentAdditionalReqVO createReqVO);
73   -
74   - /**
75   - * 评论页面标签数
  66 + * 获得商品的评价统计
76 67 *
77 68 * @param spuId spu id
78 69 * @param visible 是否可见
79   - * @return 获得商品评价分页 tab count
  70 + * @return 评价统计
80 71 */
81 72 Map<String, Long> getCommentPageTabsCount(Long spuId, Boolean visible);
  73 +
82 74 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java
... ... @@ -2,11 +2,9 @@ package cn.iocoder.yudao.module.product.service.comment;
2 2  
3 3 import cn.hutool.core.util.ObjectUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5   -import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
6 5 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
7 6 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO;
8 7 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO;
9   -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO;
10 8 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
11 9 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO;
12 10 import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
... ... @@ -17,7 +15,6 @@ import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
17 15 import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
18 16 import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
19 17 import org.springframework.stereotype.Service;
20   -import org.springframework.util.StringUtils;
21 18 import org.springframework.validation.annotation.Validated;
22 19  
23 20 import javax.annotation.Resource;
... ... @@ -25,13 +22,11 @@ import java.math.BigDecimal;
25 22 import java.math.RoundingMode;
26 23 import java.util.HashMap;
27 24 import java.util.Map;
28   -import java.util.Objects;
29 25  
30 26 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
31 27 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
32 28 import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND;
33 29  
34   -// TODO @芋艿:详细 review 下
35 30 /**
36 31 * 商品评论 Service 实现类
37 32 *
... ... @@ -43,6 +38,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
43 38  
44 39 @Resource
45 40 private ProductCommentMapper productCommentMapper;
  41 +
46 42 @Resource
47 43 private TradeOrderApi tradeOrderApi;
48 44  
... ... @@ -59,6 +55,8 @@ public class ProductCommentServiceImpl implements ProductCommentService {
59 55 // 校验评论是否存在
60 56 validateCommentExists(updateReqVO.getId());
61 57  
  58 + // 更新可见状态
  59 + // TODO @puhui999:直接使用 update 操作
62 60 productCommentMapper.updateCommentVisible(updateReqVO.getId(), updateReqVO.getVisible());
63 61 }
64 62  
... ... @@ -67,6 +65,8 @@ public class ProductCommentServiceImpl implements ProductCommentService {
67 65 // 校验评论是否存在
68 66 validateCommentExists(replyVO.getId());
69 67  
  68 + // 回复评论
  69 + // TODO @puhui999:直接使用 update 操作
70 70 productCommentMapper.commentReply(replyVO, loginUserId);
71 71 }
72 72  
... ... @@ -90,12 +90,14 @@ public class ProductCommentServiceImpl implements ProductCommentService {
90 90  
91 91 @Override
92 92 public PageResult<AppCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) {
  93 + // TODO @puhui999:逻辑可以在 controller 做哈。让 service 简介一点;因为是 view 需要不展示昵称
93 94 PageResult<AppCommentRespVO> result = ProductCommentConvert.INSTANCE.convertPage02(productCommentMapper.selectPage(pageVO, visible));
94 95 result.getList().forEach(item -> {
95 96 // 判断用户是否选择匿名
96 97 if (ObjectUtil.equal(item.getAnonymous(), true)) {
97 98 item.setUserNickname(AppCommentPageReqVO.ANONYMOUS_NICKNAME);
98 99 }
  100 + // TODO @puhui999:直接插入的时候,计算到 scores 字段里;这样就去掉 finalScore 字段哈
99 101 // 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2
100 102 BigDecimal sumScore = new BigDecimal(item.getScores() + item.getBenefitScores());
101 103 BigDecimal divide = sumScore.divide(BigDecimal.valueOf(2L), 0, RoundingMode.DOWN);
... ... @@ -127,30 +129,11 @@ public class ProductCommentServiceImpl implements ProductCommentService {
127 129 productCommentMapper.insert(productComment);
128 130 }
129 131  
130   - @Override
131   - public void additionalComment(MemberUserRespDTO user, AppCommentAdditionalReqVO createReqVO) {
132   - // 校验评论是否存在
133   - ProductCommentDO productComment = validateCommentExists(createReqVO.getId());
134   -
135   - // 判断是否是同一用户追加评论
136   - if (!Objects.equals(productComment.getUserId(), user.getId())) {
137   - throw exception(COMMENT_ERROR_OPT);
138   - }
139   -
140   - // 判断是否已经追加评论过了
141   - if (StringUtils.hasText(productComment.getAdditionalContent())) {
142   - throw exception(COMMENT_ADDITIONAL_EXISTS);
143   - }
144   -
145   - productCommentMapper.additionalComment(createReqVO);
146   - }
147   -
148   - private ProductCommentDO validateCommentExists(Long id) {
  132 + private void validateCommentExists(Long id) {
149 133 ProductCommentDO productComment = productCommentMapper.selectById(id);
150 134 if (productComment == null) {
151 135 throw exception(COMMENT_NOT_EXISTS);
152 136 }
153   - return productComment;
154 137 }
155 138  
156 139 }
... ...
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java
... ... @@ -82,7 +82,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest {
82 82 o.setUserNickname("王二狗");
83 83 o.setSpuName("感冒药");
84 84 o.setScores(ProductCommentScoresEnum.FOUR.getScores());
85   - o.setReplied(Boolean.TRUE);
  85 + o.setReplyStatus(Boolean.TRUE);
86 86 o.setVisible(Boolean.TRUE);
87 87 o.setId(generateId());
88 88 o.setUserId(generateId());
... ... @@ -118,7 +118,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest {
118 118 // 测试 scores 不匹配
119 119 productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setScores(ProductCommentScoresEnum.ONE.getScores())));
120 120 // 测试 replied 不匹配
121   - productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setReplied(Boolean.FALSE)));
  121 + productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setReplyStatus(Boolean.FALSE)));
122 122 // 测试 visible 不匹配
123 123 productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setVisible(Boolean.FALSE)));
124 124  
... ...