Commit 96e2a984 authored by 万成波's avatar 万成波

评论优化

parent dde995b4
......@@ -5,10 +5,7 @@ import com.tangguo.common.mauth.MobileAuth;
import com.tangguo.common.mauth.MobileTokenHelper;
import com.tangguo.common.utils.PageUtils;
import com.tangguo.common.utils.ValidateOperations;
import com.tangguo.domain.bo.CommentMomentBO;
import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.domain.bo.LikeMomentBO;
import com.tangguo.domain.bo.VoteMomentBO;
import com.tangguo.domain.bo.*;
import com.tangguo.domain.vo.BbsCommentDetailVO;
import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.domain.vo.BbsVoteOptionVO;
......@@ -54,7 +51,7 @@ public class MBbsMomentController {
*/
@MobileAuth
@GetMapping("/moments")
public AjaxResult getUserMoments(String content) {
public AjaxResult getMoments(String content) {
String username = MobileTokenHelper.getUserName();
PageUtils.clearPage();
List<BbsMomentListVO> moments = this.momentService.getMoments(username, content);
......@@ -69,9 +66,8 @@ public class MBbsMomentController {
*/
@MobileAuth
@GetMapping("/{id}")
public AjaxResult getUserMoment(@PathVariable Long id) {
String username = MobileTokenHelper.getUserName();
BbsMomentListVO dbMoment = this.momentService.getMoment(id, username);
public AjaxResult getMomentDetail(@PathVariable Long id) {
BbsMomentListVO dbMoment = this.momentService.getMomentDetail(id);
return AjaxResult.success(dbMoment);
}
......@@ -212,8 +208,22 @@ public class MBbsMomentController {
@MobileAuth
@DeleteMapping("/comment/delete/{commentId}")
public AjaxResult deleteComment(@PathVariable Long commentId) {
String userName = MobileTokenHelper.getUserName();
this.momentCommentService.deleteComment(commentId, userName);
this.momentService.userDeleteComment(commentId);
return AjaxResult.success();
}
/**
* 精选评论
*
* @param bo 评论
* @return 精选结果
*/
@MobileAuth
@PostMapping("/comment/featured")
public AjaxResult featuredComment(@RequestBody FeaturedCommentBO bo) {
ValidateOperations.generalValidate(bo);
this.momentService.userFeaturedComment(bo);
return AjaxResult.success();
}
......
......@@ -52,7 +52,7 @@ public class BbsMomentController extends BaseController {
@PreAuthorize("@ss.hasPermi('bbs:moment:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
BbsMomentListVO dbMoment = this.bbsMomentService.getMoment(id, SecurityUtils.getUsername());
BbsMomentListVO dbMoment = this.bbsMomentService.getMomentDetail(id);
return success(dbMoment);
}
......
package com.tangguo.domain.bo;
import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
*
*
* @author 谈笑
* @createTime 2025-09-05 11:58:28 星期五
*/
@Data
public class FeaturedCommentBO {
/**
* 动态Id
*/
@NotNull(message = "动态Id不能为空")
private Long momentId;
/**
* 评论Id
*/
@NotNull(message = "评论Id不能为空")
private Long commentId;
/**
* 精选状态:0 取消精选、1 精选
*/
@NotNull(message = "精选状态不能为空")
@Min(value = 0, message = "精选状态值错误")
@Max(value = 1, message = "精选状态值错误")
private Integer featuredStatus;
}
......@@ -28,6 +28,6 @@ public interface BbsMomentMapper extends BaseMapper<BbsMoment> {
List<BbsMomentListVO> selectMoments(@Param("userName") String userName, @Param("content") String content);
BbsMomentListVO selectMoment(@Param("momentId") Long momentId, @Param("userName") String userName);
BbsMomentListVO selectMomentDetail(@Param("momentId") Long momentId, @Param("userName") String userName);
}
......@@ -2,7 +2,9 @@ package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsMomentComment;
import com.tangguo.domain.bo.FeaturedCommentBO;
import com.tangguo.domain.vo.BbsCommentDetailVO;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
......@@ -59,13 +61,4 @@ public interface IBbsMomentCommentService extends IService<BbsMomentComment> {
*/
List<BbsCommentDetailVO> getMomentComments(Long momentId, String userName);
/**
* 删除评论
*
* @param commentId 评论Id
* @param userName 用户名
*/
void deleteComment(Long commentId, String userName);
}
......@@ -2,10 +2,7 @@ package com.tangguo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.bo.CommentMomentBO;
import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.domain.bo.LikeMomentBO;
import com.tangguo.domain.bo.VoteMomentBO;
import com.tangguo.domain.bo.*;
import com.tangguo.domain.vo.BbsMomentListVO;
import com.tangguo.domain.vo.BbsUserMomentCountVO;
......@@ -68,10 +65,9 @@ public interface IBbsMomentService extends IService<BbsMoment> {
* 查询动态详情
*
* @param momentId 动态Id
* @param userName 用户名
* @return 动态列表
*/
BbsMomentListVO getMoment(Long momentId, String userName);
BbsMomentListVO getMomentDetail(Long momentId);
/**
......@@ -113,4 +109,20 @@ public interface IBbsMomentService extends IService<BbsMoment> {
*/
void userCommentMoment(CommentMomentBO bo);
/**
* 删除评论
*
* @param commentId 评论Id
*/
void userDeleteComment(Long commentId);
/**
* 精选评论
*
* @param bo 评论
*/
void userFeaturedComment(FeaturedCommentBO bo);
}
......@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangguo.common.enums.CommentStatus;
import com.tangguo.common.exception.ServiceException;
import com.tangguo.domain.BbsMomentComment;
import com.tangguo.domain.bo.FeaturedCommentBO;
import com.tangguo.domain.vo.BbsCommentDetailVO;
import com.tangguo.mapper.BbsMomentCommentMapper;
import com.tangguo.service.IBbsMomentCommentService;
......@@ -107,29 +108,4 @@ public class BbsMomentCommentServiceImpl extends ServiceImpl<BbsMomentCommentMap
return this.baseMapper.selectMomentComments(momentId, userName);
}
/**
* 删除评论
*
* @param commentId 评论Id
* @param userName 用户名
*/
@Override
public void deleteComment(Long commentId, String userName) {
BbsMomentComment dbComment = this.getOne(
Wrappers.lambdaQuery(BbsMomentComment.class).eq(BbsMomentComment::getId, commentId)
);
if (Objects.isNull(dbComment)) {
throw new ServiceException("删除失败,未查询到当前动态评论数据。");
}
if (!dbComment.getUserName().equals(userName)) {
throw new ServiceException("删除失败,没有对当前动态评论的操作权限。");
}
BbsMomentComment updComment = new BbsMomentComment();
updComment.setId(dbComment.getId());
updComment.setStatus(CommentStatus.SC.getStatus());
this.updateById(updComment);
}
}
......@@ -13,10 +13,7 @@ import com.tangguo.domain.BbsMoment;
import com.tangguo.domain.BbsMomentAttachment;
import com.tangguo.domain.BbsMomentComment;
import com.tangguo.domain.BbsMomentVoteOption;
import com.tangguo.domain.bo.CommentMomentBO;
import com.tangguo.domain.bo.CreateMomentBO;
import com.tangguo.domain.bo.LikeMomentBO;
import com.tangguo.domain.bo.VoteMomentBO;
import com.tangguo.domain.bo.*;
import com.tangguo.domain.vo.*;
import com.tangguo.mapper.BbsMomentMapper;
import com.tangguo.service.*;
......@@ -47,16 +44,16 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
private IBbsMomentAttachmentService attachmentsService;
@Resource
private IBbsMomentVoteOptionService voteOptionService;
private IBbsMomentLikeService likeService;
@Resource
private IBbsMomentCommentService commentService;
private IBbsMomentVoteService voteService;
@Resource
private IBbsMomentLikeService likeService;
private IBbsMomentVoteOptionService voteOptionService;
@Resource
private IBbsMomentVoteService voteService;
private IBbsMomentCommentService commentService;
/**
......@@ -128,12 +125,12 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
* 查询动态详情
*
* @param momentId 动态Id
* @param userName 用户名
* @return 动态列表
*/
@Override
public BbsMomentListVO getMoment(Long momentId, String userName) {
BbsMomentListVO dbMoment = this.baseMapper.selectMoment(momentId, userName);
public BbsMomentListVO getMomentDetail(Long momentId) {
String userName = MobileTokenHelper.getUserName();
BbsMomentListVO dbMoment = this.baseMapper.selectMomentDetail(momentId, userName);
this.fillMoment(Collections.singletonList(dbMoment), userName);
dbMoment.setComments(null);
return dbMoment;
......@@ -328,6 +325,64 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
}
/**
* 删除评论
*
* @param commentId 评论Id
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void userDeleteComment(Long commentId) {
BbsMomentComment dbComment = this.commentService.getById(commentId);
if (Objects.isNull(dbComment)) {
throw new ServiceException("删除失败,未查询到当前动态评论数据。");
}
String userName = MobileTokenHelper.getUserName();
if (!dbComment.getUserName().equals(userName)) {
throw new ServiceException("删除失败,没有对当前动态评论的操作权限。");
}
BbsMomentComment updComment = new BbsMomentComment();
updComment.setId(dbComment.getId());
updComment.setStatus(CommentStatus.SC.getStatus());
this.commentService.updateById(updComment);
}
/**
* 精选评论
*
* @param bo 评论
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void userFeaturedComment(FeaturedCommentBO bo) {
BbsMoment dbMoment = this.getById(bo.getMomentId());
if (Objects.isNull(dbMoment)) {
throw new ServiceException("操作失败,未查询到当前动态数据。");
}
String userName = MobileTokenHelper.getUserName();
if (!dbMoment.getUserName().equals(userName)) {
throw new ServiceException("操作失败,没有对当前动态评论的操作权限。");
}
if (EnableStatus.QY.getStatus() != dbMoment.getIsEnableFeaturedComment()) {
throw new ServiceException("操作失败,当前动态未开启评论精选。");
}
BbsMomentComment dbComment = this.commentService.getById(bo.getCommentId());
if (Objects.isNull(dbComment)) {
throw new ServiceException("操作失败,未查询到当前动态评论数据。");
}
BbsMomentComment updComment = new BbsMomentComment();
updComment.setId(dbComment.getId());
updComment.setIsFeatured(bo.getFeaturedStatus());
this.commentService.updateById(updComment);
}
/**
* 构建动态实体
*
......
......@@ -114,7 +114,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectMoment" resultType="com.tangguo.domain.vo.BbsMomentListVO">
<select id="selectMomentDetail" resultType="com.tangguo.domain.vo.BbsMomentListVO">
SELECT
m.*,
uv.nike_name,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment