SampleTest.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package org.jeecg;
  2. import cn.com.ctop.bytedance.service.IReportService;
  3. import cn.com.ctop.common.module.entity.CtopOauthToken;
  4. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  5. import cn.com.ctop.common.module.service.IFileInfoService;
  6. import cn.com.ctop.common.module.utils.CtopAdConstant;
  7. import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
  8. import com.alibaba.fastjson.JSONObject;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.jeecg.common.util.DateUtils;
  11. import org.jeecg.modules.ctop.service.ICreateInternalService;
  12. import org.junit.Test;
  13. import org.junit.runner.RunWith;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.boot.test.context.SpringBootTest;
  16. import org.springframework.test.context.junit4.SpringRunner;
  17. import java.io.IOException;
  18. import java.util.Date;
  19. import java.util.List;
  20. import java.util.concurrent.CountDownLatch;
  21. import java.util.concurrent.ExecutorService;
  22. import java.util.concurrent.Executors;
  23. @RunWith(SpringRunner.class)
  24. @SpringBootTest
  25. @Slf4j
  26. public class SampleTest {
  27. @Autowired
  28. private ICreateInternalService createInternalService;
  29. @Autowired
  30. private IKuaishouInterfaceService kuaishouInterfaceService;
  31. @Autowired
  32. private IReportService reportService;
  33. @Test
  34. public void testJob() {
  35. Date getDate = DateUtils.addDay(new Date(), -1);
  36. //1:查询当日数据
  37. List<CtopOauthToken> tokens = tokenService.getTokenListByType(2 + "");
  38. if (null == tokens || tokens.size() <= 0) {
  39. log.info("定时获取头条数据异常:为获取到可用的token");
  40. return;
  41. }
  42. tokens.forEach(token -> {
  43. // //2:获取广告计划信息数据
  44. kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getDate, getDate);
  45. // //3:获取广告组信息数据
  46. kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getDate, getDate);
  47. // //4: 获取广告创意信息数据
  48. kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate);
  49. });
  50. }
  51. @Autowired
  52. IFileInfoService fileInfoService;
  53. @Test
  54. public void testVideoList() throws IOException {
  55. CtopOauthToken token = tokenService.getOauthTokenByAccountId("1232598");
  56. kuaishouInterfaceService.getVideoList(token);
  57. }
  58. @Test
  59. public void testNg() {
  60. JSONObject json = new JSONObject();
  61. createInternalService.createInternal(json);
  62. }
  63. static ExecutorService executorService = null;
  64. static CountDownLatch countDownLatch = null; //线程计数器 如果不用执行完后统一走流程,可以不要这个
  65. @Test
  66. public void loadData() throws InterruptedException {
  67. Date getDate = DateUtils.addDay(new Date(), -1);
  68. // Date getDate = new Date();
  69. List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
  70. if (null == tokens || tokens.size() <= 0) {
  71. log.info("定时获取头条数据异常:为获取到可用的token");
  72. return;
  73. }
  74. int times = tokens.size();
  75. executorService = Executors.newFixedThreadPool(10);
  76. countDownLatch = new CountDownLatch(times);
  77. for (CtopOauthToken token : tokens) {
  78. executorService.submit(new Runnable() {
  79. @Override
  80. public void run() {
  81. if (token.getAccountId() == 2731757) {
  82. System.out.println("" + token.getAccountId() + "开始");
  83. kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate);
  84. System.out.println("" + token.getAccountId() + "结束");
  85. }
  86. countDownLatch.countDown();
  87. }
  88. });
  89. }
  90. countDownLatch.await();
  91. System.out.println("Game Over");
  92. //关掉线程池
  93. executorService.shutdown();
  94. }
  95. @Test
  96. public void loadAllMetiaralInfo() {
  97. Date getDate = DateUtils.addDay(new Date(), -1);
  98. List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
  99. if (null == tokens || tokens.size() <= 0) {
  100. log.info("定时获取头条数据异常:为获取到可用的token");
  101. return;
  102. }
  103. // tokens.forEach(token -> {
  104. // kuaishouInterfaceService.getCampaignList(token);
  105. // });
  106. // tokens.forEach(token -> {
  107. // kuaishouInterfaceService.getGroupList(token);
  108. // });
  109. tokens.forEach(token -> {
  110. kuaishouInterfaceService.getCreativeList(token);
  111. });
  112. tokens.forEach(token -> {
  113. kuaishouInterfaceService.getVideoList(token);
  114. });
  115. log.info("快手物料数据同步完成");
  116. tokens.forEach(token -> {
  117. kuaishouInterfaceService.getAdvertiserReportDaily(token, getDate, getDate);
  118. });
  119. tokens.forEach(token -> {
  120. kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getDate, getDate);
  121. });
  122. tokens.forEach(token -> {
  123. kuaishouInterfaceService.getAdvertiserGroupReportDaily(token, getDate, getDate);
  124. });
  125. tokens.forEach(token -> {
  126. kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token, getDate, getDate);
  127. });
  128. }
  129. @Autowired
  130. private ICtopOauthTokenService tokenService;
  131. }