From 20100aa78b95cd976ec8180a1a26d9ad1eca6d1c Mon Sep 17 00:00:00 2001 From: puhui999 <puhui999@163.com> Date: Mon, 12 Jun 2023 12:08:55 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix=EF=BC=9A=E5=AE=8C=E5=96=84=E5=95=86?= =?UTF-8?q?=E5=93=81=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/comment/ProductCommentApi.java | 21 +++ .../api/comment/dto/CommentCreateReqDTO.java | 80 ++++++++++ .../api/comment/ProductCommentApiImpl.java | 28 ++++ .../comment/ProductCommentController.java | 8 +- .../comment/vo/ProductCommentBaseVO.java | 20 ++- .../comment/vo/ProductCommentCreateReqVO.java | 14 +- .../comment/vo/ProductCommentPageReqVO.java | 4 +- .../comment/vo/ProductCommentRespVO.java | 2 +- .../app/comment/AppCommentController.java | 60 -------- .../comment/AppProductCommentController.java | 52 +++++++ .../app/comment/vo/AppCommentPageReqVO.java | 36 +---- .../vo/AppCommentStatisticsRespVO.java | 29 ++++ ...seVO.java => AppProductCommentBaseVO.java} | 24 +-- ...java => AppProductCommentCreateReqVO.java} | 10 +- ...spVO.java => AppProductCommentRespVO.java} | 27 ++-- .../app/spu/AppProductSpuController.java | 3 - .../comment/ProductCommentConvert.java | 78 +++++----- .../dataobject/comment/ProductCommentDO.java | 5 + .../mysql/comment/ProductCommentMapper.java | 8 +- .../comment/ProductCommentService.java | 29 ++-- .../comment/ProductCommentServiceImpl.java | 141 +++++++++--------- .../ProductCommentServiceImplTest.java | 44 ++---- .../module/trade/api/order/TradeOrderApi.java | 11 +- .../trade/api/order/TradeOrderApiImpl.java | 16 +- .../app/order/AppTradeOrderController.java | 22 ++- .../AppTradeOrderItemCommentCreateReqVO.java | 71 +++++++++ .../convert/order/TradeOrderConvert.java | 19 ++- 27 files changed, 536 insertions(+), 326 deletions(-) create mode 100644 yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/comment/ProductCommentApi.java create mode 100644 yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/comment/dto/CommentCreateReqDTO.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/comment/ProductCommentApiImpl.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentStatisticsRespVO.java rename yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/{AppCommentBaseVO.java => AppProductCommentBaseVO.java} (76%) rename yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/{AppCommentCreateReqVO.java => AppProductCommentCreateReqVO.java} (68%) rename yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/{AppCommentRespVO.java => AppProductCommentRespVO.java} (59%) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/item/AppTradeOrderItemCommentCreateReqVO.java diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/comment/ProductCommentApi.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/comment/ProductCommentApi.java new file mode 100644 index 000000000..2daf87d0e --- /dev/null +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/comment/ProductCommentApi.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.product.api.comment; + +import cn.iocoder.yudao.module.product.api.comment.dto.CommentCreateReqDTO; + +/** + * 产品评论 API 接口 + * + * @author HUIHUI + */ +public interface ProductCommentApi { + + /** + * 创建评论 + * + * @param createReqDTO 评论参数 + * @param orderId 订单 id + * @return 返回评论创建后的 id + */ + Long createComment(CommentCreateReqDTO createReqDTO, Long orderId); + +} diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/comment/dto/CommentCreateReqDTO.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/comment/dto/CommentCreateReqDTO.java new file mode 100644 index 000000000..640d04784 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/comment/dto/CommentCreateReqDTO.java @@ -0,0 +1,80 @@ +package cn.iocoder.yudao.module.product.api.comment.dto; + +import lombok.Data; + +import java.util.List; + +/** + * 评论创建请求 DTO + * + * @author HUIHUI + */ +@Data +public class CommentCreateReqDTO { + + /** + * 是否匿名 + */ + private Boolean anonymous; + + /** + * 交易订单项编号 + */ + private Long orderItemId; + + /** + * 商品 SPU 编号 + */ + private Long spuId; + + /** + * 商品 SPU 名称 + */ + private String spuName; + + /** + * 商品 SKU 编号 + */ + private Long skuId; + + /** + * 评分星级 1-5 分 + */ + private Integer scores; + + /** + * 描述星级 1-5 分 + */ + private Integer descriptionScores; + + /** + * 服务星级 1-5 分 + */ + private Integer benefitScores; + + /** + * 评论内容 + */ + private String content; + + /** + * 评论图片地址数组,以逗号分隔最多上传9张 + */ + private List<String> picUrls; + + /** + * 评价人名称 + */ + private String userNickname; + + /** + * 评价人头像 + */ + private String userAvatar; + + /** + * 评价人 + */ + private Long userId; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/comment/ProductCommentApiImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/comment/ProductCommentApiImpl.java new file mode 100644 index 000000000..cd1145c66 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/comment/ProductCommentApiImpl.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.product.api.comment; + +import cn.iocoder.yudao.module.product.api.comment.dto.CommentCreateReqDTO; +import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; +import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; +import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; + +/** + * 商品评论 API 实现类 + * + * @author HUIHUI + */ +@Service +@Validated +public class ProductCommentApiImpl implements ProductCommentApi { + @Resource + private ProductCommentService productCommentService; + + @Override + public Long createComment(CommentCreateReqDTO createReqDTO, Long orderId) { + ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqDTO, orderId); + return productCommentService.createComment(commentDO); + } +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java index fb8f8fe34..6a8b12778 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java @@ -35,8 +35,7 @@ public class ProductCommentController { return success(ProductCommentConvert.INSTANCE.convertPage(pageResult)); } - // TODO @puhui999:update-visible - @PutMapping("/update/visible") + @PutMapping("/update-visible") @Operation(summary = "显示 / 隐藏评论") @PreAuthorize("@ss.hasPermission('product:comment:update')") public CommonResult<Boolean> updateCommentVisible(@Valid @RequestBody ProductCommentUpdateVisibleReqVO updateReqVO) { @@ -48,7 +47,7 @@ public class ProductCommentController { @Operation(summary = "商家回复") @PreAuthorize("@ss.hasPermission('product:comment:update')") public CommonResult<Boolean> commentReply(@Valid @RequestBody ProductCommentReplyVO replyVO) { - productCommentService.commentReply(replyVO, getLoginUserId()); + productCommentService.replyComment(replyVO, getLoginUserId()); return success(true); } @@ -56,8 +55,7 @@ public class ProductCommentController { @Operation(summary = "添加自评") @PreAuthorize("@ss.hasPermission('product:comment:update')") public CommonResult<Boolean> createComment(@Valid @RequestBody ProductCommentCreateReqVO createReqVO) { - // TODO @puhui999:不用 ProductCommentConvert.INSTANCE.convert(createReqVO) 哈;多写一个 create 方法即可; - productCommentService.createComment(ProductCommentConvert.INSTANCE.convert(createReqVO), Boolean.TRUE); + productCommentService.createComment(createReqVO); return success(true); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java index 775801bbc..b934298b7 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java @@ -10,17 +10,15 @@ import java.util.List; @Data public class ProductCommentBaseVO { - // TODO @puhui999:把 example 补充下 - - @Schema(description = "评价人名称", required = true, example = "张三") + @Schema(description = "评价人名称", required = true, example = "小姑凉") @NotNull(message = "评价人名称不能为空") private String userNickname; - @Schema(description = "评价人头像", required = true) + @Schema(description = "评价人头像", required = true, example = "https://www.iocoder.cn/xx.png") @NotNull(message = "评价人头像不能为空") private String userAvatar; - @Schema(description = "商品 SPU 编号", required = true, example = "29502") + @Schema(description = "商品 SPU 编号", required = true, example = "清凉丝滑透气小短袖") @NotNull(message = "商品 SPU 编号不能为空") private Long spuId; @@ -28,27 +26,27 @@ public class ProductCommentBaseVO { @NotNull(message = "商品 SPU 名称不能为空") private String spuName; - @Schema(description = "商品 SKU 编号", required = true, example = "3082") + @Schema(description = "商品 SKU 编号", required = true, example = "1") @NotNull(message = "商品 SKU 编号不能为空") private Long skuId; - @Schema(description = "评分星级 1-5分", required = true) + @Schema(description = "评分星级 1-5分", required = true, example = "5") @NotNull(message = "评分星级不能为空") private Integer scores; - @Schema(description = "描述星级 1-5分", required = true) + @Schema(description = "描述星级 1-5分", required = true, example = "5") @NotNull(message = "描述星级不能为空") private Integer descriptionScores; - @Schema(description = "服务星级 1-5分", required = true) + @Schema(description = "服务星级 1-5分", required = true, example = "5") @NotNull(message = "服务星级分不能为空") private Integer benefitScores; - @Schema(description = "评论内容", required = true) + @Schema(description = "评论内容", required = true, example = "穿起来非常丝滑凉快") @NotNull(message = "评论内容不能为空") private String content; - @Schema(description = "评论图片地址数组,以逗号分隔最多上传9张", required = true) + @Schema(description = "评论图片地址数组,以逗号分隔最多上传9张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]") @Size(max = 9, message = "评论图片地址数组长度不能超过9张") private List<String> picUrls; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentCreateReqVO.java index 8fd0e7099..1d325e03d 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentCreateReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentCreateReqVO.java @@ -1,7 +1,11 @@ package cn.iocoder.yudao.module.product.controller.admin.comment.vo; -import lombok.*; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotNull; @Schema(description = "管理后台 - 商品评价创建 Request VO") @Data @@ -9,4 +13,12 @@ import io.swagger.v3.oas.annotations.media.Schema; @ToString(callSuper = true) public class ProductCommentCreateReqVO extends ProductCommentBaseVO { + @Schema(description = "评价人", required = true, example = "16868") + @NotNull(message = "评价人不能为空") + private Long userId; + + @Schema(description = "评价订单项", required = true, example = "19292") + @NotNull(message = "评价订单项不能为空") + private Long orderItemId; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentPageReqVO.java index 5a90d1c20..f7da9b5d9 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentPageReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentPageReqVO.java @@ -31,11 +31,11 @@ public class ProductCommentPageReqVO extends PageParam { @Schema(description = "商品SPU名称", example = "感冒药") private String spuName; - @Schema(description = "评分星级 1-5分") + @Schema(description = "评分星级 1-5分", example = "5") @InEnum(ProductCommentScoresEnum.class) private Integer scores; - @Schema(description = "商家是否回复") + @Schema(description = "商家是否回复", example = "true") private Boolean replied; @Schema(description = "创建时间") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java index 400630afd..c9a06d476 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java @@ -16,7 +16,7 @@ public class ProductCommentRespVO extends ProductCommentBaseVO { @Schema(description = "订单项编号", required = true, example = "24965") private Long id; - @Schema(description = "是否匿名:[false:不匿名 true:匿名]", required = true) + @Schema(description = "是否匿名:[false:不匿名 true:匿名]", required = true, example = "false") private Boolean anonymous; @Schema(description = "交易订单编号", required = true, example = "24428") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java deleted file mode 100644 index 7d05161e7..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java +++ /dev/null @@ -1,60 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.app.comment; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.api.user.MemberUserApi; -import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentCreateReqVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; -import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; -import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import javax.annotation.Resource; -import javax.validation.Valid; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; - -// TODO @puhui999:AppCommentController =》 AppProductCommentController -@Tag(name = "用户 APP - 商品评价") -@RestController -@RequestMapping("/product/comment") -@Validated -public class AppCommentController { - - @Resource - private ProductCommentService productCommentService; - - @Resource - private MemberUserApi memberUserApi; - - @GetMapping("/page") - @Operation(summary = "获得商品评价分页") - public CommonResult<PageResult<AppCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) { - return success(productCommentService.getCommentPage(pageVO, Boolean.TRUE)); - } - - // TODO @puhui999:方法名改成 getCommentStatistics?然后搞个对应的 vo?想了下,这样更优雅 - @GetMapping("/get-count") - @Operation(summary = "获得商品的评价统计") // TODO @puhui999:@RequestParam 哈,针对 spuId - public CommonResult<Map<String, Long>> getCommentPage(@Valid Long spuId) { - return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE)); - } - - @PostMapping(value = "/create") - @Operation(summary = "创建商品评价") - public CommonResult<Boolean> createComment(@RequestBody AppCommentCreateReqVO createReqVO) { - // TODO: 2023/3/20 要不要判断订单、商品是否存在 - // TODO @ouhui999:这个接口,搞到交易那比较合适; - MemberUserRespDTO user = memberUserApi.getUser(getLoginUserId()); - productCommentService.createComment(ProductCommentConvert.INSTANCE.convert(user, createReqVO), Boolean.FALSE); - return success(true); - } - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java new file mode 100644 index 000000000..6921e6cbf --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.module.product.controller.app.comment; + +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; +import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; +import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "用户 APP - 商品评价") +@RestController +@RequestMapping("/product/comment") +@Validated +public class AppProductCommentController { + + @Resource + private ProductCommentService productCommentService; + + @GetMapping("/page") + @Operation(summary = "获得商品评价分页") + public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) { + PageResult<AppProductCommentRespVO> result = productCommentService.getCommentPage(pageVO, Boolean.TRUE); + result.getList().forEach(item -> { + // 判断用户是否选择匿名 + if (ObjectUtil.equal(item.getAnonymous(), true)) { + item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); + } + }); + return success(result); + } + + @GetMapping("/getCommentStatistics") + @Operation(summary = "获得商品的评价统计") + public CommonResult<AppCommentStatisticsRespVO> getCommentPage(@Valid @RequestParam("spuId") Long spuId) { + return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE)); + } + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java index d2bf4ef99..8799c5c75 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java @@ -14,55 +14,21 @@ import javax.validation.constraints.NotNull; @ToString(callSuper = true) public class AppCommentPageReqVO extends PageParam { - // TODO @puhui999:不传递就是 all; - /** - * 所有 - */ - public static final Integer ALL = 0; - - /** - * 所有数量 key - */ - public static final String ALL_COUNT = "allCount"; - - // TODO @puhui999:good 好评; /** * 好评 */ - public static final Integer FAVOURABLE_COMMENT = 1; - - // TODO @puhui999:medium 中评;然后 mediumCount 就好啦; - /** - * 好评数量 key - */ - public static final String FAVOURABLE_COMMENT_COUNT = "favourableCommentCount"; + public static final Integer GOOD_COMMENT = 1; /** * 中评 */ public static final Integer MEDIOCRE_COMMENT = 2; - /** - * 中评数量 key - */ - public static final String MEDIOCRE_COMMENT_COUNT = "mediocreCommentCount"; - /** * 差评 */ public static final Integer NEGATIVE_COMMENT = 3; - /** - * 差评数量 key - */ - public static final String NEGATIVE_COMMENT_COUNT = "negativeCommentCount"; - - // TODO @puhui999:这个挪到 DO 那没问题的哈;NICKNAME_ANONYMOUS - /** - * 默认匿名昵称 - */ - public static final String ANONYMOUS_NICKNAME = "匿名用户"; - @Schema(description = "商品SPU编号", example = "29502") @NotNull(message = "商品SPU编号不能为空") private Long spuId; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentStatisticsRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentStatisticsRespVO.java new file mode 100644 index 000000000..0687e5eea --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentStatisticsRespVO.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.product.controller.app.comment.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.ToString; + +/** + * APP 商品评价页评论分类数统计 Response VO + * + * @author HUIHUI + */ +@Schema(description = "APP - 商品评价页评论分类数统计 Response VO") +@Data +@ToString(callSuper = true) +public class AppCommentStatisticsRespVO { + + @Schema(description = "所有评论数量", required = true, example = "15721") + private Long allCount; + + @Schema(description = "好评数量", required = true, example = "15721") + private Long goodCount; + + @Schema(description = "中评数量", required = true, example = "15721") + private Long mediocreCount; + + @Schema(description = "差评数量", required = true, example = "15721") + private Long negativeCount; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentBaseVO.java similarity index 76% rename from yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentBaseVO.java rename to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentBaseVO.java index 2cbefad01..7173844ec 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentBaseVO.java @@ -7,39 +7,43 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.List; -// TODO @puhui999:把 Product 前缀给补下哈 +/** + * 商品评论 Base VO + * + * @author HUIHUI + */ @Data -public class AppCommentBaseVO { +public class AppProductCommentBaseVO { - @Schema(description = "商品SPU编号", required = true, example = "29502") + @Schema(description = "商品SPU编号", required = true, example = "91192") @NotNull(message = "商品SPU编号不能为空") private Long spuId; - @Schema(description = "商品SPU名称", required = true, example = "赵六") + @Schema(description = "商品SPU名称", required = true, example = "清凉丝滑小短袖") @NotNull(message = "商品SPU名称不能为空") private String spuName; - @Schema(description = "商品SKU编号", required = true, example = "3082") + @Schema(description = "商品SKU编号", required = true, example = "81192") @NotNull(message = "商品SKU编号不能为空") private Long skuId; - @Schema(description = "评分星级 1-5分", required = true) + @Schema(description = "评分星级 1-5分", required = true, example = "5") @NotNull(message = "评分星级 1-5分不能为空") private Integer scores; - @Schema(description = "描述星级 1-5分", required = true) + @Schema(description = "描述星级 1-5分", required = true, example = "5") @NotNull(message = "描述星级 1-5分不能为空") private Integer descriptionScores; - @Schema(description = "服务星级 1-5分", required = true) + @Schema(description = "服务星级 1-5分", required = true, example = "5") @NotNull(message = "服务星级 1-5分不能为空") private Integer benefitScores; - @Schema(description = "评论内容", required = true) + @Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评") @NotNull(message = "评论内容不能为空") private String content; - @Schema(description = "评论图片地址数组,以逗号分隔最多上传9张", required = true) + @Schema(description = "评论图片地址数组,以逗号分隔最多上传9张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]") @Size(max = 9, message = "评论图片地址数组长度不能超过9张") private List<String> picUrls; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java similarity index 68% rename from yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentCreateReqVO.java rename to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java index 6eb8e89e3..42cdc7e5b 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentCreateReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java @@ -7,23 +7,17 @@ import lombok.ToString; import javax.validation.constraints.NotNull; -// TODO @puhui999:不应该继承 AppCommentCreateReqVO +// TODO @puhui999:不应该继承 AppProductCommentCreateReqVO @Schema(description = "用户APP - 商品评价创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class AppCommentCreateReqVO extends AppCommentBaseVO { +public class AppProductCommentCreateReqVO extends AppProductCommentBaseVO { @Schema(description = "是否匿名", required = true, example = "true") @NotNull(message = "是否匿名不能为空") private Boolean anonymous; - // TODO @puhui999:不应该传递 orderId - - @Schema(description = "交易订单编号", required = true, example = "12312") - @NotNull(message = "交易订单编号不能为空") - private Long orderId; - @Schema(description = "交易订单项编号", required = true, example = "2312312") @NotNull(message = "交易订单项编号不能为空") private Long orderItemId; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java similarity index 59% rename from yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java rename to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java index 77c419b96..43a4096b0 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java @@ -4,17 +4,18 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; import java.util.List; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + @Schema(description = "用户APP - 商品评价 Response VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class AppCommentRespVO extends AppCommentBaseVO { - - // TODO puhui999:把 example 也补充下哈 +public class AppProductCommentRespVO extends AppProductCommentBaseVO { @Schema(description = "评价人的用户编号", required = true, example = "15721") private Long userId; @@ -22,13 +23,13 @@ public class AppCommentRespVO extends AppCommentBaseVO { @Schema(description = "评价人名称", required = true, example = "张三") private String userNickname; - @Schema(description = "评价人头像", required = true) + @Schema(description = "评价人头像", required = true, example = "https://www.iocoder.cn/xx.png") private String userAvatar; @Schema(description = "订单项编号", required = true, example = "24965") private Long id; - @Schema(description = "是否匿名", required = true) + @Schema(description = "是否匿名", required = true, example = "false") private Boolean anonymous; @Schema(description = "交易订单编号", required = true, example = "24428") @@ -37,31 +38,31 @@ public class AppCommentRespVO extends AppCommentBaseVO { @Schema(description = "交易订单项编号", required = true, example = "8233") private Long orderItemId; - @Schema(description = "商家是否回复", required = true) + @Schema(description = "商家是否回复", required = true, example = "true") private Boolean replyStatus; @Schema(description = "回复管理员编号", example = "22212") private Long replyUserId; - @Schema(description = "商家回复内容") + @Schema(description = "商家回复内容", example = "亲,你的好评就是我的动力(*^▽^*)") private String replyContent; @Schema(description = "商家回复时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime replyTime; - @Schema(description = "追加评价内容") + @Schema(description = "追加评价内容", example = "穿了很久都很丝滑诶") private String additionalContent; - @Schema(description = "追评评价图片地址数组,以逗号分隔最多上传9张") + @Schema(description = "追评评价图片地址数组,以逗号分隔最多上传9张", example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]") private List<String> additionalPicUrls; @Schema(description = "追加评价时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime additionalTime; - @Schema(description = "创建时间", required = true) + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime createTime; - @Schema(description = "最终评分", required = true) - private Integer finalScore; - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java index 693e8e911..3f3008176 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; -import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; import io.swagger.v3.oas.annotations.Operation; @@ -40,8 +39,6 @@ public class AppProductSpuController { private ProductSpuService productSpuService; @Resource private ProductSkuService productSkuService; - @Resource - private ProductPropertyValueService productPropertyValueService; @GetMapping("/page") @Operation(summary = "获得商品 SPU 分页") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java index 77f208214..ff895f491 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java @@ -1,15 +1,19 @@ package cn.iocoder.yudao.module.product.convert.comment; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.product.api.comment.dto.CommentCreateReqDTO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentCreateReqVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; import org.mapstruct.factory.Mappers; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.List; /** @@ -24,50 +28,42 @@ public interface ProductCommentConvert { ProductCommentRespVO convert(ProductCommentDO bean); + @Mapping(target = "allCount", source = "allCount") + @Mapping(target = "goodCount", source = "goodCount") + @Mapping(target = "mediocreCount", source = "mediocreCount") + @Mapping(target = "negativeCount", source = "negativeCount") + AppCommentStatisticsRespVO convert(Long allCount, Long goodCount, Long mediocreCount, Long negativeCount); + List<ProductCommentRespVO> convertList(List<ProductCommentDO> list); PageResult<ProductCommentRespVO> convertPage(PageResult<ProductCommentDO> page); - PageResult<AppCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult); + PageResult<AppProductCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult); - // TODO @puhui999:用 mapstruct 的映射 - default ProductCommentDO convert(MemberUserRespDTO user, AppCommentCreateReqVO createReqVO) { - ProductCommentDO productComment = new ProductCommentDO(); - productComment.setUserId(user.getId()); - productComment.setUserNickname(user.getNickname()); - productComment.setUserAvatar(user.getAvatar()); - productComment.setAnonymous(createReqVO.getAnonymous()); - productComment.setOrderId(createReqVO.getOrderId()); - productComment.setOrderItemId(createReqVO.getOrderItemId()); - productComment.setSpuId(createReqVO.getSpuId()); - productComment.setSpuName(createReqVO.getSpuName()); - productComment.setSkuId(createReqVO.getSkuId()); - productComment.setScores(createReqVO.getScores()); - productComment.setDescriptionScores(createReqVO.getDescriptionScores()); - productComment.setBenefitScores(createReqVO.getBenefitScores()); - productComment.setContent(createReqVO.getContent()); - productComment.setPicUrls(createReqVO.getPicUrls()); - return productComment; + /** + * 计算综合评分 + * + * @param descriptionScores 描述星级 + * @param benefitScores 服务星级 + * @return {@link Integer} + */ + @Named("convertScores") + default Integer convertScores(Integer descriptionScores, Integer benefitScores) { + // 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2 + BigDecimal sumScore = new BigDecimal(descriptionScores + benefitScores); + BigDecimal divide = sumScore.divide(BigDecimal.valueOf(2L), 0, RoundingMode.DOWN); + return divide.intValue(); } - // TODO @puhui999:用 mapstruct 的映射 - default ProductCommentDO convert(ProductCommentCreateReqVO createReq) { - ProductCommentDO productComment = new ProductCommentDO(); - productComment.setUserId(0L); - productComment.setUserNickname(createReq.getUserNickname()); - productComment.setUserAvatar(createReq.getUserAvatar()); - productComment.setAnonymous(Boolean.FALSE); - productComment.setOrderId(0L); - productComment.setOrderItemId(0L); - productComment.setSpuId(createReq.getSpuId()); - productComment.setSpuName(createReq.getSpuName()); - productComment.setSkuId(createReq.getSkuId()); - productComment.setScores(createReq.getScores()); - productComment.setDescriptionScores(createReq.getDescriptionScores()); - productComment.setBenefitScores(createReq.getBenefitScores()); - productComment.setContent(createReq.getContent()); - productComment.setPicUrls(createReq.getPicUrls()); - return productComment; - } + @Mapping(target = "orderId", source = "orderId") + @Mapping(target = "scores", expression = "java(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()))") + ProductCommentDO convert(CommentCreateReqDTO createReqDTO, Long orderId); + + @Mapping(target = "userId", constant = "0L") + @Mapping(target = "orderId", constant = "0L") + @Mapping(target = "orderItemId", constant = "0L") + @Mapping(target = "anonymous", expression = "java(Boolean.FALSE)") + @Mapping(target = "scores", expression = "java(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()))") + ProductCommentDO convert(ProductCommentCreateReqVO createReq); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java index cf7b47051..07e8fa5b6 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java @@ -28,6 +28,11 @@ import java.util.List; @AllArgsConstructor public class ProductCommentDO extends BaseDO { + /** + * 默认匿名昵称 + */ + public static final String NICKNAME_ANONYMOUS = "匿名用户"; + /** * 评论编号,主键自增 */ diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java index 796a790f4..13c0f47f7 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java @@ -31,7 +31,7 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> { // TODO 芋艿:在看看这块 static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> queryWrapper, Integer type) { // 构建好评查询语句:好评计算 (商品评分星级+服务评分星级) >= 8 - if (ObjectUtil.equal(type, AppCommentPageReqVO.FAVOURABLE_COMMENT)) { + if (ObjectUtil.equal(type, AppCommentPageReqVO.GOOD_COMMENT)) { queryWrapper.apply("(scores + benefit_scores) >= 8"); } // 构建中评查询语句:中评计算 (商品评分星级+服务评分星级) > 4 且 (商品评分星级+服务评分星级) < 8 @@ -72,16 +72,14 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> { update(null, lambdaUpdateWrapper); } - // TODO @puhui999:使用 select 替代 find - default ProductCommentDO findByUserIdAndOrderIdAndSpuId(Long userId, Long orderId, Long spuId) { + default ProductCommentDO selectByUserIdAndOrderIdAndSpuId(Long userId, Long orderId, Long spuId) { return selectOne(new LambdaQueryWrapperX<ProductCommentDO>() .eq(ProductCommentDO::getUserId, userId) .eq(ProductCommentDO::getOrderId, orderId) .eq(ProductCommentDO::getSpuId, spuId)); } - // TODO @puhui999:selectCountBySpuId 即可 - default Long selectTabCount(Long spuId, Boolean visible, Integer type) { + default Long selectCountBySpuId(Long spuId, Boolean visible, Integer type) { LambdaQueryWrapperX<ProductCommentDO> queryWrapper = new LambdaQueryWrapperX<ProductCommentDO>() .eqIfPresent(ProductCommentDO::getSpuId, spuId) .eqIfPresent(ProductCommentDO::getVisible, visible); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java index 7bf9ccb36..10592f7b9 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java @@ -1,17 +1,17 @@ package cn.iocoder.yudao.module.product.service.comment; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import java.util.Map; - /** * 商品评论 Service 接口 * @@ -37,13 +37,14 @@ public interface ProductCommentService { void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO); // TODO @puhui999:replyComment + /** * 商家回复 * * @param replyVO 商家回复 * @param loginUserId 管理后台商家登陆人 ID */ - void commentReply(ProductCommentReplyVO replyVO, Long loginUserId); + void replyComment(ProductCommentReplyVO replyVO, Long loginUserId); /** * 获得商品评价分页 @@ -52,15 +53,23 @@ public interface ProductCommentService { * @param visible 是否可见 * @return 商品评价分页 */ - PageResult<AppCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); + PageResult<AppProductCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); /** - * 创建商品评论 + * 创建商品评论 后台管理员创建评论使用 * - * @param productComment 创建实体 - * @param system 是否系统评价 + * @param createReqVO 商品评价创建 Request VO 对象 */ - void createComment(ProductCommentDO productComment, Boolean system); + void createComment(ProductCommentCreateReqVO createReqVO); + + /** + * 创建评论 + * 创建商品评论 APP 端创建商品评论使用 + * + * @param commentDO 评论对象 + * @return 返回评论 id + */ + Long createComment(ProductCommentDO commentDO); /** * 获得商品的评价统计 @@ -69,6 +78,6 @@ public interface ProductCommentService { * @param visible 是否可见 * @return 评价统计 */ - Map<String, Long> getCommentPageTabsCount(Long spuId, Boolean visible); + AppCommentStatisticsRespVO getCommentPageTabsCount(Long spuId, Boolean visible); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java index 1f1156e1c..6dc67beb8 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java @@ -1,31 +1,28 @@ package cn.iocoder.yudao.module.product.service.comment; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; -import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.HashMap; -import java.util.Map; +import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; /** * 商品评论 Service 实现类 @@ -46,94 +43,96 @@ public class ProductCommentServiceImpl implements ProductCommentService { private ProductSpuService productSpuService; @Override - public PageResult<ProductCommentDO> getCommentPage(ProductCommentPageReqVO pageReqVO) { - return productCommentMapper.selectPage(pageReqVO); - } - - @Override + @Transactional(rollbackFor = Exception.class) public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) { // 校验评论是否存在 - validateCommentExists(updateReqVO.getId()); + ProductCommentDO productCommentDO = validateCommentExists(updateReqVO.getId()); + productCommentDO.setVisible(updateReqVO.getVisible()); // 更新可见状态 - // TODO @puhui999:直接使用 update 操作 - productCommentMapper.updateCommentVisible(updateReqVO.getId(), updateReqVO.getVisible()); + productCommentMapper.updateById(productCommentDO); } @Override - public void commentReply(ProductCommentReplyVO replyVO, Long loginUserId) { + @Transactional(rollbackFor = Exception.class) + public void replyComment(ProductCommentReplyVO replyVO, Long loginUserId) { // 校验评论是否存在 - validateCommentExists(replyVO.getId()); + ProductCommentDO productCommentDO = validateCommentExists(replyVO.getId()); + productCommentDO.setReplyTime(LocalDateTime.now()); + productCommentDO.setReplyUserId(loginUserId); + productCommentDO.setReplyStatus(Boolean.TRUE); + productCommentDO.setReplyContent(replyVO.getReplyContent()); // 回复评论 - // TODO @puhui999:直接使用 update 操作 - productCommentMapper.commentReply(replyVO, loginUserId); + productCommentMapper.updateById(productCommentDO); } @Override - public Map<String, Long> getCommentPageTabsCount(Long spuId, Boolean visible) { - Map<String, Long> countMap = new HashMap<>(4); - // 查询商品 id = spuId 的所有评论数量 - countMap.put(AppCommentPageReqVO.ALL_COUNT, - productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.ALL)); - // 查询商品 id = spuId 的所有好评数量 - countMap.put(AppCommentPageReqVO.FAVOURABLE_COMMENT_COUNT, - productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.FAVOURABLE_COMMENT)); - // 查询商品 id = spuId 的所有中评数量 - countMap.put(AppCommentPageReqVO.MEDIOCRE_COMMENT_COUNT, - productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.MEDIOCRE_COMMENT)); - // 查询商品 id = spuId 的所有差评数量 - countMap.put(AppCommentPageReqVO.NEGATIVE_COMMENT_COUNT, - productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.NEGATIVE_COMMENT)); - return countMap; + @Transactional(rollbackFor = Exception.class) + public void createComment(ProductCommentCreateReqVO createReqVO) { + // 校验订单 + Long orderId = tradeOrderApi.validateOrder(createReqVO.getUserId(), createReqVO.getOrderItemId()); + // 校验评论 + validateComment(createReqVO.getSpuId(), createReqVO.getUserId(), orderId); + + ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO); + productCommentMapper.insert(commentDO); } @Override - public PageResult<AppCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { - // TODO @puhui999:逻辑可以在 controller 做哈。让 service 简介一点;因为是 view 需要不展示昵称 - PageResult<AppCommentRespVO> result = ProductCommentConvert.INSTANCE.convertPage02(productCommentMapper.selectPage(pageVO, visible)); - result.getList().forEach(item -> { - // 判断用户是否选择匿名 - if (ObjectUtil.equal(item.getAnonymous(), true)) { - item.setUserNickname(AppCommentPageReqVO.ANONYMOUS_NICKNAME); - } - // TODO @puhui999:直接插入的时候,计算到 scores 字段里;这样就去掉 finalScore 字段哈 - // 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2 - BigDecimal sumScore = new BigDecimal(item.getScores() + item.getBenefitScores()); - BigDecimal divide = sumScore.divide(BigDecimal.valueOf(2L), 0, RoundingMode.DOWN); - item.setFinalScore(divide.intValue()); - }); - return result; + @Transactional(rollbackFor = Exception.class) + public Long createComment(ProductCommentDO commentDO) { + // 校验评论 + validateComment(commentDO.getSpuId(), commentDO.getUserId(), commentDO.getOrderId()); + + productCommentMapper.insert(commentDO); + return commentDO.getId(); } - @Override - public void createComment(ProductCommentDO productComment, Boolean system) { - // TODO @puhui999:这里不区分是否为 system;直接都校验 - if (!system) { - // TODO 判断订单是否存在 fix; - // TODO @puhui999:改成 order 那有个 comment 接口,哪里校验下;商品评论这里不校验订单是否存在哈 - TradeOrderRespDTO order = tradeOrderApi.getOrder(productComment.getOrderId()); - if (null == order) { - throw exception(ORDER_NOT_FOUND); - } - ProductSpuDO spu = productSpuService.getSpu(productComment.getSpuId()); - if (null == spu) { - throw exception(SPU_NOT_EXISTS); - } - // 判断当前订单的当前商品用户是否评价过 - ProductCommentDO exist = productCommentMapper.findByUserIdAndOrderIdAndSpuId(productComment.getId(), productComment.getOrderId(), productComment.getSpuId()); - if (null != exist) { - throw exception(ORDER_SPU_COMMENT_EXISTS); - } + // TODO 只有创建和更新诶 要不要删除接口 + + private void validateComment(Long spuId, Long userId, Long orderId) { + ProductSpuDO spu = productSpuService.getSpu(spuId); + if (null == spu) { + throw exception(SPU_NOT_EXISTS); + } + // 判断当前订单的当前商品用户是否评价过 + ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderIdAndSpuId(userId, orderId, spuId); + if (null != exist) { + throw exception(ORDER_SPU_COMMENT_EXISTS); } - productCommentMapper.insert(productComment); } - private void validateCommentExists(Long id) { + private ProductCommentDO validateCommentExists(Long id) { ProductCommentDO productComment = productCommentMapper.selectById(id); if (productComment == null) { throw exception(COMMENT_NOT_EXISTS); } + return productComment; + } + + @Override + public AppCommentStatisticsRespVO getCommentPageTabsCount(Long spuId, Boolean visible) { + return ProductCommentConvert.INSTANCE.convert( + // 查询商品 id = spuId 的所有评论数量 + productCommentMapper.selectCountBySpuId(spuId, visible, null), + // 查询商品 id = spuId 的所有好评数量 + productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.GOOD_COMMENT), + // 查询商品 id = spuId 的所有中评数量 + productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.MEDIOCRE_COMMENT), + // 查询商品 id = spuId 的所有差评数量 + productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.NEGATIVE_COMMENT) + ); + } + + @Override + public PageResult<AppProductCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { + return ProductCommentConvert.INSTANCE.convertPage02(productCommentMapper.selectPage(pageVO, visible)); + } + + @Override + public PageResult<ProductCommentDO> getCommentPage(ProductCommentPageReqVO pageReqVO) { + return productCommentMapper.selectPage(pageReqVO); } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java index 6754f3ba0..418562d03 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java @@ -4,14 +4,13 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.RandomUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; @@ -26,7 +25,6 @@ import org.springframework.context.annotation.Lazy; import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.Date; -import java.util.Map; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; @@ -93,12 +91,10 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { o.setSkuId(generateId()); o.setDescriptionScores(ProductCommentScoresEnum.FOUR.getScores()); o.setBenefitScores(ProductCommentScoresEnum.FOUR.getScores()); - o.setDeliveryScores(ProductCommentScoresEnum.FOUR.getScores()); o.setContent("真好吃"); o.setReplyUserId(generateId()); o.setReplyContent("确实"); o.setReplyTime(LocalDateTime.now()); - o.setAdditionalTime(LocalDateTime.now()); o.setCreateTime(LocalDateTime.now()); o.setUpdateTime(LocalDateTime.now()); }); @@ -139,23 +135,23 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { assertEquals(8, all.getTotal()); // 测试获取所有商品分页评论数据 - PageResult<AppCommentRespVO> result1 = productCommentService.getCommentPage(new AppCommentPageReqVO(), Boolean.TRUE); + PageResult<AppProductCommentRespVO> result1 = productCommentService.getCommentPage(new AppCommentPageReqVO(), Boolean.TRUE); assertEquals(7, result1.getTotal()); // 测试获取所有商品分页中评数据 - PageResult<AppCommentRespVO> result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); + PageResult<AppProductCommentRespVO> result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); assertEquals(2, result2.getTotal()); // 测试获取指定 spuId 商品分页中评数据 - PageResult<AppCommentRespVO> result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); + PageResult<AppProductCommentRespVO> result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); assertEquals(2, result3.getTotal()); // 测试分页 tab count - Map<String, Long> tabsCount = productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE); - assertEquals(6, tabsCount.get(AppCommentPageReqVO.ALL_COUNT)); - assertEquals(4, tabsCount.get(AppCommentPageReqVO.FAVOURABLE_COMMENT_COUNT)); - assertEquals(2, tabsCount.get(AppCommentPageReqVO.MEDIOCRE_COMMENT_COUNT)); - assertEquals(0, tabsCount.get(AppCommentPageReqVO.NEGATIVE_COMMENT_COUNT)); + AppCommentStatisticsRespVO tabsCount = productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE); + assertEquals(6, tabsCount.getAllCount()); + assertEquals(4, tabsCount.getGoodCount()); + assertEquals(2, tabsCount.getMediocreCount()); + assertEquals(0, tabsCount.getNegativeCount()); } @@ -190,7 +186,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { ProductCommentReplyVO replyVO = new ProductCommentReplyVO(); replyVO.setId(productCommentId); replyVO.setReplyContent("测试"); - productCommentService.commentReply(replyVO, 1L); + productCommentService.replyComment(replyVO, 1L); ProductCommentDO productCommentDO = productCommentMapper.selectById(productCommentId); assertEquals("测试", productCommentDO.getReplyContent()); @@ -199,24 +195,6 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { @Test public void testCreateComment_success() { // mock 测试 - ProductCommentDO productComment = randomPojo(ProductCommentDO.class, o -> { - o.setAdditionalContent(""); - }); - - productCommentService.createComment(productComment, Boolean.TRUE); - - MemberUserRespDTO user = new MemberUserRespDTO(); - user.setId(productComment.getUserId()); - - AppCommentAdditionalReqVO createReqVO = new AppCommentAdditionalReqVO(); - createReqVO.setId(productComment.getId()); - createReqVO.setAdditionalContent("追加"); - createReqVO.setAdditionalPicUrls(productComment.getAdditionalPicUrls()); - - productCommentService.additionalComment(user, createReqVO); - ProductCommentDO exist = productCommentMapper.selectById(productComment.getId()); - - assertEquals("追加", exist.getAdditionalContent()); } } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java index 8dc2aaced..5f98073d1 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java @@ -1,7 +1,5 @@ package cn.iocoder.yudao.module.trade.api.order; -import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; - /** * 订单 API 接口 * @@ -10,11 +8,12 @@ import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; public interface TradeOrderApi { /** - * 获取订单通过订单 id + * 验证订单 * - * @param id id - * @return 订单信息 Response DTO + * @param userId 用户 id + * @param orderItemId 订单项 id + * @return 校验通过返回订单 id */ - TradeOrderRespDTO getOrder(Long id); + Long validateOrder(Long userId, Long orderItemId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java index 3abdb2a9d..120b6d054 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java @@ -1,13 +1,15 @@ package cn.iocoder.yudao.module.trade.api.order; -import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; -import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_ITEM_NOT_FOUND; + /** * 订单 API 接口实现类 * @@ -21,8 +23,14 @@ public class TradeOrderApiImpl implements TradeOrderApi { private TradeOrderService tradeOrderService; @Override - public TradeOrderRespDTO getOrder(Long id) { - return TradeOrderConvert.INSTANCE.convert(tradeOrderService.getOrder(id)); + public Long validateOrder(Long userId, Long orderItemId) { + // 校验订单项,订单项存在订单就存在 + TradeOrderItemDO item = tradeOrderService.getOrderItem(userId, orderItemId); + if (item == null) { + throw exception(ORDER_ITEM_NOT_FOUND); + } + + return item.getOrderId(); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index e3008fdd6..112717f54 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -4,9 +4,11 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO; +import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.*; +import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemRespVO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; @@ -14,6 +16,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; +import com.google.common.collect.Maps; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -23,14 +26,15 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.HashMap; import java.util.List; import java.util.Map; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_ITEM_NOT_FOUND; @Tag(name = "用户 App - 交易订单") @RestController @@ -48,6 +52,9 @@ public class AppTradeOrderController { @Resource private TradeOrderProperties tradeOrderProperties; + @Resource + private ProductCommentApi productCommentApi; + @GetMapping("/settlement") @Operation(summary = "获得订单结算信息") @PreAuthenticated @@ -105,7 +112,7 @@ public class AppTradeOrderController { @GetMapping("/get-count") @Operation(summary = "获得交易订单数量") public CommonResult<Map<String, Long>> getOrderCount() { - Map<String, Long> orderCount = new HashMap<>(); + Map<String, Long> orderCount = Maps.newLinkedHashMapWithExpectedSize(5); // 全部 orderCount.put("allCount", tradeOrderService.getOrderCount(getLoginUserId(), null, null)); // 待付款(未支付) @@ -129,11 +136,16 @@ public class AppTradeOrderController { return success(TradeOrderConvert.INSTANCE.convert03(item)); } - // TODO 芋艿:待实现 @PostMapping("/item/create-comment") @Operation(summary = "创建交易订单项的评价") - public CommonResult<Long> createOrderItemComment() { - return success(0L); + public CommonResult<Long> createOrderItemComment(@RequestBody AppTradeOrderItemCommentCreateReqVO createReqVO) { + // 校验订单项,订单项存在订单就存在 + TradeOrderItemDO item = tradeOrderService.getOrderItem(createReqVO.getUserId(), createReqVO.getOrderItemId()); + if (item == null) { + throw exception(ORDER_ITEM_NOT_FOUND); + } + + return success(productCommentApi.createComment(TradeOrderConvert.INSTANCE.convert04(createReqVO), item.getOrderId())); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/item/AppTradeOrderItemCommentCreateReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/item/AppTradeOrderItemCommentCreateReqVO.java new file mode 100644 index 000000000..9fbec0625 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/item/AppTradeOrderItemCommentCreateReqVO.java @@ -0,0 +1,71 @@ +package cn.iocoder.yudao.module.trade.controller.app.order.vo.item; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.List; + +/** + * 商品评价创建 Request VO + * + * @author HUIHUI + */ +@Schema(description = "用户APP - 商品评价创建 Request VO") +@Data +public class AppTradeOrderItemCommentCreateReqVO { + + @Schema(description = "是否匿名", required = true, example = "true") + @NotNull(message = "是否匿名不能为空") + private Boolean anonymous; + + @Schema(description = "交易订单项编号", required = true, example = "2312312") + @NotNull(message = "交易订单项编号不能为空") + private Long orderItemId; + + @Schema(description = "商品SPU编号", required = true, example = "29502") + @NotNull(message = "商品SPU编号不能为空") + private Long spuId; + + @Schema(description = "商品SPU名称", required = true, example = "丝滑飘逸小短裙") + @NotNull(message = "商品SPU名称不能为空") + private String spuName; + + @Schema(description = "商品SKU编号", required = true, example = "3082") + @NotNull(message = "商品SKU编号不能为空") + private Long skuId; + + @Schema(description = "评分星级 1-5分", required = true, example = "5") + @NotNull(message = "评分星级 1-5分不能为空") + private Integer scores; + + @Schema(description = "描述星级 1-5分", required = true, example = "5") + @NotNull(message = "描述星级 1-5分不能为空") + private Integer descriptionScores; + + @Schema(description = "服务星级 1-5分", required = true, example = "5") + @NotNull(message = "服务星级 1-5分不能为空") + private Integer benefitScores; + + @Schema(description = "评论内容", required = true, example = "穿身上很漂亮诶(*^▽^*)") + @NotNull(message = "评论内容不能为空") + private String content; + + @Schema(description = "评论图片地址数组,以逗号分隔最多上传9张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xx.png]") + @Size(max = 9, message = "评论图片地址数组长度不能超过9张") + private List<String> picUrls; + + @Schema(description = "评价人名称", required = true, example = "小姑凉") + @NotNull(message = "评价人名称不能为空") + private String userNickname; + + @Schema(description = "评价人头像", required = true, example = "https://www.iocoder.cn/xx.png") + @NotNull(message = "评价人头像不能为空") + private String userAvatar; + + @Schema(description = "评价人", required = true, example = "16868") + @NotNull(message = "评价人不能为空") + private Long userId; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index 8c5501b53..6e81746a4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; +import cn.iocoder.yudao.module.product.api.comment.dto.CommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO; @@ -18,6 +19,7 @@ import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDetailR import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageItemRespVO; import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.*; +import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; @@ -75,9 +77,10 @@ public interface TradeOrderConvert { return orderItem; }); } + TradeOrderItemDO convert(TradePriceCalculateRespBO.OrderItem item); - @Mapping(source = "userId" , target = "userId") + @Mapping(source = "userId", target = "userId") PriceCalculateReqDTO convert(AppTradeOrderCreateReqVO createReqVO, Long userId); @Mappings({ @@ -85,6 +88,7 @@ public interface TradeOrderConvert { @Mapping(source = "count", target = "incrCount"), }) ProductSkuUpdateStockReqDTO.Item convert(TradeOrderItemDO bean); + List<ProductSkuUpdateStockReqDTO.Item> convertList(List<TradeOrderItemDO> list); default PayOrderCreateReqDTO convert(TradeOrderDO order, List<TradeOrderItemDO> orderItems, @@ -136,7 +140,7 @@ public interface TradeOrderConvert { properties.forEach(property -> { ProductPropertyValueDetailRespDTO propertyValueDetail = propertyValueDetailMap.get(property.getValueId()); if (propertyValueDetail == null) { - return; + return; } item.getProperties().add(convert(propertyValueDetail)); }); @@ -148,7 +152,9 @@ public interface TradeOrderConvert { }); return new PageResult<>(orderVOs, pageResult.getTotal()); } + TradeOrderPageItemRespVO convert(TradeOrderDO order, List<TradeOrderItemDO> items); + ProductPropertyValueDetailRespVO convert(ProductPropertyValueDetailRespDTO bean); // TODO 芋艿:可简化 @@ -179,7 +185,9 @@ public interface TradeOrderConvert { orderVO.setUser(convert(user)); return orderVO; } + TradeOrderDetailRespVO convert2(TradeOrderDO order, List<TradeOrderItemDO> items); + MemberUserRespVO convert(MemberUserRespDTO bean); // TODO 芋艿:可简化 @@ -214,7 +222,9 @@ public interface TradeOrderConvert { }); return new PageResult<>(orderVOs, pageResult.getTotal()); } + AppTradeOrderPageItemRespVO convert02(TradeOrderDO order, List<TradeOrderItemDO> items); + AppProductPropertyValueDetailRespVO convert02(ProductPropertyValueDetailRespDTO bean); default AppTradeOrderDetailRespVO convert02(TradeOrderDO order, List<TradeOrderItemDO> orderItems, @@ -243,10 +253,13 @@ public interface TradeOrderConvert { orderVO.setReceiverAreaName(AreaUtils.format(order.getReceiverAreaId())); return orderVO; } + AppTradeOrderDetailRespVO convert3(TradeOrderDO order, List<TradeOrderItemDO> items); AppTradeOrderItemRespVO convert03(TradeOrderItemDO bean); + CommentCreateReqDTO convert04(AppTradeOrderItemCommentCreateReqVO createReqVO); + default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO, List<TradeCartDO> cartList) { TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO(); @@ -286,6 +299,8 @@ public interface TradeOrderConvert { } return respVO; } + AppTradeOrderSettlementRespVO convert0(TradePriceCalculateRespBO calculate, AddressRespDTO address); + } From 9ff873fe53d7356b2552c9b756e268a29a00b266 Mon Sep 17 00:00:00 2001 From: puhui999 <puhui999@163.com> Date: Mon, 12 Jun 2023 12:09:16 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix=EF=BC=9A=E5=AE=8C=E5=96=84=E5=95=86?= =?UTF-8?q?=E5=93=81=E8=AF=84=E8=AE=BA=E6=B5=8B=E8=AF=95=20sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/resources/sql/create_tables.sql | 109 +++++++++++++----- 1 file changed, 77 insertions(+), 32 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql index 983aee740..e9fa0f6ce 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql @@ -126,36 +126,81 @@ CREATE TABLE IF NOT EXISTS `product_property_value` ( PRIMARY KEY("id") ) COMMENT '规格值'; -CREATE TABLE IF NOT EXISTS `product_comment` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '评价编号', - `user_id` bigint NOT NULL COMMENT ' 评价ID 用户编号', - `user_nickname` varchar(128) NOT NULL COMMENT '评价人名称', - `user_avatar` varchar(255) NOT NULL COMMENT '评价人头像', - `anonymous` bit(1) NOT NULL DEFAULT 0 COMMENT '是否匿名 0:不匿名 1:匿名', - `order_id` bigint NOT NULL COMMENT '交易订单编号', - `order_item_id` bigint NOT NULL COMMENT '交易订单项编号', - `spu_id` bigint NOT NULL COMMENT '商品SPU编号', - `spu_name` varchar NOT NULL COMMENT '商品SPU名称', - `sku_id` bigint NOT NULL COMMENT '商品SKU编号', - `visible` bit(1) NOT NULL DEFAULT 1 COMMENT '是否可见 true:显示 false:隐藏', - `scores` int NOT NULL COMMENT '评分星级 1-5分', - `description_scores` int NOT NULL COMMENT '描述星级 1-5分', - `benefit_scores` int NOT NULL COMMENT '服务星级 1-5分', - `delivery_scores` int NOT NULL COMMENT '配送星级 1-5分', - `content` varchar(2000) NOT NULL COMMENT '评论内容', - `pic_urls` varchar(1024) DEFAULT '' COMMENT '评论图片地址数组,以逗号分隔最多上传9张', - `replied` bit(1) NOT NULL DEFAULT 0 COMMENT '商家是否回复 1:回复 0:未回复', - `reply_user_id` bigint COMMENT '回复管理员编号', - `reply_content` varchar(2000) COMMENT '商家回复内容', - `reply_time` datetime COMMENT '商家回复时间', - `additional_content` varchar(2000) COMMENT '追加评价内容', - `additional_pic_urls` varchar(1024) COMMENT '追评评价图片地址数组,以逗号分隔最多上传9张', - `additional_time` datetime COMMENT '追加评价时间', - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, +CREATE TABLE IF NOT EXISTS `product_comment` +( + `id` + bigint + NOT + NULL + AUTO_INCREMENT + COMMENT + '评论编号,主键自增', + `user_id` + bigint + DEFAULT + NULL + COMMENT + '评价人的用户编号关联 MemberUserDO 的 id 编号', + `user_nickname` + varchar +( + 255 +) DEFAULT NULL COMMENT '评价人名称', + `user_avatar` varchar +( + 1024 +) DEFAULT NULL COMMENT '评价人头像', + `anonymous` bit +( + 1 +) DEFAULT NULL COMMENT '是否匿名', + `order_id` bigint DEFAULT NULL COMMENT '交易订单编号关联 TradeOrderDO 的 id 编号', + `order_item_id` bigint DEFAULT NULL COMMENT '交易订单项编号关联 TradeOrderItemDO 的 id 编号', + `spu_id` bigint DEFAULT NULL COMMENT '商品 SPU 编号关联 ProductSpuDO 的 id', + `spu_name` varchar +( + 255 +) DEFAULT NULL COMMENT '商品 SPU 名称', + `sku_id` bigint DEFAULT NULL COMMENT '商品 SKU 编号关联 ProductSkuDO 的 id 编号', + `visible` bit +( + 1 +) DEFAULT NULL COMMENT '是否可见true:显示false:隐藏', + `scores` tinyint DEFAULT NULL COMMENT '评分星级1-5分', + `description_scores` tinyint DEFAULT NULL COMMENT '描述星级1-5 星', + `benefit_scores` tinyint DEFAULT NULL COMMENT '服务星级1-5 星', + `content` varchar +( + 1024 +) DEFAULT NULL COMMENT '评论内容', + `pic_urls` varchar +( + 4096 +) DEFAULT NULL COMMENT '评论图片地址数组', + `reply_status` bit +( + 1 +) DEFAULT NULL COMMENT '商家是否回复', + `reply_user_id` bigint DEFAULT NULL COMMENT '回复管理员编号关联 AdminUserDO 的 id 编号', + `reply_content` varchar +( + 1024 +) DEFAULT NULL COMMENT '商家回复内容', + `reply_time` datetime DEFAULT NULL COMMENT '商家回复时间', + `creator` varchar +( + 64 +) DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar +( + 64 +) DEFAULT '' COMMENT '更新者', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY (`id`) -) COMMENT '商品评价'; \ No newline at end of file + "tenant_id" bigint not null default '0', + PRIMARY KEY +( + `id` +) + ) COMMENT '产品评论表'; From 60172274ecaa925236a73d63e4599f4fd014142f Mon Sep 17 00:00:00 2001 From: puhui999 <puhui999@163.com> Date: Mon, 12 Jun 2023 17:02:46 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix=EF=BC=9A=E5=90=88=E5=B9=B6=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=90=8E=E4=BF=AE=E6=94=B9=E5=B7=AE=E5=BC=82=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E5=95=86=E5=93=81=E8=AF=84=E8=AE=BA=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/ProductCommentController.java | 2 +- ...yVO.java => ProductCommentReplyReqVO.java} | 3 +- .../comment/AppProductCommentController.java | 78 ++++++++++++++++--- .../app/comment/vo/AppCommentPageReqVO.java | 5 ++ .../comment/vo/AppProductCommentBaseVO.java | 54 ------------- .../vo/AppProductCommentCreateReqVO.java | 44 ++++++++++- .../comment/vo/AppProductCommentRespVO.java | 51 +++++++++++- .../comment/ProductCommentConvert.java | 4 + .../mysql/comment/ProductCommentMapper.java | 21 ----- .../comment/ProductCommentService.java | 6 +- .../comment/ProductCommentServiceImpl.java | 40 +++++++++- .../ProductCommentServiceImplTest.java | 7 +- .../app/order/AppTradeOrderController.java | 2 + 13 files changed, 212 insertions(+), 105 deletions(-) rename yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/{ProductCommentReplyVO.java => ProductCommentReplyReqVO.java} (91%) delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentBaseVO.java diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java index 6a8b12778..91020a51c 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java @@ -46,7 +46,7 @@ public class ProductCommentController { @PutMapping("/reply") @Operation(summary = "商家回复") @PreAuthorize("@ss.hasPermission('product:comment:update')") - public CommonResult<Boolean> commentReply(@Valid @RequestBody ProductCommentReplyVO replyVO) { + public CommonResult<Boolean> commentReply(@Valid @RequestBody ProductCommentReplyReqVO replyVO) { productCommentService.replyComment(replyVO, getLoginUserId()); return success(true); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyReqVO.java similarity index 91% rename from yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyVO.java rename to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyReqVO.java index a935108dc..927f898cd 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyReqVO.java @@ -7,11 +7,10 @@ import lombok.ToString; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -// TODO @puhui999:ReqVO @Schema(description = "管理后台 - 商品评价可见修改 Request VO") @Data @ToString(callSuper = true) -public class ProductCommentReplyVO { +public class ProductCommentReplyReqVO { @Schema(description = "评价编号", required = true, example = "15721") @NotNull(message = "评价编号不能为空") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java index 6921e6cbf..90a387c80 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java @@ -1,14 +1,15 @@ package cn.iocoder.yudao.module.product.controller.app.comment; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; -import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; +import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -18,6 +19,11 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.validation.Valid; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -30,17 +36,69 @@ public class AppProductCommentController { @Resource private ProductCommentService productCommentService; + @GetMapping("/list") + @Operation(summary = "获得最近的 n 条商品评价") + @Parameters({ + @Parameter(name = "spuId", description = "商品 SPU 编号", required = true, example = "1024"), + @Parameter(name = "count", description = "数量", required = true, example = "10") + }) + public CommonResult<List<AppProductCommentRespVO>> getCommentList(@RequestParam("spuId") Long spuId, + @RequestParam(value = "count", defaultValue = "10") Integer count) { + + List<AppProductPropertyValueDetailRespVO> list = new ArrayList<>(); + + AppProductPropertyValueDetailRespVO item1 = new AppProductPropertyValueDetailRespVO(); + item1.setPropertyId(1L); + item1.setPropertyName("颜色"); + item1.setValueId(1024L); + item1.setValueName("红色"); + list.add(item1); + + AppProductPropertyValueDetailRespVO item2 = new AppProductPropertyValueDetailRespVO(); + item2.setPropertyId(2L); + item2.setPropertyName("尺寸"); + item2.setValueId(2048L); + item2.setValueName("大号"); + list.add(item2); + + AppProductPropertyValueDetailRespVO item3 = new AppProductPropertyValueDetailRespVO(); + item3.setPropertyId(3L); + item3.setPropertyName("重量"); + item3.setValueId(3072L); + item3.setValueName("500克"); + list.add(item3); + + // TODO 生成 mock 的数据 + AppProductCommentRespVO appCommentRespVO = new AppProductCommentRespVO(); + appCommentRespVO.setUserId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setUserNickname("用户" + new Random().nextInt(100)); + appCommentRespVO.setUserAvatar("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); + appCommentRespVO.setId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setAnonymous(new Random().nextBoolean()); + appCommentRespVO.setOrderId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setOrderItemId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setReplyStatus(new Random().nextBoolean()); + appCommentRespVO.setReplyUserId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setReplyContent("回复内容" + new Random().nextInt(100)); + appCommentRespVO.setReplyTime(LocalDateTime.now().minusDays(new Random().nextInt(30))); + appCommentRespVO.setCreateTime(LocalDateTime.now().minusDays(new Random().nextInt(30))); + appCommentRespVO.setSpuId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setSpuName("商品" + new Random().nextInt(100)); + appCommentRespVO.setSkuId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setSkuProperties(list); + appCommentRespVO.setScores(new Random().nextInt(5) + 1); + appCommentRespVO.setDescriptionScores(new Random().nextInt(5) + 1); + appCommentRespVO.setBenefitScores(new Random().nextInt(5) + 1); + appCommentRespVO.setContent("评论内容" + new Random().nextInt(100)); + appCommentRespVO.setPicUrls(Arrays.asList("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg")); + + return success(Arrays.asList(appCommentRespVO)); + } + @GetMapping("/page") @Operation(summary = "获得商品评价分页") public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) { - PageResult<AppProductCommentRespVO> result = productCommentService.getCommentPage(pageVO, Boolean.TRUE); - result.getList().forEach(item -> { - // 判断用户是否选择匿名 - if (ObjectUtil.equal(item.getAnonymous(), true)) { - item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); - } - }); - return success(result); + return success(productCommentService.getCommentPage(pageVO, Boolean.TRUE)); } @GetMapping("/getCommentStatistics") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java index 8799c5c75..0e6ef98cc 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java @@ -8,6 +8,11 @@ import lombok.ToString; import javax.validation.constraints.NotNull; +/** + * 用户 APP - 商品评价分页 Request VO + * + * @author HUIHUI + */ @Schema(description = "用户APP - 商品评价分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentBaseVO.java deleted file mode 100644 index 8c989ef18..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentBaseVO.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.app.comment.vo; - -import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import java.util.List; - -/** - * 商品评论 Base VO - * - * @author HUIHUI - */ -@Data -public class AppProductCommentBaseVO { - - @Schema(description = "商品SPU编号", required = true, example = "91192") - @NotNull(message = "商品SPU编号不能为空") - private Long spuId; - - @Schema(description = "商品SPU名称", required = true, example = "清凉丝滑小短袖") - @NotNull(message = "商品SPU名称不能为空") - private String spuName; - - @Schema(description = "商品SKU编号", required = true, example = "81192") - @NotNull(message = "商品SKU编号不能为空") - private Long skuId; - - @Schema(description = "商品 SKU 属性", required = true) - private List<AppProductPropertyValueDetailRespVO> skuProperties; // TODO puhui999:这个需要从数据库查询哈 - - @Schema(description = "评分星级 1-5分", required = true, example = "5") - @NotNull(message = "评分星级 1-5分不能为空") - private Integer scores; - - @Schema(description = "描述星级 1-5分", required = true, example = "5") - @NotNull(message = "描述星级 1-5分不能为空") - private Integer descriptionScores; - - @Schema(description = "服务星级 1-5分", required = true, example = "5") - @NotNull(message = "服务星级 1-5分不能为空") - private Integer benefitScores; - - @Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评") - @NotNull(message = "评论内容不能为空") - private String content; - - @Schema(description = "评论图片地址数组,以逗号分隔最多上传9张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]") - @Size(max = 9, message = "评论图片地址数组长度不能超过9张") - private List<String> picUrls; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java index 42cdc7e5b..53e797447 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java @@ -2,17 +2,21 @@ package cn.iocoder.yudao.module.product.controller.app.comment.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; import lombok.ToString; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.List; -// TODO @puhui999:不应该继承 AppProductCommentCreateReqVO +/** + * 用户APP - 商品评价创建 Request VO + * + * @author HUIHUI + */ @Schema(description = "用户APP - 商品评价创建 Request VO") @Data -@EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class AppProductCommentCreateReqVO extends AppProductCommentBaseVO { +public class AppProductCommentCreateReqVO { @Schema(description = "是否匿名", required = true, example = "true") @NotNull(message = "是否匿名不能为空") @@ -22,4 +26,36 @@ public class AppProductCommentCreateReqVO extends AppProductCommentBaseVO { @NotNull(message = "交易订单项编号不能为空") private Long orderItemId; + @Schema(description = "商品SPU编号", required = true, example = "91192") + @NotNull(message = "商品SPU编号不能为空") + private Long spuId; + + @Schema(description = "商品SPU名称", required = true, example = "清凉丝滑小短袖") + @NotNull(message = "商品SPU名称不能为空") + private String spuName; + + @Schema(description = "商品SKU编号", required = true, example = "81192") + @NotNull(message = "商品SKU编号不能为空") + private Long skuId; + + @Schema(description = "评分星级 1-5分", required = true, example = "5") + @NotNull(message = "评分星级 1-5分不能为空") + private Integer scores; + + @Schema(description = "描述星级 1-5分", required = true, example = "5") + @NotNull(message = "描述星级 1-5分不能为空") + private Integer descriptionScores; + + @Schema(description = "服务星级 1-5分", required = true, example = "5") + @NotNull(message = "服务星级 1-5分不能为空") + private Integer benefitScores; + + @Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评") + @NotNull(message = "评论内容不能为空") + private String content; + + @Schema(description = "评论图片地址数组,以逗号分隔最多上传9张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]") + @Size(max = 9, message = "评论图片地址数组长度不能超过9张") + private List<String> picUrls; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java index 5fb8eb351..e78f996e1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java @@ -1,19 +1,27 @@ package cn.iocoder.yudao.module.product.controller.app.comment.vo; +import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; import lombok.ToString; import org.springframework.format.annotation.DateTimeFormat; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; import java.time.LocalDateTime; import java.util.List; -@Schema(description = "用户APP - 商品评价 Response VO") +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +/** + * 用户APP - 商品评价详情 Response VO + * + * @author HUIHUI + */ +@Schema(description = "用户APP - 商品评价详情 Response VO") @Data -@EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class AppProductCommentRespVO extends AppProductCommentBaseVO { +public class AppProductCommentRespVO { @Schema(description = "评价人的用户编号", required = true, example = "15721") private Long userId; @@ -63,4 +71,39 @@ public class AppProductCommentRespVO extends AppProductCommentBaseVO { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime createTime; + @Schema(description = "商品SPU编号", required = true, example = "91192") + @NotNull(message = "商品SPU编号不能为空") + private Long spuId; + + @Schema(description = "商品SPU名称", required = true, example = "清凉丝滑小短袖") + @NotNull(message = "商品SPU名称不能为空") + private String spuName; + + @Schema(description = "商品SKU编号", required = true, example = "81192") + @NotNull(message = "商品SKU编号不能为空") + private Long skuId; + + @Schema(description = "商品 SKU 属性", required = true) + private List<AppProductPropertyValueDetailRespVO> skuProperties; + + @Schema(description = "评分星级 1-5分", required = true, example = "5") + @NotNull(message = "评分星级 1-5分不能为空") + private Integer scores; + + @Schema(description = "描述星级 1-5分", required = true, example = "5") + @NotNull(message = "描述星级 1-5分不能为空") + private Integer descriptionScores; + + @Schema(description = "服务星级 1-5分", required = true, example = "5") + @NotNull(message = "服务星级 1-5分不能为空") + private Integer benefitScores; + + @Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评") + @NotNull(message = "评论内容不能为空") + private String content; + + @Schema(description = "评论图片地址数组,以逗号分隔最多上传9张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]") + @Size(max = 9, message = "评论图片地址数组长度不能超过9张") + private List<String> picUrls; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java index ff895f491..9ec7e5cb4 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java @@ -6,7 +6,9 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; +import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; @@ -36,6 +38,8 @@ public interface ProductCommentConvert { List<ProductCommentRespVO> convertList(List<ProductCommentDO> list); + List<AppProductPropertyValueDetailRespVO> convertList01(List<ProductSkuDO.Property> properties); + PageResult<ProductCommentRespVO> convertPage(PageResult<ProductCommentDO> page); PageResult<AppProductCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java index 13c0f47f7..f44c1e334 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java @@ -6,14 +6,10 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; -import java.time.LocalDateTime; - @Mapper public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> { @@ -55,23 +51,6 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> { return selectPage(reqVO, queryWrapper); } - default void updateCommentVisible(Long id, Boolean visible) { - LambdaUpdateWrapper<ProductCommentDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<ProductCommentDO>() - .set(ProductCommentDO::getVisible, visible) - .eq(ProductCommentDO::getId, id); - update(null, lambdaUpdateWrapper); - } - - default void commentReply(ProductCommentReplyVO replyVO, Long loginUserId) { - LambdaUpdateWrapper<ProductCommentDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<ProductCommentDO>() - .set(ProductCommentDO::getReplyStatus, Boolean.TRUE) - .set(ProductCommentDO::getReplyTime, LocalDateTime.now()) - .set(ProductCommentDO::getReplyUserId, loginUserId) - .set(ProductCommentDO::getReplyContent, replyVO.getReplyContent()) - .eq(ProductCommentDO::getId, replyVO.getId()); - update(null, lambdaUpdateWrapper); - } - default ProductCommentDO selectByUserIdAndOrderIdAndSpuId(Long userId, Long orderId, Long spuId) { return selectOne(new LambdaQueryWrapperX<ProductCommentDO>() .eq(ProductCommentDO::getUserId, userId) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java index 10592f7b9..c6841770a 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.product.service.comment; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; +import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; @@ -36,15 +36,13 @@ public interface ProductCommentService { */ void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO); - // TODO @puhui999:replyComment - /** * 商家回复 * * @param replyVO 商家回复 * @param loginUserId 管理后台商家登陆人 ID */ - void replyComment(ProductCommentReplyVO replyVO, Long loginUserId); + void replyComment(ProductCommentReplyReqVO replyVO, Long loginUserId); /** * 获得商品评价分页 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java index 6dc67beb8..05d38899c 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java @@ -1,25 +1,36 @@ package cn.iocoder.yudao.module.product.service.comment; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; +import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; +import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; +import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; @@ -42,6 +53,10 @@ public class ProductCommentServiceImpl implements ProductCommentService { @Resource private ProductSpuService productSpuService; + @Resource + @Lazy + private ProductSkuService productSkuService; + @Override @Transactional(rollbackFor = Exception.class) public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) { @@ -55,7 +70,7 @@ public class ProductCommentServiceImpl implements ProductCommentService { @Override @Transactional(rollbackFor = Exception.class) - public void replyComment(ProductCommentReplyVO replyVO, Long loginUserId) { + public void replyComment(ProductCommentReplyReqVO replyVO, Long loginUserId) { // 校验评论是否存在 ProductCommentDO productCommentDO = validateCommentExists(replyVO.getId()); productCommentDO.setReplyTime(LocalDateTime.now()); @@ -127,7 +142,26 @@ public class ProductCommentServiceImpl implements ProductCommentService { @Override public PageResult<AppProductCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { - return ProductCommentConvert.INSTANCE.convertPage02(productCommentMapper.selectPage(pageVO, visible)); + PageResult<AppProductCommentRespVO> result = ProductCommentConvert.INSTANCE.convertPage02( + productCommentMapper.selectPage(pageVO, visible)); + Set<Long> skuIds = result.getList().stream().map(AppProductCommentRespVO::getSkuId).collect(Collectors.toSet()); + List<ProductSkuDO> skuList = productSkuService.getSkuList(skuIds); + Map<Long, ProductSkuDO> skuDOMap = new HashMap<>(skuIds.size()); + if (CollUtil.isNotEmpty(skuList)) { + skuDOMap.putAll(skuList.stream().collect(Collectors.toMap(ProductSkuDO::getId, c -> c))); + } + result.getList().forEach(item -> { + // 判断用户是否选择匿名 + if (ObjectUtil.equal(item.getAnonymous(), true)) { + item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); + } + ProductSkuDO productSkuDO = skuDOMap.get(item.getSkuId()); + if (productSkuDO != null) { + List<AppProductPropertyValueDetailRespVO> skuProperties = ProductCommentConvert.INSTANCE.convertList01(productSkuDO.getProperties()); + item.setSkuProperties(skuProperties); + } + }); + return result; } @Override diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java index 6e4419d4f..ad782bc51 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java @@ -5,7 +5,7 @@ import cn.hutool.core.util.RandomUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; +import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; @@ -15,6 +15,7 @@ import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; import cn.iocoder.yudao.module.product.enums.comment.ProductCommentScoresEnum; +import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; import org.junit.jupiter.api.Test; @@ -52,6 +53,8 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { private TradeOrderApi tradeOrderApi; @MockBean private ProductSpuService productSpuService; + @MockBean + private ProductSkuService productSkuService; public String generateNo() { return DateUtil.format(new Date(), "yyyyMMddHHmmss") + RandomUtil.randomInt(100000, 999999); @@ -183,7 +186,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { Long productCommentId = productComment.getId(); - ProductCommentReplyVO replyVO = new ProductCommentReplyVO(); + ProductCommentReplyReqVO replyVO = new ProductCommentReplyReqVO(); replyVO.setId(productCommentId); replyVO.setReplyContent("测试"); productCommentService.replyComment(replyVO, 1L); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index defc1cee7..d36c0f80a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -148,4 +148,6 @@ public class AppTradeOrderController { return success(productCommentApi.createComment(TradeOrderConvert.INSTANCE.convert04(createReqVO), item.getOrderId())); } + // TODO 合并代码后发现只有商家回复功能 用户追评不要了吗? + }