SampleTest.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.text.SimpleDateFormat;
  19. import java.util.Date;
  20. import java.util.List;
  21. import java.util.concurrent.CountDownLatch;
  22. import java.util.concurrent.ExecutorService;
  23. import java.util.concurrent.Executors;
  24. @RunWith(SpringRunner.class)
  25. @SpringBootTest
  26. @Slf4j
  27. public class SampleTest {
  28. @Autowired
  29. private ICreateInternalService createInternalService;
  30. @Autowired
  31. private IKuaishouInterfaceService kuaishouInterfaceService;
  32. @Autowired
  33. private IReportService reportService;
  34. @Test
  35. public void testJob() {
  36. Date getDate = DateUtils.addDay(new Date(), -1);
  37. //1:查询当日数据
  38. List<CtopOauthToken> tokens = tokenService.getTokenListByType(2 + "");
  39. if (null == tokens || tokens.size() <= 0) {
  40. log.info("定时获取头条数据异常:为获取到可用的token");
  41. return;
  42. }
  43. tokens.forEach(token -> {
  44. // //2:获取广告计划信息数据
  45. kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getDate, getDate);
  46. // //3:获取广告组信息数据
  47. kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getDate, getDate);
  48. // //4: 获取广告创意信息数据
  49. kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate);
  50. });
  51. }
  52. @Autowired
  53. IFileInfoService fileInfoService;
  54. @Test
  55. public void testVideoList() throws IOException {
  56. CtopOauthToken token = tokenService.getOauthTokenByAccountId("1232598");
  57. kuaishouInterfaceService.getVideoList(token);
  58. }
  59. @Test
  60. public void testNg() {
  61. JSONObject json = new JSONObject();
  62. createInternalService.createInternal(json);
  63. }
  64. static ExecutorService executorService = null;
  65. static CountDownLatch countDownLatch = null; //线程计数器
  66. @Test
  67. public void loadData() throws InterruptedException {
  68. Date getDate = new Date();
  69. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
  70. String hour = simpleDateFormat.format(getDate);
  71. if (null != hour && hour.equals("00")) {
  72. getDate = DateUtils.addDay(getDate, -1);
  73. }
  74. //1:查询当日数据
  75. List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
  76. if (null == tokens || tokens.size() <= 0) {
  77. log.info("定时获取头条数据异常:为获取到可用的token");
  78. return;
  79. }
  80. executorService = Executors.newFixedThreadPool(10);
  81. countDownLatch = new CountDownLatch(tokens.size());
  82. Date finalGetDate = getDate;
  83. tokens.forEach(token -> {
  84. executorService.submit(new Runnable() {
  85. @Override
  86. public void run() {
  87. try {
  88. kuaishouInterfaceService.getAdvertiserReportHourly(token, finalGetDate, finalGetDate);
  89. //2:获取广告计划信息数据
  90. kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, finalGetDate, finalGetDate);
  91. //3:获取广告组信息数据
  92. kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, finalGetDate, finalGetDate);
  93. //4: 获取广告创意信息数据
  94. kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, finalGetDate, finalGetDate);
  95. } catch (Exception e) {
  96. e.printStackTrace();
  97. } finally {
  98. countDownLatch.countDown();
  99. }
  100. }
  101. });
  102. });
  103. try {
  104. countDownLatch.await();
  105. } catch (InterruptedException e) {
  106. e.printStackTrace();
  107. }
  108. for (CtopOauthToken token : tokens) {
  109. kuaishouInterfaceService.updateCreativeReportHourlyStatistic(token, getDate);
  110. }
  111. executorService.shutdown();
  112. }
  113. @Test
  114. public void loadAllMetiaralInfo() throws InterruptedException {
  115. Long start = System.currentTimeMillis();
  116. Date getDate = new Date();
  117. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
  118. String hour = simpleDateFormat.format(getDate);
  119. if (null != hour && hour.equals("00")) {
  120. getDate = DateUtils.addDay(getDate, -1);
  121. }
  122. //1:查询当日数据
  123. List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
  124. if (null == tokens || tokens.size() <= 0) {
  125. log.info("定时获取头条数据异常:为获取到可用的token");
  126. return;
  127. }
  128. int times = tokens.size();
  129. executorService = Executors.newFixedThreadPool(10);
  130. countDownLatch = new CountDownLatch(times);
  131. tokens.forEach(token -> {
  132. executorService.submit(new Runnable() {
  133. @Override
  134. public void run() {
  135. try {
  136. Long start = System.currentTimeMillis();
  137. //1:获取全量广告计划数据
  138. kuaishouInterfaceService.getCampaignList(token);
  139. Long end1 = System.currentTimeMillis();
  140. //1:获取全量广告组数据
  141. kuaishouInterfaceService.getGroupList(token);
  142. Long end2 = System.currentTimeMillis();
  143. //1:获取全量创意数据
  144. kuaishouInterfaceService.getCreativeList(token);
  145. Long end3 = System.currentTimeMillis();
  146. //2:获取全量视频素材数据
  147. kuaishouInterfaceService.getVideoList(token);
  148. } catch (Exception e) {
  149. e.printStackTrace();
  150. } finally {
  151. countDownLatch.countDown();
  152. }
  153. }
  154. });
  155. });
  156. countDownLatch.await();
  157. System.out.println("数据获取完成");
  158. //关掉线程池
  159. executorService.shutdown();
  160. Long end1 = System.currentTimeMillis();
  161. System.out.println("#######################" + (end1 - start) + "#################");
  162. log.info("物料数据同步完成");
  163. // for (CtopOauthToken token : tokens) {
  164. // kuaishouInterfaceService.getAdvertiserReportHourly(token, getDate, getDate);
  165. // }
  166. // for (CtopOauthToken token : tokens) {
  167. // //2:获取广告计划信息数据
  168. // kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getDate, getDate);
  169. // }
  170. // for (CtopOauthToken token : tokens) {
  171. // //3:获取广告组信息数据
  172. // kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getDate, getDate);
  173. // }
  174. // for (CtopOauthToken token : tokens) {
  175. // //4: 获取广告创意信息数据
  176. // kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate);
  177. // kuaishouInterfaceService.updateCreativeReportHourlyStatistic(token, getDate);
  178. // }
  179. //
  180. // Long end2 = System.currentTimeMillis();
  181. // System.out.println("#######################"+(end2-end1)+"#################");
  182. }
  183. @Autowired
  184. private ICtopOauthTokenService tokenService;
  185. }