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.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.Parameter; 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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "管理后台 - 商品评价") @RestController @RequestMapping("/product/comment") @Validated public class ProductCommentController { @Resource private ProductCommentService productCommentService; @GetMapping("/page") @Operation(summary = "获得商品评价分页") @PreAuthorize("@ss.hasPermission('product:comment:query')") public CommonResult> getCommentPage(@Valid ProductCommentPageReqVO pageVO) { PageResult pageResult = productCommentService.getCommentPage(pageVO); return success(BeanUtils.toBean(pageResult, ProductCommentRespVO.class)); } @GetMapping("/get") @Operation(summary = "获得商品评价") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('product:comment:query')") public CommonResult getComment(@RequestParam("id") Long id) { ProductCommentDO comment = productCommentService.getComment(id); return success(BeanUtils.toBean(comment, ProductCommentRespVO.class)); } @PutMapping("/update-visible") @Operation(summary = "显示 / 隐藏评论") @PreAuthorize("@ss.hasPermission('product:comment:update')") public CommonResult updateCommentVisible(@Valid @RequestBody ProductCommentUpdateVisibleReqVO updateReqVO) { productCommentService.updateCommentVisible(updateReqVO); return success(true); } @PutMapping("/reply") @Operation(summary = "商家回复") @PreAuthorize("@ss.hasPermission('product:comment:update')") public CommonResult commentReply(@Valid @RequestBody ProductCommentReplyReqVO replyVO) { productCommentService.replyComment(replyVO, getLoginUserId()); return success(true); } @PostMapping("/create") @Operation(summary = "添加自评") @PreAuthorize("@ss.hasPermission('product:comment:update')") public CommonResult createComment(@Valid @RequestBody ProductCommentCreateReqVO createReqVO) { productCommentService.createComment(createReqVO); return success(true); } }