feat(admin): Implement admin module foundation
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
package com.nuaa.video.comment.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.nuaa.video.comment.entity.Comment;
|
||||
import com.nuaa.video.comment.service.CommentService;
|
||||
import com.nuaa.video.comment.vo.CommentStatVO;
|
||||
import com.nuaa.video.comment.vo.CommentVO;
|
||||
import com.nuaa.video.common.model.vo.Result;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 评论管理控制器 - 供管理后台调用
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/comment/admin")
|
||||
@RequiredArgsConstructor
|
||||
public class AdminCommentController {
|
||||
|
||||
private final CommentService commentService;
|
||||
|
||||
/**
|
||||
* 获取评论列表 - 管理接口
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Result<Page<CommentVO>> getCommentList(
|
||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "10") Integer size,
|
||||
@RequestParam(value = "videoId", required = false) Long videoId,
|
||||
@RequestParam(value = "userId", required = false) Long userId,
|
||||
@RequestParam(value = "keyword", required = false) String keyword) {
|
||||
|
||||
return commentService.getAdminCommentList(page, size, videoId, userId, keyword);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论详情 - 管理接口
|
||||
*/
|
||||
@GetMapping("/{commentId}")
|
||||
public Result<CommentVO> getCommentDetail(@PathVariable Long commentId) {
|
||||
return commentService.getAdminCommentDetail(commentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除评论 - 管理接口
|
||||
*/
|
||||
@DeleteMapping("/{commentId}")
|
||||
public Result<Void> deleteComment(@PathVariable Long commentId) {
|
||||
return commentService.adminDeleteComment(commentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论统计信息 - 管理接口
|
||||
*/
|
||||
@GetMapping("/stats")
|
||||
public Result<CommentStatVO> getCommentStats() {
|
||||
return commentService.getCommentStats();
|
||||
}
|
||||
}
|
||||
@@ -95,4 +95,24 @@ public interface CommentService extends IService<Comment> {
|
||||
* @return 统计信息
|
||||
*/
|
||||
Result<CommentStatVO> getCommentStat(Long videoId);
|
||||
|
||||
/**
|
||||
* 获取评论列表 - 管理接口
|
||||
*/
|
||||
Result<Page<CommentVO>> getAdminCommentList(Integer page, Integer size, Long videoId, Long userId, String keyword);
|
||||
|
||||
/**
|
||||
* 获取评论详情 - 管理接口
|
||||
*/
|
||||
Result<CommentVO> getAdminCommentDetail(Long commentId);
|
||||
|
||||
/**
|
||||
* 管理员删除评论 - 管理接口
|
||||
*/
|
||||
Result<Void> adminDeleteComment(Long commentId);
|
||||
|
||||
/**
|
||||
* 获取评论统计信息 - 管理接口
|
||||
*/
|
||||
Result<CommentStatVO> getCommentStats();
|
||||
}
|
||||
+121
@@ -25,7 +25,9 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -362,6 +364,125 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> impl
|
||||
return Result.success(statVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Page<CommentVO>> getAdminCommentList(Integer page, Integer size, Long videoId, Long userId, String keyword) {
|
||||
if (page == null || page < 1) {
|
||||
page = 1;
|
||||
}
|
||||
if (size == null || size < 1) {
|
||||
size = 10;
|
||||
}
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 管理员可以查看所有状态的评论,包括已删除的
|
||||
|
||||
// 按视频ID筛选
|
||||
if (videoId != null) {
|
||||
queryWrapper.eq(Comment::getVideoId, videoId);
|
||||
}
|
||||
|
||||
// 按用户ID筛选
|
||||
if (userId != null) {
|
||||
queryWrapper.eq(Comment::getUserId, userId);
|
||||
}
|
||||
|
||||
// 按关键词筛选
|
||||
if (StringUtils.hasText(keyword)) {
|
||||
queryWrapper.like(Comment::getContent, keyword);
|
||||
}
|
||||
|
||||
// 按创建时间降序排序
|
||||
queryWrapper.orderByDesc(Comment::getCreateTime);
|
||||
|
||||
// 分页查询
|
||||
Page<Comment> commentPage = new Page<>(page, size);
|
||||
commentPage = page(commentPage, queryWrapper);
|
||||
|
||||
// 转换为VO
|
||||
Page<CommentVO> voPage = new Page<>();
|
||||
BeanUtils.copyProperties(commentPage, voPage, "records");
|
||||
|
||||
List<CommentVO> commentVOList = new ArrayList<>();
|
||||
for (Comment comment : commentPage.getRecords()) {
|
||||
CommentVO vo = convertToCommentVO(comment, null);
|
||||
commentVOList.add(vo);
|
||||
}
|
||||
|
||||
voPage.setRecords(commentVOList);
|
||||
|
||||
return Result.success(voPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<CommentVO> getAdminCommentDetail(Long commentId) {
|
||||
// 查询评论信息
|
||||
Comment comment = getById(commentId);
|
||||
if (comment == null) {
|
||||
return Result.error("评论不存在");
|
||||
}
|
||||
|
||||
// 转换为VO
|
||||
CommentVO vo = convertToCommentVO(comment, null);
|
||||
|
||||
// 获取回复列表
|
||||
Result<List<ReplyVO>> repliesResult = commentReplyService.getHotReplies(commentId, 10, null);
|
||||
if (repliesResult.getCode() == 200 && repliesResult.getData() != null) {
|
||||
vo.setHotReplies(repliesResult.getData());
|
||||
} else {
|
||||
vo.setHotReplies(new ArrayList<>());
|
||||
}
|
||||
|
||||
return Result.success(vo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<Void> adminDeleteComment(Long commentId) {
|
||||
// 查询评论是否存在
|
||||
Comment comment = getById(commentId);
|
||||
if (comment == null) {
|
||||
return Result.error("评论不存在");
|
||||
}
|
||||
|
||||
// 逻辑删除评论(设置状态为0)
|
||||
comment.setStatus(0);
|
||||
comment.setUpdatedBy("admin");
|
||||
comment.setUpdateTime(LocalDateTime.now());
|
||||
updateById(comment);
|
||||
|
||||
// 更新视频评论数
|
||||
contentFeignClient.increaseCommentCount(comment.getVideoId(), -1, "Bearer ");
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<CommentStatVO> getCommentStats() {
|
||||
CommentStatVO statVO = new CommentStatVO();
|
||||
|
||||
// 获取各种统计数据
|
||||
// 1. 总评论数
|
||||
long totalComments = count();
|
||||
statVO.setCommentCount((int)totalComments);
|
||||
|
||||
// 2. 今日新增评论数
|
||||
LocalDate today = LocalDate.now();
|
||||
long todayComments = count(new LambdaQueryWrapper<Comment>()
|
||||
.ge(Comment::getCreateTime, today.atStartOfDay()));
|
||||
|
||||
// 3. 回复总数
|
||||
long totalReplies = commentReplyMapper.selectCount(null);
|
||||
statVO.setReplyCount((int)totalReplies);
|
||||
|
||||
// 4. 总点赞数
|
||||
long totalLikes = commentLikeMapper.selectCount(null);
|
||||
statVO.setLikeCount((int)totalLikes);
|
||||
|
||||
return Result.success(statVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将评论实体转换为VO
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user