浏览代码

Merge remote-tracking branch 'origin/master'

zhaoxian 2 年之前
父节点
当前提交
2bad76b7f9

+ 1 - 1
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/IAdUnitReportService.java

@@ -26,7 +26,7 @@ public interface IAdUnitReportService{
 
     void crowdAnalysisReport(Long advertiserId, String accessToken, String date,  List<Long> campaignIds,List<Long> unitIds, List<String> reportDims,Integer page);
 
-    void getKuaishouDailyFlows(Long advertiserId, String accessToken,int page);
+    void getKuaishouDailyFlows(Long advertiserId, String accessToken,String startDate,String endDate,int page);
 
     void getKuaishouDailyFundGet(Long advertiserId,String accessToken);
 }

+ 15 - 20
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/impl/AdUnitReportServiceImpl.java

@@ -63,28 +63,21 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
      */
     @Override
     public void getAdUnitReport(Long advertiserId, String accessToken, String startDate, String endDate, int page) {
-        log.info("accountId:=={}=====获取广告组数据信息====page--{}===》》》》", advertiserId, page);
-        Integer page_size = 500;
-
-        Map<String, String> headers = new HashMap<>();
-        headers.put("Access-Token", accessToken);
-        Map<String, Object> param = new HashMap<>();
+        JSONObject param = new JSONObject();
         param.put("advertiser_id", advertiserId);
-
-        if (!Check.isNull(startDate)) {
+        param.put("page_size", 500);
+        param.put("page", page);
+        if (startDate != null && endDate != null) {
             param.put("start_date", startDate);
-        }
-        if (!Check.isNull(endDate)) {
             param.put("end_date", endDate);
         }
-        param.put("page_size", page_size);
-        param.put("page", page);
-
-
-        String result = HttpUtils.httpPostRequest(postUrl + KuaishouConstant.AD_UNIT_LIST, param, headers);
-       // System.err.println(result);
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json");
 
+        String result = HttpUtils.kuaiShouhttpPostRequest("https://ad.e.kuaishou.com/rest/openapi/v1/ad_unit/list", param.toJSONString(), headers);
         JSONObject resultJson = JSONObject.parseObject(result);
+
         if (Check.isNull(resultJson)) {
             log.info("accountId:=={}=====广告组数据信息====暂无====》》》》", advertiserId);
             return;
@@ -112,12 +105,12 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
 
         if (!Check.isNull(ksAdUnitList)) {
             adUnitReportMapper.replaceBatchKsAdUnit(ksAdUnitList);
-            log.info("组数据添加成功,accountId:{},条数:{}",advertiserId,ksAdUnitList.size());
+            log.info("组数据添加成功,accountId:{},条数:{}", advertiserId, ksAdUnitList.size());
         }
 
         //是否有下一页
         Boolean toGet = true;
-        if (details.size() < page_size) {
+        if (details.size() < page) {
             toGet = false;
         }
         if (toGet) {
@@ -457,7 +450,7 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
      * @param page
      */
     @Override
-    public void getKuaishouDailyFlows(Long advertiserId, String accessToken, int page) {
+    public void getKuaishouDailyFlows(Long advertiserId, String accessToken, String startDate, String endDate, int page) {
         log.info("获取账户流水========,账户id:{},page--{}", advertiserId, page);
         Integer page_size = 500;
         String url = postUrl + KuaishouConstant.FUND_DAILY_FLOWS;
@@ -467,6 +460,8 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
         param.put("advertiser_id", advertiserId);
         param.put("page_size", page_size);
         param.put("page", page);
+        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");
@@ -495,7 +490,7 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
             toGet = false;
         }
         if (toGet) {
-            getKuaishouDailyFlows(advertiserId, accessToken, page + 1);
+            getKuaishouDailyFlows(advertiserId, accessToken, startDate, endDate, page + 1);
         } else {
             log.info("账户流水========获取完成:accountId:{}", advertiserId);
         }

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

@@ -69,6 +69,39 @@ public class HttpUtils {
     return HttpClients.createDefault();
   }
 
+
+  public static String kuaiShouhttpPostRequest(String url, String body, Map<String, String> headers) {
+    HttpClient httpClient = createSslClientDefault();
+    String strReturn = "";
+    try {
+      HttpPost httppost = new HttpPost(url);
+      RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(120000).setConnectTimeout(120000).build();
+      httppost.setConfig(requestConfig);
+      if (!Check.isNullMap(headers)) {
+        for (String key : headers.keySet()) {
+          httppost.setHeader(key, headers.get(key));
+        }
+      }
+
+      httppost.setHeader("User-Agent", USER_AGENT);
+      if (!Check.isNull(body)) {
+        httppost.setEntity(new StringEntity(body, Charset.forName("UTF-8")));
+      }
+      HttpEntity respentity;
+      HttpResponse response = httpClient.execute(httppost);
+      int statusCode = response.getStatusLine().getStatusCode();
+      if (statusCode == HttpStatus.SC_OK) {
+        respentity = response.getEntity();
+        strReturn = EntityUtils.toString(respentity);
+        return strReturn;
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      log.error(e.getMessage());
+    }
+    return strReturn;
+  }
+
   public static String httpPostRequest(String url, Map<String, Object> param, Map<String, String> headers) {
 
     HttpClient httpClient = createSslClientDefault();

+ 5 - 1
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/AdUnitReportJob.java

@@ -277,11 +277,15 @@ public class AdUnitReportJob {
             log.error("此账户未获取到相关token,accountId:{}", param);
             return;
         }
+
+        String endDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String startDate = DateUtils.getAnotherDay("yyyy-MM-dd", endDate, -2);
+
         dailyExecutorService.submit(
                 new Runnable() {
                     @Override
                     public void run() {
-                        adUnitReportService.getKuaishouDailyFlows(Long.valueOf(param), token, 1);
+                        adUnitReportService.getKuaishouDailyFlows(Long.valueOf(param), token,startDate, endDate,1);
                     }
                 });
     }