Pārlūkot izejas kodu

用户上传视频

wangyunpeng 3 nedēļas atpakaļ
vecāks
revīzija
91fad4d7f0

+ 3 - 0
api-module/src/main/java/com/tzld/piaoquan/api/common/enums/ExceptionEnum.java

@@ -52,6 +52,9 @@ public enum ExceptionEnum {
     THIRD_PART_STAFF_NOT_FOUND(5001, "账号不存在"),
     THIRD_PART_ROOM_NOT_FOUND(5002, "群不存在"),
 
+    // 用户上传内容管理
+    VIDEO_PUBLISH_FAILED(6001, "视频发布失败"),
+
     // 自动回复
     CGI_REPLY_BUCKET_DATA_NOT_FOUND(10000, "自动回复数据不存在"),
     CGI_REPLY_BUCKET_DATA_NOT_AUTO_REPLY(10001, "非自动回复数据"),

+ 92 - 1
api-module/src/main/java/com/tzld/piaoquan/api/component/VideoApiService.java

@@ -1,6 +1,9 @@
 package com.tzld.piaoquan.api.component;
 
 import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
+import com.tzld.piaoquan.api.common.exception.CommonException;
+import com.tzld.piaoquan.api.model.vo.contentplatform.WxBaseUserInfoVO;
 import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,8 +30,96 @@ public class VideoApiService {
             JSONObject data = res.getJSONObject("data");
             return data.getJSONArray("videoCoverImages").toJavaList(String.class);
         } catch (Exception e) {
-            log.error("getVideoDetailRequest error", e);
+            log.error("getCoverImagePaths error", e);
         }
         return null;
     }
+
+    public WxBaseUserInfoVO webLogin(String code, Integer appType, String appId, String machineCode) {
+        String url = videoApiHost + "/longvideoapi/user/webLogin";
+        try {
+            String post = httpPoolClient.post(url, "code=" + code +
+                    "&appType=" + appType +
+                    "&appId=" + appId +
+                    "&path=%2F" +
+                    "&clientTimestamp=" + System.currentTimeMillis() +
+                    "6&loginUid=" +
+                    "&token=" +
+                    "&machineCode=" + machineCode, "application/x-www-form-urlencoded;charset=UTF-8");
+            JSONObject res = JSONObject.parseObject(post);
+            return res.getObject("data", WxBaseUserInfoVO.class);
+        } catch (Exception e) {
+            log.error("webLogin error", e);
+        }
+        return null;
+    }
+
+    public void saveUserPhoneNumber(Long uid, String phoneNumber) {
+        String url = videoApiHost + "/longvideoapi/openapi/user/saveUserPhoneNumber";
+        try {
+            JSONObject param = new JSONObject();
+            param.put("uid", uid);
+            param.put("phoneNumber", phoneNumber);
+            String post = httpPoolClient.post(url, param.toJSONString());
+        } catch (Exception e) {
+            log.error("saveUserPhoneNumber error", e);
+        }
+    }
+
+    public Long publishVideo(Long uid, String videoUrl, String coverUrl, String title) {
+        String url = videoApiHost + "/longvideoapi/crawler/video/send";
+        try {
+            String post = httpPoolClient.post(url, "videoPath=" + videoUrl +
+                    "&crawlerSrcCode=\"CONTENT\"" +
+                    "&crawlerSrcPublishTimestamp=\"" + System.currentTimeMillis() + "\"" +
+                    "&crawlerTaskTimestamp=\"" + System.currentTimeMillis() + "\"" +
+                    "&coverImgPath=" + coverUrl +
+                    "&loginUid=" + uid +
+                    "&title=" + title, "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("videoId");
+            log.info("publishVideo success, uid:{} videoId={}", uid, videoId);
+            return videoId;
+        } catch (Exception e) {
+            log.error("publishVideo error", e);
+        }
+        return null;
+    }
+
+    public void updateVideo(Long uid, Long videoId, String coverUrl, String title) {
+        String url = videoApiHost + "/longvideoapi/openapi/video/update";
+        try {
+            JSONObject param = new JSONObject();
+            param.put("loginUid", uid);
+            param.put("videoId", videoId);
+            param.put("coverImgPath", coverUrl);
+            param.put("title", title);
+            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);
+                throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
+            }
+        } catch (Exception e) {
+            log.error("updateVideo error", e);
+        }
+    }
+
+    public void deleteVideo(Long uid, Long videoId) {
+        String url = videoApiHost + "/longvideoapi/openapi/video/delete";
+        try {
+            JSONObject param = new JSONObject();
+            param.put("loginUid", uid);
+            param.put("videoId", videoId);
+            String post = httpPoolClient.post(url, param.toJSONString());
+        } catch (Exception e) {
+            log.error("deleteVideo error", e);
+        }
+    }
+
 }

+ 3 - 0
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/ContentPlatformSettingService.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.api.service.contentplatform;
 
 import com.tzld.piaoquan.api.model.param.contentplatform.WxWebLoginParam;
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformPqAccountRel;
 import com.tzld.piaoquan.api.model.vo.contentplatform.WxBaseUserInfoVO;
 
 public interface ContentPlatformSettingService {
@@ -8,4 +9,6 @@ public interface ContentPlatformSettingService {
     WxBaseUserInfoVO wxLoginByWeb(WxWebLoginParam param);
 
     WxBaseUserInfoVO getBindPQUserInfo();
+
+    ContentPlatformPqAccountRel getPqAccountRel(Long accountId);
 }

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

@@ -30,8 +30,8 @@ public class ContentPlatformSettingServiceImpl implements ContentPlatformSetting
     @Override
     public WxBaseUserInfoVO wxLoginByWeb(WxWebLoginParam param) {
         ContentPlatformAccount user = LoginUserContext.getUser();
-        // todo uploadVideo 调用webLogin接口 登录/注册 票圈用户
-        WxBaseUserInfoVO wxBaseUserInfoVO = new WxBaseUserInfoVO();
+        // 调用webLogin接口 登录/注册 票圈用户
+        WxBaseUserInfoVO wxBaseUserInfoVO = videoApiService.webLogin(param.getCode(), param.getAppType(), param.getAppId(), param.getMachineCode());
         ContentPlatformPqAccountRel pqAccountRel = getPqAccountRel(user.getId());
         if (Objects.nonNull(pqAccountRel)) {
             wxBaseUserInfoVO = new WxBaseUserInfoVO();
@@ -54,10 +54,12 @@ public class ContentPlatformSettingServiceImpl implements ContentPlatformSetting
     }
 
     private void asyncUpdatePqAccountTelNum(Long uid, String telNum) {
-        // todo uploadVideo 修改票圈用户手机号
+        // 修改票圈用户手机号
+        videoApiService.saveUserPhoneNumber(uid, telNum);
     }
 
-    private ContentPlatformPqAccountRel getPqAccountRel(Long accountId) {
+    @Override
+    public ContentPlatformPqAccountRel getPqAccountRel(Long accountId) {
         ContentPlatformPqAccountRelExample example = new ContentPlatformPqAccountRelExample();
         example.createCriteria().andAccountIdEqualTo(accountId);
         List<ContentPlatformPqAccountRel> pqAccountRels = pqAccountRelMapper.selectByExample(example);

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

@@ -1,6 +1,8 @@
 package com.tzld.piaoquan.api.service.contentplatform.impl;
 
+import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
 import com.tzld.piaoquan.api.common.enums.contentplatform.UploadVideoAuditStatusEnum;
+import com.tzld.piaoquan.api.common.exception.CommonException;
 import com.tzld.piaoquan.api.component.VideoApiService;
 import com.tzld.piaoquan.api.dao.mapper.contentplatform.ContentPlatformUploadVideoMapper;
 import com.tzld.piaoquan.api.model.config.LoginUserContext;
@@ -9,9 +11,11 @@ import com.tzld.piaoquan.api.model.param.contentplatform.PublishVideoParam;
 import com.tzld.piaoquan.api.model.param.contentplatform.UploadVideoListParam;
 import com.tzld.piaoquan.api.model.param.contentplatform.VideoAuditCallBackParam;
 import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformAccount;
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformPqAccountRel;
 import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformUploadVideo;
 import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformUploadVideoExample;
 import com.tzld.piaoquan.api.model.vo.contentplatform.UploadVideoItemVO;
+import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformSettingService;
 import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformUploadContentService;
 import com.tzld.piaoquan.growth.common.utils.page.Page;
 import lombok.extern.slf4j.Slf4j;
@@ -31,13 +35,18 @@ public class ContentPlatformUploadContentServiceImpl implements ContentPlatformU
     @Autowired
     ContentPlatformUploadVideoMapper uploadVideoMapper;
     @Autowired
+    ContentPlatformSettingService settingService;
+    @Autowired
     VideoApiService videoApiService;
 
     @Override
     public UploadVideoItemVO publishVideo(PublishVideoParam param) {
         ContentPlatformAccount user = LoginUserContext.getUser();
-        // todo uploadVideo 调用视频发布 获取videoId
-        Long videoId = null;
+        // 调用视频发布 获取videoId
+        Long videoId = videoApiService.publishVideo(user.getId(), param.getVideoUrl(), param.getCoverUrl(), param.getTitle());
+        if (videoId == null) {
+            throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED);
+        }
         ContentPlatformUploadVideo uploadVideo = new ContentPlatformUploadVideo();
         uploadVideo.setVideoId(videoId);
         uploadVideo.setTitle(param.getTitle());
@@ -53,6 +62,7 @@ public class ContentPlatformUploadContentServiceImpl implements ContentPlatformU
 
     @Override
     public UploadVideoItemVO updateVideo(PublishVideoParam param) {
+        ContentPlatformAccount user = LoginUserContext.getUser();
         ContentPlatformUploadVideo uploadVideo = getUploadVideo(param.getVideoId());
         if (uploadVideo == null) {
             return null;
@@ -63,7 +73,9 @@ public class ContentPlatformUploadContentServiceImpl implements ContentPlatformU
         uploadVideo.setAuditStatus(UploadVideoAuditStatusEnum.AUDITING.getVal());
         uploadVideo.setUpdateTimestamp(System.currentTimeMillis());
         uploadVideoMapper.updateByPrimaryKeySelective(uploadVideo);
-        // todo uploadVideo 调用修改视频接口
+        // 调用修改视频接口
+        ContentPlatformPqAccountRel pqAccountRel = settingService.getPqAccountRel(user.getId());
+        videoApiService.updateVideo(pqAccountRel.getPqUid(), uploadVideo.getVideoId(), param.getCoverUrl(), param.getTitle());
         return UploadVideoItemVO.convert(uploadVideo);
     }
 
@@ -79,6 +91,7 @@ public class ContentPlatformUploadContentServiceImpl implements ContentPlatformU
 
     @Override
     public void deleteVideo(DeleteVideoParam param) {
+        ContentPlatformAccount user = LoginUserContext.getUser();
         ContentPlatformUploadVideo uploadVideo = getUploadVideo(param.getVideoId());
         if (uploadVideo == null) {
             return;
@@ -86,7 +99,9 @@ public class ContentPlatformUploadContentServiceImpl implements ContentPlatformU
         uploadVideo.setIsDelete(1);
         uploadVideo.setUpdateTimestamp(System.currentTimeMillis());
         uploadVideoMapper.updateByPrimaryKeySelective(uploadVideo);
-        // todo uploadVideo 调用删除视频接口
+        // 调用删除视频接口
+        ContentPlatformPqAccountRel pqAccountRel = settingService.getPqAccountRel(user.getId());
+        videoApiService.deleteVideo(pqAccountRel.getPqUid(), uploadVideo.getVideoId());
     }
 
     @Override