Ver código fonte

获取时间

yumeng 5 anos atrás
pai
commit
c9403bdca1

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

@@ -7,10 +7,8 @@ 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.service.IKuaiShouCampaignService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+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;
 import cn.com.ctop.toutiao.modules.report.service.IBytedancePlanDailyReportService;
@@ -94,6 +92,48 @@ public class TestController {
 
     @Autowired
     private IMaterialCutFrameService cutFrameService;
+    @Autowired
+    IKuaiShouVideoGetService videoGetService;
+    @Autowired
+    private IKuaiShouVideoTimeService timeService;
+
+
+    @GetMapping(value = "/getVideoTime")
+    public void getVideoTime() throws InterruptedException {
+        QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("channel_type", 0);
+        List<KuaiShouVideoGet> list = videoGetService.list(queryWrapper);
+        for (KuaiShouVideoGet video : list) {
+            Date date = timeService.getVideoTime(video.getPhotoId(), video.getAccountId());
+            if (Check.isNull(date)) {
+                continue;
+            }
+            video.setUploadDate(date);
+            videoGetService.updateById(video);
+            Thread.sleep(100);
+
+        }
+
+    }
+
+
+    @GetMapping(value = "/getSuZhao")
+    public void getSuZhao() throws InterruptedException {
+        QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("channel_type", 1);
+        List<KuaiShouVideoGet> list = videoGetService.list(queryWrapper);
+        for (KuaiShouVideoGet video : list) {
+            Date date = timeService.getVideoTime(video.getPhotoId(), video.getAccountId());
+            if (Check.isNull(date)) {
+                continue;
+            }
+            video.setUploadDate(date);
+            videoGetService.updateById(video);
+            Thread.sleep(100);
+
+        }
+
+    }
 
 
     @GetMapping(value = "/getAccountList")

Diferenças do arquivo suprimidas por serem muito extensas
+ 2 - 2
module-common/src/main/java/cn/com/ctop/common/module/utils/HttpUtils.java


+ 2 - 0
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadServiceImpl.java

@@ -35,6 +35,7 @@ import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
 
 import java.io.File;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
@@ -224,6 +225,7 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
                                             String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
                                             videoGet.setStatDate(DateUtils.parseDate(nowDate, "yyyy-MM-dd"));
                                             videoGet.setCoverUrl(materialInfo.getUrl() + "?x-oss-process=video/snapshot,t_10000,m_fast");
+                                            videoGet.setUploadDate(new Date());
                                             kuaiShouVideoGetService.saveOrUpdate(videoGet);
                                             materialUploadImageService.uploadImage(videoGet.getSignature(), accountId, ctopOauthToken.getAccessToken());
 

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

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

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

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

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

@@ -0,0 +1,64 @@
+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;
+    }
+}

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

@@ -215,8 +215,16 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             }
             for (int i = 0; i < details.size(); i++) {
                 var detailJson = details.getJSONObject(i);
+                KuaiShouVideoGet byId = kuaiShouVideoGetService.getById(token.getAccountId() + detailJson.getString("photo_id"));
+                if (!Check.isNull(byId)) {
+                    continue;
+                }
                 var kuaiShouVideoGet = JSONObject.toJavaObject(detailJson, KuaiShouVideoGet.class);
                 kuaiShouVideoGet.setId(token.getAccountId() + kuaiShouVideoGet.getPhotoId());
+
+                Date videoTime = videoTimeService.getVideoTime(kuaiShouVideoGet.getPhotoId(), token.getAccountId());
+                kuaiShouVideoGet.setUploadDate(videoTime);
+
                 kuaiShouVideoGet.setAccountId(token.getAccountId());
                 kuaiShouVideoGet.setStatDate(DateUtils.parseDate(statDate, "yyyy-MM-dd"));
                 kuaiShouVideoGet.setUpdateTime(new Date());
@@ -2842,6 +2850,9 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
      * @param accountId
      * @param page
      */
+    @Autowired
+    private IKuaiShouVideoTimeService videoTimeService;
+
     @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";
@@ -2872,7 +2883,14 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             }
             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);
+                kuaiShouVideoGet.setUploadDate(videoTime);
                 kuaiShouVideoGet.setAccountId(accountId);
                 kuaiShouVideoGet.setId(accountId + kuaiShouVideoGet.getPhotoId());
                 kuaiShouVideoGet.setCreateTime(new Date());