Ver código fonte

user-service 和 content-service 添加 admin 管理接口

reghao 7 meses atrás
pai
commit
3992d1d8f9

+ 11 - 6
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/controller/AdminVideoController.java

@@ -1,8 +1,11 @@
 package cn.reghao.tnb.content.app.vod.controller;
 
+import cn.reghao.jutil.jdk.db.PageList;
 import cn.reghao.jutil.web.WebResult;
 import cn.reghao.tnb.common.auth.AuthUser;
 import cn.reghao.tnb.content.api.iface.AdminVideoService;
+import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
+import cn.reghao.tnb.content.app.vod.rpc.AdminVideoServiceImpl;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.web.bind.annotation.*;
@@ -15,12 +18,13 @@ import org.springframework.web.bind.annotation.*;
 @RestController
 @RequestMapping("/api/content/admin/video")
 public class AdminVideoController {
-    private final AdminVideoService adminVideoService;
+    private final AdminVideoServiceImpl adminVideoService;
 
-    public AdminVideoController(AdminVideoService adminVideoService) {
+    public AdminVideoController(AdminVideoServiceImpl adminVideoService) {
         this.adminVideoService = adminVideoService;
     }
 
+    @AuthUser
     @Operation(summary = "点赞视频", description = "N")
     @PostMapping("/thumb/{videoId}")
     public String thumbUpVideo(@PathVariable("videoId") String videoId) {
@@ -28,9 +32,10 @@ public class AdminVideoController {
     }
 
     @AuthUser
-    @Operation(summary = "下载视频", description = "N")
-    @GetMapping("/download/{videoId}")
-    public String getDownloadUrl(@PathVariable("videoId") String videoId) {
-        return WebResult.success();
+    @Operation(summary = "获取所有的视频", description = "N")
+    @GetMapping("/all")
+    public String getVideoPosts(@RequestParam("nextId") int nextId) {
+        PageList<VideoPost> pageList = adminVideoService.getVideoPosts(nextId);
+        return WebResult.success(pageList);
     }
 }

+ 10 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/rpc/AdminVideoServiceImpl.java

@@ -44,6 +44,7 @@ public class AdminVideoServiceImpl implements AdminVideoService {
     private final VideoPostQuery videoPostQuery;
     private final VideoRepository videoRepository;
     private final CategoryService categoryService;
+    private int pageSize = 100;
 
     public AdminVideoServiceImpl(RabbitTemplate rabbitTemplate, VideoPostMapper videoPostMapper,
                                  VideoPostQuery videoPostQuery, VideoRepository videoRepository,
@@ -192,4 +193,13 @@ public class AdminVideoServiceImpl implements AdminVideoService {
             e.printStackTrace();
         }*/
     }
+
+    public PageList<VideoPost> getVideoPosts(int nextId) {
+        List<VideoPost> list = videoPostMapper.findAllById(pageSize, nextId);
+        if (!list.isEmpty()) {
+            nextId = list.get(list.size()-1).getId();
+        }
+
+        return PageList.pageList(""+nextId, list);
+    }
 }

+ 25 - 7
user/user-service/src/main/java/cn/reghao/tnb/user/app/controller/AdminUserController.java

@@ -1,8 +1,13 @@
 package cn.reghao.tnb.user.app.controller;
 
+import cn.reghao.jutil.jdk.db.PageList;
 import cn.reghao.jutil.web.WebResult;
+import cn.reghao.tnb.account.api.dto.AccountAvatar;
 import cn.reghao.tnb.account.api.dto.CrawledUser;
+import cn.reghao.tnb.common.auth.AuthUser;
+import cn.reghao.tnb.user.api.dto.UserInfo;
 import cn.reghao.tnb.user.api.iface.AdminUserService;
+import cn.reghao.tnb.user.app.rpc.AdminUserServiceImpl;
 import cn.reghao.tnb.user.app.service.CrawledUserService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -10,6 +15,8 @@ import org.springframework.http.MediaType;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 /**
  * @author reghao
  * @date 2025-08-19 07:35:20
@@ -18,20 +25,31 @@ import org.springframework.web.bind.annotation.*;
 @RestController
 @RequestMapping("/api/user/admin")
 public class AdminUserController {
-    private AdminUserService adminUserService;
+    private final AdminUserServiceImpl adminUserService;
 
-    public AdminUserController(AdminUserService adminUserService) {
+    public AdminUserController(AdminUserServiceImpl adminUserService) {
         this.adminUserService = adminUserService;
     }
 
-    @Operation(summary = "创建 bilibili 用户帐号", description = "N")
-    @PostMapping("/create/bili")
-    public String updateUserProfile(@RequestBody @Validated CrawledUser crawledUser) {
-        return WebResult.success();
+    @AuthUser
+    @Operation(summary = "获取所有的用户", description = "N")
+    @GetMapping("/user/all")
+    public String getAllUsers(@RequestParam("nextId") int nextId) {
+        PageList<UserInfo> list = adminUserService.getUserList(nextId);
+        return WebResult.success(list);
+    }
+
+    @AuthUser
+    @Operation(summary = "获取所有的用户", description = "N")
+    @GetMapping("/user/avatar")
+    public String getAllUsers1() {
+        List<AccountAvatar> list = adminUserService.getPublishUsers(1);
+        return WebResult.success(list);
     }
 
+    @AuthUser
     @Operation(summary = "查找 bilibili 用户", description = "N")
-    @GetMapping(value = "/search", produces = MediaType.APPLICATION_JSON_VALUE)
+    @PostMapping(value = "/search", produces = MediaType.APPLICATION_JSON_VALUE)
     public String searchUser(@RequestParam("username") String username) {
         return WebResult.success();
     }

+ 4 - 0
user/user-service/src/main/java/cn/reghao/tnb/user/app/db/mapper/UserProfileMapper.java

@@ -6,6 +6,8 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.util.List;
+
 /**
  * @author reghao
  * @date 2024-02-14 14:59:15
@@ -15,4 +17,6 @@ public interface UserProfileMapper extends BaseMapper<UserProfile> {
     void updateUserSignature(@Param("userId") long userId, @Param("signature") String signature);
 
     UserProfile findByUserId(long userId);
+    int countAll();
+    List<UserProfile> findAllById(@Param("pageSize") int pageSize, @Param("nextId") int nextId);
 }

+ 37 - 1
user/user-service/src/main/java/cn/reghao/tnb/user/app/rpc/AdminUserServiceImpl.java

@@ -2,12 +2,15 @@ package cn.reghao.tnb.user.app.rpc;
 
 import cn.reghao.jutil.jdk.db.PageList;
 import cn.reghao.tnb.account.api.dto.AccountAvatar;
+import cn.reghao.tnb.account.api.dto.AccountInfo;
 import cn.reghao.tnb.account.api.iface.AccountQuery;
 import cn.reghao.tnb.content.api.iface.UserContentService;
 import cn.reghao.tnb.user.api.dto.UserInfo;
 import cn.reghao.tnb.user.api.dto.UserSearch;
 import cn.reghao.tnb.user.api.dto.VipPlanInfo;
 import cn.reghao.tnb.user.api.iface.AdminUserService;
+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.po.VipPlan;
 import cn.reghao.tnb.user.app.service.UserVipService;
 import org.apache.dubbo.config.annotation.DubboReference;
@@ -29,9 +32,12 @@ public class AdminUserServiceImpl implements AdminUserService {
     @DubboReference(check = false, retries = 0, timeout = 30_000)
     private UserContentService userContentService;
     private final UserVipService userVipService;
+    private final UserProfileMapper userProfileMapper;
+    private int pageSize = 100;
 
-    public AdminUserServiceImpl(UserVipService userVipService) {
+    public AdminUserServiceImpl(UserVipService userVipService, UserProfileMapper userProfileMapper) {
         this.userVipService = userVipService;
+        this.userProfileMapper = userProfileMapper;
     }
 
     @Override
@@ -39,6 +45,36 @@ public class AdminUserServiceImpl implements AdminUserService {
         return PageList.empty();
     }
 
+    public PageList<UserInfo> getUserList(int nextId) {
+        int total = userProfileMapper.countAll();
+        List<UserProfile> userProfileList = userProfileMapper.findAllById(pageSize, nextId);
+        List<UserInfo> list = userProfileList.stream().map(this::getUserInfo).collect(Collectors.toList());
+        if (!userProfileList.isEmpty()) {
+            nextId = userProfileList.get(userProfileList.size()-1).getId();
+        }
+
+        return PageList.pageList(""+nextId, list);
+    }
+
+    private UserInfo getUserInfo(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);
+        String username = accountInfo.getUsername();
+        if (username.startsWith("bilibili_")) {
+            long biliUserId = Long.parseLong(username.replace("bilibili_", ""));
+            userInfo.setBiliUserId(biliUserId);
+        }
+
+        return userInfo;
+    }
+
     @Override
     public List<AccountAvatar> getPublishUsers(int publishType) {
         List<Long> userIds = userContentService.getContentUser(publishType);

+ 11 - 0
user/user-service/src/main/resources/mapper/UserProfileMapper.xml

@@ -33,6 +33,17 @@
         where user_id=#{userId}
     </update>
 
+    <select id="countAll" resultType="java.lang.Integer">
+        select count(*)
+        from user_profile
+    </select>
+    <select id="findAllById" resultType="cn.reghao.tnb.user.app.model.po.UserProfile">
+        select *
+        from user_profile
+        where id > #{nextId}
+        order by id asc
+        limit #{pageSize}
+    </select>
     <select id="findByUserId" resultType="cn.reghao.tnb.user.app.model.po.UserProfile">
         select *
         from user_profile