SampleTest.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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.batch.service.IKuaiShouDailyReportTaskService;
  13. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
  14. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  15. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
  16. import cn.com.ctop.oa.modules.service.IWechatDepartmentService;
  17. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  18. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  19. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  20. import lombok.extern.slf4j.Slf4j;
  21. import org.jeecg.common.util.DateUtils;
  22. import org.junit.Test;
  23. import org.junit.runner.RunWith;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.boot.test.context.SpringBootTest;
  26. import org.springframework.test.context.ActiveProfiles;
  27. import org.springframework.test.context.junit4.SpringRunner;
  28. import java.io.File;
  29. import java.util.Date;
  30. import java.util.HashMap;
  31. import java.util.List;
  32. import java.util.concurrent.CountDownLatch;
  33. import java.util.concurrent.ExecutorService;
  34. import java.util.concurrent.Executors;
  35. @RunWith(SpringRunner.class)
  36. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  37. @ActiveProfiles("wps")
  38. @Slf4j
  39. public class SampleTest {
  40. @Autowired
  41. private ICtopOauthTokenService oauthTokenService;
  42. @Autowired
  43. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  44. @Autowired
  45. private IReportService reportService;
  46. @Autowired
  47. private IUserAllocationService userAllocationService;
  48. @Autowired
  49. private IByteDanceAdvertiserDataService advertiserDataService;
  50. @Autowired
  51. private IKuaiShouHistoryReportTaskService kuaiShouHistoryReportTaskService;
  52. @Autowired
  53. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  54. @Autowired
  55. private IWechatDepartmentService wechatDepartment;
  56. @Test
  57. public void getDepartment() {
  58. wechatDepartment.getDepartment();
  59. }
  60. @Test
  61. public void loadBytedanceCreativeData() {
  62. QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  63. queryWrapper.eq("media_id", 2);
  64. List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
  65. for (CtopOauthToken token : list) {
  66. kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-03-09", "2020-09-08", "history");
  67. }
  68. }
  69. @Test
  70. public void getTaskList() {
  71. kuaiShouHistoryReportTaskService.getTaskList();
  72. }
  73. @Autowired
  74. private IBindAccountLoginService bindAccountLoginService;
  75. @Autowired
  76. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  77. @Test
  78. public void loadKuaishouCookie() {
  79. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  80. if (list != null && !list.isEmpty()) {
  81. int i = 0;
  82. for (BindAccountLogin login : list) {
  83. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  84. if (i > 5) {
  85. break;
  86. }
  87. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  88. i++;
  89. }
  90. }
  91. }
  92. }
  93. static ExecutorService executorService = null;
  94. //线程计数器
  95. static CountDownLatch countDownLatch = null;
  96. @Test
  97. public void deleteKuaishouComment() {
  98. Long start = System.currentTimeMillis();
  99. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  100. if (loginList != null && !loginList.isEmpty()) {
  101. executorService = Executors.newFixedThreadPool(5);
  102. countDownLatch = new CountDownLatch(loginList.size());
  103. loginList.forEach(login -> executorService.submit(() -> {
  104. try {
  105. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  106. } catch (Exception e) {
  107. log.error(e.getMessage(), e);
  108. } finally {
  109. countDownLatch.countDown();
  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. }
  121. @Autowired
  122. private IUserAllocationService allocationService;
  123. @Test
  124. public void testLoadBytedanceData() {
  125. List<UserAllocation> allocations = allocationService.getByParams(435L, null, 0);
  126. for (UserAllocation allocation : allocations) {
  127. for (int i = 2; i < 10; i++) {
  128. CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId());
  129. Date getDate = DateUtils.addDay(new Date(), -i);
  130. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  131. }
  132. }
  133. }
  134. @Test
  135. public void loadKuaishouAgentData() {
  136. kuaishouReportDailyAgentService.loginAgent();
  137. for (int i = 0; i < 20; i++) {
  138. String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -i));
  139. kuaishouReportDailyAgentService.getReport(currentDate, DateUtils.getNowDate("yyyy-MM-dd"));
  140. }
  141. //
  142. // try {
  143. // for (int i = 1; i < 30; i++) {
  144. // kuaishouReportDailyAgentService.getAccount(i);
  145. // }
  146. // } catch (Exception e) {
  147. // e.printStackTrace();
  148. // }
  149. }
  150. @Autowired
  151. private GroovyScriptExecutor groovyScriptExecutor;
  152. @Autowired
  153. private ICtopCheckTaskListService checkTaskListService;
  154. @Test
  155. public void checkDataStateJobTest() {
  156. //查询需要检查的任务列表
  157. List<CtopCheckTaskList> ctopCheckTaskList = checkTaskListService.queryExecuteList("checkDataStateJob");
  158. if (ctopCheckTaskList != null) {
  159. ctopCheckTaskList.forEach(it -> groovyScriptExecutor.execute(it));
  160. }
  161. }
  162. @Test
  163. public void loadAccountData() {
  164. CtopOauthToken token = oauthTokenService.getTokenByAccountId(1665922219192387L);
  165. reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-09-01", "yy-MM-dd"), DateUtils.parseDate("2020-09-01", "yy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  166. }
  167. @Autowired
  168. IUReportExportService uReportExportService;
  169. @Autowired
  170. EmailSendMsgHandle emailSendMsgHandle;
  171. @Autowired
  172. IUReportService uReportService;
  173. @Test
  174. public void sendUReport() {
  175. uReportService.uReportList().forEach(uReport -> {
  176. List<UReportSubscriber> uReportSubscriber = uReportService.getUReportSubscriberByFileId(uReport.getString("id"));
  177. if (!uReportSubscriber.isEmpty()) {
  178. String title = uReport.getString("name").replace(".ureport.xml", "");
  179. String content = "您订阅的日报在附件中请注意查收》》》";
  180. //下载文件到本地
  181. uReportExportService.exportExcel(uReport.getString("name"));
  182. uReportSubscriber.forEach(sender -> {
  183. emailSendMsgHandle.SendAttachment("bijiequan@c-top.com.cn", title, content,
  184. new File(System.getProperty("user.dir") + File.separator + "uReport" + File.separator + uReport.getString("name").replace("ureport.xml", "") + "xlsx"));
  185. });
  186. }
  187. });
  188. //发完全部订阅,删除文件
  189. File file = new File(System.getProperty("user.dir") + File.separator + "uReport");
  190. File[] files = file.listFiles();
  191. if (files != null && files.length > 0) {
  192. for (File f : files) {
  193. f.delete();
  194. }
  195. }
  196. }
  197. }