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,14 +9,12 @@ import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDT
9 */ 9 */
10 public interface ProductCommentApi { 10 public interface ProductCommentApi {
11 11
12 - // TODO @puhui:Long orderId 放到 createReqDTO 里噶?  
13 /** 12 /**
14 * 创建评论 13 * 创建评论
15 * 14 *
16 * @param createReqDTO 评论参数 15 * @param createReqDTO 评论参数
17 - * @param orderId 订单 id  
18 * @return 返回评论创建后的 id 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,19 +17,13 @@ public class ProductCommentCreateReqDTO {
17 */ 17 */
18 private Long skuId; 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 * 评分星级 1-5 分 29 * 评分星级 1-5 分
@@ -60,14 +54,6 @@ public class ProductCommentCreateReqDTO { @@ -60,14 +54,6 @@ public class ProductCommentCreateReqDTO {
60 * 评价人 54 * 评价人
61 */ 55 */
62 private Long userId; 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 package cn.iocoder.yudao.module.product.api.comment; 1 package cn.iocoder.yudao.module.product.api.comment;
2 2
3 import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; 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 import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; 4 import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
7 import org.springframework.stereotype.Service; 5 import org.springframework.stereotype.Service;
8 import org.springframework.validation.annotation.Validated; 6 import org.springframework.validation.annotation.Validated;
@@ -22,9 +20,8 @@ public class ProductCommentApiImpl implements ProductCommentApi { @@ -22,9 +20,8 @@ public class ProductCommentApiImpl implements ProductCommentApi {
22 private ProductCommentService productCommentService; 20 private ProductCommentService productCommentService;
23 21
24 @Override 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,43 +10,51 @@ import java.util.List;
10 @Data 10 @Data
11 public class ProductCommentBaseVO { 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 @NotNull(message = "评价人名称不能为空") 22 @NotNull(message = "评价人名称不能为空")
15 private String userNickname; 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 @NotNull(message = "评价人头像不能为空") 26 @NotNull(message = "评价人头像不能为空")
19 private String userAvatar; 27 private String userAvatar;
20 28
21 - @Schema(description = "商品 SPU 编号", required = true, example = "清凉丝滑透气小短袖") 29 + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖")
22 @NotNull(message = "商品 SPU 编号不能为空") 30 @NotNull(message = "商品 SPU 编号不能为空")
23 private Long spuId; 31 private Long spuId;
24 32
25 - @Schema(description = "商品 SPU 名称", required = true, example = "赵六") 33 + @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
26 @NotNull(message = "商品 SPU 名称不能为空") 34 @NotNull(message = "商品 SPU 名称不能为空")
27 private String spuName; 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 @NotNull(message = "商品 SKU 编号不能为空") 38 @NotNull(message = "商品 SKU 编号不能为空")
31 private Long skuId; 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 @NotNull(message = "评分星级不能为空") 42 @NotNull(message = "评分星级不能为空")
35 private Integer scores; 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 @NotNull(message = "描述星级不能为空") 46 @NotNull(message = "描述星级不能为空")
39 private Integer descriptionScores; 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 @NotNull(message = "服务星级分不能为空") 50 @NotNull(message = "服务星级分不能为空")
43 private Integer benefitScores; 51 private Integer benefitScores;
44 52
45 - @Schema(description = "评论内容", required = true, example = "穿起来非常丝滑凉快") 53 + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快")
46 @NotNull(message = "评论内容不能为空") 54 @NotNull(message = "评论内容不能为空")
47 private String content; 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 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张") 58 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
51 private List<String> picUrls; 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,21 +5,10 @@ import lombok.Data;
5 import lombok.EqualsAndHashCode; 5 import lombok.EqualsAndHashCode;
6 import lombok.ToString; 6 import lombok.ToString;
7 7
8 -import javax.validation.constraints.NotNull;  
9 -  
10 @Schema(description = "管理后台 - 商品评价创建 Request VO") 8 @Schema(description = "管理后台 - 商品评价创建 Request VO")
11 @Data 9 @Data
12 @EqualsAndHashCode(callSuper = true) 10 @EqualsAndHashCode(callSuper = true)
13 @ToString(callSuper = true) 11 @ToString(callSuper = true)
14 public class ProductCommentCreateReqVO extends ProductCommentBaseVO { 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,11 +12,11 @@ import javax.validation.constraints.NotNull;
12 @ToString(callSuper = true) 12 @ToString(callSuper = true)
13 public class ProductCommentReplyReqVO { 13 public class ProductCommentReplyReqVO {
14 14
15 - @Schema(description = "评价编号", required = true, example = "15721") 15 + @Schema(description = "评价编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
16 @NotNull(message = "评价编号不能为空") 16 @NotNull(message = "评价编号不能为空")
17 private Long id; 17 private Long id;
18 18
19 - @Schema(description = "商家回复内容", required = true, example = "谢谢亲") 19 + @Schema(description = "商家回复内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "谢谢亲")
20 @NotEmpty(message = "商家回复内容不能为空") 20 @NotEmpty(message = "商家回复内容不能为空")
21 private String replyContent; 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,37 +13,31 @@ import java.time.LocalDateTime;
13 @ToString(callSuper = true) 13 @ToString(callSuper = true)
14 public class ProductCommentRespVO extends ProductCommentBaseVO { 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 private Long id; 17 private Long id;
18 18
19 - @Schema(description = "是否匿名", required = true, example = "false") 19 + @Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
20 private Boolean anonymous; 20 private Boolean anonymous;
21 21
22 - @Schema(description = "交易订单编号", required = true, example = "24428") 22 + @Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
23 private Long orderId; 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 private Boolean visible; 26 private Boolean visible;
33 27
34 - @Schema(description = "商家是否回复:[1:回复 0:未回复]", required = true) 28 + @Schema(description = "商家是否回复:[1:回复 0:未回复]", requiredMode = Schema.RequiredMode.REQUIRED)
35 private Boolean replyStatus; 29 private Boolean replyStatus;
36 30
37 - @Schema(description = "回复管理员编号", example = "22212") 31 + @Schema(description = "回复管理员编号", example = "9527")
38 private Long replyUserId; 32 private Long replyUserId;
39 33
40 - @Schema(description = "商家回复内容") 34 + @Schema(description = "商家回复内容", example = "感谢好评哦亲(づ ̄3 ̄)づ╭❤~")
41 private String replyContent; 35 private String replyContent;
42 36
43 - @Schema(description = "商家回复时间") 37 + @Schema(description = "商家回复时间", example = "2023-08-08 12:20:55")
44 private LocalDateTime replyTime; 38 private LocalDateTime replyTime;
45 39
46 - @Schema(description = "创建时间", required = true) 40 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
47 private LocalDateTime createTime; 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 +11,11 @@ import javax.validation.constraints.NotNull;
11 @ToString(callSuper = true) 11 @ToString(callSuper = true)
12 public class ProductCommentUpdateVisibleReqVO { 12 public class ProductCommentUpdateVisibleReqVO {
13 13
14 - @Schema(description = "评价编号", required = true, example = "15721") 14 + @Schema(description = "评价编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
15 @NotNull(message = "评价编号不能为空") 15 @NotNull(message = "评价编号不能为空")
16 private Long id; 16 private Long id;
17 17
18 - @Schema(description = "是否可见", required = true, example = "false") 18 + @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
19 @NotNull(message = "是否可见不能为空") 19 @NotNull(message = "是否可见不能为空")
20 private Boolean visible; 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 package cn.iocoder.yudao.module.product.controller.app.comment; 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 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; 7 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
6 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; 8 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
7 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; 9 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
8 import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; 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 import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; 14 import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
  15 +import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
10 import io.swagger.v3.oas.annotations.Operation; 16 import io.swagger.v3.oas.annotations.Operation;
11 import io.swagger.v3.oas.annotations.Parameter; 17 import io.swagger.v3.oas.annotations.Parameter;
12 import io.swagger.v3.oas.annotations.Parameters; 18 import io.swagger.v3.oas.annotations.Parameters;
13 import io.swagger.v3.oas.annotations.tags.Tag; 19 import io.swagger.v3.oas.annotations.tags.Tag;
  20 +import org.springframework.context.annotation.Lazy;
14 import org.springframework.validation.annotation.Validated; 21 import org.springframework.validation.annotation.Validated;
15 import org.springframework.web.bind.annotation.GetMapping; 22 import org.springframework.web.bind.annotation.GetMapping;
16 import org.springframework.web.bind.annotation.RequestMapping; 23 import org.springframework.web.bind.annotation.RequestMapping;
@@ -19,11 +26,11 @@ import org.springframework.web.bind.annotation.RestController; @@ -19,11 +26,11 @@ import org.springframework.web.bind.annotation.RestController;
19 26
20 import javax.annotation.Resource; 27 import javax.annotation.Resource;
21 import javax.validation.Valid; 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 import java.util.List; 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 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 35 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
29 36
@@ -36,7 +43,10 @@ public class AppProductCommentController { @@ -36,7 +43,10 @@ public class AppProductCommentController {
36 @Resource 43 @Resource
37 private ProductCommentService productCommentService; 44 private ProductCommentService productCommentService;
38 45
39 - // TODO @puhui999:可以实现下 46 + @Resource
  47 + @Lazy
  48 + private ProductSkuService productSkuService;
  49 +
40 @GetMapping("/list") 50 @GetMapping("/list")
41 @Operation(summary = "获得最近的 n 条商品评价") 51 @Operation(summary = "获得最近的 n 条商品评价")
42 @Parameters({ 52 @Parameters({
@@ -45,67 +55,38 @@ public class AppProductCommentController { @@ -45,67 +55,38 @@ public class AppProductCommentController {
45 }) 55 })
46 public CommonResult<List<AppProductCommentRespVO>> getCommentList(@RequestParam("spuId") Long spuId, 56 public CommonResult<List<AppProductCommentRespVO>> getCommentList(@RequestParam("spuId") Long spuId,
47 @RequestParam(value = "count", defaultValue = "10") Integer count) { 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 @GetMapping("/page") 62 @GetMapping("/page")
99 @Operation(summary = "获得商品评价分页") 63 @Operation(summary = "获得商品评价分页")
100 public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) { 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 @GetMapping("/getCommentStatistics") 86 @GetMapping("/getCommentStatistics")
106 @Operation(summary = "获得商品的评价统计") 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,16 +9,16 @@ import lombok.ToString;
9 @ToString(callSuper = true) 9 @ToString(callSuper = true)
10 public class AppCommentStatisticsRespVO { 10 public class AppCommentStatisticsRespVO {
11 11
12 - @Schema(description = "所有评论数量", required = true, example = "15721") 12 + @Schema(description = "所有评论数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
13 private Long allCount; 13 private Long allCount;
14 14
15 - @Schema(description = "好评数量", required = true, example = "15721") 15 + @Schema(description = "好评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
16 private Long goodCount; 16 private Long goodCount;
17 17
18 - @Schema(description = "中评数量", required = true, example = "15721") 18 + @Schema(description = "中评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
19 private Long mediocreCount; 19 private Long mediocreCount;
20 20
21 - @Schema(description = "差评数量", required = true, example = "15721") 21 + @Schema(description = "差评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
22 private Long negativeCount; 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,43 +13,43 @@ import java.util.List;
13 @ToString(callSuper = true) 13 @ToString(callSuper = true)
14 public class AppProductCommentCreateReqVO { 14 public class AppProductCommentCreateReqVO {
15 15
16 - @Schema(description = "是否匿名", required = true, example = "true") 16 + @Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
17 @NotNull(message = "是否匿名不能为空") 17 @NotNull(message = "是否匿名不能为空")
18 private Boolean anonymous; 18 private Boolean anonymous;
19 19
20 - @Schema(description = "交易订单项编号", required = true, example = "2312312") 20 + @Schema(description = "交易订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2312312")
21 @NotNull(message = "交易订单项编号不能为空") 21 @NotNull(message = "交易订单项编号不能为空")
22 private Long orderItemId; 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 @NotNull(message = "商品SPU编号不能为空") 25 @NotNull(message = "商品SPU编号不能为空")
26 private Long spuId; 26 private Long spuId;
27 27
28 - @Schema(description = "商品 SPU 名称", required = true, example = "清凉丝滑小短袖") 28 + @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑小短袖")
29 @NotNull(message = "商品SPU名称不能为空") 29 @NotNull(message = "商品SPU名称不能为空")
30 private String spuName; 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 @NotNull(message = "商品SKU编号不能为空") 33 @NotNull(message = "商品SKU编号不能为空")
34 private Long skuId; 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 @NotNull(message = "评分星级 1-5 分不能为空") 37 @NotNull(message = "评分星级 1-5 分不能为空")
38 private Integer scores; 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 @NotNull(message = "描述星级 1-5 分不能为空") 41 @NotNull(message = "描述星级 1-5 分不能为空")
42 private Integer descriptionScores; 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 @NotNull(message = "服务星级 1-5 分不能为空") 45 @NotNull(message = "服务星级 1-5 分不能为空")
46 private Integer benefitScores; 46 private Integer benefitScores;
47 47
48 - @Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评") 48 + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "哇,真的很丝滑凉快诶,好评")
49 @NotNull(message = "评论内容不能为空") 49 @NotNull(message = "评论内容不能为空")
50 private String content; 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 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张") 53 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
54 private List<String> picUrls; 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,28 +23,28 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
23 @ToString(callSuper = true) 23 @ToString(callSuper = true)
24 public class AppProductCommentRespVO { 24 public class AppProductCommentRespVO {
25 25
26 - @Schema(description = "评价人的用户编号", required = true, example = "15721") 26 + @Schema(description = "评价人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
27 private Long userId; 27 private Long userId;
28 28
29 - @Schema(description = "评价人名称", required = true, example = "张三") 29 + @Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
30 private String userNickname; 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 private String userAvatar; 33 private String userAvatar;
34 34
35 - @Schema(description = "订单项编号", required = true, example = "24965") 35 + @Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24965")
36 private Long id; 36 private Long id;
37 37
38 - @Schema(description = "是否匿名", required = true, example = "false") 38 + @Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
39 private Boolean anonymous; 39 private Boolean anonymous;
40 40
41 - @Schema(description = "交易订单编号", required = true, example = "24428") 41 + @Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
42 private Long orderId; 42 private Long orderId;
43 43
44 - @Schema(description = "交易订单项编号", required = true, example = "8233") 44 + @Schema(description = "交易订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8233")
45 private Long orderItemId; 45 private Long orderItemId;
46 46
47 - @Schema(description = "商家是否回复", required = true, example = "true") 47 + @Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
48 private Boolean replyStatus; 48 private Boolean replyStatus;
49 49
50 @Schema(description = "回复管理员编号", example = "22212") 50 @Schema(description = "回复管理员编号", example = "22212")
@@ -71,38 +71,38 @@ public class AppProductCommentRespVO { @@ -71,38 +71,38 @@ public class AppProductCommentRespVO {
71 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) 71 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
72 private LocalDateTime createTime; 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 @NotNull(message = "商品SPU编号不能为空") 75 @NotNull(message = "商品SPU编号不能为空")
76 private Long spuId; 76 private Long spuId;
77 77
78 - @Schema(description = "商品SPU名称", required = true, example = "清凉丝滑小短袖") 78 + @Schema(description = "商品SPU名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑小短袖")
79 @NotNull(message = "商品SPU名称不能为空") 79 @NotNull(message = "商品SPU名称不能为空")
80 private String spuName; 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 @NotNull(message = "商品SKU编号不能为空") 83 @NotNull(message = "商品SKU编号不能为空")
84 private Long skuId; 84 private Long skuId;
85 85
86 - @Schema(description = "商品 SKU 属性", required = true) 86 + @Schema(description = "商品 SKU 属性", requiredMode = Schema.RequiredMode.REQUIRED)
87 private List<AppProductPropertyValueDetailRespVO> skuProperties; 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 @NotNull(message = "评分星级 1-5 分不能为空") 90 @NotNull(message = "评分星级 1-5 分不能为空")
91 private Integer scores; 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 @NotNull(message = "描述星级 1-5 分不能为空") 94 @NotNull(message = "描述星级 1-5 分不能为空")
95 private Integer descriptionScores; 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 @NotNull(message = "服务星级 1-5 分不能为空") 98 @NotNull(message = "服务星级 1-5 分不能为空")
99 private Integer benefitScores; 99 private Integer benefitScores;
100 100
101 - @Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评") 101 + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "哇,真的很丝滑凉快诶,好评")
102 @NotNull(message = "评论内容不能为空") 102 @NotNull(message = "评论内容不能为空")
103 private String content; 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 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张") 106 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
107 private List<String> picUrls; 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 package cn.iocoder.yudao.module.product.convert.comment; 1 package cn.iocoder.yudao.module.product.convert.comment;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
4 import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; 5 import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
5 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO; 6 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
6 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO; 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,6 +10,7 @@ import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductComme
9 import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; 10 import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
10 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; 11 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
11 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; 12 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
  13 +import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
12 import org.mapstruct.Mapper; 14 import org.mapstruct.Mapper;
13 import org.mapstruct.Mapping; 15 import org.mapstruct.Mapping;
14 import org.mapstruct.Named; 16 import org.mapstruct.Named;
@@ -59,9 +61,18 @@ public interface ProductCommentConvert { @@ -59,9 +61,18 @@ public interface ProductCommentConvert {
59 return divide.intValue(); 61 return divide.intValue();
60 } 62 }
61 63
62 - @Mapping(target = "orderId", source = "orderId") 64 + ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO);
  65 +
63 @Mapping(target = "scores", expression = "java(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()))") 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 @Mapping(target = "userId", constant = "0L") 77 @Mapping(target = "userId", constant = "0L")
67 @Mapping(target = "orderId", constant = "0L") 78 @Mapping(target = "orderId", constant = "0L")
@@ -70,4 +81,5 @@ public interface ProductCommentConvert { @@ -70,4 +81,5 @@ public interface ProductCommentConvert {
70 @Mapping(target = "scores", expression = "java(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()))") 81 @Mapping(target = "scores", expression = "java(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()))")
71 ProductCommentDO convert(ProductCommentCreateReqVO createReq); 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,6 +2,7 @@ package cn.iocoder.yudao.module.product.dal.mysql.comment;
2 2
3 3
4 import cn.hutool.core.util.ObjectUtil; 4 import cn.hutool.core.util.ObjectUtil;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 7 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
7 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 8 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
@@ -25,19 +26,18 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; { @@ -25,19 +26,18 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; {
25 } 26 }
26 27
27 // TODO 芋艿:在看看这块 28 // TODO 芋艿:在看看这块
28 - // TODO @puhui999:直接使用 scores 来算好评、中评、差评  
29 static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> queryWrapper, Integer type) { 29 static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> queryWrapper, Integer type) {
30 - // 构建好评查询语句:好评计算 (商品评分星级+服务评分星级) >= 8 30 + // 构建好评查询语句:好评计算 总评 >= 4
31 if (ObjectUtil.equal(type, AppCommentPageReqVO.GOOD_COMMENT)) { 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 if (ObjectUtil.equal(type, AppCommentPageReqVO.MEDIOCRE_COMMENT)) { 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 if (ObjectUtil.equal(type, AppCommentPageReqVO.NEGATIVE_COMMENT)) { 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,10 +52,10 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; {
52 return selectPage(reqVO, queryWrapper); 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 return selectOne(new LambdaQueryWrapperX<ProductCommentDO>() 56 return selectOne(new LambdaQueryWrapperX<ProductCommentDO>()
57 .eq(ProductCommentDO::getUserId, userId) 57 .eq(ProductCommentDO::getUserId, userId)
58 - .eq(ProductCommentDO::getOrderId, orderId) 58 + .eq(ProductCommentDO::getOrderItemId, orderItemId)
59 .eq(ProductCommentDO::getSpuId, spuId)); 59 .eq(ProductCommentDO::getSpuId, spuId));
60 } 60 }
61 61
@@ -68,4 +68,12 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; { @@ -68,4 +68,12 @@ public interface ProductCommentMapper extends BaseMapperX&lt;ProductCommentDO&gt; {
68 return selectCount(queryWrapper); 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 package cn.iocoder.yudao.module.product.service.comment; 1 package cn.iocoder.yudao.module.product.service.comment;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
4 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO; 5 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
5 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; 6 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
6 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO; 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,6 +13,8 @@ import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
12 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
13 import org.springframework.validation.annotation.Validated; 14 import org.springframework.validation.annotation.Validated;
14 15
  16 +import java.util.List;
  17 +
15 /** 18 /**
16 * 商品评论 Service 接口 19 * 商品评论 Service 接口
17 * 20 *
@@ -65,10 +68,10 @@ public interface ProductCommentService { @@ -65,10 +68,10 @@ public interface ProductCommentService {
65 * 创建评论 68 * 创建评论
66 * 创建商品评论 APP 端创建商品评论使用 69 * 创建商品评论 APP 端创建商品评论使用
67 * 70 *
68 - * @param commentDO 评论对象 71 + * @param createReqDTO 创建请求 dto
69 * @return 返回评论 id 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,6 +80,15 @@ public interface ProductCommentService {
77 * @param visible 是否可见 80 * @param visible 是否可见
78 * @return 评价统计 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 package cn.iocoder.yudao.module.product.service.comment; 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 import cn.iocoder.yudao.framework.common.pojo.PageResult; 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 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO; 7 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
7 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; 8 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
8 import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO; 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,7 +11,6 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen
10 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; 11 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
11 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; 12 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
12 import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; 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 import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; 14 import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
15 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; 15 import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
16 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; 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,7 +18,6 @@ import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
18 import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; 18 import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper;
19 import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; 19 import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
20 import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; 20 import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
21 -import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;  
22 import org.springframework.context.annotation.Lazy; 21 import org.springframework.context.annotation.Lazy;
23 import org.springframework.stereotype.Service; 22 import org.springframework.stereotype.Service;
24 import org.springframework.transaction.annotation.Transactional; 23 import org.springframework.transaction.annotation.Transactional;
@@ -26,11 +25,7 @@ import org.springframework.validation.annotation.Validated; @@ -26,11 +25,7 @@ import org.springframework.validation.annotation.Validated;
26 25
27 import javax.annotation.Resource; 26 import javax.annotation.Resource;
28 import java.time.LocalDateTime; 27 import java.time.LocalDateTime;
29 -import java.util.HashMap;  
30 import java.util.List; 28 import java.util.List;
31 -import java.util.Map;  
32 -import java.util.Set;  
33 -import java.util.stream.Collectors;  
34 29
35 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 30 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
36 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; 31 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
@@ -48,15 +43,15 @@ public class ProductCommentServiceImpl implements ProductCommentService { @@ -48,15 +43,15 @@ public class ProductCommentServiceImpl implements ProductCommentService {
48 private ProductCommentMapper productCommentMapper; 43 private ProductCommentMapper productCommentMapper;
49 44
50 @Resource 45 @Resource
51 - private TradeOrderApi tradeOrderApi;  
52 -  
53 - @Resource  
54 private ProductSpuService productSpuService; 46 private ProductSpuService productSpuService;
55 47
56 @Resource 48 @Resource
57 @Lazy 49 @Lazy
58 private ProductSkuService productSkuService; 50 private ProductSkuService productSkuService;
59 51
  52 + @Resource
  53 + private MemberUserApi memberUserApi;
  54 +
60 @Override 55 @Override
61 @Transactional(rollbackFor = Exception.class) 56 @Transactional(rollbackFor = Exception.class)
62 public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) { 57 public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) {
@@ -85,11 +80,8 @@ public class ProductCommentServiceImpl implements ProductCommentService { @@ -85,11 +80,8 @@ public class ProductCommentServiceImpl implements ProductCommentService {
85 @Override 80 @Override
86 @Transactional(rollbackFor = Exception.class) 81 @Transactional(rollbackFor = Exception.class)
87 public void createComment(ProductCommentCreateReqVO createReqVO) { 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 ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO); 86 ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO);
95 productCommentMapper.insert(commentDO); 87 productCommentMapper.insert(commentDO);
@@ -97,26 +89,41 @@ public class ProductCommentServiceImpl implements ProductCommentService { @@ -97,26 +89,41 @@ public class ProductCommentServiceImpl implements ProductCommentService {
97 89
98 @Override 90 @Override
99 @Transactional(rollbackFor = Exception.class) 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 productCommentMapper.insert(commentDO); 107 productCommentMapper.insert(commentDO);
105 return commentDO.getId(); 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 if (null != exist) { 114 if (null != exist) {
116 throw exception(ORDER_SPU_COMMENT_EXISTS); 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 private ProductCommentDO validateCommentExists(Long id) { 127 private ProductCommentDO validateCommentExists(Long id) {
121 ProductCommentDO productComment = productCommentMapper.selectById(id); 128 ProductCommentDO productComment = productCommentMapper.selectById(id);
122 if (productComment == null) { 129 if (productComment == null) {
@@ -126,7 +133,7 @@ public class ProductCommentServiceImpl implements ProductCommentService { @@ -126,7 +133,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
126 } 133 }
127 134
128 @Override 135 @Override
129 - public AppCommentStatisticsRespVO getCommentPageTabsCount(Long spuId, Boolean visible) { 136 + public AppCommentStatisticsRespVO getCommentStatistics(Long spuId, Boolean visible) {
130 return ProductCommentConvert.INSTANCE.convert( 137 return ProductCommentConvert.INSTANCE.convert(
131 // 查询商品 id = spuId 的所有评论数量 138 // 查询商品 id = spuId 的所有评论数量
132 productCommentMapper.selectCountBySpuId(spuId, visible, null), 139 productCommentMapper.selectCountBySpuId(spuId, visible, null),
@@ -140,28 +147,17 @@ public class ProductCommentServiceImpl implements ProductCommentService { @@ -140,28 +147,17 @@ public class ProductCommentServiceImpl implements ProductCommentService {
140 } 147 }
141 148
142 @Override 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 public PageResult<AppProductCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { 158 public PageResult<AppProductCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) {
144 - PageResult<AppProductCommentRespVO> result = ProductCommentConvert.INSTANCE.convertPage02( 159 + return ProductCommentConvert.INSTANCE.convertPage02(
145 productCommentMapper.selectPage(pageVO, visible)); 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 @Override 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,7 +150,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest {
150 assertEquals(2, result3.getTotal()); 150 assertEquals(2, result3.getTotal());
151 151
152 // 测试分页 tab count 152 // 测试分页 tab count
153 - AppCommentStatisticsRespVO tabsCount = productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE); 153 + AppCommentStatisticsRespVO tabsCount = productCommentService.getCommentStatistics(spuId, Boolean.TRUE);
154 assertEquals(6, tabsCount.getAllCount()); 154 assertEquals(6, tabsCount.getAllCount());
155 assertEquals(4, tabsCount.getGoodCount()); 155 assertEquals(4, tabsCount.getGoodCount());
156 assertEquals(2, tabsCount.getMediocreCount()); 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,7 +2,11 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity;
2 2
3 import cn.hutool.core.util.ObjectUtil; 3 import cn.hutool.core.util.ObjectUtil;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 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 import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO; 10 import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO;
7 import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO; 11 import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO;
8 import org.mapstruct.Mapper; 12 import org.mapstruct.Mapper;
@@ -20,7 +24,7 @@ public interface SeckillActivityConvert { @@ -20,7 +24,7 @@ public interface SeckillActivityConvert {
20 24
21 SeckillActivityConvert INSTANCE = Mappers.getMapper(SeckillActivityConvert.class); 25 SeckillActivityConvert INSTANCE = Mappers.getMapper(SeckillActivityConvert.class);
22 26
23 - SeckillProductDO convert(SeckillActivityBaseVO.Product product); 27 + SeckillProductDO convert(SeckillProductCreateReqVO product);
24 28
25 SeckillActivityDO convert(SeckillActivityCreateReqVO bean); 29 SeckillActivityDO convert(SeckillActivityCreateReqVO bean);
26 30
@@ -42,12 +46,12 @@ public interface SeckillActivityConvert { @@ -42,12 +46,12 @@ public interface SeckillActivityConvert {
42 * @param productVO 前端传入的商品 46 * @param productVO 前端传入的商品
43 * @return 是否匹配 47 * @return 是否匹配
44 */ 48 */
45 - default boolean isEquals(SeckillProductDO productDO, SeckillActivityBaseVO.Product productVO) { 49 + default boolean isEquals(SeckillProductDO productDO, SeckillProductCreateReqVO productVO) {
46 return ObjectUtil.equals(productDO.getSpuId(), productVO.getSpuId()) 50 return ObjectUtil.equals(productDO.getSpuId(), productVO.getSpuId())
47 && ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId()) 51 && ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId())
48 && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice()); 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,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; 5 import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
6 import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO; 6 import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO;
7 import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; 7 import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi;
  8 +import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
8 import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi; 9 import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi;
9 import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; 10 import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
10 import cn.iocoder.yudao.module.trade.controller.app.order.vo.*; 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,6 +36,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
35 import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; 36 import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
36 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; 37 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
37 import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_ITEM_NOT_FOUND; 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 @Tag(name = "用户 App - 交易订单") 41 @Tag(name = "用户 App - 交易订单")
40 @RestController 42 @RestController
@@ -138,16 +140,20 @@ public class AppTradeOrderController { @@ -138,16 +140,20 @@ public class AppTradeOrderController {
138 @PostMapping("/item/create-comment") 140 @PostMapping("/item/create-comment")
139 @Operation(summary = "创建交易订单项的评价") 141 @Operation(summary = "创建交易订单项的评价")
140 public CommonResult<Long> createOrderItemComment(@RequestBody AppTradeOrderItemCommentCreateReqVO createReqVO) { 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 throw exception(ORDER_ITEM_NOT_FOUND); 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,7 +21,7 @@ public class AppTradeOrderSettlementReqVO {
21 @Deprecated // TODO 芋艿:后续干掉这个字段,对于前端不需要关注这个 21 @Deprecated // TODO 芋艿:后续干掉这个字段,对于前端不需要关注这个
22 private Integer type; 22 private Integer type;
23 23
24 - @Schema(description = "商品项数组", required = true) 24 + @Schema(description = "商品项数组", requiredMode = Schema.RequiredMode.REQUIRED)
25 @NotNull(message = "商品不能为空") 25 @NotNull(message = "商品不能为空")
26 private List<Item> items; 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,13 +12,13 @@ import java.util.List;
12 @Data 12 @Data
13 public class AppTradeOrderSettlementRespVO { 13 public class AppTradeOrderSettlementRespVO {
14 14
15 - @Schema(description = "购物项数组", required = true) 15 + @Schema(description = "购物项数组", requiredMode = Schema.RequiredMode.REQUIRED)
16 private List<Item> items; 16 private List<Item> items;
17 17
18 - @Schema(description = "费用", required = true) 18 + @Schema(description = "费用", requiredMode = Schema.RequiredMode.REQUIRED)
19 private Price price; 19 private Price price;
20 20
21 - @Schema(description = "收件地址", required = true) 21 + @Schema(description = "收件地址", requiredMode = Schema.RequiredMode.REQUIRED)
22 private Address address; 22 private Address address;
23 23
24 @Schema(description = "购物项") 24 @Schema(description = "购物项")
@@ -27,29 +27,29 @@ public class AppTradeOrderSettlementRespVO { @@ -27,29 +27,29 @@ public class AppTradeOrderSettlementRespVO {
27 27
28 // ========== SPU 信息 ========== 28 // ========== SPU 信息 ==========
29 29
30 - @Schema(description = "SPU 编号", required = true, example = "2048") 30 + @Schema(description = "SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
31 private Long spuId; 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 private String spuName; 33 private String spuName;
34 34
35 // ========== SKU 信息 ========== 35 // ========== SKU 信息 ==========
36 36
37 - @Schema(description = "SKU 编号", required = true, example = "1024") 37 + @Schema(description = "SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
38 private Integer skuId; 38 private Integer skuId;
39 - @Schema(description = "价格,单位:分", required = true, example = "100") 39 + @Schema(description = "价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
40 private Integer price; 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 private String picUrl; 42 private String picUrl;
43 43
44 - @Schema(description = "属性数组", required = true, example = "100") 44 + @Schema(description = "属性数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
45 private List<AppProductPropertyValueDetailRespVO> properties; 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 private Long cartId; 50 private Long cartId;
51 51
52 - @Schema(description = "购买数量", required = true, example = "1") 52 + @Schema(description = "购买数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
53 private Integer count; 53 private Integer count;
54 54
55 } 55 }
@@ -60,19 +60,19 @@ public class AppTradeOrderSettlementRespVO { @@ -60,19 +60,19 @@ public class AppTradeOrderSettlementRespVO {
60 @AllArgsConstructor 60 @AllArgsConstructor
61 public static class Price { 61 public static class Price {
62 62
63 - @Schema(description = "商品原价(总),单位:分", required = true, example = "500") 63 + @Schema(description = "商品原价(总),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "500")
64 private Integer totalPrice; 64 private Integer totalPrice;
65 65
66 - @Schema(description = "运费金额,单位:分", required = true, example = "50") 66 + @Schema(description = "运费金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
67 private Integer deliveryPrice; 67 private Integer deliveryPrice;
68 68
69 - @Schema(description = "优惠劵减免金额,单位:分", required = true, example = "100") 69 + @Schema(description = "优惠劵减免金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
70 private Integer couponPrice; 70 private Integer couponPrice;
71 71
72 - @Schema(description = "积分抵扣的金额,单位:分", required = true, example = "50") 72 + @Schema(description = "积分抵扣的金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
73 private Integer pointPrice; 73 private Integer pointPrice;
74 74
75 - @Schema(description = "实际支付金额(总),单位:分", required = true, example = "450") 75 + @Schema(description = "实际支付金额(总),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "450")
76 private Integer payPrice; 76 private Integer payPrice;
77 77
78 } 78 }
@@ -81,34 +81,34 @@ public class AppTradeOrderSettlementRespVO { @@ -81,34 +81,34 @@ public class AppTradeOrderSettlementRespVO {
81 @Data 81 @Data
82 public static class Address { 82 public static class Address {
83 83
84 - @Schema(description = "编号", required = true, example = "1") 84 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
85 private Long id; 85 private Long id;
86 86
87 - @Schema(description = "收件人名称", required = true, example = "小王") 87 + @Schema(description = "收件人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小王")
88 private String name; 88 private String name;
89 89
90 - @Schema(description = "手机号", required = true, example = "15601691300") 90 + @Schema(description = "手机号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15601691300")
91 private String mobile; 91 private String mobile;
92 92
93 - @Schema(description = "省份编号", required = true, example = "1") 93 + @Schema(description = "省份编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
94 private Integer provinceId; 94 private Integer provinceId;
95 - @Schema(description = "省份名字", required = true, example = "北京") 95 + @Schema(description = "省份名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "北京")
96 private String provinceName; 96 private String provinceName;
97 97
98 - @Schema(description = "城市编号", required = true, example = "1") 98 + @Schema(description = "城市编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
99 private Integer cityId; 99 private Integer cityId;
100 - @Schema(description = "城市名字", required = true, example = "北京") 100 + @Schema(description = "城市名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "北京")
101 private String cityName; 101 private String cityName;
102 102
103 - @Schema(description = "地区编号", required = true, example = "1") 103 + @Schema(description = "地区编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
104 private Integer districtId; 104 private Integer districtId;
105 - @Schema(description = "地区名字", required = true, example = "朝阳区") 105 + @Schema(description = "地区名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "朝阳区")
106 private String districtName; 106 private String districtName;
107 107
108 - @Schema(description = "详细地址", required = true, example = "望京悠乐汇 A 座") 108 + @Schema(description = "详细地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "望京悠乐汇 A 座")
109 private String detailAddress; 109 private String detailAddress;
110 110
111 - @Schema(description = "是否默认收件地址", required = true, example = "true") 111 + @Schema(description = "是否默认收件地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
112 private Boolean defaulted; 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,59 +11,33 @@ import java.util.List;
11 @Data 11 @Data
12 public class AppTradeOrderItemCommentCreateReqVO { 12 public class AppTradeOrderItemCommentCreateReqVO {
13 13
14 - @Schema(description = "是否匿名", required = true, example = "true") 14 + @Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
15 @NotNull(message = "是否匿名不能为空") 15 @NotNull(message = "是否匿名不能为空")
16 private Boolean anonymous; 16 private Boolean anonymous;
17 17
18 - @Schema(description = "交易订单项编号", required = true, example = "2312312") 18 + @Schema(description = "交易订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2312312")
19 @NotNull(message = "交易订单项编号不能为空") 19 @NotNull(message = "交易订单项编号不能为空")
20 private Long orderItemId; 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 @NotNull(message = "评分星级 1-5 分不能为空") 23 @NotNull(message = "评分星级 1-5 分不能为空")
37 private Integer scores; 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 @NotNull(message = "描述星级 1-5 分不能为空") 27 @NotNull(message = "描述星级 1-5 分不能为空")
41 private Integer descriptionScores; 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 @NotNull(message = "服务星级 1-5 分不能为空") 31 @NotNull(message = "服务星级 1-5 分不能为空")
45 private Integer benefitScores; 32 private Integer benefitScores;
46 33
47 - @Schema(description = "评论内容", required = true, example = "穿身上很漂亮诶(*^▽^*)") 34 + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿身上很漂亮诶(*^▽^*)")
48 @NotNull(message = "评论内容不能为空") 35 @NotNull(message = "评论内容不能为空")
49 private String content; 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 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张") 39 @Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
53 private List<String> picUrls; 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,15 +10,15 @@ import java.util.List;
10 @Data 10 @Data
11 public class AppTradeOrderItemRespVO { 11 public class AppTradeOrderItemRespVO {
12 12
13 - @Schema(description = "编号", required = true, example = "1") 13 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
14 private Long id; 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 private Long spuId; 17 private Long spuId;
18 - @Schema(description = "商品 SPU 名称", required = true, example = "芋道源码") 18 + @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
19 private String spuName; 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 private Long skuId; 22 private Long skuId;
23 23
24 /** 24 /**
@@ -26,18 +26,18 @@ public class AppTradeOrderItemRespVO { @@ -26,18 +26,18 @@ public class AppTradeOrderItemRespVO {
26 */ 26 */
27 private List<AppProductPropertyValueDetailRespVO> properties; 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 private String picUrl; 30 private String picUrl;
31 31
32 - @Schema(description = "购买数量", required = true, example = "1") 32 + @Schema(description = "购买数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
33 private Integer count; 33 private Integer count;
34 34
35 - @Schema(description = "是否评价", required = true, example = "true") 35 + @Schema(description = "是否评价", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
36 private Boolean commentStatus; 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 private Integer price; 41 private Integer price;
42 42
43 // ========== 营销基本信息 ========== 43 // ========== 营销基本信息 ==========
@@ -46,7 +46,7 @@ public class AppTradeOrderItemRespVO { @@ -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 private Integer afterSaleStatus; 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,7 +259,17 @@ public interface TradeOrderConvert {
259 259
260 AppTradeOrderItemRespVO convert03(TradeOrderItemDO bean); 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 default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO, 274 default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO,
265 List<TradeCartDO> cartList) { 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 package cn.iocoder.yudao.module.trade.dal.mysql.order; 1 package cn.iocoder.yudao.module.trade.dal.mysql.order;
2 2
3 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 3 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  4 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
4 import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; 5 import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
5 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; 6 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
6 import org.apache.ibatis.annotations.Mapper; 7 import org.apache.ibatis.annotations.Mapper;
@@ -24,4 +25,9 @@ public interface TradeOrderItemMapper extends BaseMapperX&lt;TradeOrderItemDO&gt; { @@ -24,4 +25,9 @@ public interface TradeOrderItemMapper extends BaseMapperX&lt;TradeOrderItemDO&gt; {
24 return selectList(TradeOrderItemDO::getOrderId, orderIds); 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,4 +50,10 @@ public interface TradeOrderMapper extends BaseMapperX&lt;TradeOrderDO&gt; {
50 .eqIfPresent(TradeOrderDO::getStatus, status) 50 .eqIfPresent(TradeOrderDO::getStatus, status)
51 .eqIfPresent(TradeOrderDO::getCommentStatus, commentStatus)); 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,4 +160,21 @@ public interface TradeOrderService {
160 */ 160 */
161 List<TradeOrderItemDO> getOrderItemListByOrderId(Collection<Long> orderIds); 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,6 +565,16 @@ public class TradeOrderServiceImpl implements TradeOrderService {
565 return tradeOrderItemMapper.selectListByOrderId(orderIds); 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 *