|
@@ -281,15 +281,14 @@ public class BytedanceReportController {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 头条视频素材报表--此接口仅有视频素材
|
|
|
+ * 头条视频素材报表--此接口仅有视频素材,异步拉取数据
|
|
|
* @param startDate
|
|
|
* @param endDate
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/bytedance/bytedanceVideoMaterialReport")
|
|
|
public Result bytedanceVideoMaterialReport(@RequestParam(name = "startDate") String startDate,
|
|
|
- @RequestParam(name = "endDate") String endDate,
|
|
|
- @RequestParam(name = "accountId") Long accountId) {
|
|
|
+ @RequestParam(name = "endDate") String endDate) {
|
|
|
Result result = new Result<>();
|
|
|
if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)){
|
|
|
result.error500("开始时间和结束时间不能为空");
|
|
@@ -298,24 +297,36 @@ public class BytedanceReportController {
|
|
|
try {
|
|
|
log.info("头条获取视频素材报表数据任务执行开始");
|
|
|
Long starttime = System.currentTimeMillis();
|
|
|
- CtopOauthToken token = tokenService.getAccessTokenByAccountIdAndMediaId(1,93238965516L);
|
|
|
-
|
|
|
-
|
|
|
- try {
|
|
|
- ////间隔天数
|
|
|
- //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;
|
|
|
- //获取头条素材报表数据
|
|
|
- bytedanceReportService.bytedanceVideoMaterialReport(token, startDate, endDate);
|
|
|
- // }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
|
|
|
+ if (null == tokens || tokens.size() <= 0) {
|
|
|
+ log.info("头条获取素材报表数据任务执行失败:未获取到可用的token");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
+ final ExecutorService executorService = Executors.newFixedThreadPool(8);
|
|
|
+ tokens.forEach(token -> {
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+
|
|
|
+ try {
|
|
|
+ //间隔天数
|
|
|
+ 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;
|
|
|
+ //获取头条素材报表数据
|
|
|
+ bytedanceReportService.bytedanceVideoMaterialReport(token, start, end);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
////
|
|
|
Long endtime = System.currentTimeMillis();
|
|
|
log.info("头条获取视频素材报表数据任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
|
|
@@ -327,4 +338,49 @@ public class BytedanceReportController {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 头条视频素材报表--此接口仅有视频素材,单个accountId拉取数据
|
|
|
+ * @param startDate
|
|
|
+ * @param endDate
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/bytedance/bytedanceVideoMaterialReportByAccountId")
|
|
|
+ public Result bytedanceVideoMaterialReportByAccountId(@RequestParam(name = "startDate") String startDate,
|
|
|
+ @RequestParam(name = "endDate") String endDate,
|
|
|
+ @RequestParam(name = "accountId") Long accountId) {
|
|
|
+ Result result = new Result<>();
|
|
|
+ if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)||accountId==null){
|
|
|
+ result.error500("开始时间,结束时间和账户id不能为空");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ log.info("头条获取单个账户视频素材报表数据任务执行开始");
|
|
|
+ Long starttime = System.currentTimeMillis();
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(accountId));
|
|
|
+ if (null == token ) {
|
|
|
+ log.info("头条获取单个账户视频素材报表数据任务执行失败:未获取到可用的token");
|
|
|
+ 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;
|
|
|
+ //获取头条素材报表数据
|
|
|
+ bytedanceReportService.bytedanceVideoMaterialReport(token, start, end);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long endtime = System.currentTimeMillis();
|
|
|
+ log.info("头条获取视频素材报表数据任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("头条获取视频素材报表数据任务执行结失败");
|
|
|
+ e.printStackTrace();
|
|
|
+ result.setSuccess(false);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|