SampleTest.java 7.3 KB

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