787 lines
29 KiB
Java
787 lines
29 KiB
Java
package com.example.caseData.service;
|
||
|
||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
import com.example.caseData.dao.*;
|
||
import com.example.caseData.exception.BusinessException;
|
||
import com.example.caseData.extend.app.Base;
|
||
import com.example.caseData.extend.app.UserInfo.GetUserInfoResponse;
|
||
import com.example.caseData.extend.app.UserInfo.UserInfo;
|
||
import com.example.caseData.extend.app.UserPoint.UserPoint;
|
||
import com.example.caseData.extend.app.Video.Video;
|
||
import com.example.caseData.extend.app.label.Label;
|
||
import com.example.caseData.model.*;
|
||
import com.example.caseData.model.UserCollectClinicalVideoModel;
|
||
import com.example.caseData.request.CaseClinicalVideoRequest.addClinicalVideoApp;
|
||
import com.example.caseData.request.CaseClinicalVideoRequest.addClinicalVideoComment;
|
||
import com.example.caseData.utils.Replace;
|
||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||
import jakarta.annotation.Resource;
|
||
import jakarta.servlet.http.HttpServletRequest;
|
||
import jakarta.validation.ConstraintViolation;
|
||
import jakarta.validation.Validation;
|
||
import jakarta.validation.Validator;
|
||
import org.apache.commons.io.IOUtils;
|
||
import org.springframework.stereotype.Service;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||
|
||
import java.lang.reflect.Field;
|
||
import java.nio.charset.StandardCharsets;
|
||
import java.time.LocalDateTime;
|
||
import java.time.format.DateTimeFormatter;
|
||
import java.util.*;
|
||
|
||
//import static com.baomidou.mybatisplus.extension.toolkit.Db.removeById;
|
||
//import static com.baomidou.mybatisplus.extension.toolkit.Db.save;
|
||
|
||
@Service
|
||
public class CaseClinicalVideoService {
|
||
@Resource
|
||
private UserCollectClinicalVideoDao userCollectClinicalVideoDao;
|
||
|
||
@Resource
|
||
private CaseClinicalVideoDao caseClinicalVideoDao;
|
||
|
||
@Resource
|
||
private CaseClinicalVideoLabelDao caseClinicalVideoLabelDao;
|
||
|
||
@Resource
|
||
private StatsCaseClinicalDao statsCaseClinicalDao;
|
||
|
||
@Resource
|
||
private UserDao userDao;
|
||
|
||
@Resource
|
||
private BasicHospitalDao basicHospitalDao;
|
||
|
||
@Resource
|
||
private StatsCaseClinicalHospitalDao statsCaseClinicalHospitalDao;
|
||
|
||
@Resource
|
||
private StatsCaseClinicalDoctorDao statsCaseClinicalDoctorDao;
|
||
|
||
@Resource
|
||
private CaseClinicalVideoAuthorDao caseClinicalVideoAuthorDao;
|
||
|
||
@Resource
|
||
private CaseClinicalDoctorDao caseClinicalDoctorDao;
|
||
|
||
@Resource
|
||
private BasicSensitiveWordService basicSensitiveWordService;
|
||
|
||
@Resource
|
||
private UserCommentClinicalVideoDao userCommentClinicalVideoDao;
|
||
|
||
@Resource
|
||
private CaseClinicalLabelService caseClinicalLabelService;
|
||
|
||
@Resource
|
||
private StatsCaseClinicalLabelDao statsCaseClinicalLabelDao;
|
||
|
||
@Resource
|
||
private Video Video;
|
||
|
||
@Resource
|
||
private UserInfo userInfo;
|
||
|
||
@Resource
|
||
private UserService userService;
|
||
|
||
@Resource
|
||
private CaseClinicalService caseClinicalService;
|
||
|
||
/**
|
||
* 新增收藏-临床病例库-视频
|
||
* @param videoId 视频id
|
||
* @param userId 用户id
|
||
* @return bool
|
||
*/
|
||
@Transactional
|
||
public boolean AddClinicalVideoCollect(String videoId,String userId){
|
||
// 检测用户是否已收藏过
|
||
UserCollectClinicalVideoModel userCollectClinicalVideo = getUserCollectClinicalVideoStatus(videoId,userId);
|
||
if (userCollectClinicalVideo != null) {
|
||
return true;
|
||
}
|
||
|
||
// 新增收藏
|
||
UserCollectClinicalVideoModel userCollectClinicalVideoData = new UserCollectClinicalVideoModel();
|
||
userCollectClinicalVideoData.setUserId(Long.valueOf(userId));
|
||
userCollectClinicalVideoData.setVideoId(Long.valueOf(videoId));
|
||
int res = userCollectClinicalVideoDao.insert(userCollectClinicalVideoData);
|
||
if (res <= 0){
|
||
return false;
|
||
}
|
||
|
||
// 新增统计字段
|
||
boolean r = IncClinicalVideoStats(videoId,2,1);
|
||
if (!r){
|
||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 取消收藏-临床病例库-视频
|
||
* @param videoId 视频id
|
||
* @param userId 用户id
|
||
* @return bool
|
||
*/
|
||
@Transactional
|
||
public boolean DeleteClinicalVideoCollect(String videoId,String userId){
|
||
// 检测用户是否已收藏过
|
||
UserCollectClinicalVideoModel userCollectClinicalVideo = getUserCollectClinicalVideoStatus(videoId,userId);
|
||
if (userCollectClinicalVideo == null) {
|
||
return true;
|
||
}
|
||
|
||
// 删除收藏
|
||
int res = userCollectClinicalVideoDao.deleteById(userCollectClinicalVideo.getCollectId());
|
||
if (res <= 0){
|
||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||
return false;
|
||
}
|
||
|
||
// 减少视频的统计字段
|
||
boolean r = DecClinicalVideoStats(videoId,2,1);
|
||
if (!r){
|
||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 新增评论-临床病例库-视频
|
||
* @param videoId 视频id
|
||
* @param userId 用户id
|
||
* @return bool
|
||
*/
|
||
@Transactional
|
||
public boolean AddClinicalVideoComment(String videoId, String userId, addClinicalVideoComment request){
|
||
// 获取视频数据
|
||
CaseClinicalVideoModel video = caseClinicalVideoDao.selectById(videoId);
|
||
if (video == null) {
|
||
throw new BusinessException("非法视频");
|
||
}
|
||
|
||
if (video.getVideoStatus() != 1){
|
||
throw new BusinessException("非法视频");
|
||
}
|
||
|
||
// 处理评论内容
|
||
BasicSensitiveWordService.FilterResult result = basicSensitiveWordService.filter(request.getContent());
|
||
if (result.hasSensitive == 1){
|
||
throw new BusinessException("存在敏感词,请修改后提交");
|
||
}
|
||
|
||
// 新增评论
|
||
UserCommentClinicalVideoModel userCommentClinicalVideoData = new UserCommentClinicalVideoModel();
|
||
userCommentClinicalVideoData.setUserId(Long.valueOf(userId));
|
||
userCommentClinicalVideoData.setVideoId(Long.valueOf(videoId));
|
||
userCommentClinicalVideoData.setStatus(1);
|
||
userCommentClinicalVideoData.setIsSensitive(0);
|
||
userCommentClinicalVideoData.setContent(request.getContent());
|
||
userCommentClinicalVideoData.setCommentImage(Replace.removeOssDomain(request.getCommentImage()));
|
||
|
||
// 评论根id
|
||
if (request.getRootId() != null) {
|
||
userCommentClinicalVideoData.setRootId(Long.valueOf(request.getRootId()));
|
||
}
|
||
|
||
// 评论父级id
|
||
if (request.getParentId() != null) {
|
||
userCommentClinicalVideoData.setParentId(Long.valueOf(request.getParentId()));
|
||
}
|
||
|
||
int res = userCommentClinicalVideoDao.insert(userCommentClinicalVideoData);
|
||
if (res <= 0){
|
||
return false;
|
||
}
|
||
|
||
// 新增文章的统计字段
|
||
boolean r = IncClinicalVideoStats(videoId,3,1);
|
||
if (!r){
|
||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||
return false;
|
||
}
|
||
|
||
// 发放积分
|
||
userService.ReportUserScore(videoId,2,userId);
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 删除评论-临床病例库-视频
|
||
* @param commentId 评论id
|
||
* @param userId 用户id
|
||
* @return bool
|
||
*/
|
||
@Transactional
|
||
public boolean DeleteClinicalVideoComment(String commentId, String userId){
|
||
// 获取评论数据
|
||
UserCommentClinicalVideoModel comment = userCommentClinicalVideoDao.selectById(commentId);
|
||
if (comment == null) {
|
||
return false;
|
||
}
|
||
|
||
// 获取视频数据
|
||
CaseClinicalVideoModel video = caseClinicalVideoDao.selectById(comment.getVideoId());
|
||
if (video == null) {
|
||
return false;
|
||
}
|
||
|
||
if (video.getVideoStatus() != 1){
|
||
return false;
|
||
}
|
||
|
||
// 检测用户是否视频作者
|
||
if (!Objects.equals(comment.getUserId(), Long.valueOf(userId))){
|
||
// 检测用户是否文章作者
|
||
boolean isAuthor = checkUserIsVideoAuthor(String.valueOf(video.getVideoId()),userId);
|
||
if (!isAuthor) {
|
||
System.out.println(333);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
// 删除评论
|
||
int res = userCommentClinicalVideoDao.deleteById(comment.getCommentId());
|
||
if (res <= 0){
|
||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||
return false;
|
||
}
|
||
|
||
// 减少文章的统计字段
|
||
boolean r = DecClinicalVideoStats(String.valueOf(comment.getVideoId()),2,1);
|
||
if (!r){
|
||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 置顶评论-临床病例库-视频
|
||
* @param commentId 评论id
|
||
* @param userId 用户id
|
||
* @return bool
|
||
*/
|
||
@Transactional
|
||
public boolean AddTopClinicalVideoComment(String commentId, String userId){
|
||
// 获取评论数据
|
||
UserCommentClinicalVideoModel comment = userCommentClinicalVideoDao.selectById(commentId);
|
||
if (comment == null) {
|
||
return false;
|
||
}
|
||
|
||
// 获取视频数据
|
||
CaseClinicalVideoModel video = caseClinicalVideoDao.selectById(comment.getVideoId());
|
||
if (video == null) {
|
||
return false;
|
||
}
|
||
|
||
if (video.getVideoStatus() != 1){
|
||
return false;
|
||
}
|
||
|
||
// 检测用户是否视频作者
|
||
boolean isAuthor = checkUserIsVideoAuthor(String.valueOf(comment.getVideoId()),userId);
|
||
if (!isAuthor) {
|
||
return false;
|
||
}
|
||
|
||
if (comment.getIsTop() == 1){
|
||
return true;
|
||
}
|
||
|
||
// 置顶评论
|
||
comment.setIsTop(1);
|
||
userCommentClinicalVideoDao.updateById(comment);
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 取消置顶评论-临床病例库-视频
|
||
* @param commentId 评论id
|
||
* @param userId 用户id
|
||
* @return bool
|
||
*/
|
||
@Transactional
|
||
public boolean deleteTopClinicalVideoComment(String commentId, String userId){
|
||
// 获取评论数据
|
||
UserCommentClinicalVideoModel comment = userCommentClinicalVideoDao.selectById(commentId);
|
||
if (comment == null) {
|
||
return false;
|
||
}
|
||
|
||
// 获取视频数据
|
||
CaseClinicalVideoModel video = caseClinicalVideoDao.selectById(comment.getVideoId());
|
||
if (video == null) {
|
||
return false;
|
||
}
|
||
|
||
if (video.getVideoStatus() != 1){
|
||
return false;
|
||
}
|
||
|
||
// 检测用户是否视频作者
|
||
boolean isAuthor = checkUserIsVideoAuthor(String.valueOf(comment.getVideoId()),userId);
|
||
if (!isAuthor) {
|
||
return false;
|
||
}
|
||
|
||
// 取消置顶评论
|
||
if (comment.getIsTop() == 0){
|
||
return true;
|
||
}
|
||
|
||
// 置顶评论
|
||
comment.setIsTop(0);
|
||
userCommentClinicalVideoDao.updateById(comment);
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 检测用户是否视频作者
|
||
* @param videoId 视频id
|
||
* @param userId 用户id
|
||
* @return bool 是否作者
|
||
*/
|
||
public boolean checkUserIsVideoAuthor(String videoId,String userId){
|
||
// 获取当前登录用户数据
|
||
UserModel user = userDao.selectById(Long.valueOf(userId));
|
||
if (user == null) {
|
||
return false;
|
||
}
|
||
|
||
// 当前用户是否是作者之一
|
||
boolean isAuthor = false;
|
||
|
||
// 获取视频作者数据
|
||
LambdaQueryWrapper<CaseClinicalVideoAuthorModel> authorQueryWrapper = new LambdaQueryWrapper<>();
|
||
authorQueryWrapper.eq(CaseClinicalVideoAuthorModel::getVideoId, videoId);
|
||
List<CaseClinicalVideoAuthorModel> caseClinicalVideoAuthors = caseClinicalVideoAuthorDao.selectList(authorQueryWrapper);
|
||
for (CaseClinicalVideoAuthorModel author : caseClinicalVideoAuthors) {
|
||
// 查询医生
|
||
CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectById(author.getDoctorId());
|
||
if (caseClinicalDoctor == null) {
|
||
return false;
|
||
}
|
||
|
||
if (Objects.equals(caseClinicalDoctor.getDoctorIden(), user.getUserIden())){
|
||
isAuthor = true;
|
||
}
|
||
}
|
||
|
||
return isAuthor;
|
||
}
|
||
|
||
/**
|
||
* 获取用户收藏数据
|
||
* @param videoId 视频id
|
||
* @param userId 用户id
|
||
* @return bool false:未收藏 true:已收藏
|
||
*/
|
||
public UserCollectClinicalVideoModel getUserCollectClinicalVideoStatus(String videoId, String userId){
|
||
// 检测用户是否已收藏过
|
||
LambdaQueryWrapper<UserCollectClinicalVideoModel> mapQueryWrapper = new LambdaQueryWrapper<>();
|
||
mapQueryWrapper.eq(UserCollectClinicalVideoModel::getUserId, userId);
|
||
mapQueryWrapper.eq(UserCollectClinicalVideoModel::getVideoId, videoId);
|
||
|
||
return userCollectClinicalVideoDao.selectOne(mapQueryWrapper);
|
||
}
|
||
|
||
/**
|
||
* 新增视频的统计字段
|
||
* @param videoId 视频id
|
||
* @param type 类型:1:阅读量 2:收藏量 3:评论数 4:文章数
|
||
*/
|
||
@Transactional
|
||
public boolean IncClinicalVideoStats(String videoId,Integer type,Integer num){
|
||
try {
|
||
String caseClinicalVideoField = ""; // 具体文章
|
||
String statsCaseClinicalField = ""; // 全部文章
|
||
|
||
// 阅读
|
||
if (type == 1){
|
||
caseClinicalVideoField = "read_num"; // 具体文章
|
||
statsCaseClinicalField = "video_read_num"; // 全部文章
|
||
}
|
||
|
||
// 收藏
|
||
if (type == 2){
|
||
caseClinicalVideoField = "collect_num"; // 具体文章
|
||
statsCaseClinicalField = "video_collect_num"; // 全部文章
|
||
}
|
||
|
||
// 评论
|
||
if (type == 3){
|
||
caseClinicalVideoField = "comment_num"; // 具体文章
|
||
statsCaseClinicalField = "video_comment_num"; // 全部文章
|
||
}
|
||
|
||
// 文章数
|
||
if (type == 4){
|
||
statsCaseClinicalField = "video_num"; // 全部文章
|
||
}
|
||
|
||
if (!caseClinicalVideoField.isEmpty()){
|
||
caseClinicalVideoDao.inc(Long.valueOf(videoId),caseClinicalVideoField,num);
|
||
}
|
||
|
||
statsCaseClinicalDao.inc(1L,statsCaseClinicalField,num);
|
||
|
||
return true;
|
||
} catch (Exception e) {
|
||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 减少视频的统计字段
|
||
* @param videoId 文章id
|
||
* @param type 类型:1:阅读量 2:收藏量 3:评论数 4:文章数
|
||
*/
|
||
@Transactional
|
||
public boolean DecClinicalVideoStats(String videoId,Integer type,Integer num){
|
||
try {
|
||
String caseClinicalVideoField = ""; // 具体文章
|
||
String statsCaseClinicalField = ""; // 全部文章
|
||
|
||
// 阅读
|
||
if (type == 1){
|
||
caseClinicalVideoField = "read_num"; // 具体文章
|
||
statsCaseClinicalField = "video_read_num"; // 全部文章
|
||
}
|
||
|
||
// 收藏
|
||
if (type == 2){
|
||
caseClinicalVideoField = "collect_num"; // 具体文章
|
||
statsCaseClinicalField = "video_collect_num"; // 全部文章
|
||
}
|
||
|
||
// 评论
|
||
if (type == 3){
|
||
caseClinicalVideoField = "comment_num"; // 具体文章
|
||
statsCaseClinicalField = "video_comment_num"; // 全部文章
|
||
}
|
||
|
||
// 文章数
|
||
if (type == 4){
|
||
statsCaseClinicalField = "video_num"; // 全部文章
|
||
}
|
||
|
||
if (!caseClinicalVideoField.isEmpty()){
|
||
caseClinicalVideoDao.dec(Long.valueOf(videoId),caseClinicalVideoField,num);
|
||
}
|
||
|
||
statsCaseClinicalDao.dec(1L,statsCaseClinicalField,num);
|
||
|
||
return true;
|
||
} catch (Exception e) {
|
||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 检测作品状态
|
||
*/
|
||
public boolean checkClinicalVideoStatus(CaseClinicalVideoModel caseClinicalVideo){
|
||
// 删除状态
|
||
if (caseClinicalVideo.getDeleteStatus() == 1){
|
||
return false;
|
||
}
|
||
|
||
// 状态(1:正常 2:禁用)
|
||
if (caseClinicalVideo.getVideoStatus() == 2){
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 临床病例库-视频-同步app视频
|
||
* @return bool
|
||
*/
|
||
@Transactional
|
||
public boolean AddClinicalVideoApp(HttpServletRequest request){
|
||
try {
|
||
// 1. 手动读取请求体并转为 addClinicalVideoApp 对象
|
||
ObjectMapper objectMapper = new ObjectMapper();
|
||
addClinicalVideoApp r = objectMapper.readValue(request.getInputStream(), addClinicalVideoApp.class);
|
||
|
||
// 2. 自动校验(@Validated)
|
||
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
|
||
Set<ConstraintViolation<addClinicalVideoApp>> violations = validator.validate(r);
|
||
if (!violations.isEmpty()) {
|
||
String errorMessage = violations.iterator().next().getMessage();
|
||
throw new BusinessException("-1", errorMessage);
|
||
}
|
||
|
||
// 检测签名
|
||
Video.checkSign(request,"26e8675f44565b1ed4eaaa0fcf3531d7",r,objectMapper);
|
||
|
||
// 获取视频数据
|
||
LambdaQueryWrapper<CaseClinicalVideoModel> videoQueryWrapper = new LambdaQueryWrapper<>();
|
||
videoQueryWrapper.eq(CaseClinicalVideoModel::getVideoNo, r.getVideoNo());
|
||
CaseClinicalVideoModel caseClinicalVideo = caseClinicalVideoDao.selectOne(videoQueryWrapper);
|
||
|
||
// 修改
|
||
if (Objects.equals(r.getAction(), "update")){
|
||
if (caseClinicalVideo == null){
|
||
r.setAction("add");
|
||
}
|
||
}
|
||
|
||
System.out.println(r);
|
||
// 新增
|
||
if (Objects.equals(r.getAction(), "add")){
|
||
if (caseClinicalVideo != null){
|
||
if (caseClinicalVideo.getDeleteStatus() == 0){
|
||
// 已存在该视频
|
||
return true;
|
||
}else{
|
||
caseClinicalVideo.setDeleteStatus(0);
|
||
caseClinicalVideo.setVideoTitle(r.getVideoTitle());
|
||
caseClinicalVideo.setVideoNo(r.getVideoNo());
|
||
|
||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||
LocalDateTime pushDate = LocalDateTime.parse(r.getPushDate(), formatter);
|
||
caseClinicalVideo.setPushDate(pushDate);
|
||
caseClinicalVideo.setIsLink(r.getIsLink());
|
||
caseClinicalVideo.setIsLinkUrl(r.getIsLinkUrl());
|
||
caseClinicalVideoDao.updateById(caseClinicalVideo);
|
||
}
|
||
}else{
|
||
// 新增视频
|
||
caseClinicalVideo = new CaseClinicalVideoModel();
|
||
caseClinicalVideo.setVideoTitle(r.getVideoTitle());
|
||
caseClinicalVideo.setVideoNo(r.getVideoNo());
|
||
|
||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||
LocalDateTime pushDate = LocalDateTime.parse(r.getPushDate(), formatter);
|
||
caseClinicalVideo.setPushDate(pushDate);
|
||
caseClinicalVideo.setIsLink(r.getIsLink());
|
||
caseClinicalVideo.setIsLinkUrl(r.getIsLinkUrl());
|
||
int res = caseClinicalVideoDao.insert(caseClinicalVideo);
|
||
if (res <= 0){
|
||
throw new BusinessException("-1", "内部错误,添加视频失败");
|
||
}
|
||
}
|
||
|
||
// 新增统计
|
||
IncClinicalVideoStats(String.valueOf(caseClinicalVideo.getVideoId()),4,1);
|
||
|
||
// 作者处理
|
||
if (r.getAuthor() != null) {
|
||
AddClinicalVideoAppAuthor(caseClinicalVideo,r);
|
||
}
|
||
|
||
// 标签处理
|
||
if (r.getLabel() != null) {
|
||
AddClinicalVideoAppLabel(caseClinicalVideo,r);
|
||
}
|
||
}
|
||
|
||
// 修改
|
||
if (Objects.equals(r.getAction(), "update")){
|
||
if (caseClinicalVideo == null){
|
||
throw new BusinessException("-1", "无法完成此操作");
|
||
}
|
||
|
||
// 文章主体
|
||
if (!Objects.equals(caseClinicalVideo.getVideoNo(), r.getVideoNo())){
|
||
caseClinicalVideo.setVideoNo(r.getVideoNo());
|
||
}
|
||
|
||
if (!Objects.equals(caseClinicalVideo.getIsLink(), r.getIsLink())){
|
||
caseClinicalVideo.setIsLink(r.getIsLink());
|
||
|
||
if (!Objects.equals(caseClinicalVideo.getIsLinkUrl(), r.getIsLinkUrl())){
|
||
caseClinicalVideo.setIsLinkUrl(r.getIsLinkUrl());
|
||
}
|
||
}
|
||
|
||
caseClinicalVideoDao.updateById(caseClinicalVideo);
|
||
|
||
// 作者处理
|
||
if (r.getAuthor() != null) {
|
||
AddClinicalVideoAppAuthor(caseClinicalVideo,r);
|
||
}
|
||
|
||
// 标签处理
|
||
if (r.getLabel() != null) {
|
||
AddClinicalVideoAppLabel(caseClinicalVideo,r);
|
||
}
|
||
}
|
||
|
||
// 删除
|
||
if (Objects.equals(r.getAction(), "delete")){
|
||
if (caseClinicalVideo == null){
|
||
return true;
|
||
}
|
||
|
||
deleteClinicalVideo(caseClinicalVideo);
|
||
}
|
||
} catch (Exception e) {
|
||
throw new BusinessException("-1", e.getMessage());
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 临床病例库-视频-同步app视频-作者处理
|
||
* @param caseClinicalVideo
|
||
* @param r
|
||
*/
|
||
@Transactional
|
||
public void AddClinicalVideoAppAuthor(CaseClinicalVideoModel caseClinicalVideo,addClinicalVideoApp r){
|
||
// 获取全部作者
|
||
LambdaQueryWrapper<CaseClinicalVideoAuthorModel> authorQueryWrapper = new LambdaQueryWrapper<>();
|
||
authorQueryWrapper.eq(CaseClinicalVideoAuthorModel::getVideoId, caseClinicalVideo.getVideoId());
|
||
List<CaseClinicalVideoAuthorModel> caseClinicalVideoAuthors = caseClinicalVideoAuthorDao.selectList(authorQueryWrapper);
|
||
for (CaseClinicalVideoAuthorModel author : caseClinicalVideoAuthors){
|
||
// 获取医生数据
|
||
LambdaQueryWrapper<CaseClinicalDoctorModel> doctorQueryWrapper = new LambdaQueryWrapper<>();
|
||
doctorQueryWrapper.eq(CaseClinicalDoctorModel::getDoctorId, author.getDoctorId());
|
||
CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectOne(doctorQueryWrapper);
|
||
if (caseClinicalDoctor == null) {
|
||
throw new BusinessException("-1", "无法完成此操作");
|
||
}
|
||
|
||
// 获取医院数据
|
||
BasicHospitalModel basicHospital = basicHospitalDao.selectById(caseClinicalDoctor.getHospitalId());
|
||
if (basicHospital == null) {
|
||
throw new BusinessException("-1", "无法完成此操作");
|
||
}
|
||
|
||
// 减少作者统计
|
||
caseClinicalService.DecStatsCaseClinicalDoctor(String.valueOf(caseClinicalDoctor.getDoctorId()),2);
|
||
|
||
// 减少医院统计
|
||
caseClinicalService.DecStatsCaseClinicalHospital(String.valueOf(caseClinicalDoctor.getHospitalId()),2);
|
||
|
||
// 删除该作者
|
||
caseClinicalVideoAuthorDao.deleteById(author.getAuthorId());
|
||
}
|
||
|
||
// 新增新的作者
|
||
|
||
// 获取app用户数据
|
||
for (addClinicalVideoApp.Author author : r.getAuthor()){
|
||
CaseClinicalDoctorModel caseClinicalDoctor = new CaseClinicalDoctorModel();
|
||
|
||
if (author.getDoctorIden() != null && !author.getDoctorIden().isEmpty()) {
|
||
GetUserInfoResponse result = userInfo.getUserInfoByUuid(author.getDoctorIden());
|
||
caseClinicalDoctor = userService.GetCaseClinicalDoctor(result);
|
||
}else{
|
||
GetUserInfoResponse result = new GetUserInfoResponse();
|
||
GetUserInfoResponse.ResponsData resultData = new GetUserInfoResponse.ResponsData();
|
||
resultData.setOfficeName(author.getDoctorName());
|
||
resultData.setRealname(author.getDoctorName());
|
||
resultData.setHospitalUuid(author.getHospitalIden());
|
||
result.setData(resultData);
|
||
caseClinicalDoctor = userService.GetCaseClinicalDoctor(result);
|
||
}
|
||
|
||
CaseClinicalVideoAuthorModel caseClinicalVideoAuthor = new CaseClinicalVideoAuthorModel();
|
||
caseClinicalVideoAuthor.setVideoId(caseClinicalVideo.getVideoId());
|
||
caseClinicalVideoAuthor.setDoctorId(String.valueOf(caseClinicalDoctor.getDoctorId()));
|
||
caseClinicalVideoAuthorDao.insert(caseClinicalVideoAuthor);
|
||
|
||
LocalDateTime lastPushDate = caseClinicalVideoDao.selectLastVideoPushDateByDoctorId(caseClinicalDoctor.getDoctorId());
|
||
|
||
// 新增作者统计
|
||
caseClinicalService.IncStatsCaseClinicalDoctor(String.valueOf(caseClinicalDoctor.getDoctorId()),2,lastPushDate);
|
||
|
||
// 新增医院统计
|
||
caseClinicalService.IncStatsCaseClinicalHospital(String.valueOf(caseClinicalDoctor.getHospitalId()),2,lastPushDate);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 临床病例库-视频-同步app视频-标签处理
|
||
* @param caseClinicalVideo
|
||
* @param r
|
||
*/
|
||
@Transactional
|
||
public void AddClinicalVideoAppLabel(CaseClinicalVideoModel caseClinicalVideo,addClinicalVideoApp r){
|
||
// 获取全部b标签
|
||
LambdaQueryWrapper<CaseClinicalVideoLabelModel> labelQueryWrapper = new LambdaQueryWrapper<>();
|
||
labelQueryWrapper.eq(CaseClinicalVideoLabelModel::getVideoId, caseClinicalVideo.getVideoId());
|
||
List<CaseClinicalVideoLabelModel> caseClinicalVideoLabels = caseClinicalVideoLabelDao.selectList(labelQueryWrapper);
|
||
for (CaseClinicalVideoLabelModel label : caseClinicalVideoLabels){
|
||
// 减少标签统计
|
||
caseClinicalService.DecStatsCaseClinicalLabel(label.getAppIden(),2);
|
||
|
||
// 删除视频标签
|
||
caseClinicalVideoLabelDao.deleteById(label.getVideoLabelId());
|
||
}
|
||
|
||
for (addClinicalVideoApp.Label label : r.getLabel()){
|
||
CaseClinicalVideoLabelModel caseClinicalVideoLabel = new CaseClinicalVideoLabelModel();
|
||
caseClinicalVideoLabel.setVideoId(caseClinicalVideo.getVideoId());
|
||
caseClinicalVideoLabel.setAppIden(label.getAppIden());
|
||
caseClinicalVideoLabel.setLabelName(label.getLabelName());
|
||
caseClinicalVideoLabelDao.insert(caseClinicalVideoLabel);
|
||
|
||
LocalDateTime lastPushDate = caseClinicalVideoDao.selectLastVideoPushDateByLabelId(label.getAppIden());
|
||
|
||
// 新增标签统计
|
||
caseClinicalService.IncStatsCaseClinicalLabel(label.getAppIden(),caseClinicalVideoLabel.getLabelName(),2,lastPushDate);
|
||
}
|
||
}
|
||
|
||
// 删除视频数据
|
||
@Transactional
|
||
public void deleteClinicalVideo(CaseClinicalVideoModel caseClinicalVideo){
|
||
// 修改视频为删除
|
||
caseClinicalVideo.setDeleteStatus(1);
|
||
caseClinicalVideoDao.updateById(caseClinicalVideo);
|
||
|
||
// 修改视频统计数量
|
||
DecClinicalVideoStats(String.valueOf(caseClinicalVideo.getVideoId()),4,1);
|
||
|
||
// 获取视频标签数据
|
||
LambdaQueryWrapper<CaseClinicalVideoLabelModel> labelQueryWrapper = new LambdaQueryWrapper<>();
|
||
labelQueryWrapper.eq(CaseClinicalVideoLabelModel::getVideoId, caseClinicalVideo.getVideoId());
|
||
List<CaseClinicalVideoLabelModel> caseClinicalVideoLabels = caseClinicalVideoLabelDao.selectList(labelQueryWrapper);
|
||
for (CaseClinicalVideoLabelModel label : caseClinicalVideoLabels){
|
||
// 减少标签统计
|
||
caseClinicalService.DecStatsCaseClinicalLabel(label.getAppIden(),2);
|
||
}
|
||
|
||
// 获取视频作者数据
|
||
LambdaQueryWrapper<CaseClinicalVideoAuthorModel> authorQueryWrapper = new LambdaQueryWrapper<>();
|
||
authorQueryWrapper.eq(CaseClinicalVideoAuthorModel::getVideoId, caseClinicalVideo.getVideoId());
|
||
List<CaseClinicalVideoAuthorModel> caseClinicalVideoAuthors = caseClinicalVideoAuthorDao.selectList(authorQueryWrapper);
|
||
for (CaseClinicalVideoAuthorModel author : caseClinicalVideoAuthors){
|
||
// 获取医生数据
|
||
LambdaQueryWrapper<CaseClinicalDoctorModel> doctorQueryWrapper = new LambdaQueryWrapper<>();
|
||
doctorQueryWrapper.eq(CaseClinicalDoctorModel::getDoctorId,author.getDoctorId());
|
||
CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectOne(doctorQueryWrapper);
|
||
if (caseClinicalDoctor == null) {
|
||
throw new BusinessException("-1", "无法完成此操作");
|
||
}
|
||
|
||
// 减少医生统计
|
||
caseClinicalService.DecStatsCaseClinicalDoctor(author.getDoctorId(),2);
|
||
|
||
// 减少医院统计
|
||
caseClinicalService.DecStatsCaseClinicalHospital(String.valueOf(caseClinicalDoctor.getHospitalId()),2);
|
||
}
|
||
}
|
||
}
|