فهرست منبع

Merge branch '20250925-wyp-uploadVideo' into test

wangyunpeng 3 هفته پیش
والد
کامیت
7e89b63263

+ 24 - 19
api-module/src/main/java/com/tzld/piaoquan/api/component/VideoApiService.java

@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
+import java.util.Objects;
 
 @Slf4j
 @Component
@@ -69,6 +70,7 @@ public class VideoApiService {
 
     public Long publishVideo(Long uid, String videoUrl, String coverUrl, String title) {
         String url = videoApiHost + "/longvideoapi/crawler/video/send";
+        JSONObject res = null;
         try {
             String param = "videoPath=" + videoUrl +
                     "&crawlerSrcCode=CONTENT" +
@@ -81,24 +83,26 @@ public class VideoApiService {
                     "&viewStatus=1" +
                     "&versionCode=1";
             String post = httpPoolClient.post(url, param, "application/x-www-form-urlencoded;charset=UTF-8");
-            JSONObject res = JSONObject.parseObject(post);
-            if (res.getInteger("code") != 0) {
-                log.error("publishVideo error, uid:{} videoUrl={} coverUrl={} title={} res={}", uid, videoUrl, coverUrl, title, res);
-                throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
-            }
-            JSONObject data = res.getJSONObject("data");
-            Long videoId = data.getLong("id");
-            log.info("publishVideo success, uid:{} videoId={}", uid, videoId);
-            return videoId;
+            res = JSONObject.parseObject(post);
         } catch (Exception e) {
             log.error("publishVideo error", e);
         }
-        return null;
+        if (Objects.isNull(res)) {
+            return null;
+        }
+        if (res.getInteger("code") != 0) {
+            log.error("publishVideo error, uid:{} videoUrl={} coverUrl={} title={} res={}", uid, videoUrl, coverUrl, title, res);
+            throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
+        }
+        JSONObject data = res.getJSONObject("data");
+        Long videoId = data.getLong("id");
+        log.info("publishVideo success, uid:{} videoId={}", uid, videoId);
+        return videoId;
     }
 
-    public String updateVideo(Long uid, Long videoId, String coverUrl, String title) {
+    public void updateVideo(Long uid, Long videoId, String coverUrl, String title) {
         String url = videoApiHost + "/longvideoapi/openapi/video/update";
-        String result = null;
+        JSONObject res = null;
         try {
             JSONObject videoDetail = getVideoInfo(videoId);
             JSONObject chargeDetail = videoDetail.getJSONObject("chargeDetail");
@@ -117,16 +121,17 @@ public class VideoApiService {
             param.put("allowIosPlay", chargeDetail.getLong("allowIosPlay"));
             param.put("allowDownload", 0);
             String post = httpPoolClient.post(url, param.toJSONString());
-            JSONObject res = JSONObject.parseObject(post);
-            if (res.getInteger("code") != 0) {
-                log.error("updateVideo error, uid:{} videoId={} coverUrl={} title={} res={}", uid, videoId, coverUrl, title, res);
-                result = res.getString("msg");
-                throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
-            }
+            res = JSONObject.parseObject(post);
         } catch (Exception e) {
             log.error("updateVideo error", e);
         }
-        return result;
+        if (Objects.isNull(res)) {
+            throw new CommonException(ExceptionEnum.VIDEO_UPDATE_FAILED);
+        }
+        if (res.getInteger("code") != 0) {
+            log.error("updateVideo error, uid:{} videoId={} coverUrl={} title={} res={}", uid, videoId, coverUrl, title, res);
+            throw new CommonException(ExceptionEnum.VIDEO_UPDATE_FAILED.getCode(), res.getString("msg"));
+        }
     }
 
     public JSONObject getVideoInfo(Long videoId) {

+ 4 - 8
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/impl/ContentPlatformUploadContentServiceImpl.java

@@ -71,19 +71,15 @@ public class ContentPlatformUploadContentServiceImpl implements ContentPlatformU
         if (uploadVideo == null) {
             return null;
         }
+        // 调用修改视频接口
+        ContentPlatformPqAccountRel pqAccountRel = settingService.getPqAccountRel(user.getId());
+        videoApiService.updateVideo(pqAccountRel.getPqUid(), uploadVideo.getVideoId(), param.getCoverUrl(), param.getTitle());
+        // save
         uploadVideo.setTitle(param.getTitle());
         uploadVideo.setCover(param.getCoverUrl());
-        uploadVideo.setVideo(param.getVideoUrl());
         uploadVideo.setAuditStatus(UploadVideoAuditStatusEnum.AUDITING.getVal());
         uploadVideo.setUpdateTimestamp(System.currentTimeMillis());
         uploadVideoMapper.updateByPrimaryKeySelective(uploadVideo);
-        // 调用修改视频接口
-        ContentPlatformPqAccountRel pqAccountRel = settingService.getPqAccountRel(user.getId());
-        String result = videoApiService.updateVideo(pqAccountRel.getPqUid(), uploadVideo.getVideoId(), param.getCoverUrl(), param.getTitle());
-        if (StringUtils.isNotBlank(result)) {
-            throw new CommonException(ExceptionEnum.VIDEO_UPDATE_FAILED.getCode(),
-                    ExceptionEnum.VIDEO_UPDATE_FAILED.getMsg() + "," + result);
-        }
         return UploadVideoItemVO.convert(uploadVideo);
     }