SampleTest.java 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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.UserAllocation;
  8. import cn.com.ctop.common.module.message.handle.impl.EmailSendMsgHandle;
  9. import cn.com.ctop.common.module.service.*;
  10. import cn.com.ctop.common.module.utils.CtopAdConstant;
  11. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
  12. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  13. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
  14. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  15. import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
  16. import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
  17. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  18. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  19. import com.xxl.job.core.log.XxlJobLogger;
  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.util.Date;
  29. import java.util.HashMap;
  30. import java.util.List;
  31. import java.util.concurrent.CountDownLatch;
  32. import java.util.concurrent.ExecutorService;
  33. import java.util.concurrent.Executors;
  34. @RunWith(SpringRunner.class)
  35. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  36. @ActiveProfiles("wps")
  37. @Slf4j
  38. public class SampleTest {
  39. @Autowired
  40. private ICtopOauthTokenService oauthTokenService;
  41. @Autowired
  42. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  43. @Autowired
  44. private IReportService reportService;
  45. @Autowired
  46. private IByteDanceAdvertiserDataService advertiserDataService;
  47. @Autowired
  48. private IKuaiShouHistoryReportTaskService kuaiShouHistoryReportTaskService;
  49. @Autowired
  50. private ICtopOauthTokenService tokenService;
  51. @Test
  52. public void loadBytedanceCreativeData() {
  53. QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  54. queryWrapper.eq("media_id", 2);
  55. List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
  56. for (CtopOauthToken token : list) {
  57. kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-20", "2020-09-20", "daily");
  58. }
  59. }
  60. @Test
  61. public void getTaskList() {
  62. kuaiShouHistoryReportTaskService.getTaskList();
  63. }
  64. @Autowired
  65. private IBindAccountLoginService bindAccountLoginService;
  66. @Autowired
  67. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  68. @Test
  69. public void loadKuaishouCookie() {
  70. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  71. if (list != null && !list.isEmpty()) {
  72. int i = 0;
  73. for (BindAccountLogin login : list) {
  74. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  75. if (i > 5) {
  76. break;
  77. }
  78. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  79. i++;
  80. }
  81. }
  82. }
  83. }
  84. static ExecutorService executorService = null;
  85. //线程计数器/bytedance/bytedanceMaterialReport
  86. static CountDownLatch countDownLatch = null;
  87. @Test
  88. public void deleteKuaishouComment() {
  89. Long start = System.currentTimeMillis();
  90. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  91. if (loginList != null && !loginList.isEmpty()) {
  92. executorService = Executors.newFixedThreadPool(5);
  93. countDownLatch = new CountDownLatch(loginList.size());
  94. loginList.forEach(login -> executorService.submit(() -> {
  95. try {
  96. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  97. } catch (Exception e) {
  98. log.error(e.getMessage(), e);
  99. } finally {
  100. countDownLatch.countDown();
  101. }
  102. }));
  103. try {
  104. countDownLatch.await();
  105. } catch (InterruptedException e) {
  106. e.printStackTrace();
  107. }
  108. Long end = System.currentTimeMillis();
  109. log.info("快手删评论所用时长:{}毫秒", end - start);
  110. }
  111. }
  112. @Autowired
  113. private IUserAllocationService allocationService;
  114. @Test
  115. public void testLoadBytedanceData() {
  116. List<UserAllocation> allocations = allocationService.getByParams(633L, null, 0);
  117. for (UserAllocation allocation : allocations) {
  118. // for (int i = 2; i < 10; i++) {
  119. CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId());
  120. Date getDate = DateUtils.addDay(new Date(), 0);
  121. // reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  122. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  123. // }
  124. }
  125. }
  126. @Test
  127. public void loadKuaishouAgentData() {
  128. kuaishouReportDailyAgentService.loginAgent();
  129. // for (int i = 0; i < 20; i++) {
  130. // String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -i));
  131. // kuaishouReportDailyAgentService.getReport(currentDate, DateUtils.getNowDate("yyyy-MM-dd"));
  132. // }
  133. //
  134. try {
  135. for (int i = 1; i < 30; i++) {
  136. kuaishouReportDailyAgentService.getAccount(i);
  137. }
  138. } catch (Exception e) {
  139. e.printStackTrace();
  140. }
  141. }
  142. @Autowired
  143. private GroovyScriptExecutor groovyScriptExecutor;
  144. @Autowired
  145. private ICtopCheckTaskListService checkTaskListService;
  146. @Test
  147. public void checkDataStateJobTest() {
  148. //查询需要检查的任务列表
  149. List<CtopCheckTaskList> ctopCheckTaskList = checkTaskListService.queryExecuteList("checkDataStateJob");
  150. if (ctopCheckTaskList != null) {
  151. ctopCheckTaskList.forEach(it -> groovyScriptExecutor.execute(it));
  152. }
  153. }
  154. @Test
  155. public void loadAccountData() {
  156. // List<UserAllocation> allocations = allocationService.getByParams(776L,null,0);
  157. // for (UserAllocation allocation:allocations) {
  158. CtopOauthToken token = tokenService.getTokenByAccountId(93238965516L);
  159. for(int i=92;i<100;i++){
  160. Date getDate = DateUtils.addDay(new Date(),-i);
  161. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  162. }
  163. // }
  164. }
  165. @Autowired
  166. IUReportExportService uReportExportService;
  167. @Autowired
  168. EmailSendMsgHandle emailSendMsgHandle;
  169. @Autowired
  170. IUReportService uReportService;
  171. @Test
  172. public void loadBytedanceData(){
  173. List<UserAllocation>allocations = allocationService.getByParams(633L,null,0);
  174. for (int i=0;i<allocations.size();i++) {
  175. CtopOauthToken token = tokenService.getTokenByAccountId(allocations.get(i).getAccountId());
  176. for(int j=10;j<110;j++){
  177. Date getDate = DateUtils.addDay(new Date(), -j);
  178. reportService.getAdvertiserReport(token, getDate, getDate,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  179. }
  180. }
  181. }
  182. @Test
  183. public void loaddata(){
  184. for(int i=0;i<30;i++){
  185. Date getDate = DateUtils.addDay(new Date(), -i);
  186. String date = DateUtils.formatDate(getDate);
  187. videoReportDailyService.videoInfoList(date, date);
  188. }
  189. }
  190. @Autowired
  191. private IBytedanceReportService bytedanceReportService;
  192. @Autowired
  193. private IByteDanceVideoReportDailyService videoReportDailyService;
  194. @Test
  195. public void loadMatData(){
  196. List<UserAllocation> allocations = allocationService.getByParams(320L,null,0);
  197. countDownLatch = new CountDownLatch(allocations.size());
  198. executorService = Executors.newFixedThreadPool(2);
  199. allocations.forEach(allocation -> {
  200. executorService.submit(new Runnable() {
  201. @Override
  202. public void run() {
  203. try {
  204. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  205. //获取全量视频素材数据
  206. advertiserDataService.getMaterialList(token);
  207. } catch (Exception e) {
  208. e.printStackTrace();
  209. } finally {
  210. countDownLatch.countDown();
  211. }
  212. }
  213. });
  214. });
  215. try {
  216. countDownLatch.await();
  217. } catch (InterruptedException e) {
  218. e.printStackTrace();
  219. }
  220. XxlJobLogger.log("物料数据同步完成");
  221. }
  222. }