|
@@ -19,8 +19,10 @@ import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 业务 服务层实现
|
|
* 业务 服务层实现
|
|
@@ -87,96 +89,171 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
//找出板块下的分类
|
|
//找出板块下的分类
|
|
Long classId = communityArticle.getClassId();
|
|
Long classId = communityArticle.getClassId();
|
|
Long userId = SecurityUtils.getUserId();
|
|
Long userId = SecurityUtils.getUserId();
|
|
- List<CommunityClassCircle> classCircles = communityClassCircleMapper.selectList(new QueryWrapper<CommunityClassCircle>().eq("class_id", classId));
|
|
|
|
- List<Long> circleIds = new ArrayList<>();
|
|
|
|
- for (CommunityClassCircle classCircle : classCircles) {
|
|
|
|
- circleIds.add(classCircle.getCircleId());
|
|
|
|
|
|
+ List<Long> circleIds = null;
|
|
|
|
+ if (!Objects.isNull(classId)) {
|
|
|
|
+ List<CommunityClassCircle> classCircles = communityClassCircleMapper.selectList(new QueryWrapper<CommunityClassCircle>().eq("class_id", classId));
|
|
|
|
+ circleIds = new ArrayList<>();
|
|
|
|
+ for (CommunityClassCircle classCircle : classCircles) {
|
|
|
|
+ circleIds.add(classCircle.getCircleId());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- List<CommunityArticleVo> communityArticleVos = new ArrayList<>();
|
|
|
|
- if (!classCircles.isEmpty()) {
|
|
|
|
- int offset = (pageNum - 1) * pageSize;
|
|
|
|
- communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, circleIds, offset, pageSize);
|
|
|
|
- for (CommunityArticleVo articleVo : communityArticleVos) {
|
|
|
|
- List<CommunityArticleImages> imageList = articleVo.getImageList();
|
|
|
|
- List<CommunityArticleImages> videoList = new ArrayList<>();
|
|
|
|
- CommunityArticleImages videos = null;
|
|
|
|
- for (CommunityArticleImages image : imageList) {
|
|
|
|
- videos = new CommunityArticleImages();
|
|
|
|
- String imageUrl = image.getImageUrl();
|
|
|
|
- //判断是否是视频
|
|
|
|
- boolean isVideo = isVideoFile(imageUrl);
|
|
|
|
- if (isVideo) {
|
|
|
|
- imageList.remove(image);
|
|
|
|
- BeanUtils.copyProperties(image, videos);
|
|
|
|
- videoList.add(videos);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- articleVo.setVideoList(videoList);
|
|
|
|
-
|
|
|
|
- //设置文章的点赞数量
|
|
|
|
- articleVo.setLikeCount(communityLikeMapper
|
|
|
|
- .selectList(new QueryWrapper<CommunityLike>()
|
|
|
|
- .eq("article_id", articleVo.getId()))
|
|
|
|
- .size());
|
|
|
|
|
|
|
|
- articleVo.setCollectCount(communityCollectMapper
|
|
|
|
- .selectList(new QueryWrapper<CommunityArticleCollect>()
|
|
|
|
- .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()))
|
|
|
|
- .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());
|
|
|
|
|
|
+ //根据分类查找文章
|
|
|
|
+ int offset = (pageNum - 1) * pageSize;
|
|
|
|
+ List<CommunityArticleVo> communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, circleIds, offset, pageSize);
|
|
|
|
+ for (CommunityArticleVo articleVo : communityArticleVos) {
|
|
|
|
+ List<CommunityArticleImages> imageList = articleVo.getImageList();
|
|
|
|
+ List<CommunityArticleImages> videoList = new ArrayList<>();
|
|
|
|
+ CommunityArticleImages videos = null;
|
|
|
|
+ for (CommunityArticleImages image : imageList) {
|
|
|
|
+ videos = new CommunityArticleImages();
|
|
|
|
+ String imageUrl = image.getImageUrl();
|
|
|
|
+ //判断是否是视频
|
|
|
|
+ boolean isVideo = isVideoFile(imageUrl);
|
|
|
|
+ if (isVideo) {
|
|
|
|
+ imageList.remove(image);
|
|
|
|
+ BeanUtils.copyProperties(image, videos);
|
|
|
|
+ videoList.add(videos);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ articleVo.setVideoList(videoList);
|
|
|
|
+
|
|
|
|
+ //设置文章的点赞数量
|
|
|
|
+ articleVo.setLikeCount(communityLikeMapper
|
|
|
|
+ .selectList(new QueryWrapper<CommunityLike>()
|
|
|
|
+ .eq("article_id", articleVo.getId()))
|
|
|
|
+ .size());
|
|
|
|
+
|
|
|
|
+ articleVo.setCollectCount(communityCollectMapper
|
|
|
|
+ .selectList(new QueryWrapper<CommunityArticleCollect>()
|
|
|
|
+ .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()))
|
|
|
|
+ .size());
|
|
|
|
+ }
|
|
|
|
|
|
- if (!tagIds.isEmpty()) {
|
|
|
|
- List<CommunityTag> communityTags = communityTagMapper.selectBatchIds(tagIds);
|
|
|
|
- articleVo.setTags(communityTags);
|
|
|
|
- }
|
|
|
|
|
|
+ //判断是否已收藏
|
|
|
|
+ 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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return communityArticleVos;
|
|
return communityArticleVos;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// @Override
|
|
|
|
+// public List<CommunityArticleVo> selectCommunityArticleList1(CommunityArticle communityArticle, int pageNum, int pageSize) {
|
|
|
|
+// Long classId = communityArticle.getClassId();
|
|
|
|
+// Long userId = SecurityUtils.getUserId();
|
|
|
|
+// List<Long> circleIds = null;
|
|
|
|
+//
|
|
|
|
+// // 获取分类圈子ID
|
|
|
|
+// if (classId != null) {
|
|
|
|
+// circleIds = communityClassCircleMapper.getCircleIdsByClassId(classId);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 使用分页和偏移量查询文章
|
|
|
|
+// int offset = (pageNum - 1) * pageSize;
|
|
|
|
+// List<CommunityArticleVo> communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, circleIds, offset, pageSize);
|
|
|
|
+//
|
|
|
|
+// // 批量获取文章ID列表
|
|
|
|
+// List<Long> articleIds = communityArticleVos.stream().map(CommunityArticleVo::getId).collect(Collectors.toList());
|
|
|
|
+//
|
|
|
|
+// if (!articleIds.isEmpty()) {
|
|
|
|
+// // 批量查询点赞、收藏、评论等相关信息,减少单次查询
|
|
|
|
+// Map<Long, Integer> likeCounts = communityLikeMapper.getLikeCountsByArticleIds(articleIds);
|
|
|
|
+// Map<Long, Integer> collectCounts = communityCollectMapper.getCollectCountsByArticleIds(articleIds);
|
|
|
|
+// Map<Long, List<CommunityArticleImages>> imagesMap = communityArticleImagesMapper.getImagesByArticleIds(articleIds);
|
|
|
|
+// Map<Long, List<CommunityArticleCommentVo>> commentsMap = communityArticleCommentMapper.getCommentsByArticleIds(articleIds);
|
|
|
|
+//
|
|
|
|
+// // 批量获取用户是否点赞/收藏信息
|
|
|
|
+// Map<Long, Boolean> userLikes = communityLikeMapper.getUserLikesByArticleIds(userId, articleIds);
|
|
|
|
+// Map<Long, Boolean> userCollects = communityCollectMapper.getUserCollectsByArticleIds(userId, articleIds);
|
|
|
|
+//
|
|
|
|
+// for (CommunityArticleVo articleVo : communityArticleVos) {
|
|
|
|
+// Long articleId = articleVo.getId();
|
|
|
|
+//
|
|
|
|
+// // 设置文章的点赞和收藏数量
|
|
|
|
+// articleVo.setLikeCount(likeCounts.getOrDefault(articleId, 0));
|
|
|
|
+// articleVo.setCollectCount(collectCounts.getOrDefault(articleId, 0));
|
|
|
|
+//
|
|
|
|
+// // 设置用户点赞/收藏状态
|
|
|
|
+// articleVo.setLike(userLikes.getOrDefault(articleId, false));
|
|
|
|
+// articleVo.setCollect(userCollects.getOrDefault(articleId, false));
|
|
|
|
+//
|
|
|
|
+// // 设置图片和视频
|
|
|
|
+// List<CommunityArticleImages> imageList = imagesMap.get(articleId);
|
|
|
|
+// List<CommunityArticleImages> videoList = new ArrayList<>();
|
|
|
|
+// if (imageList != null) {
|
|
|
|
+// for (Iterator<CommunityArticleImages> iterator = imageList.iterator(); iterator.hasNext(); ) {
|
|
|
|
+// CommunityArticleImages image = iterator.next();
|
|
|
|
+// if (isVideoFile(image.getImageUrl())) {
|
|
|
|
+// videoList.add(image);
|
|
|
|
+// iterator.remove();
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// articleVo.setImageList(imageList);
|
|
|
|
+// articleVo.setVideoList(videoList);
|
|
|
|
+//
|
|
|
|
+// // 设置评论信息
|
|
|
|
+// List<CommunityArticleCommentVo> comments = commentsMap.get(articleId);
|
|
|
|
+// if (comments != null) {
|
|
|
|
+// for (CommunityArticleCommentVo comment : comments) {
|
|
|
|
+// // 设置评论的用户信息及点赞状态
|
|
|
|
+// SysUser sysUser = sysUserMapper.selectUserById(comment.getUserId());
|
|
|
|
+// comment.setUsername(sysUser.getUserName());
|
|
|
|
+// comment.setAvatar(sysUser.getAvatar());
|
|
|
|
+// comment.setCommentLike(communityCommentLikeMapper.isUserLikedComment(comment.getId(), userId));
|
|
|
|
+// comment.setCommentLikeCount(communityCommentLikeMapper.getCommentLikeCount(comment.getId()));
|
|
|
|
+// }
|
|
|
|
+// articleVo.setComments(comments);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// return communityArticleVos;
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 发布文章
|
|
* 发布文章
|
|
@@ -412,6 +489,17 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
.selectList(new QueryWrapper<CommunityUserLike>()
|
|
.selectList(new QueryWrapper<CommunityUserLike>()
|
|
.eq("like_user_id", userId)).size());
|
|
.eq("like_user_id", userId)).size());
|
|
communityUserInfoVo.setCompanionCount(0);
|
|
communityUserInfoVo.setCompanionCount(0);
|
|
|
|
+
|
|
|
|
+ //设置是否被当前登录的用户关注
|
|
|
|
+ communityUserInfoVo.setLike(false);
|
|
|
|
+ Long loginUserId = SecurityUtils.getLoginUser().getUserId();
|
|
|
|
+ if (!Objects.equals(userId, loginUserId)) {
|
|
|
|
+ CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>().eq("user_id", loginUserId).eq("like_user_id", userId));
|
|
|
|
+ if (!Objects.isNull(communityUserLike) && !Objects.isNull(communityUserLike.getId())) {
|
|
|
|
+ communityUserInfoVo.setLike(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
return communityUserInfoVo;
|
|
return communityUserInfoVo;
|
|
}
|
|
}
|
|
|
|
|