SampleTest.java 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  17. import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
  18. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  19. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  20. import com.xxl.job.core.biz.model.ReturnT;
  21. import com.xxl.job.core.log.XxlJobLogger;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.jeecg.common.constant.SystemDateConstant;
  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("test")
  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. @Test
  58. public void loadBytedanceCreativeData() {
  59. QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  60. queryWrapper.eq("media_id", 2);
  61. List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
  62. // for (CtopOauthToken token : list) {
  63. kuaiShouHistoryReportTaskService.createTask(1872430L, "9cd4d43ea697ad9f2aa91fc0f4b921e5", "2020-03-15", "2020-09-15", "history");
  64. // }
  65. }
  66. @Test
  67. public void getTaskList() {
  68. kuaiShouHistoryReportTaskService.getTaskList();
  69. }
  70. @Autowired
  71. private IBindAccountLoginService bindAccountLoginService;
  72. @Autowired
  73. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  74. @Test
  75. public void loadKuaishouCookie() {
  76. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  77. if (list != null && !list.isEmpty()) {
  78. int i = 0;
  79. for (BindAccountLogin login : list) {
  80. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  81. if (i > 5) {
  82. break;
  83. }
  84. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  85. i++;
  86. }
  87. }
  88. }
  89. }
  90. static ExecutorService executorService = null;
  91. //线程计数器/bytedance/bytedanceMaterialReport
  92. static CountDownLatch countDownLatch = null;
  93. @Test
  94. public void deleteKuaishouComment() {
  95. Long start = System.currentTimeMillis();
  96. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  97. if (loginList != null && !loginList.isEmpty()) {
  98. executorService = Executors.newFixedThreadPool(5);
  99. countDownLatch = new CountDownLatch(loginList.size());
  100. loginList.forEach(login -> executorService.submit(() -> {
  101. try {
  102. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  103. } catch (Exception e) {
  104. log.error(e.getMessage(), e);
  105. } finally {
  106. countDownLatch.countDown();
  107. }
  108. }));
  109. try {
  110. countDownLatch.await();
  111. } catch (InterruptedException e) {
  112. e.printStackTrace();
  113. }
  114. Long end = System.currentTimeMillis();
  115. log.info("快手删评论所用时长:{}毫秒", end - start);
  116. }
  117. }
  118. @Autowired
  119. private IUserAllocationService allocationService;
  120. @Test
  121. public void testLoadBytedanceData() {
  122. List<UserAllocation> allocations = allocationService.getByParams(435L, null, 0);
  123. for (UserAllocation allocation : allocations) {
  124. for (int i = 2; i < 10; i++) {
  125. CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId());
  126. Date getDate = DateUtils.addDay(new Date(), -i);
  127. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  128. }
  129. }
  130. }
  131. @Test
  132. public void loadKuaishouAgentData() {
  133. kuaishouReportDailyAgentService.loginAgent();
  134. for (int i = 0; i < 20; i++) {
  135. String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -i));
  136. kuaishouReportDailyAgentService.getReport(currentDate, DateUtils.getNowDate("yyyy-MM-dd"));
  137. }
  138. //
  139. // try {
  140. // for (int i = 1; i < 30; i++) {
  141. // kuaishouReportDailyAgentService.getAccount(i);
  142. // }
  143. // } catch (Exception e) {
  144. // e.printStackTrace();
  145. // }
  146. }
  147. @Autowired
  148. private GroovyScriptExecutor groovyScriptExecutor;
  149. @Autowired
  150. private ICtopCheckTaskListService checkTaskListService;
  151. @Test
  152. public void checkDataStateJobTest() {
  153. //查询需要检查的任务列表
  154. List<CtopCheckTaskList> ctopCheckTaskList = checkTaskListService.queryExecuteList("checkDataStateJob");
  155. if (ctopCheckTaskList != null) {
  156. ctopCheckTaskList.forEach(it -> groovyScriptExecutor.execute(it));
  157. }
  158. }
  159. @Test
  160. public void loadAccountData() {
  161. CtopOauthToken token = oauthTokenService.getTokenByAccountId(1665922219192387L);
  162. reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-09-01", "yy-MM-dd"), DateUtils.parseDate("2020-09-01", "yy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  163. }
  164. @Autowired
  165. private ICtopOauthTokenService tokenService;
  166. @Test
  167. public void loadAllHourReport(){
  168. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  169. String getDate="2020-09-27";
  170. tokens.forEach(token -> {
  171. reportService.getAdvertiserReport(token, DateUtils.parseDate(getDate, SystemDateConstant.yyyy_MM_dd), DateUtils.parseDate(getDate, SystemDateConstant.yyyy_MM_dd), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  172. });
  173. }
  174. @Autowired
  175. IUReportExportService uReportExportService;
  176. @Autowired
  177. EmailSendMsgHandle emailSendMsgHandle;
  178. @Autowired
  179. IUReportService uReportService;
  180. @Test
  181. public void sendUReport() {
  182. uReportService.uReportList().forEach(uReport -> {
  183. List<UReportSubscriber> uReportSubscriber = uReportService.getUReportSubscriberByFileId(uReport.getString("id"));
  184. if (!uReportSubscriber.isEmpty()) {
  185. String title = uReport.getString("name").replace(".ureport.xml", "");
  186. String content = "您订阅的日报在附件中请注意查收》》》";
  187. //下载文件到本地
  188. uReportExportService.exportExcel(uReport.getString("name"));
  189. uReportSubscriber.forEach(sender -> {
  190. emailSendMsgHandle.SendAttachment("bijiequan@c-top.com.cn", title, content,
  191. new File(System.getProperty("user.dir") + File.separator + "uReport" + File.separator + uReport.getString("name").replace("ureport.xml", "") + "xlsx"));
  192. });
  193. }
  194. });
  195. //发完全部订阅,删除文件
  196. File file = new File(System.getProperty("user.dir") + File.separator + "uReport");
  197. File[] files = file.listFiles();
  198. if (files != null && files.length > 0) {
  199. for (File f : files) {
  200. f.delete();
  201. }
  202. }
  203. }
  204. @Autowired
  205. IBytedanceReportService bytedanceReportService;
  206. //头条素材报表拉数据
  207. @Test
  208. public void getMaterialReportByDate() {
  209. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  210. String startDate="2020-09-29";
  211. String endDate="2020-09-29";
  212. tokens.forEach(token -> {
  213. try {
  214. //获取头条素材报表数据
  215. XxlJobLogger.log("账户" + token.getAccountId() + "素材报表数据任务开始,任务时间:" +new Date());
  216. bytedanceReportService.bytedanceMaterialReport(token, startDate, endDate);
  217. XxlJobLogger.log("账户" + token.getAccountId() + "素材报表数据任务完成,任务时间:" + new Date());
  218. } catch (Exception e) {
  219. e.printStackTrace();
  220. } finally {
  221. }
  222. });
  223. }
  224. }