|
@@ -93,165 +93,6 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
@Autowired
|
|
|
private CommunityUserNotificationMapper communityUserNotificationMapper;
|
|
|
|
|
|
-// @Override
|
|
|
-// public List<CommunityArticleVo> selectCommunityArticleList(CommunityArticle communityArticle, int pageNum, int pageSize, int searchType) {
|
|
|
-// Long userId = SecurityUtils.getUserId();
|
|
|
-//
|
|
|
-// // 处理文章浏览量
|
|
|
-// updateArticlePageViews(communityArticle.getId());
|
|
|
-//
|
|
|
-// // 获取圈子IDs
|
|
|
-// List<Long> circleIds = getCircleIds(communityArticle.getClassId(), communityArticle.getCircleId());
|
|
|
-// if (circleIds.isEmpty()) {
|
|
|
-// return new ArrayList<>();
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 查询文章列表
|
|
|
-// int offset = (pageNum - 1) * pageSize;
|
|
|
-// List<CommunityArticleVo> articleVos = communityArticleMapper.selectCommunityArticleList(
|
|
|
-// communityArticle, circleIds, offset, pageSize, searchType);
|
|
|
-//
|
|
|
-// // 批量处理文章数据
|
|
|
-// return processArticleVos(articleVos, circleIds, userId);
|
|
|
-// }
|
|
|
-
|
|
|
- private void updateArticlePageViews(Long articleId) {
|
|
|
- if (Objects.nonNull(articleId)) {
|
|
|
- CommunityArticle article = communityArticleMapper.selectById(articleId);
|
|
|
- article.setPageViews(article.getPageViews() + 1);
|
|
|
- communityArticleMapper.updateById(article);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private List<Long> getCircleIds(Long classId, Long circleId) {
|
|
|
- if (Objects.nonNull(circleId)) {
|
|
|
- return Collections.singletonList(circleId);
|
|
|
- }
|
|
|
-
|
|
|
- if (Objects.nonNull(classId)) {
|
|
|
- return communityClassCircleMapper.selectList(
|
|
|
- new QueryWrapper<CommunityClassCircle>().eq("class_id", classId))
|
|
|
- .stream()
|
|
|
- .map(CommunityClassCircle::getCircleId)
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
-
|
|
|
- private List<CommunityArticleVo> processArticleVos(List<CommunityArticleVo> articleVos, List<Long> circleIds, Long userId) {
|
|
|
- List<CommunityArticleVo> result = new ArrayList<>(articleVos);
|
|
|
-
|
|
|
- for (CommunityArticleVo articleVo : result) {
|
|
|
- articleVo.setCircleIds(circleIds);
|
|
|
-
|
|
|
- // 处理图片和视频
|
|
|
- processMediaList(articleVo);
|
|
|
-
|
|
|
- // 设置计数
|
|
|
- setArticleCounts(articleVo);
|
|
|
-
|
|
|
- // 设置用户交互状态
|
|
|
- setUserInteractionStatus(articleVo, userId);
|
|
|
-
|
|
|
- // 处理文章标签
|
|
|
- if (!processArticleTags(articleVo, userId)) {
|
|
|
- result.remove(articleVo);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- private void processMediaList(CommunityArticleVo articleVo) {
|
|
|
- List<Map<String, Object>> imageList = articleVo.getImageList();
|
|
|
- List<CommunityArticleImages> videoList = new ArrayList<>();
|
|
|
-
|
|
|
- Iterator<Map<String, Object>> iterator = imageList.iterator();
|
|
|
- while (iterator.hasNext()) {
|
|
|
- Map<String, Object> image = iterator.next();
|
|
|
- String imageUrl = image.get("imageUrl").toString();
|
|
|
-
|
|
|
- if (isVideoFile(imageUrl)) {
|
|
|
- iterator.remove();
|
|
|
- CommunityArticleImages video = new CommunityArticleImages();
|
|
|
- BeanUtils.copyProperties(image, video);
|
|
|
- videoList.add(video);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- articleVo.setVideoList(videoList);
|
|
|
- }
|
|
|
-
|
|
|
- private void setArticleCounts(CommunityArticleVo articleVo) {
|
|
|
- Long articleId = articleVo.getId();
|
|
|
-
|
|
|
- // 使用单个查询获取所有计数
|
|
|
- articleVo.setLikeCount(communityLikeMapper.selectCount(
|
|
|
- new QueryWrapper<CommunityLike>().eq("article_id", articleId)).intValue());
|
|
|
-
|
|
|
- articleVo.setCollectCount(communityCollectMapper.selectCount(
|
|
|
- new QueryWrapper<CommunityArticleCollect>().eq("article_id", articleId)).intValue());
|
|
|
-
|
|
|
- articleVo.setRecommendCount(recommendMapper.selectCount(
|
|
|
- new QueryWrapper<CommunityArticleRecommend>()
|
|
|
- .eq("article_id", articleId)
|
|
|
- .and(wrapper -> wrapper.ne("is_delete", true).or().isNull("is_delete"))).intValue());
|
|
|
- }
|
|
|
-
|
|
|
- private void setUserInteractionStatus(CommunityArticleVo articleVo, Long userId) {
|
|
|
- Long articleId = articleVo.getId();
|
|
|
-
|
|
|
- articleVo.setCollect(communityCollectMapper.exists(
|
|
|
- new QueryWrapper<CommunityArticleCollect>()
|
|
|
- .eq("user_id", userId)
|
|
|
- .eq("article_id", articleId)));
|
|
|
-
|
|
|
- articleVo.setLike(communityLikeMapper.exists(
|
|
|
- new QueryWrapper<CommunityLike>()
|
|
|
- .eq("user_id", userId)
|
|
|
- .eq("article_id", articleId)));
|
|
|
-
|
|
|
- articleVo.setRecommend(recommendMapper.exists(
|
|
|
- new QueryWrapper<CommunityArticleRecommend>()
|
|
|
- .eq("user_id", userId)
|
|
|
- .eq("article_id", articleId)
|
|
|
- .and(wrapper -> wrapper.ne("is_delete", true).or().isNull("is_delete"))));
|
|
|
- }
|
|
|
-
|
|
|
- private boolean processArticleTags(CommunityArticleVo articleVo, Long userId) {
|
|
|
- List<CommunityArticleTag> articleTags = communityArticleTagMapper.selectList(
|
|
|
- new QueryWrapper<CommunityArticleTag>().eq("article_id", articleVo.getId()));
|
|
|
-
|
|
|
- List<Long> tagIds = articleTags.stream()
|
|
|
- .map(CommunityArticleTag::getTagId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- if (tagIds.isEmpty()) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- // 检查标签是否被拉黑
|
|
|
- List<CommunityTagBlock> tagBlocks = communityTagBlockMapper.selectList(
|
|
|
- new QueryWrapper<CommunityTagBlock>()
|
|
|
- .in("tag_id", tagIds)
|
|
|
- .eq("user_id", userId));
|
|
|
-
|
|
|
- if (tagBlocks.stream().anyMatch(CommunityTagBlock::isBlock)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- List<Long> validTagIds = tagBlocks.isEmpty() ? tagIds :
|
|
|
- tagBlocks.stream().map(CommunityTagBlock::getTagId).collect(Collectors.toList());
|
|
|
-
|
|
|
- if (!validTagIds.isEmpty()) {
|
|
|
- List<CommunityTag> communityTags = communityTagMapper.selectBatchIds(validTagIds);
|
|
|
- articleVo.setTags(communityTags);
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 查询文章列表
|
|
|
*
|
|
@@ -406,6 +247,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
communityArticle.setUserId(userId);
|
|
|
communityArticle.setCreateBy(userId);
|
|
|
communityArticle.setUpdateBy(userId);
|
|
|
+ communityArticle.setIsDelete(false);
|
|
|
communityArticle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
communityArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
communityArticleMapper.insert(communityArticle);
|