ソースを参照

素造接口对接

yumeng 5 年 前
コミット
6dee1a40fa
14 ファイル変更135 行追加241 行削除
  1. 0 1
      jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java
  2. 24 56
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java
  3. 5 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouSuZaoLoadJob.java
  4. 3 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/KuaiShouUploadServiceImpl.java
  5. 4 1
      module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouSuZaoLoadJob.java
  6. 3 4
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java
  7. 0 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouVideoGet.java
  8. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java
  9. 0 9
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoTimeService.java
  10. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java
  11. 3 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouMaterialUploadServiceImpl.java
  12. 55 62
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoGetServiceImpl.java
  13. 0 64
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoTimeServiceImpl.java
  14. 36 35
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

+ 0 - 1
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -32,7 +32,6 @@ public class DateUtils extends PropertyEditorSupport {
     private static final long SECOND_IN_MILLIS = 1000L;
 
 
-
     public static Date getNowDate() throws ParseException {
         SimpleDateFormat dsdf = new SimpleDateFormat("yyyy-MM-dd");
         String nowDate = getNowDate("yyyy-MM-dd");

+ 24 - 56
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -7,7 +7,6 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.common.module.utils.ResultMapUtils;
 import cn.com.ctop.common.module.utils.StatusCode;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.service.*;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
@@ -97,69 +96,38 @@ public class TestController {
     private IMaterialCutFrameService cutFrameService;
     @Autowired
     IKuaiShouVideoGetService videoGetService;
-    @Autowired
-    private IKuaiShouVideoTimeService timeService;
 
 
-    @GetMapping(value = "/getVideoTime")
-    public void getVideoTime() throws InterruptedException {
+    @GetMapping(value = "/getSuZhao")
+    public void getSuZhao() throws JobExecutionException {
         Thread thread = new Thread() {
             @Override
             public void run() {
-                QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
-                queryWrapper.eq("channel_type", 0);
-                List<KuaiShouVideoGet> list = videoGetService.list(queryWrapper);
-                for (KuaiShouVideoGet video : list) {
-                    videoService.submit(new Runnable() {
-                        @Override
-                        public void run() {
-                            Date date = timeService.getVideoTime(video.getPhotoId(), video.getAccountId());
-                            if (!Check.isNull(date)) {
-                                video.setUploadDate(date);
-                                videoGetService.updateById(video);
-                            }
+                SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
+                try {
 
-                            try {
-                                Thread.sleep(1000);
-                            } catch (InterruptedException e) {
-                                e.printStackTrace();
+                    //1:查询当日数据
+                    List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
+                    if (null == tokens || tokens.size() <= 0) {
+                        log.info("定时获取快手数据异常:未获取到可用的token");
+                        return;
+                    }
+
+                    executorService = Executors.newFixedThreadPool(8);
+                    tokens.forEach(token -> {
+                        executorService.submit(new Runnable() {
+                            @Override
+                            public void run() {
+                                //1: 获取广告主信息数据
+                                kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1, null, null);
                             }
-                        }
+                        });
                     });
+                } catch (Exception e) {
+                    e.printStackTrace();
                 }
-            }
-        };
-        thread.start();
-
-    }
 
 
-    @GetMapping(value = "/getSuZhao")
-    public void getSuZhao() throws InterruptedException {
-        Thread thread = new Thread() {
-            @Override
-            public void run() {
-                QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
-                queryWrapper.eq("channel_type", 1);
-                List<KuaiShouVideoGet> list = videoGetService.list(queryWrapper);
-                for (KuaiShouVideoGet video : list) {
-                    suzhaoService.submit(new Runnable() {
-                        @Override
-                        public void run() {
-                            Date date = timeService.getVideoTime(video.getPhotoId(), video.getAccountId());
-                            if (!Check.isNull(date)) {
-                                video.setUploadDate(date);
-                                videoGetService.updateById(video);
-                            }
-
-                            try {
-                                Thread.sleep(1000);
-                            } catch (InterruptedException e) {
-                                e.printStackTrace();
-                            }
-                        }
-                    });
-                }
             }
         };
         thread.start();
@@ -223,7 +191,7 @@ public class TestController {
                             @Override
                             public void run() {
                                 try {
-                                    kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1);
+                                    kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1, null, null);
                                     String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
                                     String videoEndDate = DateUtils.addDay(nowDate, -180);
                                     SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
@@ -255,7 +223,7 @@ public class TestController {
     }
 
 
-    @GetMapping(value = "/getVideoByAccountId")
+   /* @GetMapping(value = "/getVideoByAccountId")
     public String getVideoByAccountId(Long accountId) throws IOException {
 
         try {
@@ -295,7 +263,7 @@ public class TestController {
             e.printStackTrace();
         }
         return "Success";
-    }
+    }*/
 
 
     @GetMapping(value = "/createCutTask")

+ 5 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouSuZaoLoadJob.java

@@ -4,7 +4,9 @@ import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import com.xxl.job.core.util.DateUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
 import org.quartz.Job;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
@@ -35,7 +37,9 @@ public class KuaishouSuZaoLoadJob implements Job {
                         @Override
                         public void run() {
                             try {
-                                kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1);
+                                String endDate = DateUtils.getNowDate("yyyy-MM-dd");
+                                String startDate = DateUtils.getAnotherDay("yyyy-mm-dd", endDate, -1);
+                                kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1, startDate, endDate);
                             } catch (Exception e) {
                                 e.printStackTrace();
                             } finally {

+ 3 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/KuaiShouUploadServiceImpl.java

@@ -18,6 +18,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.ParseException;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.ctop.service.IKuaiShouUploadService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -130,8 +131,8 @@ public class KuaiShouUploadServiceImpl implements IKuaiShouUploadService {
                                             videoGet.setAccountId(accountId);
                                             videoGet.setId(accountId + photoId);
                                             videoGet.setUrl(materialInfo.getUrl());
-
-
+                                            videoGet.setCoverUrl(materialInfo.getUrl()+ "?x-oss-process=video/snapshot,t_00000,m_fast");
+                                            videoGet.setStatDate(DateUtils.getNowDate());
                                             videoGet.setMaterialType(finalType);
                                             videoGet.setPhotoId(photoId);
                                             videoGet.setSignature(signature);

+ 4 - 1
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouSuZaoLoadJob.java

@@ -6,6 +6,7 @@ import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import com.xxl.job.core.log.XxlJobLogger;
+import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -25,7 +26,9 @@ public class KuaishouSuZaoLoadJob {
     public ReturnT<String> execute(String param) throws Exception {
         List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
         executorService = Executors.newFixedThreadPool(8);
-        tokens.forEach(token -> executorService.submit(() -> kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1)));
+        String endDate = DateUtils.getDate("yyyy-MM-dd");
+        String startDate = DateUtils.getAnotherDay("yyyy-MM-dd", endDate, -1);
+        tokens.forEach(token -> executorService.submit(() -> kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1, startDate, endDate)));
         XxlJobLogger.log("快手素造数据同步完成");
         return ReturnT.SUCCESS;
     }

+ 3 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java

@@ -163,12 +163,12 @@ public class BatchController {
             };
             thread2.start();
 
-
             Thread thread3 = new Thread() {
                 @Override
                 public void run() {
-                    iKuaishouInterfaceService.getSuZaoList(oauthToken.getAccessToken(), oauthToken.getAccountId(), 1);
-                    videoGetService.getKeyFrame(oauthToken);
+                    String endDate = DateUtils.getNowDate("yyyy-MM-dd");
+                    String startDate = DateUtils.getAnotherDay("yyyy-mm-dd", endDate, -1);
+                    iKuaishouInterfaceService.getSuZaoList(oauthToken.getAccessToken(), oauthToken.getAccountId(), 1, startDate, endDate);
                 }
             };
             thread3.start();
@@ -182,7 +182,6 @@ public class BatchController {
             };
             thread4.start();
 
-
         } catch (Exception e) {
             e.printStackTrace();
             result.setSuccess(false);

+ 0 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouVideoGet.java

@@ -75,8 +75,6 @@ public class KuaiShouVideoGet {
     private String signature;
 
     private Date statDate;
-    private Date  uploadDate;
-
 
     private Integer materialType;
     /**

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java

@@ -17,5 +17,5 @@ import java.util.List;
 public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
     void replaceBatch(List<KuaiShouVideoGet> videoGets);
 
-    void getKeyFrame(CtopOauthToken token);
+    void getKeyFrame(String token,Long accountId, String md5, String photoId);
 }

+ 0 - 9
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoTimeService.java

@@ -1,9 +0,0 @@
-package cn.com.ctop.kuaishou.modules.batch.service;
-
-
-public interface IKuaiShouVideoTimeService {
-
-    java.util.Date getVideoTime(String photoId, Long accountId);
-
-
-}

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java

@@ -458,7 +458,7 @@ public interface IKuaishouInterfaceService {
      * @param accountId
      * @param page
      */
-    void getSuZaoList(String token, Long accountId, int page);
+    void getSuZaoList(String token, Long accountId, int page, String startDate,String endDate);
 
     /**
      * 异步获取创意信息

+ 3 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouMaterialUploadServiceImpl.java

@@ -12,6 +12,7 @@ import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.io.FileSystemResource;
@@ -85,12 +86,13 @@ public class KuaiShouMaterialUploadServiceImpl implements IKuaiShouMaterialUploa
                         videoGet.setMaterialType(type);
                         videoGet.setPhotoId(photoId);
                         videoGet.setSignature(signature);
+                        videoGet.setStatDate(DateUtils.getNowDate());
+                        videoGet.setCoverUrl(url + "?x-oss-process=video/snapshot,t_00000,m_fast");
                         kuaiShouVideoGetService.saveOrUpdate(videoGet);
                         returnJson.put("success", true);
                         returnJson.put("photoId", photoId);
                         returnJson.put("signature", signature);
                         returnJson.put("message", "上传成功");
-
                     }
                     LoadFileUtil.delFile(localUrl);
                     log.info("快手素材上传完成,accountId:{},code:{},返回信息:{}", accountId, signature, resultJson);
@@ -99,7 +101,6 @@ public class KuaiShouMaterialUploadServiceImpl implements IKuaiShouMaterialUploa
                     returnJson.put("success", false);
                     returnJson.put("signature", signature);
                     returnJson.put("message", resultJson.getString("message"));
-
                 }
             } else {
                 log.error("快手上传素材返回信息为空请求参数:{}", requestJson);

+ 55 - 62
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoGetServiceImpl.java

@@ -1,6 +1,5 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
-import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.MaterialCutFrame;
 import cn.com.ctop.common.module.service.IMaterialCutFrameService;
 import cn.com.ctop.common.module.utils.Check;
@@ -27,7 +26,6 @@ import java.util.concurrent.Executors;
 /**
  * @Description: 快手-获取视频接口
  * @Author: jeecg-boot
- *
  * @Date: 2019-07-25
  * @Version: V1.0
  */
@@ -51,82 +49,77 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
     /**
      * 获取关键帧
      *
-     *
      * @param
      */
     @Override
-    public void getKeyFrame(CtopOauthToken token) {
+    public void getKeyFrame(String token, Long accountId, String md5, String photoId) {
         try {
-            QueryWrapper<KuaiShouVideoGet> videoGetQueryWrapper = new QueryWrapper<>();
+     /*       QueryWrapper<KuaiShouVideoGet> videoGetQueryWrapper = new QueryWrapper<>();
             videoGetQueryWrapper.eq("account_id", token.getAccountId());
             videoGetQueryWrapper.eq("channel_type", 1);
             List<KuaiShouVideoGet> kuaiShouVideoGets = videoGetMapper.selectList(videoGetQueryWrapper);
             if (Check.isNull(kuaiShouVideoGets)) {
                 return;
-            }
-            for (KuaiShouVideoGet videoGet : kuaiShouVideoGets) {
-                synchronized (this) {
-                    if (!Check.isNull(videoGet.getSignature())) {
-                        QueryWrapper<MaterialCutFrame> cutFrameQueryWrapper = new QueryWrapper<>();
-                        cutFrameQueryWrapper.eq("video_signature", videoGet.getSignature());
-                        cutFrameQueryWrapper.last("limit 1");
-                        MaterialCutFrame one = materialCutFrameService.getOne(cutFrameQueryWrapper);
-                        if (!Check.isNull(one)) {
-                            continue;
-                        }
-                    }
-
-                    executorService.submit(new Runnable() {
-                        @Override
-                        public void run() {
-                            String url = "https://ad.e.kuaishou.com/rest/openapi/v1/tool/key_frame";
-                            JSONArray photoArr = new JSONArray();
-                            photoArr.add(videoGet.getPhotoId());
-                            Map<String, String> headers = new HashMap<>();
-                            headers.put("Access-Token", token.getAccessToken());
-                            headers.put("Content-Type", "application/json");
-                            JSONObject requestJson = new JSONObject();
-                            requestJson.put("advertiser_id", token.getAccountId());
-                            requestJson.put("photo_ids", photoArr);
-                            String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
-                            JSONObject resultJson = JSONObject.parseObject(result);
-                            if (!Check.isNull(resultJson)) {
-                                Integer code = resultJson.getInteger("code");
-                                if (code == 0) {
-                                    JSONArray dataArr = resultJson.getJSONArray("data");
-                                    if (!Check.isNull(dataArr)) {
-                                        for (int i = 0; i < dataArr.size(); i++) {
-                                            String imageUrl = dataArr.getString(i);
-                                            String localPath = LoadFileUtil.downLoadFromUrl(imageUrl, downloadUrl);
-                                            String md5 = null;
-                                            try {
-                                                md5 = LoadFileUtil.getMD5(localPath);
-                                            } catch (IOException e) {
-                                                e.printStackTrace();
-                                                continue;
-                                            }
-                                            Map<String, Object> deleteMap = new HashMap<>();
-                                            deleteMap.put("video_signature", videoGet.getSignature());
-                                            deleteMap.put("signature", md5);
-                                            materialCutFrameService.removeByMap(deleteMap);
-
-                                            MaterialCutFrame materialCutFrame = new MaterialCutFrame();
-                                            materialCutFrame.setImageIndex(i);
-                                            materialCutFrame.setVideoSignature(videoGet.getSignature());
-                                            materialCutFrame.setUrl(imageUrl);
-                                            materialCutFrame.setSignature(md5);
-                                            materialCutFrameService.save(materialCutFrame);
-                                            LoadFileUtil.delFile(localPath);
+            }*/
+            //   for (KuaiShouVideoGet videoGet : kuaiShouVideoGets) {
+            synchronized (this) {
+                QueryWrapper<MaterialCutFrame> cutFrameQueryWrapper = new QueryWrapper<>();
+                cutFrameQueryWrapper.eq("video_signature", md5);
+                cutFrameQueryWrapper.last("limit 1");
+                MaterialCutFrame one = materialCutFrameService.getOne(cutFrameQueryWrapper);
+                if (!Check.isNull(one)) {
+                    return;
+                }
+                executorService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        String url = "https://ad.e.kuaishou.com/rest/openapi/v1/tool/key_frame";
+                        JSONArray photoArr = new JSONArray();
+                        photoArr.add(photoId);
+                        Map<String, String> headers = new HashMap<>();
+                        headers.put("Access-Token", token);
+                        headers.put("Content-Type", "application/json");
+                        JSONObject requestJson = new JSONObject();
+                        requestJson.put("advertiser_id", accountId);
+                        requestJson.put("photo_ids", photoArr);
+                        String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+                        JSONObject resultJson = JSONObject.parseObject(result);
+                        if (!Check.isNull(resultJson)) {
+                            Integer code = resultJson.getInteger("code");
+                            if (code == 0) {
+                                JSONArray dataArr = resultJson.getJSONArray("data");
+                                if (!Check.isNull(dataArr)) {
+                                    for (int i = 0; i < dataArr.size(); i++) {
+                                        String imageUrl = dataArr.getString(i);
+                                        String localPath = LoadFileUtil.downLoadFromUrl(imageUrl, downloadUrl);
+                                        String md5 = null;
+                                        try {
+                                            md5 = LoadFileUtil.getMD5(localPath);
+                                        } catch (IOException e) {
+                                            e.printStackTrace();
+                                            continue;
                                         }
+                                        Map<String, Object> deleteMap = new HashMap<>();
+                                        deleteMap.put("video_signature", md5);
+                                        deleteMap.put("signature", md5);
+                                        materialCutFrameService.removeByMap(deleteMap);
+                                        MaterialCutFrame materialCutFrame = new MaterialCutFrame();
+                                        materialCutFrame.setImageIndex(i);
+                                        materialCutFrame.setVideoSignature(md5);
+                                        materialCutFrame.setUrl(imageUrl);
+                                        materialCutFrame.setSignature(md5);
+                                        materialCutFrameService.save(materialCutFrame);
+                                        LoadFileUtil.delFile(localPath);
                                     }
                                 }
                             }
                         }
-                    });
-                }
-
+                    }
+                });
             }
 
+            // }
+
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 0 - 64
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoTimeServiceImpl.java

@@ -1,64 +0,0 @@
-package cn.com.ctop.kuaishou.modules.batch.service.impl;
-
-import cn.com.ctop.common.module.utils.Check;
-import cn.com.ctop.common.module.utils.HttpUtils;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoTimeService;
-import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAgentAccount;
-import cn.com.ctop.kuaishou.modules.report.service.IKuaishouAgentAccountService;
-import com.alibaba.fastjson.JSONObject;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-
-@Slf4j
-@Service
-public class KuaiShouVideoTimeServiceImpl implements IKuaiShouVideoTimeService {
-    @Autowired
-    private IKuaishouAgentAccountService agentAccountService;
-
-    @Override
-    public java.util.Date getVideoTime(String photoId, Long accountId) {
-
-        KuaishouAgentAccount agentAccount = agentAccountService.getById(accountId);
-        if (Check.isNull(agentAccount)) {
-            log.info("未获取到userId:accountId:{}",accountId);
-            return null;
-        }
-
-        try {
-            String videoUrl = "http://yongzhou.s.gifshow.com/i/photo/lwx?userId=" + agentAccount.getUserId() + "&photoId=" + photoId;
-            String res = HttpUtils.getKuaishouShareUrl(videoUrl);
-            String path = res.split("\\?")[0];
-            String photoIdStr = path.substring(path.lastIndexOf("/") + 1, path.length());
-            path = path.substring(0, path.lastIndexOf("/"));
-            String uid = path.substring(path.lastIndexOf("/") + 1, path.length());
-            String result = HttpUtils.postKuaishouVideoUrl("https://live.kuaishou.com/m_graphql", uid, photoIdStr);
-            JSONObject resultJson = JSONObject.parseObject(result);
-            if (!Check.isNull(resultJson)) {
-                JSONObject dataJson = resultJson.getJSONObject("data");
-                if (!Check.isNull(dataJson)) {
-                    JSONObject feedById = dataJson.getJSONObject("feedById");
-                    if (!Check.isNull(feedById)) {
-                        JSONObject currentWork = feedById.getJSONObject("currentWork");
-                        if (!Check.isNull(currentWork)) {
-                            Long timestamp = currentWork.getLong("timestamp");
-                            return new java.util.Date(timestamp);
-
-                        }
-
-                    }
-
-                }
-
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            log.error("获取时间错误");
-        }
-
-
-        return null;
-    }
-}

+ 36 - 35
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -222,11 +222,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 var kuaiShouVideoGet = JSONObject.toJavaObject(detailJson, KuaiShouVideoGet.class);
                 kuaiShouVideoGet.setId(token.getAccountId() + kuaiShouVideoGet.getPhotoId());
 
-                Date videoTime = videoTimeService.getVideoTime(kuaiShouVideoGet.getPhotoId(), token.getAccountId());
-                if (!Check.isNull(videoTime)) {
-                    kuaiShouVideoGet.setUploadDate(videoTime);
-                }
-
                 kuaiShouVideoGet.setAccountId(token.getAccountId());
                 kuaiShouVideoGet.setStatDate(DateUtils.parseDate(statDate, "yyyy-MM-dd"));
                 kuaiShouVideoGet.setUpdateTime(new Date());
@@ -2861,18 +2856,22 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
      * @param page
      */
     @Autowired
-    private IKuaiShouVideoTimeService videoTimeService;
+    private IKuaiShouVideoGetService videoGetService;
 
     @Override
-    public void getSuZaoList(String token, Long accountId, int page) {
-        String url = "https://ad.e.kuaishou.com/rest/openapi/v1/file/ad/video/su_zao/list";
+    public void getSuZaoList(String token, Long accountId, int page, String startDate, String endDate) {
+        String url = "https://ad.e.kuaishou.com/rest/openapi/v1/ad_creator/video/list";
         Map<String, String> headers = new HashMap<String, String>();
         headers.put("Content-Type", "application/json");
         headers.put("Access-Token", token);
         Map<String, Object> param = new HashMap<String, Object>();
         param.put("advertiser_id", accountId);
         param.put("page", page);
-        param.put("page_size", 500);
+        param.put("page_size", 200);
+        if (!Check.isNull(startDate) && !Check.isNull(startDate)) {
+            param.put("start_date", startDate);
+            param.put("end_date", endDate);
+        }
         String result = HttpUtils.httpPostRequest(url, param, headers);
         JSONObject resultJson = JSONObject.parseObject(result);
         Integer code = resultJson.getInteger("code");
@@ -2883,40 +2882,42 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         }
         JSONObject dataJson = resultJson.getJSONObject("data");
         if (!Check.isNull(dataJson)) {
-            Integer total_count = dataJson.getInteger("total_count");
-           /* if (total_count > 2000) {
-                return;
-            }*/
             JSONArray details = dataJson.getJSONArray("details");
             if (Check.isNull(details)) {
                 return;
             }
             for (int i = 0; i < details.size(); i++) {
-                var detailJson = details.getJSONObject(i);
-
-                KuaiShouVideoGet byId = kuaiShouVideoGetService.getById(accountId + detailJson.getString("photo_id"));
-                if (!Check.isNull(byId)) {
-                    continue;
-                }
-                var kuaiShouVideoGet = JSONObject.toJavaObject(detailJson, KuaiShouVideoGet.class);
-               /* Date videoTime = videoTimeService.getVideoTime(kuaiShouVideoGet.getPhotoId(), accountId);
-                if (!Check.isNull(videoTime)) {
-                    kuaiShouVideoGet.setUploadDate(videoTime);
-                }*/
-                kuaiShouVideoGet.setStatDate(new Date());
-                kuaiShouVideoGet.setAccountId(accountId);
-                kuaiShouVideoGet.setId(accountId + kuaiShouVideoGet.getPhotoId());
-                kuaiShouVideoGet.setCreateTime(new Date());
-                kuaiShouVideoGet.setUpdateTime(new Date());
-                Integer type = MaterialEnum.getTypeBySize(kuaiShouVideoGet.getWidth(), kuaiShouVideoGet.getHeight());
-                if (!Check.isNull(type)) {
-                    kuaiShouVideoGet.setMaterialType(type);
+                JSONObject jsonObject = details.getJSONObject(i);
+                if (!Check.isNull(jsonObject)) {
+                    KuaiShouVideoGet kuaiShouVideoGet = new KuaiShouVideoGet();
+                    Long photo_id = jsonObject.getLong("photo_id");
+                    kuaiShouVideoGet.setId(accountId + photo_id + "");
+                    kuaiShouVideoGet.setPhotoId(String.valueOf(photo_id));
+                    kuaiShouVideoGet.setUrl(jsonObject.getString("watermark_url"));
+                    kuaiShouVideoGet.setWidth(jsonObject.getInteger("width"));
+                    kuaiShouVideoGet.setHeight(jsonObject.getInteger("height"));
+                    kuaiShouVideoGet.setCoverUrl(jsonObject.getString("cover_url"));
+                    kuaiShouVideoGet.setAccountId(accountId);
+                    String md5 = jsonObject.getString("md5");
+                    kuaiShouVideoGet.setSignature(md5);
+                    kuaiShouVideoGet.setStatDate(jsonObject.getDate("sync_date"));
+                    kuaiShouVideoGet.setChannelType(1);
+                    Integer type = MaterialEnum.getTypeBySize(kuaiShouVideoGet.getWidth(), kuaiShouVideoGet.getHeight());
+                    if (!Check.isNull(type)) {
+                        kuaiShouVideoGet.setMaterialType(type);
+                    }
+                    kuaiShouVideoGetService.saveOrUpdate(kuaiShouVideoGet);
+                    Thread thread = new Thread() {
+                        @Override
+                        public void run() {
+                            videoGetService.getKeyFrame(token, accountId, md5, String.valueOf(photo_id));
+                        }
+                    };
+                    thread.start();
                 }
-                kuaiShouVideoGet.setChannelType(1);
-                kuaiShouVideoGetService.saveOrUpdate(kuaiShouVideoGet);
             }
         }
-        getSuZaoList(token, accountId, page + 1);
+        getSuZaoList(token, accountId, page + 1, startDate, endDate);
 
     }