From 50f7be99767f647b267129f32fc3b7ebcbe04b27 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 14 Jan 2024 13:21:13 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20MALL=EF=BC=9A=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E5=95=86=E8=AF=84=E8=AE=BA=E7=9A=84=20VO=20=E8=BD=AC=E5=8C=96?= =?UTF-8?q?=EF=BC=8C=E5=8E=BB=E9=99=A4=E6=97=A0=E7=94=A8=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/ProductCommentController.java | 9 +- .../comment/vo/ProductCommentBaseVO.java | 47 ------- .../comment/vo/ProductCommentCreateReqVO.java | 45 ++++++- .../comment/vo/ProductCommentRespVO.java | 65 +++++---- .../comment/AppProductCommentController.java | 55 ++------ .../vo/AppCommentStatisticsRespVO.java | 24 ---- .../comment/vo/AppProductCommentRespVO.java | 3 +- .../comment/ProductCommentConvert.java | 123 ++++-------------- .../dal/dataobject/spu/ProductSpuDO.java | 7 - .../mysql/comment/ProductCommentMapper.java | 18 --- .../comment/ProductCommentService.java | 22 ---- .../comment/ProductCommentServiceImpl.java | 34 +---- 12 files changed, 133 insertions(+), 319 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java delete mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentStatisticsRespVO.java diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java index c28c28394..3cac6d068 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 @@ -2,19 +2,18 @@ package cn.iocoder.yudao.module.product.controller.admin.comment; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.*; -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 io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; -import jakarta.validation.Valid; - import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @@ -32,7 +31,7 @@ public class ProductCommentController { @PreAuthorize("@ss.hasPermission('product:comment:query')") public CommonResult> getCommentPage(@Valid ProductCommentPageReqVO pageVO) { PageResult pageResult = productCommentService.getCommentPage(pageVO); - return success(ProductCommentConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, ProductCommentRespVO.class)); } @PutMapping("/update-visible") 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 deleted file mode 100644 index a8394afab..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentBaseVO.java +++ /dev/null @@ -1,47 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.admin.comment.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import java.util.List; - -@Data -public class ProductCommentBaseVO { - - @Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868") - private Long userId; - - @Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292") - private Long orderItemId; - - @Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉") - @NotNull(message = "评价人名称不能为空") - private String userNickname; - - @Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png") - @NotNull(message = "评价人头像不能为空") - private String userAvatar; - - @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "商品 SKU 编号不能为空") - private Long skuId; - - @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") - @NotNull(message = "描述星级不能为空") - private Integer descriptionScores; - - @Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") - @NotNull(message = "服务星级分不能为空") - private Integer benefitScores; - - @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快") - @NotNull(message = "评论内容不能为空") - private String content; - - @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.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 f976b756d..b411db073 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,14 +1,49 @@ package cn.iocoder.yudao.module.product.controller.admin.comment.vo; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; + +import java.util.List; @Schema(description = "管理后台 - 商品评价创建 Request VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ProductCommentCreateReqVO extends ProductCommentBaseVO { +public class ProductCommentCreateReqVO { + + @Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868") + private Long userId; + + @Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292") + private Long orderItemId; + + @Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉") + @NotNull(message = "评价人名称不能为空") + private String userNickname; + + @Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png") + @NotNull(message = "评价人头像不能为空") + private String userAvatar; + + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "商品 SKU 编号不能为空") + private Long skuId; + + @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + @NotNull(message = "描述星级不能为空") + private Integer descriptionScores; + + @Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + @NotNull(message = "服务星级分不能为空") + private Integer benefitScores; + + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快") + @NotNull(message = "评论内容不能为空") + private String content; + + @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, + example = "[https://www.iocoder.cn/xx.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/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 00aa4aa76..605019a19 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 @@ -2,32 +2,68 @@ package cn.iocoder.yudao.module.product.controller.admin.comment.vo; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSkuSaveReqVO; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; import java.time.LocalDateTime; import java.util.List; @Schema(description = "管理后台 - 商品评价 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class ProductCommentRespVO extends ProductCommentBaseVO { +public class ProductCommentRespVO { @Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24965") private Long id; + @Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868") + private Long userId; + + @Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉") + private String userNickname; + + @Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png") + private String userAvatar; @Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "false") private Boolean anonymous; @Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428") private Long orderId; + @Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292") + private Long orderItemId; + + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖") + private Long spuId; + + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Long skuId; + + @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") + private String spuName; + + @Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg") + private String skuPicUrl; + + @Schema(description = "商品 SKU 规格值数组") + private List skuProperties; + @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED) private Boolean visible; + @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + private Integer scores; + + @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + private Integer descriptionScores; + + @Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") + private Integer benefitScores; + + @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快") + private String content; + + @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]") + private List picUrls; + @Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED) private Boolean replyStatus; @@ -43,21 +79,4 @@ public class ProductCommentRespVO extends ProductCommentBaseVO { @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; - @Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") - private Integer scores; - - @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖") - @NotNull(message = "商品 SPU 编号不能为空") - private Long spuId; - - @Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") - @NotNull(message = "商品 SPU 名称不能为空") - private String spuName; - - @Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg") - private String skuPicUrl; - - @Schema(description = "商品 SKU 规格值数组") - private List skuProperties; - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java index 0fadfeb93..cd9fac80e 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java @@ -3,31 +3,21 @@ package cn.iocoder.yudao.module.product.controller.app.comment; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 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.convert.comment.ProductCommentConvert; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; -import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; 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.context.annotation.Lazy; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; 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 jakarta.annotation.Resource; -import jakarta.validation.Valid; -import java.util.List; -import java.util.Set; - import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Tag(name = "用户 APP - 商品评价") @RestController @@ -38,43 +28,22 @@ public class AppProductCommentController { @Resource private ProductCommentService productCommentService; - @Resource - @Lazy - private ProductSkuService productSkuService; - - @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) { - return success(productCommentService.getCommentList(spuId, count)); - } - @GetMapping("/page") @Operation(summary = "获得商品评价分页") public CommonResult> getCommentPage(@Valid AppCommentPageReqVO pageVO) { // 查询评论分页 - PageResult commentPageResult = productCommentService.getCommentPage(pageVO, Boolean.TRUE); - if (CollUtil.isEmpty(commentPageResult.getList())) { - return success(PageResult.empty(commentPageResult.getTotal())); + PageResult pageResult = productCommentService.getCommentPage(pageVO, Boolean.TRUE); + if (CollUtil.isEmpty(pageResult.getList())) { + return success(PageResult.empty(pageResult.getTotal())); } // 拼接返回 - Set skuIds = convertSet(commentPageResult.getList(), ProductCommentDO::getSkuId); - PageResult commentVOPageResult = ProductCommentConvert.INSTANCE.convertPage02( - commentPageResult, productSkuService.getSkuList(skuIds)); - return success(commentVOPageResult); - } - - // TODO 芋艿:需要搞下 - @GetMapping("/statistics") - @Operation(summary = "获得商品的评价统计") - public CommonResult getCommentStatistics(@Valid @RequestParam("spuId") Long spuId) { - return success(productCommentService.getCommentStatistics(spuId, Boolean.TRUE)); + pageResult.getList().forEach(item -> { + if (Boolean.TRUE.equals(item.getAnonymous())) { + item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); + } + }); + return success(BeanUtils.toBean(pageResult, AppProductCommentRespVO.class)); } } 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 deleted file mode 100644 index e863ab02c..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentStatisticsRespVO.java +++ /dev/null @@ -1,24 +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.ToString; - -@Schema(description = "APP - 商品评价页评论分类数统计 Response VO") -@Data -@ToString(callSuper = true) -public class AppCommentStatisticsRespVO { - - @Schema(description = "好评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721") - private Long goodCount; - - @Schema(description = "中评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721") - private Long mediocreCount; - - @Schema(description = "差评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721") - private Long negativeCount; - - @Schema(description = "总平均分", requiredMode = Schema.RequiredMode.REQUIRED, example = "3.55") - private Double scores; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java index 1d42bab80..31e50c060 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java @@ -91,7 +91,8 @@ public class AppProductCommentRespVO { @NotNull(message = "评论内容不能为空") private String content; - @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]") + @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, + example = "[https://www.iocoder.cn/xx.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 fb6ac4f85..7a3a3c011 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,29 +1,17 @@ package cn.iocoder.yudao.module.product.convert.comment; -import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; 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.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 cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; 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; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; /** * 商品评价 Convert @@ -35,48 +23,35 @@ public interface ProductCommentConvert { ProductCommentConvert INSTANCE = Mappers.getMapper(ProductCommentConvert.class); - ProductCommentRespVO convert(ProductCommentDO bean); - - @Mapping(target = "scores", expression = "java(calculateOverallScore(goodCount, mediocreCount, negativeCount))") - AppCommentStatisticsRespVO convert(Long goodCount, Long mediocreCount, Long negativeCount); - - @Named("calculateOverallScore") - default double calculateOverallScore(long goodCount, long mediocreCount, long negativeCount) { - return (goodCount * 5 + mediocreCount * 3 + negativeCount) / (double) (goodCount + mediocreCount + negativeCount); + default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO, + ProductSpuDO spu, ProductSkuDO sku, MemberUserRespDTO user) { + ProductCommentDO comment = BeanUtils.toBean(createReqDTO, ProductCommentDO.class) + .setScores(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores())); + if (user != null) { + comment.setUserId(user.getId()).setUserNickname(user.getNickname()).setUserAvatar(user.getAvatar()); + } + if (spu != null) { + comment.setSpuId(spu.getId()).setSpuName(spu.getName()); + } + if (sku != null) { + comment.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties()); + } + return comment; } - List convertList(List list); - - PageResult convertPage(PageResult page); - - PageResult convertPage01(PageResult pageResult); - - default PageResult convertPage02(PageResult pageResult, - List skuList) { - Map skuMap = CollectionUtils.convertMap(skuList, ProductSkuDO::getId); - PageResult page = convertPage01(pageResult); - page.getList().forEach(item -> { - // 判断用户是否选择匿名 - if (ObjectUtil.equal(item.getAnonymous(), true)) { - item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); - } - // 设置 SKU 规格值 - findAndThen(skuMap, item.getSkuId(), - sku -> item.setSkuProperties(convertList01(sku.getProperties()))); - }); - return page; + default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu, ProductSkuDO sku) { + ProductCommentDO comment = BeanUtils.toBean(createReq, ProductCommentDO.class) + .setVisible(true).setUserId(0L).setAnonymous(false) + .setScores(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores())); + if (spu != null) { + comment.setSpuId(spu.getId()).setSpuName(spu.getName()); + } + if (sku != null) { + comment.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties()); + } + return comment; } - List convertList01(List properties); - - /** - * 计算综合评分 - * - * @param descriptionScores 描述星级 - * @param benefitScores 服务星级 - * @return 综合评分 - */ - @Named("convertScores") default Integer convertScores(Integer descriptionScores, Integer benefitScores) { // 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2 BigDecimal sumScore = new BigDecimal(descriptionScores + benefitScores); @@ -84,50 +59,4 @@ public interface ProductCommentConvert { return divide.intValue(); } - @Mapping(target = "scores", - expression = "java(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()))") - ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO); - - default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO, - ProductSpuDO spu, ProductSkuDO sku, MemberUserRespDTO user) { - ProductCommentDO comment = convert(createReqDTO).setReplyStatus(false); - if (user != null) { - comment.setUserId(user.getId()); - comment.setUserNickname(user.getNickname()); - comment.setUserAvatar(user.getAvatar()); - } - if (spu != null) { - comment.setSpuId(spu.getId()); - comment.setSpuName(spu.getName()); - } - if (sku != null) { - comment.setSkuPicUrl(sku.getPicUrl()); - comment.setSkuProperties(sku.getProperties()); - } - return comment; - } - - @Mapping(target = "visible", constant = "true") - @Mapping(target = "replyStatus", constant = "false") - @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); - - List convertList02(List list); - - default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu, ProductSkuDO sku) { - ProductCommentDO commentDO = convert(createReq); - if (spu != null) { - commentDO.setSpuId(spu.getId()).setSpuName(spu.getName()); - } - if (sku != null) { - commentDO.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties()); - } - return commentDO; - } - } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java index 969460d2c..d2b519596 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java @@ -144,13 +144,6 @@ public class ProductSpuDO extends BaseDO { * 赠送积分 */ private Integer giveIntegral; - /** - * 赠送的优惠劵编号的数组 - * - * 对应 CouponTemplateDO 的 id 属性 - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private List giveCouponTemplateIds; // TODO @puhui999:字段估计要改成 brokerageType /** 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 387a3736b..ca04c507c 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 @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.product.dal.mysql.comment; import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.framework.common.pojo.PageParam; 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; @@ -59,21 +58,4 @@ public interface ProductCommentMapper extends BaseMapperX { .eq(ProductCommentDO::getOrderItemId, orderItemId)); } - default Long selectCountBySpuId(Long spuId, Boolean visible, Integer type) { - LambdaQueryWrapperX queryWrapper = new LambdaQueryWrapperX() - .eqIfPresent(ProductCommentDO::getSpuId, spuId) - .eqIfPresent(ProductCommentDO::getVisible, visible); - // 构建评价查询语句 - appendTabQuery(queryWrapper, type); - return selectCount(queryWrapper); - } - - default PageResult selectCommentList(Long spuId, Integer count) { - // 构建分页查询条件 - return selectPage(new PageParam().setPageSize(count), new LambdaQueryWrapperX() - .eqIfPresent(ProductCommentDO::getSpuId, spuId) - .orderByDesc(ProductCommentDO::getCreateTime) - ); - } - } 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 e531f5513..b54e21918 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 @@ -7,14 +7,10 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import java.util.List; - /** * 商品评论 Service 接口 * @@ -73,22 +69,4 @@ public interface ProductCommentService { */ PageResult getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); - /** - * 获得商品的评价统计 - * - * @param spuId spu id - * @param visible 是否可见 - * @return 评价统计 - */ - AppCommentStatisticsRespVO getCommentStatistics(Long spuId, Boolean visible); - - /** - * 得到评论列表 - * - * @param spuId 商品 id - * @param count 数量 - * @return {@link Object} - */ - List getCommentList(Long spuId, Integer count); - } 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 bec1f5341..a089e2673 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 @@ -9,8 +9,6 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO; import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; @@ -18,13 +16,12 @@ 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 jakarta.annotation.Resource; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import jakarta.annotation.Resource; import java.time.LocalDateTime; -import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; @@ -54,28 +51,28 @@ public class ProductCommentServiceImpl implements ProductCommentService { @Override public void createComment(ProductCommentCreateReqVO createReqVO) { // 校验 SKU - ProductSkuDO skuDO = validateSku(createReqVO.getSkuId()); + ProductSkuDO sku = validateSku(createReqVO.getSkuId()); // 校验 SPU - ProductSpuDO spuDO = validateSpu(skuDO.getSpuId()); + ProductSpuDO spu = validateSpu(sku.getSpuId()); // 创建评论 - ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqVO, spuDO, skuDO); + ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqVO, spu, sku); productCommentMapper.insert(comment); } @Override public Long createComment(ProductCommentCreateReqDTO createReqDTO) { // 校验 SKU - ProductSkuDO skuDO = validateSku(createReqDTO.getSkuId()); + ProductSkuDO sku = validateSku(createReqDTO.getSkuId()); // 校验 SPU - ProductSpuDO spuDO = validateSpu(skuDO.getSpuId()); + ProductSpuDO spu = validateSpu(sku.getSpuId()); // 校验评论 validateCommentExists(createReqDTO.getUserId(), createReqDTO.getOrderId()); // 获取用户详细信息 MemberUserRespDTO user = memberUserApi.getUser(createReqDTO.getUserId()); // 创建评论 - ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqDTO, spuDO, skuDO, user); + ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqDTO, spu, sku, user); productCommentMapper.insert(comment); return comment.getId(); } @@ -137,23 +134,6 @@ public class ProductCommentServiceImpl implements ProductCommentService { return productComment; } - @Override - public AppCommentStatisticsRespVO getCommentStatistics(Long spuId, Boolean visible) { - return ProductCommentConvert.INSTANCE.convert( - // 查询商品 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 List getCommentList(Long spuId, Integer count) { - return ProductCommentConvert.INSTANCE.convertList02(productCommentMapper.selectCommentList(spuId, count).getList()); - } - @Override public PageResult getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { return productCommentMapper.selectPage(pageVO, visible);