SampleTest.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  10. import cn.com.ctop.kuaishou.modules.report.service.IKuaiShouDailyAgentService;
  11. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
  12. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  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.ActiveProfiles;
  20. import org.springframework.test.context.junit4.SpringRunner;
  21. import java.util.Date;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.concurrent.CountDownLatch;
  25. import java.util.concurrent.ExecutorService;
  26. import java.util.concurrent.Executors;
  27. @RunWith(SpringRunner.class)
  28. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  29. @ActiveProfiles("wps")
  30. @Slf4j
  31. public class SampleTest {
  32. @Autowired
  33. private ICtopOauthTokenService oauthTokenService;
  34. @Autowired
  35. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  36. @Autowired
  37. private IKuaiShouDailyAgentService kuaiShouDailyAgentService;
  38. @Autowired
  39. private IReportService reportService;
  40. @Test
  41. public void loadBytedanceCreativeData() {
  42. String accountIdString = "1661556811389966,1650504410207245,1652711697337351,1652711697724429,1650504410574859,1668459522250759";
  43. String[] accountIds = accountIdString.split(",");
  44. for(int i=0;i<accountIds.length;i++){
  45. CtopOauthToken token = oauthTokenService.getTokenByAccountId(Long.parseLong(accountIds[i]));
  46. reportService.getAdvertiserPlanReport(token,new Date(),new Date(),CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  47. }
  48. }
  49. @Autowired
  50. private IBindAccountLoginService bindAccountLoginService;
  51. @Autowired
  52. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  53. @Test
  54. public void loadKuaishouCookie(){
  55. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY,1);
  56. if(list!=null&&!list.isEmpty()){
  57. int i=0;
  58. for (BindAccountLogin login:list) {
  59. if(null==login.getCookie()||"".equals(login.getCookie().trim())){
  60. if(i>5){
  61. break;
  62. }
  63. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  64. i++;
  65. }
  66. }
  67. }
  68. }
  69. static ExecutorService executorService = null;
  70. //线程计数器
  71. static CountDownLatch countDownLatch = null;
  72. @Test
  73. public void deleteKuaishouComment(){
  74. Long start = System.currentTimeMillis();
  75. List<BindAccountLogin>loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY,1);
  76. if (loginList != null && !loginList.isEmpty()) {
  77. executorService = Executors.newFixedThreadPool(5);
  78. countDownLatch = new CountDownLatch(loginList.size());
  79. loginList.forEach(login -> executorService.submit(()->{
  80. try {
  81. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(),login);
  82. }catch (Exception e){
  83. log.error(e.getMessage(),e);
  84. }finally {
  85. countDownLatch.countDown();
  86. }
  87. }));
  88. try {
  89. countDownLatch.await();
  90. } catch (InterruptedException e) {
  91. e.printStackTrace();
  92. }
  93. Long end = System.currentTimeMillis();
  94. log.info("快手删评论所用时长:{}毫秒",end-start);
  95. }
  96. }
  97. @Autowired
  98. private IUserAllocationService allocationService;
  99. @Test
  100. public void testLoadBytedanceData() {
  101. List<UserAllocation>allocations = allocationService.getByParams(435L,null,0);
  102. for (UserAllocation allocation:allocations) {
  103. for(int i=2;i<10;i++){
  104. CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId());
  105. Date getDate = DateUtils.addDay(new Date(),-i);
  106. reportService.getAdvertiserReport(token,getDate,getDate,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  107. }
  108. }
  109. }
  110. @Test
  111. public void loadKuaishouAgentData() {
  112. // for(int i=0;i<20;i++){
  113. // String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(),-i));
  114. // kuaishouReportDailyAgentService.getReport(currentDate,DateUtils.getNowDate("yyyy-MM-dd"));
  115. // }
  116. //
  117. kuaishouReportDailyAgentService.loginAgent();
  118. try {
  119. for(int i=1;i<30;i++){
  120. kuaishouReportDailyAgentService.getAccount(i);
  121. }
  122. }catch (Exception e){
  123. e.printStackTrace();
  124. }
  125. // String currentDate = D ateUtils.formatDate(DateUtils.addDay(new Date(),-1));
  126. // kuaishouReportDailyAgentService.getReport(currentDate,DateUtils.getNowDate("yyyy-MM-dd"));
  127. }
  128. }