SampleTest.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package org.jeecg;
  2. import cn.com.ctop.common.module.entity.BindAccountLogin;
  3. import cn.com.ctop.common.module.entity.CtopOauthToken;
  4. import cn.com.ctop.common.module.entity.UserAllocation;
  5. import cn.com.ctop.common.module.service.IBindAccountLoginService;
  6. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  7. import cn.com.ctop.common.module.service.IUserAllocationService;
  8. import cn.com.ctop.common.module.utils.CtopAdConstant;
  9. import cn.com.ctop.crawler.modules.pangolin.entity.PangolinApp;
  10. import cn.com.ctop.crawler.modules.pangolin.service.PangolinAppService;
  11. import cn.com.ctop.crawler.modules.pangolin.service.PangolinCrawlerService;
  12. import cn.com.ctop.crawler.modules.pangolin.service.PangolinLoginService;
  13. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
  14. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  15. import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
  16. import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
  17. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  18. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.jeecg.common.util.DateUtils;
  21. import org.junit.Test;
  22. import org.junit.runner.RunWith;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.boot.test.context.SpringBootTest;
  25. import org.springframework.test.context.junit4.SpringRunner;
  26. import java.util.Date;
  27. import java.util.HashMap;
  28. import java.util.List;
  29. import java.util.concurrent.CountDownLatch;
  30. import java.util.concurrent.ExecutorService;
  31. import java.util.concurrent.Executors;
  32. @RunWith(SpringRunner.class)
  33. @SpringBootTest
  34. @Slf4j
  35. public class SampleTest {
  36. @Autowired
  37. private IBytedanceReportService bytedanceReportService;
  38. @Autowired
  39. private IByteDanceVideoReportDailyService byteDanceVideoReportDailyService;
  40. @Autowired
  41. private ICtopOauthTokenService oauthTokenService;
  42. @Autowired
  43. private IReportService reportService;
  44. @Autowired
  45. private IUserAllocationService userAllocationService;
  46. @Test
  47. public void testOceanEngineJob() {
  48. List<UserAllocation>tokens = userAllocationService.getByProjectId(107L,null);
  49. Date startDate = DateUtils.getDate();
  50. tokens.forEach(token -> {
  51. CtopOauthToken getToken = oauthTokenService.getTokenByAccountId(token.getAccountId());
  52. reportService.getAdvertiserReport(getToken,startDate,startDate,CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  53. });
  54. }
  55. @Autowired
  56. private IBindAccountLoginService bindAccountLoginService;
  57. @Autowired
  58. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  59. @Test
  60. public void kuaishouLogin() {
  61. Long start = System.currentTimeMillis();
  62. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  63. if (list != null && !list.isEmpty()) {
  64. for (BindAccountLogin login : list) {
  65. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  66. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  67. }
  68. }
  69. }
  70. Long end = System.currentTimeMillis();
  71. log.info("总用时:{}毫秒", end - start);
  72. }
  73. static ExecutorService executorService = null;
  74. static CountDownLatch countDownLatch = null;
  75. @Test
  76. public void kuaishouCommentDelete() {
  77. Long start = System.currentTimeMillis();
  78. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  79. if (list != null && !list.isEmpty()) {
  80. executorService = Executors.newFixedThreadPool(10);
  81. countDownLatch = new CountDownLatch(list.size());
  82. list.forEach(login -> {
  83. executorService.submit(() -> {
  84. try {
  85. if (null != login.getCookie() && !"".equals(login.getCookie().trim())) {
  86. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  87. }
  88. } catch (Exception e) {
  89. } finally {
  90. countDownLatch.countDown();
  91. }
  92. });
  93. });
  94. }
  95. try {
  96. countDownLatch.await();
  97. } catch (InterruptedException e) {
  98. e.printStackTrace();
  99. }
  100. Long end = System.currentTimeMillis();
  101. log.info("总用时:{}毫秒", end - start);
  102. }
  103. @Autowired
  104. private PangolinLoginService pangolinLoginService;
  105. @Autowired
  106. private PangolinCrawlerService pangolinCrawlerService;
  107. @Autowired
  108. private PangolinAppService pangolinAppService;
  109. @Test
  110. public void testPangolinLogin() {
  111. QueryWrapper<BindAccountLogin> queryWrapper = new QueryWrapper<>();
  112. queryWrapper.eq("login_type", "pangolin");
  113. queryWrapper.eq("status", 1);
  114. List<BindAccountLogin> list = bindAccountLoginService.list(queryWrapper);
  115. if (list != null && !list.isEmpty()) {
  116. for (BindAccountLogin login : list) {
  117. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  118. pangolinLoginService.pangolinLogin(login.getAccountName(), login.getPassword());
  119. }
  120. }
  121. }
  122. }
  123. @Test
  124. public void testPangolinData() {
  125. QueryWrapper<BindAccountLogin> queryWrapper = new QueryWrapper<>();
  126. queryWrapper.eq("login_type", "pangolin");
  127. queryWrapper.eq("status", 1);
  128. queryWrapper.isNotNull("cookie");
  129. List<BindAccountLogin> list = bindAccountLoginService.list(queryWrapper);
  130. if (list != null && !list.isEmpty()) {
  131. for (BindAccountLogin bindAccountLogin : list) {
  132. pangolinCrawlerService.getChannelList(bindAccountLogin);
  133. pangolinCrawlerService.getActivationList(bindAccountLogin, DateUtils.getNowDate("yyyy-MM-dd"), 1);
  134. pangolinCrawlerService.getCheckList(bindAccountLogin);
  135. QueryWrapper<PangolinApp> queryWrapper1 = new QueryWrapper<>();
  136. queryWrapper1.eq("account_name", bindAccountLogin.getAccountName());
  137. List<PangolinApp> appList = pangolinAppService.list(queryWrapper1);
  138. if (appList != null && !appList.isEmpty()) {
  139. appList.forEach(pangolinApp -> pangolinCrawlerService.getRealTimeList(bindAccountLogin, pangolinApp.getId()));
  140. }
  141. }
  142. }
  143. }
  144. @Autowired
  145. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  146. @Test
  147. public void testLoadKuaishouData(){
  148. CtopOauthToken token = oauthTokenService.getTokenByAccountId(4801739L);
  149. for(int i=0;i<50;i++){
  150. Date startDate = DateUtils.addDay(new Date(),-(i+30));
  151. dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), DateUtils.formatDate(startDate));
  152. }
  153. }
  154. }