Procházet zdrojové kódy

对返回给前端的 userId 进行混淆

reghao před 1 rokem
rodič
revize
24ecba3890
31 změnil soubory, kde provedl 210 přidání a 75 odebrání
  1. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/aop/DataSourceAspect.java
  2. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/chat/model/dto/chat/ChatInitialRet.java
  3. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/chat/model/dto/chat/ChatRecordGetRet.java
  4. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/chat/model/dto/chat/ChatUserInfo.java
  5. 9 5
      content/content-service/src/main/java/cn/reghao/tnb/content/app/chat/service/ChatRecordService.java
  6. 17 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/config/BeansConfig.java
  7. 2 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/controller/ImagePostController.java
  8. 8 3
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/controller/ImageQueryController.java
  9. 31 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/vo/AlbumCard.java
  10. 3 3
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/vo/ImageAlbumCard.java
  11. 19 10
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/service/ImagePostService.java
  12. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/mobile/model/Owner.java
  13. 1 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/mobile/model/VideoBean.java
  14. 7 2
      content/content-service/src/main/java/cn/reghao/tnb/content/app/mobile/service/AndroidService.java
  15. 7 3
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/controller/ContentController.java
  16. 8 3
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/controller/VideoQueryController.java
  17. 4 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/mapper/VideoPostMapper.java
  18. 3 3
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/vo/VideoDetail.java
  19. 10 2
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/impl/VideoPostQueryImpl.java
  20. 1 1
      user/user-api/src/main/java/cn/reghao/tnb/user/api/dto/ContactDetail.java
  21. 3 3
      user/user-api/src/main/java/cn/reghao/tnb/user/api/dto/UserCard.java
  22. 3 3
      user/user-api/src/main/java/cn/reghao/tnb/user/api/dto/UserInfo.java
  23. 17 0
      user/user-service/src/main/java/cn/reghao/tnb/user/app/config/BeansConfig.java
  24. 7 3
      user/user-service/src/main/java/cn/reghao/tnb/user/app/controller/UserProfileController.java
  25. 19 11
      user/user-service/src/main/java/cn/reghao/tnb/user/app/controller/UserRelationController.java
  26. 1 1
      user/user-service/src/main/java/cn/reghao/tnb/user/app/model/dto/ChatUserInfo.java
  27. 1 1
      user/user-service/src/main/java/cn/reghao/tnb/user/app/model/dto/ContactInfo.java
  28. 1 1
      user/user-service/src/main/java/cn/reghao/tnb/user/app/model/dto/ContactInfoResult.java
  29. 1 1
      user/user-service/src/main/java/cn/reghao/tnb/user/app/model/dto/SearchContactResult.java
  30. 9 2
      user/user-service/src/main/java/cn/reghao/tnb/user/app/rpc/UserServiceImpl.java
  31. 13 7
      user/user-service/src/main/java/cn/reghao/tnb/user/app/service/UserProfileService.java

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/aop/DataSourceAspect.java

@@ -26,7 +26,7 @@ public class DataSourceAspect {
     @Before("aspect()")
     public void before(JoinPoint point) {
         String method = point.getSignature().getName();
-        if (method.startsWith("find")) {
+        if (method.startsWith("find") || method.startsWith("count")) {
             log.info("method {} hit slave DataSource", method);
             DynamicDataSource.name.set(DataSourceType.slave.getName());
         } else {

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/chat/model/dto/chat/ChatInitialRet.java

@@ -21,7 +21,7 @@ public class ChatInitialRet {
     private String msgText;
     private String updatedAt;
 
-    private long receiverId;
+    private String receiverId;
     private String name;
     private String avatar;
     private boolean isOnline;

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/chat/model/dto/chat/ChatRecordGetRet.java

@@ -34,7 +34,7 @@ public class ChatRecordGetRet implements Serializable {
     private CodeBlockResult codeBlock;
     private FileMsgResult file;
 
-    private long userId;
+    private String userId;
     private String nickname;
     private String avatar;
 

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/chat/model/dto/chat/ChatUserInfo.java

@@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
 @NoArgsConstructor
 @Getter
 public class ChatUserInfo {
-    private long receiverId;
+    private String receiverId;
     private String name;
     private String avatar;
     private boolean isOnline;

+ 9 - 5
content/content-service/src/main/java/cn/reghao/tnb/content/app/chat/service/ChatRecordService.java

@@ -1,6 +1,7 @@
 package cn.reghao.tnb.content.app.chat.service;
 
 import cn.reghao.file.api.iface.OssService;
+import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.content.app.chat.db.mapper.*;
 import cn.reghao.tnb.content.app.chat.model.constant.MsgType;
@@ -35,15 +36,17 @@ public class ChatRecordService {
     private final TextMessageMapper textMessageMapper;
     private final CodeBlockMessageMapper codeBlockMessageMapper;
     private final FileMessageMapper fileMessageMapper;
+    private IDObfuscation userIdObfuscation;
 
-    public ChatRecordService(ChatDialogMapper chatDialogMapper,
-                             ChatRecordMapper chatRecordMapper, TextMessageMapper textMessageMapper,
-                             CodeBlockMessageMapper codeBlockMessageMapper, FileMessageMapper fileMessageMapper) {
+    public ChatRecordService(ChatDialogMapper chatDialogMapper, ChatRecordMapper chatRecordMapper,
+                             TextMessageMapper textMessageMapper, CodeBlockMessageMapper codeBlockMessageMapper,
+                             FileMessageMapper fileMessageMapper, IDObfuscation userIdObfuscation) {
         this.chatDialogMapper = chatDialogMapper;
         this.chatRecordMapper = chatRecordMapper;
         this.textMessageMapper = textMessageMapper;
         this.codeBlockMessageMapper = codeBlockMessageMapper;
         this.fileMessageMapper = fileMessageMapper;
+        this.userIdObfuscation = userIdObfuscation;
     }
 
 
@@ -52,7 +55,8 @@ public class ChatRecordService {
         List<ChatRecordGetRet> list = chatRecordMapper.findChatRecordGetRet(receiverId, loginUser, recordId, limit);
         list.forEach(chatRecordGetRet -> {
             try {
-                UserInfo userInfo = contactService.getUserInfo(chatRecordGetRet.getUserId());
+                long userId1 = userIdObfuscation.restore(chatRecordGetRet.getUserId());
+                UserInfo userInfo = contactService.getUserInfo(userId1);
                 if (userInfo != null) {
                     chatRecordGetRet.setNickname(userInfo.getScreenName());
                     chatRecordGetRet.setAvatar(userInfo.getAvatarUrl());
@@ -116,7 +120,7 @@ public class ChatRecordService {
         List<ChatRecordGetRet> list =
                 chatRecordMapper.findChatRecordGetRetByMsgType(msgType, receiverId, loginUser, recordId, limit);
         list.forEach(chatRecordGetRet -> {
-            long userId = chatRecordGetRet.getUserId();
+            long userId = userIdObfuscation.restore(chatRecordGetRet.getUserId());
             ContactDetail contactDetail = contactService.getContactDetail(userId);
             chatRecordGetRet.setNickname(contactDetail.getScreenName());
             chatRecordGetRet.setAvatar(contactDetail.getAvatarUrl());

+ 17 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/config/BeansConfig.java

@@ -0,0 +1,17 @@
+package cn.reghao.tnb.content.app.config;
+
+import cn.reghao.jutil.jdk.string.IDObfuscation;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author reghao
+ * @date 2025-03-29 21:58:56
+ */
+@Configuration
+public class BeansConfig {
+    @Bean
+    public IDObfuscation userIdObfuscation() {
+        return new IDObfuscation(0x12345);
+    }
+}

+ 2 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/controller/ImagePostController.java

@@ -8,6 +8,7 @@ import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.content.api.dto.ImagePublishSbt;
 import cn.reghao.tnb.content.app.data.model.dto.AlbumImageData;
 import cn.reghao.tnb.content.app.data.model.po.ImagePost;
+import cn.reghao.tnb.content.app.data.model.vo.AlbumCard;
 import cn.reghao.tnb.content.app.data.service.ImagePostService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -50,7 +51,7 @@ public class ImagePostController {
     @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getUserImageAlbum(@RequestParam("page") int page) {
         long userId = UserContext.getUser();
-        PageList<ImagePost> pageList = imagePostService.getUserAlbums(userId, page);
+        PageList<AlbumCard> pageList = imagePostService.getUserAlbums(userId, page);
         return WebResult.success(pageList);
     }
 

+ 8 - 3
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/controller/ImageQueryController.java

@@ -1,8 +1,10 @@
 package cn.reghao.tnb.content.app.data.controller;
 
 import cn.reghao.jutil.jdk.db.PageList;
+import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.tnb.content.app.data.model.po.ImagePost;
+import cn.reghao.tnb.content.app.data.model.vo.AlbumCard;
 import cn.reghao.tnb.content.app.data.service.ImagePostService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -20,15 +22,18 @@ import org.springframework.web.bind.annotation.*;
 @RequestMapping("/api/content/image")
 public class ImageQueryController {
     private final ImagePostService imagePostService;
+    private final IDObfuscation userIdObfuscation;
 
-    public ImageQueryController(ImagePostService imagePostService) {
+    public ImageQueryController(ImagePostService imagePostService, IDObfuscation userIdObfuscation) {
         this.imagePostService = imagePostService;
+        this.userIdObfuscation = userIdObfuscation;
     }
 
     @ApiOperation(value = "获取用户的图片稿件列表", notes = "N")
     @GetMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getUserImageAlbum(@RequestParam("userId") long userId, @RequestParam("page") int page) {
-        PageList<ImagePost> pageList = imagePostService.getUserAlbums(userId, page);
+    public String getUserImageAlbum(@RequestParam("userId") String userId, @RequestParam("page") int page) {
+        long userId1 = userIdObfuscation.restore(userId);
+        PageList<AlbumCard> pageList = imagePostService.getUserAlbums(userId1, page);
         return WebResult.success(pageList);
     }
 

+ 31 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/vo/AlbumCard.java

@@ -0,0 +1,31 @@
+package cn.reghao.tnb.content.app.data.model.vo;
+
+import cn.reghao.tnb.content.app.data.model.po.ImagePost;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author reghao
+ * @date 2025-03-29 22:52:55
+ */
+public class AlbumCard {
+    private Long albumId;
+    private String albumName;
+    private Integer channelId;
+    private String coverUrl;
+    private Integer total;
+    private LocalDateTime createdAt;
+    private Integer scope;
+    private String userId;
+
+    public AlbumCard(ImagePost imagePost, String userIdStr) {
+        this.albumId = imagePost.getAlbumId();
+        this.albumName = imagePost.getAlbumName();
+        this.channelId = imagePost.getChannelId();
+        this.coverUrl = imagePost.getCoverUrl();
+        this.total = imagePost.getTotal();
+        this.createdAt = imagePost.getCreatedAt();
+        this.scope = imagePost.getScope();
+        this.userId = userIdStr;
+    }
+}

+ 3 - 3
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/vo/ImageAlbumCard.java

@@ -15,12 +15,12 @@ import lombok.*;
 public class ImageAlbumCard {
     private Long albumId;
     private String albumName;
-    private Long userId;
+    private String userId;
     private PageList<ImageData> images;
 
-    public ImageAlbumCard(ImagePost imagePost) {
+    public ImageAlbumCard(ImagePost imagePost, String userIdStr) {
         this.albumId = imagePost.getAlbumId();
         this.albumName = imagePost.getAlbumName();
-        this.userId = imagePost.getUserId();
+        this.userId = userIdStr;
     }
 }

+ 19 - 10
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/service/ImagePostService.java

@@ -4,6 +4,7 @@ import cn.reghao.file.api.iface.OssService;
 import cn.reghao.jutil.jdk.db.Page;
 import cn.reghao.jutil.jdk.db.PageList;
 import cn.reghao.jutil.jdk.result.Result;
+import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.jutil.tool.id.SnowFlake;
 import cn.reghao.oss.sdk.model.dto.media.ImageInfo;
@@ -14,6 +15,7 @@ import cn.reghao.tnb.content.app.data.db.repository.ImageRepository;
 import cn.reghao.tnb.content.app.data.model.dto.AlbumImageData;
 import cn.reghao.tnb.content.app.data.model.po.ImagePost;
 import cn.reghao.tnb.content.app.data.model.po.ImageFile;
+import cn.reghao.tnb.content.app.data.model.vo.AlbumCard;
 import cn.reghao.tnb.content.app.data.model.vo.ImageAlbumCard;
 import cn.reghao.tnb.content.app.data.model.vo.ImageAlbumQuery;
 import cn.reghao.tnb.content.app.data.model.vo.ImageData;
@@ -26,6 +28,7 @@ import org.springframework.stereotype.Service;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 /**
@@ -43,13 +46,15 @@ public class ImagePostService {
     private final ImageRepository imageRepository;
     private final AlbumRepository albumRepository;
     private final ContentPermission contentPermission;
+    private final IDObfuscation userIdObfuscation;
 
     public ImagePostService(ImageRepository imageRepository, AlbumRepository albumRepository,
-                            ContentPermission contentPermission) {
+                            ContentPermission contentPermission, IDObfuscation userIdObfuscation) {
         this.idGenerator = new SnowFlake(1L, 1L);
         this.imageRepository = imageRepository;
         this.albumRepository = albumRepository;
         this.contentPermission = contentPermission;
+        this.userIdObfuscation = userIdObfuscation;
     }
 
     public Result create(ImagePublishSbt imagePublishSbt) {
@@ -114,7 +119,7 @@ public class ImagePostService {
         return albumRepository.getByImagePost(imageFileId, loginUser) != null;
     }
 
-    public PageList<ImagePost> getUserAlbums(long userId, int page) {
+    public PageList<AlbumCard> getUserAlbums(long userId, int page) {
         List<Integer> scopes = contentPermission.getUserScopes();
         long loginUser = UserContext.getUser();
         if (loginUser == userId) {
@@ -125,24 +130,27 @@ public class ImagePostService {
         int total = imageRepository.countByCriteria(imageAlbumQuery);
         Page page1 = new Page(page, pageSize);
         List<ImagePost> list = imageRepository.findImageAlbumByPage(page1, imageAlbumQuery);
-        list.forEach(imageAlbum -> {
+        List<AlbumCard> albumCards = list.stream().map(imagePost -> {
             try {
-                int scope = imageAlbum.getScope();
+                int scope = imagePost.getScope();
                 if (scope != PostScope.PUBLIC.getCode()) {
-                    int channelId = imageAlbum.getChannelId();
-                    String coverUrl = imageAlbum.getCoverUrl();
+                    int channelId = imagePost.getChannelId();
+                    String coverUrl = imagePost.getCoverUrl();
                     if (!coverUrl.isBlank()) {
                         ImageFile imageFile = imageRepository.getByUrl(coverUrl);
                         String objectId = imageFile.getObjectId();
-                        imageAlbum.setCoverUrl(ossService.getSignedUrl(channelId, objectId));
+                        imagePost.setCoverUrl(ossService.getSignedUrl(channelId, objectId));
                     }
                 }
+                String userIdStr = userIdObfuscation.obfuscate(imagePost.getUserId());
+                return new AlbumCard(imagePost, userIdStr);
             } catch (Exception e) {
                 e.printStackTrace();
             }
-        });
+            return null;
+        }).filter(Objects::nonNull).collect(Collectors.toList());
 
-        return PageList.pageList(page, pageSize, total, list);
+        return PageList.pageList(page, pageSize, total, albumCards);
     }
 
     public String getImageAlbum(long albumId, int pageNumber) {
@@ -192,7 +200,8 @@ public class ImagePostService {
         });
 
         PageList<ImageData> pageList = PageList.pageList(pageNumber, pageSize, total, list);
-        ImageAlbumCard imageAlbumCard = new ImageAlbumCard(imagePost);
+        String userIdStr = userIdObfuscation.obfuscate(imagePost.getUserId());
+        ImageAlbumCard imageAlbumCard = new ImageAlbumCard(imagePost, userIdStr);
         imageAlbumCard.setImages(pageList);
         if (scope != PostScope.PUBLIC.getCode()) {
             imageAlbumCard.getImages().getList().forEach(imageData -> {

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/mobile/model/Owner.java

@@ -7,7 +7,7 @@ import cn.reghao.tnb.user.api.dto.UserCard;
  * @date 2023-09-03 22:47:12
  */
 public class Owner {
-    private Long userId;
+    private String userId;
     private String username;
     private String avatarUrl;
 

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/mobile/model/VideoBean.java

@@ -13,7 +13,7 @@ public class VideoBean {
     private String duration;
     private Integer viewCount;
     private Integer commentCount;
-    private Long userId;
+    private String userId;
     private String username;
     private String avatarUrl;
 

+ 7 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/mobile/service/AndroidService.java

@@ -1,6 +1,7 @@
 package cn.reghao.tnb.content.app.mobile.service;
 
 import cn.reghao.jutil.jdk.db.PageList;
+import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.tnb.content.api.dto.VideoUrls;
 import cn.reghao.tnb.content.app.vod.model.vo.VideoDetail;
 import cn.reghao.tnb.content.app.vod.model.query.VideoQuery;
@@ -42,11 +43,12 @@ public class AndroidService {
     private final CategoryService categoryService;
     private final ContentPermission contentPermission;
     private final VideoPostQuery videoPostQuery;
+    private IDObfuscation userIdObfuscation;
 
     public AndroidService(VideoPlayService videoPlayService, SearchService searchService,
                           VideoPostMapper videoPostMapper, VideoTagMapper videoTagMapper,
                           CategoryService categoryService, ContentPermission contentPermission,
-                          VideoPostQuery videoPostQuery) {
+                          VideoPostQuery videoPostQuery, IDObfuscation userIdObfuscation) {
         this.videoPlayService = videoPlayService;
         this.searchService = searchService;
         this.videoPostMapper = videoPostMapper;
@@ -54,6 +56,7 @@ public class AndroidService {
         this.categoryService = categoryService;
         this.contentPermission = contentPermission;
         this.videoPostQuery = videoPostQuery;
+        this.userIdObfuscation = userIdObfuscation;
     }
 
     public HotSearchTag getSearchTag() {
@@ -127,7 +130,9 @@ public class AndroidService {
 
         List<String> tags = videoTagMapper.findVideoTags(videoId);
         videoDetail.setTags(tags);
-        UserCard userCard = userService.getUserAvatar(videoDetail.getUserId());
+        String publishByStr = videoDetail.getUserId();
+        long publishBy = userIdObfuscation.restore(publishByStr);
+        UserCard userCard = userService.getUserAvatar(publishBy);
 
         VideoDetails videoDetails = new VideoDetails(videoDetail, userCard);
         return new VideoDetailsResult(videoDetails);

+ 7 - 3
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/controller/ContentController.java

@@ -1,5 +1,6 @@
 package cn.reghao.tnb.content.app.vod.controller;
 
+import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.tnb.content.api.iface.AdminSiteService;
 import cn.reghao.tnb.content.app.vod.model.vo.UserContentData;
@@ -21,10 +22,12 @@ import org.springframework.web.bind.annotation.*;
 public class ContentController {
     private final AdminSiteService siteService;
     private final ContentService contentService;
+    private final IDObfuscation userIdObfuscation;
 
-    public ContentController(AdminSiteService siteService, ContentService contentService) {
+    public ContentController(AdminSiteService siteService, ContentService contentService, IDObfuscation userIdObfuscation) {
         this.siteService = siteService;
         this.contentService = contentService;
+        this.userIdObfuscation = userIdObfuscation;
     }
 
     @ApiOperation(value = "获取站点公告", notes = "N")
@@ -36,8 +39,9 @@ public class ContentController {
 
     @ApiOperation(value = "获取用户内容数据", notes = "N")
     @GetMapping(value = "/userdata", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getUserContentData(@RequestParam("userId") long userId) {
-        UserContentData userContentData = contentService.getUserContentData(userId);
+    public String getUserContentData(@RequestParam("userId") String userId) {
+        long userId1 = userIdObfuscation.restore(userId);
+        UserContentData userContentData = contentService.getUserContentData(userId1);
         return WebResult.success(userContentData);
     }
 }

+ 8 - 3
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/controller/VideoQueryController.java

@@ -1,6 +1,7 @@
 package cn.reghao.tnb.content.app.vod.controller;
 
 import cn.reghao.jutil.jdk.db.PageList;
+import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.tnb.common.auth.AuthUser;
 import cn.reghao.tnb.common.auth.UserContext;
@@ -31,10 +32,13 @@ import java.util.List;
 public class VideoQueryController {
     private final VideoPostQuery videoPostQuery;
     private final RecommendService recommendService;
+    private final IDObfuscation userIdObfuscation;
 
-    public VideoQueryController(VideoPostQuery videoPostQuery, RecommendService recommendService) {
+    public VideoQueryController(VideoPostQuery videoPostQuery, RecommendService recommendService,
+                                IDObfuscation userIdObfuscation) {
         this.videoPostQuery = videoPostQuery;
         this.recommendService = recommendService;
+        this.userIdObfuscation = userIdObfuscation;
     }
 
     @TimeConsumed
@@ -55,8 +59,9 @@ public class VideoQueryController {
 
     @ApiOperation(value = "获取某个用户发布的视频", notes = "N")
     @GetMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getUserVideos(@RequestParam("userId") long userId, @RequestParam("page") int page) {
-        PageList<VideoCard> pageList = videoPostQuery.getUserVideos(userId, page);
+    public String getUserVideos(@RequestParam("userId") String userId, @RequestParam("page") int page) {
+        long userId1 = userIdObfuscation.restore(userId);
+        PageList<VideoCard> pageList = videoPostQuery.getUserVideos(userId1, page);
         return WebResult.success(pageList);
     }
 

+ 4 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/mapper/VideoPostMapper.java

@@ -63,4 +63,8 @@ public interface VideoPostMapper extends BaseMapper<VideoPost> {
     List<GroupCount> findGroupByCategoryId();
     List<String> findRandomVideoIds(List<Integer> scopes, int size);
     List<String> findShortVideo(List<Integer> scopes);
+
+    int countDurationLt(int duration);
+    int countDurationBetween(int duration1, int duration2);
+    int countDurationGt(int duration);
 }

+ 3 - 3
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/vo/VideoDetail.java

@@ -33,7 +33,7 @@ public class VideoDetail implements Serializable {
     private int scope;
     private int status;
     private List<String> tags = new ArrayList<>();
-    private long userId;
+    private String userId;
 
     private int view;
     private int comment;
@@ -42,7 +42,7 @@ public class VideoDetail implements Serializable {
     private int thumbUp;
     private int thumbDown;
 
-    public VideoDetail(VideoPost videoPost, VideoStatistic videoStatistic) {
+    public VideoDetail(VideoPost videoPost, VideoStatistic videoStatistic, String publishBy) {
         this.videoId = videoPost.getVideoId();
         this.videoFileId = videoPost.getVideoFileId();
         this.title = videoPost.getTitle();
@@ -52,7 +52,7 @@ public class VideoDetail implements Serializable {
         this.pubDate = videoPost.getPublishAt();
         this.scope = videoPost.getScope();
         this.status = videoPost.getStatus();
-        this.userId = videoPost.getPublishBy();
+        this.userId = publishBy;
         this.view = videoStatistic.getView();
         this.comment = videoStatistic.getComment();
         this.favorite = videoStatistic.getFavorite();

+ 10 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/impl/VideoPostQueryImpl.java

@@ -3,6 +3,7 @@ package cn.reghao.tnb.content.app.vod.service.impl;
 import cn.reghao.file.api.iface.OssService;
 import cn.reghao.jutil.jdk.db.Page;
 import cn.reghao.jutil.jdk.db.PageList;
+import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.oss.sdk.model.dto.media.VideoInfo;
 import cn.reghao.tnb.common.auth.UserContext;
@@ -60,6 +61,7 @@ public class VideoPostQueryImpl implements VideoPostQuery {
     private final CategoryService categoryService;
     private final VideoRepository videoRepository;
     private final Random random = new SecureRandom();
+    private IDObfuscation userIdObfuscation;
 
     public VideoPostQueryImpl(VideoPostMapper videoPostMapper, VideoTagMapper videoTagMapper,
                               VideoStatisticMapper videoStatisticMapper, VideoCategoryPostMapper videoCategoryPostMapper,
@@ -71,6 +73,7 @@ public class VideoPostQueryImpl implements VideoPostQuery {
         this.contentPermission = contentPermission;
         this.categoryService = categoryService;
         this.videoRepository = videoRepository;
+        this.userIdObfuscation = new IDObfuscation(0x12345);
     }
 
     public List<VideoCard> getVideoCards(List<String> videoIds) {
@@ -116,7 +119,10 @@ public class VideoPostQueryImpl implements VideoPostQuery {
 
         VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
         VideoStatistic videoStatistic = videoStatisticMapper.findByVideoId(videoId);
-        VideoDetail videoDetail = new VideoDetail(videoPost, videoStatistic);
+
+        long publishBy = videoPost.getPublishBy();
+        String publishByStr = userIdObfuscation.obfuscate(publishBy);
+        VideoDetail videoDetail = new VideoDetail(videoPost, videoStatistic, publishByStr);
         List<String> tags = videoTagMapper.findVideoTags(videoId);
         videoDetail.setTags(tags);
         return videoDetail;
@@ -231,8 +237,10 @@ public class VideoPostQueryImpl implements VideoPostQuery {
             return WebResult.failWithMsg("permission denied");
         }
 
+        long publishBy = videoPost.getPublishBy();
+        String publishByStr = userIdObfuscation.obfuscate(publishBy);
         VideoStatistic videoStatistic = videoStatisticMapper.findByVideoId(videoId);
-        VideoDetail videoDetail = new VideoDetail(videoPost, videoStatistic);
+        VideoDetail videoDetail = new VideoDetail(videoPost, videoStatistic, publishByStr);
         List<String> tags = videoTagMapper.findVideoTags(videoId);
         videoDetail.setTags(tags);
         return WebResult.success(videoDetail);

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

@@ -16,7 +16,7 @@ import java.io.Serializable;
 public class ContactDetail implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    private long userId;
+    private String userId;
     private String screenName;
     private String avatarUrl;
     private int gender;

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

@@ -16,7 +16,7 @@ import java.io.Serializable;
 public class UserCard implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    private Long userId;
+    private String userId;
     private String screenName;
     private String avatarUrl;
     private int gender;
@@ -24,8 +24,8 @@ public class UserCard implements Serializable {
     private int follower;
     private boolean followed;
 
-    public UserCard(UserInfo userInfo, boolean followed) {
-        this.userId = userInfo.getUserId();
+    public UserCard(UserInfo userInfo, String userIdStr, boolean followed) {
+        this.userId = userIdStr;
         this.screenName = userInfo.getScreenName();
         this.avatarUrl = userInfo.getAvatarUrl();
         this.gender = userInfo.getGender();

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

@@ -17,7 +17,7 @@ import java.io.Serializable;
 public class UserInfo implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    private Long userId;
+    private String userId;
     private String screenName;
     private String avatarUrl;
     private Integer gender;
@@ -27,8 +27,8 @@ public class UserInfo implements Serializable {
     private Boolean vip;
     private Long biliUserId;
 
-    public UserInfo(AccountInfo accountInfo, int gender, String signature, int following, int follower, boolean vip) {
-        this.userId = accountInfo.getUserId();
+    public UserInfo(AccountInfo accountInfo, String userIdStr, int gender, String signature, int following, int follower, boolean vip) {
+        this.userId = userIdStr;
         this.screenName = accountInfo.getScreenName();
         this.avatarUrl = accountInfo.getAvatarUrl();
         this.gender = gender;

+ 17 - 0
user/user-service/src/main/java/cn/reghao/tnb/user/app/config/BeansConfig.java

@@ -0,0 +1,17 @@
+package cn.reghao.tnb.user.app.config;
+
+import cn.reghao.jutil.jdk.string.IDObfuscation;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author reghao
+ * @date 2025-03-29 21:58:56
+ */
+@Configuration
+public class BeansConfig {
+    @Bean
+    public IDObfuscation userIdObfuscation() {
+        return new IDObfuscation(0x12345);
+    }
+}

+ 7 - 3
user/user-service/src/main/java/cn/reghao/tnb/user/app/controller/UserProfileController.java

@@ -1,5 +1,6 @@
 package cn.reghao.tnb.user.app.controller;
 
+import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.tnb.user.api.dto.UserInfo;
 import cn.reghao.tnb.user.app.model.dto.UserProfileUpdate;
@@ -21,9 +22,11 @@ import java.util.Collections;
 @RequestMapping("/api/user")
 public class UserProfileController {
     private final UserProfileService userProfileService;
+    private final IDObfuscation userIdObfuscation;
 
-    public UserProfileController(UserProfileService userProfileService) {
+    public UserProfileController(UserProfileService userProfileService, IDObfuscation userIdObfuscation) {
         this.userProfileService = userProfileService;
+        this.userIdObfuscation = userIdObfuscation;
     }
 
     @ApiOperation(value = "修改用户资料", notes = "N")
@@ -35,8 +38,9 @@ public class UserProfileController {
 
     @ApiOperation(value = "获取用户资料", notes = "N")
     @GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getUserInfo(@RequestParam("userId") long userId) {
-        UserInfo userInfo = userProfileService.getUserInfo(userId);
+    public String getUserInfo(@RequestParam("userId") String userId) {
+        long userId1 = userIdObfuscation.restore(userId);
+        UserInfo userInfo = userProfileService.getUserInfo(userId1);
         return WebResult.success(userInfo);
     }
 

+ 19 - 11
user/user-service/src/main/java/cn/reghao/tnb/user/app/controller/UserRelationController.java

@@ -1,5 +1,6 @@
 package cn.reghao.tnb.user.app.controller;
 
+import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.tnb.user.api.dto.UserCard;
 import cn.reghao.tnb.common.auth.AuthUser;
@@ -20,52 +21,59 @@ import java.util.List;
 @RequestMapping("/api/user/relation")
 public class UserRelationController {
     private final UserRelationService userRelationService;
+    private final IDObfuscation userIdObfuscation;
 
-    public UserRelationController(UserRelationService userRelationService) {
+    public UserRelationController(UserRelationService userRelationService, IDObfuscation userIdObfuscation) {
         this.userRelationService = userRelationService;
+        this.userIdObfuscation = userIdObfuscation;
     }
 
     @ApiOperation(value = "关注用户", notes = "N")
     @PostMapping("/follow/{followingId}")
-    public String followUser(@PathVariable("followingId") Long followingId) {
+    public String followUser(@PathVariable("followingId") String followingId) {
+        long followingId1 = userIdObfuscation.restore(followingId);
         long loginUser = UserContext.getUser();
-        userRelationService.followUser(loginUser, followingId);
+        userRelationService.followUser(loginUser, followingId1);
         return WebResult.success();
     }
 
     @AuthUser
     @ApiOperation(value = "取消关注用户", notes = "N")
     @PostMapping("/unfollow/{followingId}")
-    public String unfollowUser(@PathVariable("followingId") Long followingId) {
+    public String unfollowUser(@PathVariable("followingId") String followingId) {
+        long followingId1 = userIdObfuscation.restore(followingId);
         long loginUser = UserContext.getUser();
-        userRelationService.unfollowUser(loginUser, followingId);
+        userRelationService.unfollowUser(loginUser, followingId1);
         return WebResult.success();
     }
 
     @ApiOperation(value = "检查是否关注了用户", notes = "N")
     @GetMapping("/check/{userId}")
-    public String check(@PathVariable("userId") Long userId) {
+    public String check(@PathVariable("userId") String userId) {
+        long userId1 = userIdObfuscation.restore(userId);
         long loginUser = UserContext.getUser();
         boolean followed;
         if (loginUser == -1) {
             followed = false;
         } else {
-            followed = userRelationService.isFollowing(loginUser, userId);
+            followed = userRelationService.isFollowing(loginUser, userId1);
         }
         return WebResult.success(followed);
     }
 
     @ApiOperation(value = "获取用户的关注列表", notes = "N")
     @GetMapping("/following/{userId}")
-    public String getFollowing(@PathVariable("userId") Long userId) {
-        List<UserCard> list = userRelationService.getFollowingCards(userId);
+    public String getFollowing(@PathVariable("userId") String userId) {
+        long userId1 = userIdObfuscation.restore(userId);
+        List<UserCard> list = userRelationService.getFollowingCards(userId1);
         return WebResult.success(list);
     }
 
     @ApiOperation(value = "获取用户的粉丝列表", notes = "N")
     @GetMapping("/follower/{userId}")
-    public String getFollower(@PathVariable("userId") Long userId) {
-        List<UserCard> list = userRelationService.getFollowerCards(userId);
+    public String getFollower(@PathVariable("userId") String userId) {
+        long userId1 = userIdObfuscation.restore(userId);
+        List<UserCard> list = userRelationService.getFollowerCards(userId1);
         return WebResult.success(list);
     }
 }

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

@@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
 @NoArgsConstructor
 @Getter
 public class ChatUserInfo {
-    private long receiverId;
+    private String receiverId;
     private String name;
     private String avatar;
     private boolean isOnline;

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

@@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
 @AllArgsConstructor
 @Data
 public class ContactInfo {
-    private long id;
+    private String id;
     private String nickname;
     private int gender;
     private String motto;

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

@@ -12,7 +12,7 @@ import lombok.Setter;
 @Setter
 @Getter
 public class ContactInfoResult {
-    private long id;
+    private String id;
     private String mobile;
     private String nickname;
     private int gender;

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

@@ -9,7 +9,7 @@ import lombok.Data;
  */
 @Data
 public class SearchContactResult {
-    private long id;
+    private String id;
     private String mobile;
     private String nickname;
     private int gender;

+ 9 - 2
user/user-service/src/main/java/cn/reghao/tnb/user/app/rpc/UserServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.reghao.tnb.user.app.rpc;
 
+import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.tnb.account.api.iface.AccountQuery;
 import cn.reghao.tnb.user.api.dto.UserCard;
 import cn.reghao.tnb.user.api.dto.UserMessageDto;
@@ -29,13 +30,16 @@ public class UserServiceImpl implements UserService {
     private final UserVipService userVipService;
     private final UserProfileService userProfileService;
     private final UserMessageService userMessageService;
+    private IDObfuscation userIdObfuscation;
 
     public UserServiceImpl(UserRelationService userRelationService, UserVipService userVipService,
-                           UserProfileService userProfileService, UserMessageService userMessageService) {
+                           UserProfileService userProfileService, UserMessageService userMessageService,
+                           IDObfuscation userIdObfuscation) {
         this.userRelationService = userRelationService;
         this.userVipService = userVipService;
         this.userProfileService = userProfileService;
         this.userMessageService = userMessageService;
+        this.userIdObfuscation = userIdObfuscation;
     }
 
     @Override
@@ -46,7 +50,10 @@ public class UserServiceImpl implements UserService {
     @Override
     public List<Long> getFollowingIds(long userId) {
         return userRelationService.getFollowingCards(userId).stream()
-                .map(UserCard::getUserId)
+                .map(userCard -> {
+                    String userIdStr = userCard.getUserId();
+                    return userIdObfuscation.restore(userIdStr);
+                })
                 .collect(Collectors.toList());
     }
 

+ 13 - 7
user/user-service/src/main/java/cn/reghao/tnb/user/app/service/UserProfileService.java

@@ -2,6 +2,7 @@ package cn.reghao.tnb.user.app.service;
 
 import cn.reghao.jutil.jdk.db.Page;
 import cn.reghao.jutil.jdk.db.PageList;
+import cn.reghao.jutil.jdk.string.IDObfuscation;
 import cn.reghao.tnb.account.api.dto.AccountInfo;
 import cn.reghao.tnb.account.api.iface.AccountQuery;
 import cn.reghao.tnb.common.auth.UserContext;
@@ -34,12 +35,14 @@ public class UserProfileService {
     private final UserProfileMapper userProfileMapper;
     private final UserRelationMapper userRelationMapper;
     private final UserVipService userVipService;
+    private final IDObfuscation userIdObfuscation;
 
     public UserProfileService(UserProfileMapper userProfileMapper, UserRelationMapper userRelationMapper,
-                              UserVipService userVipService) {
+                              UserVipService userVipService, IDObfuscation userIdObfuscation) {
         this.userProfileMapper = userProfileMapper;
         this.userVipService = userVipService;
         this.userRelationMapper = userRelationMapper;
+        this.userIdObfuscation = userIdObfuscation;
     }
 
     public void updateUserProfile(UserProfileUpdate userProfileUpdate) {
@@ -64,7 +67,8 @@ public class UserProfileService {
         int following = userProfile.getFollowing();
         int follower = userProfile.getFollower();
         boolean vip = userVipService.isVip(userId);
-        UserInfo userInfo = new UserInfo(accountInfo, gender, signature, following, follower, vip);
+        String userIdStr = userIdObfuscation.obfuscate(userId);
+        UserInfo userInfo = new UserInfo(accountInfo, userIdStr, gender, signature, following, follower, vip);
         String username = accountInfo.getUsername();
         if (username.startsWith("bilibili_")) {
             long biliUserId = Long.parseLong(username.replace("bilibili_", ""));
@@ -98,7 +102,8 @@ public class UserProfileService {
                     int following = userProfile.getFollowing();
                     int follower = userProfile.getFollower();
                     boolean vip = userVipService.isVip(userId);
-                    return new UserInfo(accountInfo, gender, signature, following, follower, vip);
+                    String userIdStr = userIdObfuscation.obfuscate(userId);
+                    return new UserInfo(accountInfo, userIdStr, gender, signature, following, follower, vip);
                 })
                 .collect(Collectors.toList());
     }
@@ -106,9 +111,9 @@ public class UserProfileService {
     public UserCard getUserCard(long userId) {
         long loginUser = UserContext.getUser();
         UserInfo userInfo = getUserInfo(userId);
-        long userId1 = userInfo.getUserId();
-        boolean followed = isFollowing(loginUser, userId1);
-        return new UserCard(userInfo, followed);
+        boolean followed = isFollowing(loginUser, userId);
+        String userIdStr = userIdObfuscation.obfuscate(userId);
+        return new UserCard(userInfo, userIdStr, followed);
     }
 
     public List<UserCard> getUserCards(List<Long> list) {
@@ -120,7 +125,8 @@ public class UserProfileService {
         return list.stream().map(userId -> {
             UserInfo userInfo = getUserInfo(userId);
             boolean followed = isFollowing(loginUser, userId);
-            return new UserCard(userInfo, followed);
+            String userIdStr = userIdObfuscation.obfuscate(userId);
+            return new UserCard(userInfo, userIdStr, followed);
         }).collect(Collectors.toList());
     }