|
@@ -1,1773 +0,0 @@
|
|
|
-package com.ruoyi.generator.service;
|
|
|
-
|
|
|
-import com.alibaba.fastjson2.JSONObject;
|
|
|
-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;
|
|
|
-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.mapper.SysUserMapper;
|
|
|
-import org.apache.ibatis.annotations.Param;
|
|
|
-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;
|
|
|
-import java.net.URL;
|
|
|
-import java.text.ParseException;
|
|
|
-import java.time.LocalDate;
|
|
|
-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;
|
|
|
-
|
|
|
-/**
|
|
|
- * 业务 服务层实现
|
|
|
- *
|
|
|
- * @author ruoyi
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMapper, CommunityArticle> implements ICommunityArticleService {
|
|
|
- private static final Logger log = LoggerFactory.getLogger(CommunityArticleServiceImpl.class);
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityArticleMapper communityArticleMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SysUserMapper sysUserMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityLikeMapper communityLikeMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityCollectMapper communityCollectMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityArticleCommentMapper communityArticleCommentMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityCommentLikeMapper communityCommentLikeMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityArticleTagMapper articleTagMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityArticleTagMapper communityArticleTagMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityTagMapper communityTagMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityArticleImagesMapper communityArticleImagesMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityClassCircleMapper communityClassCircleMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityCircleMapper communityCircleMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityUserCircleMapper communityUserCircleMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityUserLikeMapper communityUserLikeMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityUserInfoMapper communityUserInfoMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ICommunityArticleClassService communityArticleClassService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityCollectionArticleMapper communityCollectionArticleMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ICommunityCollectionArticleService collectionArticleService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityTagBlockMapper communityTagBlockMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityArticleRecommendMapper recommendMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ICommunityArticleService communityArticleService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ICommunityPrivacyService communityPrivacyService;
|
|
|
- @Autowired
|
|
|
- private CommunityCollectionMapper communityCollectionMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityUserBlockMapper communityUserBlockMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityUserPromptMapper communityUserPromptMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityArticleCollectMapper communityArticleCollectMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityCommentRaffleMapper communityCommentRaffleMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommunityArticleCircleMapper communityArticleCircleMapper;
|
|
|
- @Autowired
|
|
|
- private RedisCache redisCache;
|
|
|
- @Autowired
|
|
|
- private RedisTemplate<Object, Object> redisTemplate;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ICommunityArticleAtService communityArticleAtService;
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询文章列表
|
|
|
- *
|
|
|
- * @param communityArticle 文章信息
|
|
|
- * @return 文章信息集合
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<CommunityArticleVo> selectCommunityArticleList(Long userId, TableDataInfo rspData, CommunityArticle communityArticle, int pageNum, int pageSize, int searchType) {
|
|
|
-
|
|
|
- List<CommunityArticleVo> communityArticleVos = null;
|
|
|
- //找出板块下的分类
|
|
|
- List<Long> classIds = communityArticle.getClassIds();
|
|
|
- System.out.println("classIds: " + classIds);
|
|
|
- if (classIds != null && classIds.contains(19L)) { // Check for null and then use contains()
|
|
|
- classIds = null;
|
|
|
- searchType = 3;
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Boolean isDraft = communityArticle.getIsDraft();
|
|
|
- //判断草稿箱是否为空 为空则为false
|
|
|
- if (isDraft == null) {
|
|
|
- communityArticle.setIsDraft(false);
|
|
|
- }
|
|
|
-
|
|
|
- //根据分类查找文章
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- rspData.setTotal(communityArticleVos.size());
|
|
|
- List<CommunityArticleVo> communityArticleVos_copy = new ArrayList<>(communityArticleVos);
|
|
|
- for (CommunityArticleVo articleVo : communityArticleVos_copy) {
|
|
|
- //判断当前文章是否被用户拉黑
|
|
|
- List<CommunityUserBlock> communityUserBlocks = communityUserBlockMapper.selectList(new QueryWrapper<CommunityUserBlock>()
|
|
|
- .eq("user_id", userId)
|
|
|
- .eq("peer_id", articleVo.getUserId()));
|
|
|
-
|
|
|
- for (CommunityUserBlock userBlock : communityUserBlocks) {
|
|
|
- if (userBlock.isBlock()) {
|
|
|
- articleVo.setBlock(userBlock.isBlock());
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //获取文章是否被关注
|
|
|
- List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>()
|
|
|
- .eq("user_id", userId)
|
|
|
- .eq("like_user_id", articleVo.getUserId())
|
|
|
- );
|
|
|
-
|
|
|
- for (CommunityUserLike communityUserLike : communityUserLikes) {
|
|
|
- articleVo.setCare(communityUserLike.getUserId() != null);
|
|
|
- }
|
|
|
-
|
|
|
- /* communityArticleMapper.selectList();
|
|
|
- articleVo.setCare();*/
|
|
|
-
|
|
|
- List<Map<String, Object>> imageList = articleVo.getImageList();
|
|
|
-
|
|
|
- //设置文章的板块
|
|
|
- List<CommunityArticleClass> articleId = communityArticleCircleMapper.selectList(
|
|
|
- new QueryWrapper<CommunityArticleClass>()
|
|
|
- .eq("article_id", articleVo.getId())
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- })
|
|
|
- );
|
|
|
- // 使用 Java Streams API 提取 classId,并转换成 List<Long>
|
|
|
- List<Long> classIdss = articleId.stream()
|
|
|
- .map(CommunityArticleClass::getClassId)
|
|
|
- .collect(Collectors.toList());
|
|
|
- articleVo.setClassIds(classIdss);
|
|
|
-
|
|
|
-
|
|
|
- List<CommunityArticleImages> videoList = new ArrayList<>();
|
|
|
- CommunityArticleImages videos = null;
|
|
|
- List<Map<String, Object>> imageList_copy = new ArrayList<>(imageList);
|
|
|
- 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(communityLikeMapper.selectList(new QueryWrapper<CommunityLike>().eq("article_id", articleVo.getId())).size());
|
|
|
- //设置文章的收藏数量
|
|
|
- articleVo.setCollectCount(communityCollectMapper.selectList(new QueryWrapper<CommunityArticleCollect>().eq("article_id", articleVo.getId())).size());
|
|
|
- //设置文章推荐数量
|
|
|
- articleVo.setRecommendCount(recommendMapper.selectList(new QueryWrapper<CommunityArticleRecommend>()
|
|
|
- .eq("article_id", articleVo.getId())
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- })).size());
|
|
|
- //设置文章所属合集
|
|
|
- articleVo.setCollectionVo(communityCollectionMapper.selectCollectById(userId, articleVo.getId()));
|
|
|
-
|
|
|
-
|
|
|
- //设置中奖信息
|
|
|
- CommunityCommentRaffleVo communityCommentRaffleVo = new CommunityCommentRaffleVo();
|
|
|
- CommunityCommentRaffle communityCommentRaffle = communityCommentRaffleMapper.selectOne(
|
|
|
- new QueryWrapper<CommunityCommentRaffle>()
|
|
|
- .eq("article_id", articleVo.getId())
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- }));
|
|
|
- if (communityCommentRaffle != null) {
|
|
|
- BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
|
|
|
- CommunityUserInfoVo communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId(), false);
|
|
|
- communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
|
|
|
- communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
|
|
|
- articleVo.setCommentRaffleVo(communityCommentRaffleVo);
|
|
|
- }
|
|
|
- //文章下的评论
|
|
|
-// List<Map<String, Object>> comments = articleVo.getComments();
|
|
|
-// for (Map<String, Object> communityArticleCommentVo : comments) {
|
|
|
-// String commentUserId = communityArticleCommentVo.get("userId").toString();
|
|
|
-// if (Objects.isNull(commentUserId)) {
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// //获取评论的用户信息
|
|
|
-// SysUser sysUser = sysUserMapper.selectUserById(Long.parseLong(commentUserId));
|
|
|
-// communityArticleCommentVo.put("username", sysUser.getUserName());
|
|
|
-// communityArticleCommentVo.put("avatar", sysUser.getAvatar());
|
|
|
-// //当前登录用户是否已点赞
|
|
|
-// List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", communityArticleCommentVo.get("id")).eq("user_id", userId));
|
|
|
-// communityArticleCommentVo.put("commentLike", !commentLikes.isEmpty());
|
|
|
-//
|
|
|
-// //该评论的点赞数量
|
|
|
-// communityArticleCommentVo.put("commentLikeCount", communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", communityArticleCommentVo.get("id"))).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));
|
|
|
-
|
|
|
- //判断是否已推荐
|
|
|
- CommunityArticleRecommend recommend = recommendMapper.selectOne(new QueryWrapper<CommunityArticleRecommend>()
|
|
|
- .eq("user_id", userId)
|
|
|
- .eq("article_id", articleVo.getId()).and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- }));
|
|
|
- articleVo.setRecommend(!Objects.isNull(recommend));
|
|
|
-
|
|
|
- //获取文章标签
|
|
|
- List<CommunityArticleTag> articleTags = communityArticleTagMapper.selectList(new QueryWrapper<CommunityArticleTag>()
|
|
|
- .eq("article_id", articleVo.getId())
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- }));
|
|
|
- List<Long> tagList = articleTags.stream().map(CommunityArticleTag::getTagId).collect(Collectors.toList());
|
|
|
- List<Long> tagIds = new ArrayList<>();
|
|
|
-
|
|
|
- if (!tagList.isEmpty()) {
|
|
|
- //判断当前标签是否被当前登录用户拉黑
|
|
|
- List<CommunityTagBlock> communityTagBlocks = communityTagBlockMapper.selectList(new QueryWrapper<CommunityTagBlock>()
|
|
|
- .in("tag_id", tagList)
|
|
|
- .eq("user_id", userId)
|
|
|
- .eq("is_block", 1));
|
|
|
-
|
|
|
- for (CommunityTagBlock tagBlock : communityTagBlocks) {
|
|
|
- if (tagBlock.isBlock()) {
|
|
|
- communityArticleVos.remove(articleVo);
|
|
|
- break;
|
|
|
- }
|
|
|
- tagIds.add(tagBlock.getTagId());
|
|
|
- }
|
|
|
-
|
|
|
- if (communityTagBlocks.isEmpty()) {
|
|
|
- tagIds.addAll(tagList);
|
|
|
- }
|
|
|
-
|
|
|
- if (!tagIds.isEmpty()) {
|
|
|
- List<CommunityTag> communityTags = communityTagMapper.selectBatchIds(tagIds);
|
|
|
- articleVo.setTags(communityTags);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- 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>().eq("is_block", 1));
|
|
|
- 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(), true);
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发布文章
|
|
|
- *
|
|
|
- * @param communityArticle 文章信息
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void insertCommunityArticle(CommunityArticle communityArticle) {
|
|
|
-
|
|
|
- //判断是否传ID 如果有ID贼删除原来的文章 重新插入一条新文章
|
|
|
- if (communityArticle.getId() != null) {
|
|
|
- //增加字段 文章编辑字段
|
|
|
- communityArticle.setIsDelete(true);
|
|
|
-
|
|
|
- UpdateWrapper<CommunityArticle> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.eq("id", communityArticle.getId());
|
|
|
-
|
|
|
- // 创建一个新的 CommunityArticle 对象,只设置 isDelete 字段
|
|
|
- CommunityArticle updateArticle = new CommunityArticle();
|
|
|
- updateArticle.setIsDelete(communityArticle.getIsDelete());
|
|
|
-
|
|
|
- communityArticleService.update(updateArticle, updateWrapper);
|
|
|
-
|
|
|
- communityArticle.setParentId(communityArticle.getId());
|
|
|
- communityArticle.setId(null);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
- //插入文章信息
|
|
|
- communityArticle.setUserId(userId);
|
|
|
- communityArticle.setCreateBy(userId);
|
|
|
- communityArticle.setUpdateBy(userId);
|
|
|
- communityArticle.setIsDelete(false);
|
|
|
-/* communityArticle.setComment(false);
|
|
|
- communityArticle.setDownload(false);
|
|
|
- communityArticle.setRaffle(false);*/
|
|
|
- communityArticle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
-
|
|
|
- String address = null;
|
|
|
- try {
|
|
|
- address = AddressUtils.getAddress(null);
|
|
|
- } catch (ExecutionException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- communityArticle.setAddress(address);
|
|
|
-
|
|
|
- communityArticleMapper.insert(communityArticle);
|
|
|
- //插入标签日志
|
|
|
- List<String> tags = communityArticle.getTags();
|
|
|
- if (tags != null && !tags.isEmpty()) {
|
|
|
- CommunityArticleTag tagLog = null;
|
|
|
- for (String tag : tags) {
|
|
|
- tagLog = new CommunityArticleTag();
|
|
|
- tagLog.setArticleId(communityArticle.getId());
|
|
|
- tagLog.setTagId(Long.parseLong(tag));
|
|
|
- tagLog.setUpdateBy(userId);
|
|
|
- tagLog.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- tagLog.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- tagLog.setCreateBy(userId);
|
|
|
- articleTagMapper.insert(tagLog);
|
|
|
-
|
|
|
- //标签热度自增
|
|
|
- CommunityTag communityTag = communityTagMapper.selectById(Long.parseLong(tag));
|
|
|
- communityTag.setTagHot(Objects.isNull(communityTag.getTagHot()) ? 1 : communityTag.getTagHot() + 1);
|
|
|
- communityTag.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityTag.setUpdateBy(userId);
|
|
|
- communityTagMapper.updateById(communityTag);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //插入图片日志
|
|
|
- List<CommunityImagesVo> images = communityArticle.getImages();
|
|
|
- if (images != null && !images.isEmpty()) {
|
|
|
- CommunityArticleImages articleImages = null;
|
|
|
- for (CommunityImagesVo image : images) {
|
|
|
- articleImages = new CommunityArticleImages();
|
|
|
- articleImages.setArticleId(communityArticle.getId());
|
|
|
- articleImages.setImageUrl(image.getImages());
|
|
|
- articleImages.setCompressUrl(image.getCompressedImages());
|
|
|
- articleImages.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- articleImages.setCreateBy(userId);
|
|
|
- communityArticleImagesMapper.insert(articleImages);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //插入板块
|
|
|
- List<Long> classIds = communityArticle.getClassIds();
|
|
|
- if (classIds != null && !classIds.isEmpty()) {
|
|
|
- List<CommunityArticleClass> articleClasses = new ArrayList<>();
|
|
|
- CommunityArticleClass articleClass = null;
|
|
|
- for (Long classId : classIds) {
|
|
|
- articleClass = new CommunityArticleClass();
|
|
|
- articleClass.setClassId(classId);
|
|
|
- articleClass.setArticleId(communityArticle.getId());
|
|
|
- articleClass.setCreateBy(userId);
|
|
|
- articleClass.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- articleClasses.add(articleClass);
|
|
|
- }
|
|
|
- communityArticleClassService.saveBatch(articleClasses);
|
|
|
- }
|
|
|
-
|
|
|
- //插入合集
|
|
|
- List<String> collectionIds = communityArticle.getCollectionIds();
|
|
|
- if (collectionIds != null && !collectionIds.isEmpty()) {
|
|
|
- List<CommunityCollectionArticle> collectionArticles = new ArrayList<>();
|
|
|
- CommunityCollectionArticle collectionArticle = null;
|
|
|
- for (String collectionId : collectionIds) {
|
|
|
- collectionArticle = new CommunityCollectionArticle();
|
|
|
- collectionArticle.setCollectionId(Long.parseLong(collectionId));
|
|
|
- collectionArticle.setArticleId(communityArticle.getId());
|
|
|
- collectionArticle.setCreateBy(userId);
|
|
|
- collectionArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- collectionArticles.add(collectionArticle);
|
|
|
- }
|
|
|
- collectionArticleService.saveBatch(collectionArticles);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // at 人插入at通知表 判断是不是草稿箱 草稿箱不需要通知
|
|
|
- if (communityArticle.getIsDraft() != null && !communityArticle.getIsDraft()) {
|
|
|
- //拿到需要At人的ID
|
|
|
- List<Long> atUserIds = communityArticle.getAtUserIds();
|
|
|
- if (atUserIds != null && !atUserIds.isEmpty()) {
|
|
|
- List<CommunityArticleAt> communityArticleAts = new ArrayList<>();
|
|
|
- CommunityArticleAt communityArticleAt = null;
|
|
|
- for (Long atUserId : atUserIds) {
|
|
|
- communityArticleAt = new CommunityArticleAt();
|
|
|
- communityArticleAt.setType(0L);
|
|
|
- communityArticleAt.setArticleId(communityArticle.getId());
|
|
|
- communityArticleAt.setUserId(userId);
|
|
|
- communityArticleAt.setPeerId(atUserId);
|
|
|
- communityArticleAt.setCreateBy(userId);
|
|
|
- communityArticleAt.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityArticleAts.add(communityArticleAt);
|
|
|
- }
|
|
|
- communityArticleAtService.saveBatch(communityArticleAts);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 编辑文章
|
|
|
- *
|
|
|
- * @param communityArticle 文章信息
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void editCommunityArticle(CommunityArticle communityArticle) {
|
|
|
-
|
|
|
- Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
- //编辑文章信息
|
|
|
- communityArticle.setUpdateBy(userId);
|
|
|
- communityArticle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
-
|
|
|
-
|
|
|
- CommunityArticle article = communityArticleMapper.selectOne((new QueryWrapper<CommunityArticle>()
|
|
|
- .eq("id", communityArticle.getId())
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- })));
|
|
|
-
|
|
|
- if (article != null) {
|
|
|
- Integer pageViews = Math.toIntExact(article.getPageViews());
|
|
|
- if (pageViews != null) {
|
|
|
- communityArticle.setPageViews(pageViews);
|
|
|
- } else {
|
|
|
- // 处理 pageViews 为 null 的情况,比如设置为 0 或记录日志
|
|
|
- communityArticle.setPageViews(0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String address = null;
|
|
|
- try {
|
|
|
- address = AddressUtils.getAddress(null);
|
|
|
- } catch (ExecutionException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- communityArticle.setAddress(address);
|
|
|
-
|
|
|
- communityArticleMapper.updateById(communityArticle);
|
|
|
-
|
|
|
-
|
|
|
- //插入标签日志
|
|
|
- List<String> tags = communityArticle.getTags();
|
|
|
- if (tags != null && !tags.isEmpty()) {
|
|
|
- //不在本次更新的标签都传失效
|
|
|
- communityArticleTagMapper.update(
|
|
|
- null,
|
|
|
- new UpdateWrapper<CommunityArticleTag>()
|
|
|
- .eq("article_id", communityArticle.getId())
|
|
|
- .notIn("tag_id", tags)
|
|
|
- .set("is_delete", true)
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
- })
|
|
|
- );
|
|
|
-
|
|
|
- CommunityArticleTag tagLog = null;
|
|
|
- for (String tag : tags) {
|
|
|
-
|
|
|
- //查询该标签是否在数据库中存在
|
|
|
- CommunityArticleTag communityArticleTag = communityArticleTagMapper.selectOne((new QueryWrapper<CommunityArticleTag>()
|
|
|
- .eq("article_id", communityArticle.getId())
|
|
|
- .eq("tag_id", tag)
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- })));
|
|
|
- //不为空就不操作
|
|
|
- if (communityArticleTag == null) {
|
|
|
- tagLog = new CommunityArticleTag();
|
|
|
- tagLog.setArticleId(communityArticle.getId());
|
|
|
- tagLog.setTagId(Long.parseLong(tag));
|
|
|
- tagLog.setUpdateBy(userId);
|
|
|
- tagLog.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- tagLog.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- tagLog.setCreateBy(userId);
|
|
|
- articleTagMapper.insert(tagLog);
|
|
|
-
|
|
|
- //标签热度自增
|
|
|
- CommunityTag communityTag = communityTagMapper.selectById(Long.parseLong(tag));
|
|
|
- communityTag.setTagHot(Objects.isNull(communityTag.getTagHot()) ? 1 : communityTag.getTagHot() + 1);
|
|
|
- communityTag.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityTag.setUpdateBy(userId);
|
|
|
- communityTagMapper.updateById(communityTag);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //插入图片日志
|
|
|
- List<CommunityImagesVo> images = communityArticle.getImages();
|
|
|
-
|
|
|
- //插入图片日志 都失效
|
|
|
- communityArticleImagesMapper.update(
|
|
|
- null,
|
|
|
- new UpdateWrapper<CommunityArticleImages>()
|
|
|
- .eq("article_id", communityArticle.getId())
|
|
|
- .set("is_delete", true)
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
- })
|
|
|
- );
|
|
|
-
|
|
|
- if (images != null && !images.isEmpty()) {
|
|
|
- CommunityArticleImages articleImages = null;
|
|
|
- for (CommunityImagesVo image : images) {
|
|
|
- articleImages = new CommunityArticleImages();
|
|
|
- articleImages.setArticleId(communityArticle.getId());
|
|
|
- articleImages.setImageUrl(image.getImages());
|
|
|
- articleImages.setCompressUrl(image.getCompressedImages());
|
|
|
- articleImages.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- articleImages.setCreateBy(userId);
|
|
|
- communityArticleImagesMapper.insert(articleImages);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //插入板块
|
|
|
- List<Long> classIds = communityArticle.getClassIds();
|
|
|
-
|
|
|
- //插入板块 都失效
|
|
|
- communityArticleClassService.update(
|
|
|
- null,
|
|
|
- new UpdateWrapper<CommunityArticleClass>()
|
|
|
- .eq("article_id", communityArticle.getId())
|
|
|
- .set("is_delete", true)
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
- })
|
|
|
- );
|
|
|
-
|
|
|
- if (classIds != null && !classIds.isEmpty()) {
|
|
|
- List<CommunityArticleClass> articleClasses = new ArrayList<>();
|
|
|
- CommunityArticleClass articleClass = null;
|
|
|
- for (Long classId : classIds) {
|
|
|
- articleClass = new CommunityArticleClass();
|
|
|
- articleClass.setClassId(classId);
|
|
|
- articleClass.setArticleId(communityArticle.getId());
|
|
|
- articleClass.setCreateBy(userId);
|
|
|
- articleClass.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- articleClasses.add(articleClass);
|
|
|
- }
|
|
|
- communityArticleClassService.saveBatch(articleClasses);
|
|
|
- }
|
|
|
-
|
|
|
- //插入合集
|
|
|
- List<String> collectionIds = communityArticle.getCollectionIds();
|
|
|
-
|
|
|
- if (collectionIds != null && !collectionIds.isEmpty()) {
|
|
|
- //插入合集 都失效
|
|
|
- collectionArticleService.update(
|
|
|
- null,
|
|
|
- new UpdateWrapper<CommunityCollectionArticle>()
|
|
|
- .eq("article_id", communityArticle.getId())
|
|
|
- .eq("create_by", userId)
|
|
|
- .set("is_delete", true)
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
- })
|
|
|
- );
|
|
|
-
|
|
|
- List<CommunityCollectionArticle> collectionArticles = new ArrayList<>();
|
|
|
- CommunityCollectionArticle collectionArticle = null;
|
|
|
- for (String collectionId : collectionIds) {
|
|
|
- collectionArticle = new CommunityCollectionArticle();
|
|
|
- collectionArticle.setCollectionId(Long.parseLong(collectionId));
|
|
|
- collectionArticle.setArticleId(communityArticle.getId());
|
|
|
- collectionArticle.setCreateBy(userId);
|
|
|
- collectionArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- collectionArticles.add(collectionArticle);
|
|
|
- }
|
|
|
- collectionArticleService.saveBatch(collectionArticles);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // at 人插入at通知表 判断是不是草稿箱 草稿箱不需要通知
|
|
|
- if (communityArticle.getIsDraft() != null && !communityArticle.getIsDraft()) {
|
|
|
- //拿到需要At人的ID
|
|
|
- List<Long> atUserIds = communityArticle.getAtUserIds();
|
|
|
-
|
|
|
- if (atUserIds != null && !atUserIds.isEmpty()) {
|
|
|
- List<CommunityArticleAt> communityArticleAts = new ArrayList<>();
|
|
|
- CommunityArticleAt communityArticleAt = null;
|
|
|
- for (Long atUserId : atUserIds) {
|
|
|
- communityArticleAt = new CommunityArticleAt();
|
|
|
- communityArticleAt.setType(0L);
|
|
|
- communityArticleAt.setArticleId(communityArticle.getId());
|
|
|
- communityArticleAt.setUserId(userId);
|
|
|
- communityArticleAt.setPeerId(atUserId);
|
|
|
- communityArticleAt.setCreateBy(userId);
|
|
|
- communityArticleAt.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityArticleAts.add(communityArticleAt);
|
|
|
- }
|
|
|
- communityArticleAtService.saveBatch(communityArticleAts);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送评论
|
|
|
- *
|
|
|
- * @param communityArticleComment 评论信息
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void sendComment(CommunityArticleComment communityArticleComment) throws ParseException {
|
|
|
- communityArticleComment.setId(null);
|
|
|
- communityArticleComment.setCreateBy(SecurityUtils.getLoginUser().getUserId());
|
|
|
- communityArticleComment.setUpdateBy(SecurityUtils.getLoginUser().getUserId());
|
|
|
- communityArticleComment.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityArticleComment.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityArticleComment.setDelete(false);
|
|
|
- String address = null;
|
|
|
- try {
|
|
|
- address = AddressUtils.getAddress(null);
|
|
|
- } catch (ExecutionException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
-
|
|
|
- communityArticleComment.setAddress(address);
|
|
|
- communityArticleCommentMapper.insert(communityArticleComment);
|
|
|
-
|
|
|
- //拿到需要At人的ID
|
|
|
- List<Long> atUserIds = communityArticleComment.getAtUserIds();
|
|
|
- if (atUserIds != null && !atUserIds.isEmpty()) {
|
|
|
- List<CommunityArticleAt> communityArticleAts = new ArrayList<>();
|
|
|
- CommunityArticleAt communityArticleAt = null;
|
|
|
- for (Long atUserId : atUserIds) {
|
|
|
- communityArticleAt = new CommunityArticleAt();
|
|
|
- communityArticleAt.setType(1L);
|
|
|
- communityArticleAt.setArticleId(communityArticleComment.getArticleId());
|
|
|
- communityArticleAt.setCommentId(communityArticleComment.getId());
|
|
|
- communityArticleAt.setUserId(SecurityUtils.getLoginUser().getUserId());
|
|
|
- communityArticleAt.setPeerId(atUserId);
|
|
|
- communityArticleAt.setCreateBy(SecurityUtils.getLoginUser().getUserId());
|
|
|
- communityArticleAt.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityArticleAts.add(communityArticleAt);
|
|
|
- }
|
|
|
- communityArticleAtService.saveBatch(communityArticleAts);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除评论
|
|
|
- *
|
|
|
- * @param communityArticleComment 评论信息
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void deleteComment(CommunityArticleComment communityArticleComment) {
|
|
|
- communityArticleComment.setDelete(true);
|
|
|
- communityArticleComment.setUpdateBy(SecurityUtils.getUserId());
|
|
|
- communityArticleComment.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityArticleCommentMapper.updateById(communityArticleComment);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询该文章对应的用户是否已经点赞
|
|
|
- *
|
|
|
- * @param communityLike 点赞信息
|
|
|
- * @return 点赞信息
|
|
|
- */
|
|
|
- @Override
|
|
|
- public CommunityLike selectCommunityLikeById(CommunityLike communityLike) {
|
|
|
- QueryWrapper<CommunityLike> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("article_id", communityLike.getArticleId()).eq("user_id", communityLike.getUserId());
|
|
|
- return communityLikeMapper.selectOne(queryWrapper);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 新增点赞
|
|
|
- *
|
|
|
- * @param communityLike 点赞信息
|
|
|
- * @return 点赞是否成功
|
|
|
- */
|
|
|
- @Override
|
|
|
- public boolean insertCommunityLikeById(CommunityLike communityLike) {
|
|
|
- return communityLikeMapper.insert(communityLike) > 0;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除点赞
|
|
|
- *
|
|
|
- * @param communityLike 点赞信息
|
|
|
- * @return 删除是否成功
|
|
|
- */
|
|
|
- @Override
|
|
|
- public boolean deleteCommunityLikeById(CommunityLike communityLike) {
|
|
|
- return communityLikeMapper.deleteById(communityLike.getId()) > 0;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询该文章对应的用户是否已经收藏
|
|
|
- *
|
|
|
- * @param collect 收藏信息
|
|
|
- * @return 收藏信息
|
|
|
- */
|
|
|
- @Override
|
|
|
- public CommunityArticleCollect selectCommunityCollectById(CommunityArticleCollect collect) {
|
|
|
- return communityCollectMapper.selectOne(new QueryWrapper<CommunityArticleCollect>().eq("article_id", collect.getArticleId()).eq("user_id", SecurityUtils.getUserId()));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 新增收藏
|
|
|
- *
|
|
|
- * @param collect 收藏信息
|
|
|
- * @return 收藏是否成功
|
|
|
- */
|
|
|
- @Override
|
|
|
- public boolean insertCommunityCollectById(CommunityArticleCollect collect) {
|
|
|
- return communityCollectMapper.insert(collect) > 0;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除收藏
|
|
|
- *
|
|
|
- * @param collect 收藏信息
|
|
|
- * @return 删除是否成功
|
|
|
- */
|
|
|
- @Override
|
|
|
- public boolean deleteCommunityCollectById(CommunityArticleCollect collect) {
|
|
|
- return communityCollectMapper.deleteById(collect) > 0;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据板块获取圈子列表
|
|
|
- *
|
|
|
- * @param classId 板块id
|
|
|
- * @return 圈子列表信息
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<CommunityCircleVo> selectCommunityCircleList(String classId) {
|
|
|
- List<CommunityClassCircle> classes = communityClassCircleMapper.selectList(new QueryWrapper<CommunityClassCircle>().eq("class_id", classId));
|
|
|
- List<Long> circleIds = new ArrayList<>();
|
|
|
- for (CommunityClassCircle aClass : classes) {
|
|
|
- circleIds.add(aClass.getCircleId());
|
|
|
- }
|
|
|
-
|
|
|
- List<CommunityCircleVo> communityCircleVos = null;
|
|
|
- if (!circleIds.isEmpty()) {
|
|
|
- List<CommunityCircle> communityCircles = communityCircleMapper.selectBatchIds(circleIds);
|
|
|
- //复制到Vo对象中
|
|
|
- communityCircleVos = new ArrayList<>();
|
|
|
- CommunityCircleVo communityCircleVo = null;
|
|
|
- for (CommunityCircle communityCircle : communityCircles) {
|
|
|
- communityCircleVo = new CommunityCircleVo();
|
|
|
- BeanUtils.copyProperties(communityCircle, communityCircleVo);
|
|
|
-
|
|
|
- //获取当前用户是否有关注这些圈子
|
|
|
- CommunityUserCircle communityUserCircles = communityUserCircleMapper.selectOne(new QueryWrapper<CommunityUserCircle>().eq("circle_id", communityCircle.getId()).eq("user_id", SecurityUtils.getLoginUser().getUserId()).eq("is_delete", 0));
|
|
|
- if (Objects.isNull(communityUserCircles) || Objects.isNull(communityUserCircles.getId())) {
|
|
|
- //没找到关注数据,则设为false,反之则true
|
|
|
- communityCircleVo.setLike(false);
|
|
|
- } else {
|
|
|
- communityCircleVo.setLike(true);
|
|
|
- }
|
|
|
- communityCircleVos.add(communityCircleVo);
|
|
|
- }
|
|
|
- }
|
|
|
- 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.setRead(false);
|
|
|
- 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, boolean isToken) {
|
|
|
- SysUser sysUser = sysUserMapper.selectUserById(userId);
|
|
|
-
|
|
|
- System.out.println(sysUser);
|
|
|
- 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.setSex(sysUser.getSex());
|
|
|
- communityUserInfoVo.setUserId(userId);
|
|
|
- communityUserInfoVo.setUserState(sysUser.getUserState());
|
|
|
- communityUserInfoVo.setReportTime(sysUser.getReportTime());
|
|
|
-
|
|
|
- //设置关注,粉丝,陪伴天数 文章数量
|
|
|
- communityUserInfoVo.setLikeCount(communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>().eq("user_id", userId)).size());
|
|
|
- communityUserInfoVo.setFansCount(communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>().eq("like_user_id", userId)).size());
|
|
|
-
|
|
|
- Date createTime = sysUser.getCreateTime();
|
|
|
- // 将 Date 对象转换为 LocalDate 对象
|
|
|
- LocalDate localCreateTime = createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
- // 获取当前日期
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
- // 计算两个日期之间的天数差
|
|
|
- long daysDifference = ChronoUnit.DAYS.between(localCreateTime, today);
|
|
|
- communityUserInfoVo.setCompanionCount((int) daysDifference);
|
|
|
-
|
|
|
- communityUserInfoVo.setArticleCount(communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
|
|
|
- .eq("user_id", userId)
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- })).size());
|
|
|
-
|
|
|
-
|
|
|
- String address = null;
|
|
|
- try {
|
|
|
- address = AddressUtils.getAddress(sysUser.getLoginIp());
|
|
|
- } catch (ExecutionException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- communityUserInfoVo.setAddress(address);
|
|
|
- //设置是否被当前登录的用户关注
|
|
|
- communityUserInfoVo.setLike(false);
|
|
|
- if (isToken) {
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据条件搜索用户列表信息(无权限卡控)
|
|
|
- *
|
|
|
- * @param searchValue 搜索值
|
|
|
- * @return 用户
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<CommunityUserInfoVo> selectUserBySearchValue(@Param("searchValue") String searchValue,
|
|
|
- @Param("offset") int offset,
|
|
|
- @Param("limit") int limit) {
|
|
|
- return communityUserInfoMapper.selectUserBySearchValue(searchValue, offset, limit);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<CommunityUserInfoVo> selectBlockUserBySearchValue(@Param("searchValue") String searchValue,
|
|
|
- @Param("userId") Long userId,
|
|
|
- @Param("offset") int offset,
|
|
|
- @Param("limit") int limit) {
|
|
|
- return communityUserInfoMapper.selectBlockUserBySearchValue(searchValue, userId, offset, limit);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据条件搜索用户列表信息(有权限卡控)
|
|
|
- *
|
|
|
- * @param searchValue 搜索值
|
|
|
- * @return 用户
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<CommunityUserInfoVo> selectUsersByAccountOrName(@Param("searchValue") String searchValue,
|
|
|
- @Param("offset") int offset,
|
|
|
- @Param("limit") int limit) {
|
|
|
- List<CommunityUserInfoVo> communityUserInfoVos = communityUserInfoMapper.selectUsersByAccountOrName(searchValue, offset, limit);
|
|
|
- communityUserInfoVos.forEach(item -> {
|
|
|
- CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>()
|
|
|
- .eq("user_id", SecurityUtils.getUserId())
|
|
|
- .eq("like_user_id", item.getUserId()));
|
|
|
-
|
|
|
- if (Objects.nonNull(communityUserLike)) {
|
|
|
- item.setLike(true);
|
|
|
- }
|
|
|
- });
|
|
|
- return communityUserInfoVos;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取关注列表
|
|
|
- *
|
|
|
- * @param userId 登录用户id
|
|
|
- * @return 当前用户关注列表
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<CommunityUserLikeVo> selectCommunityUserLikeList(Long userId, String userName, int pageNum, int pageSize, int searchType) {
|
|
|
- int offset = (pageNum - 1) * pageSize;
|
|
|
-// Page<CommunityUserLike> page = new Page<>(pageNum, pageSize);
|
|
|
-// QueryWrapper<CommunityUserLike> queryWrapper = new QueryWrapper<CommunityUserLike>()
|
|
|
-// .eq("user_id", userId);
|
|
|
-// if (searchType == 1) {
|
|
|
-// queryWrapper.orderByDesc("create_time");
|
|
|
-// } else {
|
|
|
-// queryWrapper.orderByAsc("create_time");
|
|
|
-// }
|
|
|
-//
|
|
|
-// List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectPage(page, queryWrapper).getRecords();
|
|
|
-
|
|
|
- List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectUserLikeList(userId, offset, pageSize, userName, searchType);
|
|
|
-
|
|
|
- List<CommunityUserLikeVo> communityUserLikeVos = new ArrayList<>();
|
|
|
- CommunityUserLikeVo communityUserLikeVo = null;
|
|
|
- Boolean isCare = false;
|
|
|
-
|
|
|
- for (CommunityUserLike communityUserLike : communityUserLikes) {
|
|
|
- communityUserLikeVo = new CommunityUserLikeVo();
|
|
|
- //用户信息
|
|
|
- SysUser sysUserLike = sysUserMapper.selectUserById(communityUserLike.getLikeUserId());
|
|
|
- SysUser sysUser = sysUserMapper.selectUserById(communityUserLike.getUserId());
|
|
|
- //用户自我介绍
|
|
|
- CommunityUserInfo userInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getUserId()));
|
|
|
- CommunityUserInfo likeUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getLikeUserId()));
|
|
|
- BeanUtils.copyProperties(communityUserLike, communityUserLikeVo);
|
|
|
-
|
|
|
- //关注的用户是否已经关注当前用户
|
|
|
- CommunityUserLike communityUserLikeFans = communityUserLikeMapper.selectOne(
|
|
|
- new QueryWrapper<CommunityUserLike>()
|
|
|
- .eq("like_user_id", userId)
|
|
|
- .eq("user_id", communityUserLike.getLikeUserId()));
|
|
|
-
|
|
|
- if (communityUserLikeFans != null) {
|
|
|
- isCare = true;
|
|
|
- }
|
|
|
- communityUserLikeVo.setIsCare(isCare);
|
|
|
-
|
|
|
- if (Objects.nonNull(userInfo)) {
|
|
|
- communityUserLikeVo.setProfile(userInfo.getProfile());
|
|
|
- }
|
|
|
-
|
|
|
- if (Objects.nonNull(likeUserInfo)) {
|
|
|
- communityUserLikeVo.setLikeProfile(likeUserInfo.getProfile());
|
|
|
- }
|
|
|
-
|
|
|
- if (Objects.nonNull(sysUser)) {
|
|
|
- communityUserLikeVo.setAvatar(sysUser.getAvatar());
|
|
|
- communityUserLikeVo.setUsername(sysUser.getNickName());
|
|
|
- }
|
|
|
-
|
|
|
- if (Objects.nonNull(sysUserLike)) {
|
|
|
- communityUserLikeVo.setLikeUsername(sysUserLike.getNickName());
|
|
|
- communityUserLikeVo.setLikeAvatar(sysUserLike.getAvatar());
|
|
|
- }
|
|
|
-
|
|
|
- //如果不需要搜索名字直接添加
|
|
|
-// if (userName != null && communityUserLikeVo.getLikeUsername().matches("(?i).*" + Pattern.quote(userName) + ".*")) {
|
|
|
-// communityUserLikeVos.add(communityUserLikeVo);
|
|
|
-// } else if (userName == null) {
|
|
|
-// communityUserLikeVos.add(communityUserLikeVo);
|
|
|
-// }
|
|
|
- communityUserLikeVos.add(communityUserLikeVo);
|
|
|
- }
|
|
|
- return communityUserLikeVos;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取粉丝列表
|
|
|
- *
|
|
|
- * @param userId 登录用户id
|
|
|
- * @return 当前用户粉丝列表
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<CommunityUserLikeVo> selectUserFansList(Long userId, String userName, int pageNum, int pageSize, int searchType) {
|
|
|
- //int offset = (pageNum - 1) * pageSize;
|
|
|
- Page<CommunityUserLike> page = new Page<>(pageNum, pageSize);
|
|
|
- QueryWrapper<CommunityUserLike> queryWrapper = new QueryWrapper<CommunityUserLike>()
|
|
|
- .eq("like_user_id", userId);
|
|
|
- if (searchType == 1) {
|
|
|
- queryWrapper.orderByDesc("create_time");
|
|
|
- } else {
|
|
|
- queryWrapper.orderByAsc("create_time");
|
|
|
- }
|
|
|
-
|
|
|
- List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectPage(page, queryWrapper).getRecords();
|
|
|
-
|
|
|
- List<CommunityUserLikeVo> communityUserLikeVos = new ArrayList<>();
|
|
|
- CommunityUserLikeVo communityUserLikeVo = null;
|
|
|
-
|
|
|
- for (CommunityUserLike communityUserLike : communityUserLikes) {
|
|
|
- Boolean isCare = false;
|
|
|
- // System.out.println(communityUserLike.getUserId() + "---" + userId);
|
|
|
- //用户信息
|
|
|
- SysUser sysUserLike = sysUserMapper.selectUserById(communityUserLike.getLikeUserId());
|
|
|
- //用户自我介绍
|
|
|
- CommunityUserInfo userInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getUserId()));
|
|
|
- CommunityUserInfo likeUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getLikeUserId()));
|
|
|
-
|
|
|
-
|
|
|
- //用户是否关注当前用户
|
|
|
- CommunityUserLike communityUserLikeFans = communityUserLikeMapper.selectOne(
|
|
|
- new QueryWrapper<CommunityUserLike>()
|
|
|
- .eq("like_user_id", communityUserLike.getUserId())
|
|
|
- .eq("user_id", userId));
|
|
|
-
|
|
|
- if (communityUserLikeFans != null) {
|
|
|
- isCare = true;
|
|
|
- }
|
|
|
- communityUserLikeVo = new CommunityUserLikeVo();
|
|
|
- BeanUtils.copyProperties(communityUserLike, communityUserLikeVo);
|
|
|
- SysUser sysUser = sysUserMapper.selectUserById(communityUserLike.getUserId());
|
|
|
-
|
|
|
- communityUserLikeVo.setIsCare(isCare);
|
|
|
-
|
|
|
-
|
|
|
- if (Objects.nonNull(sysUser)) {
|
|
|
- communityUserLikeVo.setAvatar(sysUser.getAvatar());
|
|
|
- communityUserLikeVo.setUsername(sysUser.getNickName());
|
|
|
- }
|
|
|
-
|
|
|
- if (Objects.nonNull(userInfo)) {
|
|
|
- communityUserLikeVo.setProfile(userInfo.getProfile());
|
|
|
- }
|
|
|
-
|
|
|
- if (Objects.nonNull(sysUserLike)) {
|
|
|
- communityUserLikeVo.setLikeUsername(sysUserLike.getNickName());
|
|
|
- communityUserLikeVo.setLikeAvatar(sysUserLike.getAvatar());
|
|
|
- }
|
|
|
-
|
|
|
- if (Objects.nonNull(likeUserInfo)) {
|
|
|
- communityUserLikeVo.setLikeProfile(likeUserInfo.getProfile());
|
|
|
- }
|
|
|
- //如果不需要搜索名字直接添加
|
|
|
- if (userName != null && communityUserLikeVo.getUsername().matches("(?i).*" + Pattern.quote(userName) + ".*")) {
|
|
|
- communityUserLikeVos.add(communityUserLikeVo);
|
|
|
- } else if (userName == null) {
|
|
|
- communityUserLikeVos.add(communityUserLikeVo);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- return communityUserLikeVos;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取互相关注列表
|
|
|
- *
|
|
|
- * @param userId 登录用户id
|
|
|
- * @return 获取互相关注列表
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<CommunityUserLikeVo> selectMutualAttention(Long userId, String userName, int pageNum, int pageSize, int searchType) {
|
|
|
-
|
|
|
- //先查询自己关注的人
|
|
|
- List<CommunityUserLikeVo> communityUserLikeVos = selectCommunityUserLikeList(userId, null, 1, 10000000, 0);
|
|
|
- //再查询被关注的人是否关注自己
|
|
|
- List<Long> likeUserIds = new ArrayList<>();
|
|
|
- for (CommunityUserLikeVo communityUserLikeVo : communityUserLikeVos) {
|
|
|
- likeUserIds.add(communityUserLikeVo.getLikeUserId());
|
|
|
- }
|
|
|
-
|
|
|
- if (!likeUserIds.isEmpty()) {
|
|
|
- QueryWrapper<CommunityUserLike> queryWrapper = new QueryWrapper<CommunityUserLike>()
|
|
|
- .in("user_id", likeUserIds).eq("like_user_id", userId);
|
|
|
- if (searchType == 1) {
|
|
|
- queryWrapper.orderByDesc("create_time");
|
|
|
- } else {
|
|
|
- queryWrapper.orderByAsc("create_time");
|
|
|
- }
|
|
|
- //分页查询数据
|
|
|
- //int offset = (pageNum - 1) * pageSize;
|
|
|
- Page<CommunityUserLike> page = new Page<>(pageNum, pageSize);
|
|
|
-
|
|
|
- List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectPage(page, queryWrapper).getRecords();
|
|
|
-
|
|
|
- System.out.println("communityUserLikes: " + communityUserLikes);
|
|
|
- CommunityUserLikeVo communityUserLikeVo = null;
|
|
|
- communityUserLikeVos = new ArrayList<>();
|
|
|
- for (CommunityUserLike communityUserLike : communityUserLikes) {
|
|
|
- //用户信息
|
|
|
- SysUser sysUserLike = sysUserMapper.selectUserById(communityUserLike.getLikeUserId());
|
|
|
- //用户自我介绍
|
|
|
- CommunityUserInfo userInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getUserId()));
|
|
|
- CommunityUserInfo likeUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getLikeUserId()));
|
|
|
-
|
|
|
- communityUserLikeVo = new CommunityUserLikeVo();
|
|
|
- BeanUtils.copyProperties(communityUserLike, communityUserLikeVo);
|
|
|
- SysUser sysUser = sysUserMapper.selectUserById(communityUserLike.getUserId());
|
|
|
- communityUserLikeVo.setProfile(userInfo.getProfile());
|
|
|
- communityUserLikeVo.setAvatar(sysUser.getAvatar());
|
|
|
- communityUserLikeVo.setUsername(sysUser.getNickName());
|
|
|
- communityUserLikeVo.setLikeUsername(sysUserLike.getNickName());
|
|
|
- communityUserLikeVo.setLikeAvatar(sysUserLike.getAvatar());
|
|
|
- communityUserLikeVo.setLikeProfile(likeUserInfo.getProfile());
|
|
|
- communityUserLikeVo.setIsCare(true);
|
|
|
-
|
|
|
-
|
|
|
- //如果不需要搜索名字直接添加
|
|
|
- if (userName != null && communityUserLikeVo.getUsername().matches("(?i).*" + Pattern.quote(userName) + ".*")) {
|
|
|
- communityUserLikeVos.add(communityUserLikeVo);
|
|
|
- } else if (userName == null) {
|
|
|
- communityUserLikeVos.add(communityUserLikeVo);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- return communityUserLikeVos;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断评论的人 是否在文章作者的关注列表中
|
|
|
- *
|
|
|
- * @param userId 必填
|
|
|
- * @param commentId 可选 评论的评论接口
|
|
|
- * @param articleId 可选 文章评论接口
|
|
|
- * @return true or false
|
|
|
- * @throws ParseException
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Boolean checkCommentPermission(Long userId, Long commentId, Long articleId) throws ParseException {
|
|
|
- /**
|
|
|
- * 1.传commentId 说明是 评论的评论接口
|
|
|
- * 2.传articleId 说明是文章评论接口
|
|
|
- * 3.询隐私设置表 communityPrivacyService.selectUserPrivacy 权限有没有开启
|
|
|
- * 4.没有开启 直接结束
|
|
|
- * 5.开启 查询作者关注列表
|
|
|
- * 6。是否是关注的人评论我 有则评论成功,没有则返回失败
|
|
|
- */
|
|
|
- //假设传的评论ID 根据 评论ID要找到文章ID
|
|
|
- if (articleId == null) {
|
|
|
- List<CommunityArticleComment> communityArticleComments
|
|
|
- = communityArticleCommentMapper
|
|
|
- .selectList(new QueryWrapper<CommunityArticleComment>().eq("id", commentId));
|
|
|
- CommunityArticleComment communityArticleComment = communityArticleComments.get(0);
|
|
|
- articleId = communityArticleComment.getArticleId();
|
|
|
- }
|
|
|
- ;
|
|
|
-
|
|
|
- //获取文章信息 找到文章创建人
|
|
|
- List<CommunityArticle> communityArticles
|
|
|
- = communityArticleMapper
|
|
|
- .selectList(new QueryWrapper<CommunityArticle>().eq("id", articleId));
|
|
|
-
|
|
|
- // 提取用户ID
|
|
|
- Long articleUserId = null; // 初始化用户ID
|
|
|
-
|
|
|
- if (!communityArticles.isEmpty()) { // 检查列表是否为空
|
|
|
- CommunityArticle article = communityArticles.get(0); // 获取第一个文章
|
|
|
- articleUserId = article.getUserId(); // 假设CommunityArticle有getUserId()方法
|
|
|
- } else {
|
|
|
- // 处理未找到文章的情况
|
|
|
- // 例如,可以抛出异常或记录日志
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // 直接允许作者评论
|
|
|
- if (articleUserId.equals(userId)) {
|
|
|
- /* // 如果评论者是文章作者,直接进行评论
|
|
|
- communityArticleService.sendComment(communityArticleComment);*/
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- // 查询隐私设置
|
|
|
- List<CommunityUserPrivacyVo> communityUserPrivacyVos = communityPrivacyService.selectUserPrivacy(articleUserId);
|
|
|
- // 检查隐私设置 只允许我关注的人评论我
|
|
|
- boolean IsComment = false;
|
|
|
- for (CommunityUserPrivacyVo privacyVo : communityUserPrivacyVos) {
|
|
|
- if (privacyVo.getIsComment() != null && privacyVo.getIsComment()) {
|
|
|
- IsComment = true; // 只允许特定用户评论
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- // 如果评论受限,则查询用户关注列表
|
|
|
- if (IsComment) {
|
|
|
- List<CommunityUserLikeVo> communityUserLikeVos = communityArticleService.selectCommunityUserLikeList(articleUserId, null, 1, 100000, 0);
|
|
|
- // 3. 检查评论者是否在关注列表中
|
|
|
- boolean isFollower = communityUserLikeVos.stream()
|
|
|
- .anyMatch(like -> like.getLikeUserId().equals(userId));
|
|
|
- System.out.println(userId);
|
|
|
- // 如果不是关注者,返回失败
|
|
|
- if (!isFollower) {
|
|
|
- //return AjaxResult.error("您没有权限评论此文章,因为只允许关注的人评论您!");
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<TrendingTop> selectTrendingTopByContent(String content) {
|
|
|
- return communityArticleMapper.selectTrendingTopByContent(content);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 个人中心简介信息
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<CommunityUserPromptVo> selectCommunityUserPrompt(Long userId) {
|
|
|
- if (Objects.isNull(userId)) {
|
|
|
- userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
- }
|
|
|
- // 查询自己的通知列表
|
|
|
- List<CommunityUserPrompt> communityUserPrompts
|
|
|
- = communityUserPromptMapper
|
|
|
- .selectList(new QueryWrapper<CommunityUserPrompt>().eq("user_id", userId));
|
|
|
-
|
|
|
-
|
|
|
- // 创建一个用于存放VO的列表
|
|
|
- List<CommunityUserPromptVo> communityUserPromptVos = new ArrayList<>();
|
|
|
- // 遍历查询结果,复制属性到 VO 对象
|
|
|
- for (CommunityUserPrompt communityUserPrompt : communityUserPrompts) {
|
|
|
- CommunityUserPromptVo communityUserPromptVo = new CommunityUserPromptVo();
|
|
|
- BeanUtils.copyProperties(communityUserPrompt, communityUserPromptVo);
|
|
|
- communityUserPromptVos.add(communityUserPromptVo);
|
|
|
- }
|
|
|
- // 判断隐私权限是否为空
|
|
|
- if (communityUserPromptVos.isEmpty()) {
|
|
|
- // 如果没有隐私权限,插入一条关于 userId 的数据
|
|
|
- CommunityUserPrompt newPrompt = new CommunityUserPrompt();
|
|
|
- newPrompt.setUserId(userId);
|
|
|
- newPrompt.setLikeUser(false);
|
|
|
- newPrompt.setCommentCircle(false);
|
|
|
- newPrompt.setLikeCollect(false);
|
|
|
- // 设置其他必要的默认值,例如:
|
|
|
- // 使用 MyBatis-Plus 执行插入操作
|
|
|
- communityUserPromptMapper.insert(newPrompt);
|
|
|
- // 将新插入的记录转换为 VO 并返回
|
|
|
- CommunityUserPromptVo newPromptVo = new CommunityUserPromptVo();
|
|
|
- BeanUtils.copyProperties(newPrompt, newPromptVo);
|
|
|
- communityUserPromptVos.add(newPromptVo);
|
|
|
- }
|
|
|
- return communityUserPromptVos;
|
|
|
- }
|
|
|
-
|
|
|
- // 修改service实现
|
|
|
- @Override
|
|
|
- public List<CommunityArticleVo> selectUserNoCo(Long userId, int pageNum, int pageSize, int searchType) {
|
|
|
- //PageHelper.startPage(pageNum, pageSize);
|
|
|
- return communityArticleMapper.selectUserNoCoArticles(userId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<CommunityArticleVo> selectUserLike(Long userId, int pageNum, int pageSize, int searchType) {
|
|
|
- // 查询的喜欢列表
|
|
|
- List<CommunityLike> communityUserLike
|
|
|
- = communityLikeMapper
|
|
|
- .selectList(new QueryWrapper<CommunityLike>().eq("user_id", userId));
|
|
|
- List<Long> articleIds = communityUserLike.stream().map(item -> item.getArticleId()).collect(Collectors.toList());
|
|
|
- TableDataInfo rspData = null;
|
|
|
- CommunityArticle communityArticle = null;
|
|
|
- List<CommunityArticleVo> communityArticleVos = null;
|
|
|
- if (!articleIds.isEmpty()) {
|
|
|
- rspData = new TableDataInfo();
|
|
|
- communityArticle = new CommunityArticle();
|
|
|
- communityArticle.setArticleIds(articleIds);
|
|
|
- communityArticleVos = communityArticleService.selectCommunityArticleList(userId, rspData, communityArticle, pageNum, pageSize, searchType);
|
|
|
- }
|
|
|
- return communityArticleVos;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<CommunityArticleVo> selectUserCollect(Long userId, int pageNum, int pageSize, int searchType) {
|
|
|
- // 查询收藏的列表
|
|
|
- List<CommunityArticleCollect> communityArticleCollects
|
|
|
- = communityArticleCollectMapper
|
|
|
- .selectList(new QueryWrapper<CommunityArticleCollect>().eq("user_id", userId));
|
|
|
-
|
|
|
-
|
|
|
- List<Long> articleIds = communityArticleCollects.stream().map(item -> item.getArticleId()).collect(Collectors.toList());
|
|
|
- TableDataInfo rspData = null;
|
|
|
- CommunityArticle communityArticle = null;
|
|
|
- List<CommunityArticleVo> communityArticleVos = null;
|
|
|
- if (!articleIds.isEmpty()) {
|
|
|
- rspData = new TableDataInfo();
|
|
|
- communityArticle = new CommunityArticle();
|
|
|
- communityArticle.setArticleIds(articleIds);
|
|
|
- communityArticleVos = communityArticleService.selectCommunityArticleList(userId, rspData, communityArticle, pageNum, pageSize, searchType);
|
|
|
- }
|
|
|
- return communityArticleVos;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 开启抽奖
|
|
|
- *
|
|
|
- * @param articleId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public CommunityCommentRaffleVo selectCommentRaffle(Long articleId) {
|
|
|
- CommunityCommentRaffle communityCommentRaffle = communityCommentRaffleMapper.selectOne(
|
|
|
- new QueryWrapper<CommunityCommentRaffle>()
|
|
|
- .eq("article_id", articleId)
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- }));
|
|
|
-
|
|
|
- CommunityCommentRaffleVo communityCommentRaffleVo = new CommunityCommentRaffleVo();
|
|
|
- CommunityUserInfoVo communityUserInfoVo = null;
|
|
|
- //如果抽奖表为空则需要插入一条数据
|
|
|
- if (communityCommentRaffle == null) {
|
|
|
- List<CommunityArticleComment> communityArticleComments = communityArticleCommentMapper.selectList(new QueryWrapper<CommunityArticleComment>()
|
|
|
- .eq("article_id", articleId)
|
|
|
- .and((wrapper) -> {
|
|
|
- wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
- })
|
|
|
- );
|
|
|
- if (communityArticleComments.size() == 0) {
|
|
|
- return communityCommentRaffleVo;
|
|
|
- }
|
|
|
- // 使用 Random 类生成一个随机索引
|
|
|
- Random random = new Random();
|
|
|
- int randomIndex = random.nextInt(communityArticleComments.size());
|
|
|
- CommunityArticleComment communityArticleComment = communityArticleComments.get(randomIndex);
|
|
|
- CommunityCommentRaffle commentRaffle = new CommunityCommentRaffle();
|
|
|
- commentRaffle.setArticleId(communityArticleComment.getArticleId());
|
|
|
- commentRaffle.setCommentId(communityArticleComment.getId());
|
|
|
- commentRaffle.setUserId(communityArticleComment.getUserId());
|
|
|
- commentRaffle.setCreateBy(SecurityUtils.getUserId());
|
|
|
- commentRaffle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
- communityCommentRaffleMapper.insert(commentRaffle);
|
|
|
- BeanUtils.copyProperties(commentRaffle, communityCommentRaffleVo);
|
|
|
- communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(commentRaffle.getUserId(), true);
|
|
|
- communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
|
|
|
- communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
|
|
|
- return communityCommentRaffleVo;
|
|
|
- }
|
|
|
-
|
|
|
- BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
|
|
|
- communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId(), true);
|
|
|
- communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
|
|
|
- communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
|
|
|
- return communityCommentRaffleVo;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断是否是视频文件
|
|
|
- *
|
|
|
- * @param fileUrl 文件地址
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
- public static boolean isVideoFile(String fileUrl) {
|
|
|
- try {
|
|
|
- // 打开 HTTP 连接
|
|
|
- URL url = new URL(fileUrl);
|
|
|
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
- connection.setRequestMethod("GET");
|
|
|
-
|
|
|
- // 获取文件类型
|
|
|
- String mimeType = connection.getContentType();
|
|
|
-
|
|
|
- // 判断是否为视频类型
|
|
|
- return mimeType != null && mimeType.startsWith("video");
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|