新增了病例交流2

This commit is contained in:
wucongxing8150 2025-06-03 09:02:32 +08:00
parent 82c2055756
commit 9e1c30a81c
7 changed files with 585 additions and 11 deletions

View File

@ -6,14 +6,14 @@ 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.caseClinicalArticle.CaseClinicalArticleDto;
import com.example.caseData.dto.caseExchange.CaseExchangeDto;
import com.example.caseData.dto.caseExchangeVote.CaseExchangeVoteDto;
import com.example.caseData.dto.caseExchangeVoteOption.CaseExchangeVoteOptionDto;
import com.example.caseData.exception.BusinessException;
import com.example.caseData.model.*;
import com.example.caseData.request.CaseClinicalArticleRequest.addClinicalArticleComment;
import com.example.caseData.request.caseExchangeRequest.addCaseExchange;
import com.example.caseData.request.caseExchangeRequest.addCaseExchangeComment;
import com.example.caseData.request.caseExchangeRequest.getCaseExchangeCommentPage;
import com.example.caseData.request.caseExchangeRequest.getCaseExchangeSearchPage;
import com.example.caseData.service.CaseExchangeService;
import com.example.caseData.utils.Replace;
@ -26,6 +26,7 @@ import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@RestController
@RequestMapping("/api")
@ -345,4 +346,238 @@ public class CaseExchangeController {
return Response.success();
}
/**
* 病例交流-收藏
*/
@PostMapping("/exchange/collect/{exchange_id}")
public Response<T> AddCaseExchangeCollect(
@PathVariable("exchange_id") String exchangeId
) {
String userId = (String) httpServletRequest.getAttribute("userId");
if (userId == null) {
return Response.error("操作失败");
}
boolean res = caseExchangeService.AddCaseExchangeCollect(exchangeId,userId);
if (!res){
return Response.error("操作失败");
}
return Response.success();
}
/**
* 病例交流-取消收藏
*/
@DeleteMapping("/exchange/collect/{exchange_id}")
public Response<T> DeleteCaseExchangeCollect(
@PathVariable("exchange_id") String exchangeId
) {
String userId = (String) httpServletRequest.getAttribute("userId");
if (userId == null) {
return Response.error("操作失败");
}
boolean res = caseExchangeService.DeleteCaseExchangeCollect(exchangeId,userId);
if (!res){
return Response.error("操作失败");
}
return Response.success();
}
/**
* 病例交流-新增评论
*/
@PostMapping("/exchange/comment/{exchange_id}")
public Response<T> AddCaseExchangeComment(
@PathVariable("exchange_id") String exchangeId,
@Validated()
@RequestBody addCaseExchangeComment request
) {
String userId = (String) httpServletRequest.getAttribute("userId");
if (userId == null) {
return Response.error("操作失败");
}
try {
boolean res = caseExchangeService.AddCaseExchangeComment(exchangeId,userId,request);
if (!res){
return Response.error("操作失败");
}
} catch (BusinessException e) {
return Response.error(e.getMessage());
}
return Response.success();
}
/**
* 病例交流-评论-删除
*/
@DeleteMapping("/exchange/comment/{comment_id}")
public Response<T> DeleteCaseExchangeComment(
@PathVariable("comment_id") String commentId
) {
String userId = (String) httpServletRequest.getAttribute("userId");
if (userId == null) {
return Response.error("操作失败");
}
try {
boolean res = caseExchangeService.DeleteCaseExchangeComment(commentId,userId);
if (!res){
return Response.error("操作失败");
}
} catch (BusinessException e) {
return Response.error(e.getMessage());
}
return Response.success();
}
/**
* 病例交流-评论-置顶
*/
@PutMapping("/exchange/comment/top/{comment_id}")
public Response<T> AddTopCaseExchangeComment(
@PathVariable("comment_id") String commentId
) {
String userId = (String) httpServletRequest.getAttribute("userId");
if (userId == null) {
return Response.error("操作失败");
}
try {
boolean res = caseExchangeService.AddTopCaseExchangeComment(commentId,userId);
if (!res){
return Response.error("操作失败");
}
} catch (BusinessException e) {
return Response.error(e.getMessage());
}
return Response.success();
}
/**
* 病例交流-评论-取消置顶
*/
@DeleteMapping("/exchange/comment/top/{comment_id}")
public Response<T> deleteTopCaseExchangeComment(
@PathVariable("comment_id") String commentId
) {
String userId = (String) httpServletRequest.getAttribute("userId");
if (userId == null) {
return Response.error("操作失败");
}
try {
boolean res = caseExchangeService.deleteTopCaseExchangeComment(commentId,userId);
if (!res){
return Response.error("操作失败");
}
} catch (BusinessException e) {
return Response.error(e.getMessage());
}
return Response.success();
}
// /**
// * 病例交流-评论-列表
// */
// @PostMapping("/exchange/comment/page")
// public Response<Map<String, Object>> getCaseExchangeCommentPage(
// @Validated()
// @RequestBody getCaseExchangeCommentPage 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<UserCommentCaseExchangeDto> page = new Page<>(request.getPage(), request.getPageSize());
//
// // 获取文章评论数据
// IPage<UserCommentCaseExchangeDto> resultPage = userCommentCaseExchangeDao.getCaseExchangeCommentPage(
// page,
// request.getArticleId(),
// request.getRootId()
// );
//
// // 获取文章数据
// CaseCaseExchangeModel article = caseExchangeDao.selectById(request.getArticleId());
// if (article == null) {
// return Response.error();
// }
//
// if (article.getArticleStatus() != 1){
// return Response.error();
// }
//
// // 获取文章作者数据
// LambdaQueryWrapper<CaseCaseExchangeAuthorModel> authorQueryWrapper = new LambdaQueryWrapper<>();
// authorQueryWrapper.eq(CaseCaseExchangeAuthorModel::getArticleId, request.getArticleId());
// List<CaseCaseExchangeAuthorModel> caseExchangeAuthors = caseExchangeAuthorDao.selectList(authorQueryWrapper);
// for (CaseCaseExchangeAuthorModel author : caseExchangeAuthors) {
// // 查询医生
// CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectById(author.getDoctorId());
// if (caseClinicalDoctor == null) {
// return Response.error();
// }
//
// // 处理是否本人评论
// for (UserCommentCaseExchangeDto dto : resultPage.getRecords()) {
// if (Objects.equals(dto.getUserIden(), caseClinicalDoctor.getDoctorIden())){
// dto.setIsAuthor(1);
// }
// }
// }
//
// // 处理返回值
// for (UserCommentCaseExchangeDto dto : resultPage.getRecords()) {
// // 去除用户唯一标识
// dto.setUserIden(null);
//
// // 获取次级评论
// if (request.getIsHaveSubComment() == 1){
// if (dto.getRootId() == null){
// List<UserCommentCaseExchangeDto> subComments = userCommentCaseExchangeDao.getCaseExchangeCommentList(
// dto.getArticleId(),
// 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);
// }
}

View File

@ -9,6 +9,7 @@ import com.example.caseData.model.CaseClinicalArticleModel;
import com.example.caseData.model.CaseExchangeModel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import java.util.Map;
@ -27,4 +28,25 @@ public interface CaseExchangeDao extends BaseMapper<CaseExchangeModel> {
@Param("userId") String userId,
@Param("order") Map<String, String> order
);
/**
* Inc 自增
* @param exchangeId 文章 ID
* @param field 字段名称
* @param numeral 增加的数值
* @return 更新的行数
*/
@Update("UPDATE case_exchange SET ${field} = ${field} + #{numeral} WHERE exchange_id = #{exchangeId}")
int inc(@Param("exchangeId") Long exchangeId, @Param("field") String field, @Param("numeral") int numeral);
/**
* Dec 自减
*
* @param exchangeId 文章 ID
* @param field 字段名称
* @param numeral 减少的数值
* @return 更新的行数
*/
@Update("UPDATE case_exchange SET ${field} = ${field} - #{numeral} WHERE exchange_id = #{exchangeId}")
int dec(@Param("exchangeId") Long exchangeId, @Param("field") String field, @Param("numeral") int numeral);
}

View File

@ -9,22 +9,22 @@ import org.apache.ibatis.annotations.Update;
public interface StatsCaseExchangeDao extends BaseMapper<StatsCaseExchangeModel> {
/**
* Inc 自增
* @param articleId 文章 ID
* @param statsId 文章 ID
* @param field 字段名称
* @param numeral 增加的数值
* @return 更新的行数
*/
@Update("UPDATE stats_case_exchange SET ${field} = ${field} + #{numeral} WHERE stats_id = #{statsId}")
int inc(@Param("statsId") Long articleId, @Param("field") String field, @Param("numeral") int numeral);
int inc(@Param("statsId") Long statsId, @Param("field") String field, @Param("numeral") int numeral);
/**
* Dec 自减
*
* @param articleId 文章 ID
* @param statsId 文章 ID
* @param field 字段名称
* @param numeral 减少的数值
* @return 更新的行数
*/
@Update("UPDATE stats_case_exchange SET ${field} = ${field} - #{numeral} WHERE stats_id = #{statsId}")
int dec(@Param("statsId") Long articleId, @Param("field") String field, @Param("numeral") int numeral);
int dec(@Param("statsId") Long statsId, @Param("field") String field, @Param("numeral") int numeral);
}

View File

@ -16,22 +16,22 @@ import java.util.Map;
public interface StatsCaseExchangeUserDao extends BaseMapper<StatsCaseExchangeUserModel> {
/**
* Inc 自增
* @param articleId 文章 ID
* @param userId 文章 ID
* @param field 字段名称
* @param numeral 增加的数值
* @return 更新的行数
*/
@Update("UPDATE stats_case_exchange_user SET ${field} = ${field} + #{numeral} WHERE stats_id = #{statsId}")
int inc(@Param("statsId") Long articleId, @Param("field") String field, @Param("numeral") int numeral);
@Update("UPDATE stats_case_exchange_user SET ${field} = ${field} + #{numeral} WHERE user_id = #{userId}")
int inc(@Param("userId") Long userId, @Param("field") String field, @Param("numeral") int numeral);
/**
* Dec 自减
*
* @param articleId 文章 ID
* @param userId 文章 ID
* @param field 字段名称
* @param numeral 减少的数值
* @return 更新的行数
*/
@Update("UPDATE stats_case_exchange_user SET ${field} = ${field} - #{numeral} WHERE stats_id = #{statsId}")
int dec(@Param("statsId") Long articleId, @Param("field") String field, @Param("numeral") int numeral);
int dec(@Param("userId") Long userId, @Param("field") String field, @Param("numeral") int numeral);
}

View File

@ -0,0 +1,25 @@
package com.example.caseData.request.caseExchangeRequest;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
@Data
public class addCaseExchangeComment {
// 父级 次级评论此字段必须存在
@JsonProperty("parent_id")
private String parentId;
// 根评论标识 次级评论此字段必须存在
@JsonProperty("root_id")
private String rootId;
// 评论内容
@JsonProperty("content")
@NotEmpty(message = "请输入评论内容")
private String content;
// 评论图片
@JsonProperty("comment_image")
private String commentImage;
}

View File

@ -0,0 +1,43 @@
package com.example.caseData.request.caseExchangeRequest;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
@Data
public class getCaseExchangeCommentPage {
// 分页参数
@Min(value = 1,message = "页码最小为 1")
private Integer page = 1;
@JsonProperty("page_size")
@Min(value = 1, message = "每页个数最小为 1")
private Integer pageSize = 20;
// 文章id
@NotEmpty(message = "错误")
@JsonProperty("exchange_id")
private String exchangeId;
// 根评论id
@JsonProperty("root_id")
private String rootId;
// 是否需要子评论(0: 1:)
@JsonProperty("is_have_sub_comment")
private Integer isHaveSubComment;
// 校验分页参数
public void validateForPage() {
// 如果 page 为空设为默认值 1
if (page == null) {
page = 1;
}
if (pageSize == null) {
pageSize = 20;
}
}
}

View File

@ -5,14 +5,17 @@ import com.example.caseData.dao.*;
import com.example.caseData.exception.BusinessException;
import com.example.caseData.model.*;
import com.example.caseData.request.caseExchangeRequest.addCaseExchange;
import com.example.caseData.request.caseExchangeRequest.addCaseExchangeComment;
import com.example.caseData.utils.Replace;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Service
public class CaseExchangeService {
@ -41,6 +44,12 @@ public class CaseExchangeService {
@Resource
private StatsCaseExchangeUserDao statsCaseExchangeUserDao;
@Resource
private UserCommentExchangeDao userCommentExchangeDao;
@Resource
private UserDao userDao;
/**
* 新增-病例交流
* @param userId 用户id
@ -165,6 +174,246 @@ public class CaseExchangeService {
return true;
}
/**
* 新增收藏-病例交流
* @param exchangeId 病例交流id
* @param userId 用户id
* @return bool
*/
@Transactional
public boolean AddCaseExchangeCollect(String exchangeId,String userId){
// 获取病例交流数据
CaseExchangeModel article = caseExchangeDao.selectById(exchangeId);
if (article == null) {
return false;
}
// 检测用户是否已收藏过
UserCollectExchangeModel userCollectExchange = getUserCollectExchangeStatus(exchangeId,userId);
if (userCollectExchange != null) {
return true;
}
// 新增收藏
UserCollectExchangeModel userCollectExchangeData = new UserCollectExchangeModel();
userCollectExchangeData.setUserId(Long.valueOf(userId));
userCollectExchangeData.setExchangeId(Long.valueOf(exchangeId));
int res = userCollectExchangeDao.insert(userCollectExchangeData);
if (res <= 0){
return false;
}
// 增加病例交流收藏数
caseExchangeDao.inc(Long.valueOf(exchangeId),"collect_num",1);
// 增加病例交流总收藏数
statsCaseExchangeDao.inc(1L,"exchange_collect_num",1);
// 增加用户交流收藏数
statsCaseExchangeUserDao.inc(Long.valueOf(userId),"exchange_collect_num",1);
return true;
}
/**
* 取消收藏-病例交流
* @param exchangeId 病例交流id
* @param userId 用户id
* @return bool
*/
@Transactional
public boolean DeleteCaseExchangeCollect(String exchangeId,String userId){
// 检测用户是否已收藏过
UserCollectExchangeModel userCollectExchange = getUserCollectExchangeStatus(exchangeId,userId);
if (userCollectExchange == null) {
return true;
}
// 删除收藏
int res = userCollectExchangeDao.deleteById(userCollectExchange.getCollectId());
if (res <= 0){
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return false;
}
// 减少病例交流收藏数
caseExchangeDao.dec(Long.valueOf(exchangeId),"collect_num",1);
// 减少病例交流总收藏数
statsCaseExchangeDao.dec(1L,"exchange_collect_num",1);
// 减少用户交流收藏数
statsCaseExchangeUserDao.dec(Long.valueOf(userId),"exchange_collect_num",1);
return true;
}
/**
* 新增评论-病例交流
* @param exchangeId 病例交流id
* @param userId 用户id
* @return bool
*/
@Transactional
public boolean AddCaseExchangeComment(String exchangeId, String userId, addCaseExchangeComment request){
// 获取病例交流数据
CaseExchangeModel article = caseExchangeDao.selectById(exchangeId);
if (article == null) {
throw new BusinessException("非法病例交流");
}
if (article.getExchangeStatus() != 1){
throw new BusinessException("非法病例交流");
}
// 处理评论内容
BasicSensitiveWordService.FilterResult result = basicSensitiveWordService.filter(request.getContent());
if (result.hasSensitive == 1){
throw new BusinessException("存在敏感词,请修改后提交");
}
// 新增评论
UserCommentExchangeModel userCommentExchangeData = new UserCommentExchangeModel();
userCommentExchangeData.setUserId(Long.valueOf(userId));
userCommentExchangeData.setExchangeId(Long.valueOf(exchangeId));
userCommentExchangeData.setStatus(1);
userCommentExchangeData.setIsSensitive(0);
userCommentExchangeData.setContent(request.getContent());
userCommentExchangeData.setCommentImage(Replace.addOssDomain(request.getCommentImage()));
// 评论根id
if (request.getRootId() != null) {
userCommentExchangeData.setRootId(Long.valueOf(request.getRootId()));
}
// 评论父级id
if (request.getParentId() != null) {
userCommentExchangeData.setParentId(Long.valueOf(request.getParentId()));
}
int res = userCommentExchangeDao.insert(userCommentExchangeData);
return res > 0;
}
/**
* 删除评论-病例交流
* @param commentId 评论id
* @param userId 用户id
* @return bool
*/
@Transactional
public boolean DeleteCaseExchangeComment(String commentId, String userId){
// 获取评论数据
UserCommentExchangeModel comment = userCommentExchangeDao.selectById(commentId);
if (comment == null) {
return false;
}
// 获取病例交流数据
CaseExchangeModel article = caseExchangeDao.selectById(comment.getExchangeId());
if (article == null) {
return false;
}
if (article.getExchangeStatus() != 1){
return false;
}
// 检测用户是否病例交流作者
if (!Objects.equals(comment.getUserId(), Long.valueOf(userId))){
return false;
}
// 删除评论
int res = userCommentExchangeDao.deleteById(comment.getCommentId());
if (res <= 0){
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return false;
}
return true;
}
/**
* 置顶评论-病例交流
* @param commentId 评论id
* @param userId 用户id
* @return bool
*/
@Transactional
public boolean AddTopCaseExchangeComment(String commentId, String userId){
// 获取评论数据
UserCommentExchangeModel comment = userCommentExchangeDao.selectById(commentId);
if (comment == null) {
return false;
}
// 获取病例交流数据
CaseExchangeModel article = caseExchangeDao.selectById(comment.getExchangeId());
if (article == null) {
return false;
}
if (article.getExchangeStatus() != 1){
return false;
}
// 检测用户是否病例交流作者
if (!Objects.equals(comment.getUserId(), Long.valueOf(userId))){
return false;
}
if (comment.getIsTop() == 1){
return true;
}
// 置顶评论
comment.setIsTop(1);
userCommentExchangeDao.updateById(comment);
return true;
}
/**
* 取消置顶评论-病例交流
* @param commentId 评论id
* @param userId 用户id
* @return bool
*/
@Transactional
public boolean deleteTopCaseExchangeComment(String commentId, String userId){
// 获取评论数据
UserCommentExchangeModel comment = userCommentExchangeDao.selectById(commentId);
if (comment == null) {
return false;
}
// 获取病例交流数据
CaseExchangeModel article = caseExchangeDao.selectById(comment.getExchangeId());
if (article == null) {
return false;
}
if (article.getExchangeStatus() != 1){
return false;
}
// 检测用户是否病例交流作者
if (!Objects.equals(comment.getUserId(), Long.valueOf(userId))){
return false;
}
// 取消置顶评论
if (comment.getIsTop() == 0){
return true;
}
// 置顶评论
comment.setIsTop(0);
userCommentExchangeDao.updateById(comment);
return true;
}
/**
* 获取用户收藏数据