refactor(video): 重构视频审核服务异常处理

- 将 javax.servlet.http.HttpServletResponse 替换为 jakarta.servlet.http.HttpServletResponse
- 使用 BaseException 替换 BizException 处理业务异常
- 修改视频查询方法 selectById 为 getEntity
- 统一参数校验和用户登录状态检查的异常抛出方式
This commit is contained in:
2025-11-18 00:54:11 +08:00
parent a5ffb86790
commit 5c49a5af9e
2 changed files with 7 additions and 6 deletions

View File

@@ -7,11 +7,11 @@ import com.ycwl.basic.model.pc.videoreview.dto.VideoReviewRespDTO;
import com.ycwl.basic.model.pc.videoreview.dto.VideoReviewStatisticsRespDTO;
import com.ycwl.basic.service.VideoReviewService;
import com.ycwl.basic.utils.ApiResponse;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

View File

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ycwl.basic.constant.BaseContextHandler;
import com.ycwl.basic.exception.BaseException;
import com.ycwl.basic.exception.BizException;
import com.ycwl.basic.mapper.VideoMapper;
import com.ycwl.basic.mapper.VideoReviewMapper;
@@ -51,22 +52,22 @@ public class VideoReviewServiceImpl implements VideoReviewService {
public Long addReview(VideoReviewAddReqDTO reqDTO) {
// 1. 参数校验
if (reqDTO.getVideoId() == null) {
throw new BizException("视频ID不能为空");
throw new BaseException("视频ID不能为空");
}
if (reqDTO.getRating() == null || reqDTO.getRating() < 1 || reqDTO.getRating() > 5) {
throw new BizException("评分必须在1-5之间");
throw new BaseException("评分必须在1-5之间");
}
// 2. 查询视频信息,获取景区ID
VideoEntity video = videoMapper.selectById(reqDTO.getVideoId());
VideoEntity video = videoMapper.getEntity(reqDTO.getVideoId());
if (video == null) {
throw new BizException("视频不存在");
throw new BaseException("视频不存在");
}
// 3. 获取当前登录用户(管理员)
String userIdStr = BaseContextHandler.getUserId();
if (userIdStr == null || userIdStr.isEmpty()) {
throw new BizException("未登录或登录已过期");
throw new BaseException("未登录或登录已过期");
}
Long creator = Long.valueOf(userIdStr);