Kaynağa Gözat

代码优化

fangzhen 5 ay önce
ebeveyn
işleme
dca461483e

+ 1 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -28,8 +28,6 @@ import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * 社区文章管理
@@ -615,6 +613,7 @@ public class CommunityArticleController extends BaseController {
         try {
             communityUserInfoVos = communityArticleService.selectUsersByAccountOrName(SearchValue);
         } catch (Exception e) {
+            System.out.println(e.getMessage());
             throw new ProjectException();
         }
 

+ 1 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/community/CommunityUserInfoMapper.java

@@ -19,7 +19,7 @@ public interface CommunityUserInfoMapper extends BaseMapper<CommunityUserInfo> {
 
     /**
      * 根据账户或者用户名称,搜索用户
-     * @param SearchValue
+     * @param SearchValue 搜索值
      * @return 用户
      */
     List<CommunityUserInfoVo> selectUsersByAccountOrName(String SearchValue);

+ 14 - 5
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -532,14 +532,13 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         communityUserInfoVo.setCompanionCount(0);
 
 
-
         String truncatedString = null;
         try {
             String ip = IpUtils.get();
             String address = AddressUtils.getRealAddressByIP(ip);
             // 使用空格分割字符串
             String[] parts = address.split(" ", 2); // 这里的2表示只分割一次
-            truncatedString = parts[0].replace("市","").replace("省","");
+            truncatedString = parts[0].replace("市", "").replace("省", "");
         } catch (ExecutionException e) {
             throw new RuntimeException(e);
         } catch (InterruptedException e) {
@@ -574,12 +573,22 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     /**
      * 根据账户或者用户名称,搜索用户
      *
-     * @param SearchValue
+     * @param SearchValue 搜索值
      * @return 用户
      */
     @Override
     public List<CommunityUserInfoVo> selectUsersByAccountOrName(String SearchValue) {
-        return communityUserInfoMapper.selectUsersByAccountOrName(SearchValue);
+        List<CommunityUserInfoVo> communityUserInfoVos = communityUserInfoMapper.selectUsersByAccountOrName(SearchValue);
+        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;
     }
 
 
@@ -771,7 +780,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     }
 
     @Override
-    public  List<TrendingTop> selectTrendingTopByContent(String content) {
+    public List<TrendingTop> selectTrendingTopByContent(String content) {
         return communityArticleMapper.selectTrendingTopByContent(content);
     }
 

+ 2 - 0
ruoyi-generator/src/main/resources/mapper/community/CommunityUserInfoMapper.xml

@@ -24,6 +24,7 @@
     <select id="selectUsersByAccountOrName" resultType="com.ruoyi.generator.vo.CommunityUserInfoVo">
         select
         b.id as id,
+        a.user_id as userId,
         a.nick_name as nickName,
         a.avatar as avatar,
         (select count(1) as fansCount from community_user_like c where c.like_user_id = a.user_id) as fansCount,
@@ -39,6 +40,7 @@
         union all
         select
         b.id as id,
+        a.user_id as userId,
         a.nick_name as nickName,
         a.avatar as avatar,
         (select count(1) as fansCount from community_user_like c where c.like_user_id = a.user_id) as fansCount,