From 20100aa78b95cd976ec8180a1a26d9ad1eca6d1c Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 12 Jun 2023 12:08:55 +0800 Subject: [PATCH] =?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 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 updateCommentVisible(@Valid @RequestBody ProductCommentUpdateVisibleReqVO updateReqVO) { @@ -48,7 +47,7 @@ public class ProductCommentController { @Operation(summary = "商家回复") @PreAuthorize("@ss.hasPermission('product:comment:update')") public CommonResult 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 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 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> 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> getCommentPage(@Valid Long spuId) { - return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE)); - } - - @PostMapping(value = "/create") - @Operation(summary = "创建商品评价") - public CommonResult 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> getCommentPage(@Valid AppCommentPageReqVO pageVO) { + PageResult 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 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 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 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 convertList(List list); PageResult convertPage(PageResult page); - PageResult convertPage02(PageResult pageResult); + PageResult convertPage02(PageResult 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 { // TODO 芋艿:在看看这块 static void appendTabQuery(LambdaQueryWrapperX 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 { 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() .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 queryWrapper = new LambdaQueryWrapperX() .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 getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); + PageResult 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 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 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 getCommentPageTabsCount(Long spuId, Boolean visible) { - Map 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 getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { - // TODO @puhui999:逻辑可以在 controller 做哈。让 service 简介一点;因为是 view 需要不展示昵称 - PageResult 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 getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { + return ProductCommentConvert.INSTANCE.convertPage02(productCommentMapper.selectPage(pageVO, visible)); + } + + @Override + public PageResult 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 result1 = productCommentService.getCommentPage(new AppCommentPageReqVO(), Boolean.TRUE); + PageResult result1 = productCommentService.getCommentPage(new AppCommentPageReqVO(), Boolean.TRUE); assertEquals(7, result1.getTotal()); // 测试获取所有商品分页中评数据 - PageResult result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); + PageResult result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); assertEquals(2, result2.getTotal()); // 测试获取指定 spuId 商品分页中评数据 - PageResult result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); + PageResult result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); assertEquals(2, result3.getTotal()); // 测试分页 tab count - Map 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> getOrderCount() { - Map orderCount = new HashMap<>(); + Map 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 createOrderItemComment() { - return success(0L); + public CommonResult 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 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 convertList(List list); default PayOrderCreateReqDTO convert(TradeOrderDO order, List 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 items); + ProductPropertyValueDetailRespVO convert(ProductPropertyValueDetailRespDTO bean); // TODO 芋艿:可简化 @@ -179,7 +185,9 @@ public interface TradeOrderConvert { orderVO.setUser(convert(user)); return orderVO; } + TradeOrderDetailRespVO convert2(TradeOrderDO order, List items); + MemberUserRespVO convert(MemberUserRespDTO bean); // TODO 芋艿:可简化 @@ -214,7 +222,9 @@ public interface TradeOrderConvert { }); return new PageResult<>(orderVOs, pageResult.getTotal()); } + AppTradeOrderPageItemRespVO convert02(TradeOrderDO order, List items); + AppProductPropertyValueDetailRespVO convert02(ProductPropertyValueDetailRespDTO bean); default AppTradeOrderDetailRespVO convert02(TradeOrderDO order, List orderItems, @@ -243,10 +253,13 @@ public interface TradeOrderConvert { orderVO.setReceiverAreaName(AreaUtils.format(order.getReceiverAreaId())); return orderVO; } + AppTradeOrderDetailRespVO convert3(TradeOrderDO order, List items); AppTradeOrderItemRespVO convert03(TradeOrderItemDO bean); + CommentCreateReqDTO convert04(AppTradeOrderItemCommentCreateReqVO createReqVO); + default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO, List cartList) { TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO(); @@ -286,6 +299,8 @@ public interface TradeOrderConvert { } return respVO; } + AppTradeOrderSettlementRespVO convert0(TradePriceCalculateRespBO calculate, AddressRespDTO address); + }