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..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 @@ -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) { @@ -47,8 +46,8 @@ public class ProductCommentController { @PutMapping("/reply") @Operation(summary = "商家回复") @PreAuthorize("@ss.hasPermission('product:comment:update')") - public CommonResult commentReply(@Valid @RequestBody ProductCommentReplyVO replyVO) { - productCommentService.commentReply(replyVO, getLoginUserId()); + public CommonResult commentReply(@Valid @RequestBody ProductCommentReplyReqVO replyVO) { + 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/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/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/AppProductCommentController.java similarity index 65% rename from yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java rename to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java index 3c9359412..90a387c80 100644 --- 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/AppProductCommentController.java @@ -1,52 +1,49 @@ package cn.iocoder.yudao.module.product.controller.app.comment; -import cn.hutool.core.map.MapUtil; 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.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.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.*; +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 java.time.LocalDateTime; -import java.util.*; +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; -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 { +public class AppProductCommentController { @Resource private ProductCommentService productCommentService; - @Resource - private MemberUserApi memberUserApi; - @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> getCommentList(@RequestParam("spuId") Long spuId, - @RequestParam(value = "count", defaultValue = "10") Integer count) { + public CommonResult> getCommentList(@RequestParam("spuId") Long spuId, + @RequestParam(value = "count", defaultValue = "10") Integer count) { List list = new ArrayList<>(); @@ -72,7 +69,7 @@ public class AppCommentController { list.add(item3); // TODO 生成 mock 的数据 - AppCommentRespVO appCommentRespVO = new AppCommentRespVO(); + 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"); @@ -85,7 +82,6 @@ public class AppCommentController { 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.setFinalScore(new Random().nextInt(5) + 1); appCommentRespVO.setSpuId((long) (new Random().nextInt(100000) + 10000)); appCommentRespVO.setSpuName("商品" + new Random().nextInt(100)); appCommentRespVO.setSkuId((long) (new Random().nextInt(100000) + 10000)); @@ -101,30 +97,14 @@ public class AppCommentController { @GetMapping("/page") @Operation(summary = "获得商品评价分页") - public CommonResult> getCommentPage(@Valid AppCommentPageReqVO pageVO) { + public CommonResult> getCommentPage(@Valid AppCommentPageReqVO pageVO) { return success(productCommentService.getCommentPage(pageVO, Boolean.TRUE)); } - // TODO @puhui999:方法名改成 getCommentStatistics?然后搞个对应的 vo?想了下,这样更优雅 - @GetMapping("/statistics") - @Operation(summary = "获得商品的评价统计") // TODO @puhui999:@RequestParam 哈,针对 spuId - public CommonResult> getCommentStatistics(@Valid Long spuId) { - // TODO 生成 mock 的数据 - if (true) { - return success(MapUtil.builder("allCount", 10L).put("goodPercent", "10.33").build()); - } - return null; -// 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); + @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/AppCommentCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentCreateReqVO.java deleted file mode 100644 index 6eb8e89e3..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentCreateReqVO.java +++ /dev/null @@ -1,31 +0,0 @@ -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; - -// TODO @puhui999:不应该继承 AppCommentCreateReqVO -@Schema(description = "用户APP - 商品评价创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class AppCommentCreateReqVO extends AppCommentBaseVO { - - @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/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..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,61 +8,32 @@ import lombok.ToString; import javax.validation.constraints.NotNull; +/** + * 用户 APP - 商品评价分页 Request VO + * + * @author HUIHUI + */ @Schema(description = "用户APP - 商品评价分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) @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/AppCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java deleted file mode 100644 index 69456030b..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java +++ /dev/null @@ -1,57 +0,0 @@ -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 java.time.LocalDateTime; - -@Schema(description = "用户APP - 商品评价 Response VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class AppCommentRespVO extends AppCommentBaseVO { - - // TODO puhui999:把 example 也补充下哈 - - @Schema(description = "评价人的用户编号", required = true, example = "15721") - private Long userId; - - @Schema(description = "评价人名称", required = true, example = "张三") - private String userNickname; - - @Schema(description = "评价人头像", required = true) - private String userAvatar; - - @Schema(description = "订单项编号", required = true, example = "24965") - private Long id; - - @Schema(description = "是否匿名", required = true) - private Boolean anonymous; - - @Schema(description = "交易订单编号", required = true, example = "24428") - private Long orderId; - - @Schema(description = "交易订单项编号", required = true, example = "8233") - private Long orderItemId; - - @Schema(description = "商家是否回复", required = true) - private Boolean replyStatus; - - @Schema(description = "回复管理员编号", example = "22212") - private Long replyUserId; - - @Schema(description = "商家回复内容") - private String replyContent; - - @Schema(description = "商家回复时间") - private LocalDateTime replyTime; - - @Schema(description = "创建时间", required = true) - 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/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/AppProductCommentCreateReqVO.java similarity index 60% 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/AppProductCommentCreateReqVO.java index 12910f25e..53e797447 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/AppProductCommentCreateReqVO.java @@ -1,49 +1,60 @@ 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.ToString; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.List; -// TODO @puhui999:C 端可以不要 base 哈。 +/** + * 用户APP - 商品评价创建 Request VO + * + * @author HUIHUI + */ +@Schema(description = "用户APP - 商品评价创建 Request VO") @Data -public class AppCommentBaseVO { +@ToString(callSuper = true) +public class AppProductCommentCreateReqVO { - @Schema(description = "商品SPU编号", required = true, example = "29502") + @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 = "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 = "商品 SKU 属性", required = true) - private List skuProperties; // TODO puhui999:这个需要从数据库查询哈 - - @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/AppProductCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java new file mode 100644 index 000000000..e78f996e1 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java @@ -0,0 +1,109 @@ +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.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; + +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 +@ToString(callSuper = true) +public class AppProductCommentRespVO { + + @Schema(description = "评价人的用户编号", required = true, example = "15721") + private Long userId; + + @Schema(description = "评价人名称", required = true, example = "张三") + private String userNickname; + + @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, example = "false") + private Boolean anonymous; + + @Schema(description = "交易订单编号", required = true, example = "24428") + private Long orderId; + + @Schema(description = "交易订单项编号", required = true, example = "8233") + private Long orderItemId; + + @Schema(description = "商家是否回复", required = true, example = "true") + private Boolean replyStatus; + + @Schema(description = "回复管理员编号", example = "22212") + private Long replyUserId; + + @Schema(description = "商家回复内容", example = "亲,你的好评就是我的动力(*^▽^*)") + private String replyContent; + + @Schema(description = "商家回复时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime replyTime; + + @Schema(description = "追加评价内容", example = "穿了很久都很丝滑诶") + private String additionalContent; + + @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 = "创建时间") + @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 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 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 77f208214..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 @@ -1,15 +1,21 @@ 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.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; import org.mapstruct.factory.Mappers; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.List; /** @@ -24,50 +30,44 @@ 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); + List convertList01(List properties); + 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 5082b2da9..f353d7761 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..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 { @@ -31,7 +27,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 @@ -55,33 +51,14 @@ public interface ProductCommentMapper extends BaseMapperX { return selectPage(reqVO, queryWrapper); } - default void updateCommentVisible(Long id, Boolean visible) { - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .set(ProductCommentDO::getVisible, visible) - .eq(ProductCommentDO::getId, id); - update(null, lambdaUpdateWrapper); - } - - default void commentReply(ProductCommentReplyVO replyVO, Long loginUserId) { - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .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); - } - - // 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..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 @@ -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.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.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 接口 * @@ -36,14 +36,13 @@ public interface ProductCommentService { */ void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO); - // TODO @puhui999:replyComment /** * 商家回复 * * @param replyVO 商家回复 * @param loginUserId 管理后台商家登陆人 ID */ - void commentReply(ProductCommentReplyVO replyVO, Long loginUserId); + void replyComment(ProductCommentReplyReqVO replyVO, Long loginUserId); /** * 获得商品评价分页 @@ -52,15 +51,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 +76,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..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,31 +1,39 @@ 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.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.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 cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; +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.math.BigDecimal; -import java.math.RoundingMode; +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.*; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; /** * 商品评论 Service 实现类 @@ -45,95 +53,120 @@ public class ProductCommentServiceImpl implements ProductCommentService { @Resource private ProductSpuService productSpuService; - @Override - public PageResult getCommentPage(ProductCommentPageReqVO pageReqVO) { - return productCommentMapper.selectPage(pageReqVO); - } + @Resource + @Lazy + private ProductSkuService productSkuService; @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(ProductCommentReplyReqVO 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)); + @Transactional(rollbackFor = Exception.class) + public Long createComment(ProductCommentDO commentDO) { + // 校验评论 + validateComment(commentDO.getSpuId(), commentDO.getUserId(), commentDO.getOrderId()); + + productCommentMapper.insert(commentDO); + return commentDO.getId(); + } + + // 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); + } + } + + 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) { + PageResult result = ProductCommentConvert.INSTANCE.convertPage02( + productCommentMapper.selectPage(pageVO, visible)); + Set skuIds = result.getList().stream().map(AppProductCommentRespVO::getSkuId).collect(Collectors.toSet()); + List skuList = productSkuService.getSkuList(skuIds); + Map 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(AppCommentPageReqVO.ANONYMOUS_NICKNAME); + item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); + } + ProductSkuDO productSkuDO = skuDOMap.get(item.getSkuId()); + if (productSkuDO != null) { + List skuProperties = ProductCommentConvert.INSTANCE.convertList01(productSkuDO.getProperties()); + item.setSkuProperties(skuProperties); } - // 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; } @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); - } - } - productCommentMapper.insert(productComment); - } - - private void validateCommentExists(Long id) { - ProductCommentDO productComment = productCommentMapper.selectById(id); - if (productComment == null) { - throw exception(COMMENT_NOT_EXISTS); - } + 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 520555141..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,15 +5,17 @@ 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; -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; 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; @@ -24,7 +26,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; @@ -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); @@ -135,23 +138,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()); } @@ -183,10 +186,10 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { Long productCommentId = productComment.getId(); - ProductCommentReplyVO replyVO = new ProductCommentReplyVO(); + ProductCommentReplyReqVO replyVO = new ProductCommentReplyReqVO(); replyVO.setId(productCommentId); replyVO.setReplyContent("测试"); - productCommentService.commentReply(replyVO, 1L); + productCommentService.replyComment(replyVO, 1L); ProductCommentDO productCommentDO = productCommentMapper.selectById(productCommentId); assertEquals("测试", productCommentDO.getReplyContent()); 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 '产品评论表'; 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 d680c9c15..2d7463cd4 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 @@ -5,9 +5,11 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; 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; @@ -15,6 +17,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; @@ -24,14 +27,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 @@ -49,6 +53,9 @@ public class AppTradeOrderController { @Resource private TradeOrderProperties tradeOrderProperties; + @Resource + private ProductCommentApi productCommentApi; + @GetMapping("/settlement") @Operation(summary = "获得订单结算信息") @PreAuthenticated @@ -106,7 +113,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)); // 待付款(未支付) @@ -130,11 +137,18 @@ 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())); } + // TODO 合并代码后发现只有商家回复功能 用户追评不要了吗? + } 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); + }