SampleTest.java 10 KB

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