SampleTest.java 9.3 KB

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