Przeglądaj źródła

user 添加 UserService#getUserContacts 方法和实现

reghao 1 tydzień temu
rodzic
commit
01459b966a

+ 1 - 1
common/src/main/java/cn/reghao/tnb/common/db/PageScroll.java

@@ -53,7 +53,7 @@ public class PageScroll<T> implements Serializable {
         this.prevId = prevId;
         this.hasPrev = hasPrev;
         this.nextId = nextId;
-        this.hasNext = false;
+        this.hasNext = hasNext;
     }
 
     private PageScroll(int pageSize, int totalSize, String prevId, String nextId, List<T> list) {

+ 30 - 0
user/user-api/src/main/java/cn/reghao/tnb/user/api/dto/ContactInfo.java

@@ -0,0 +1,30 @@
+package cn.reghao.tnb.user.api.dto;
+
+import cn.reghao.tnb.auth.api.dto.AccountInfo;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * @author reghao
+ * @date 2026-06-09 14:37:13
+ */
+@NoArgsConstructor
+@Data
+public class ContactInfo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private Long userId;
+    private String screenName;
+    private String avatarUrl;
+    private String username;
+    private Long chatId;
+
+    public ContactInfo(AccountInfo  accountInfo) {
+        this.userId = accountInfo.getUserId();
+        this.screenName = accountInfo.getScreenName();
+        this.avatarUrl = accountInfo.getAvatarUrl();
+        this.username = accountInfo.getUsername();
+    }
+}

+ 2 - 0
user/user-api/src/main/java/cn/reghao/tnb/user/api/iface/UserService.java

@@ -1,5 +1,6 @@
 package cn.reghao.tnb.user.api.iface;
 
+import cn.reghao.tnb.user.api.dto.ContactInfo;
 import cn.reghao.tnb.user.api.dto.UserCard;
 
 import java.util.List;
@@ -15,4 +16,5 @@ public interface UserService {
     int getRecommendMode(long userId);
     boolean setRecommendMode(long userId, int mode);
     boolean contactContain(long userId, long friendId);
+    List<ContactInfo> getUserContacts(long userId);
 }

+ 12 - 0
user/user-service/src/main/java/cn/reghao/tnb/user/app/rpc/UserServiceImpl.java

@@ -1,6 +1,8 @@
 package cn.reghao.tnb.user.app.rpc;
 
+import cn.reghao.tnb.auth.api.dto.AccountInfo;
 import cn.reghao.tnb.auth.api.iface.AccountQuery;
+import cn.reghao.tnb.user.api.dto.ContactInfo;
 import cn.reghao.tnb.user.api.dto.UserCard;
 import cn.reghao.tnb.user.api.iface.UserService;
 import cn.reghao.tnb.user.app.db.mapper.UserContactMapper;
@@ -86,4 +88,14 @@ public class UserServiceImpl implements UserService {
     public boolean contactContain(long userId, long friendId) {
         return userContactMapper.findByOwnerAndFriendId(userId, friendId) != null;
     }
+
+    @Override
+    public List<ContactInfo> getUserContacts(long userId) {
+        return userContactMapper.findByOwner(userId).stream()
+                .map(userContact -> {
+                    long friendId = userContact.getFriendId();
+                    AccountInfo accountInfo = accountQuery.getAccountInfo(friendId);
+                    return new ContactInfo(accountInfo);
+                }).toList();
+    }
 }