Quellcode durchsuchen

快手日报 时报kuaishou_account_report_hourly kuaishou_account_report_daily

zhaoxian vor 1 Jahr
Ursprung
Commit
7a9d858f32

+ 164 - 33
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/controller/KuaishouController.java

@@ -1,6 +1,16 @@
 package cn.com.ctop.job.kuaishou.controller;
 
-import cn.com.ctop.job.kuaishou.data.service.*;
+import cn.com.ctop.job.kuaishou.data.service.IAdUnitReportService;
+import cn.com.ctop.job.kuaishou.data.service.IKuaishouAccountReportDailyService;
+import cn.com.ctop.job.kuaishou.data.service.IKuaishouAccountReportHourlyService;
+import cn.com.ctop.job.kuaishou.data.service.IKuaishouCampaignReportDailyService;
+import cn.com.ctop.job.kuaishou.data.service.IKuaishouMaterialVideoReportDailyService;
+import cn.com.ctop.job.kuaishou.data.service.IKuaishouUnitAudienceAgeReportDailyService;
+import cn.com.ctop.job.kuaishou.data.service.IKuaishouUnitReportDailyService;
+import cn.com.ctop.job.kuaishou.data.service.IKuaishouUnitReportHourlyService;
+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.service.impl.AdUnitReportServiceImpl;
 import cn.com.ctop.job.kuaishou.data.utils.Check;
 import cn.com.ctop.job.kuaishou.data.utils.DateUtils;
 import com.alibaba.fastjson.JSONArray;
@@ -8,12 +18,21 @@ import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * zian Y
@@ -37,6 +56,10 @@ public class KuaishouController {
     @Autowired
     private IKuaishouUnitReportHourlyService unitReportHourlyService;
 
+    @Autowired
+    private IKuaishouAccountReportDailyService kuaishouAccountReportDailyService;
+
+    private static ExecutorService dailyExecutorService = Executors.newFixedThreadPool(10);
 
 
     @ApiOperation(value = "根据账户获取视频素材-账户下全部视频素材", notes = "根据账户获取视频素材-账户下全部视频素材")
@@ -56,37 +79,42 @@ public class KuaishouController {
 
     @ApiOperation(value = "根据账户获取视频素材-账户下全部视频素材", notes = "根据账户获取视频素材-账户下全部视频素材")
     @GetMapping(value = "/KuaishouUnitAudienceReport")
-    public void KuaishouUnitAudienceReportJob(String startDate, String endDate) throws Exception {
-        List<String> allDates = DateUtils.getAllDatesOfTwoTimes(startDate, endDate);
-
-        for (String date : allDates) {
-            List<Long> accountIds = unitReportDailyService.selectAccountIdsByTime(date);
-            for (Long accountId : accountIds) {
-                String token = tokenService.getByAccountId(accountId);
-                if (Check.isNull(token)) {
-                    continue;
-                }
-                //广告计划 ID 集
-                List<JSONObject> campaignArray = unitReportDailyService.selectPlanIdsByAccountIdAndTime(accountId, date);
-                if (Check.isNull(campaignArray)) {
-                    log.error("未查询到计划ID");
+    public void KuaishouUnitAudienceReportJob(String date) throws Exception {
+
+        List<JSONObject> tokens = tokenService.getByProjectId(458L);    //淘特项目
+//        String date = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.getNowDate("yyyy-MM-dd"), -1);
+        Date enDate = DateUtils.addDay(DateUtils.getNowDate(), -1);
+        for (JSONObject t : tokens) {
+            Long accountId = t.getLong("accountId");
+            String token = t.getString("accessToken");
+            if (Check.isNull(token)) {
+                log.error("此账户未获取到相关token,accountId:{}", accountId);
+                continue;
+            }
+            //过期跳过
+            if (enDate.after(t.getDate("accessTokenExpiresIn"))) {
+                continue;
+            }
+            //广告计划 ID 集
+            List<JSONObject> campaignArray = unitReportDailyService.selectPlanIdsByAccountIdAndTime(accountId, date);
+            if (Check.isNull(campaignArray)) {
+                log.error("未查询到计划ID");
+                continue;
+            }
+            //广告组 ID 集
+            for (JSONObject obj : campaignArray) {
+                Long campaignId = obj.getLong("campaignId");
+                List<Long> unitIds = unitReportDailyService.selectUnitIdsByAccountIdAndTime(accountId, campaignId, date);
+                if (Check.isNull(unitIds)) {
                     continue;
                 }
-                //广告组 ID 集
-                for (JSONObject obj : campaignArray) {
-                    Long campaignId = obj.getLong("campaignId");
-                    List<Long> unitIds = unitReportDailyService.selectUnitIdsByAccountIdAndTime(accountId, campaignId, date);
-                    if (Check.isNull(unitIds)) {
-                        continue;
-                    }
-                    if (unitIds.size() > 59) {
-                        List<List<Long>> unitIdArray = Lists.partition(unitIds, 59);
-                        for (List<Long> list : unitIdArray) {
-                            unitReportDailyService.standardCrowdAnalysisReport(accountId, token, date, campaignId, list);
-                        }
-                    } else {
-                        unitReportDailyService.standardCrowdAnalysisReport(accountId, token, date, campaignId, unitIds);
+                if (unitIds.size() > 59) {
+                    List<List<Long>> unitIdArray = Lists.partition(unitIds, 59);
+                    for (List<Long> list : unitIdArray) {
+                        unitReportDailyService.standardCrowdAnalysisReport(accountId, token, date, campaignId, list);
                     }
+                } else {
+                    unitReportDailyService.standardCrowdAnalysisReport(accountId, token, date, campaignId, unitIds);
                 }
             }
         }
@@ -94,16 +122,119 @@ public class KuaishouController {
 
     @ApiOperation(value = "获取快手当天-广告组信息、组时报", notes = "更新快手当天-广告组信息、组时报")
     @GetMapping(value = "/getKuaishouAdUnitRealTime")
-    public void getKuaishouVideoByAccountId(@RequestParam(name="accountId") long accountId) {
+    public void getKuaishouVideoByAccountId(@RequestParam(name = "accountId") long accountId) {
         String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
         String token = tokenService.getByAccountId(accountId);
         //更新 组
-        adUnitReportService.getAdUnitReport(accountId,token, nowDate, nowDate, 1);
+        adUnitReportService.getAdUnitReport(accountId, token, nowDate, nowDate, 1);
         //更新 组时报
         unitReportHourlyService.getUnitReportHour(accountId, token, nowDate, nowDate, 1);
     }
 
 
+    @Autowired
+    private IKuaishouUnitReportDailyService unitReportDailyService1;
+    @Autowired
+    private IKuaishouMaterialVideoReportDailyService videoReportDailyService;
+
+    @Autowired
+    private IKuaishouCampaignReportDailyService campaignReportDailyService;
+    @Autowired
+    private AdUnitReportServiceImpl reportService;
+
+
+    @Autowired
+    private IKuaishouUnitReportDailyService unitReportDailyService2;
+
+    @Autowired
+    private IKuaishouAccountReportHourlyService kuaishouAccountReportHourlyService;
+
+    @GetMapping(value = "/testOne")
+    public void testOne(@RequestParam(name = "accountId") long accountId) throws Exception {
+//        String token = tokenService.getByAccountId(accountId);
+//        List<String> list = new ArrayList<>();
+//        list.add("2023-11-10");
+//        list.add("2023-08-26");
+//        list.add("2023-08-27");
+//        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+//        String date = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -4);
+//        for (String s : list) {
+//            unitReportDailyService2.getUnitReportDaily(accountId, token, s, s, 1);
+        reportService.getAgentReport();
+//            campaignReportDailyService.getCampaignReportDaily(accountId, token, s, s, 1);
+//        }
+
+//        videoReportDailyService.getImageReportDaily(accountId, token, date, nowDate, 1);
+
+//        videoListService.getVideosByAccountId(accountId, "2023-11-01", "2023-11-09");
+
+
+    }
+
+    @GetMapping(value = "/testAllDate")
+    public void testAllDate() throws Exception {
+
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+
+        String yesterda = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+
+        List<Long> accountIds = tokenService.getAllAccountIds();
+        for (Long accountId : accountIds) {
+            String token = tokenService.getByAccountId(accountId);
+            dailyExecutorService.submit(
+                    new Runnable() {
+                        @SneakyThrows
+                        @Override
+                        public void run() {
+                            Thread.sleep(500);
+                            kuaishouAccountReportDailyService
+                                    .getAdvertiserReportDaily(accountId, token, "2024-02-16", "2024-02-17", 1);
+
+                        }
+                    });
+        }
+    }
+
+    @GetMapping(value = "/testAllHour")
+    public void testAllHour() throws Exception {
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String yesterda = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+
+        //获取 两个日期之间的所有 日期
+        List<String> dates = DateUtils.getAllDatesOfTwoTimes("2024-02-15", nowDate);
+
+        List<Long> accountIds = tokenService.getAllAccountIds();
 
+        for (String date : dates) {
+            for (Long accountId : accountIds) {
+                String token = tokenService.getByAccountId(accountId);
+                dailyExecutorService.submit(
+                        new Runnable() {
+                            @SneakyThrows
+                            @Override
+                            public void run() {
+                                Thread.sleep(500);
+                                kuaishouAccountReportHourlyService
+                                        .getAdvertiserReportHour(accountId, token, date, date, 1);
+                            }
+                        });
+            }
+        }
+    }
+
+
+    /**
+     * 获取原生效果数据整体概览接口(数据概览、分日转化数据分布、转化漏斗)
+     *
+     * @throws Exception
+     */
+    @GetMapping(value = "effectNativeChartReport")
+    public void effectNativeChartReport(Long accountId) throws Exception {
+        String token = tokenService.getByAccountId(Long.valueOf(accountId));
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String beforeYesterday = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -2);
+
+        kuaishouAccountReportDailyService.effectNativeChartReport(accountId, token, beforeYesterday, beforeYesterday);
+    }
 
 }

+ 2 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/mapper/OauthTokenMapper.java

@@ -17,4 +17,6 @@ public interface OauthTokenMapper extends BaseMapper<OauthToken> {
     String getByAccountId(@Param("accountId") Long accountId);
 
     List<JSONObject> getByProjectId(@Param("projectId") Long projectId);
+
+    List<Long> getAllAccountIds();
 }

+ 21 - 15
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/mapper/xml/OauthTokenMapper.xml

@@ -3,30 +3,36 @@
 <mapper namespace="cn.com.ctop.job.kuaishou.data.mapper.OauthTokenMapper">
 
     <select id="getByAccountId" resultType="java.lang.String">
-       SELECT
-       (CASE
-		WHEN
-		t2.access_token IS NOT NULL
-		THEN t2.access_token
-		ELSE
-		t1.access_token
-		END
-		) as 'access_token'
-		FROM
-			`jeecg-boot`.ctop_oauth_token t1
-			LEFT JOIN `jeecg-boot`.ctop_oauth_agent_token t2 ON t1.app_id = t2.app_id
-	WHERE
-	t1.account_id = #{accountId}
+        SELECT (CASE
+                    WHEN
+                        t2.access_token IS NOT NULL
+                        THEN t2.access_token
+                    ELSE
+                        t1.access_token
+            END
+                   ) as 'access_token'
+        FROM `jeecg-boot`.ctop_oauth_token t1
+                 LEFT JOIN `jeecg-boot`.ctop_oauth_agent_token t2 ON t1.app_id = t2.app_id
+        WHERE t1.account_id = #{accountId}
     </select>
 
 
     <select id="getByProjectId" resultType="com.alibaba.fastjson.JSONObject">
         select t1.access_token as 'accessToken',t1.account_id as 'accountId',t1.access_token_expires_in as 'accessTokenExpiresIn'
         from `jeecg-boot`.ctop_oauth_token t1
-        left join `jeecg-boot`.ctop_user_allocation t2
+                 left join `jeecg-boot`.ctop_user_allocation t2
                            on t1.account_id = t2.account_id
         where t2.account_status = 0
           and t2.project_id = #{projectId}
         group by t1.account_id
     </select>
+
+
+    <select id="getAllAccountIds" resultType="Long">
+        SELECT account_id
+        FROM `jeecg-boot`.ctop_user_allocation
+        WHERE media_id = 2
+          and account_status = 0
+    </select>
+
 </mapper>

+ 2 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/IOauthTokenService.java

@@ -17,4 +17,6 @@ public interface IOauthTokenService extends IService<OauthToken> {
   String getByAccountId(Long accountId);
 
     List<JSONObject> getByProjectId(Long projectId);
+
+  List<Long> getAllAccountIds();
 }

+ 5 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/impl/OauthTokenServiceImpl.java

@@ -30,4 +30,9 @@ public class OauthTokenServiceImpl extends ServiceImpl<OauthTokenMapper, OauthTo
   public List<JSONObject> getByProjectId(Long projectId) {
     return tokenMapper.getByProjectId(projectId);
   }
+
+  @Override
+  public List<Long> getAllAccountIds() {
+    return tokenMapper.getAllAccountIds();
+  }
 }

+ 1 - 1
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/utils/HttpUtils.java

@@ -136,7 +136,7 @@ public class HttpUtils {
       }
     } catch (Exception e) {
       e.printStackTrace();
-      log.error(e.getMessage());
+      log.error("httpPostRequest接口异常:"+e.getMessage());
     }
     return strReturn;
   }