|
@@ -5,14 +5,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
-import com.ruoyi.generator.domain.Community.CommunityArticle;
|
|
|
-import com.ruoyi.generator.domain.Community.CommunityArticleCollect;
|
|
|
-import com.ruoyi.generator.domain.Community.CommunityArticleComment;
|
|
|
-import com.ruoyi.generator.domain.Community.CommunityLike;
|
|
|
-import com.ruoyi.generator.mapper.community.CommunityArticleCommentMapper;
|
|
|
-import com.ruoyi.generator.mapper.community.CommunityArticleMapper;
|
|
|
-import com.ruoyi.generator.mapper.community.CommunityCollectMapper;
|
|
|
-import com.ruoyi.generator.mapper.community.CommunityLikeMapper;
|
|
|
+import com.ruoyi.generator.domain.Community.*;
|
|
|
+import com.ruoyi.generator.mapper.community.*;
|
|
|
import com.ruoyi.generator.vo.CommunityArticleCommentVo;
|
|
|
import com.ruoyi.generator.vo.CommunityArticleVo;
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
@@ -21,6 +15,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.text.ParseException;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
@@ -44,9 +39,13 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
|
|
|
@Autowired
|
|
|
private CommunityCollectMapper communityCollectMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private CommunityArticleCommentMapper communityArticleCommentMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CommunityCommentLikeMapper communityCommentLikeMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询文章列表
|
|
|
*
|
|
@@ -56,31 +55,46 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
@Override
|
|
|
public List<CommunityArticleVo> selectCommunityArticleList(CommunityArticle communityArticle) {
|
|
|
List<CommunityArticleVo> communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle);
|
|
|
- CommunityArticleVo communityArticleVo = null;
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
- for (int i = 0; i < communityArticleVos.size(); i++) {
|
|
|
- communityArticleVo = communityArticleVos.get(i);
|
|
|
+ for (CommunityArticleVo articleVo : communityArticleVos) {
|
|
|
+ //设置文章的点赞数量
|
|
|
+ articleVo.setLikeCount(communityLikeMapper
|
|
|
+ .selectList(new QueryWrapper<CommunityLike>()
|
|
|
+ .eq("article_id", articleVo.getId()))
|
|
|
+ .size());
|
|
|
+
|
|
|
//文章下的评论
|
|
|
- List<CommunityArticleCommentVo> comments = communityArticleVo.getComments();
|
|
|
+ List<CommunityArticleCommentVo> comments = articleVo.getComments();
|
|
|
for (CommunityArticleCommentVo communityArticleCommentVo : comments) {
|
|
|
//获取评论的用户信息
|
|
|
SysUser sysUser = sysUserMapper.selectUserById(communityArticleCommentVo.getUserId());
|
|
|
communityArticleCommentVo.setUsername(sysUser.getUserName());
|
|
|
communityArticleCommentVo.setAvatar(sysUser.getAvatar());
|
|
|
+ //当前登录用户是否已点赞
|
|
|
+ List<CommunityCommentLike> commentLikes = communityCommentLikeMapper
|
|
|
+ .selectList(new QueryWrapper<CommunityCommentLike>()
|
|
|
+ .eq("comment_id", communityArticleCommentVo.getId()).eq("user_id", userId));
|
|
|
+ communityArticleCommentVo.setCommentLike(!commentLikes.isEmpty());
|
|
|
+
|
|
|
+ //该评论的点赞数量
|
|
|
+ communityArticleCommentVo.setCommentLikeCount(communityCommentLikeMapper
|
|
|
+ .selectList(new QueryWrapper<CommunityCommentLike>()
|
|
|
+ .eq("comment_id", communityArticleCommentVo.getId()))
|
|
|
+ .size());
|
|
|
|
|
|
//判断是否已收藏
|
|
|
CommunityArticleCollect collect = communityCollectMapper
|
|
|
.selectOne(new QueryWrapper<CommunityArticleCollect>()
|
|
|
.eq("user_id", userId)
|
|
|
.eq("article_id", communityArticleCommentVo.getArticleId()));
|
|
|
- communityArticleVo.setCollect(!Objects.isNull(collect));
|
|
|
+ articleVo.setCollect(!Objects.isNull(collect));
|
|
|
|
|
|
//判断是否已点赞
|
|
|
CommunityLike like = communityLikeMapper
|
|
|
.selectOne(new QueryWrapper<CommunityLike>()
|
|
|
.eq("user_id", userId)
|
|
|
.eq("article_id", communityArticleCommentVo.getArticleId()));
|
|
|
- communityArticleVo.setLike(!Objects.isNull(like));
|
|
|
+ articleVo.setLike(!Objects.isNull(like));
|
|
|
}
|
|
|
}
|
|
|
return communityArticleVos;
|
|
@@ -89,15 +103,16 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
|
|
|
/**
|
|
|
* 发送评论
|
|
|
+ *
|
|
|
* @param communityArticleComment 评论信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public void sendComment(CommunityArticleComment communityArticleComment) {
|
|
|
+ public void sendComment(CommunityArticleComment communityArticleComment) throws ParseException {
|
|
|
communityArticleComment.setId(null);
|
|
|
communityArticleComment.setCreateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
|
|
|
communityArticleComment.setUpdateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
|
|
|
- communityArticleComment.setCreateTime(DateUtils.parseDate(DateUtils.getNowDate()));
|
|
|
- communityArticleComment.setUpdateTime(DateUtils.parseDate(DateUtils.getNowDate()));
|
|
|
+ communityArticleComment.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ communityArticleComment.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
communityArticleCommentMapper.insert(communityArticleComment);
|
|
|
}
|
|
|
|