|
@@ -3,6 +3,7 @@ package cn.com.ctop.toutiao.modules.report.controller;
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportMaterialRetry;
|
|
|
+import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
|
|
|
import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -24,6 +25,8 @@ public class BytedanceReportController {
|
|
|
private IBytedanceReportService bytedanceReportService;
|
|
|
@Autowired
|
|
|
private ICtopOauthTokenService tokenService;
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceVideoReportDailyService byteDanceVideoReportDailyService;
|
|
|
|
|
|
@PostMapping("/kuaiShou/accountReport")
|
|
|
public Result<JSONObject> getKuaiShouAccountReport(@RequestBody JSONObject requestJson) {
|
|
@@ -185,9 +188,28 @@ public class BytedanceReportController {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try {
|
|
|
- CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(retry.getAccountId()));
|
|
|
+ String startDate = retry.getStartDate();
|
|
|
+ String endDate = retry.getEndDate();
|
|
|
+ Long accountId = retry.getAccountId();
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(accountId));
|
|
|
log.info("头条素材报表当前accountId为:" + token.getAccountId());
|
|
|
- bytedanceReportService.bytedanceMaterialReportRetry(token, retry.getStartDate(), retry.getEndDate());
|
|
|
+ //int code = bytedanceReportService.bytedanceMaterialReportRetry(token, startDate, endDate);
|
|
|
+
|
|
|
+ Long days = DateUtils.getDiscrepantDays(startDate, endDate); //间隔天数
|
|
|
+ String start = null;
|
|
|
+ String end = null;
|
|
|
+ for (int i = 0; i <= days; i++) {
|
|
|
+ start = DateUtils.addDay(startDate, i);
|
|
|
+ end = start;
|
|
|
+ //获取头条素材报表数据
|
|
|
+ int code = bytedanceReportService.bytedanceMaterialReport(token, start, end);
|
|
|
+ if(code ==200 || code == 1){
|
|
|
+ //重试成功清洗数据
|
|
|
+ byteDanceVideoReportDailyService.videoInfoListByAccountId(start,end,accountId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ byteDanceVideoReportDailyService.videoInfoListByAccountId(retry.getStartDate(), retry.getEndDate(), token.getAccountId());
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
@@ -207,18 +229,54 @@ public class BytedanceReportController {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 绑定头条账户之后的操作,对此账户进行素材报表数据拉取以及素材报表数据清洗
|
|
|
+ * @param accountId
|
|
|
+ * @param startDate
|
|
|
+ * @param endDate
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/bytedance/bytedanceMaterialReportAndVideoReport")
|
|
|
+ public Result bytedanceMaterialReportAndVideoReport(@RequestParam(name = "accountId") Long accountId,
|
|
|
+ @RequestParam(name = "startDate") String startDate,
|
|
|
+ @RequestParam(name = "endDate") String endDate) {
|
|
|
+ Result result = new Result<>();
|
|
|
+ if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate) || null == accountId){
|
|
|
+ result.error500("开始时间和结束时间、accountId均不能为空");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
+ try {
|
|
|
+ log.info("头条获取素材报表数据任务执行开始");
|
|
|
+ Long starttime = System.currentTimeMillis();
|
|
|
+ CtopOauthToken token = tokenService.getAccessTokenByAccountIdAndMediaId(1,accountId);
|
|
|
+ if (null == token) {
|
|
|
+ log.info("头条获取素材报表数据任务执行失败:未获取到可用的token,accountId:" + accountId);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
+ Long days = DateUtils.getDiscrepantDays(startDate, endDate); //间隔天数
|
|
|
+ String start = null;
|
|
|
+ String end = null;
|
|
|
+ for (int i = 0; i <= days; i++) {
|
|
|
+ start = DateUtils.addDay(startDate, i);
|
|
|
+ end = start;
|
|
|
+ //获取头条素材报表数据
|
|
|
+ int code = bytedanceReportService.bytedanceMaterialReport(token, start, end);
|
|
|
+ //如果成功的话跑视频清洗数据方法,失败会进入重试库,重试成功后再清洗数据
|
|
|
+ if(code ==200 || code == 1){
|
|
|
+ byteDanceVideoReportDailyService.videoInfoListByAccountId(start,end,accountId);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ Long endtime = System.currentTimeMillis();
|
|
|
+ log.info("头条获取素材报表数据任务执行结束,accountId:{},执行耗时:{}秒", accountId, (endtime - starttime) / 1000);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("头条获取素材报表数据任务执行结失败accountId:" + accountId);
|
|
|
+ e.printStackTrace();
|
|
|
+ result.setSuccess(false);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
}
|