|
@@ -8,9 +8,7 @@ import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
|
import com.ruoyi.generator.domain.Community.*;
|
|
import com.ruoyi.generator.domain.Community.*;
|
|
import com.ruoyi.generator.mapper.community.*;
|
|
import com.ruoyi.generator.mapper.community.*;
|
|
-import com.ruoyi.generator.vo.CommunityArticleCommentVo;
|
|
|
|
-import com.ruoyi.generator.vo.CommunityArticleVo;
|
|
|
|
-import com.ruoyi.generator.vo.CommunityCircleVo;
|
|
|
|
|
|
+import com.ruoyi.generator.vo.*;
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -70,6 +68,12 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
@Autowired
|
|
@Autowired
|
|
private CommunityUserCircleMapper communityUserCircleMapper;
|
|
private CommunityUserCircleMapper communityUserCircleMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private CommunityUserLikeMapper communityUserLikeMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CommunityUserInfoMapper communityUserInfoMapper;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询文章列表
|
|
* 查询文章列表
|
|
*
|
|
*
|
|
@@ -77,7 +81,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
* @return 文章信息集合
|
|
* @return 文章信息集合
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public List<CommunityArticleVo> selectCommunityArticleList(CommunityArticle communityArticle) {
|
|
|
|
|
|
+ public List<CommunityArticleVo> selectCommunityArticleList(CommunityArticle communityArticle, int pageNum, int pageSize) {
|
|
//找出板块下的分类
|
|
//找出板块下的分类
|
|
Long classId = communityArticle.getClassId();
|
|
Long classId = communityArticle.getClassId();
|
|
List<CommunityClassCircle> classCircles = communityClassCircleMapper.selectList(new QueryWrapper<CommunityClassCircle>().eq("class_id", classId));
|
|
List<CommunityClassCircle> classCircles = communityClassCircleMapper.selectList(new QueryWrapper<CommunityClassCircle>().eq("class_id", classId));
|
|
@@ -85,64 +89,68 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
for (CommunityClassCircle classCircle : classCircles) {
|
|
for (CommunityClassCircle classCircle : classCircles) {
|
|
circleIds.add(classCircle.getCircleId());
|
|
circleIds.add(classCircle.getCircleId());
|
|
}
|
|
}
|
|
-
|
|
|
|
- List<CommunityArticleVo> communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, circleIds);
|
|
|
|
- Long userId = SecurityUtils.getUserId();
|
|
|
|
- for (CommunityArticleVo articleVo : communityArticleVos) {
|
|
|
|
- //设置文章的点赞数量
|
|
|
|
- articleVo.setLikeCount(communityLikeMapper
|
|
|
|
- .selectList(new QueryWrapper<CommunityLike>()
|
|
|
|
- .eq("article_id", articleVo.getId()))
|
|
|
|
- .size());
|
|
|
|
-
|
|
|
|
- //文章下的评论
|
|
|
|
- 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()))
|
|
|
|
|
|
+ List<CommunityArticleVo> communityArticleVos = new ArrayList<>();
|
|
|
|
+ if (!classCircles.isEmpty()) {
|
|
|
|
+
|
|
|
|
+ int offset = (pageNum - 1) * pageSize;
|
|
|
|
+ communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, circleIds, offset, pageSize);
|
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
|
+ for (CommunityArticleVo articleVo : communityArticleVos) {
|
|
|
|
+ //设置文章的点赞数量
|
|
|
|
+ articleVo.setLikeCount(communityLikeMapper
|
|
|
|
+ .selectList(new QueryWrapper<CommunityLike>()
|
|
|
|
+ .eq("article_id", articleVo.getId()))
|
|
.size());
|
|
.size());
|
|
- }
|
|
|
|
|
|
|
|
- //判断是否已收藏
|
|
|
|
- CommunityArticleCollect collect = communityCollectMapper
|
|
|
|
- .selectOne(new QueryWrapper<CommunityArticleCollect>()
|
|
|
|
- .eq("user_id", userId)
|
|
|
|
- .eq("article_id", articleVo.getId()));
|
|
|
|
- articleVo.setCollect(!Objects.isNull(collect));
|
|
|
|
-
|
|
|
|
- //判断是否已点赞
|
|
|
|
- CommunityLike like = communityLikeMapper
|
|
|
|
- .selectOne(new QueryWrapper<CommunityLike>()
|
|
|
|
- .eq("user_id", userId)
|
|
|
|
- .eq("article_id", articleVo.getId()));
|
|
|
|
- articleVo.setLike(!Objects.isNull(like));
|
|
|
|
-
|
|
|
|
- //获取文章标签
|
|
|
|
- List<CommunityArticleTag> articleTags = communityArticleTagMapper
|
|
|
|
- .selectList(new QueryWrapper<CommunityArticleTag>()
|
|
|
|
- .eq("article_id", articleVo.getId()));
|
|
|
|
- List<Long> tagIds = new ArrayList<>();
|
|
|
|
- for (CommunityArticleTag articleTag : articleTags) {
|
|
|
|
- tagIds.add(articleTag.getTagId());
|
|
|
|
- }
|
|
|
|
|
|
+ //文章下的评论
|
|
|
|
+ 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", articleVo.getId()));
|
|
|
|
+ articleVo.setCollect(!Objects.isNull(collect));
|
|
|
|
+
|
|
|
|
+ //判断是否已点赞
|
|
|
|
+ CommunityLike like = communityLikeMapper
|
|
|
|
+ .selectOne(new QueryWrapper<CommunityLike>()
|
|
|
|
+ .eq("user_id", userId)
|
|
|
|
+ .eq("article_id", articleVo.getId()));
|
|
|
|
+ articleVo.setLike(!Objects.isNull(like));
|
|
|
|
+
|
|
|
|
+ //获取文章标签
|
|
|
|
+ List<CommunityArticleTag> articleTags = communityArticleTagMapper
|
|
|
|
+ .selectList(new QueryWrapper<CommunityArticleTag>()
|
|
|
|
+ .eq("article_id", articleVo.getId()));
|
|
|
|
+ List<Long> tagIds = new ArrayList<>();
|
|
|
|
+ for (CommunityArticleTag articleTag : articleTags) {
|
|
|
|
+ tagIds.add(articleTag.getTagId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!tagIds.isEmpty()) {
|
|
|
|
+ List<CommunityTag> communityTags = communityTagMapper.selectBatchIds(tagIds);
|
|
|
|
+ articleVo.setTags(communityTags);
|
|
|
|
+ }
|
|
|
|
|
|
- if (!tagIds.isEmpty()) {
|
|
|
|
- List<CommunityTag> communityTags = communityTagMapper.selectBatchIds(tagIds);
|
|
|
|
- articleVo.setTags(communityTags);
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
return communityArticleVos;
|
|
return communityArticleVos;
|
|
}
|
|
}
|
|
@@ -323,4 +331,100 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
}
|
|
}
|
|
return communityCircleVos;
|
|
return communityCircleVos;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 关注或取消关注用户粉丝/关注
|
|
|
|
+ *
|
|
|
|
+ * @param likeUserId 被关注人id
|
|
|
|
+ * @return 登录用户关注信息
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public CommunityUserLike addOrDeleteUserLike(Long likeUserId) {
|
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId(); // 当前登录用户id
|
|
|
|
+ //1.检查是否已被当前用户关注
|
|
|
|
+ CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>()
|
|
|
|
+ .eq("user_id", userId)
|
|
|
|
+ .eq("like_user_id", likeUserId));
|
|
|
|
+ //2.1 没有则进行关注,返回关注列表信息
|
|
|
|
+ if (Objects.isNull(communityUserLike) || Objects.isNull(communityUserLike.getId())) {
|
|
|
|
+ communityUserLike = new CommunityUserLike();
|
|
|
|
+ communityUserLike.setUserId(userId);
|
|
|
|
+ communityUserLike.setLikeUserId(likeUserId);
|
|
|
|
+ communityUserLike.setCreateBy(userId);
|
|
|
|
+ communityUserLike.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
|
+ communityUserLikeMapper.insert(communityUserLike);
|
|
|
|
+
|
|
|
|
+ communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>()
|
|
|
|
+ .eq("user_id", userId)
|
|
|
|
+ .eq("like_user_id", likeUserId));
|
|
|
|
+ return communityUserLike;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //2.2 已关注则取消关注
|
|
|
|
+ communityUserLikeMapper.deleteById(communityUserLike);
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取当前登录用户信息
|
|
|
|
+ *
|
|
|
|
+ * @param userId 用户id
|
|
|
|
+ * @return 用户信息
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public CommunityUserInfoVo selectCommunityUserInfoById(Long userId) {
|
|
|
|
+ SysUser sysUser = sysUserMapper.selectUserById(userId);
|
|
|
|
+ CommunityUserInfo communityUserInfo = communityUserInfoMapper
|
|
|
|
+ .selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", userId));
|
|
|
|
+ CommunityUserInfoVo communityUserInfoVo = new CommunityUserInfoVo();
|
|
|
|
+ BeanUtils.copyProperties(communityUserInfo, communityUserInfoVo);
|
|
|
|
+ communityUserInfoVo.setAvatar(sysUser.getAvatar());
|
|
|
|
+ communityUserInfoVo.setNickName(sysUser.getNickName());
|
|
|
|
+ communityUserInfoVo.setUserId(userId);
|
|
|
|
+ return communityUserInfoVo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取关注列表
|
|
|
|
+ *
|
|
|
|
+ * @param userId 登录用户id
|
|
|
|
+ * @return 当前用户关注列表
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<CommunityUserLikeVo> selectCommunityUserLikeList(Long userId) {
|
|
|
|
+ List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>().eq("user_id", userId));
|
|
|
|
+ List<CommunityUserLikeVo> communityUserLikeVos = new ArrayList<>();
|
|
|
|
+ CommunityUserLikeVo communityUserLikeVo = null;
|
|
|
|
+ for (CommunityUserLike communityUserLike : communityUserLikes) {
|
|
|
|
+ communityUserLikeVo = new CommunityUserLikeVo();
|
|
|
|
+ SysUser sysUser = sysUserMapper.selectUserById(communityUserLike.getLikeUserId());
|
|
|
|
+ BeanUtils.copyProperties(communityUserLike, communityUserLikeVo);
|
|
|
|
+ communityUserLikeVo.setLikeUsername(sysUser.getUserName());
|
|
|
|
+ communityUserLikeVos.add(communityUserLikeVo);
|
|
|
|
+ }
|
|
|
|
+ return communityUserLikeVos;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取粉丝列表
|
|
|
|
+ *
|
|
|
|
+ * @param userId 登录用户id
|
|
|
|
+ * @return 当前用户粉丝列表
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<CommunityUserLikeVo> selectUserFansList(Long userId) {
|
|
|
|
+ List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>().eq("like_user_id", userId));
|
|
|
|
+ List<CommunityUserLikeVo> communityUserLikeVos = new ArrayList<>();
|
|
|
|
+ CommunityUserLikeVo communityUserLikeVo = null;
|
|
|
|
+ for (CommunityUserLike communityUserLike : communityUserLikes) {
|
|
|
|
+ communityUserLikeVo = new CommunityUserLikeVo();
|
|
|
|
+ BeanUtils.copyProperties(communityUserLike, communityUserLikeVo);
|
|
|
|
+ SysUser sysUser = sysUserMapper.selectUserById(communityUserLike.getUserId());
|
|
|
|
+ communityUserLikeVo.setUsername(sysUser.getUserName());
|
|
|
|
+ communityUserLikeVos.add(communityUserLikeVo);
|
|
|
|
+ }
|
|
|
|
+ return communityUserLikeVos;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|