瀏覽代碼

user-service 添加一个 AdminUser 类和 UserGender 枚举

reghao 1 月之前
父節點
當前提交
c42f6bcf0f

+ 1 - 1
file/file-service/src/main/java/cn/reghao/tnb/file/app/zchat/model/dto/group/GroupMemberRet.java

@@ -14,7 +14,7 @@ public class GroupMemberRet {
     private long userId;
     private String nickname;
     private String avatar;
-    private int gender;
+    private String gender;
     private String motto;
 
     private boolean owner;

+ 40 - 0
user/user-api/src/main/java/cn/reghao/tnb/user/api/constant/UserGender.java

@@ -0,0 +1,40 @@
+package cn.reghao.tnb.user.api.constant;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author reghao
+ * @date 2026-05-20 17:48:59
+ */
+public enum UserGender {
+    Female(0, "女"),
+    Male(1, "男"),
+    Unknown(2, "未知");
+
+    private final int code;
+    private final String desc;
+
+    private static Map<Integer, String> descMap = new HashMap<>();
+    static {
+        for (UserGender type : UserGender.values()) {
+            descMap.put(type.code, type.desc);
+        }
+    }
+    UserGender(int code, String desc) {
+        this.code = code;
+        this.desc = desc;
+    }
+
+    public String getName() {
+        return this.name();
+    }
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public static String getDescByCode(int code) {
+        return descMap.get(code);
+    }
+}

+ 1 - 1
user/user-api/src/main/java/cn/reghao/tnb/user/api/dto/ContactDetail.java

@@ -19,7 +19,7 @@ public class ContactDetail implements Serializable {
     private String userId;
     private String screenName;
     private String avatarUrl;
-    private int gender;
+    private String gender;
     private String signature;
     private String remarkName;
     private String mobile;

+ 1 - 1
user/user-api/src/main/java/cn/reghao/tnb/user/api/dto/UserCard.java

@@ -19,7 +19,7 @@ public class UserCard implements Serializable {
     private String userId;
     private String screenName;
     private String avatarUrl;
-    private int gender;
+    private String gender;
     private int following;
     private int follower;
     private boolean followed;

+ 10 - 8
user/user-api/src/main/java/cn/reghao/tnb/user/api/dto/UserInfo.java

@@ -1,11 +1,13 @@
 package cn.reghao.tnb.user.api.dto;
 
 import cn.reghao.tnb.auth.api.dto.AccountInfo;
+import cn.reghao.tnb.user.api.constant.UserGender;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 import lombok.Setter;
 
 import java.io.Serializable;
+import java.util.List;
 
 /**
  * @author reghao
@@ -20,18 +22,18 @@ public class UserInfo implements Serializable {
     private String userId;
     private String screenName;
     private String avatarUrl;
-    private Integer gender;
+    private String gender;
     private String signature;
-    private Integer following;
-    private Integer follower;
-    private Boolean vip;
-    private Long biliUserId;
+    private int following;
+    private int follower;
+    private boolean vip;
+    private long biliUserId;
 
-    public UserInfo(AccountInfo accountInfo, String userIdStr, int gender, String signature, int following, int follower, boolean vip) {
-        this.userId = userIdStr;
+    public UserInfo(AccountInfo accountInfo, int gender, String signature, int following, int follower, boolean vip) {
+        this.userId = accountInfo.getUserIdStr();
         this.screenName = accountInfo.getScreenName();
         this.avatarUrl = accountInfo.getAvatarUrl();
-        this.gender = gender;
+        this.gender = UserGender.getDescByCode(gender);
         this.signature = signature;
         this.following = following;
         this.follower = follower;

+ 0 - 25
user/user-api/src/main/java/cn/reghao/tnb/user/api/dto/UserSearch.java

@@ -1,25 +0,0 @@
-package cn.reghao.tnb.user.api.dto;
-
-import lombok.Getter;
-import lombok.Setter;
-
-import jakarta.validation.constraints.NotBlank;
-import jakarta.validation.constraints.NotNull;
-import java.io.Serializable;
-
-/**
- * @author reghao
- * @date 2023-12-07 15:52:09
- */
-@Setter
-@Getter
-public class UserSearch implements Serializable {
-    private static final long serialVersionUID = 1L;
-
-    @NotNull
-    private Integer type;
-    @NotBlank
-    private String keyword;
-    @NotNull
-    private Integer page;
-}

+ 4 - 2
user/user-service/src/main/java/cn/reghao/tnb/user/app/controller/AdminUserController.java

@@ -5,6 +5,8 @@ import cn.reghao.tnb.common.web.WebResult;
 import cn.reghao.tnb.user.api.dto.UserInfo;
 import cn.reghao.tnb.user.api.dto.VipPlanInfo;
 import cn.reghao.tnb.user.api.dto.WalletChargeDto;
+import cn.reghao.tnb.user.app.model.dto.UserQuery;
+import cn.reghao.tnb.user.app.model.vo.AdminUser;
 import cn.reghao.tnb.user.app.service.AdminUserService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -29,8 +31,8 @@ public class AdminUserController {
 
     @Operation(summary = "用户帐号列表页面", description = "N")
     @GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String indexPage(@RequestParam(value = "nextId", required = false) Integer nextId) {
-        PageList<UserInfo> pageList = adminUserService.getUserList(1);
+    public String getUserList(UserQuery userQuery) {
+        PageList<AdminUser> pageList = adminUserService.getUserList(userQuery,1);
         return WebResult.success(pageList);
     }
 

+ 1 - 1
user/user-service/src/main/java/cn/reghao/tnb/user/app/model/dto/ContactInfo.java

@@ -16,7 +16,7 @@ import lombok.NoArgsConstructor;
 public class ContactInfo {
     private String id;
     private String nickname;
-    private int gender;
+    private String gender;
     private String motto;
     private String avatar;
     private String friendRemark;

+ 1 - 1
user/user-service/src/main/java/cn/reghao/tnb/user/app/model/dto/ContactInfoResult.java

@@ -15,7 +15,7 @@ public class ContactInfoResult {
     private String id;
     private String mobile;
     private String nickname;
-    private int gender;
+    private String gender;
     private String motto;
     private String avatar;
     private int friendStatus;

+ 1 - 1
user/user-service/src/main/java/cn/reghao/tnb/user/app/model/dto/SearchContactResult.java

@@ -12,7 +12,7 @@ public class SearchContactResult {
     private String id;
     private String mobile;
     private String nickname;
-    private int gender;
+    private String gender;
     private String motto;
     private String avatar;
 

+ 13 - 0
user/user-service/src/main/java/cn/reghao/tnb/user/app/model/dto/UserQuery.java

@@ -0,0 +1,13 @@
+package cn.reghao.tnb.user.app.model.dto;
+
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2026-05-20 16:20:19
+ */
+@Data
+public class UserQuery {
+    private int pn;
+    private String screenName;
+}

+ 2 - 1
user/user-service/src/main/java/cn/reghao/tnb/user/app/model/po/UserProfile.java

@@ -1,6 +1,7 @@
 package cn.reghao.tnb.user.app.model.po;
 
 import cn.reghao.jutil.jdk.web.db.BaseObject;
+import cn.reghao.tnb.user.api.constant.UserGender;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 
@@ -28,7 +29,7 @@ public class UserProfile extends BaseObject<Integer> {
 
     public UserProfile(long userId) {
         this.userId = userId;
-        this.gender = 2;
+        this.gender = UserGender.Unknown.getCode();
         this.signature = "";
         this.following = 0;
         this.follower = 0;

+ 40 - 0
user/user-service/src/main/java/cn/reghao/tnb/user/app/model/vo/AdminUser.java

@@ -0,0 +1,40 @@
+package cn.reghao.tnb.user.app.model.vo;
+
+import cn.reghao.tnb.auth.api.dto.AccountInfo;
+import cn.reghao.tnb.user.api.constant.UserGender;
+import cn.reghao.tnb.user.app.model.po.UserProfile;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2026-05-20 16:36:59
+ */
+@Data
+public class AdminUser {
+    private long userId;
+    private String userIdStr;
+    private String screenName;
+    private String avatarUrl;
+    private String gender;
+    private String signature;
+    private int following;
+    private int follower;
+    private boolean vip;
+    private long biliUserId;
+    private List<String> roles;
+
+    public AdminUser(AccountInfo accountInfo, UserProfile userProfile, boolean vip) {
+        this.userId = accountInfo.getUserId();
+        this.userIdStr = accountInfo.getUserIdStr();
+        this.screenName = accountInfo.getScreenName();
+        this.avatarUrl = accountInfo.getAvatarUrl();
+        this.gender = UserGender.getDescByCode(userProfile.getGender());
+        this.signature = userProfile.getSignature();
+        this.following = userProfile.getFollowing();
+        this.follower = userProfile.getFollower();
+        this.vip = vip;
+        this.roles = accountInfo.getRoles();
+    }
+}

+ 8 - 18
user/user-service/src/main/java/cn/reghao/tnb/user/app/service/AdminUserService.java

@@ -5,13 +5,13 @@ import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
 import cn.reghao.tnb.auth.api.dto.AccountInfo;
 import cn.reghao.tnb.auth.api.iface.AccountQuery;
 import cn.reghao.tnb.auth.api.iface.AdminAccountService;
-import cn.reghao.tnb.user.api.dto.UserInfo;
-import cn.reghao.tnb.user.api.dto.UserSearch;
+import cn.reghao.tnb.user.app.model.dto.UserQuery;
 import cn.reghao.tnb.user.api.dto.VipPlanInfo;
 import cn.reghao.tnb.user.api.dto.WalletChargeDto;
 import cn.reghao.tnb.user.api.iface.UserWalletService;
 import cn.reghao.tnb.user.app.db.mapper.UserProfileMapper;
 import cn.reghao.tnb.user.app.model.po.UserProfile;
+import cn.reghao.tnb.user.app.model.vo.AdminUser;
 import cn.reghao.tnb.user.app.model.vo.VipPlan;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.data.domain.Page;
@@ -54,14 +54,10 @@ public class AdminUserService {
         return new PageImpl<>(pageList.getList(), pageRequest, pageList.getTotalSize());
     }
 
-    public PageList<UserInfo> getUserList(UserSearch userSearch) {
-        return PageList.empty();
-    }
-
-    public PageList<UserInfo> getUserList(int nextId) {
+    public PageList<AdminUser> getUserList(UserQuery userQuery, int nextId) {
         int total = userProfileMapper.countAll();
         List<UserProfile> userProfileList = userProfileMapper.findAllById(pageSize, nextId);
-        List<UserInfo> list = userProfileList.stream().map(this::getUserInfo).collect(Collectors.toList());
+        List<AdminUser> list = userProfileList.stream().map(this::getAdminUser).collect(Collectors.toList());
         if (!userProfileList.isEmpty()) {
             nextId = userProfileList.get(userProfileList.size()-1).getId();
         }
@@ -69,23 +65,17 @@ public class AdminUserService {
         return PageList.pageList(""+nextId, list);
     }
 
-    private UserInfo getUserInfo(UserProfile userProfile) {
+    private AdminUser getAdminUser(UserProfile userProfile) {
         long userId = userProfile.getUserId();
         AccountInfo accountInfo = accountQuery.getAccountInfo(userId);
-        int gender = userProfile.getGender();
-        String signature = userProfile.getSignature();
-        int following = userProfile.getFollowing();
-        int follower = userProfile.getFollower();
         boolean vip = userVipService.isVip(userId);
-        String userIdStr = accountQuery.getUserIdStr(userId);
-        UserInfo userInfo = new UserInfo(accountInfo, userIdStr, gender, signature, following, follower, vip);
+        AdminUser adminUser = new AdminUser(accountInfo, userProfile, vip);
         String username = accountInfo.getUsername();
         if (username.startsWith("bilibili_")) {
             long biliUserId = Long.parseLong(username.replace("bilibili_", ""));
-            userInfo.setBiliUserId(biliUserId);
+            adminUser.setBiliUserId(biliUserId);
         }
-
-        return userInfo;
+        return adminUser;
     }
 
     public List<VipPlanInfo> getVipPlans() {

+ 1 - 2
user/user-service/src/main/java/cn/reghao/tnb/user/app/service/UserProfileService.java

@@ -55,8 +55,7 @@ public class UserProfileService {
         int following = userProfile.getFollowing();
         int follower = userProfile.getFollower();
         boolean vip = userVipService.isVip(userId);
-        String userIdStr = accountQuery.getUserIdStr(userId);
-        UserInfo userInfo = new UserInfo(accountInfo, userIdStr, gender, signature, following, follower, vip);
+        UserInfo userInfo = new UserInfo(accountInfo, gender, signature, following, follower, vip);
         String username = accountInfo.getUsername();
         if (username.startsWith("bilibili_")) {
             long biliUserId = Long.parseLong(username.replace("bilibili_", ""));