SampleTest.java 9.2 KB

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