fangzhen 5 mesiacov pred
rodič
commit
7aad61ddef

+ 46 - 35
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -10,7 +10,6 @@ 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.common.utils.ip.IpUtils;
 import com.ruoyi.generator.domain.Community.*;
 import com.ruoyi.generator.mapper.community.*;
 import com.ruoyi.generator.vo.*;
@@ -115,7 +114,8 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     private CommunityArticleCollectMapper communityArticleCollectMapper;
 
     @Autowired
-    private  CommunityCommentRaffleMapper communityCommentRaffleMapper;
+    private CommunityCommentRaffleMapper communityCommentRaffleMapper;
+
     /**
      * 查询文章列表
      *
@@ -166,8 +166,8 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
             //获取文章是否被关注
             List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>()
-                    .eq("user_id",userId)
-                    .eq("like_user_id",articleVo.getUserId())
+                    .eq("user_id", userId)
+                    .eq("like_user_id", articleVo.getUserId())
             );
 
             for (CommunityUserLike communityUserLike : communityUserLikes) {
@@ -635,7 +635,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
      * @return 当前用户关注列表
      */
     @Override
-    public List<CommunityUserLikeVo> selectCommunityUserLikeList(Long userId,String userName,int pageNum, int pageSize,int searchType) {
+    public List<CommunityUserLikeVo> selectCommunityUserLikeList(Long userId, String userName, int pageNum, int pageSize, int searchType) {
         int offset = (pageNum - 1) * pageSize;
         Page<CommunityUserLike> page = new Page<>(offset, pageSize);
         QueryWrapper<CommunityUserLike> queryWrapper = new QueryWrapper<CommunityUserLike>()
@@ -664,10 +664,10 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             //关注的用户是否已经关注当前用户
             CommunityUserLike communityUserLikeFans = communityUserLikeMapper.selectOne(
                     new QueryWrapper<CommunityUserLike>()
-                            .eq("like_user_id", userId )
-                            .eq("user_id", communityUserLike.getLikeUserId() ));
+                            .eq("like_user_id", userId)
+                            .eq("user_id", communityUserLike.getLikeUserId()));
 
-            if (communityUserLikeFans != null){
+            if (communityUserLikeFans != null) {
                 isCare = true;
             }
             communityUserLikeVo.setIsCare(isCare);
@@ -691,9 +691,9 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             }
 
             //如果不需要搜索名字直接添加
-            if ( userName != null && communityUserLikeVo.getLikeUsername().matches("(?i).*" + Pattern.quote(userName) + ".*") ) {
+            if (userName != null && communityUserLikeVo.getLikeUsername().matches("(?i).*" + Pattern.quote(userName) + ".*")) {
                 communityUserLikeVos.add(communityUserLikeVo);
-            }else if(  userName == null ){
+            } else if (userName == null) {
                 communityUserLikeVos.add(communityUserLikeVo);
             }
 
@@ -709,7 +709,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
      * @return 当前用户粉丝列表
      */
     @Override
-    public List<CommunityUserLikeVo> selectUserFansList(Long userId,String userName,int pageNum, int pageSize,int searchType) {
+    public List<CommunityUserLikeVo> selectUserFansList(Long userId, String userName, int pageNum, int pageSize, int searchType) {
         int offset = (pageNum - 1) * pageSize;
         Page<CommunityUserLike> page = new Page<>(offset, pageSize);
         QueryWrapper<CommunityUserLike> queryWrapper = new QueryWrapper<CommunityUserLike>()
@@ -735,10 +735,10 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             //粉丝是否已经关注当前用户
             CommunityUserLike communityUserLikeFans = communityUserLikeMapper.selectOne(
                     new QueryWrapper<CommunityUserLike>()
-                            .eq("like_user_id", communityUserLike.getUserId() )
-                            .eq("user_id", userId ));
+                            .eq("like_user_id", communityUserLike.getUserId())
+                            .eq("user_id", userId));
 
-            if (communityUserLikeFans != null){
+            if (communityUserLikeFans != null) {
                 isCare = true;
             }
             communityUserLikeVo = new CommunityUserLikeVo();
@@ -753,22 +753,22 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
                 communityUserLikeVo.setUsername(sysUser.getNickName());
             }
 
-            if (Objects.nonNull(userInfo)){
+            if (Objects.nonNull(userInfo)) {
                 communityUserLikeVo.setProfile(userInfo.getProfile());
             }
 
-            if (Objects.nonNull(sysUserLike)){
+            if (Objects.nonNull(sysUserLike)) {
                 communityUserLikeVo.setLikeUsername(sysUserLike.getNickName());
                 communityUserLikeVo.setLikeAvatar(sysUserLike.getAvatar());
             }
 
-            if (Objects.nonNull(likeUserInfo)){
+            if (Objects.nonNull(likeUserInfo)) {
                 communityUserLikeVo.setLikeProfile(likeUserInfo.getProfile());
             }
             //如果不需要搜索名字直接添加
-            if ( userName != null && communityUserLikeVo.getUsername().matches("(?i).*" + Pattern.quote(userName) + ".*") ) {
+            if (userName != null && communityUserLikeVo.getUsername().matches("(?i).*" + Pattern.quote(userName) + ".*")) {
                 communityUserLikeVos.add(communityUserLikeVo);
-            }else if(  userName == null ){
+            } else if (userName == null) {
                 communityUserLikeVos.add(communityUserLikeVo);
             }
 
@@ -783,10 +783,10 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
      * @return 获取互相关注列表
      */
     @Override
-    public List<CommunityUserLikeVo> selectMutualAttention(Long userId,String userName,int pageNum, int pageSize, int searchType) {
+    public List<CommunityUserLikeVo> selectMutualAttention(Long userId, String userName, int pageNum, int pageSize, int searchType) {
 
         //先查询自己关注的人
-        List<CommunityUserLikeVo> communityUserLikeVos = selectCommunityUserLikeList(userId,null,1,10000000,0);
+        List<CommunityUserLikeVo> communityUserLikeVos = selectCommunityUserLikeList(userId, null, 1, 10000000, 0);
         //再查询被关注的人是否关注自己
         List<Long> likeUserIds = new ArrayList<>();
         for (CommunityUserLikeVo communityUserLikeVo : communityUserLikeVos) {
@@ -830,9 +830,9 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
 
                 //如果不需要搜索名字直接添加
-                if ( userName != null && communityUserLikeVo.getUsername().matches("(?i).*" + Pattern.quote(userName) + ".*") ) {
+                if (userName != null && communityUserLikeVo.getUsername().matches("(?i).*" + Pattern.quote(userName) + ".*")) {
                     communityUserLikeVos.add(communityUserLikeVo);
-                }else if(  userName == null ){
+                } else if (userName == null) {
                     communityUserLikeVos.add(communityUserLikeVo);
                 }
 
@@ -907,7 +907,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         }
         // 如果评论受限,则查询用户关注列表
         if (IsComment) {
-            List<CommunityUserLikeVo> communityUserLikeVos = communityArticleService.selectCommunityUserLikeList(articleUserId,null,1,100000,0);
+            List<CommunityUserLikeVo> communityUserLikeVos = communityArticleService.selectCommunityUserLikeList(articleUserId, null, 1, 100000, 0);
             // 3. 检查评论者是否在关注列表中
             boolean isFollower = communityUserLikeVos.stream()
                     .anyMatch(like -> like.getLikeUserId().equals(userId));
@@ -927,9 +927,9 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     }
 
 
-
     /**
      * 个人中心简介信息
+     *
      * @param userId
      * @return
      */
@@ -979,10 +979,15 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
                 = communityLikeMapper
                 .selectList(new QueryWrapper<CommunityLike>().eq("user_id", userId));
         List<Long> articleIds = communityUserLike.stream().map(item -> item.getArticleId()).collect(Collectors.toList());
-        TableDataInfo rspData = new TableDataInfo();
-        CommunityArticle communityArticle = new CommunityArticle();
-        communityArticle.setArticleIds(articleIds);
-        List<CommunityArticleVo> communityArticleVos = communityArticleService.selectCommunityArticleList(rspData, communityArticle, pageNum, pageSize, searchType);
+        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(rspData, communityArticle, pageNum, pageSize, searchType);
+        }
         return communityArticleVos;
     }
 
@@ -996,15 +1001,21 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
 
         List<Long> articleIds = communityArticleCollects.stream().map(item -> item.getArticleId()).collect(Collectors.toList());
-        TableDataInfo rspData = new TableDataInfo();
-        CommunityArticle communityArticle = new CommunityArticle();
-        communityArticle.setArticleIds(articleIds);
-        List<CommunityArticleVo> communityArticleVos = communityArticleService.selectCommunityArticleList(rspData, communityArticle, pageNum, pageSize, searchType);
+        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(rspData, communityArticle, pageNum, pageSize, searchType);
+        }
         return communityArticleVos;
     }
 
     /**
      * 开启抽奖
+     *
      * @param articleId
      * @return
      */
@@ -1020,7 +1031,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         CommunityCommentRaffleVo communityCommentRaffleVo = new CommunityCommentRaffleVo();
         CommunityUserInfoVo communityUserInfoVo = null;
         //如果抽奖表为空则需要插入一条数据
-        if (communityCommentRaffle == null){
+        if (communityCommentRaffle == null) {
             List<CommunityArticleComment> communityArticleComments = communityArticleCommentMapper.selectList(new QueryWrapper<CommunityArticleComment>()
                     .eq("article_id", articleId)
                     .and((wrapper) -> {
@@ -1042,7 +1053,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(commentRaffle.getUserId());
             communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
             communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
-            return  communityCommentRaffleVo;
+            return communityCommentRaffleVo;
         }
 
         BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);