瀏覽代碼

调整数据拉取

yumeng 4 年之前
父節點
當前提交
f23b006ea8

+ 66 - 36
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -9,6 +9,7 @@ import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateService;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAgentAccount;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouAgentAccountMapper;
@@ -17,7 +18,6 @@ import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataServ
 import cn.com.ctop.toutiao.modules.report.service.IBytedanceFundDailyService;
 import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
 import cn.com.ctop.toutiao.modules.report.service.IReportService;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonNode;
@@ -58,15 +58,40 @@ public class SampleTest {
 
     @Autowired
     private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IByteDanceAdvertiserDataService byteDanceAdvertiserDataService;
+
+    @Autowired
+    private IKuaishouTemplateService kuaishouTemplateService;
+
 
     @Test
     public void loadBytedanceCreativeData() {
-        QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("media_id", 2);
-        List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
-        for (CtopOauthToken token : list) {
-            kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-20", "2020-09-20", "daily");
+
+        List<CtopOauthToken> ctopOauthTokens = tokenService.selectKuaiShouToken();
+        for (CtopOauthToken token : ctopOauthTokens) {
+            kuaishouTemplateService.getTemplateByAccountId(token.getAccountId(), token.getAccessToken(), 1);
         }
+
+
+
+
+       /* Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", "d7048013910d63c434debabb058b9fe4d60e3b6b");
+
+        JSONObject params=new JSONObject();
+        params.put("advertiser_id","1660666858777607");
+        params.put("convert_id","1678604543575044");
+
+
+        JSONObject jsonObject = JSONObject.parseObject(HttpUtils.httpGet("https://ad.oceanengine.com/open_api/2/tools/ad_convert/read/", params, headers));
+        System.err.println(jsonObject);
+
+
+       // JSONObject jsonObject = JSONObject.parseObject(HttpUtils.httpGet(QueryToolUrlConstant.AD_CONVERT_QUERY, params, headers));
+
+        byteDanceAdvertiserDataService.getBytedancePlanList("1660666858777607","d7048013910d63c434debabb058b9fe4d60e3b6b",1,null,"2020-11-12");*/
     }
 
     @Autowired
@@ -126,20 +151,20 @@ public class SampleTest {
 
     @Test
     public void testLoadBytedanceData() {
-        List<UserAllocation>allocations = allocationService.getByParams(273L,null,0);
-        if(null!=allocations&&!allocations.isEmpty()){
-            for(UserAllocation allocation:allocations){
+        List<UserAllocation> allocations = allocationService.getByParams(273L, null, 0);
+        if (null != allocations && !allocations.isEmpty()) {
+            for (UserAllocation allocation : allocations) {
                 CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
                 String startDate = "2020-11-05";
                 String endDate = "2020-11-09";
-                reportService.getAdvertiserPlanReport(token, DateUtils.parseDate(startDate,"yyyy-MM-dd"), DateUtils.parseDate(endDate,"yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+                reportService.getAdvertiserPlanReport(token, DateUtils.parseDate(startDate, "yyyy-MM-dd"), DateUtils.parseDate(endDate, "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
             }
         }
         System.out.println("任务结束");
     }
 
     @Test
-    public void loadBytedancePlanData(){
+    public void loadBytedancePlanData() {
         CtopOauthToken token = tokenService.getTokenByAccountId(100198696723L);
 //        advertiserDataService.getAdvertiserPlan(token, "", null, null);
         Date getDate = DateUtils.addDay(new Date(), 0);
@@ -148,15 +173,16 @@ public class SampleTest {
 
     @Autowired
     private IBytedanceFundDailyService bytedanceFundDailyService;
+
     @Test
     public void loadFoudData() {
         List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
         for (CtopOauthToken token : tokens) {
-            System.out.println(token.getAccountId()+"############################");
-            for(int i=20;i<130;i++){
-                Date date = DateUtils.addDay(new Date(),-i);
-                bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date),1);
-                System.out.println(i+"############################");
+            System.out.println(token.getAccountId() + "############################");
+            for (int i = 20; i < 130; i++) {
+                Date date = DateUtils.addDay(new Date(), -i);
+                bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date), 1);
+                System.out.println(i + "############################");
             }
         }
     }
@@ -168,9 +194,9 @@ public class SampleTest {
      * 测试获取快手图片消耗数据任务
      */
     @Test
-    public void loadKuaishouImageTask(){
+    public void loadKuaishouImageTask() {
         List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
-        for(int i=1;i<130;i++) {
+        for (int i = 1; i < 130; i++) {
             Date getDate = DateUtils.addDay(new Date(), -i);
             String getDateStr = DateUtils.formatDate(getDate);
             tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
@@ -179,14 +205,15 @@ public class SampleTest {
 
     @Autowired
     private IKuaiShouDailyReportTaskService dailyReportTaskService;
+
     /**
      * 测试获取快手图片消耗数据入库
      */
     @Test
-    public void loadKuaishouImageTaskFile(){
+    public void loadKuaishouImageTaskFile() {
         String nowDate = DateUtils.getDate("yyyy-MM-dd");
         List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
-        for(int i=1;i<15;i++){
+        for (int i = 1; i < 15; i++) {
             String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -i);
             tokens.forEach(token -> dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate));
         }
@@ -194,15 +221,15 @@ public class SampleTest {
     }
 
     @Test
-    public void testLoadBytedanceImageData(){
-        List<CtopOauthToken>tokens = tokenService.selectToutiaoToken();
+    public void testLoadBytedanceImageData() {
+        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
         countDownLatch = new CountDownLatch(tokens.size());
         executorService = Executors.newFixedThreadPool(8);
-        tokens.forEach(token->executorService.submit(()->{
+        tokens.forEach(token -> executorService.submit(() -> {
             try {
                 advertiserDataService.getMaterialList(token);
-            }catch (Exception e){
-            }finally {
+            } catch (Exception e) {
+            } finally {
                 countDownLatch.countDown();
             }
         }));
@@ -214,10 +241,12 @@ public class SampleTest {
         System.out.println("素材数据获取完成");
 
     }
+
     @Autowired
     private KuaishouAgentAccountMapper kuaishouAgentAccountMapper;
     @Autowired
     private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
+
     @Test
     public void loadKuaishouAgentData() throws JsonProcessingException {
 //        kuaishouReportDailyAgentService.loginAgent();
@@ -262,6 +291,7 @@ public class SampleTest {
             }
         }
     }
+
     @Autowired
     private IKuaishouInterfaceService kuaishouInterfaceService;
 
@@ -276,16 +306,15 @@ public class SampleTest {
     }
 
 
-
     @Test
     public void loadAccountData() {
 //        List<UserAllocation> allocations = allocationService.getByParams(776L,null,0);
 //        for (UserAllocation allocation:allocations) {
-            CtopOauthToken token = tokenService.getTokenByAccountId(93238965516L);
-            for(int i=92;i<100;i++){
-                Date getDate = DateUtils.addDay(new Date(),-i);
-                reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
-            }
+        CtopOauthToken token = tokenService.getTokenByAccountId(93238965516L);
+        for (int i = 92; i < 100; i++) {
+            Date getDate = DateUtils.addDay(new Date(), -i);
+            reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+        }
 //        }
     }
 
@@ -297,10 +326,10 @@ public class SampleTest {
     IUReportService uReportService;
 
     @Test
-    public void loadBytedanceData(){
+    public void loadBytedanceData() {
         List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
-        for (int i=0;i<tokens.size();i++) {
-            for(int j=0;j<4;j++){
+        for (int i = 0; i < tokens.size(); i++) {
+            for (int j = 0; j < 4; j++) {
                 String getDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -j));
                 bytedanceReportService.bytedanceVideoMaterialReport(tokens.get(i), getDate, getDate);
             }
@@ -309,9 +338,10 @@ public class SampleTest {
 
     @Autowired
     private IBytedanceReportService bytedanceReportService;
+
     @Test
-    public void loadMatData(){
-        List<UserAllocation> allocations = allocationService.getByParams(289L,null,0);
+    public void loadMatData() {
+        List<UserAllocation> allocations = allocationService.getByParams(289L, null, 0);
         countDownLatch = new CountDownLatch(allocations.size());
         executorService = Executors.newFixedThreadPool(2);
         allocations.forEach(allocation -> {

+ 5 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java

@@ -5,6 +5,9 @@ import cn.com.ctop.common.module.utils.Check;
 import com.alibaba.fastjson.JSONObject;
 import org.springframework.stereotype.Service;
 
+import java.util.Arrays;
+import java.util.List;
+
 @Service
 public class MessageTemplateImpl implements IMessageTemplate {
 
@@ -187,8 +190,9 @@ public class MessageTemplateImpl implements IMessageTemplate {
                 .append("下的账户:").append(advertiserId + ",").append("<br/>")
                 .append("广告组id为:").append(unitId).append("<br/>")
                 .append("广告组名称为:").append(unit_name).append("<br/>")
-                .append("出价设置过高。").append("<br/>")
+                .append("出价设置过高。").append("<br/>")
                 .append("系统已执行暂停此组操作,请您及时查看!");
         return text.toString();
     }
+
 }

+ 2 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouTemplateServiceImpl.java

@@ -48,11 +48,11 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
             Integer code = resultJson.getInteger("code");
             if (code == 0) {
                 JSONObject dataJson = resultJson.getJSONObject("data");
-                if (!Check.isNull(dataJson)) {
+                if (Check.isNull(dataJson)) {
                     return;
                 }
                 JSONArray details = dataJson.getJSONArray("details");
-                if (!Check.isNull(details)) {
+                if (Check.isNull(details)) {
                     return;
                 }
                 for (int i = 0; i < details.size(); i++) {

+ 4 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/IByteDanceAdvertiserDataService.java

@@ -38,4 +38,8 @@ public interface IByteDanceAdvertiserDataService {
     void getImageByPage(CtopOauthToken token, String imageIds, int page);
 
     JSONArray advertiserList(String token);
+
+
+    void getBytedancePlanList(String accountId, String accessToken, int pageNum, String createDate, String updateDate);
+
 }

+ 43 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -716,4 +716,47 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         params.put("page_size", 100);
         return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
     }
+
+
+    public void getBytedancePlanList(String accountId, String accessToken, int pageNum, String createDate, String updateDate) {
+
+        // 请求地址
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_get");
+        // 请求参数
+        Map<String, Object> filtering = new HashMap<>();
+        if (null != createDate && !"".equals(createDate)) {
+            filtering.put("ad_create_time", createDate);
+        }
+        if (null != updateDate && !"".equals(updateDate)) {
+            filtering.put("ad_modify_time", updateDate);
+        }
+
+        JSONObject param = new JSONObject();
+        param.put("advertiser_id", accountId);
+        param.put("page", pageNum);
+        param.put("page_size", 1000);
+        param.put("filtering", filtering);
+        JSONObject resultObject = HttpUtils.bytedanceGetRequest(accessToken, url, param);
+        Integer code = resultObject.getInteger("code");
+        if (null == code || !code.equals(0)) {
+            log.error("获取广告计划信息接口异常==》accountId:{},message:{}", accountId, resultObject.getString("message"));
+            return;
+        }
+        JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
+        if (null == data || data.isEmpty()) {
+            return;
+        }
+        for (int i = 0; i < data.size(); i++) {
+            JSONObject dataObject = data.getJSONObject(i);
+            ByteDanceAdvertisePlan advertisePlan = new ByteDanceAdvertisePlan(dataObject, accountId);
+            BigDecimal deepCpabid = dataObject.getBigDecimal("deep_cpabid");
+            if (null != deepCpabid) {
+                advertisePlan.setDeepCpaBid(deepCpabid);
+            }
+            //   advertisePlanService.saveOrUpdate(advertisePlan);
+        }
+        getBytedancePlanList(accountId, accessToken, pageNum + 1, createDate, updateDate);
+    }
+
+
 }