Przeglądaj źródła

巨量产品数据报表

huangpingkang 1 rok temu
rodzic
commit
7198c96d3e

+ 17 - 8
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/BytedanceController.java

@@ -3,15 +3,16 @@ package cn.com.ctop.job.bytedance.controller;
 import cn.com.ctop.job.bytedance.data.service.IAdminAdvertiserListService;
 import cn.com.ctop.job.bytedance.data.service.IBytedanceProductReportService;
 import cn.com.ctop.job.bytedance.data.utils.Check;
-import cn.com.ctop.job.bytedance.data.utils.DateUtils;
 import com.alibaba.fastjson.JSONObject;
 import io.swagger.annotations.Api;
 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.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -53,13 +54,21 @@ public class BytedanceController {
     }
 
     @GetMapping("/productData")
-    public void productData(String param) {
-        String[] s = param.split("_");
-        Long advertiserId = Long.valueOf(s[0]);
-        String accessToken = s[1];
-        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
-        String data = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
-        productReportService.getBytedanceProductDailyReport(advertiserId, accessToken, data, data, 1, null, 1, null);
+    public void productData(@RequestParam(required = false) Long advertiserId, String startDate, String endDate) {
+        List<JSONObject> costAccount = productReportService.getCostAccount(advertiserId, startDate, endDate);
+        for (JSONObject jsonObject : costAccount) {
+            Long adverId = jsonObject.getLong("advertiserId");
+            String accessToken = jsonObject.getString("accessToken");
+
+            dailyRetrExecutorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    if (!Check.isNull(accessToken)) {
+                        productReportService.getBytedanceProductDailyReport(adverId, accessToken, startDate, endDate, 1, null, 1, null);
+                    }
+                }
+            });
+        }
 
     }
 

+ 4 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/BytedanceProductReportMapper.java

@@ -2,9 +2,13 @@ package cn.com.ctop.job.bytedance.data.mapper;
 
 
 import cn.com.ctop.job.bytedance.data.entity.BytedanceProductReportDaily;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
 public interface BytedanceProductReportMapper {
+    List<JSONObject> queryCostAccount(@Param("advertiserId") Long advertiserId, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
     void replaceProductReportDailies(List<BytedanceProductReportDaily> reports);
 }

+ 13 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/BytedanceProductReportMapper.xml

@@ -1,6 +1,19 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="cn.com.ctop.job.bytedance.data.mapper.BytedanceProductReportMapper">
+    <select id="queryCostAccount" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.advertiser_id AS advertiserId, t3.access_token AS accessToken
+        FROM (
+            select advertiser_id from media_api.bytedance_promoter_report_hour
+            where stat_time_day >= ${startDate} and stat_time_day &lt;= ${endDate}
+            <if test="advertiserId != null">
+                and advertiser_id = ${advertiserId}
+            </if>
+            group by 1
+        ) t1
+        LEFT JOIN deepthink.bytedance_advertiser_list t2 ON t1.advertiser_id = t2.advertiser_id
+        LEFT JOIN deepthink.bytedance_auth_list t3 ON t2.admin_advertiser_id = t3.admin_advertiser_id
+    </select>
 
     <insert id="replaceProductReportDailies">
         replace into media_api.bytedance_product_report_daily (

+ 6 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IBytedanceProductReportService.java

@@ -1,6 +1,12 @@
 package cn.com.ctop.job.bytedance.data.service;
 
+import com.alibaba.fastjson.JSONObject;
+
+import java.util.List;
+
 public interface IBytedanceProductReportService {
     void getBytedanceProductDailyReport(Long advertiserId, String accessToken, String startDate, String endDate, Integer page,
                                         Long errorId, Integer isLog, Integer isSend);
+
+    List<JSONObject> getCostAccount(Long advertiserId, String startDate, String endDate);
 }

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

@@ -106,6 +106,11 @@ public class BytedanceProductReportServiceImpl implements IBytedanceProductRepor
         }
     }
 
+    @Override
+    public List<JSONObject> getCostAccount(Long advertiserId, String startDate, String endDate) {
+        return productReportMapper.queryCostAccount(advertiserId, startDate.replace("-", ""), endDate.replace("-", ""));
+    }
+
     private void insertErrorLog(Integer isLog, Long advertiserId, String startDate, String endDate) {
         if (isLog != null && 1 == isLog) {
             BytedanceErrorLog errorInfo = new BytedanceErrorLog();