|
@@ -1,21 +1,36 @@
|
|
|
package cn.com.ctop.job.bytedance.controller;
|
|
|
|
|
|
+import cn.com.ctop.job.bytedance.data.constant.CtopAdConstant;
|
|
|
import cn.com.ctop.job.bytedance.data.entity.OauthToken;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IByteDanceAdvertiserDataService;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IBytedanceCampaignReportDailyService;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IBytedanceCampaignReportHourlyService;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IBytedanceCreativeReportDailyService;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IBytedanceCreativeReportHourlyService;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IBytedanceFileVideoGetService;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IBytedanceMaterialReportDailyService;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IBytedanceProjectService;
|
|
|
import cn.com.ctop.job.bytedance.data.service.IOauthTokenService;
|
|
|
import cn.com.ctop.job.bytedance.data.utils.Check;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.DateUtils;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-
|
|
|
-import java.util.HashMap;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
|
* zian Y
|
|
@@ -24,7 +39,7 @@ import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/bytedance/bytedanceController")
|
|
|
-@Api(tags="头条")
|
|
|
+@Api(tags = "头条")
|
|
|
@Slf4j
|
|
|
public class BytedanceController {
|
|
|
@Autowired
|
|
@@ -34,23 +49,141 @@ public class BytedanceController {
|
|
|
private IBytedanceFileVideoGetService fileVideoService;
|
|
|
|
|
|
|
|
|
-
|
|
|
- @ApiOperation(value="根据账户获取视频素材-账户/素材id 下全部视频素材", notes="根据账户获取视频素材-账户/素材id 下全部视频素材")
|
|
|
+ @ApiOperation(value = "根据账户获取视频素材-账户/素材id 下全部视频素材", notes = "根据账户获取视频素材-账户/素材id 下全部视频素材")
|
|
|
@PostMapping(value = "/getBytedanceVideoByAccountId")
|
|
|
- public Map<String,String> getBytedanceVideoByAccountId(@RequestBody JSONObject jsonObject) {
|
|
|
+ public Map<String, String> getBytedanceVideoByAccountId(@RequestBody JSONObject jsonObject) {
|
|
|
Long accountId = jsonObject.getLong("accountId");
|
|
|
JSONArray dataList = jsonObject.getJSONArray("materialIds");
|
|
|
- List<Long> materialIds = Check.isNull(dataList) ? null : JSONArray.parseObject(dataList.toJSONString(),List.class);
|
|
|
+ List<Long> materialIds = Check.isNull(dataList) ? null : JSONArray.parseObject(dataList.toJSONString(), List.class);
|
|
|
|
|
|
String token = tokenService.getByAccountId(accountId);
|
|
|
OauthToken oauthToken = new OauthToken();
|
|
|
oauthToken.setAccessToken(token);
|
|
|
oauthToken.setAccountId(accountId);
|
|
|
- return fileVideoService.getBytedanceVideoByAccountId(oauthToken, materialIds,1, 100);
|
|
|
+ return fileVideoService.getBytedanceVideoByAccountId(oauthToken, materialIds, 1, 100);
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private static ExecutorService dailyExecutorService = Executors.newFixedThreadPool(10);
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceAdvertiserDataService advertiserDataService;
|
|
|
+
|
|
|
|
|
|
+ /**
|
|
|
+ * 代理商日报
|
|
|
+ *
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/bytedanceAdvertiserDailyReport")
|
|
|
+ public void bytedanceAdvertiserDailyReport() throws Exception {
|
|
|
+ List<Long> agentByTouTiao = tokenService.getAgentByTouTiao();
|
|
|
+ List<String> allDatesOfTwoTimes = DateUtils.getAllDatesOfTwoTimes("2022-09-01", "2022-09-14");
|
|
|
+ for (Long aLong : agentByTouTiao) {
|
|
|
+ String token = tokenService.getByAccountId(Long.valueOf(aLong));
|
|
|
+ OauthToken oauthToken = new OauthToken();
|
|
|
+ oauthToken.setAccessToken(token);
|
|
|
+ oauthToken.setAccountId(aLong);
|
|
|
+
|
|
|
+ allDatesOfTwoTimes.forEach(date -> dailyExecutorService.submit(() -> {
|
|
|
+ advertiserDataService.getAgentReport(oauthToken, date, date, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ advertiserDataService.getAgentReport(oauthToken, date, date, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
|
|
|
+
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IBytedanceCreativeReportDailyService creativeReportDailyService;
|
|
|
+ @Autowired
|
|
|
+ IBytedanceCreativeReportHourlyService creativeReportHourlyService;
|
|
|
+ @Autowired
|
|
|
+ IBytedanceCampaignReportHourlyService campaignReportHourlyService;
|
|
|
+ @Autowired
|
|
|
+ IBytedanceCampaignReportDailyService campaignReportDailyService;
|
|
|
+ @Autowired
|
|
|
+ private IBytedanceMaterialReportDailyService materialReportDailyService;
|
|
|
+ @Autowired
|
|
|
+ private IBytedanceProjectService listService;
|
|
|
+
|
|
|
+ @GetMapping(value = "/testReport")
|
|
|
+ public String testReport() {
|
|
|
+ List<Long> accountIds = tokenService.getAllToutiaoAccountIds();
|
|
|
+ for (Long id : accountIds) {
|
|
|
+ String token = tokenService.getByAccountId(id);
|
|
|
+ OauthToken oauthToken = new OauthToken();
|
|
|
+ oauthToken.setAccessToken(token);
|
|
|
+ oauthToken.setAccountId(id);
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
+ String yesterda = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
|
|
|
+ String start = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -8);
|
|
|
+ Date getDate = new Date();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
|
|
|
+ String hour = simpleDateFormat.format(getDate);
|
|
|
+ dailyExecutorService.submit(
|
|
|
+ new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ Thread.sleep(500);
|
|
|
+ // materialReportDailyService.bytedanceDailyMaterialReportJobV3Video(oauthToken, yesterda2, yesterda, 1, 100);
|
|
|
+// listService.getProjectList(oauthToken, start, yesterda, 1);
|
|
|
+// advertiserDataService.getV3AdvertiserReport(oauthToken, start, yesterda, CtopAdConstant.BYTEDANCE_REPORT_V3_TYPE_DAILY);
|
|
|
+// materialReportDailyService.bytedanceDailyMaterialReportJobV3Video(oauthToken, yesterda, yesterda, 1, 100);
|
|
|
+// materialReportDailyService.bytedanceDailyMaterialReportJobV3Image(oauthToken, yesterda2, yesterda, 1, 100);
|
|
|
+ advertiserDataService.getV3PromotionProjectReport(oauthToken, "2023-07-01", "2023-07-06", CtopAdConstant.BYTEDANCE_REPORT_V3_TYPE_DAILY);
|
|
|
+ advertiserDataService.getV3PromotionMaterialReport(oauthToken, "2023-07-01", "2023-07-06", CtopAdConstant.BYTEDANCE_REPORT_V3_TYPE_DAILY);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ return "ok";
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping(value = "/testOneReport")
|
|
|
+ public String testOneReport(Long accountId) {
|
|
|
+ String token = tokenService.getByAccountId(accountId);
|
|
|
+ if (Check.isNull(token)) {
|
|
|
+ log.error("此账户未获取到相关token,accountId:{}", accountId);
|
|
|
+ return "no";
|
|
|
+ }
|
|
|
+ OauthToken oauthToken = new OauthToken();
|
|
|
+ oauthToken.setAccessToken(token);
|
|
|
+ oauthToken.setAccountId(accountId);
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
+ String yesterda = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
|
|
|
+ String start = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -2);
|
|
|
+
|
|
|
+
|
|
|
+ Date getDate = new Date();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
|
|
|
+ String hour = simpleDateFormat.format(getDate);
|
|
|
+ dailyExecutorService.submit(
|
|
|
+ new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ Thread.sleep(500);
|
|
|
+// materialReportDailyService.bytedanceDailyMaterialReportJobV3Video(oauthToken, start, yesterda, 1, 100);
|
|
|
+// advertiserDataService.getV3AdvertiserConfig(oauthToken);
|
|
|
+ advertiserDataService.getV3PromotionMaterialReport(oauthToken, yesterda, yesterda, CtopAdConstant.BYTEDANCE_REPORT_V3_TYPE_DAILY);
|
|
|
+// advertiserDataService.getV3AdvertiserReport(oauthToken, nowDate, nowDate, CtopAdConstant.BYTEDANCE_REPORT_V3_TYPE_HOURLY);
|
|
|
+// listService.getProjectList(oauthToken, start, yesterda, 1);
|
|
|
+// materialReportDailyService.bytedanceDailyMaterialReportJobV3Image(oauthToken, yesterda2, yesterda, 1, 100);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return "ok";
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|