yumeng hace 5 años
padre
commit
e2b4efd632

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

@@ -13,6 +13,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.entity.KuaiShouCampaign;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService;
@@ -161,31 +163,38 @@ public class TestController {
     }
 
 
-    @GetMapping(value = "/gerCreativeReport")
-    public void gerCreativeReport() {
+    @Autowired
+    private IKuaiShouCampaignService campaignService;
+
+    @GetMapping(value = "/getCreativeReportByAccount")
+    public void gerCreativeReportByAccount(Long accountId, String startDateStr, String endDateStr) {
         Thread thread = new Thread() {
             @SneakyThrows
             @Override
             public void run() {
                 SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
-                Date startDate = sim.parse("2020-02-10");
-                Date endDate = sim.parse("2020-02-11");
+                Date startDate = sim.parse(startDateStr);
+                Date endDate = sim.parse(endDateStr);
                 //1:查询当日数据
                 //executorService = Executors.newFixedThreadPool(3);
                 QueryWrapper<CtopOauthToken> oauthTokenQueryWrapper = new QueryWrapper<>();
                 oauthTokenQueryWrapper.eq("media_id", 2);
-                List<CtopOauthToken> ctopOauthTokens = oauthTokenMapper.selectList(oauthTokenQueryWrapper);
-                for (CtopOauthToken token : ctopOauthTokens) {
-                    executorService.submit(new Runnable() {
-                        @Override
-                        public void run() {
-                            System.err.println("创意报表accountId:" + token.getAccountId());
-                            kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token, startDate, endDate);
-                        }
-                    });
+                oauthTokenQueryWrapper.eq("account_id", accountId);
+                CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(oauthTokenQueryWrapper);
+
+                System.err.println("创意报表accountId:" + ctopOauthToken.getAccountId());
+                QueryWrapper<KuaiShouCampaign> campaignQueryWrapper = new QueryWrapper<>();
+                campaignQueryWrapper.eq("account_id", accountId);
+                List<KuaiShouCampaign> list = campaignService.list(campaignQueryWrapper);
+                if (!Check.isNull(list)) {
+                    for (KuaiShouCampaign campaign : list) {
+                        kuaishouInterfaceService.getAdvertiserCreativeReportDailyV2(campaign.getCampaignId(), ctopOauthToken, startDate, endDate);
 
+                    }
 
                 }
+
+
             }
         };
         thread.start();

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

@@ -352,6 +352,7 @@ public interface IKuaishouInterfaceService {
     void getCreative(String token, Long advertiserId, Long creativeId);
 
 
+    void getAdvertiserCreativeReportDailyV2(Long campaignId, CtopOauthToken ctopOauthToken, Date startDate, Date endDate);
 }
 
 

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

@@ -3723,5 +3723,66 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         return null;
     }
 
+    @Override
+    public void getAdvertiserCreativeReportDailyV2(Long campaignId, CtopOauthToken token, Date startDate, Date endDate) {
+        getAdvertiserCreativeReportDailyByPageV2(campaignId, token, startDate, endDate, 1);
+    }
+
+    private void getAdvertiserCreativeReportDailyByPageV2(Long campaignId, CtopOauthToken token, Date startDate, Date endDate, int page) {
+        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
+        Map<String, String> headers = new HashMap<String, String>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token.getAccessToken());
+        Map<String, Object> param = new HashMap<String, Object>();
+        if (!Check.isNull(startDate)) {
+            param.put("start_date", DateUtils.formatDate(startDate));
+        }
+        if (!Check.isNull(endDate)) {
+            param.put("end_date", DateUtils.formatDate(endDate));
+        }
+
+        JSONArray jsonArray = new JSONArray();
+        jsonArray.add(campaignId);
+        param.put("campaign_ids", jsonArray);
+        param.put("advertiser_id", token.getAccountId());
+        param.put("temporal_granularity", "DAILY");
+        param.put("page_size", 500);
+        param.put("page", page);
+
+        String result = HttpUtils.httpPostRequest(url, param, headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        Integer code = resultJson.getInteger("code");
+        String message = resultJson.getString("message");
+        if (null == code || code != 0) {
+            log.error("获取快手广告创意分天报表异常:{},accountId:{}", message, token.getAccountId());
+            return;
+        }
+        JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
+        if (null == details || details.size() <= 0) {
+            log.info("快手广告创意分天报表信息为空=》accountId:{}", token.getAccountId());
+            return;
+        }
+        for (int i = 0; i < details.size(); i++) {
+            var detailJson = details.getJSONObject(i);
+            var show = detailJson.getLong("show");
+            detailJson.put("photo_show", show);
+            var like = detailJson.getLong("like");
+            detailJson.put("photo_like", like);
+            var creative = JSONObject.toJavaObject(detailJson, KuaishouReportDailyCreative.class);
+            creative.setAccountId(token.getAccountId());
+            creative.setId("" + creative.getAccountId() + creative.getCreativeId() + creative.getStatDate());
+
+            // 取得MD5
+            String signature = creativeService.getCodeByCreativeId(creative.getCreativeId());
+            if (!Check.isNull(signature)) {
+                creative.setSignature(signature);
+            }
+            KuaishouReportDailyCreativeStatistic statistic = setDailyStatistic(creative, token);
+            dailyCreativeStatisticService.saveOrUpdate(statistic);
+            dailyCreativeService.saveOrUpdate(creative);
+        }
+        getAdvertiserCreativeReportDailyByPageV2(campaignId, token, startDate, endDate, page + 1);
+    }
+
 
 }