mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
fix:完善 app 商品评论页获取评论分页接口和相关评论分类数量接口
This commit is contained in:
parent
5bfca56efa
commit
151e58daa1
@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
@ -41,6 +42,12 @@ public class AppCommentController {
|
|||||||
return success(ProductCommentConvert.INSTANCE.convertPage02(pageResult));
|
return success(ProductCommentConvert.INSTANCE.convertPage02(pageResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get-count")
|
||||||
|
@Operation(summary = "获得商品评价分页 tab count")
|
||||||
|
public CommonResult<Map<String, Long>> getCommentPage(@Valid Long spuId) {
|
||||||
|
return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE));
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/create")
|
@PostMapping(value = "/create")
|
||||||
@Operation(summary = "创建商品评价")
|
@Operation(summary = "创建商品评价")
|
||||||
public CommonResult<Boolean> createComment(@RequestBody AppCommentCreateReqVO createReqVO) {
|
public CommonResult<Boolean> createComment(@RequestBody AppCommentCreateReqVO createReqVO) {
|
||||||
|
@ -18,4 +18,8 @@ public class AppCommentPageReqVO extends PageParam {
|
|||||||
@NotNull(message = "商品SPU编号不能为空")
|
@NotNull(message = "商品SPU编号不能为空")
|
||||||
private Long spuId;
|
private Long spuId;
|
||||||
|
|
||||||
|
@Schema(description = "app 评论页 tab 类型 (0 全部、1 好评、2 中评、3 差评)", example = "0")
|
||||||
|
@NotNull(message = "商品SPU编号不能为空")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,23 @@ import java.util.List;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ProductCommentDO extends BaseDO {
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 评论编号,主键自增
|
* 评论编号,主键自增
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.product.dal.mysql.comment;
|
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.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
@ -34,11 +35,33 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
|
|||||||
.orderByDesc(ProductCommentDO::getId));
|
.orderByDesc(ProductCommentDO::getId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> 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<ProductCommentDO> selectPage(AppCommentPageReqVO reqVO, Boolean visible) {
|
default PageResult<ProductCommentDO> selectPage(AppCommentPageReqVO reqVO, Boolean visible) {
|
||||||
return selectPage(reqVO, new LambdaQueryWrapperX<ProductCommentDO>()
|
LambdaQueryWrapperX<ProductCommentDO> queryWrapper = new LambdaQueryWrapperX<ProductCommentDO>()
|
||||||
.eqIfPresent(ProductCommentDO::getSpuId, reqVO.getSpuId())
|
.eqIfPresent(ProductCommentDO::getSpuId, reqVO.getSpuId())
|
||||||
.eqIfPresent(ProductCommentDO::getVisible, visible)
|
.eqIfPresent(ProductCommentDO::getVisible, visible);
|
||||||
.orderByDesc(ProductCommentDO::getId));
|
// 构建评价查询语句
|
||||||
|
appendTabQuery(queryWrapper, reqVO.getType());
|
||||||
|
// 按评价时间排序最新的显示在前面
|
||||||
|
queryWrapper.orderByDesc(ProductCommentDO::getCreateTime);
|
||||||
|
return selectPage(reqVO, queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void updateCommentVisible(Long id, Boolean visible) {
|
default void updateCommentVisible(Long id, Boolean visible) {
|
||||||
@ -74,4 +97,13 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
|
|||||||
update(null, lambdaUpdateWrapper);
|
update(null, lambdaUpdateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Long selectTabCount(Long spuId, Boolean visible, Integer type) {
|
||||||
|
LambdaQueryWrapperX<ProductCommentDO> queryWrapper = new LambdaQueryWrapperX<ProductCommentDO>()
|
||||||
|
.eqIfPresent(ProductCommentDO::getSpuId, spuId)
|
||||||
|
.eqIfPresent(ProductCommentDO::getVisible, visible);
|
||||||
|
// 构建评价查询语句
|
||||||
|
appendTabQuery(queryWrapper, type);
|
||||||
|
return selectCount(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品评论 Service 接口
|
* 商品评论 Service 接口
|
||||||
*
|
*
|
||||||
@ -68,4 +70,12 @@ public interface ProductCommentService {
|
|||||||
*/
|
*/
|
||||||
void additionalComment(MemberUserRespDTO user, AppCommentAdditionalReqVO createReqVO);
|
void additionalComment(MemberUserRespDTO user, AppCommentAdditionalReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论页面标签数
|
||||||
|
*
|
||||||
|
* @param spuId spu id
|
||||||
|
* @param visible 是否可见
|
||||||
|
* @return 获得商品评价分页 tab count
|
||||||
|
*/
|
||||||
|
Map<String, Long> getCommentPageTabsCount(Long spuId, Boolean visible);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ import org.springframework.util.StringUtils;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
@ -62,6 +64,20 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
|||||||
productCommentMapper.commentReply(replyVO, loginUserId);
|
productCommentMapper.commentReply(replyVO, loginUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Long> getCommentPageTabsCount(Long spuId, Boolean visible) {
|
||||||
|
Map<String, Long> 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
|
@Override
|
||||||
public PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) {
|
public PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) {
|
||||||
return productCommentMapper.selectPage(pageVO, visible);
|
return productCommentMapper.selectPage(pageVO, visible);
|
||||||
|
Loading…
Reference in New Issue
Block a user