SampleTest.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package org.jeecg;
  2. import cn.com.ctop.check.component.execute.GroovyScriptExecutor;
  3. import cn.com.ctop.check.entity.CtopCheckTaskList;
  4. import cn.com.ctop.check.service.ICtopCheckTaskListService;
  5. import cn.com.ctop.common.module.entity.BindAccountLogin;
  6. import cn.com.ctop.common.module.entity.CtopOauthToken;
  7. import cn.com.ctop.common.module.entity.UReportSubscriber;
  8. import cn.com.ctop.common.module.entity.UserAllocation;
  9. import cn.com.ctop.common.module.message.handle.impl.EmailSendMsgHandle;
  10. import cn.com.ctop.common.module.service.*;
  11. import cn.com.ctop.common.module.utils.CtopAdConstant;
  12. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  13. import cn.com.ctop.kuaishou.modules.report.service.IKuaiShouDailyAgentService;
  14. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
  15. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  16. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.jeecg.common.util.DateUtils;
  19. import org.junit.Test;
  20. import org.junit.runner.RunWith;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.boot.test.context.SpringBootTest;
  23. import org.springframework.test.context.ActiveProfiles;
  24. import org.springframework.test.context.junit4.SpringRunner;
  25. import java.io.File;
  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(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  34. @ActiveProfiles("wps")
  35. @Slf4j
  36. public class SampleTest {
  37. @Autowired
  38. private ICtopOauthTokenService oauthTokenService;
  39. @Autowired
  40. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  41. @Autowired
  42. private IKuaiShouDailyAgentService kuaiShouDailyAgentService;
  43. @Autowired
  44. private IReportService reportService;
  45. @Autowired
  46. private IByteDanceAdvertiserDataService byteDanceAdvertiserDataService;
  47. @Test
  48. public void loadBytedanceCreativeData() {
  49. byteDanceAdvertiserDataService.advertiserList("2093115cd521740b024a5811d361712e0b5c3303");
  50. }
  51. @Autowired
  52. private IBindAccountLoginService bindAccountLoginService;
  53. @Autowired
  54. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  55. @Test
  56. public void loadKuaishouCookie() {
  57. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  58. if (list != null && !list.isEmpty()) {
  59. int i = 0;
  60. for (BindAccountLogin login : list) {
  61. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  62. if (i > 5) {
  63. break;
  64. }
  65. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  66. i++;
  67. }
  68. }
  69. }
  70. }
  71. static ExecutorService executorService = null;
  72. //线程计数器
  73. static CountDownLatch countDownLatch = null;
  74. @Test
  75. public void deleteKuaishouComment() {
  76. Long start = System.currentTimeMillis();
  77. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  78. if (loginList != null && !loginList.isEmpty()) {
  79. executorService = Executors.newFixedThreadPool(5);
  80. countDownLatch = new CountDownLatch(loginList.size());
  81. loginList.forEach(login -> executorService.submit(() -> {
  82. try {
  83. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  84. } catch (Exception e) {
  85. log.error(e.getMessage(), e);
  86. } finally {
  87. countDownLatch.countDown();
  88. }
  89. }));
  90. try {
  91. countDownLatch.await();
  92. } catch (InterruptedException e) {
  93. e.printStackTrace();
  94. }
  95. Long end = System.currentTimeMillis();
  96. log.info("快手删评论所用时长:{}毫秒", end - start);
  97. }
  98. }
  99. @Autowired
  100. private IUserAllocationService allocationService;
  101. @Test
  102. public void testLoadBytedanceData() {
  103. List<UserAllocation> allocations = allocationService.getByParams(435L, null, 0);
  104. for (UserAllocation allocation : allocations) {
  105. for (int i = 2; i < 10; i++) {
  106. CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId());
  107. Date getDate = DateUtils.addDay(new Date(), -i);
  108. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  109. }
  110. }
  111. }
  112. @Test
  113. public void loadKuaishouAgentData() {
  114. // for(int i=0;i<20;i++){
  115. // String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(),-i));
  116. // kuaishouReportDailyAgentService.getReport(currentDate,DateUtils.getNowDate("yyyy-MM-dd"));
  117. // }
  118. //
  119. kuaishouReportDailyAgentService.loginAgent();
  120. try {
  121. for (int i = 1; i < 30; i++) {
  122. kuaishouReportDailyAgentService.getAccount(i);
  123. }
  124. } catch (Exception e) {
  125. e.printStackTrace();
  126. }
  127. // String currentDate = D ateUtils.formatDate(DateUtils.addDay(new Date(),-1));
  128. // kuaishouReportDailyAgentService.getReport(currentDate,DateUtils.getNowDate("yyyy-MM-dd"));
  129. }
  130. @Autowired
  131. private GroovyScriptExecutor groovyScriptExecutor;
  132. @Autowired
  133. private ICtopCheckTaskListService checkTaskListService;
  134. @Test
  135. public void checkDataStateJobTest() {
  136. //查询需要检查的任务列表
  137. List<CtopCheckTaskList> ctopCheckTaskList = checkTaskListService.queryExecuteList("checkDataStateJob");
  138. if (ctopCheckTaskList != null) {
  139. ctopCheckTaskList.forEach(it -> groovyScriptExecutor.execute(it));
  140. }
  141. }
  142. @Test
  143. public void loadAccountData() {
  144. CtopOauthToken token = oauthTokenService.getTokenByAccountId(1665922219192387L);
  145. reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-09-01", "yy-MM-dd"), DateUtils.parseDate("2020-09-01", "yy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  146. }
  147. @Autowired
  148. IUReportExportService uReportExportService;
  149. @Autowired
  150. EmailSendMsgHandle emailSendMsgHandle;
  151. @Autowired
  152. IUReportService uReportService;
  153. @Test
  154. public void sendUReport() {
  155. uReportService.uReportList().forEach(uReport -> {
  156. List<UReportSubscriber> uReportSubscriber = uReportService.getUReportSubscriberByFileId(uReport.getString("id"));
  157. if (!uReportSubscriber.isEmpty()) {
  158. String title = uReport.getString("name").replace(".ureport.xml", "");
  159. String content = "您订阅的日报在附件中请注意查收》》》";
  160. //下载文件到本地
  161. uReportExportService.exportExcel(uReport.getString("name"));
  162. uReportSubscriber.forEach(sender -> {
  163. emailSendMsgHandle.SendAttachment("bijiequan@c-top.com.cn", title, content,
  164. new File(System.getProperty("user.dir") + File.separator + "uReport" + File.separator + uReport.getString("name").replace("ureport.xml", "") + "xlsx"));
  165. });
  166. }
  167. });
  168. //发完全部订阅,删除文件
  169. File file = new File(System.getProperty("user.dir") + File.separator + "uReport");
  170. File[] files = file.listFiles();
  171. if (files != null && files.length > 0) {
  172. for (File f : files) {
  173. f.delete();
  174. }
  175. }
  176. }
  177. }