Commit 700d95a43dbdbb32ee10eeee4f81b6c641c28233

Authored by puhui999
1 parent 8dfb2983

fix:完善商品评论 review 提到的问题

Showing 28 changed files with 310 additions and 296 deletions
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/comment/ProductCommentApi.java
... ... @@ -9,14 +9,12 @@ import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDT
9 9 */
10 10 public interface ProductCommentApi {
11 11  
12   - // TODO @puhui:Long orderId 放到 createReqDTO 里噶?
13 12 /**
14 13 * 创建评论
15 14 *
16 15 * @param createReqDTO 评论参数
17   - * @param orderId 订单 id
18 16 * @return 返回评论创建后的 id
19 17 */
20   - Long createComment(ProductCommentCreateReqDTO createReqDTO, Long orderId);
  18 + Long createComment(ProductCommentCreateReqDTO createReqDTO);
21 19  
22 20 }
... ...
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/comment/dto/ProductCommentCreateReqDTO.java
... ... @@ -17,19 +17,13 @@ public class ProductCommentCreateReqDTO {
17 17 */
18 18 private Long skuId;
19 19 /**
20   - * 交易订单项编号
21   - */
22   - private Long orderItemId;
23   -
24   - // TODO @huihui:spuId、spuName 去查询哇?通过 skuId
25   - /**
26   - * 商品 SPU 编号
  20 + * 订单编号
27 21 */
28   - private Long spuId;
  22 + private Long orderId;
29 23 /**
30   - * 商品 SPU 名称
  24 + * 交易订单项编号
31 25 */
32   - private String spuName;
  26 + private Long orderItemId;
33 27  
34 28 /**
35 29 * 评分星级 1-5 分
... ... @@ -60,14 +54,6 @@ public class ProductCommentCreateReqDTO {
60 54 * 评价人
61 55 */
62 56 private Long userId;
63   - // TODO @puhui999:是不是 userNickname、userAvatar 去掉?通过 userId 查询
64   - /**
65   - * 评价人名称
66   - */
67   - private String userNickname;
68   - /**
69   - * 评价人头像
70   - */
71   - private String userAvatar;
  57 +
72 58  
73 59 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/comment/ProductCommentApiImpl.java
1 1 package cn.iocoder.yudao.module.product.api.comment;
2 2  
3 3 import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
4   -import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
5   -import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
6 4 import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
7 5 import org.springframework.stereotype.Service;
8 6 import org.springframework.validation.annotation.Validated;
... ... @@ -22,9 +20,8 @@ public class ProductCommentApiImpl implements ProductCommentApi {
22 20 private ProductCommentService productCommentService;
23 21  
24 22 @Override
25   - public Long createComment(ProductCommentCreateReqDTO createReqDTO, Long orderId) {
26   - ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqDTO, orderId);
27   - return productCommentService.createComment(commentDO);
  23 + public Long createComment(ProductCommentCreateReqDTO createReqDTO) {
  24 + return productCommentService.createComment(createReqDTO);
28 25 }
29 26  
30 27 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java
... ... @@ -10,43 +10,51 @@ import java.util.List;
10 10 @Data
11 11 public class ProductCommentBaseVO {
12 12  
13   - @Schema(description = "评价人名称", required = true, example = "小姑凉")
  13 + @Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868")
  14 + @NotNull(message = "评价人不能为空")
  15 + private Long userId;
  16 +
  17 + @Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292")
  18 + @NotNull(message = "评价订单项不能为空")
  19 + private Long orderItemId;
  20 +
  21 + @Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉")
14 22 @NotNull(message = "评价人名称不能为空")
15 23 private String userNickname;
16 24  
17   - @Schema(description = "评价人头像", required = true, example = "https://www.iocoder.cn/xx.png")
  25 + @Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
18 26 @NotNull(message = "评价人头像不能为空")
19 27 private String userAvatar;
20 28  
21   - @Schema(description = "商品 SPU 编号", required = true, example = "清凉丝滑透气小短袖")
  29 + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖")
22 30 @NotNull(message = "商品 SPU 编号不能为空")
23 31 private Long spuId;
24 32  
25   - @Schema(description = "商品 SPU 名称", required = true, example = "赵六")
  33 + @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
26 34 @NotNull(message = "商品 SPU 名称不能为空")
27 35 private String spuName;
28 36  
29   - @Schema(description = "商品 SKU 编号", required = true, example = "1")
  37 + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
30 38 @NotNull(message = "商品 SKU 编号不能为空")
31 39 private Long skuId;
32 40  
33   - @Schema(description = "评分星级 1-5 分", required = true, example = "5")
  41 + @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
34 42 @NotNull(message = "评分星级不能为空")
35 43 private Integer scores;
36 44  
37   - @Schema(description = "描述星级 1-5 分", required = true, example = "5")
  45 + @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
38 46 @NotNull(message = "描述星级不能为空")
39 47 private Integer descriptionScores;
40 48  
41   - @Schema(description = "服务星级 1-5 分", required = true, example = "5")
  49 + @Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
42 50 @NotNull(message = "服务星级分不能为空")
43 51 private Integer benefitScores;
44 52  
45   - @Schema(description = "评论内容", required = true, example = "穿起来非常丝滑凉快")
  53 + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快")
46 54 @NotNull(message = "评论内容不能为空")
47 55 private String content;
48 56  
49   - @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
  57 + @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
50 58 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
51 59 private List<String> picUrls;
52 60  
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentCreateReqVO.java
... ... @@ -5,21 +5,10 @@ import lombok.Data;
5 5 import lombok.EqualsAndHashCode;
6 6 import lombok.ToString;
7 7  
8   -import javax.validation.constraints.NotNull;
9   -
10 8 @Schema(description = "管理后台 - 商品评价创建 Request VO")
11 9 @Data
12 10 @EqualsAndHashCode(callSuper = true)
13 11 @ToString(callSuper = true)
14 12 public class ProductCommentCreateReqVO extends ProductCommentBaseVO {
15 13  
16   - // TODO @puhui999:是不是也放到父类里?
17   - @Schema(description = "评价人", required = true, example = "16868")
18   - @NotNull(message = "评价人不能为空")
19   - private Long userId;
20   -
21   - @Schema(description = "评价订单项", required = true, example = "19292")
22   - @NotNull(message = "评价订单项不能为空")
23   - private Long orderItemId;
24   -
25 14 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyReqVO.java
... ... @@ -12,11 +12,11 @@ import javax.validation.constraints.NotNull;
12 12 @ToString(callSuper = true)
13 13 public class ProductCommentReplyReqVO {
14 14  
15   - @Schema(description = "评价编号", required = true, example = "15721")
  15 + @Schema(description = "评价编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
16 16 @NotNull(message = "评价编号不能为空")
17 17 private Long id;
18 18  
19   - @Schema(description = "商家回复内容", required = true, example = "谢谢亲")
  19 + @Schema(description = "商家回复内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "谢谢亲")
20 20 @NotEmpty(message = "商家回复内容不能为空")
21 21 private String replyContent;
22 22  
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java
... ... @@ -13,37 +13,31 @@ import java.time.LocalDateTime;
13 13 @ToString(callSuper = true)
14 14 public class ProductCommentRespVO extends ProductCommentBaseVO {
15 15  
16   - @Schema(description = "订单项编号", required = true, example = "24965")
  16 + @Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24965")
17 17 private Long id;
18 18  
19   - @Schema(description = "是否匿名", required = true, example = "false")
  19 + @Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
20 20 private Boolean anonymous;
21 21  
22   - @Schema(description = "交易订单编号", required = true, example = "24428")
  22 + @Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
23 23 private Long orderId;
24 24  
25   - @Schema(description = "评价人 用户编号", required = true, example = "15721")
26   - private Long userId;
27   -
28   - @Schema(description = "交易订单项编号", required = true, example = "8233")
29   - private Long orderItemId;
30   -
31   - @Schema(description = "是否可见:[true:显示 false:隐藏]", required = true)
  25 + @Schema(description = "是否可见:[true:显示 false:隐藏]", requiredMode = Schema.RequiredMode.REQUIRED)
32 26 private Boolean visible;
33 27  
34   - @Schema(description = "商家是否回复:[1:回复 0:未回复]", required = true)
  28 + @Schema(description = "商家是否回复:[1:回复 0:未回复]", requiredMode = Schema.RequiredMode.REQUIRED)
35 29 private Boolean replyStatus;
36 30  
37   - @Schema(description = "回复管理员编号", example = "22212")
  31 + @Schema(description = "回复管理员编号", example = "9527")
38 32 private Long replyUserId;
39 33  
40   - @Schema(description = "商家回复内容")
  34 + @Schema(description = "商家回复内容", example = "感谢好评哦亲(づ ̄3 ̄)づ╭❤~")
41 35 private String replyContent;
42 36  
43   - @Schema(description = "商家回复时间")
  37 + @Schema(description = "商家回复时间", example = "2023-08-08 12:20:55")
44 38 private LocalDateTime replyTime;
45 39  
46   - @Schema(description = "创建时间", required = true)
  40 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
47 41 private LocalDateTime createTime;
48 42  
49 43 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentUpdateVisibleReqVO.java
... ... @@ -11,11 +11,11 @@ import javax.validation.constraints.NotNull;
11 11 @ToString(callSuper = true)
12 12 public class ProductCommentUpdateVisibleReqVO {
13 13  
14   - @Schema(description = "评价编号", required = true, example = "15721")
  14 + @Schema(description = "评价编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
15 15 @NotNull(message = "评价编号不能为空")
16 16 private Long id;
17 17  
18   - @Schema(description = "是否可见", required = true, example = "false")
  18 + @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, 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/AppProductCommentController.java
1 1 package cn.iocoder.yudao.module.product.controller.app.comment;
2 2  
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.ObjectUtil;
3 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 7 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
6 8 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
7 9 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
8 10 import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
  11 +import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
  12 +import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
  13 +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
9 14 import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
  15 +import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
10 16 import io.swagger.v3.oas.annotations.Operation;
11 17 import io.swagger.v3.oas.annotations.Parameter;
12 18 import io.swagger.v3.oas.annotations.Parameters;
13 19 import io.swagger.v3.oas.annotations.tags.Tag;
  20 +import org.springframework.context.annotation.Lazy;
14 21 import org.springframework.validation.annotation.Validated;
15 22 import org.springframework.web.bind.annotation.GetMapping;
16 23 import org.springframework.web.bind.annotation.RequestMapping;
... ... @@ -19,11 +26,11 @@ import org.springframework.web.bind.annotation.RestController;
19 26  
20 27 import javax.annotation.Resource;
21 28 import javax.validation.Valid;
22   -import java.time.LocalDateTime;
23   -import java.util.ArrayList;
24   -import java.util.Arrays;
  29 +import java.util.HashMap;
25 30 import java.util.List;
26   -import java.util.Random;
  31 +import java.util.Map;
  32 +import java.util.Set;
  33 +import java.util.stream.Collectors;
27 34  
28 35 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
29 36  
... ... @@ -36,7 +43,10 @@ public class AppProductCommentController {
36 43 @Resource
37 44 private ProductCommentService productCommentService;
38 45  
39   - // TODO @puhui999:可以实现下
  46 + @Resource
  47 + @Lazy
  48 + private ProductSkuService productSkuService;
  49 +
40 50 @GetMapping("/list")
41 51 @Operation(summary = "获得最近的 n 条商品评价")
42 52 @Parameters({
... ... @@ -45,67 +55,38 @@ public class AppProductCommentController {
45 55 })
46 56 public CommonResult<List<AppProductCommentRespVO>> getCommentList(@RequestParam("spuId") Long spuId,
47 57 @RequestParam(value = "count", defaultValue = "10") Integer count) {
48   - List<AppProductPropertyValueDetailRespVO> list = new ArrayList<>();
49   -
50   - AppProductPropertyValueDetailRespVO item1 = new AppProductPropertyValueDetailRespVO();
51   - item1.setPropertyId(1L);
52   - item1.setPropertyName("颜色");
53   - item1.setValueId(1024L);
54   - item1.setValueName("红色");
55   - list.add(item1);
56   -
57   - AppProductPropertyValueDetailRespVO item2 = new AppProductPropertyValueDetailRespVO();
58   - item2.setPropertyId(2L);
59   - item2.setPropertyName("尺寸");
60   - item2.setValueId(2048L);
61   - item2.setValueName("大号");
62   - list.add(item2);
63   -
64   - AppProductPropertyValueDetailRespVO item3 = new AppProductPropertyValueDetailRespVO();
65   - item3.setPropertyId(3L);
66   - item3.setPropertyName("重量");
67   - item3.setValueId(3072L);
68   - item3.setValueName("500克");
69   - list.add(item3);
70   -
71   - // TODO 生成 mock 的数据
72   - AppProductCommentRespVO appCommentRespVO = new AppProductCommentRespVO();
73   - appCommentRespVO.setUserId((long) (new Random().nextInt(100000) + 10000));
74   - appCommentRespVO.setUserNickname("用户" + new Random().nextInt(100));
75   - appCommentRespVO.setUserAvatar("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg");
76   - appCommentRespVO.setId((long) (new Random().nextInt(100000) + 10000));
77   - appCommentRespVO.setAnonymous(new Random().nextBoolean());
78   - appCommentRespVO.setOrderId((long) (new Random().nextInt(100000) + 10000));
79   - appCommentRespVO.setOrderItemId((long) (new Random().nextInt(100000) + 10000));
80   - appCommentRespVO.setReplyStatus(new Random().nextBoolean());
81   - appCommentRespVO.setReplyUserId((long) (new Random().nextInt(100000) + 10000));
82   - appCommentRespVO.setReplyContent("回复内容" + new Random().nextInt(100));
83   - appCommentRespVO.setReplyTime(LocalDateTime.now().minusDays(new Random().nextInt(30)));
84   - appCommentRespVO.setCreateTime(LocalDateTime.now().minusDays(new Random().nextInt(30)));
85   - appCommentRespVO.setSpuId((long) (new Random().nextInt(100000) + 10000));
86   - appCommentRespVO.setSpuName("商品" + new Random().nextInt(100));
87   - appCommentRespVO.setSkuId((long) (new Random().nextInt(100000) + 10000));
88   - appCommentRespVO.setSkuProperties(list);
89   - appCommentRespVO.setScores(new Random().nextInt(5) + 1);
90   - appCommentRespVO.setDescriptionScores(new Random().nextInt(5) + 1);
91   - appCommentRespVO.setBenefitScores(new Random().nextInt(5) + 1);
92   - appCommentRespVO.setContent("评论内容" + new Random().nextInt(100));
93   - appCommentRespVO.setPicUrls(Arrays.asList("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"));
  58 + return success(productCommentService.getCommentList(spuId, count));
94 59  
95   - return success(Arrays.asList(appCommentRespVO));
96 60 }
97 61  
98 62 @GetMapping("/page")
99 63 @Operation(summary = "获得商品评价分页")
100 64 public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) {
101   - return success(productCommentService.getCommentPage(pageVO, Boolean.TRUE));
  65 + PageResult<AppProductCommentRespVO> page = productCommentService.getCommentPage(pageVO, Boolean.TRUE);
  66 + Set<Long> skuIds = page.getList().stream().map(AppProductCommentRespVO::getSkuId).collect(Collectors.toSet());
  67 + List<ProductSkuDO> skuList = productSkuService.getSkuList(skuIds);
  68 + Map<Long, ProductSkuDO> skuDOMap = new HashMap<>(skuIds.size());
  69 + if (CollUtil.isNotEmpty(skuList)) {
  70 + skuDOMap.putAll(skuList.stream().collect(Collectors.toMap(ProductSkuDO::getId, c -> c)));
  71 + }
  72 + page.getList().forEach(item -> {
  73 + // 判断用户是否选择匿名
  74 + if (ObjectUtil.equal(item.getAnonymous(), true)) {
  75 + item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
  76 + }
  77 + ProductSkuDO productSkuDO = skuDOMap.get(item.getSkuId());
  78 + if (productSkuDO != null) {
  79 + List<AppProductPropertyValueDetailRespVO> skuProperties = ProductCommentConvert.INSTANCE.convertList01(productSkuDO.getProperties());
  80 + item.setSkuProperties(skuProperties);
  81 + }
  82 + });
  83 + return success(page);
102 84 }
103 85  
104   - // TODO @puhui:get-statistics;方法改成 getCommentStatistics;getCommentPageTabsCount 也改掉哈
105 86 @GetMapping("/getCommentStatistics")
106 87 @Operation(summary = "获得商品的评价统计")
107   - public CommonResult<AppCommentStatisticsRespVO> getCommentPage(@Valid @RequestParam("spuId") Long spuId) {
108   - return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE));
  88 + public CommonResult<AppCommentStatisticsRespVO> getCommentStatistics(@Valid @RequestParam("spuId") Long spuId) {
  89 + return success(productCommentService.getCommentStatistics(spuId, Boolean.TRUE));
109 90 }
110 91  
111 92 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentStatisticsRespVO.java
... ... @@ -9,16 +9,16 @@ import lombok.ToString;
9 9 @ToString(callSuper = true)
10 10 public class AppCommentStatisticsRespVO {
11 11  
12   - @Schema(description = "所有评论数量", required = true, example = "15721")
  12 + @Schema(description = "所有评论数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
13 13 private Long allCount;
14 14  
15   - @Schema(description = "好评数量", required = true, example = "15721")
  15 + @Schema(description = "好评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
16 16 private Long goodCount;
17 17  
18   - @Schema(description = "中评数量", required = true, example = "15721")
  18 + @Schema(description = "中评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
19 19 private Long mediocreCount;
20 20  
21   - @Schema(description = "差评数量", required = true, example = "15721")
  21 + @Schema(description = "差评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
22 22 private Long negativeCount;
23 23  
24 24 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java
... ... @@ -13,43 +13,43 @@ import java.util.List;
13 13 @ToString(callSuper = true)
14 14 public class AppProductCommentCreateReqVO {
15 15  
16   - @Schema(description = "是否匿名", required = true, example = "true")
  16 + @Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
17 17 @NotNull(message = "是否匿名不能为空")
18 18 private Boolean anonymous;
19 19  
20   - @Schema(description = "交易订单项编号", required = true, example = "2312312")
  20 + @Schema(description = "交易订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2312312")
21 21 @NotNull(message = "交易订单项编号不能为空")
22 22 private Long orderItemId;
23 23  
24   - @Schema(description = "商品 SPU 编号", required = true, example = "91192")
  24 + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "91192")
25 25 @NotNull(message = "商品SPU编号不能为空")
26 26 private Long spuId;
27 27  
28   - @Schema(description = "商品 SPU 名称", required = true, example = "清凉丝滑小短袖")
  28 + @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑小短袖")
29 29 @NotNull(message = "商品SPU名称不能为空")
30 30 private String spuName;
31 31  
32   - @Schema(description = "商品 SKU 编号", required = true, example = "81192")
  32 + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "81192")
33 33 @NotNull(message = "商品SKU编号不能为空")
34 34 private Long skuId;
35 35  
36   - @Schema(description = "评分星级 1-5 分", required = true, example = "5")
  36 + @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
37 37 @NotNull(message = "评分星级 1-5 分不能为空")
38 38 private Integer scores;
39 39  
40   - @Schema(description = "描述星级 1-5 分", required = true, example = "5")
  40 + @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
41 41 @NotNull(message = "描述星级 1-5 分不能为空")
42 42 private Integer descriptionScores;
43 43  
44   - @Schema(description = "服务星级 1-5 分", required = true, example = "5")
  44 + @Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
45 45 @NotNull(message = "服务星级 1-5 分不能为空")
46 46 private Integer benefitScores;
47 47  
48   - @Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评")
  48 + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "哇,真的很丝滑凉快诶,好评")
49 49 @NotNull(message = "评论内容不能为空")
50 50 private String content;
51 51  
52   - @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
  52 + @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
53 53 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
54 54 private List<String> picUrls;
55 55  
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java
... ... @@ -23,28 +23,28 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
23 23 @ToString(callSuper = true)
24 24 public class AppProductCommentRespVO {
25 25  
26   - @Schema(description = "评价人的用户编号", required = true, example = "15721")
  26 + @Schema(description = "评价人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
27 27 private Long userId;
28 28  
29   - @Schema(description = "评价人名称", required = true, example = "张三")
  29 + @Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
30 30 private String userNickname;
31 31  
32   - @Schema(description = "评价人头像", required = true, example = "https://www.iocoder.cn/xx.png")
  32 + @Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
33 33 private String userAvatar;
34 34  
35   - @Schema(description = "订单项编号", required = true, example = "24965")
  35 + @Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24965")
36 36 private Long id;
37 37  
38   - @Schema(description = "是否匿名", required = true, example = "false")
  38 + @Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
39 39 private Boolean anonymous;
40 40  
41   - @Schema(description = "交易订单编号", required = true, example = "24428")
  41 + @Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
42 42 private Long orderId;
43 43  
44   - @Schema(description = "交易订单项编号", required = true, example = "8233")
  44 + @Schema(description = "交易订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8233")
45 45 private Long orderItemId;
46 46  
47   - @Schema(description = "商家是否回复", required = true, example = "true")
  47 + @Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
48 48 private Boolean replyStatus;
49 49  
50 50 @Schema(description = "回复管理员编号", example = "22212")
... ... @@ -71,38 +71,38 @@ public class AppProductCommentRespVO {
71 71 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
72 72 private LocalDateTime createTime;
73 73  
74   - @Schema(description = "商品SPU编号", required = true, example = "91192")
  74 + @Schema(description = "商品SPU编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "91192")
75 75 @NotNull(message = "商品SPU编号不能为空")
76 76 private Long spuId;
77 77  
78   - @Schema(description = "商品SPU名称", required = true, example = "清凉丝滑小短袖")
  78 + @Schema(description = "商品SPU名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑小短袖")
79 79 @NotNull(message = "商品SPU名称不能为空")
80 80 private String spuName;
81 81  
82   - @Schema(description = "商品SKU编号", required = true, example = "81192")
  82 + @Schema(description = "商品SKU编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "81192")
83 83 @NotNull(message = "商品SKU编号不能为空")
84 84 private Long skuId;
85 85  
86   - @Schema(description = "商品 SKU 属性", required = true)
  86 + @Schema(description = "商品 SKU 属性", requiredMode = Schema.RequiredMode.REQUIRED)
87 87 private List<AppProductPropertyValueDetailRespVO> skuProperties;
88 88  
89   - @Schema(description = "评分星级 1-5 分", required = true, example = "5")
  89 + @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
90 90 @NotNull(message = "评分星级 1-5 分不能为空")
91 91 private Integer scores;
92 92  
93   - @Schema(description = "描述星级 1-5 分", required = true, example = "5")
  93 + @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
94 94 @NotNull(message = "描述星级 1-5 分不能为空")
95 95 private Integer descriptionScores;
96 96  
97   - @Schema(description = "服务星级 1-5 分", required = true, example = "5")
  97 + @Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
98 98 @NotNull(message = "服务星级 1-5 分不能为空")
99 99 private Integer benefitScores;
100 100  
101   - @Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评")
  101 + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "哇,真的很丝滑凉快诶,好评")
102 102 @NotNull(message = "评论内容不能为空")
103 103 private String content;
104 104  
105   - @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
  105 + @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
106 106 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
107 107 private List<String> picUrls;
108 108  
... ...
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 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
4 5 import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
5 6 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
6 7 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO;
... ... @@ -9,6 +10,7 @@ import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductComme
9 10 import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
10 11 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
11 12 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
  13 +import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
12 14 import org.mapstruct.Mapper;
13 15 import org.mapstruct.Mapping;
14 16 import org.mapstruct.Named;
... ... @@ -59,9 +61,18 @@ public interface ProductCommentConvert {
59 61 return divide.intValue();
60 62 }
61 63  
62   - @Mapping(target = "orderId", source = "orderId")
  64 + ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO);
  65 +
63 66 @Mapping(target = "scores", expression = "java(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()))")
64   - ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO, Long orderId);
  67 + default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO, ProductSpuDO spuDO, MemberUserRespDTO user) {
  68 + ProductCommentDO commentDO = convert(createReqDTO);
  69 + commentDO.setUserId(user.getId());
  70 + commentDO.setUserNickname(user.getNickname());
  71 + commentDO.setUserAvatar(user.getAvatar());
  72 + commentDO.setSpuId(spuDO.getId());
  73 + commentDO.setSpuName(spuDO.getName());
  74 + return commentDO;
  75 + }
65 76  
66 77 @Mapping(target = "userId", constant = "0L")
67 78 @Mapping(target = "orderId", constant = "0L")
... ... @@ -70,4 +81,5 @@ public interface ProductCommentConvert {
70 81 @Mapping(target = "scores", expression = "java(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()))")
71 82 ProductCommentDO convert(ProductCommentCreateReqVO createReq);
72 83  
  84 + List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list);
73 85 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java
... ... @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.product.dal.mysql.comment;
2 2  
3 3  
4 4 import cn.hutool.core.util.ObjectUtil;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
5 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 7 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
7 8 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
... ... @@ -25,19 +26,18 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; {
25 26 }
26 27  
27 28 // TODO 芋艿:在看看这块
28   - // TODO @puhui999:直接使用 scores 来算好评、中评、差评
29 29 static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> queryWrapper, Integer type) {
30   - // 构建好评查询语句:好评计算 (商品评分星级+服务评分星级) >= 8
  30 + // 构建好评查询语句:好评计算 总评 >= 4
31 31 if (ObjectUtil.equal(type, AppCommentPageReqVO.GOOD_COMMENT)) {
32   - queryWrapper.apply("(scores + benefit_scores) >= 8");
  32 + queryWrapper.apply("scores >= 4");
33 33 }
34   - // 构建中评查询语句:中评计算 (商品评分星级+服务评分星级) > 4 且 (商品评分星级+服务评分星级) < 8
  34 + // 构建中评查询语句:中评计算 总评 >= 3 且 总评 < 4
35 35 if (ObjectUtil.equal(type, AppCommentPageReqVO.MEDIOCRE_COMMENT)) {
36   - queryWrapper.apply("(scores + benefit_scores) > 4 and (scores + benefit_scores) < 8");
  36 + queryWrapper.apply("scores >=3 and scores < 4");
37 37 }
38   - // 构建差评查询语句:差评计算 (商品评分星级+服务评分星级) <= 4
  38 + // 构建差评查询语句:差评计算 总评 < 3
39 39 if (ObjectUtil.equal(type, AppCommentPageReqVO.NEGATIVE_COMMENT)) {
40   - queryWrapper.apply("(scores + benefit_scores) <= 4");
  40 + queryWrapper.apply("scores < 3");
41 41 }
42 42 }
43 43  
... ... @@ -52,10 +52,10 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; {
52 52 return selectPage(reqVO, queryWrapper);
53 53 }
54 54  
55   - default ProductCommentDO selectByUserIdAndOrderIdAndSpuId(Long userId, Long orderId, Long spuId) {
  55 + default ProductCommentDO selectByUserIdAndOrderItemIdAndSpuId(Long userId, Long orderItemId, Long spuId) {
56 56 return selectOne(new LambdaQueryWrapperX<ProductCommentDO>()
57 57 .eq(ProductCommentDO::getUserId, userId)
58   - .eq(ProductCommentDO::getOrderId, orderId)
  58 + .eq(ProductCommentDO::getOrderItemId, orderItemId)
59 59 .eq(ProductCommentDO::getSpuId, spuId));
60 60 }
61 61  
... ... @@ -68,4 +68,12 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; {
68 68 return selectCount(queryWrapper);
69 69 }
70 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 +
71 79 }
... ...
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.product.api.comment.dto.ProductCommentCreateReqDTO;
4 5 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
5 6 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
6 7 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO;
... ... @@ -12,6 +13,8 @@ import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
12 13 import org.springframework.stereotype.Service;
13 14 import org.springframework.validation.annotation.Validated;
14 15  
  16 +import java.util.List;
  17 +
15 18 /**
16 19 * 商品评论 Service 接口
17 20 *
... ... @@ -65,10 +68,10 @@ public interface ProductCommentService {
65 68 * 创建评论
66 69 * 创建商品评论 APP 端创建商品评论使用
67 70 *
68   - * @param commentDO 评论对象
  71 + * @param createReqDTO 创建请求 dto
69 72 * @return 返回评论 id
70 73 */
71   - Long createComment(ProductCommentDO commentDO);
  74 + Long createComment(ProductCommentCreateReqDTO createReqDTO);
72 75  
73 76 /**
74 77 * 获得商品的评价统计
... ... @@ -77,6 +80,15 @@ public interface ProductCommentService {
77 80 * @param visible 是否可见
78 81 * @return 评价统计
79 82 */
80   - AppCommentStatisticsRespVO getCommentPageTabsCount(Long spuId, Boolean visible);
  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);
81 93  
82 94 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java
1 1 package cn.iocoder.yudao.module.product.service.comment;
2 2  
3   -import cn.hutool.core.collection.CollUtil;
4   -import cn.hutool.core.util.ObjectUtil;
5 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
  5 +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
  6 +import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
6 7 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
7 8 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
8 9 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO;
... ... @@ -10,7 +11,6 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen
10 11 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
11 12 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
12 13 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
13   -import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
14 14 import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
15 15 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
16 16 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
... ... @@ -18,7 +18,6 @@ import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
18 18 import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper;
19 19 import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
20 20 import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
21   -import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
22 21 import org.springframework.context.annotation.Lazy;
23 22 import org.springframework.stereotype.Service;
24 23 import org.springframework.transaction.annotation.Transactional;
... ... @@ -26,11 +25,7 @@ import org.springframework.validation.annotation.Validated;
26 25  
27 26 import javax.annotation.Resource;
28 27 import java.time.LocalDateTime;
29   -import java.util.HashMap;
30 28 import java.util.List;
31   -import java.util.Map;
32   -import java.util.Set;
33   -import java.util.stream.Collectors;
34 29  
35 30 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
36 31 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
... ... @@ -48,15 +43,15 @@ public class ProductCommentServiceImpl implements ProductCommentService {
48 43 private ProductCommentMapper productCommentMapper;
49 44  
50 45 @Resource
51   - private TradeOrderApi tradeOrderApi;
52   -
53   - @Resource
54 46 private ProductSpuService productSpuService;
55 47  
56 48 @Resource
57 49 @Lazy
58 50 private ProductSkuService productSkuService;
59 51  
  52 + @Resource
  53 + private MemberUserApi memberUserApi;
  54 +
60 55 @Override
61 56 @Transactional(rollbackFor = Exception.class)
62 57 public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) {
... ... @@ -85,11 +80,8 @@ public class ProductCommentServiceImpl implements ProductCommentService {
85 80 @Override
86 81 @Transactional(rollbackFor = Exception.class)
87 82 public void createComment(ProductCommentCreateReqVO createReqVO) {
88   - // 校验订单
89   - // TODO @puhui999:不校验哈;尽可能解耦
90   - Long orderId = tradeOrderApi.validateOrder(createReqVO.getUserId(), createReqVO.getOrderItemId());
91 83 // 校验评论
92   - validateComment(createReqVO.getSpuId(), createReqVO.getUserId(), orderId);
  84 + validateComment(createReqVO.getSpuId(), createReqVO.getUserId(), createReqVO.getOrderItemId());
93 85  
94 86 ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO);
95 87 productCommentMapper.insert(commentDO);
... ... @@ -97,26 +89,41 @@ public class ProductCommentServiceImpl implements ProductCommentService {
97 89  
98 90 @Override
99 91 @Transactional(rollbackFor = Exception.class)
100   - public Long createComment(ProductCommentDO commentDO) {
  92 + public Long createComment(ProductCommentCreateReqDTO createReqDTO) {
  93 + // 通过 sku ID 拿到 spu 相关信息
  94 + ProductSkuDO sku = productSkuService.getSku(createReqDTO.getSkuId());
  95 + if (sku == null) {
  96 + throw exception(SKU_NOT_EXISTS);
  97 + }
  98 + // 校验 spu 如果存在返回详情
  99 + ProductSpuDO spuDO = validateSpu(sku.getSpuId());
101 100 // 校验评论
102   - validateComment(commentDO.getSpuId(), commentDO.getUserId(), commentDO.getOrderId());
  101 + validateComment(spuDO.getId(), createReqDTO.getUserId(), createReqDTO.getOrderId());
  102 + // 获取用户详细信息
  103 + MemberUserRespDTO user = memberUserApi.getUser(createReqDTO.getUserId());
103 104  
  105 + // 创建评论
  106 + ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqDTO, spuDO, user);
104 107 productCommentMapper.insert(commentDO);
105 108 return commentDO.getId();
106 109 }
107 110  
108   - private void validateComment(Long spuId, Long userId, Long orderId) {
109   - ProductSpuDO spu = productSpuService.getSpu(spuId);
110   - if (null == spu) {
111   - throw exception(SPU_NOT_EXISTS);
112   - }
  111 + private void validateComment(Long spuId, Long userId, Long orderItemId) {
113 112 // 判断当前订单的当前商品用户是否评价过
114   - ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderIdAndSpuId(userId, orderId, spuId);
  113 + ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderItemIdAndSpuId(userId, orderItemId, spuId);
115 114 if (null != exist) {
116 115 throw exception(ORDER_SPU_COMMENT_EXISTS);
117 116 }
118 117 }
119 118  
  119 + private ProductSpuDO validateSpu(Long spuId) {
  120 + ProductSpuDO spu = productSpuService.getSpu(spuId);
  121 + if (null == spu) {
  122 + throw exception(SPU_NOT_EXISTS);
  123 + }
  124 + return spu;
  125 + }
  126 +
120 127 private ProductCommentDO validateCommentExists(Long id) {
121 128 ProductCommentDO productComment = productCommentMapper.selectById(id);
122 129 if (productComment == null) {
... ... @@ -126,7 +133,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
126 133 }
127 134  
128 135 @Override
129   - public AppCommentStatisticsRespVO getCommentPageTabsCount(Long spuId, Boolean visible) {
  136 + public AppCommentStatisticsRespVO getCommentStatistics(Long spuId, Boolean visible) {
130 137 return ProductCommentConvert.INSTANCE.convert(
131 138 // 查询商品 id = spuId 的所有评论数量
132 139 productCommentMapper.selectCountBySpuId(spuId, visible, null),
... ... @@ -140,28 +147,17 @@ public class ProductCommentServiceImpl implements ProductCommentService {
140 147 }
141 148  
142 149 @Override
  150 + public List<AppProductCommentRespVO> getCommentList(Long spuId, Integer count) {
  151 + // 校验商品 spu 是否存在
  152 + ProductSpuDO spuDO = validateSpu(spuId);
  153 +
  154 + return ProductCommentConvert.INSTANCE.convertList02(productCommentMapper.selectCommentList(spuDO.getId(), count).getList());
  155 + }
  156 +
  157 + @Override
143 158 public PageResult<AppProductCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) {
144   - PageResult<AppProductCommentRespVO> result = ProductCommentConvert.INSTANCE.convertPage02(
  159 + return ProductCommentConvert.INSTANCE.convertPage02(
145 160 productCommentMapper.selectPage(pageVO, visible));
146   - // TODO @puhui999:要不这块放到 controller 里拼接?
147   - Set<Long> skuIds = result.getList().stream().map(AppProductCommentRespVO::getSkuId).collect(Collectors.toSet());
148   - List<ProductSkuDO> skuList = productSkuService.getSkuList(skuIds);
149   - Map<Long, ProductSkuDO> skuDOMap = new HashMap<>(skuIds.size());
150   - if (CollUtil.isNotEmpty(skuList)) {
151   - skuDOMap.putAll(skuList.stream().collect(Collectors.toMap(ProductSkuDO::getId, c -> c)));
152   - }
153   - result.getList().forEach(item -> {
154   - // 判断用户是否选择匿名
155   - if (ObjectUtil.equal(item.getAnonymous(), true)) {
156   - item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
157   - }
158   - ProductSkuDO productSkuDO = skuDOMap.get(item.getSkuId());
159   - if (productSkuDO != null) {
160   - List<AppProductPropertyValueDetailRespVO> skuProperties = ProductCommentConvert.INSTANCE.convertList01(productSkuDO.getProperties());
161   - item.setSkuProperties(skuProperties);
162   - }
163   - });
164   - return result;
165 161 }
166 162  
167 163 @Override
... ...
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java
... ... @@ -150,7 +150,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest {
150 150 assertEquals(2, result3.getTotal());
151 151  
152 152 // 测试分页 tab count
153   - AppCommentStatisticsRespVO tabsCount = productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE);
  153 + AppCommentStatisticsRespVO tabsCount = productCommentService.getCommentStatistics(spuId, Boolean.TRUE);
154 154 assertEquals(6, tabsCount.getAllCount());
155 155 assertEquals(4, tabsCount.getGoodCount());
156 156 assertEquals(2, tabsCount.getMediocreCount());
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java
... ... @@ -2,7 +2,11 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity;
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.promotion.controller.admin.seckill.vo.activity.*;
  5 +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO;
  6 +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityDetailRespVO;
  7 +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityRespVO;
  8 +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO;
  9 +import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductCreateReqVO;
6 10 import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO;
7 11 import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO;
8 12 import org.mapstruct.Mapper;
... ... @@ -20,7 +24,7 @@ public interface SeckillActivityConvert {
20 24  
21 25 SeckillActivityConvert INSTANCE = Mappers.getMapper(SeckillActivityConvert.class);
22 26  
23   - SeckillProductDO convert(SeckillActivityBaseVO.Product product);
  27 + SeckillProductDO convert(SeckillProductCreateReqVO product);
24 28  
25 29 SeckillActivityDO convert(SeckillActivityCreateReqVO bean);
26 30  
... ... @@ -42,12 +46,12 @@ public interface SeckillActivityConvert {
42 46 * @param productVO 前端传入的商品
43 47 * @return 是否匹配
44 48 */
45   - default boolean isEquals(SeckillProductDO productDO, SeckillActivityBaseVO.Product productVO) {
  49 + default boolean isEquals(SeckillProductDO productDO, SeckillProductCreateReqVO productVO) {
46 50 return ObjectUtil.equals(productDO.getSpuId(), productVO.getSpuId())
47 51 && ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId())
48 52 && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice());
49   - //&& ObjectUtil.equals(productDO.getQuota(), productVO.getQuota())
50   - //&& ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount());
  53 + //&& ObjectUtil.equals(productDO.getQuota(), productVO.getQuota())
  54 + //&& ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount());
51 55 }
52 56  
53 57 /**
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java
... ... @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
6 6 import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO;
7 7 import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi;
  8 +import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
8 9 import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi;
9 10 import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
10 11 import cn.iocoder.yudao.module.trade.controller.app.order.vo.*;
... ... @@ -35,6 +36,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
35 36 import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
36 37 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
37 38 import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_ITEM_NOT_FOUND;
  39 +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND;
38 40  
39 41 @Tag(name = "用户 App - 交易订单")
40 42 @RestController
... ... @@ -138,16 +140,20 @@ public class AppTradeOrderController {
138 140 @PostMapping("/item/create-comment")
139 141 @Operation(summary = "创建交易订单项的评价")
140 142 public CommonResult<Long> createOrderItemComment(@RequestBody AppTradeOrderItemCommentCreateReqVO createReqVO) {
141   - // 校验订单项,订单项存在订单就存在
142   - // TODO @puhui999:要去查询订单是不是自己的;不然别人模拟请求哈;
143   - TradeOrderItemDO item = tradeOrderService.getOrderItem(createReqVO.getUserId(), createReqVO.getOrderItemId());
144   - if (item == null) {
  143 + Long loginUserId = getLoginUserId();
  144 + // 先通过订单项 ID 查询订单项是否存在
  145 + TradeOrderItemDO orderItemDO = tradeOrderService.getOrderItemByIdAndUserId(createReqVO.getOrderItemId(), loginUserId);
  146 + if (orderItemDO == null) {
145 147 throw exception(ORDER_ITEM_NOT_FOUND);
146 148 }
  149 + // 校验订单
  150 + TradeOrderDO orderDO = tradeOrderService.getOrderByIdAndUserId(orderItemDO.getOrderId(), loginUserId);
  151 + if (orderDO == null) {
  152 + throw exception(ORDER_NOT_FOUND);
  153 + }
147 154  
148   - return success(productCommentApi.createComment(TradeOrderConvert.INSTANCE.convert04(createReqVO), item.getOrderId()));
  155 + ProductCommentCreateReqDTO productCommentCreateReqDTO = TradeOrderConvert.INSTANCE.convert04(createReqVO, orderItemDO);
  156 + return success(productCommentApi.createComment(productCommentCreateReqDTO));
149 157 }
150 158  
151   - // TODO 合并代码后发现只有商家回复功能 用户追评不要了吗?不要了哈;
152   -
153 159 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java
... ... @@ -21,7 +21,7 @@ public class AppTradeOrderSettlementReqVO {
21 21 @Deprecated // TODO 芋艿:后续干掉这个字段,对于前端不需要关注这个
22 22 private Integer type;
23 23  
24   - @Schema(description = "商品项数组", required = true)
  24 + @Schema(description = "商品项数组", requiredMode = Schema.RequiredMode.REQUIRED)
25 25 @NotNull(message = "商品不能为空")
26 26 private List<Item> items;
27 27  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementRespVO.java
... ... @@ -12,13 +12,13 @@ import java.util.List;
12 12 @Data
13 13 public class AppTradeOrderSettlementRespVO {
14 14  
15   - @Schema(description = "购物项数组", required = true)
  15 + @Schema(description = "购物项数组", requiredMode = Schema.RequiredMode.REQUIRED)
16 16 private List<Item> items;
17 17  
18   - @Schema(description = "费用", required = true)
  18 + @Schema(description = "费用", requiredMode = Schema.RequiredMode.REQUIRED)
19 19 private Price price;
20 20  
21   - @Schema(description = "收件地址", required = true)
  21 + @Schema(description = "收件地址", requiredMode = Schema.RequiredMode.REQUIRED)
22 22 private Address address;
23 23  
24 24 @Schema(description = "购物项")
... ... @@ -27,29 +27,29 @@ public class AppTradeOrderSettlementRespVO {
27 27  
28 28 // ========== SPU 信息 ==========
29 29  
30   - @Schema(description = "SPU 编号", required = true, example = "2048")
  30 + @Schema(description = "SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
31 31 private Long spuId;
32   - @Schema(description = "SPU 名字", required = true, example = "Apple iPhone 12")
  32 + @Schema(description = "SPU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "Apple iPhone 12")
33 33 private String spuName;
34 34  
35 35 // ========== SKU 信息 ==========
36 36  
37   - @Schema(description = "SKU 编号", required = true, example = "1024")
  37 + @Schema(description = "SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
38 38 private Integer skuId;
39   - @Schema(description = "价格,单位:分", required = true, example = "100")
  39 + @Schema(description = "价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
40 40 private Integer price;
41   - @Schema(description = "图片地址", required = true, example = "https://www.iocoder.cn/1.png")
  41 + @Schema(description = "图片地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
42 42 private String picUrl;
43 43  
44   - @Schema(description = "属性数组", required = true, example = "100")
  44 + @Schema(description = "属性数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
45 45 private List<AppProductPropertyValueDetailRespVO> properties;
46 46  
47 47 // ========== 购物车信息 ==========
48 48  
49   - @Schema(description = "购物车编号", required = true, example = "100")
  49 + @Schema(description = "购物车编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
50 50 private Long cartId;
51 51  
52   - @Schema(description = "购买数量", required = true, example = "1")
  52 + @Schema(description = "购买数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
53 53 private Integer count;
54 54  
55 55 }
... ... @@ -60,19 +60,19 @@ public class AppTradeOrderSettlementRespVO {
60 60 @AllArgsConstructor
61 61 public static class Price {
62 62  
63   - @Schema(description = "商品原价(总),单位:分", required = true, example = "500")
  63 + @Schema(description = "商品原价(总),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "500")
64 64 private Integer totalPrice;
65 65  
66   - @Schema(description = "运费金额,单位:分", required = true, example = "50")
  66 + @Schema(description = "运费金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
67 67 private Integer deliveryPrice;
68 68  
69   - @Schema(description = "优惠劵减免金额,单位:分", required = true, example = "100")
  69 + @Schema(description = "优惠劵减免金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
70 70 private Integer couponPrice;
71 71  
72   - @Schema(description = "积分抵扣的金额,单位:分", required = true, example = "50")
  72 + @Schema(description = "积分抵扣的金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
73 73 private Integer pointPrice;
74 74  
75   - @Schema(description = "实际支付金额(总),单位:分", required = true, example = "450")
  75 + @Schema(description = "实际支付金额(总),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "450")
76 76 private Integer payPrice;
77 77  
78 78 }
... ... @@ -81,34 +81,34 @@ public class AppTradeOrderSettlementRespVO {
81 81 @Data
82 82 public static class Address {
83 83  
84   - @Schema(description = "编号", required = true, example = "1")
  84 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
85 85 private Long id;
86 86  
87   - @Schema(description = "收件人名称", required = true, example = "小王")
  87 + @Schema(description = "收件人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小王")
88 88 private String name;
89 89  
90   - @Schema(description = "手机号", required = true, example = "15601691300")
  90 + @Schema(description = "手机号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15601691300")
91 91 private String mobile;
92 92  
93   - @Schema(description = "省份编号", required = true, example = "1")
  93 + @Schema(description = "省份编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
94 94 private Integer provinceId;
95   - @Schema(description = "省份名字", required = true, example = "北京")
  95 + @Schema(description = "省份名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "北京")
96 96 private String provinceName;
97 97  
98   - @Schema(description = "城市编号", required = true, example = "1")
  98 + @Schema(description = "城市编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
99 99 private Integer cityId;
100   - @Schema(description = "城市名字", required = true, example = "北京")
  100 + @Schema(description = "城市名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "北京")
101 101 private String cityName;
102 102  
103   - @Schema(description = "地区编号", required = true, example = "1")
  103 + @Schema(description = "地区编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
104 104 private Integer districtId;
105   - @Schema(description = "地区名字", required = true, example = "朝阳区")
  105 + @Schema(description = "地区名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "朝阳区")
106 106 private String districtName;
107 107  
108   - @Schema(description = "详细地址", required = true, example = "望京悠乐汇 A 座")
  108 + @Schema(description = "详细地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "望京悠乐汇 A 座")
109 109 private String detailAddress;
110 110  
111   - @Schema(description = "是否默认收件地址", required = true, example = "true")
  111 + @Schema(description = "是否默认收件地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
112 112 private Boolean defaulted;
113 113  
114 114 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/item/AppTradeOrderItemCommentCreateReqVO.java
... ... @@ -11,59 +11,33 @@ import java.util.List;
11 11 @Data
12 12 public class AppTradeOrderItemCommentCreateReqVO {
13 13  
14   - @Schema(description = "是否匿名", required = true, example = "true")
  14 + @Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
15 15 @NotNull(message = "是否匿名不能为空")
16 16 private Boolean anonymous;
17 17  
18   - @Schema(description = "交易订单项编号", required = true, example = "2312312")
  18 + @Schema(description = "交易订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2312312")
19 19 @NotNull(message = "交易订单项编号不能为空")
20 20 private Long orderItemId;
21 21  
22   - // TODO @puhui:spuId、spuName、skuId 直接查询出来;
23   - @Schema(description = "商品SPU编号", required = true, example = "29502")
24   - @NotNull(message = "商品SPU编号不能为空")
25   - private Long spuId;
26   -
27   - @Schema(description = "商品SPU名称", required = true, example = "丝滑飘逸小短裙")
28   - @NotNull(message = "商品SPU名称不能为空")
29   - private String spuName;
30   -
31   - @Schema(description = "商品SKU编号", required = true, example = "3082")
32   - @NotNull(message = "商品SKU编号不能为空")
33   - private Long skuId;
34   -
35   - @Schema(description = "评分星级 1-5 分", required = true, example = "5")
  22 + @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
36 23 @NotNull(message = "评分星级 1-5 分不能为空")
37 24 private Integer scores;
38 25  
39   - @Schema(description = "描述星级 1-5 分", required = true, example = "5")
  26 + @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
40 27 @NotNull(message = "描述星级 1-5 分不能为空")
41 28 private Integer descriptionScores;
42 29  
43   - @Schema(description = "服务星级 1-5 分", required = true, example = "5")
  30 + @Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
44 31 @NotNull(message = "服务星级 1-5 分不能为空")
45 32 private Integer benefitScores;
46 33  
47   - @Schema(description = "评论内容", required = true, example = "穿身上很漂亮诶(*^▽^*)")
  34 + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿身上很漂亮诶(*^▽^*)")
48 35 @NotNull(message = "评论内容不能为空")
49 36 private String content;
50 37  
51   - @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xx.png]")
  38 + @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xx.png]")
52 39 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
53 40 private List<String> picUrls;
54 41  
55   - @Schema(description = "评价人名称", required = true, example = "小姑凉")
56   - @NotNull(message = "评价人名称不能为空")
57   - private String userNickname;
58   -
59   - // TODO @puhui:userAvatar、userAvatar、userId 直接查询出来;
60   -
61   - @Schema(description = "评价人头像", required = true, example = "https://www.iocoder.cn/xx.png")
62   - @NotNull(message = "评价人头像不能为空")
63   - private String userAvatar;
64   -
65   - @Schema(description = "评价人", required = true, example = "16868")
66   - @NotNull(message = "评价人不能为空")
67   - private Long userId;
68 42  
69 43 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/item/AppTradeOrderItemRespVO.java
... ... @@ -10,15 +10,15 @@ import java.util.List;
10 10 @Data
11 11 public class AppTradeOrderItemRespVO {
12 12  
13   - @Schema(description = "编号", required = true, example = "1")
  13 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
14 14 private Long id;
15 15  
16   - @Schema(description = "商品 SPU 编号", required = true, example = "1")
  16 + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
17 17 private Long spuId;
18   - @Schema(description = "商品 SPU 名称", required = true, example = "芋道源码")
  18 + @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
19 19 private String spuName;
20 20  
21   - @Schema(description = "商品 SKU 编号", required = true, example = "1")
  21 + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
22 22 private Long skuId;
23 23  
24 24 /**
... ... @@ -26,18 +26,18 @@ public class AppTradeOrderItemRespVO {
26 26 */
27 27 private List<AppProductPropertyValueDetailRespVO> properties;
28 28  
29   - @Schema(description = "商品图片", required = true, example = "https://www.iocoder.cn/1.png")
  29 + @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
30 30 private String picUrl;
31 31  
32   - @Schema(description = "购买数量", required = true, example = "1")
  32 + @Schema(description = "购买数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
33 33 private Integer count;
34 34  
35   - @Schema(description = "是否评价", required = true, example = "true")
  35 + @Schema(description = "是否评价", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
36 36 private Boolean commentStatus;
37 37  
38 38 // ========== 价格 + 支付基本信息 ==========
39 39  
40   - @Schema(description = "商品原价(单)", required = true, example = "100")
  40 + @Schema(description = "商品原价(单)", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
41 41 private Integer price;
42 42  
43 43 // ========== 营销基本信息 ==========
... ... @@ -46,7 +46,7 @@ public class AppTradeOrderItemRespVO {
46 46  
47 47 // ========== 售后基本信息 ==========
48 48  
49   - @Schema(description = "售后状态", required = true, example = "1")
  49 + @Schema(description = "售后状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
50 50 private Integer afterSaleStatus;
51 51  
52 52 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java
... ... @@ -259,7 +259,17 @@ public interface TradeOrderConvert {
259 259  
260 260 AppTradeOrderItemRespVO convert03(TradeOrderItemDO bean);
261 261  
262   - ProductCommentCreateReqDTO convert04(AppTradeOrderItemCommentCreateReqVO createReqVO);
  262 + @Mapping(target = "skuId", source = "tradeOrderItemDO.skuId")
  263 + @Mapping(target = "orderId", source = "tradeOrderItemDO.orderId")
  264 + @Mapping(target = "orderItemId", source = "tradeOrderItemDO.id")
  265 + @Mapping(target = "scores", source = "createReqVO.scores")
  266 + @Mapping(target = "descriptionScores", source = "createReqVO.descriptionScores")
  267 + @Mapping(target = "benefitScores", source = "createReqVO.benefitScores")
  268 + @Mapping(target = "content", source = "createReqVO.content")
  269 + @Mapping(target = "picUrls", source = "createReqVO.picUrls")
  270 + @Mapping(target = "anonymous", source = "createReqVO.anonymous")
  271 + @Mapping(target = "userId", source = "tradeOrderItemDO.userId")
  272 + ProductCommentCreateReqDTO convert04(AppTradeOrderItemCommentCreateReqVO createReqVO, TradeOrderItemDO tradeOrderItemDO);
263 273  
264 274 default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO,
265 275 List<TradeCartDO> cartList) {
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java
1 1 package cn.iocoder.yudao.module.trade.dal.mysql.order;
2 2  
3 3 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  4 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
4 5 import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
5 6 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
6 7 import org.apache.ibatis.annotations.Mapper;
... ... @@ -24,4 +25,9 @@ public interface TradeOrderItemMapper extends BaseMapperX&lt;TradeOrderItemDO&gt; {
24 25 return selectList(TradeOrderItemDO::getOrderId, orderIds);
25 26 }
26 27  
  28 + default TradeOrderItemDO selectOrderItemByIdAndUserId(Long orderItemId, Long loginUserId) {
  29 + return selectOne(new LambdaQueryWrapperX<TradeOrderItemDO>()
  30 + .eq(TradeOrderItemDO::getId, orderItemId)
  31 + .eq(TradeOrderItemDO::getUserId, loginUserId));
  32 + }
27 33 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java
... ... @@ -50,4 +50,10 @@ public interface TradeOrderMapper extends BaseMapperX&lt;TradeOrderDO&gt; {
50 50 .eqIfPresent(TradeOrderDO::getStatus, status)
51 51 .eqIfPresent(TradeOrderDO::getCommentStatus, commentStatus));
52 52 }
  53 +
  54 + default TradeOrderDO selectOrderByIdAndUserId(Long orderId, Long loginUserId) {
  55 + return selectOne(new LambdaQueryWrapperX<TradeOrderDO>()
  56 + .eq(TradeOrderDO::getId, orderId)
  57 + .eq(TradeOrderDO::getUserId, loginUserId));
  58 + }
53 59 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java
... ... @@ -160,4 +160,21 @@ public interface TradeOrderService {
160 160 */
161 161 List<TradeOrderItemDO> getOrderItemListByOrderId(Collection<Long> orderIds);
162 162  
  163 + /**
  164 + * 得到订单项通过 订单项 id 和用户 id
  165 + *
  166 + * @param orderItemId 订单项 id
  167 + * @param loginUserId 登录用户 id
  168 + * @return 得到订单项
  169 + */
  170 + TradeOrderItemDO getOrderItemByIdAndUserId(Long orderItemId, Long loginUserId);
  171 +
  172 + /**
  173 + * 得到订单通过 id 和 用户 id
  174 + *
  175 + * @param orderId 订单 id
  176 + * @param loginUserId 登录用户 id
  177 + * @return 得到订单
  178 + */
  179 + TradeOrderDO getOrderByIdAndUserId(Long orderId, Long loginUserId);
163 180 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java
... ... @@ -565,6 +565,16 @@ public class TradeOrderServiceImpl implements TradeOrderService {
565 565 return tradeOrderItemMapper.selectListByOrderId(orderIds);
566 566 }
567 567  
  568 + @Override
  569 + public TradeOrderItemDO getOrderItemByIdAndUserId(Long orderItemId, Long loginUserId) {
  570 + return tradeOrderItemMapper.selectOrderItemByIdAndUserId(orderItemId, loginUserId);
  571 + }
  572 +
  573 + @Override
  574 + public TradeOrderDO getOrderByIdAndUserId(Long orderId, Long loginUserId) {
  575 + return tradeOrderMapper.selectOrderByIdAndUserId(orderId, loginUserId);
  576 + }
  577 +
568 578 /**
569 579 * 判断指定订单的所有订单项,是不是都售后成功
570 580 *
... ...