fix:完善商品评论
parent
dde89d51d5
commit
20100aa78b
@ -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);
|
||||
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package cn.iocoder.yudao.module.product.controller.app.comment;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
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 cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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 javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "用户 APP - 商品评价")
|
||||
@RestController
|
||||
@RequestMapping("/product/comment")
|
||||
@Validated
|
||||
public class AppProductCommentController {
|
||||
|
||||
@Resource
|
||||
private ProductCommentService productCommentService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得商品评价分页")
|
||||
public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) {
|
||||
PageResult<AppProductCommentRespVO> result = productCommentService.getCommentPage(pageVO, Boolean.TRUE);
|
||||
result.getList().forEach(item -> {
|
||||
// 判断用户是否选择匿名
|
||||
if (ObjectUtil.equal(item.getAnonymous(), true)) {
|
||||
item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
|
||||
}
|
||||
});
|
||||
return success(result);
|
||||
}
|
||||
|
||||
@GetMapping("/getCommentStatistics")
|
||||
@Operation(summary = "获得商品的评价统计")
|
||||
public CommonResult<AppCommentStatisticsRespVO> getCommentPage(@Valid @RequestParam("spuId") Long spuId) {
|
||||
return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE));
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue