423 lines
15 KiB
Java
423 lines
15 KiB
Java
package com.example.caseData.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.example.caseData.common.Response;
|
|
import com.example.caseData.dao.*;
|
|
import com.example.caseData.dto.T;
|
|
import com.example.caseData.dto.caseClinicalVideo.CaseClinicalVideoDto;
|
|
import com.example.caseData.dto.userCommentClinicalArticle.GetUserClinicalArticleCommentPageDto;
|
|
import com.example.caseData.dto.userCommentClinicalArticle.UserCommentClinicalArticleDto;
|
|
import com.example.caseData.dto.userCommentClinicalVideo.GetUserClinicalVideoCommentPageDto;
|
|
import com.example.caseData.dto.userCommentClinicalVideo.UserCommentClinicalVideoDto;
|
|
import com.example.caseData.exception.BusinessException;
|
|
import com.example.caseData.model.*;
|
|
import com.example.caseData.request.CaseClinicalArticleRequest.getUserClinicalArticleCommentPage;
|
|
import com.example.caseData.request.CaseClinicalVideoRequest.addClinicalVideoApp;
|
|
import com.example.caseData.request.CaseClinicalVideoRequest.addClinicalVideoComment;
|
|
import com.example.caseData.request.CaseClinicalVideoRequest.getClinicalVideoCommentPage;
|
|
import com.example.caseData.service.CaseClinicalVideoService;
|
|
import com.example.caseData.service.CaseClinicalVideoService;
|
|
import com.example.caseData.utils.Replace;
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.*;
|
|
|
|
@RestController
|
|
@RequestMapping("/api")
|
|
public class CaseClinicalVideoController {
|
|
@Resource
|
|
private CaseClinicalVideoDao caseClinicalVideoDao;
|
|
|
|
@Resource
|
|
private CaseClinicalVideoAuthorDao caseClinicalVideoAuthorDao;
|
|
|
|
@Resource
|
|
private StatsCaseClinicalDoctorDao statsCaseClinicalDoctorDao;
|
|
|
|
@Resource
|
|
private CaseClinicalDoctorDao caseClinicalDoctorDao;
|
|
|
|
@Resource
|
|
private BasicHospitalDao basicHospitalDao;
|
|
|
|
@Resource
|
|
private HttpServletRequest httpServletRequest;
|
|
|
|
@Resource
|
|
private CaseClinicalVideoService caseClinicalVideoService;
|
|
|
|
@Resource
|
|
private UserDao userDao;
|
|
|
|
@Resource
|
|
private UserCommentClinicalVideoDao userCommentClinicalVideoDao;
|
|
|
|
/**
|
|
* 临床病例库-视频-详情
|
|
*/
|
|
@GetMapping("/clinical/video/{video_id}")
|
|
public Response<CaseClinicalVideoDto> getClinicalHospitalSearchPage(
|
|
@PathVariable("video_id") String videoId
|
|
) {
|
|
// 获取视频数据
|
|
CaseClinicalVideoModel video = caseClinicalVideoDao.selectById(videoId);
|
|
if (video == null) {
|
|
return Response.error("非法视频");
|
|
}
|
|
|
|
// 检测作品状态
|
|
boolean result = caseClinicalVideoService.checkClinicalVideoStatus(video);
|
|
if (!result){
|
|
return Response.error(201,null,"该作品已被删除");
|
|
}
|
|
|
|
// 查找作者
|
|
LambdaQueryWrapper<CaseClinicalVideoAuthorModel> authorQueryWrapper = new LambdaQueryWrapper<>();
|
|
authorQueryWrapper.eq(CaseClinicalVideoAuthorModel::getVideoId, video.getVideoId());
|
|
List<CaseClinicalVideoAuthorModel> caseClinicalVideoAuthors = caseClinicalVideoAuthorDao.selectList(authorQueryWrapper);
|
|
for (CaseClinicalVideoAuthorModel author : caseClinicalVideoAuthors) {
|
|
// 查询医生
|
|
CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectById(author.getDoctorId());
|
|
|
|
// 查询医生所属医院
|
|
BasicHospitalModel basicHospital = basicHospitalDao.selectById(caseClinicalDoctor.getHospitalId());
|
|
caseClinicalDoctor.setBasicHospital(basicHospital);
|
|
|
|
author.setCaseClinicalDoctor(caseClinicalDoctor);
|
|
}
|
|
|
|
video.setAuthor(caseClinicalVideoAuthors);
|
|
|
|
CaseClinicalVideoDto g = CaseClinicalVideoDto.GetDto(video);
|
|
|
|
// 是否已收藏
|
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
|
if (userId != null) {
|
|
// 检测用户是否已收藏过
|
|
UserCollectClinicalVideoModel userCollectClinicalVideo = caseClinicalVideoService.getUserCollectClinicalVideoStatus(videoId,userId);
|
|
if (userCollectClinicalVideo != null) {
|
|
g.setCollect(true);
|
|
}
|
|
}
|
|
|
|
return Response.success(g);
|
|
}
|
|
|
|
/**
|
|
* 临床病例库-视频-收藏
|
|
*/
|
|
@PostMapping("/clinical/video/collect/{video_id}")
|
|
public Response<T> AddClinicalVideoCollect(
|
|
@PathVariable("video_id") String videoId
|
|
) {
|
|
|
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
|
|
|
if (userId == null) {
|
|
return Response.error("操作失败");
|
|
}
|
|
|
|
boolean res = caseClinicalVideoService.AddClinicalVideoCollect(videoId,userId);
|
|
if (!res){
|
|
return Response.error("操作失败");
|
|
}
|
|
|
|
return Response.success();
|
|
}
|
|
|
|
/**
|
|
* 临床病例库-视频-取消收藏
|
|
*/
|
|
@DeleteMapping("/clinical/video/collect/{video_id}")
|
|
public Response<T> DeleteClinicalVideoCollect(
|
|
@PathVariable("video_id") String videoId
|
|
) {
|
|
|
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
|
|
|
if (userId == null) {
|
|
return Response.error("操作失败");
|
|
}
|
|
|
|
boolean res = caseClinicalVideoService.DeleteClinicalVideoCollect(videoId,userId);
|
|
if (!res){
|
|
return Response.error("操作失败");
|
|
}
|
|
|
|
return Response.success();
|
|
}
|
|
|
|
/**
|
|
* 临床病例库-视频-新增评论
|
|
*/
|
|
@PostMapping("/clinical/video/comment/{video_id}")
|
|
public Response<T> AddClinicalVideoComment(
|
|
@PathVariable("video_id") String videoId,
|
|
@Validated()
|
|
@RequestBody addClinicalVideoComment request
|
|
) {
|
|
|
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
|
|
|
if (userId == null) {
|
|
return Response.error("操作失败");
|
|
}
|
|
|
|
try {
|
|
boolean res = caseClinicalVideoService.AddClinicalVideoComment(videoId,userId,request);
|
|
if (!res){
|
|
return Response.error("操作失败");
|
|
}
|
|
} catch (BusinessException e) {
|
|
return Response.error(e.getMessage());
|
|
}
|
|
|
|
return Response.success();
|
|
}
|
|
|
|
/**
|
|
* 临床病例库-视频-评论-删除
|
|
*/
|
|
@DeleteMapping("/clinical/video/comment/{comment_id}")
|
|
public Response<T> DeleteClinicalVideoComment(
|
|
@PathVariable("comment_id") String commentId
|
|
) {
|
|
|
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
|
|
|
if (userId == null) {
|
|
return Response.error("操作失败");
|
|
}
|
|
|
|
try {
|
|
boolean res = caseClinicalVideoService.DeleteClinicalVideoComment(commentId,userId);
|
|
if (!res){
|
|
return Response.error("操作失败");
|
|
}
|
|
} catch (BusinessException e) {
|
|
return Response.error(e.getMessage());
|
|
}
|
|
|
|
return Response.success();
|
|
}
|
|
|
|
/**
|
|
* 临床病例库-视频-评论-置顶
|
|
*/
|
|
@PutMapping("/clinical/video/comment/top/{comment_id}")
|
|
public Response<T> AddTopClinicalVideoComment(
|
|
@PathVariable("comment_id") String commentId
|
|
) {
|
|
|
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
|
|
|
if (userId == null) {
|
|
return Response.error("操作失败");
|
|
}
|
|
|
|
try {
|
|
boolean res = caseClinicalVideoService.AddTopClinicalVideoComment(commentId,userId);
|
|
if (!res){
|
|
return Response.error("操作失败");
|
|
}
|
|
} catch (BusinessException e) {
|
|
return Response.error(e.getMessage());
|
|
}
|
|
|
|
return Response.success();
|
|
}
|
|
|
|
/**
|
|
* 临床病例库-视频-评论-取消置顶
|
|
*/
|
|
@DeleteMapping("/clinical/video/comment/top/{comment_id}")
|
|
public Response<T> deleteTopClinicalVideoComment(
|
|
@PathVariable("comment_id") String commentId
|
|
) {
|
|
|
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
|
|
|
if (userId == null) {
|
|
return Response.error("操作失败");
|
|
}
|
|
|
|
try {
|
|
boolean res = caseClinicalVideoService.deleteTopClinicalVideoComment(commentId,userId);
|
|
if (!res){
|
|
return Response.error("操作失败");
|
|
}
|
|
} catch (BusinessException e) {
|
|
return Response.error(e.getMessage());
|
|
}
|
|
|
|
return Response.success();
|
|
}
|
|
|
|
/**
|
|
* 临床病例库-视频-评论-列表
|
|
*/
|
|
@PostMapping("/clinical/video/comment/page")
|
|
public Response<Map<String, Object>> getClinicalVideoCommentPage(
|
|
@Validated()
|
|
@RequestBody getClinicalVideoCommentPage request
|
|
) {
|
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
|
|
|
// 获取当前登录用户数据
|
|
UserModel user = userDao.selectById(Long.valueOf(userId));
|
|
if (user == null) {
|
|
return Response.error();
|
|
}
|
|
|
|
request.validateForPage();
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
Page<UserCommentClinicalVideoDto> page = new Page<>(request.getPage(), request.getPageSize());
|
|
|
|
// 获取视频评论数据
|
|
IPage<UserCommentClinicalVideoDto> resultPage = userCommentClinicalVideoDao.getClinicalVideoCommentPage(
|
|
page,
|
|
request.getVideoId(),
|
|
request.getRootId()
|
|
);
|
|
|
|
// 获取视频数据
|
|
CaseClinicalVideoModel video = caseClinicalVideoDao.selectById(request.getVideoId());
|
|
if (video == null) {
|
|
return Response.error();
|
|
}
|
|
|
|
if (video.getVideoStatus() != 1){
|
|
return Response.error();
|
|
}
|
|
|
|
// 获取视频作者数据
|
|
LambdaQueryWrapper<CaseClinicalVideoAuthorModel> authorQueryWrapper = new LambdaQueryWrapper<>();
|
|
authorQueryWrapper.eq(CaseClinicalVideoAuthorModel::getVideoId, request.getVideoId());
|
|
List<CaseClinicalVideoAuthorModel> caseClinicalVideoAuthors = caseClinicalVideoAuthorDao.selectList(authorQueryWrapper);
|
|
for (CaseClinicalVideoAuthorModel author : caseClinicalVideoAuthors) {
|
|
// 查询医生
|
|
CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectById(author.getDoctorId());
|
|
if (caseClinicalDoctor == null) {
|
|
return Response.error();
|
|
}
|
|
|
|
// 处理是否本人评论
|
|
for (UserCommentClinicalVideoDto dto : resultPage.getRecords()) {
|
|
if (Objects.equals(dto.getUserIden(), caseClinicalDoctor.getDoctorIden())){
|
|
dto.setIsAuthor(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 处理返回值
|
|
for (UserCommentClinicalVideoDto dto : resultPage.getRecords()) {
|
|
// 去除用户唯一标识
|
|
dto.setUserIden(null);
|
|
|
|
// 图片
|
|
dto.setCommentImage(Replace.addOssDomain(dto.getCommentImage()));
|
|
|
|
// 获取次级评论
|
|
if (request.getIsHaveSubComment() == 1){
|
|
if (dto.getRootId() == null){
|
|
List<UserCommentClinicalVideoDto> subComments = userCommentClinicalVideoDao.getClinicalVideoCommentList(
|
|
dto.getVideoId(),
|
|
dto.getCommentId(),
|
|
5
|
|
);
|
|
|
|
dto.setSubComment(subComments);
|
|
}
|
|
}
|
|
}
|
|
|
|
resultMap.put("page", resultPage.getCurrent());
|
|
resultMap.put("pageSize", resultPage.getSize());
|
|
resultMap.put("total", resultPage.getTotal());
|
|
resultMap.put("data", resultPage.getRecords());
|
|
return Response.success(resultMap);
|
|
}
|
|
|
|
/**
|
|
* 临床病例库-视频-评论-分页-用户
|
|
*/
|
|
@PostMapping("/clinical/video/user/comment/page")
|
|
public Response<Map<String, Object>> getUserClinicalVideoCommentPage(
|
|
@Validated()
|
|
@RequestBody getUserClinicalArticleCommentPage request
|
|
) {
|
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
|
|
|
// 获取当前登录用户数据
|
|
UserModel user = userDao.selectById(Long.valueOf(userId));
|
|
if (user == null) {
|
|
return Response.error();
|
|
}
|
|
|
|
request.validateForPage();
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
Page<UserCommentClinicalArticleDto> page = new Page<>(request.getPage(), request.getPageSize());
|
|
|
|
// 获取文章评论数据
|
|
IPage<GetUserClinicalVideoCommentPageDto> resultPage = userCommentClinicalVideoDao.getUserClinicalVideoCommentPage(
|
|
page,
|
|
userId
|
|
);
|
|
|
|
for (GetUserClinicalVideoCommentPageDto dto : resultPage.getRecords()){
|
|
dto.setAuthor(new ArrayList<>());
|
|
|
|
// 获取文章作者数据
|
|
LambdaQueryWrapper<CaseClinicalVideoAuthorModel> authorQueryWrapper = new LambdaQueryWrapper<>();
|
|
authorQueryWrapper.eq(CaseClinicalVideoAuthorModel::getVideoId, dto.getVideoId());
|
|
List<CaseClinicalVideoAuthorModel> caseClinicalVideoAuthors = caseClinicalVideoAuthorDao.selectList(authorQueryWrapper);
|
|
for (CaseClinicalVideoAuthorModel author : caseClinicalVideoAuthors) {
|
|
GetUserClinicalVideoCommentPageDto.CaseClinicalVideoAuthorDto authorDto = new GetUserClinicalVideoCommentPageDto.CaseClinicalVideoAuthorDto();
|
|
|
|
// 查询医生
|
|
CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectById(author.getDoctorId());
|
|
if (caseClinicalDoctor == null) {
|
|
return Response.error();
|
|
}
|
|
authorDto.setDoctorName(caseClinicalDoctor.getDoctorName());
|
|
dto.getAuthor().add(authorDto);
|
|
}
|
|
}
|
|
|
|
resultMap.put("page", resultPage.getCurrent());
|
|
resultMap.put("pageSize", resultPage.getSize());
|
|
resultMap.put("total", resultPage.getTotal());
|
|
resultMap.put("data", resultPage.getRecords());
|
|
return Response.success(resultMap);
|
|
}
|
|
|
|
/**
|
|
* 临床病例库-视频-同步app视频
|
|
*/
|
|
@PostMapping("/app/clinical/video")
|
|
public Response<T> AddClinicalVideoApp(
|
|
@Validated()
|
|
@RequestBody addClinicalVideoApp request
|
|
) {
|
|
// try {
|
|
// boolean res = caseClinicalVideoService.AddClinicalVideoApp(request);
|
|
// if (!res){
|
|
// return Response.error("操作失败");
|
|
// }
|
|
// } catch (BusinessException e) {
|
|
// return Response.error(e.getMessage());
|
|
// }
|
|
|
|
return Response.success();
|
|
}
|
|
}
|