名医文章
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
package com.peanut.modules.taihumed.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.common.utils.ShiroUtils;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.*;
|
||||
import com.peanut.modules.sys.entity.SysSensitiveWords;
|
||||
import com.peanut.modules.sys.service.SysSensitiveWordsService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@RestController("commonTaihuTalentArticle")
|
||||
@RequestMapping("common/taihuTalentArticle")
|
||||
public class TaihuTalentArticleController {
|
||||
|
||||
@Autowired
|
||||
private TaihuTalentArticleService taihuTalentArticleService;
|
||||
@Autowired
|
||||
private TaihuTalentService taihuTalentService;
|
||||
@Autowired
|
||||
private TaihuTalentArticleCommentService taihuTalentArticleCommentService;
|
||||
@Autowired
|
||||
private TaihuTalentArticleLikeService taihuTalentArticleLikeService;
|
||||
@Autowired
|
||||
private SysSensitiveWordsService sysSensitiveWordsService;
|
||||
|
||||
//太湖英才文章列表
|
||||
@RequestMapping("/getArticleList")
|
||||
public R getArticleList(@RequestBody Map<String,Object> params){
|
||||
LambdaQueryWrapper<TaihuTalentArticle> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.orderByDesc(TaihuTalentArticle::getCreateTime);
|
||||
Page<TaihuTalentArticle> page = taihuTalentArticleService.page(new Page<>(Long.parseLong(params.get("current").toString()),
|
||||
Long.parseLong(params.get("limit").toString())), wrapper);
|
||||
for (TaihuTalentArticle article : page.getRecords()) {
|
||||
article.setTaihuTalent(taihuTalentService.getOne(new LambdaQueryWrapper<TaihuTalent>()
|
||||
.eq(TaihuTalent::getUserId, article.getUserId())));
|
||||
article.setCommentCount((int) taihuTalentArticleCommentService.count(new LambdaQueryWrapper<TaihuTalentArticleComment>()
|
||||
.eq(TaihuTalentArticleComment::getArticleId,article.getId())));
|
||||
article.setLikeCount((int) taihuTalentArticleLikeService.count(new LambdaQueryWrapper<TaihuTalentArticleLike>()
|
||||
.eq(TaihuTalentArticleLike::getArticleId,article.getId())));
|
||||
article.setLikeFlag((int) taihuTalentArticleLikeService.count(new LambdaQueryWrapper<TaihuTalentArticleLike>()
|
||||
.eq(TaihuTalentArticleLike::getArticleId,article.getId())
|
||||
.eq(TaihuTalentArticleLike::getUserId, ShiroUtils.getUId())));
|
||||
}
|
||||
return R.ok().put("page",page);
|
||||
}
|
||||
|
||||
//太湖英才文章详情
|
||||
@RequestMapping("/getArticleInfo")
|
||||
public R getArticleInfo(@RequestBody Map<String,Object> params){
|
||||
TaihuTalentArticle article = taihuTalentArticleService.getById(params.get("articleId").toString());
|
||||
article.setTaihuTalent(taihuTalentService.getOne(new LambdaQueryWrapper<TaihuTalent>()
|
||||
.eq(TaihuTalent::getUserId, article.getUserId())));
|
||||
article.setCommentCount((int) taihuTalentArticleCommentService.count(new LambdaQueryWrapper<TaihuTalentArticleComment>()
|
||||
.eq(TaihuTalentArticleComment::getArticleId,article.getId())));
|
||||
article.setLikeCount((int) taihuTalentArticleLikeService.count(new LambdaQueryWrapper<TaihuTalentArticleLike>()
|
||||
.eq(TaihuTalentArticleLike::getArticleId,article.getId())));
|
||||
article.setLikeCount((int) taihuTalentArticleLikeService.count(new LambdaQueryWrapper<TaihuTalentArticleLike>()
|
||||
.eq(TaihuTalentArticleLike::getArticleId,article.getId())
|
||||
.eq(TaihuTalentArticleLike::getUserId, ShiroUtils.getUId())));
|
||||
List<TaihuTalentArticleComment> comments = taihuTalentArticleCommentService.list(new LambdaQueryWrapper<TaihuTalentArticleComment>()
|
||||
.eq(TaihuTalentArticleComment::getArticleId,article.getId())
|
||||
.eq(TaihuTalentArticleComment::getPid,0)
|
||||
.orderByDesc(TaihuTalentArticleComment::getCreateTime));
|
||||
for (TaihuTalentArticleComment comment : comments) {
|
||||
comment.setChildren(taihuTalentArticleCommentService.list(new LambdaQueryWrapper<TaihuTalentArticleComment>()
|
||||
.eq(TaihuTalentArticleComment::getArticleId,article.getId())
|
||||
.ne(TaihuTalentArticleComment::getPid,0)
|
||||
.orderByAsc(TaihuTalentArticleComment::getCreateTime)));
|
||||
}
|
||||
if (!Objects.equals(article.getUserId(), ShiroUtils.getUId())){
|
||||
article.setReadCount(article.getReadCount()+1);
|
||||
taihuTalentArticleService.updateById(article);
|
||||
}
|
||||
return R.ok().put("article",article).put("comments",comments);
|
||||
}
|
||||
|
||||
//太湖英才文章点赞或取消
|
||||
@RequestMapping("/addOrCancelArticleLike")
|
||||
public R addOrCancelArticleLike(@RequestBody Map<String,Object> params){
|
||||
TaihuTalentArticleLike like = taihuTalentArticleLikeService.getOne(new LambdaQueryWrapper<TaihuTalentArticleLike>()
|
||||
.eq(TaihuTalentArticleLike::getArticleId,params.get("articleId").toString())
|
||||
.eq(TaihuTalentArticleLike::getUserId,ShiroUtils.getUId()));
|
||||
if (like != null) {
|
||||
taihuTalentArticleLikeService.removeById(like);
|
||||
}else {
|
||||
like = new TaihuTalentArticleLike();
|
||||
like.setUserId(ShiroUtils.getUId());
|
||||
like.setArticleId(Integer.parseInt(params.get("articleId").toString()));
|
||||
taihuTalentArticleLikeService.save(like);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//新增文章评论
|
||||
@RequestMapping("/addArticleComment")
|
||||
public R addArticleComment(@RequestBody TaihuTalentArticleComment comment){
|
||||
R result = new R();
|
||||
LambdaQueryWrapper<SysSensitiveWords> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.last(" where instr(\""+comment.getContent()+"\",word)>0");
|
||||
List<SysSensitiveWords> list = sysSensitiveWordsService.list(wrapper);
|
||||
if (list.size() > 0){
|
||||
String str = "";
|
||||
for (SysSensitiveWords words:list) {
|
||||
if ("".equals(str)){
|
||||
str = words.getWord();
|
||||
}else {
|
||||
str = str + "、" + words.getWord();
|
||||
}
|
||||
}
|
||||
result.put("tip","您的评论含有敏感词:"+str+",请重新输入。");
|
||||
}else {
|
||||
taihuTalentArticleCommentService.save(comment);
|
||||
result.put("tip","评论成功!");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//评论提醒
|
||||
@RequestMapping("/getCommentRemind")
|
||||
public R getCommentRemind(@RequestBody Map<String,Object> params){
|
||||
List<TaihuTalentArticleComment> list = new ArrayList<>();
|
||||
List<TaihuTalentArticleComment> userComments = taihuTalentArticleCommentService.list(new LambdaQueryWrapper<TaihuTalentArticleComment>()
|
||||
.eq(TaihuTalentArticleComment::getUserId,ShiroUtils.getUId())
|
||||
.eq(TaihuTalentArticleComment::getArticleId,params.get("articleId").toString()));
|
||||
for (TaihuTalentArticleComment comment : userComments) {
|
||||
if(comment.getPid().equals(0)){
|
||||
list.addAll(taihuTalentArticleCommentService.list(new LambdaQueryWrapper<TaihuTalentArticleComment>()
|
||||
.eq(TaihuTalentArticleComment::getPid,comment.getId())
|
||||
.eq(TaihuTalentArticleComment::getReadFlag,0)
|
||||
.eq(TaihuTalentArticleComment::getArticleId,params.get("articleId").toString())));
|
||||
}else {
|
||||
list.addAll(taihuTalentArticleCommentService.list(new LambdaQueryWrapper<TaihuTalentArticleComment>()
|
||||
.eq(TaihuTalentArticleComment::getPid,comment.getPid())
|
||||
.eq(TaihuTalentArticleComment::getReadFlag,0)
|
||||
.eq(TaihuTalentArticleComment::getArticleId,params.get("articleId").toString())));
|
||||
}
|
||||
}
|
||||
return R.ok().put("list",list);
|
||||
}
|
||||
|
||||
//我的文章列表
|
||||
@RequestMapping("/myArticleList")
|
||||
public R myArticleList(@RequestBody Map<String,Object> params){
|
||||
LambdaQueryWrapper<TaihuTalentArticle> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(TaihuTalentArticle::getUserId,ShiroUtils.getUId());
|
||||
wrapper.orderByDesc(TaihuTalentArticle::getCreateTime);
|
||||
Page<TaihuTalentArticle> page = taihuTalentArticleService.page(new Page<>(Long.parseLong(params.get("current").toString()),
|
||||
Long.parseLong(params.get("limit").toString())), wrapper);
|
||||
return R.ok().put("page",page);
|
||||
}
|
||||
|
||||
//新增文章
|
||||
@RequestMapping("/addArticle")
|
||||
public R addArticle(@RequestBody TaihuTalentArticle taihuTalentArticle){
|
||||
taihuTalentArticle.setUserId(ShiroUtils.getUId());
|
||||
taihuTalentArticleService.save(taihuTalentArticle);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user