Browse Source

根据账户获取视频素材-账户下全部视频素材

yangzian 3 years ago
parent
commit
5d00ed62de

+ 46 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/controller/KuaishouController.java

@@ -0,0 +1,46 @@
+package cn.com.ctop.job.kuaishou.controller;
+
+import cn.com.ctop.job.kuaishou.data.service.IKuaishouVideoListService;
+import cn.com.ctop.job.kuaishou.data.service.IOauthTokenService;
+import cn.com.ctop.job.kuaishou.data.utils.Check;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * zian Y
+ * 2022/2/9
+ **/
+
+@RestController
+@RequestMapping("/kuaishou/kuaishouController")
+@Api(tags="快手")
+@Slf4j
+public class KuaishouController {
+    @Autowired
+    private IOauthTokenService tokenService;
+
+    @Autowired
+    private IKuaishouVideoListService videoListService;
+
+
+
+    @ApiOperation(value="根据账户获取视频素材-账户下全部视频素材", notes="根据账户获取视频素材-账户下全部视频素材")
+    @GetMapping(value = "/getKuaishouVideoByAccountId")
+    public Map<String,String> getKuaishouVideoByAccountId(@RequestParam(name="accountId") Long accountId) {
+        String token = tokenService.getByAccountId(accountId);
+       return videoListService.getKuaishouVideoByAccountId(accountId, token, 1);
+    }
+
+
+
+
+
+}

+ 4 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/IKuaishouVideoListService.java

@@ -3,6 +3,8 @@ package cn.com.ctop.job.kuaishou.data.service;
 import cn.com.ctop.job.kuaishou.data.entity.KuaishouVideoList;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.Map;
+
 /**
  * 快手-素材列表
  *
@@ -12,4 +14,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IKuaishouVideoListService extends IService<KuaishouVideoList> {
     void getVideoList(Long advertiserId, String accessToken, String startDate, String endDate, int page);
+
+    Map<String,String> getKuaishouVideoByAccountId(Long advertiserId, String accessToken, int page);
 }

+ 109 - 1
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/impl/KuaishouVideoListServiceImpl.java

@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -32,7 +33,8 @@ import java.util.Map;
 public class KuaishouVideoListServiceImpl extends ServiceImpl<KuaishouVideoListMapper, KuaishouVideoList> implements IKuaishouVideoListService {
     @Value("${api.kuaishou.postUrl}")
     private String postUrl;
-    @Autowired
+
+    @Resource
     private KuaishouVideoListMapper videoListMapper;
 
     @Override
@@ -117,4 +119,110 @@ public class KuaishouVideoListServiceImpl extends ServiceImpl<KuaishouVideoListM
         }
     }
 
+
+
+    /**
+     *
+     * @description: 根据账户获取视频素材-账户下全部视频素材
+     *
+     * @param advertiserId
+     * @param accessToken
+     * @param page
+     * @return: java.util.Map<java.lang.String,java.lang.String>
+     * @author: zianY
+     * @time: 2022/2/9
+     */
+    @Override
+    public Map<String,String> getKuaishouVideoByAccountId(Long advertiserId, String accessToken, int page) {
+        log.info("调用接口------getKuaishouVideoByAccountId----根据账户获取视频素材---账户--{}===第{}页===》》》",advertiserId,page);
+        Map<String,String> resultMap = new HashMap<>();
+        String url = postUrl + KuaishouConstant.VIDEO_LIST;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        Map<String, Object> param = new HashMap<>();
+        param.put("advertiser_id", advertiserId);
+        Integer page_size = 500;
+        param.put("page_size", page_size);
+        param.put("page", page);
+     /*   if (!Check.isNull(startDate) && !Check.isNull(endDate)) {
+            param.put("start_date", startDate);
+            param.put("end_date", endDate);
+        }*/
+        String result = HttpUtils.httpPostRequest(url, param, headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (Check.isNull(resultJson)) {
+            resultMap.put("code","0");
+            resultMap.put("message","获取快手视频素材数据为空");
+            return resultMap;
+        }
+        Integer code = resultJson.getInteger("code");
+        String message = resultJson.getString("message");
+        if (null == code || code != 0) {
+            log.error("获取快手视频列表数据异常:{},accountId:{}", message, advertiserId);
+            resultMap.put("code","500");
+            resultMap.put("message","账户id:"+advertiserId+"---获取快手视频列表数据异常:"+message);
+            return resultMap;
+        }
+        JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
+        if (null == details || details.size() <= 0) {
+            log.info("快手视频列表信息为空=》accountId:{}", advertiserId);
+            resultMap.put("code","0");
+            resultMap.put("message","获取快手视频素材列表信息为空");
+            return resultMap;
+        }
+        Boolean toGet = true;
+        if (details.size() < page_size) {
+            toGet = false;
+        }
+        List<KuaishouVideoList> videoGetList = new ArrayList<>();
+        for (int i = 0; i < details.size(); i++) {
+            JSONObject detailJson = details.getJSONObject(i);
+            if (Check.isNull(detailJson)) {
+                continue;
+            }
+            KuaishouVideoList videoList = new KuaishouVideoList();
+            String photo_id = detailJson.getString("photo_id");
+            videoList.setAccountId(advertiserId);
+            videoList.setCoverUrl(detailJson.getString("cover_url"));
+            videoList.setPhotoId(photo_id);
+            videoList.setPhotoName(detailJson.getString("photo_name"));
+            videoList.setStatDate(detailJson.getDate("upload_time"));
+            String signature = detailJson.getString("signature");
+            videoList.setSignature(signature);
+            Integer source = detailJson.getInteger("source");
+            if (source == 2) {
+                videoList.setChannelType(1);
+            } else {
+                videoList.setChannelType(0);
+            }
+            Integer new_status = detailJson.getInteger("new_status");
+            if (new_status == 1) {
+                videoList.setStatus(0);
+            } else {
+                videoList.setStatus(1);
+            }
+            videoList.setUrl(detailJson.getString("url"));
+            Integer width = detailJson.getInteger("width");
+            videoList.setWidth(width);
+            Integer height = detailJson.getInteger("height");
+            videoList.setHeight(height);
+            Integer type = MaterialEnum.getTypeBySize(width, height);
+            if (!Check.isNull(type)) {
+                videoList.setMaterialType(type);
+            }
+            videoGetList.add(videoList);
+        }
+        if (!Check.isNull(videoGetList)) {
+            videoListMapper.replaceBatch(videoGetList);
+        }
+        if (toGet) {
+            getKuaishouVideoByAccountId(advertiserId, accessToken, page + 1);
+        } else {
+            log.info("视频列表数据获取完成:accountId:{}", advertiserId);
+        }
+        resultMap.put("code","0");
+        resultMap.put("message","success");
+        return resultMap;
+    }
+
 }