|
@@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.constant.CacheConstants;
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
|
@@ -14,11 +16,11 @@ import com.ruoyi.common.utils.ip.AddressUtils;
|
|
|
import com.ruoyi.generator.domain.Community.*;
|
|
|
import com.ruoyi.generator.mapper.community.*;
|
|
|
import com.ruoyi.generator.vo.*;
|
|
|
-import com.ruoyi.system.domain.CommunityChatMsg;
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
@@ -29,6 +31,7 @@ import java.time.ZoneId;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -123,6 +126,10 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
|
|
|
@Autowired
|
|
|
private CommunityArticleCircleMapper communityArticleCircleMapper;
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate<Object, Object> redisTemplate;
|
|
|
|
|
|
/**
|
|
|
* 查询文章列表
|
|
@@ -355,6 +362,273 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
return communityArticleVos;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询文章列表
|
|
|
+ *
|
|
|
+ * @param communityArticle 文章信息
|
|
|
+ * @return 文章信息集合
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<CommunityArticleVo> selectCommunityArticleList1(Long userId, TableDataInfo rspData, CommunityArticle communityArticle, int pageNum, int pageSize, int searchType) {
|
|
|
+
|
|
|
+ List<CommunityArticleVo> communityArticleVos = null;
|
|
|
+ //找出板块下的分类
|
|
|
+ List<Long> classIds = communityArticle.getClassIds();
|
|
|
+ Long id = communityArticle.getId();
|
|
|
+ List<Long> articleIds = communityArticle.getArticleIds();
|
|
|
+ Integer pageTagType = communityArticle.getPageTagType();
|
|
|
+ Integer noCollection = communityArticle.getNoCollection();
|
|
|
+ if (pageTagType != null && pageTagType == 1) {
|
|
|
+ List<CommunityUserLikeVo> communityUserLikeVos = selectCommunityUserLikeList(SecurityUtils.getUserId(), null, 1, 999999, 1);
|
|
|
+ if (communityUserLikeVos.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<Long> likeUserIds = communityUserLikeVos.stream().map(CommunityUserLikeVo::getLikeUserId).collect(Collectors.toList());
|
|
|
+ communityArticle.setUserIds(likeUserIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.nonNull(id)) {
|
|
|
+ //获取指定文章详细内容,文章浏览量+1
|
|
|
+ CommunityArticle article = communityArticleMapper.selectById(id);
|
|
|
+ article.setPageViews(article.getPageViews() + 1);
|
|
|
+ communityArticleMapper.updateById(article);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (articleIds != null && !articleIds.isEmpty()) {
|
|
|
+ for (Long articleId : articleIds) {
|
|
|
+ //获取指定文章详细内容,文章浏览量+1
|
|
|
+ CommunityArticle article = communityArticleMapper.selectById(articleId);
|
|
|
+ article.setPageViews(article.getPageViews() + 1);
|
|
|
+ communityArticleMapper.updateById(article);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据分类查找文章
|
|
|
+ int offset = (pageNum - 1) * pageSize;
|
|
|
+ communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, classIds, offset, pageSize, searchType, userId);
|
|
|
+
|
|
|
+ List<CommunityArticleVo> articleVos_copy = new ArrayList<>(communityArticleVos);
|
|
|
+ if (noCollection != null) {
|
|
|
+ if (noCollection == 1) {
|
|
|
+ //剔除是否有合集文章
|
|
|
+ List<Long> ids = communityArticleVos.stream().map(CommunityArticleVo::getId).collect(Collectors.toList());
|
|
|
+ if (!ids.isEmpty()) {
|
|
|
+ List<CommunityCollectionArticle> collections = communityCollectionArticleMapper.selectList(new QueryWrapper<CommunityCollectionArticle>()
|
|
|
+ .in("article_id", ids)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
+
|
|
|
+ for (CommunityArticleVo communityArticleVo : articleVos_copy) {
|
|
|
+ for (CommunityCollectionArticle collection : collections) {
|
|
|
+ if (collection.getArticleId().equals(communityArticleVo.getId())) {
|
|
|
+ communityArticleVos.remove(communityArticleVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据拉取区域
|
|
|
+ //判断当前文章是否被用户拉黑
|
|
|
+ //用户拉黑数据
|
|
|
+ List<CommunityUserBlock> communityUserBlocks = redisCache.getCacheList(CacheConstants.COMMUNITY_USER_BLOCK);
|
|
|
+ if (communityUserBlocks.isEmpty()) {
|
|
|
+ communityUserBlocks = communityUserBlockMapper.selectList(new QueryWrapper<CommunityUserBlock>());
|
|
|
+ redisCache.setCacheList(CacheConstants.COMMUNITY_USER_BLOCK, communityUserBlocks);
|
|
|
+ redisCache.expire(CacheConstants.COMMUNITY_USER_BLOCK, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //关注数据
|
|
|
+ List<CommunityUserLike> communityUserLikes = redisCache.getCacheList(CacheConstants.COMMUNITY_USER_LIKE);
|
|
|
+ if (communityUserLikes.isEmpty()) {
|
|
|
+ communityUserLikes = communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>());
|
|
|
+ redisCache.setCacheList(CacheConstants.COMMUNITY_USER_LIKE, communityUserLikes);
|
|
|
+ redisCache.expire(CacheConstants.COMMUNITY_USER_LIKE, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //文章板块数据
|
|
|
+ List<CommunityArticleClass> communityArticleClasses = redisCache.getCacheList(CacheConstants.COMMUNITY_ARTICLE_CLASS);
|
|
|
+ if (communityArticleClasses.isEmpty()) {
|
|
|
+ communityArticleClasses = communityArticleCircleMapper.selectList(new QueryWrapper<CommunityArticleClass>().eq("is_delete", false));
|
|
|
+ redisCache.setCacheList(CacheConstants.COMMUNITY_ARTICLE_CLASS, communityArticleClasses);
|
|
|
+ redisCache.expire(CacheConstants.COMMUNITY_ARTICLE_CLASS, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //文章点赞数据
|
|
|
+ List<CommunityLike> communityLikes = redisCache.getCacheList(CacheConstants.COMMUNITY_LIKE);
|
|
|
+ if (communityLikes.isEmpty()) {
|
|
|
+ communityLikes = communityLikeMapper.selectList(new QueryWrapper<CommunityLike>());
|
|
|
+ redisCache.setCacheList(CacheConstants.COMMUNITY_LIKE, communityLikes);
|
|
|
+ redisCache.expire(CacheConstants.COMMUNITY_LIKE, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //文章收藏数据
|
|
|
+ List<CommunityArticleCollect> communityArticleCollects = redisCache.getCacheList(CacheConstants.COMMUNITY_COLLECT);
|
|
|
+ if (communityArticleCollects.isEmpty()) {
|
|
|
+ communityArticleCollects = communityCollectMapper.selectList(new QueryWrapper<CommunityArticleCollect>());
|
|
|
+ redisCache.setCacheList(CacheConstants.COMMUNITY_COLLECT, communityArticleCollects);
|
|
|
+ redisCache.expire(CacheConstants.COMMUNITY_COLLECT, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //文章推荐数据
|
|
|
+ List<CommunityArticleRecommend> communityArticleRecommends = redisCache.getCacheList(CacheConstants.COMMUNITY_ARTICLE_RECOMMEND);
|
|
|
+ if (communityArticleRecommends.isEmpty()) {
|
|
|
+ communityArticleRecommends = recommendMapper.selectList(new QueryWrapper<CommunityArticleRecommend>().eq("is_delete", false));
|
|
|
+ redisCache.setCacheList(CacheConstants.COMMUNITY_ARTICLE_RECOMMEND, communityArticleRecommends);
|
|
|
+ redisCache.expire(CacheConstants.COMMUNITY_ARTICLE_RECOMMEND, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //中奖信息数据
|
|
|
+ List<CommunityCommentRaffle> communityCommentRaffles = redisCache.getCacheList(CacheConstants.COMMUNITY_COMMENT_RAFFLE);
|
|
|
+ if (communityCommentRaffles.isEmpty()) {
|
|
|
+ communityCommentRaffles = communityCommentRaffleMapper.selectList(new QueryWrapper<CommunityCommentRaffle>().eq("is_delete", false));
|
|
|
+ redisCache.setCacheList(CacheConstants.COMMUNITY_COMMENT_RAFFLE, communityCommentRaffles);
|
|
|
+ redisCache.expire(CacheConstants.COMMUNITY_COMMENT_RAFFLE, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //文章标签数据
|
|
|
+ List<CommunityArticleTag> communityArticleTags = redisCache.getCacheList(CacheConstants.COMMUNITY_ARTICLE_TAG);
|
|
|
+ if (communityArticleTags.isEmpty()) {
|
|
|
+ communityArticleTags = communityArticleTagMapper.selectList(new QueryWrapper<CommunityArticleTag>().eq("is_delete", false));
|
|
|
+ redisCache.setCacheList(CacheConstants.COMMUNITY_ARTICLE_TAG, communityArticleTags);
|
|
|
+ redisCache.expire(CacheConstants.COMMUNITY_ARTICLE_TAG, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //文章标签拉黑数据
|
|
|
+ List<CommunityTagBlock> communityTagBlocks = redisCache.getCacheList(CacheConstants.COMMUNITY_TAG_BLOCK);
|
|
|
+ if (communityTagBlocks.isEmpty()) {
|
|
|
+ communityTagBlocks = communityTagBlockMapper.selectList(new QueryWrapper<CommunityTagBlock>());
|
|
|
+ redisCache.setCacheList(CacheConstants.COMMUNITY_TAG_BLOCK, communityTagBlocks);
|
|
|
+ redisCache.expire(CacheConstants.COMMUNITY_TAG_BLOCK, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //文章标签
|
|
|
+ List<CommunityTag> communityTags = redisCache.getCacheList(CacheConstants.COMMUNITY_TAG);
|
|
|
+ if (communityTags.isEmpty()) {
|
|
|
+ communityTags = communityTagMapper.selectList(new QueryWrapper<CommunityTag>().eq("is_delete", false));
|
|
|
+ redisCache.setCacheList(CacheConstants.COMMUNITY_TAG, communityTags);
|
|
|
+ redisCache.expire(CacheConstants.COMMUNITY_TAG, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ rspData.setTotal(communityArticleVos.size());
|
|
|
+ List<CommunityArticleVo> communityArticleVos_copy = new ArrayList<>(communityArticleVos);
|
|
|
+ List<CommunityArticleImages> videoList = new ArrayList<>();
|
|
|
+ for (CommunityArticleVo articleVo : communityArticleVos_copy) {
|
|
|
+ //判断当前文章是否被用户拉黑
|
|
|
+ communityUserBlocks
|
|
|
+ .stream()
|
|
|
+ .filter(item -> item.getUserId().equals(userId) && item.getPeerId().equals(articleVo.getUserId()))
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(communityUserBlock -> articleVo.setBlock(communityUserBlock.isBlock()));
|
|
|
+
|
|
|
+ //获取文章是否被关注
|
|
|
+ communityUserLikes
|
|
|
+ .stream()
|
|
|
+ .filter(item -> item.getUserId().equals(userId) && item.getLikeUserId().equals(articleVo.getUserId()))
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(communityUserLike -> articleVo.setCare(communityUserLike.getUserId() != null));
|
|
|
+
|
|
|
+ //设置文章的板块 提取 classId,并转换成 List<Long>
|
|
|
+ List<CommunityArticleClass> communityArticleClassList = communityArticleClasses
|
|
|
+ .stream()
|
|
|
+ .filter(item ->
|
|
|
+ item.getArticleId().equals(articleVo.getId()) && !item.getIsDelete()).collect(Collectors.toList());
|
|
|
+ classIds = communityArticleClassList
|
|
|
+ .stream()
|
|
|
+ .map(CommunityArticleClass::getClassId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ articleVo.setClassIds(classIds);
|
|
|
+
|
|
|
+ List<Map<String, Object>> imageList = articleVo.getImageList();
|
|
|
+ List<Map<String, Object>> imageList_copy = new ArrayList<>(imageList);
|
|
|
+ CommunityArticleImages videos = null;
|
|
|
+ for (Map<String, Object> image : imageList_copy) {
|
|
|
+ String imageUrl = image.get("imageUrl").toString();
|
|
|
+ //判断是否是视频
|
|
|
+ boolean isVideo = isVideoFile(imageUrl);
|
|
|
+ if (isVideo) {
|
|
|
+ imageList.remove(image);
|
|
|
+ videos = JSONObject.parseObject(JSONObject.toJSONString(image), CommunityArticleImages.class);
|
|
|
+ //BeanUtils.copyProperties(image, videos);
|
|
|
+ videoList.add(videos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ articleVo.setVideoList(videoList);
|
|
|
+
|
|
|
+ //设置评论回复数量
|
|
|
+ articleVo.setCommentCount(communityArticleCommentMapper.queryCommentCount(articleVo.getId()));
|
|
|
+ //设置文章的点赞数量
|
|
|
+ articleVo.setLikeCount((int) communityLikes.stream().filter(item -> item.getArticleId().equals(articleVo.getId())).count());
|
|
|
+ //设置文章的收藏数量
|
|
|
+ articleVo.setCollectCount((int) communityArticleCollects.stream().filter(item -> item.getArticleId().equals(articleVo.getId())).count());
|
|
|
+ //设置文章推荐数量
|
|
|
+ articleVo.setRecommendCount((int) communityArticleRecommends.stream().filter(item -> item.getArticleId().equals(articleVo.getId()) && !item.isDelete()).count());
|
|
|
+ //设置文章所属合集
|
|
|
+ articleVo.setCollectionVo(communityCollectionMapper.selectCollectById(userId, articleVo.getId()));
|
|
|
+
|
|
|
+ //设置中奖信息
|
|
|
+ CommunityCommentRaffleVo communityCommentRaffleVo = new CommunityCommentRaffleVo();
|
|
|
+ communityCommentRaffles
|
|
|
+ .stream()
|
|
|
+ .filter(item -> item.getArticleId().equals(articleVo.getId()) && !item.isDelete())
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(communityCommentRaffle -> {
|
|
|
+ BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
|
|
|
+ CommunityUserInfoVo communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId());
|
|
|
+ communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
|
|
|
+ communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
|
|
|
+ articleVo.setCommentRaffleVo(communityCommentRaffleVo);
|
|
|
+ });
|
|
|
+
|
|
|
+ //判断是否已收藏
|
|
|
+ List<CommunityArticleCollect> collects = communityArticleCollects.stream().filter(item -> item.getUserId().equals(userId) && item.getArticleId().equals(articleVo.getId())).collect(Collectors.toList());
|
|
|
+ articleVo.setCollect(!collects.isEmpty());
|
|
|
+
|
|
|
+ //判断是否已点赞
|
|
|
+ List<CommunityLike> likes = communityLikes.stream().filter(item -> item.getUserId().equals(userId) && item.getArticleId().equals(articleVo.getId())).collect(Collectors.toList());
|
|
|
+ articleVo.setLike(!likes.isEmpty());
|
|
|
+
|
|
|
+ //判断是否已推荐
|
|
|
+ List<CommunityArticleRecommend> recommends = communityArticleRecommends.stream().filter(item -> item.getUserId().equals(userId) && item.getArticleId().equals(articleVo.getId()) && !item.isDelete()).collect(Collectors.toList());
|
|
|
+ articleVo.setRecommend(!recommends.isEmpty());
|
|
|
+
|
|
|
+ //获取文章标签
|
|
|
+ List<CommunityArticleTag> articleTags = communityArticleTags.stream().filter(item -> item.getArticleId().equals(articleVo.getId()) && !item.getIsDelete()).collect(Collectors.toList());
|
|
|
+ List<Long> tagList = articleTags.stream().map(CommunityArticleTag::getTagId).collect(Collectors.toList());
|
|
|
+ List<Long> tagIds = new ArrayList<>();
|
|
|
+
|
|
|
+ if (!tagList.isEmpty()) {
|
|
|
+ //判断当前标签是否被当前登录用户拉黑
|
|
|
+ List<CommunityTagBlock> communityTagBlockList = communityTagBlocks
|
|
|
+ .stream()
|
|
|
+ .filter(item -> tagList.contains(item.getTagId()) && item.getUserId().equals(userId))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (CommunityTagBlock tagBlock : communityTagBlockList) {
|
|
|
+ if (tagBlock.isBlock()) {
|
|
|
+ communityArticleVos.remove(articleVo);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ tagIds.add(tagBlock.getTagId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (communityTagBlockList.isEmpty()) {
|
|
|
+ tagIds.addAll(tagList);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!tagIds.isEmpty()) {
|
|
|
+ List<CommunityTag> communityTagList = communityTags
|
|
|
+ .stream()
|
|
|
+ .filter(item -> tagIds.contains(item.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ articleVo.setTags(communityTagList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return communityArticleVos;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发布文章
|
|
|
*
|
|
@@ -531,7 +805,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
})));
|
|
|
//不为空就不操作
|
|
|
- if (communityArticleTag == null ){
|
|
|
+ if (communityArticleTag == null) {
|
|
|
tagLog = new CommunityArticleTag();
|
|
|
tagLog.setArticleId(communityArticle.getId());
|
|
|
tagLog.setTagId(Long.parseLong(tag));
|
|
@@ -615,7 +889,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
null,
|
|
|
new UpdateWrapper<CommunityCollectionArticle>()
|
|
|
.eq("article_id", communityArticle.getId())
|
|
|
- .eq("create_by",userId)
|
|
|
+ .eq("create_by", userId)
|
|
|
.set("is_delete", true)
|
|
|
.and((wrapper) -> {
|
|
|
wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
@@ -1254,7 +1528,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<CommunityArticleVo> selectUserLike(Long userId,int pageNum, int pageSize, int searchType) {
|
|
|
+ public List<CommunityArticleVo> selectUserLike(Long userId, int pageNum, int pageSize, int searchType) {
|
|
|
// 查询自己的通知列表
|
|
|
List<CommunityLike> communityUserLike
|
|
|
= communityLikeMapper
|
|
@@ -1273,7 +1547,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<CommunityArticleVo> selectUserCollect(Long userId,int pageNum, int pageSize, int searchType) {
|
|
|
+ public List<CommunityArticleVo> selectUserCollect(Long userId, int pageNum, int pageSize, int searchType) {
|
|
|
// 查询自己的通知列表
|
|
|
List<CommunityArticleCollect> communityArticleCollects
|
|
|
= communityArticleCollectMapper
|