Przeglądaj źródła

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	pom.xml
syh 5 lat temu
rodzic
commit
d363ae2963

+ 76 - 5
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;
@@ -62,6 +60,9 @@ public class TestController {
     private IMaterialImageInfoService iMaterialImageInfoService;
     @Autowired
     private IBytedanceReportService bytedanceReportService;
+    static ExecutorService executorService = Executors.newFixedThreadPool(10);
+    static ExecutorService videoService = Executors.newFixedThreadPool(5);
+    static ExecutorService suzhaoService = Executors.newFixedThreadPool(5);
 
     @GetMapping(value = "/t")
     public String test() {
@@ -94,6 +95,76 @@ public class TestController {
 
     @Autowired
     private IMaterialCutFrameService cutFrameService;
+    @Autowired
+    IKuaiShouVideoGetService videoGetService;
+    @Autowired
+    private IKuaiShouVideoTimeService timeService;
+
+
+    @GetMapping(value = "/getVideoTime")
+    public void getVideoTime() throws InterruptedException {
+        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);
+                            }
+
+                            try {
+                                Thread.sleep(1000);
+                            } catch (InterruptedException 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();
+
+    }
 
 
     @GetMapping(value = "/getAccountList")
@@ -405,7 +476,7 @@ public class TestController {
         return "Success";
     }
 
-    static ExecutorService executorService = Executors.newFixedThreadPool(10);
+
 
 
     @GetMapping(value = "/gerCreative")

+ 1 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/YardController.java

@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
 
 /**
  * @author yumeng

+ 73 - 0
module-callback/pom.xml

@@ -0,0 +1,73 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.jeecgframework.boot</groupId>
+  <artifactId>module-callback</artifactId>
+  <version>2.0.2</version>
+
+  <name>module-callback</name>
+  <!-- FIXME change it to the project's website -->
+  <url>http://www.example.com</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <maven.compiler.source>1.7</maven.compiler.source>
+    <maven.compiler.target>1.7</maven.compiler.target>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.11</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
+      <plugins>
+        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
+        <plugin>
+          <artifactId>maven-clean-plugin</artifactId>
+          <version>3.1.0</version>
+        </plugin>
+        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
+        <plugin>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>3.0.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.8.0</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.22.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>3.0.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-install-plugin</artifactId>
+          <version>2.5.2</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-deploy-plugin</artifactId>
+          <version>2.8.2</version>
+        </plugin>
+        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
+        <plugin>
+          <artifactId>maven-site-plugin</artifactId>
+          <version>3.7.1</version>
+        </plugin>
+        <plugin>
+          <artifactId>maven-project-info-reports-plugin</artifactId>
+          <version>3.0.0</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>

+ 13 - 0
module-callback/src/main/java/org/jeecgframework/boot/App.java

@@ -0,0 +1,13 @@
+package org.jeecgframework.boot;
+
+/**
+ * Hello world!
+ *
+ */
+public class App 
+{
+    public static void main( String[] args )
+    {
+        System.out.println( "Hello World!" );
+    }
+}

+ 20 - 0
module-callback/src/test/java/org/jeecgframework/boot/AppTest.java

@@ -0,0 +1,20 @@
+package org.jeecgframework.boot;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest 
+{
+    /**
+     * Rigorous Test :-)
+     */
+    @Test
+    public void shouldAnswerWithTrue()
+    {
+        assertTrue( true );
+    }
+}

+ 70 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/HttpUtils.java

@@ -419,6 +419,74 @@ public class HttpUtils {
         return strReturn;
     }
 
+    public static void main(String[] args){
+        String res = HttpUtils.getKuaishouShareUrl("http://yongzhou.s.gifshow.com/i/photo/lwx?userId=1400097524&photoId=5191805968879099278");
+        String path = res.split("\\?")[0];
+        String photoId = path.substring(path.lastIndexOf("/")+1,path.length());
+        path =path.substring(0,path.lastIndexOf("/"));
+        String uid = path.substring(path.lastIndexOf("/")+1,path.length());
+        System.out.println(uid);
+        System.out.println(photoId);
+        res = HttpUtils.postKuaishouVideoUrl("https://live.kuaishou.com/m_graphql",uid,photoId);
+        System.out.println(res);
+    }
+
+    public static String postKuaishouVideoUrl(String url,String uid,String photoId){
+        HttpClient httpClient = createSslClientDefault();
+        String strReturn = "";
+        String paramBody = "{\"operationName\":\"FeedQuery\",\"variables\":{\"principalId\":\""+uid+"\",\"photoId\":\""+photoId+"\"},\"query\":\"query FeedQuery($principalId: String, $photoId: String) {\\n  feedById(principalId: $principalId, photoId: $photoId) {\\n    currentWork {\\n                 timestamp\\n           __typename\\n    }\\n       __typename\\n  }\\n}\\n\"}";
+        try {
+            HttpPost httppost = new HttpPost(url);
+            httppost.setHeader("User-Agent", USER_AGENT);
+            httppost.addHeader("Content-Type", "application/json");
+//            for (String key : headers.keySet()) {
+//                httppost.setHeader(key, headers.get(key));
+//            }
+            httppost.setEntity(new StringEntity(paramBody, Charset.forName("UTF-8")));
+            HttpEntity respentity;
+
+            HttpResponse response = httpClient.execute(httppost);
+            int statusCode = response.getStatusLine().getStatusCode();
+
+            respentity = response.getEntity();
+            strReturn = EntityUtils.toString(respentity);
+            return strReturn;
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage());
+        }
+        return strReturn;
+    }
+    public static String getKuaishouShareUrl(String url){
+        HttpClient httpClient = HttpClientBuilder.create().build();
+        HttpResponse response = null;
+        HttpGet httpGet = new HttpGet(url);
+        httpGet.setConfig(RequestConfig.custom().setRedirectsEnabled(false).build());
+        String result = null;
+        try {
+            httpGet.setHeader("User-Agent", USER_AGENT);
+            httpGet.setHeader("Accept-Encoding", "gzip, deflate, br");
+            httpGet.setHeader("Connection", "keep-alive");
+            httpGet.setHeader("Host", "yongzhou.s.gifshow.com");
+            httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
+            httpGet.setHeader("Upgrade-Insecure-Requests", "1");
+            httpGet.setHeader("Accept-Language", "zh-CN,zh;q=0.9");
+            response = httpClient.execute(httpGet);
+            int statusCode = response.getStatusLine().getStatusCode();
+            System.out.println(statusCode);
+            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
+                String newUrl = response.getFirstHeader("Location").getValue();
+                System.out.println(newUrl);
+                return newUrl;
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
     public static String httpGetRequest(String url) {
         HttpClient httpClient = createSslClientDefault();
         HttpResponse response = null;
@@ -428,8 +496,10 @@ public class HttpUtils {
             httpGet.setHeader("User-Agent", USER_AGENT);
             response = httpClient.execute(httpGet);
             int statusCode = response.getStatusLine().getStatusCode();
+            System.out.println(statusCode);
             if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
                 String newUrl = response.getFirstHeader("Location").getValue();
+                System.out.println(newUrl);
                 return httpGetRequest(newUrl);
             } else if (statusCode == HttpStatus.SC_OK) {
                 BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

+ 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;
+    }
+}

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

@@ -215,8 +215,18 @@ 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());
+                if(!Check.isNull(videoTime)){
+                    kuaiShouVideoGet.setUploadDate(videoTime);
+                }
+
                 kuaiShouVideoGet.setAccountId(token.getAccountId());
                 kuaiShouVideoGet.setStatDate(DateUtils.parseDate(statDate, "yyyy-MM-dd"));
                 kuaiShouVideoGet.setUpdateTime(new Date());
@@ -2842,6 +2852,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 +2885,16 @@ 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);
+                if(!Check.isNull(videoTime)){
+                    kuaiShouVideoGet.setUploadDate(videoTime);
+                }
                 kuaiShouVideoGet.setAccountId(accountId);
                 kuaiShouVideoGet.setId(accountId + kuaiShouVideoGet.getPhotoId());
                 kuaiShouVideoGet.setCreateTime(new Date());

+ 1 - 0
pom.xml

@@ -26,6 +26,7 @@
         <module>jeecg-boot-module-system</module>
         <module>module-job-bytedance</module>
         <module>module-job-kuaishou</module>
+        <module>module-callback</module>
     </modules>
 
     <distributionManagement>