评论问题111
This commit is contained in:
parent
70b69c17a5
commit
7c91ce170f
@ -8,6 +8,7 @@ import net.lab1024.sa.admin.module.business.caseClinicalArticle.domain.form.User
|
||||
import net.lab1024.sa.admin.module.business.caseClinicalArticle.domain.form.UserCommentStatusUpdateForm;
|
||||
import net.lab1024.sa.admin.module.business.caseClinicalArticle.domain.form.UserCommentTopUpdateForm;
|
||||
import net.lab1024.sa.admin.module.business.caseClinicalArticle.domain.vo.UserCommentClinicalArticleVO;
|
||||
import net.lab1024.sa.base.common.exception.BusinessException;
|
||||
import net.lab1024.sa.base.common.util.SmartBeanUtil;
|
||||
import net.lab1024.sa.base.common.util.SmartPageUtil;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
@ -17,8 +18,11 @@ import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 用户评论-临床病例-文章 Service
|
||||
@ -34,6 +38,9 @@ public class UserCommentClinicalArticleService {
|
||||
@Resource
|
||||
private UserCommentClinicalArticleDao userCommentClinicalArticleDao;
|
||||
|
||||
@Resource
|
||||
private CaseClinicalArticleService caseClinicalArticleService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@ -46,6 +53,7 @@ public class UserCommentClinicalArticleService {
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> add(UserCommentClinicalArticleAddForm addForm) {
|
||||
UserCommentClinicalArticleEntity userCommentClinicalArticleEntity = SmartBeanUtil.copy(addForm, UserCommentClinicalArticleEntity.class);
|
||||
userCommentClinicalArticleDao.insert(userCommentClinicalArticleEntity);
|
||||
@ -56,6 +64,7 @@ public class UserCommentClinicalArticleService {
|
||||
* 更新
|
||||
*
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> update(UserCommentClinicalArticleUpdateForm updateForm) {
|
||||
UserCommentClinicalArticleEntity userCommentClinicalArticleEntity = SmartBeanUtil.copy(updateForm, UserCommentClinicalArticleEntity.class);
|
||||
userCommentClinicalArticleDao.updateById(userCommentClinicalArticleEntity);
|
||||
@ -65,53 +74,145 @@ public class UserCommentClinicalArticleService {
|
||||
/**
|
||||
* 修改评论状态
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> updateStatus(Long commentId, Integer status) {
|
||||
if (null == commentId || null == status) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("参数不能为空");
|
||||
}
|
||||
|
||||
UserCommentClinicalArticleEntity entity = new UserCommentClinicalArticleEntity();
|
||||
entity.setCommentId(commentId);
|
||||
entity.setStatus(status);
|
||||
userCommentClinicalArticleDao.updateById(entity);
|
||||
|
||||
// 获取评论数据
|
||||
UserCommentClinicalArticleEntity userCommentClinicalArticle = userCommentClinicalArticleDao.selectById(commentId);
|
||||
if (null == userCommentClinicalArticle) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
if (Objects.equals(userCommentClinicalArticle.getStatus(), status)) {
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
userCommentClinicalArticle.setStatus(status);
|
||||
userCommentClinicalArticleDao.updateById(userCommentClinicalArticle);
|
||||
|
||||
// 正常
|
||||
if (status == 1){
|
||||
// 新增文章的统计字段
|
||||
boolean r = caseClinicalArticleService.IncClinicalArticleStats(
|
||||
String.valueOf(userCommentClinicalArticle.getArticleId()),
|
||||
3,
|
||||
1
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 禁用
|
||||
if (status == 2){
|
||||
// 减少文章的统计字段
|
||||
boolean r = caseClinicalArticleService.DecClinicalArticleStats(
|
||||
String.valueOf(userCommentClinicalArticle.getArticleId()),
|
||||
3,
|
||||
1
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改置顶状态
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> updateTopStatus(Long commentId, Integer isTop) {
|
||||
if (null == commentId || null == isTop) {
|
||||
return ResponseDTO.userErrorParam("参数不能为空");
|
||||
}
|
||||
|
||||
UserCommentClinicalArticleEntity entity = new UserCommentClinicalArticleEntity();
|
||||
entity.setCommentId(commentId);
|
||||
entity.setIsTop(isTop);
|
||||
userCommentClinicalArticleDao.updateById(entity);
|
||||
|
||||
// 获取评论数据
|
||||
UserCommentClinicalArticleEntity userCommentClinicalArticle = userCommentClinicalArticleDao.selectById(commentId);
|
||||
if (null == userCommentClinicalArticle) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
if (Objects.equals(userCommentClinicalArticle.getIsTop(), isTop)) {
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
userCommentClinicalArticle.setIsTop(isTop);
|
||||
userCommentClinicalArticleDao.updateById(userCommentClinicalArticle);
|
||||
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> batchDelete(List<Long> idList) {
|
||||
if (CollectionUtils.isEmpty(idList)){
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
userCommentClinicalArticleDao.deleteBatchIds(idList);
|
||||
for (Long id : idList){
|
||||
// 获取评论数据
|
||||
UserCommentClinicalArticleEntity userCommentClinicalArticle = userCommentClinicalArticleDao.selectById(id);
|
||||
if (null == userCommentClinicalArticle) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
// 减少文章的统计字段
|
||||
boolean r = caseClinicalArticleService.DecClinicalArticleStats(
|
||||
String.valueOf(userCommentClinicalArticle.getArticleId()),
|
||||
3,
|
||||
1
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
userCommentClinicalArticleDao.deleteById(id);
|
||||
}
|
||||
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> delete(Long commentId) {
|
||||
if (null == commentId){
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
// 获取评论数据
|
||||
UserCommentClinicalArticleEntity userCommentClinicalArticle = userCommentClinicalArticleDao.selectById(commentId);
|
||||
if (null == userCommentClinicalArticle) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
// 减少文章的统计字段
|
||||
boolean r = caseClinicalArticleService.DecClinicalArticleStats(
|
||||
String.valueOf(userCommentClinicalArticle.getArticleId()),
|
||||
3,
|
||||
1
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
userCommentClinicalArticleDao.deleteById(commentId);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package net.lab1024.sa.admin.module.business.caseClinicalVideo.service;
|
||||
|
||||
import net.lab1024.sa.admin.module.business.caseClinicalVideo.domain.entity.UserCommentClinicalVideoEntity;
|
||||
import net.lab1024.sa.admin.module.business.caseClinicalVideo.domain.entity.UserCommentClinicalVideoEntity;
|
||||
import net.lab1024.sa.admin.module.business.caseClinicalVideo.dao.UserCommentClinicalVideoDao;
|
||||
import net.lab1024.sa.admin.module.business.caseClinicalVideo.domain.entity.UserCommentClinicalVideoEntity;
|
||||
import net.lab1024.sa.admin.module.business.caseClinicalVideo.domain.form.UserCommentClinicalVideoAddForm;
|
||||
@ -17,8 +19,11 @@ import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 用户评论-临床病例-视频 Service
|
||||
@ -34,6 +39,9 @@ public class UserCommentClinicalVideoService {
|
||||
@Resource
|
||||
private UserCommentClinicalVideoDao userCommentClinicalVideoDao;
|
||||
|
||||
@Resource
|
||||
private CaseClinicalVideoService caseClinicalVideoService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@ -46,6 +54,7 @@ public class UserCommentClinicalVideoService {
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> add(UserCommentClinicalVideoAddForm addForm) {
|
||||
UserCommentClinicalVideoEntity userCommentClinicalVideoEntity = SmartBeanUtil.copy(addForm, UserCommentClinicalVideoEntity.class);
|
||||
userCommentClinicalVideoDao.insert(userCommentClinicalVideoEntity);
|
||||
@ -56,6 +65,7 @@ public class UserCommentClinicalVideoService {
|
||||
* 更新
|
||||
*
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> update(UserCommentClinicalVideoUpdateForm updateForm) {
|
||||
UserCommentClinicalVideoEntity userCommentClinicalVideoEntity = SmartBeanUtil.copy(updateForm, UserCommentClinicalVideoEntity.class);
|
||||
userCommentClinicalVideoDao.updateById(userCommentClinicalVideoEntity);
|
||||
@ -65,53 +75,142 @@ public class UserCommentClinicalVideoService {
|
||||
/**
|
||||
* 修改评论状态
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> updateStatus(Long commentId, Integer status) {
|
||||
if (null == commentId || null == status) {
|
||||
return ResponseDTO.userErrorParam("参数不能为空");
|
||||
}
|
||||
|
||||
// 获取评论数据
|
||||
UserCommentClinicalVideoEntity userCommentClinicalVideo = userCommentClinicalVideoDao.selectById(commentId);
|
||||
if (null == userCommentClinicalVideo) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
if (Objects.equals(userCommentClinicalVideo.getStatus(), status)) {
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
userCommentClinicalVideo.setStatus(status);
|
||||
userCommentClinicalVideoDao.updateById(userCommentClinicalVideo);
|
||||
|
||||
// 正常
|
||||
if (status == 1){
|
||||
// 新增文章的统计字段
|
||||
boolean r = caseClinicalVideoService.IncClinicalVideoStats(
|
||||
String.valueOf(userCommentClinicalVideo.getVideoId()),
|
||||
3,
|
||||
1
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 禁用
|
||||
if (status == 2){
|
||||
// 减少文章的统计字段
|
||||
boolean r = caseClinicalVideoService.DecClinicalVideoStats(
|
||||
String.valueOf(userCommentClinicalVideo.getVideoId()),
|
||||
3,
|
||||
1
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
UserCommentClinicalVideoEntity entity = new UserCommentClinicalVideoEntity();
|
||||
entity.setCommentId(commentId);
|
||||
entity.setStatus(status);
|
||||
userCommentClinicalVideoDao.updateById(entity);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改置顶状态
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> updateTopStatus(Long commentId, Integer isTop) {
|
||||
if (null == commentId || null == isTop) {
|
||||
return ResponseDTO.userErrorParam("参数不能为空");
|
||||
}
|
||||
|
||||
UserCommentClinicalVideoEntity entity = new UserCommentClinicalVideoEntity();
|
||||
entity.setCommentId(commentId);
|
||||
entity.setIsTop(isTop);
|
||||
userCommentClinicalVideoDao.updateById(entity);
|
||||
|
||||
// 获取评论数据
|
||||
UserCommentClinicalVideoEntity userCommentClinicalVideo = userCommentClinicalVideoDao.selectById(commentId);
|
||||
if (null == userCommentClinicalVideo) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
if (Objects.equals(userCommentClinicalVideo.getIsTop(), isTop)) {
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
userCommentClinicalVideo.setIsTop(isTop);
|
||||
userCommentClinicalVideoDao.updateById(userCommentClinicalVideo);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> batchDelete(List<Long> idList) {
|
||||
if (CollectionUtils.isEmpty(idList)){
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
userCommentClinicalVideoDao.deleteBatchIds(idList);
|
||||
for (Long id : idList){
|
||||
// 获取评论数据
|
||||
UserCommentClinicalVideoEntity userCommentClinicalVideo = userCommentClinicalVideoDao.selectById(id);
|
||||
if (null == userCommentClinicalVideo) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
// 减少文章的统计字段
|
||||
boolean r = caseClinicalVideoService.DecClinicalVideoStats(
|
||||
String.valueOf(userCommentClinicalVideo.getVideoId()),
|
||||
3,
|
||||
1
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
userCommentClinicalVideoDao.deleteById(id);
|
||||
}
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> delete(Long commentId) {
|
||||
if (null == commentId){
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
// 获取评论数据
|
||||
UserCommentClinicalVideoEntity userCommentClinicalVideo = userCommentClinicalVideoDao.selectById(commentId);
|
||||
if (null == userCommentClinicalVideo) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
// 减少文章的统计字段
|
||||
boolean r = caseClinicalVideoService.DecClinicalVideoStats(
|
||||
String.valueOf(userCommentClinicalVideo.getVideoId()),
|
||||
3,
|
||||
1
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
userCommentClinicalVideoDao.deleteById(commentId);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@ -30,4 +31,25 @@ public interface CaseExchangeDao extends BaseMapper<CaseExchangeEntity> {
|
||||
*/
|
||||
List<CaseExchangeVO> queryPage(Page page, @Param("queryForm") CaseExchangeQueryForm queryForm);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@ -30,4 +31,26 @@ public interface StatsCaseExchangeDao extends BaseMapper<StatsCaseExchangeEntity
|
||||
*/
|
||||
List<StatsCaseExchangeVO> queryPage(Page page, @Param("queryForm") StatsCaseExchangeQueryForm queryForm);
|
||||
|
||||
/**
|
||||
* Inc 自增
|
||||
* @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 statsId, @Param("field") String field, @Param("numeral") int numeral);
|
||||
|
||||
/**
|
||||
* Dec 自减
|
||||
*
|
||||
* @param statsId 文章 ID
|
||||
* @param field 字段名称
|
||||
* @param numeral 减少的数值
|
||||
* @return 更新的行数
|
||||
*/
|
||||
@Update("UPDATE stats_case_exchange " +
|
||||
"SET ${field} = CASE WHEN ${field} >= #{numeral} THEN ${field} - #{numeral} ELSE 0 END " +
|
||||
"WHERE stats_id = #{statsId}")
|
||||
int dec(@Param("statsId") Long statsId, @Param("field") String field, @Param("numeral") int numeral);
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@ -30,4 +31,26 @@ public interface StatsCaseExchangeUserDao extends BaseMapper<StatsCaseExchangeUs
|
||||
*/
|
||||
List<StatsCaseExchangeUserVO> queryPage(Page page, @Param("queryForm") StatsCaseExchangeUserQueryForm queryForm);
|
||||
|
||||
/**
|
||||
* Inc 自增
|
||||
* @param userId 文章 ID
|
||||
* @param field 字段名称
|
||||
* @param numeral 增加的数值
|
||||
* @return 更新的行数
|
||||
*/
|
||||
@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 userId 文章 ID
|
||||
* @param field 字段名称
|
||||
* @param numeral 减少的数值
|
||||
* @return 更新的行数
|
||||
*/
|
||||
@Update("UPDATE stats_case_exchange_user " +
|
||||
"SET ${field} = CASE WHEN ${field} >= #{numeral} THEN ${field} - #{numeral} ELSE 0 END " +
|
||||
"WHERE user_id = #{userId}")
|
||||
int dec(@Param("userId") Long userId, @Param("field") String field, @Param("numeral") int numeral);
|
||||
}
|
||||
|
||||
@ -1 +0,0 @@
|
||||
|
||||
@ -19,8 +19,12 @@ import net.lab1024.sa.admin.module.business.caseClinicalRecordScore.dao.CaseClin
|
||||
import net.lab1024.sa.admin.module.business.caseClinicalRecordScore.domain.entity.CaseClinicalRecordScoreEntity;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.dao.CaseExchangeDao;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.dao.CaseExchangeLabelDao;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.dao.StatsCaseExchangeDao;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.dao.StatsCaseExchangeUserDao;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.domain.entity.CaseExchangeEntity;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.domain.entity.CaseExchangeLabelEntity;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.domain.entity.StatsCaseExchangeEntity;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.domain.entity.StatsCaseExchangeUserEntity;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.domain.form.CaseExchangeAddForm;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.domain.form.CaseExchangeQueryForm;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.domain.form.CaseExchangeUpdateForm;
|
||||
@ -41,6 +45,7 @@ import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 病例库-病例交流 Service
|
||||
@ -71,6 +76,12 @@ public class CaseExchangeService {
|
||||
@Resource
|
||||
private CaseClinicalRecordScoreDao caseClinicalRecordScoreDao;
|
||||
|
||||
@Resource
|
||||
private StatsCaseExchangeUserDao statsCaseExchangeUserDao;
|
||||
|
||||
@Resource
|
||||
private StatsCaseExchangeDao statsCaseExchangeDao;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@ -353,6 +364,16 @@ public class CaseExchangeService {
|
||||
}
|
||||
}
|
||||
|
||||
// 病例交流统计
|
||||
if (!handleStatsCaseExchange()){
|
||||
throw new BusinessException("操作失败");
|
||||
}
|
||||
|
||||
// 新增病例交流统计-用户
|
||||
if (!handleStatsCaseExchangeUser(String.valueOf(caseExchange.getUserId()),"exchange_num")){
|
||||
throw new BusinessException("操作失败");
|
||||
}
|
||||
|
||||
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
@ -388,4 +409,184 @@ public class CaseExchangeService {
|
||||
caseExchangeLabelDao.insert(labelEntity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增病例交流统计
|
||||
* @return bool
|
||||
*/
|
||||
public boolean handleStatsCaseExchange(){
|
||||
LambdaQueryWrapper<StatsCaseExchangeEntity> mapQueryWrapper = new LambdaQueryWrapper<>();
|
||||
StatsCaseExchangeEntity statsCaseExchange = statsCaseExchangeDao.selectOne(mapQueryWrapper);
|
||||
if (statsCaseExchange == null){
|
||||
// 新增
|
||||
StatsCaseExchangeEntity statsCaseExchangeData = new StatsCaseExchangeEntity();
|
||||
statsCaseExchangeData.setExchangeNum(1);
|
||||
int res = statsCaseExchangeDao.insert(statsCaseExchangeData);
|
||||
return res > 0;
|
||||
}else{
|
||||
// 增加数量
|
||||
statsCaseExchangeDao.inc(statsCaseExchange.getStatsId(),"exchange_num",1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增病例交流统计-用户
|
||||
* @return bool
|
||||
*/
|
||||
public boolean handleStatsCaseExchangeUser(String userId,String field){
|
||||
LambdaQueryWrapper<StatsCaseExchangeUserEntity> mapQueryWrapper = new LambdaQueryWrapper<>();
|
||||
mapQueryWrapper.eq(StatsCaseExchangeUserEntity::getUserId, userId);
|
||||
StatsCaseExchangeUserEntity statsCaseExchangeUser = statsCaseExchangeUserDao.selectOne(mapQueryWrapper);
|
||||
if (statsCaseExchangeUser == null){
|
||||
// 新增
|
||||
StatsCaseExchangeUserEntity statsCaseExchangeUserData = new StatsCaseExchangeUserEntity();
|
||||
statsCaseExchangeUserData.setUserId(Long.valueOf(userId));
|
||||
statsCaseExchangeUserData.setExchangeNum(1);
|
||||
int res = statsCaseExchangeUserDao.insert(statsCaseExchangeUserData);
|
||||
return res > 0;
|
||||
}else{
|
||||
// 增加数量
|
||||
statsCaseExchangeUserDao.inc(statsCaseExchangeUser.getStatsId(),field,1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增病例交流统计字段
|
||||
* @param exchangeId 病例id
|
||||
* @param type 类型:1:阅读量 2:收藏量 3:评论数
|
||||
*/
|
||||
@Transactional
|
||||
public boolean IncCaseExchangeStats(String exchangeId,Integer type){
|
||||
try {
|
||||
// 获取病例数据
|
||||
CaseExchangeEntity caseExchange = caseExchangeDao.selectById(exchangeId);
|
||||
if (caseExchange == null){
|
||||
throw new BusinessException("操作失败");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<StatsCaseExchangeUserEntity> mapQueryWrapper = new LambdaQueryWrapper<>();
|
||||
mapQueryWrapper.eq(StatsCaseExchangeUserEntity::getUserId, caseExchange.getUserId());
|
||||
StatsCaseExchangeUserEntity statsCaseExchangeUser = statsCaseExchangeUserDao.selectOne(mapQueryWrapper);
|
||||
if (statsCaseExchangeUser == null){
|
||||
throw new BusinessException("操作失败");
|
||||
}
|
||||
|
||||
// 阅读量
|
||||
if (type == 1){
|
||||
// 总
|
||||
statsCaseExchangeDao.inc(1L,"exchange_read_num",1);
|
||||
|
||||
// 单
|
||||
caseExchangeDao.inc(Long.valueOf(exchangeId),"read_num",1);
|
||||
|
||||
// 用户-此处无需担心stats_case_exchange_user无数据,发布病例时会新增
|
||||
statsCaseExchangeUserDao.inc(statsCaseExchangeUser.getUserId(),"exchange_read_num",1);
|
||||
}
|
||||
|
||||
// 收藏量
|
||||
if (type == 2){
|
||||
// 总
|
||||
statsCaseExchangeDao.inc(1L,"exchange_collect_num",1);
|
||||
|
||||
// 单
|
||||
caseExchangeDao.inc(Long.valueOf(exchangeId),"collect_num",1);
|
||||
|
||||
// 用户-此处无需担心stats_case_exchange_user无数据,发布病例时会新增
|
||||
statsCaseExchangeUserDao.inc(statsCaseExchangeUser.getUserId(),"exchange_collect_num",1);
|
||||
}
|
||||
|
||||
// 评论数
|
||||
if (type == 3){
|
||||
// 总
|
||||
statsCaseExchangeDao.inc(1L,"exchange_comment_num",1);
|
||||
|
||||
// 单
|
||||
caseExchangeDao.inc(Long.valueOf(exchangeId),"comment_num",1);
|
||||
|
||||
// 用户-此处无需担心stats_case_exchange_user无数据,发布病例时会新增
|
||||
statsCaseExchangeUserDao.inc(statsCaseExchangeUser.getUserId(),"exchange_comment_num",1);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少病例交流统计字段
|
||||
* @param exchangeId 病例id
|
||||
* @param type 类型:1:阅读量 2:收藏量 3:评论数 4:数量
|
||||
*/
|
||||
@Transactional
|
||||
public boolean DecCaseExchangeStats(String exchangeId,Integer type,Integer num){
|
||||
try {
|
||||
// 获取病例数据
|
||||
CaseExchangeEntity caseExchange = caseExchangeDao.selectById(exchangeId);
|
||||
if (caseExchange == null){
|
||||
throw new BusinessException("操作失败");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<StatsCaseExchangeUserEntity> mapQueryWrapper = new LambdaQueryWrapper<>();
|
||||
mapQueryWrapper.eq(StatsCaseExchangeUserEntity::getUserId, caseExchange.getUserId());
|
||||
StatsCaseExchangeUserEntity statsCaseExchangeUser = statsCaseExchangeUserDao.selectOne(mapQueryWrapper);
|
||||
if (statsCaseExchangeUser == null){
|
||||
throw new BusinessException("操作失败");
|
||||
}
|
||||
|
||||
// 阅读量
|
||||
if (type == 1){
|
||||
// 总
|
||||
statsCaseExchangeDao.dec(1L,"exchange_read_num",num);
|
||||
|
||||
// 单
|
||||
caseExchangeDao.dec(Long.valueOf(exchangeId),"read_num",num);
|
||||
|
||||
// 用户
|
||||
statsCaseExchangeUserDao.dec(statsCaseExchangeUser.getUserId(),"exchange_read_num",num);
|
||||
}
|
||||
|
||||
// 收藏量
|
||||
if (type == 2){
|
||||
// 总
|
||||
statsCaseExchangeDao.dec(1L,"exchange_collect_num",num);
|
||||
|
||||
// 单
|
||||
caseExchangeDao.dec(Long.valueOf(exchangeId),"collect_num",num);
|
||||
|
||||
// 用户
|
||||
statsCaseExchangeUserDao.dec(statsCaseExchangeUser.getUserId(),"exchange_collect_num",num);
|
||||
}
|
||||
|
||||
// 评论数
|
||||
if (type == 3){
|
||||
// 总
|
||||
statsCaseExchangeDao.dec(1L,"exchange_comment_num",num);
|
||||
|
||||
// 单
|
||||
caseExchangeDao.dec(Long.valueOf(exchangeId),"comment_num",num);
|
||||
|
||||
// 用户
|
||||
statsCaseExchangeUserDao.dec(statsCaseExchangeUser.getUserId(),"exchange_comment_num",num);
|
||||
}
|
||||
|
||||
// 数量
|
||||
if (type == 4){
|
||||
// 总
|
||||
statsCaseExchangeDao.dec(1L,"exchange_num",num);
|
||||
|
||||
// 用户
|
||||
statsCaseExchangeUserDao.dec(statsCaseExchangeUser.getUserId(),"exchange_num",num);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package net.lab1024.sa.admin.module.business.caseExchange.service;
|
||||
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.domain.entity.UserCommentExchangeEntity;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.dao.UserCommentExchangeDao;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.domain.entity.UserCommentExchangeEntity;
|
||||
import net.lab1024.sa.admin.module.business.caseExchange.domain.form.UserCommentExchangeAddForm;
|
||||
@ -17,8 +18,11 @@ import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 用户评论-病例交流 Service
|
||||
@ -34,6 +38,9 @@ public class UserCommentExchangeService {
|
||||
@Resource
|
||||
private UserCommentExchangeDao userCommentExchangeDao;
|
||||
|
||||
@Resource
|
||||
private CaseExchangeService caseExchangeService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@ -46,6 +53,7 @@ public class UserCommentExchangeService {
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> add(UserCommentExchangeAddForm addForm) {
|
||||
UserCommentExchangeEntity userCommentExchangeEntity = SmartBeanUtil.copy(addForm, UserCommentExchangeEntity.class);
|
||||
userCommentExchangeDao.insert(userCommentExchangeEntity);
|
||||
@ -56,6 +64,7 @@ public class UserCommentExchangeService {
|
||||
* 更新
|
||||
*
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> update(UserCommentExchangeUpdateForm updateForm) {
|
||||
UserCommentExchangeEntity userCommentExchangeEntity = SmartBeanUtil.copy(updateForm, UserCommentExchangeEntity.class);
|
||||
userCommentExchangeDao.updateById(userCommentExchangeEntity);
|
||||
@ -65,53 +74,141 @@ public class UserCommentExchangeService {
|
||||
/**
|
||||
* 修改评论状态
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> updateStatus(Long commentId, Integer status) {
|
||||
if (null == commentId || null == status) {
|
||||
return ResponseDTO.userErrorParam("参数不能为空");
|
||||
}
|
||||
|
||||
UserCommentExchangeEntity entity = new UserCommentExchangeEntity();
|
||||
entity.setCommentId(commentId);
|
||||
entity.setStatus(status);
|
||||
userCommentExchangeDao.updateById(entity);
|
||||
|
||||
// 获取评论数据
|
||||
UserCommentExchangeEntity userCommentExchange = userCommentExchangeDao.selectById(commentId);
|
||||
if (null == userCommentExchange) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
if (Objects.equals(userCommentExchange.getStatus(), status)) {
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
userCommentExchange.setStatus(status);
|
||||
userCommentExchangeDao.updateById(userCommentExchange);
|
||||
|
||||
// 正常
|
||||
if (status == 1){
|
||||
// 新增文章的统计字段
|
||||
boolean r = caseExchangeService.IncCaseExchangeStats(
|
||||
String.valueOf(userCommentExchange.getExchangeId()),
|
||||
3
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 禁用
|
||||
if (status == 2){
|
||||
// 减少文章的统计字段
|
||||
boolean r = caseExchangeService.DecCaseExchangeStats(
|
||||
String.valueOf(userCommentExchange.getExchangeId()),
|
||||
3,
|
||||
1
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改置顶状态
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> updateTopStatus(Long commentId, Integer isTop) {
|
||||
if (null == commentId || null == isTop) {
|
||||
return ResponseDTO.userErrorParam("参数不能为空");
|
||||
}
|
||||
|
||||
UserCommentExchangeEntity entity = new UserCommentExchangeEntity();
|
||||
entity.setCommentId(commentId);
|
||||
entity.setIsTop(isTop);
|
||||
userCommentExchangeDao.updateById(entity);
|
||||
|
||||
// 获取评论数据
|
||||
UserCommentExchangeEntity userCommentExchange = userCommentExchangeDao.selectById(commentId);
|
||||
if (null == userCommentExchange) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
if (Objects.equals(userCommentExchange.getIsTop(), isTop)) {
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
userCommentExchange.setIsTop(isTop);
|
||||
userCommentExchangeDao.updateById(userCommentExchange);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> batchDelete(List<Long> idList) {
|
||||
if (CollectionUtils.isEmpty(idList)){
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
userCommentExchangeDao.deleteBatchIds(idList);
|
||||
for (Long id : idList){
|
||||
// 获取评论数据
|
||||
UserCommentExchangeEntity userCommentExchange = userCommentExchangeDao.selectById(id);
|
||||
if (null == userCommentExchange) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
// 减少文章的统计字段
|
||||
boolean r = caseExchangeService.DecCaseExchangeStats(
|
||||
String.valueOf(userCommentExchange.getExchangeId()),
|
||||
3,
|
||||
1
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
userCommentExchangeDao.deleteById(id);
|
||||
}
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个删除
|
||||
*/
|
||||
@Transactional
|
||||
public ResponseDTO<String> delete(Long commentId) {
|
||||
if (null == commentId){
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
// 获取评论数据
|
||||
UserCommentExchangeEntity userCommentExchange = userCommentExchangeDao.selectById(commentId);
|
||||
if (null == userCommentExchange) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
// 减少文章的统计字段
|
||||
boolean r = caseExchangeService.DecCaseExchangeStats(
|
||||
String.valueOf(userCommentExchange.getExchangeId()),
|
||||
3,
|
||||
1
|
||||
);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return ResponseDTO.userErrorParam("操作失败");
|
||||
}
|
||||
|
||||
userCommentExchangeDao.deleteById(commentId);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user