From 151e58daa1497f1616ae76e0ad32948dda58a38c Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 8 Jun 2023 11:37:49 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=AE=8C=E5=96=84=20app=20?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=84=E8=AE=BA=E9=A1=B5=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=88=86=E9=A1=B5=E6=8E=A5=E5=8F=A3=E5=92=8C?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E8=AF=84=E8=AE=BA=E5=88=86=E7=B1=BB=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/comment/AppCommentController.java | 7 ++++ .../app/comment/vo/AppCommentPageReqVO.java | 4 ++ .../dataobject/comment/ProductCommentDO.java | 17 +++++++++ .../mysql/comment/ProductCommentMapper.java | 38 +++++++++++++++++-- .../comment/ProductCommentService.java | 10 +++++ .../comment/ProductCommentServiceImpl.java | 16 ++++++++ 6 files changed, 89 insertions(+), 3 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java index a5621c57a..b4af14ff5 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/AppCommentController.java @@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @@ -41,6 +42,12 @@ public class AppCommentController { return success(ProductCommentConvert.INSTANCE.convertPage02(pageResult)); } + @GetMapping("/get-count") + @Operation(summary = "获得商品评价分页 tab count") + public CommonResult> getCommentPage(@Valid Long spuId) { + return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE)); + } + @PostMapping(value = "/create") @Operation(summary = "创建商品评价") public CommonResult createComment(@RequestBody AppCommentCreateReqVO createReqVO) { 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 f557d7779..fba876624 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 @@ -18,4 +18,8 @@ public class AppCommentPageReqVO extends PageParam { @NotNull(message = "商品SPU编号不能为空") private Long spuId; + @Schema(description = "app 评论页 tab 类型 (0 全部、1 好评、2 中评、3 差评)", example = "0") + @NotNull(message = "商品SPU编号不能为空") + private Integer type; + } 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 6e0bd04fa..1686d8fd5 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,23 @@ import java.util.List; @AllArgsConstructor public class ProductCommentDO extends BaseDO { + /** + * 所有 + */ + public static final Integer ALL = 0; + /** + * 好评 + */ + public static final Integer FAVOURABLE_COMMENT = 1; + /** + * 中评 + */ + public static final Integer MEDIOCRE_COMMENT = 2; + /** + * 差评 + */ + public static final Integer NEGATIVE_COMMENT = 3; + /** * 评论编号,主键自增 */ 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 e378f53ce..98a040b99 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,6 +1,7 @@ package cn.iocoder.yudao.module.product.dal.mysql.comment; +import cn.hutool.core.util.ObjectUtil; 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; @@ -34,11 +35,33 @@ public interface ProductCommentMapper extends BaseMapperX { .orderByDesc(ProductCommentDO::getId)); } + static void appendTabQuery(LambdaQueryWrapperX queryWrapper, Integer type) { + // 构建好评查询语句 + if (ObjectUtil.equal(type, ProductCommentDO.FAVOURABLE_COMMENT)) { + // 好评计算 (商品评分星级+服务评分星级) >= 8 + queryWrapper.apply("(scores + benefitScores) >= 8"); + } + // 构建中评查询语句 + if (ObjectUtil.equal(type, ProductCommentDO.MEDIOCRE_COMMENT)) { + // 中评计算 (商品评分星级+服务评分星级) > 4 且 (商品评分星级+服务评分星级) < 8 + queryWrapper.apply("(scores + benefitScores) > 4 and (scores + benefitScores) < 8"); + } + // 构建差评查询语句 + if (ObjectUtil.equal(type, ProductCommentDO.NEGATIVE_COMMENT)) { + // 差评计算 (商品评分星级+服务评分星级) <= 4 + queryWrapper.apply("(scores + benefitScores) <= 4"); + } + } + default PageResult selectPage(AppCommentPageReqVO reqVO, Boolean visible) { - return selectPage(reqVO, new LambdaQueryWrapperX() + LambdaQueryWrapperX queryWrapper = new LambdaQueryWrapperX() .eqIfPresent(ProductCommentDO::getSpuId, reqVO.getSpuId()) - .eqIfPresent(ProductCommentDO::getVisible, visible) - .orderByDesc(ProductCommentDO::getId)); + .eqIfPresent(ProductCommentDO::getVisible, visible); + // 构建评价查询语句 + appendTabQuery(queryWrapper, reqVO.getType()); + // 按评价时间排序最新的显示在前面 + queryWrapper.orderByDesc(ProductCommentDO::getCreateTime); + return selectPage(reqVO, queryWrapper); } default void updateCommentVisible(Long id, Boolean visible) { @@ -74,4 +97,13 @@ public interface ProductCommentMapper extends BaseMapperX { update(null, lambdaUpdateWrapper); } + default Long selectTabCount(Long spuId, Boolean visible, Integer type) { + LambdaQueryWrapperX queryWrapper = new LambdaQueryWrapperX() + .eqIfPresent(ProductCommentDO::getSpuId, spuId) + .eqIfPresent(ProductCommentDO::getVisible, visible); + // 构建评价查询语句 + appendTabQuery(queryWrapper, type); + return selectCount(queryWrapper); + } + } 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 6f5e1b59f..cdda9e4c1 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 @@ -11,6 +11,8 @@ 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 接口 * @@ -68,4 +70,12 @@ public interface ProductCommentService { */ void additionalComment(MemberUserRespDTO user, AppCommentAdditionalReqVO createReqVO); + /** + * 评论页面标签数 + * + * @param spuId spu id + * @param visible 是否可见 + * @return 获得商品评价分页 tab count + */ + Map 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 f16f85871..38dc20840 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 @@ -18,6 +18,8 @@ import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -62,6 +64,20 @@ public class ProductCommentServiceImpl implements ProductCommentService { productCommentMapper.commentReply(replyVO, loginUserId); } + @Override + public Map getCommentPageTabsCount(Long spuId, Boolean visible) { + Map countMap = new HashMap<>(4); + // 查询商品 id = spuId 的所有评论数量 + countMap.put("allCount", productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.ALL)); + // 查询商品 id = spuId 的所有好评数量 + countMap.put("favourableCommentCount", productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.FAVOURABLE_COMMENT)); + // 查询商品 id = spuId 的所有中评数量 + countMap.put("mediocreCommentCount", productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.MEDIOCRE_COMMENT)); + // 查询商品 id = spuId 的所有差评数量 + countMap.put("negativeCommentCount", productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.NEGATIVE_COMMENT)); + return countMap; + } + @Override public PageResult getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { return productCommentMapper.selectPage(pageVO, visible);