SampleTest.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.oceanengine.entity.HotMaterial;
  8. import cn.com.ctop.crawler.modules.oceanengine.service.IHotMaterialService;
  9. import cn.com.ctop.crawler.modules.oceanengine.service.IOceanEngineService;
  10. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  11. import cn.com.ctop.toutiao.modules.report.service.IBytedanceFundDailyService;
  12. import com.xxl.job.core.log.XxlJobLogger;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.jeecg.common.util.DateUtils;
  15. import org.junit.Test;
  16. import org.junit.runner.RunWith;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.boot.test.context.SpringBootTest;
  19. import org.springframework.test.context.junit4.SpringRunner;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.concurrent.CountDownLatch;
  23. import java.util.concurrent.ExecutorService;
  24. import java.util.concurrent.Executors;
  25. @RunWith(SpringRunner.class)
  26. @SpringBootTest
  27. @Slf4j
  28. public class SampleTest {
  29. @Autowired
  30. private IOceanEngineService oceanEngineService;
  31. @Autowired
  32. private IHotMaterialService hotMaterialService;
  33. @Test
  34. public void initImageUrl(){
  35. List<HotMaterial> hotMaterials = hotMaterialService.getId();
  36. if(null!=hotMaterials&&!hotMaterials.isEmpty()){
  37. hotMaterials.forEach(douyinHot -> {
  38. HotMaterial getHot = hotMaterialService.getById(douyinHot.getId());
  39. // String image = getHot.getCoverImage().replace("data:image/jpg;base64,", "");
  40. String destPath = "D:\\data\\effectCase\\";
  41. String fileName = getHot.getId()+".jpg";
  42. // EffectCase.base64ToFile(destPath,image,fileName);
  43. });
  44. }
  45. }
  46. @Test
  47. public void testOceanEngineJob(){
  48. String account="3248395570@qq.com";
  49. String password = "Ydxq-704127411";
  50. oceanEngineService.login(account,password);
  51. oceanEngineService.douyinHotHandler(1,1);
  52. oceanEngineService.effectCaseHandler(1);
  53. oceanEngineService.hotMaterialHandler(1,4,"抖音");
  54. oceanEngineService.hotMaterialHandler(1,8,"头条");
  55. oceanEngineService.hotMaterialHandler(1,1,"西瓜");
  56. oceanEngineService.hotMaterialHandler(1,3,"火山");
  57. oceanEngineService.hotMaterialHandler(1,9,"穿山甲");
  58. log.info("巨量创意抓取完成");
  59. }
  60. @Autowired
  61. private IBindAccountLoginService bindAccountLoginService;
  62. @Autowired
  63. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  64. @Test
  65. public void kuaishouLogin(){
  66. Long start =System.currentTimeMillis();
  67. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY,1);
  68. if(list!=null&&!list.isEmpty()){
  69. for (BindAccountLogin login:list) {
  70. if(null==login.getCookie()||"".equals(login.getCookie().trim())){
  71. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  72. }
  73. }
  74. }
  75. Long end = System.currentTimeMillis();
  76. log.info("总用时:{}毫秒",end-start);
  77. }
  78. static ExecutorService executorService = null;
  79. static CountDownLatch countDownLatch = null;
  80. @Test
  81. public void kuaishouCommentDelete(){
  82. Long start =System.currentTimeMillis();
  83. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY,1);
  84. if(list!=null&&!list.isEmpty()){
  85. executorService = Executors.newFixedThreadPool(10);
  86. countDownLatch = new CountDownLatch(list.size());
  87. list.forEach(login -> {
  88. executorService.submit(()->{
  89. try {
  90. if(null!=login.getCookie()&&!"".equals(login.getCookie().trim())){
  91. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(),login);
  92. }
  93. }catch (Exception e){
  94. }finally {
  95. countDownLatch.countDown();
  96. }
  97. });
  98. });
  99. }
  100. try {
  101. countDownLatch.await();
  102. } catch (InterruptedException e) {
  103. e.printStackTrace();
  104. }
  105. Long end = System.currentTimeMillis();
  106. log.info("总用时:{}毫秒",end-start);
  107. }
  108. @Autowired
  109. private ICtopOauthTokenService tokenService;
  110. @Autowired
  111. private IBytedanceFundDailyService bytedanceFundDailyService;
  112. @Test
  113. public void testBase64(){
  114. List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
  115. if (null == tokens || tokens.size() <= 0) {
  116. XxlJobLogger.log("头条账户流水数据异常:未获取到可用的token");
  117. return ;
  118. }
  119. executorService = Executors.newFixedThreadPool(4);
  120. countDownLatch = new CountDownLatch(tokens.size());
  121. tokens.forEach(token -> {
  122. executorService.submit(() -> {
  123. try {
  124. for(int i=0;i<12;i++){
  125. String getDate = DateUtils.addDay("2020-05-28",-i);
  126. bytedanceFundDailyService.loadFundDataByPage(token, getDate, getDate,1);
  127. }
  128. }catch (Exception e){
  129. }finally {
  130. countDownLatch.countDown();
  131. }
  132. });
  133. });
  134. try {
  135. countDownLatch.await();
  136. } catch (InterruptedException e) {
  137. }
  138. System.out.println("执行完成");
  139. }
  140. }