评论接口更改返回状态
This commit is contained in:
parent
c0f182de55
commit
66920c976c
@ -165,7 +165,7 @@ public class CaseClinicalArticleController {
|
||||
* 临床病例库-文章-新增评论
|
||||
*/
|
||||
@PostMapping("/clinical/article/comment/{article_id}")
|
||||
public Response<T> AddClinicalArticleComment(
|
||||
public Response<Map<String, Object>> AddClinicalArticleComment(
|
||||
@PathVariable("article_id") String articleId,
|
||||
@Validated()
|
||||
@RequestBody addClinicalArticleComment request
|
||||
@ -177,16 +177,18 @@ public class CaseClinicalArticleController {
|
||||
return Response.error("操作失败");
|
||||
}
|
||||
|
||||
Map<String, Object> resultData = new HashMap<>();
|
||||
resultData.put("status", 1);
|
||||
resultData.put("message", "成功");
|
||||
|
||||
try {
|
||||
boolean res = caseClinicalArticleService.AddClinicalArticleComment(articleId,userId,request);
|
||||
if (!res){
|
||||
return Response.error("操作失败");
|
||||
}
|
||||
resultData = caseClinicalArticleService.AddClinicalArticleComment(articleId,userId,request);
|
||||
Integer status = (Integer) resultData.get("status");
|
||||
String message = (String) resultData.get("message");
|
||||
return Response.success(200,null,message);
|
||||
} catch (BusinessException e) {
|
||||
return Response.error(e.getMessage());
|
||||
}
|
||||
|
||||
return Response.success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -13,7 +13,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
//import static com.baomidou.mybatisplus.extension.toolkit.Db.removeById;
|
||||
@ -137,21 +139,31 @@ public class CaseClinicalArticleService {
|
||||
* @return bool
|
||||
*/
|
||||
@Transactional
|
||||
public boolean AddClinicalArticleComment(String articleId, String userId, addClinicalArticleComment request){
|
||||
public Map<String, Object> AddClinicalArticleComment(String articleId, String userId, addClinicalArticleComment request){
|
||||
Map<String, Object> resultData = new HashMap<>();
|
||||
resultData.put("status", 1);
|
||||
resultData.put("message", "成功");
|
||||
|
||||
// 获取文章数据
|
||||
CaseClinicalArticleModel article = caseClinicalArticleDao.selectById(articleId);
|
||||
if (article == null) {
|
||||
throw new BusinessException("非法文章");
|
||||
resultData.put("status", 0);
|
||||
resultData.put("message", "非法文章");
|
||||
return resultData;
|
||||
}
|
||||
|
||||
if (article.getArticleStatus() != 1){
|
||||
throw new BusinessException("非法文章");
|
||||
resultData.put("status", 0);
|
||||
resultData.put("message", "非法文章");
|
||||
return resultData;
|
||||
}
|
||||
|
||||
// 处理评论内容
|
||||
BasicSensitiveWordService.FilterResult result = basicSensitiveWordService.filter(request.getContent());
|
||||
if (result.hasSensitive == 1){
|
||||
throw new BusinessException("存在敏感词,请修改后提交");
|
||||
resultData.put("status", 0);
|
||||
resultData.put("message", "存在敏感词,请修改后提交");
|
||||
return resultData;
|
||||
}
|
||||
|
||||
// 新增评论
|
||||
@ -175,24 +187,29 @@ public class CaseClinicalArticleService {
|
||||
|
||||
int res = userCommentClinicalArticleDao.insert(userCommentClinicalArticleData);
|
||||
if (res <= 0){
|
||||
return false;
|
||||
resultData.put("status", 0);
|
||||
resultData.put("message", "操作失败");
|
||||
return resultData;
|
||||
}
|
||||
|
||||
// 新增文章的统计字段
|
||||
boolean r = IncClinicalArticleStats(articleId,3,1);
|
||||
if (!r){
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return false;
|
||||
resultData.put("status", 0);
|
||||
resultData.put("message", "操作失败");
|
||||
return resultData;
|
||||
}
|
||||
|
||||
// 获取发放积分次数
|
||||
Integer num = userService.GetReportUserScore(userId);
|
||||
if (num < 3){
|
||||
// 发放积分
|
||||
resultData.put("status", 2);
|
||||
userService.ReportUserScore(articleId,1,userId,5);
|
||||
}
|
||||
|
||||
return true;
|
||||
return resultData;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user