SampleTest.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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.service.IBindAccountLoginService;
  5. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  6. import cn.com.ctop.common.module.utils.CtopAdConstant;
  7. import cn.com.ctop.crawler.modules.pangolin.entity.PangolinApp;
  8. import cn.com.ctop.crawler.modules.pangolin.service.PangolinAppService;
  9. import cn.com.ctop.crawler.modules.pangolin.service.PangolinCrawlerService;
  10. import cn.com.ctop.crawler.modules.pangolin.service.PangolinLoginService;
  11. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  12. import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
  13. import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
  14. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.jeecg.common.util.DateUtils;
  17. import org.junit.Test;
  18. import org.junit.runner.RunWith;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.boot.test.context.SpringBootTest;
  21. import org.springframework.test.context.junit4.SpringRunner;
  22. import java.text.SimpleDateFormat;
  23. import java.util.Date;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.concurrent.CountDownLatch;
  27. import java.util.concurrent.ExecutorService;
  28. import java.util.concurrent.Executors;
  29. @RunWith(SpringRunner.class)
  30. @SpringBootTest
  31. @Slf4j
  32. public class SampleTest {
  33. @Autowired
  34. private IBytedanceReportService bytedanceReportService;
  35. @Autowired
  36. private IByteDanceVideoReportDailyService byteDanceVideoReportDailyService;
  37. @Autowired
  38. private ICtopOauthTokenService oauthTokenService;
  39. @Test
  40. public void testOceanEngineJob() {
  41. try {
  42. CtopOauthToken byId = oauthTokenService.getById(303094936123368L);
  43. String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
  44. String endDate = DateUtils.addDay(nowDate, -180);
  45. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  46. Date start = simpleDateFormat.parse(nowDate);
  47. Date end = simpleDateFormat.parse(endDate);
  48. List<Date> dates = DateUtils.findDates(end,start);
  49. for (int i = 0; i < dates.size(); i++) {
  50. String formatDate = simpleDateFormat.format(dates.get(i));
  51. int code = bytedanceReportService.bytedanceMaterialReport(byId, formatDate, formatDate);
  52. //如果成功的话跑视频清洗数据方法,失败会进入重试库,重试成功后再清洗数据
  53. if (code == 200 || code == 1) {
  54. byteDanceVideoReportDailyService.videoInfoListByAccountId(formatDate, formatDate, byId.getAccountId());
  55. }
  56. }
  57. } catch (Exception e) {
  58. e.printStackTrace();
  59. }
  60. String account = "3248395570@qq.com";
  61. /* String password = "Ydxq-704127411";
  62. oceanEngineService.login(account,password);
  63. oceanEngineService.douyinHotHandler(1,1);
  64. oceanEngineService.effectCaseHandler(1);
  65. oceanEngineService.hotMaterialHandler(1,4,"抖音");
  66. oceanEngineService.hotMaterialHandler(1,8,"头条");
  67. oceanEngineService.hotMaterialHandler(1,1,"西瓜");
  68. oceanEngineService.hotMaterialHandler(1,3,"火山");
  69. oceanEngineService.hotMaterialHandler(1,9,"穿山甲");
  70. log.info("巨量创意抓取完成");*/
  71. }
  72. @Autowired
  73. private IBindAccountLoginService bindAccountLoginService;
  74. @Autowired
  75. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  76. @Test
  77. public void kuaishouLogin() {
  78. Long start = System.currentTimeMillis();
  79. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  80. if (list != null && !list.isEmpty()) {
  81. for (BindAccountLogin login : list) {
  82. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  83. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  84. }
  85. }
  86. }
  87. Long end = System.currentTimeMillis();
  88. log.info("总用时:{}毫秒", end - start);
  89. }
  90. static ExecutorService executorService = null;
  91. static CountDownLatch countDownLatch = null;
  92. @Test
  93. public void kuaishouCommentDelete() {
  94. Long start = System.currentTimeMillis();
  95. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  96. if (list != null && !list.isEmpty()) {
  97. executorService = Executors.newFixedThreadPool(10);
  98. countDownLatch = new CountDownLatch(list.size());
  99. list.forEach(login -> {
  100. executorService.submit(() -> {
  101. try {
  102. if (null != login.getCookie() && !"".equals(login.getCookie().trim())) {
  103. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  104. }
  105. } catch (Exception e) {
  106. } finally {
  107. countDownLatch.countDown();
  108. }
  109. });
  110. });
  111. }
  112. try {
  113. countDownLatch.await();
  114. } catch (InterruptedException e) {
  115. e.printStackTrace();
  116. }
  117. Long end = System.currentTimeMillis();
  118. log.info("总用时:{}毫秒", end - start);
  119. }
  120. @Autowired
  121. private PangolinLoginService pangolinLoginService;
  122. @Autowired
  123. private PangolinCrawlerService pangolinCrawlerService;
  124. @Autowired
  125. private PangolinAppService pangolinAppService;
  126. @Test
  127. public void testPangolinLogin(){
  128. QueryWrapper<BindAccountLogin> queryWrapper = new QueryWrapper<>();
  129. queryWrapper.eq("login_type","pangolin");
  130. queryWrapper.eq("status",1);
  131. List<BindAccountLogin> list = bindAccountLoginService.list(queryWrapper);
  132. if(list!=null&&!list.isEmpty()){
  133. for (BindAccountLogin login:list) {
  134. if(null==login.getCookie()||"".equals(login.getCookie().trim())){
  135. pangolinLoginService.pangolinLogin(login.getAccountName(), login.getPassword());
  136. }
  137. }
  138. }
  139. }
  140. @Test
  141. public void testPangolinData(){
  142. QueryWrapper<BindAccountLogin> queryWrapper = new QueryWrapper<>();
  143. queryWrapper.eq("login_type", "pangolin");
  144. queryWrapper.eq("status", 1);
  145. queryWrapper.isNotNull("cookie");
  146. List<BindAccountLogin> list = bindAccountLoginService.list(queryWrapper);
  147. if (list != null && !list.isEmpty()) {
  148. for (BindAccountLogin bindAccountLogin : list) {
  149. pangolinCrawlerService.getChannelList(bindAccountLogin);
  150. pangolinCrawlerService.getActivationList(bindAccountLogin, DateUtils.getNowDate("yyyy-MM-dd"), 1);
  151. pangolinCrawlerService.getCheckList(bindAccountLogin);
  152. QueryWrapper<PangolinApp> queryWrapper1 = new QueryWrapper<>();
  153. queryWrapper1.eq("account_name", bindAccountLogin.getAccountName());
  154. List<PangolinApp> appList = pangolinAppService.list(queryWrapper1);
  155. if (appList != null && !appList.isEmpty()) {
  156. appList.forEach(pangolinApp -> pangolinCrawlerService.getRealTimeList(bindAccountLogin, pangolinApp.getId()));
  157. }
  158. }
  159. }
  160. }
  161. }