SampleTest.java 11 KB

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