Forráskód Böngészése

update CrawledDataController

reghao 5 hónapja
szülő
commit
21250a7406

+ 2 - 0
account/account-api/src/main/java/cn/reghao/tnb/account/api/dto/CrawledUser.java

@@ -2,6 +2,7 @@ package cn.reghao.tnb.account.api.dto;
 
 import lombok.AllArgsConstructor;
 import lombok.Getter;
+import lombok.NoArgsConstructor;
 import lombok.Setter;
 
 import javax.validation.constraints.NotBlank;
@@ -13,6 +14,7 @@ import java.io.Serializable;
  * @date 2023-01-11 14:37:32
  */
 @AllArgsConstructor
+@NoArgsConstructor
 @Setter
 @Getter
 @Deprecated

+ 0 - 1
account/account-api/src/main/java/cn/reghao/tnb/account/api/iface/AccountQuery.java

@@ -10,7 +10,6 @@ import java.util.List;
  */
 public interface AccountQuery {
     AuthedAccount getAuthedAccount(int type, String sessId);
-    Long getUserId(String username);
     AccountInfo getAccountInfo(long userId);
     AccountAvatar getAccountAvatar(long userId);
     List<AccountInfo> getAccountInfos(List<Long> userIds);

+ 2 - 6
account/account-service/src/main/java/cn/reghao/tnb/account/app/rpc/AccountQueryImpl.java

@@ -51,11 +51,6 @@ public class AccountQueryImpl implements AccountQuery {
         return null;
     }
 
-    @Override
-    public Long getUserId(String username) {
-        return accountRepository.getUserIdByUsername(username);
-    }
-
     @Override
     public AccountInfo getAccountInfo(long userId) {
         AccountInfo accountInfo = accountRepository.getAccountInfo(userId);
@@ -107,7 +102,8 @@ public class AccountQueryImpl implements AccountQuery {
         String screenName = crawledUser.getScreenName();
         String username = crawledUser.getUsername();
         String avatarUrl = crawledUser.getAvatarUrl();
-        Long userId = getUserId(username);
+        AccountInfo accountInfo = getByUsername(username);
+        Long userId = accountInfo != null ? accountInfo.getUserId() : null;
         if (userId != null) {
             return userId;
         } else {

+ 6 - 7
content/content-api/src/main/java/cn/reghao/tnb/content/api/dto/spider/CrawledVideo.java

@@ -1,14 +1,11 @@
 package cn.reghao.tnb.content.api.dto.spider;
 
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
+import cn.reghao.tnb.account.api.dto.CrawledUser;
+import lombok.*;
 
 import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
-import java.time.LocalDateTime;
-import java.util.List;
 
 /**
  * 爬取的视频
@@ -18,7 +15,9 @@ import java.util.List;
  */
 @AllArgsConstructor
 @NoArgsConstructor
-@Data
+@Setter
+@Getter
+@Deprecated
 public class CrawledVideo implements Serializable {
     private static final long serialVersionUID = 1L;
 
@@ -63,5 +62,5 @@ public class CrawledVideo implements Serializable {
     @NotNull
     private Integer scope;
     @NotNull
-    private Long userId;
+    private CrawledUser crawledUser;
 }

+ 0 - 30
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/controller/CrawledDataController.java

@@ -1,21 +1,15 @@
 package cn.reghao.tnb.content.app.vod.controller;
 
 import cn.reghao.jutil.web.WebResult;
-import cn.reghao.tnb.content.api.dto.spider.BiliRegion;
 import cn.reghao.tnb.content.api.dto.comment.CommentSbtDto;
-import cn.reghao.tnb.content.api.dto.VideoFileUpdate;
 import cn.reghao.tnb.content.api.dto.spider.CrawledVideo;
 import cn.reghao.tnb.content.app.vod.service.CrawledDataService;
-import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
 import cn.reghao.tnb.content.app.vod.service.CommentService;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import io.swagger.v3.oas.annotations.Operation;
-import org.springframework.http.MediaType;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.List;
-
 /**
  * @author reghao
  * @date 2023-11-25 14:50:15
@@ -52,28 +46,4 @@ public class CrawledDataController {
         crawledDataService.updateVideoStatistic(crawledVideo);
         return WebResult.success();
     }
-
-    @Operation(summary = "添加 bili 视频资源", description = "N")
-    @PostMapping("/bili/update")
-    public String updateVideoFile(@RequestBody @Validated VideoFileUpdate videoFileUpdate) {
-        crawledDataService.updateVideoFile(videoFileUpdate);
-        return WebResult.success();
-    }
-
-    @Operation(summary = "查询 bili 视频稿件", description = "N")
-    @GetMapping("/bili")
-    public String getBiliVideoPost(@RequestParam("videoId") String videoId) {
-        VideoPost videoPost = crawledDataService.videoExist(videoId);
-        if (videoPost != null) {
-            return WebResult.success(true);
-        }
-
-        return WebResult.success(false);
-    }
-
-    @Operation(summary = "获取 bili 视频分区", description = "N")
-    @GetMapping(value = "/categories/bili", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String videoCategories() {
-        return WebResult.success();
-    }
 }

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/repository/VideoRepository.java

@@ -34,7 +34,7 @@ public class VideoRepository {
 
     @Transactional(rollbackFor = Exception.class)
     public void savePostVideo(VideoPost videoPost, VideoStatistic videoStatistic) {
-        videoPostMapper.updateVideoPublish(videoPost);
+        videoPostMapper.save(videoPost);
         videoStatisticMapper.save(videoStatistic);
     }
 

+ 2 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/po/VideoPost.java

@@ -65,7 +65,7 @@ public class VideoPost extends BaseObject<Integer> {
     }
 
     @Deprecated
-    public VideoPost(CrawledVideo video) {
+    public VideoPost(CrawledVideo video, long publishBy) {
         this.videoId = video.getVideoId();
         this.title = video.getTitle();
         this.description = video.getDescription();
@@ -77,7 +77,7 @@ public class VideoPost extends BaseObject<Integer> {
         this.duration = video.getDuration();
         this.coverUrl = video.getCoverUrl();
         this.publishAt = DateTimeConverter.localDateTime(video.getPubDate());
-        this.publishBy = video.getUserId();
+        this.publishBy = publishBy;
     }
 
     public void update(VideoPublishSbt video, String coverUrl, long publishAt) {

+ 16 - 7
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/CrawledDataService.java

@@ -2,6 +2,9 @@ package cn.reghao.tnb.content.app.vod.service;
 
 import cn.reghao.file.api.iface.OssService;
 import cn.reghao.oss.api.dto.media.VideoInfo;
+import cn.reghao.tnb.account.api.dto.AccountInfo;
+import cn.reghao.tnb.account.api.dto.CrawledUser;
+import cn.reghao.tnb.account.api.iface.AccountQuery;
 import cn.reghao.tnb.content.api.constant.PostScope;
 import cn.reghao.tnb.content.api.dto.VideoFileUpdate;
 import cn.reghao.tnb.content.api.dto.spider.CrawledVideo;
@@ -20,7 +23,9 @@ import org.springframework.stereotype.Service;
 @Slf4j
 @Service
 public class CrawledDataService {
-    @DubboReference(check = false)
+    @DubboReference(check = false, retries = 0, timeout = 5_000)
+    private AccountQuery accountQuery;
+    @DubboReference(check = false, retries = 0, timeout = 5_000)
     private OssService ossService;
 
     private final VideoPostService videoPostService;
@@ -31,19 +36,23 @@ public class CrawledDataService {
         this.videoRepository = videoRepository;
     }
 
-    public VideoPost videoExist(String videoId) {
-        VideoPost videoPost = videoRepository.getVideoPost(videoId);
-        return videoPost;
-    }
-
     public synchronized void publishVideo(CrawledVideo crawledVideo) {
         String videoId = crawledVideo.getVideoId();
         VideoPost videoPost1 = videoRepository.getVideoPost(videoId);
         if (videoPost1 != null ) {
+            log.error("VideoPost {} exists", videoPost1.getVideoId());
             return;
         }
 
-        VideoPost videoPost = new VideoPost(crawledVideo);
+        CrawledUser crawledUser = crawledVideo.getCrawledUser();
+        String username = crawledUser.getUsername();
+        AccountInfo accountInfo = accountQuery.getByUsername(username);
+        Long publishBy = accountInfo != null ? accountInfo.getUserId() : null;
+        if (publishBy == null) {
+            publishBy = accountQuery.createCrawledAccount(crawledUser);
+        }
+
+        VideoPost videoPost = new VideoPost(crawledVideo, publishBy);
         VideoStatistic videoStatistic = new VideoStatistic(crawledVideo);
         String tags = crawledVideo.getTags();
         videoPostService.saveVideo(videoPost, videoStatistic, tags);

+ 0 - 14
user/user-service/src/main/java/cn/reghao/tnb/user/app/service/AdminUserService.java

@@ -4,7 +4,6 @@ import cn.reghao.jutil.jdk.db.PageList;
 import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
 import cn.reghao.tnb.account.api.dto.AccountInfo;
 import cn.reghao.tnb.account.api.dto.AccountRegistry;
-import cn.reghao.tnb.account.api.dto.CrawledUser;
 import cn.reghao.tnb.account.api.iface.AccountQuery;
 import cn.reghao.tnb.account.api.iface.AdminAccountService;
 import cn.reghao.tnb.user.api.dto.UserInfo;
@@ -117,19 +116,6 @@ public class AdminUserService {
         return null;
     }
 
-    public synchronized Long createAccount(CrawledUser crawledUser) {
-        Long userId = accountQuery.createCrawledAccount(crawledUser);
-        UserProfile userProfile = userProfileMapper.findByUserId(userId);
-        if (userProfile == null) {
-            int gender = crawledUser.getGender();
-            String signature = crawledUser.getSignature();
-            userProfile = new UserProfile(userId, gender, signature);
-            userProfileMapper.save(userProfile);
-        }
-
-        return userId;
-    }
-
     public List<WalletChargeDto> getChargeReqs() {
         return userWalletService.getChargeReqs();
     }