|
@@ -2,11 +2,9 @@ package cn.iocoder.yudao.module.product.service.comment;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
-import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO;
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO;
|
|
|
-import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO;
|
|
|
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
|
|
|
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO;
|
|
|
import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
|
|
@@ -17,7 +15,6 @@ import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
|
|
|
import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
|
|
|
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -25,13 +22,11 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
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;
|
|
|
|
|
|
-// TODO @芋艿:详细 review 下
|
|
|
/**
|
|
|
* 商品评论 Service 实现类
|
|
|
*
|
|
@@ -43,6 +38,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
|
|
|
|
|
@Resource
|
|
|
private ProductCommentMapper productCommentMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private TradeOrderApi tradeOrderApi;
|
|
|
|
|
@@ -59,6 +55,8 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
|
|
// 校验评论是否存在
|
|
|
validateCommentExists(updateReqVO.getId());
|
|
|
|
|
|
+ // 更新可见状态
|
|
|
+ // TODO @puhui999:直接使用 update 操作
|
|
|
productCommentMapper.updateCommentVisible(updateReqVO.getId(), updateReqVO.getVisible());
|
|
|
}
|
|
|
|
|
@@ -67,6 +65,8 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
|
|
// 校验评论是否存在
|
|
|
validateCommentExists(replyVO.getId());
|
|
|
|
|
|
+ // 回复评论
|
|
|
+ // TODO @puhui999:直接使用 update 操作
|
|
|
productCommentMapper.commentReply(replyVO, loginUserId);
|
|
|
}
|
|
|
|
|
@@ -90,12 +90,14 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
|
|
|
|
|
@Override
|
|
|
public PageResult<AppCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) {
|
|
|
+ // TODO @puhui999:逻辑可以在 controller 做哈。让 service 简介一点;因为是 view 需要不展示昵称
|
|
|
PageResult<AppCommentRespVO> result = ProductCommentConvert.INSTANCE.convertPage02(productCommentMapper.selectPage(pageVO, visible));
|
|
|
result.getList().forEach(item -> {
|
|
|
// 判断用户是否选择匿名
|
|
|
if (ObjectUtil.equal(item.getAnonymous(), true)) {
|
|
|
item.setUserNickname(AppCommentPageReqVO.ANONYMOUS_NICKNAME);
|
|
|
}
|
|
|
+ // TODO @puhui999:直接插入的时候,计算到 scores 字段里;这样就去掉 finalScore 字段哈
|
|
|
// 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2
|
|
|
BigDecimal sumScore = new BigDecimal(item.getScores() + item.getBenefitScores());
|
|
|
BigDecimal divide = sumScore.divide(BigDecimal.valueOf(2L), 0, RoundingMode.DOWN);
|
|
@@ -127,30 +129,11 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
|
|
productCommentMapper.insert(productComment);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void additionalComment(MemberUserRespDTO user, AppCommentAdditionalReqVO createReqVO) {
|
|
|
- // 校验评论是否存在
|
|
|
- ProductCommentDO productComment = validateCommentExists(createReqVO.getId());
|
|
|
-
|
|
|
- // 判断是否是同一用户追加评论
|
|
|
- if (!Objects.equals(productComment.getUserId(), user.getId())) {
|
|
|
- throw exception(COMMENT_ERROR_OPT);
|
|
|
- }
|
|
|
-
|
|
|
- // 判断是否已经追加评论过了
|
|
|
- if (StringUtils.hasText(productComment.getAdditionalContent())) {
|
|
|
- throw exception(COMMENT_ADDITIONAL_EXISTS);
|
|
|
- }
|
|
|
-
|
|
|
- productCommentMapper.additionalComment(createReqVO);
|
|
|
- }
|
|
|
-
|
|
|
- private ProductCommentDO validateCommentExists(Long id) {
|
|
|
+ private void validateCommentExists(Long id) {
|
|
|
ProductCommentDO productComment = productCommentMapper.selectById(id);
|
|
|
if (productComment == null) {
|
|
|
throw exception(COMMENT_NOT_EXISTS);
|
|
|
}
|
|
|
- return productComment;
|
|
|
}
|
|
|
|
|
|
}
|