Bladeren bron

提交获取数据逻辑代码

syh 5 jaren geleden
bovenliggende
commit
1d6a491211

+ 1 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -113,6 +113,7 @@ public class ShiroConfig {
 		filterChainDefinitionMap.put("/toutiao/dictitem/list", "anon");
         filterChainDefinitionMap.put("/toutiao/loadAllData", "anon");
         filterChainDefinitionMap.put("/toutiao/loadSingleData", "anon");
+		filterChainDefinitionMap.put("/kuaishou/getReport/historyData", "anon");
 		filterChainDefinitionMap.put("/toutiao/advertiser/**", "anon");
         filterChainDefinitionMap.put("/toutiao/industry/list", "anon");
         filterChainDefinitionMap.put("/template/bytedance/industry/list", "anon");

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

@@ -264,8 +264,6 @@ public class ByteDanceAdvertiserPostController {
     public Map<String, Object> loadAllData() {
         Map<String, Object> result = new HashMap<>();
         Date endDate = new Date();
-        Date hourlyStartDate = DateUtils.addDay(endDate, -7);
-        Date startDate = DateUtils.addDay(endDate, -180);
 //        List<CtopOauthToken> bytedanceTokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
 //        if(null!=bytedanceTokens&&bytedanceTokens.size()>0){
 //            bytedanceTokens.forEach(token -> {
@@ -289,27 +287,8 @@ public class ByteDanceAdvertiserPostController {
 //            });
 //        }
         List<CtopOauthToken> kuaishouTokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
-        if (null != kuaishouTokens && kuaishouTokens.size() > 0) {
-            kuaishouTokens.forEach(token -> {
-                //1: 获取广告主信息数据
-                kuaishouInterfaceService.getAdvertiserReportDaily(token, startDate, endDate);
-                //2:获取广告计划信息数据
-                kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, startDate, endDate);
-                //3:获取广告组信息数据
-                kuaishouInterfaceService.getAdvertiserGroupReportDaily(token, startDate, endDate);
-                //4: 获取广告创意信息数据
-                kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token, startDate, endDate);
+        kuaishouInterfaceService.loadAllKuaishouData(kuaishouTokens);
 
-                //1: 获取广告主信息数据
-                kuaishouInterfaceService.getAdvertiserReportHourly(token, hourlyStartDate, endDate);
-                //2:获取广告计划信息数据
-                kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, hourlyStartDate, endDate);
-                //3:获取广告组信息数据
-                kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, hourlyStartDate, endDate);
-                //4: 获取广告创意信息数据
-                kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, hourlyStartDate, endDate);
-            });
-        }
         ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS.getCode());
         return result;
     }

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

@@ -125,6 +125,7 @@ public class CallbackController {
                     topOauthToken.setUpdateTime(new Date());
                     cTopOauthTokenMapper.insert(topOauthToken);
                     bindAccountAuthService.addBindAccount(accountId, KuaishouInterfaceConstant.LOGIN_TYPE_KUAISHOU, advertiserId); //账号绑定
+                    kuaishouInterfaceService.loadKuaishouDataSingle(topOauthToken);
                 }
                 return "授权绑定成功";
             }
@@ -134,7 +135,6 @@ public class CallbackController {
         return "授权绑定失败!";
     }
 
-
     @RequestMapping("/bytedance")
     @ResponseBody
     public String bytedance(HttpServletRequest request,

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

@@ -4,20 +4,15 @@ import cn.com.ctop.bytedance.service.IReportService;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.IFileInfoService;
+import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.common.module.utils.OSSUtils;
 import cn.com.ctop.common.module.utils.StringUtils;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
-import cn.com.ctop.toutiao.entity.ByteDanceUserOrientationTemplate;
-import cn.com.ctop.toutiao.entity.BytedanceInterestCategory;
-import cn.com.ctop.toutiao.mapper.ByteDanceUserOrientationTemplateMapper;
-import cn.com.ctop.toutiao.mapper.BytedanceAreaInfoMapper;
-import cn.com.ctop.toutiao.mapper.BytedanceInterestCategoryMapper;
 import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
-import org.jeecg.common.util.jsonschema.JsonschemaUtil;
 import org.jeecg.modules.ctop.service.ICreateInternalService;
 import org.jeecg.modules.demo.mock.MockController;
 import org.jeecg.modules.demo.test.mapper.JeecgDemoMapper;
@@ -86,15 +81,79 @@ public class SampleTest {
 //            //1: 获取广告主信息数据
 //            kuaishouInterfaceService.getAdvertiserReportHourly(token, getDate);
 //            //2:获取广告计划信息数据
-            kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getDate);
+            kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getDate, getDate);
 //            //3:获取广告组信息数据
-            kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getDate);
+            kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getDate, getDate);
 //            //4: 获取广告创意信息数据
-            kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate);
+            kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate);
         });
     }
 
     @Test
+    public void testLoadDate180() {
+        Date endDate = new Date();
+        Date hourlyStartDate = DateUtils.addDay(endDate, -7);
+        Date startDate = DateUtils.addDay(endDate, -170);
+        List<CtopOauthToken> bytedanceTokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+        if (null != bytedanceTokens && bytedanceTokens.size() > 0) {
+            bytedanceTokens.forEach(token -> {
+                //1: 获取广告主信息数据
+                reportService.getAdvertiserReport(token, startDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+                //2:获取广告组信息数据
+                reportService.getAdvertiserCampaignReport(token, startDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+                //3:获取广告计划信息数据
+                reportService.getAdvertiserPlanReport(token, startDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+                //4: 获取广告创意信息数据
+                reportService.getAdvertiserCreativeReport(token, startDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+
+                //1: 获取广告主信息数据
+                reportService.getAdvertiserReport(token, hourlyStartDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
+                //2:获取广告组信息数据
+                reportService.getAdvertiserCampaignReport(token, hourlyStartDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
+                //3:获取广告计划信息数据
+                reportService.getAdvertiserPlanReport(token, hourlyStartDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
+                //4: 获取广告创意信息数据
+                reportService.getAdvertiserCreativeReport(token, hourlyStartDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
+            });
+        }
+        List<CtopOauthToken> kuaishouTokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+        if (null != kuaishouTokens && kuaishouTokens.size() > 0) {
+            for (CtopOauthToken token : kuaishouTokens) {
+                for (int i = 0; i < 7; i++) {
+                    Date getStartDate = DateUtils.addDay(endDate, -i);
+                    //1: 获取广告主信息数据
+                    kuaishouInterfaceService.getAdvertiserReportHourly(token, getStartDate, getStartDate);
+                    //2:获取广告计划信息数据
+                    kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getStartDate, getStartDate);
+                    //3:获取广告组信息数据
+                    kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getStartDate, getStartDate);
+                    //4: 获取广告创意信息数据
+                    kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getStartDate, getStartDate);
+                }
+                for (int i = 0; i < 6; i++) {
+                    Date getStartDate = new Date();
+                    Date getEndDate = new Date();
+                    if (i == 0) {
+                        getStartDate = DateUtils.addDay(endDate, -175 + i * 30);
+                        getEndDate = DateUtils.addDay(endDate, -150 + i * 30);
+                    } else {
+                        getStartDate = DateUtils.addDay(endDate, -180 + i * 30);
+                        getEndDate = DateUtils.addDay(endDate, -150 + i * 30);
+                    }
+                    //1: 获取广告主信息数据
+                    kuaishouInterfaceService.getAdvertiserReportDaily(token, getStartDate, getEndDate);
+                    //2:获取广告计划信息数据
+                    kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getStartDate, getEndDate);
+                    //3:获取广告组信息数据
+                    kuaishouInterfaceService.getAdvertiserGroupReportDaily(token, getStartDate, getEndDate);
+                    //4: 获取广告创意信息数据
+                    kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token, getStartDate, getEndDate);
+                }
+            }
+        }
+    }
+
+    @Test
     public void testFileType() {
         File file = new File("D:\\工作文件\\360借条\\快手后台数据-户1.csv");
         System.out.println(file);
@@ -112,70 +171,11 @@ public class SampleTest {
         createInternalService.createInternal(json);
     }
 
-    @Autowired
-    private BytedanceAreaInfoMapper areaInfoMapper;
-    @Autowired
-    private BytedanceInterestCategoryMapper interestCategoryMapper;
-
-    @Test
-    public void setCategoryData() {
-        String path = "D:\\工作文件\\头条批量\\data_20190222\\ad_tag.json";
-        String jsonString = JsonschemaUtil.readJsonFile(path);
-        JSONObject data = JSONObject.parseObject(jsonString);
-        JSONArray tagArray = data.getJSONArray("adtags");
-        tagArray.forEach(tag -> {
-            JSONObject getTag = (JSONObject) tag;
-            String pcode = getTag.getString("value");
-            String plabel = getTag.getString("label");
-            BytedanceInterestCategory category = new BytedanceInterestCategory();
-            category.setCode(pcode);
-            category.setName(plabel);
-            category.setParentCode("0");
-            category.setLevel(1);
-            category.setCreateTime(new Date());
-            category.setUpdateTime(new Date());
-            interestCategoryMapper.insert(category);
-            JSONArray children = getTag.getJSONArray("subTags");
-            children.forEach(child -> {
-                JSONObject getchild = (JSONObject) child;
-                String code = getchild.getString("value");
-                String label = getchild.getString("label");
-                BytedanceInterestCategory childCategory = new BytedanceInterestCategory();
-                childCategory.setCode(code);
-                childCategory.setName(label);
-                childCategory.setParentCode(pcode);
-                childCategory.setLevel(2);
-                childCategory.setCreateTime(new Date());
-                childCategory.setUpdateTime(new Date());
-                interestCategoryMapper.insert(childCategory);
-            });
-        });
-    }
 
     @Autowired
     private ICtopOauthTokenService tokenService;
     @Autowired
-    private ByteDanceUserOrientationTemplateMapper userOrientationTemplateMapper;
-    @Autowired
     private IByteDanceAdvertiserDataService advertiserDataService;
-
-    @Test
-    public void testEditPlan() throws Exception {
-        String accountId = "74099510334";
-        Long userOrientationId = 5L;
-        Long adId = 1643004580559934L;
-        //修改用户定向
-        ByteDanceUserOrientationTemplate template = userOrientationTemplateMapper.selectById(userOrientationId);
-        if (null != template) {
-            CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId);
-            if (null != token) {
-                //获取modify_time
-                Thread.sleep(5000L);
-                advertiserDataService.getAdvertiserPlan(accountId, adId + "");
-            }
-        }
-    }
-
     @Autowired
     private IFileInfoService fileInfoService;
 

+ 4 - 13
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouReportController.java

@@ -63,38 +63,29 @@ public class KuaiShouReportController {
                         for (int i = 0; i < 6; i++) {
                             if (i == 0) {
                                 String monthBefore = DateUtils.getMonthBefore("yyyy-MM-dd", nowDate, -1);
-                                System.err.println("开始时间:" + anotherDay);
-                                System.err.println("结束时间:" + monthBefore);
-                                kuaishouInterfaceService.getAccountDailyReport(accessToken, advertiserId, monthBefore, anotherDay, 1, 500);
+                                kuaishouInterfaceService.getAccountDailyReport(accessToken, advertiserId, monthBefore, anotherDay, 500, 1);
                                 beginDate = monthBefore;
-
-
                             } else if (i > 0) {
                                 String startDate = DateUtils.getAnotherDay("yyyy-MM-dd", beginDate, -1);
                                 String monthBefore = DateUtils.getMonthBefore("yyyy-MM-dd", beginDate, -1);
-                                System.err.println("开始时间:" + startDate);
-
                                 if (i == 5) {
                                     monthBefore = DateUtils.getAnotherDay("yyyy-MM-dd", monthBefore, 4);
                                 }
-                                System.err.println("结束时间:" + monthBefore);
-                                kuaishouInterfaceService.getAccountDailyReport(accessToken, advertiserId, monthBefore, startDate, 1, 500);
+                                kuaishouInterfaceService.getAccountDailyReport(accessToken, advertiserId, monthBefore, startDate, 500, 1);
                                 beginDate = monthBefore;
 
-                                //
-
                             }
 
                         }
 
                         for (int i = 0; i < 7; i++) {
                             if (i == 0) {
-                                kuaishouInterfaceService.getAccountHourlyReport(accessToken, advertiserId, nowDate, nowDate, 1, 500);
+                                kuaishouInterfaceService.getAccountHourlyReport(accessToken, advertiserId, nowDate, nowDate, 500, 1);
                                 hourDate = nowDate;
                                 System.err.println(nowDate);
                             } else if (i > 0) {
                                 String hourAnotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", hourDate, -1);
-                                kuaishouInterfaceService.getAccountHourlyReport(accessToken, advertiserId, hourAnotherDay, hourAnotherDay, 1, 500);
+                                kuaishouInterfaceService.getAccountHourlyReport(accessToken, advertiserId, hourAnotherDay, hourAnotherDay, 500, 1);
                                 System.err.println(hourAnotherDay);
                                 hourDate = hourAnotherDay;
                             }

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

@@ -10,6 +10,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 public interface IKuaishouInterfaceService {
@@ -29,6 +30,9 @@ public interface IKuaishouInterfaceService {
 
     KuaishouResult<KuaishouReportHourlyCreative> getCreativeHourlyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum);
 
+    void loadAllKuaishouData(List<CtopOauthToken> tokens);
+
+    void loadKuaishouDataSingle(CtopOauthToken token);
 
     /**
      * 创建广告计划

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

@@ -1,10 +1,7 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.common.module.utils.Check;
-import cn.com.ctop.common.module.utils.HttpUtils;
-import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
-import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.common.module.utils.*;
 import cn.com.ctop.kuaishou.modules.batch.entity.*;
 import cn.com.ctop.kuaishou.modules.batch.mapper.*;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
@@ -122,6 +119,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
         String result = HttpUtils.httpPostRequest(url, param, headers);
         JSONObject resultJson = JSONObject.parseObject(result);
+        System.out.println(resultJson.toJSONString());
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");
         if (null == code || code != 0) {
@@ -144,7 +142,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             kuaishouReportHourlyAccount.setId("" + token.getAccountId() + kuaishouReportHourlyAccount.getStatDate() + kuaishouReportHourlyAccount.getStatHour());
             hourlyAccountService.saveOrUpdate(kuaishouReportHourlyAccount);
         }
-        getAdvertiserReportHourlyByPage(token, startDate, endDate, page + 1);
     }
 
     /**
@@ -175,6 +172,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             String result = HttpUtils.httpPostRequest(url, param, headers);
             JSONObject resultJson = JSONObject.parseObject(result);
             if (!Check.isNull(resultJson)) {
+                System.err.println(resultJson);
                 if (resultJson.getInteger("code") == 0) {
                     JSONObject dataJson = resultJson.getJSONObject("data");
                     if (!Check.isNull(dataJson)) {
@@ -186,7 +184,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                             Long like = detailJson.getLong("like");
                             detailJson.put("photo_like", like);
                             KuaishouReportHourlyAccount kuaishouReportHourlyAccount = JSONObject.toJavaObject(detailJson, KuaishouReportHourlyAccount.class);
-                            System.err.println(kuaishouReportHourlyAccount);
+//                            System.err.println(kuaishouReportHourlyAccount);
                             kuaishouReportHourlyAccount.setAccountId(advertiserId);
                             kuaishouReportHourlyAccount.setId("" + advertiserId + kuaishouReportHourlyAccount.getStatDate() + kuaishouReportHourlyAccount.getStatHour());
                             hourlyAccountService.saveOrUpdate(kuaishouReportHourlyAccount);
@@ -267,6 +265,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
             JSONObject resultJson = JSONObject.parseObject(result);
             if (!Check.isNull(resultJson)) {
+                System.err.println(resultJson);
                 if (resultJson.getInteger("code") == 0) {
                     JSONObject dataJson = resultJson.getJSONObject("data");
                     if (!Check.isNull(dataJson)) {
@@ -280,6 +279,9 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                             KuaishouReportDailyAccount kuaishouReportDailyAccount = JSONObject.toJavaObject(detailJson, KuaishouReportDailyAccount.class);
                             kuaishouReportDailyAccount.setAccountId(advertiserId);
                             kuaishouReportDailyAccount.setId("" + advertiserId + kuaishouReportDailyAccount.getStatDate());
+
+                            System.out.println("-------------------------------------------");
+                            System.out.println(kuaishouReportDailyAccount);
                             dailyAccountService.saveOrUpdate(kuaishouReportDailyAccount);
                         }
                     }
@@ -772,6 +774,51 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         return kuaishouResult;
     }
 
+    @Override
+    public void loadAllKuaishouData(List<CtopOauthToken> tokens) {
+        if (null != tokens && tokens.size() > 0) {
+            for (CtopOauthToken token : tokens) {
+                loadKuaishouDataSingle(token);
+            }
+        }
+    }
+
+    @Override
+    public void loadKuaishouDataSingle(CtopOauthToken token) {
+        Date endDate = new Date();
+        for (int i = 0; i < 7; i++) {
+            Date getStartDate = DateUtils.addDay(endDate, -i);
+            //1: 获取广告主信息数据
+            getAdvertiserReportHourly(token, getStartDate, getStartDate);
+            //2:获取广告计划信息数据
+            getAdvertiserCampaignReportHourly(token, getStartDate, getStartDate);
+            //3:获取广告组信息数据
+            getAdvertiserGroupReportHourly(token, getStartDate, getStartDate);
+            //4: 获取广告创意信息数据
+            getAdvertiserCreativeReportHourly(token, getStartDate, getStartDate);
+        }
+        for (int i = 0; i < 6; i++) {
+            Date getStartDate = new Date();
+            Date getEndDate = new Date();
+            if (i == 0) {
+                getStartDate = DateUtils.addDay(endDate, -175 + i * 30);
+                getEndDate = DateUtils.addDay(endDate, -150 + i * 30);
+            } else {
+                getStartDate = DateUtils.addDay(endDate, -180 + i * 30);
+                getEndDate = DateUtils.addDay(endDate, -150 + i * 30);
+            }
+            //1: 获取广告主信息数据
+            getAdvertiserReportDaily(token, getStartDate, getEndDate);
+            //2:获取广告计划信息数据
+            getAdvertiserCampaignReportDaily(token, getStartDate, getEndDate);
+            //3:获取广告组信息数据
+            getAdvertiserGroupReportDaily(token, getStartDate, getEndDate);
+            //4: 获取广告创意信息数据
+            getAdvertiserCreativeReportDaily(token, getStartDate, getEndDate);
+        }
+
+    }
+
 
     /**
      * 创建广告计划