Browse Source

Merge remote-tracking branch 'origin/master'

syh 5 năm trước cách đây
mục cha
commit
6edbbabfca

+ 2 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java

@@ -217,13 +217,13 @@ public class CallbackController {
 
                     //账号绑定
                     bindAccountAuthService.addBindAccount(accountId, KuaishouInterfaceConstant.LOGIN_TYPE_KUAISHOU, advertiserId);
-                    Thread t = new Thread() {
+                   /* Thread t = new Thread() {
                         @Override
                         public void run() {
                             kuaishouInterfaceService.loadKuaishouDataSingle(topOauthToken);
                         }
                     };
-                    t.start();
+                    t.start();*/
                 }
                 return "授权绑定成功";
             }

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

@@ -13,8 +13,12 @@ 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.kuaishou.modules.report.mapper.KuaishouReportDailyCreativeMapper;
+import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyCreativeStatisticMapper;
 import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -161,34 +165,110 @@ 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) {
+                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();
+    }
+
+
+    @Autowired
+    private IUserAllocationService userAllocationService;
+    @Autowired
+    private KuaishouReportDailyCreativeStatisticMapper reportDailyCreativeStatisticMapper;
+
+
+    @Autowired
+    private KuaishouReportDailyCreativeMapper reportDailyCreativeMapper;
+
+    @GetMapping(value = "/getCreativeReportByProjectId")
+    public void getCreativeReportByProjectId(Long projectId) {
+
+        try {
+            Map<String, Object> deleteMap = new HashMap<>();
+            String date = DateUtils.getDate("yyyy-MM-dd");
+            String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", date, -1);
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            Date endDate = simpleDateFormat.parse(anotherDay);
+            QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
+            userAllocationQueryWrapper.eq("project_id", projectId);
+            List<UserAllocation> list = userAllocationService.list(userAllocationQueryWrapper);
+            if (!Check.isNull(list)) {
+                for (UserAllocation allocation : list) {
                     executorService.submit(new Runnable() {
                         @Override
                         public void run() {
-                            System.err.println("创意报表accountId:" + token.getAccountId());
-                            kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token, startDate, endDate);
+                            if (!Check.isNull(allocation)) {
+
+                                QueryWrapper<CtopOauthToken> oauthTokenQueryWrapper = new QueryWrapper<>();
+                                oauthTokenQueryWrapper.eq("media_id", 2);
+                                oauthTokenQueryWrapper.eq("account_id", allocation.getAccountId());
+                                CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(oauthTokenQueryWrapper);
+                                if (!Check.isNull(ctopOauthToken)) {
+                                    deleteMap.put("account_id", allocation.getAccountId());
+                                    deleteMap.put("stat_date", anotherDay);
+                                    reportDailyCreativeStatisticMapper.deleteByMap(deleteMap);
+                                    reportDailyCreativeMapper.deleteByMap(deleteMap);
+
+                                    // 1.计划数据
+                                    kuaishouInterfaceService.getCampaignList(ctopOauthToken, null, null);
+                                    // 2:广告组数据
+                                    kuaishouInterfaceService.getGroupList(ctopOauthToken, null, null);
+                                    // 3:创意数据
+                                    kuaishouInterfaceService.getCreativeList(ctopOauthToken, null, null);
+
+                                    QueryWrapper<KuaiShouCampaign> campaignQueryWrapper = new QueryWrapper<>();
+                                    campaignQueryWrapper.eq("account_id", ctopOauthToken.getAccountId());
+                                    List<KuaiShouCampaign> campaigns = campaignService.list(campaignQueryWrapper);
+                                    if (!Check.isNull(list)) {
+                                        for (KuaiShouCampaign campaign : campaigns) {
+                                            kuaishouInterfaceService.getAdvertiserCreativeReportDailyV2(campaign.getCampaignId(), ctopOauthToken, endDate, endDate);
+                                        }
+                                    }
+                                }
+                            }
+
                         }
                     });
 
 
                 }
             }
-        };
-        thread.start();
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+
     }
 
 
@@ -231,9 +311,11 @@ public class TestController {
             public void run() {
                 try {
                     System.err.println("获取创意,accountId:" + token.getAccountId());
+                    // 1.计划数据
                     kuaishouInterfaceService.getCampaignList(token, null, null);
-                    //1:获取全量广告组数据
+                    // 2:广告组数据
                     kuaishouInterfaceService.getGroupList(token, null, null);
+                    // 3:创意数据
                     kuaishouInterfaceService.getCreativeList(token, null, null);
 
                     Thread.sleep(1 * 200);
@@ -271,8 +353,6 @@ public class TestController {
         thread.start();
     }
 
-    @Autowired
-    private IUserAllocationService userAllocationService;
 
     @Autowired
     private IBytedancePlanDailyReportService planDailyReportService;

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