SampleTest.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package org.jeecg;
  2. import cn.com.ctop.common.module.entity.BindAccountLogin;
  3. import cn.com.ctop.common.module.entity.CtopOauthToken;
  4. import cn.com.ctop.common.module.service.IBindAccountLoginService;
  5. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  6. import cn.com.ctop.common.module.utils.CtopAdConstant;
  7. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  8. import cn.com.ctop.kuaishou.modules.report.mapper.EtlKuaishouAccountMaterialReportDailyMapper;
  9. import cn.com.ctop.kuaishou.modules.report.service.IEtlKuaishouAccountMaterialReportDailyService;
  10. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyImageService;
  11. import cn.com.ctop.oa.modules.service.IWechatNoListService;
  12. import cn.com.ctop.toutiao.modules.link.service.IETLReportBytedanceVideoService;
  13. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  14. import cn.com.ctop.toutiao.modules.report.entity.BytedanceCheckReportTaskInfo;
  15. import cn.com.ctop.toutiao.modules.report.service.*;
  16. import com.xxl.job.core.context.XxlJobHelper;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.jeecg.common.util.DateUtils;
  19. import org.junit.Test;
  20. import org.junit.runner.RunWith;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.boot.test.context.SpringBootTest;
  23. import org.springframework.test.context.ActiveProfiles;
  24. import org.springframework.test.context.junit4.SpringRunner;
  25. import javax.annotation.Resource;
  26. import java.text.ParseException;
  27. import java.util.Date;
  28. import java.util.HashMap;
  29. import java.util.List;
  30. import java.util.concurrent.CountDownLatch;
  31. import java.util.concurrent.ExecutorService;
  32. import java.util.concurrent.Executors;
  33. @RunWith(SpringRunner.class)
  34. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  35. @ActiveProfiles("wps")
  36. @Slf4j
  37. public class SampleTest {
  38. @Autowired
  39. private IBytedanceVideoEtlInfoService bytedanceVideoEtlInfoService;
  40. @Autowired
  41. IBytedanceVideoReportService bytedanceVideoReportService;
  42. @Autowired
  43. IETLReportBytedanceVideoService ietlReportBytedanceVideoService;
  44. @Autowired
  45. IKuaishouReportDailyImageService kuaishouReportDailyImageService;
  46. @Autowired
  47. IRuleByteDanceAccountService ruleByteDanceAccountService;
  48. @Autowired
  49. private ICtopOauthTokenService tokenService;
  50. @Autowired
  51. private IBindAccountLoginService bindAccountLoginService;
  52. @Autowired
  53. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  54. @Autowired
  55. private IByteDanceAdvertiserDataService advertiserDataService;
  56. @Autowired
  57. private IWechatNoListService wechatNoListService;
  58. @Autowired
  59. private IETLReportBytedanceVideoService bytedanceVideoService;
  60. @Autowired
  61. private IByteDanceVideoReportDailyService videoReportDailyService;
  62. @Resource
  63. private EtlKuaishouAccountMaterialReportDailyMapper etlKuaishouAccountMaterialReportDailyMapper;
  64. @Autowired
  65. private IReportService reportService;
  66. @Resource
  67. private IBytedanceCheckReportTaskInfoService checkReportTaskInfoService;
  68. @Autowired
  69. private IEtlBytedanceReportVideoDailyService etlBytedanceReportVideoDailyService;
  70. static ExecutorService executorService = null;
  71. static CountDownLatch countDownLatch = null;
  72. @Autowired
  73. private IBytedanceReportService bytedanceReportService;
  74. @Autowired
  75. private IETLReportBytedanceVideoService etlReportBytedanceVideoService;
  76. @Autowired
  77. private IEtlKuaishouAccountMaterialReportDailyService materialReportDailyService;
  78. @Test
  79. public void loadKuaishouCookie() throws ParseException {
  80. Date startDate = new Date();
  81. for (int i = 1; i <= 2; i++) {
  82. if (i == 1) {
  83. continue;
  84. }
  85. System.err.println(DateUtils.addDay(new Date(), -i));
  86. materialReportDailyService.etlKuaishouAccountMaterialReportInfo(DateUtils.formatDate(DateUtils.addDay(new Date(), -i)));
  87. }
  88. }
  89. @Test
  90. public void deleteKuaishouComment() {
  91. Long start = System.currentTimeMillis();
  92. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  93. if (loginList != null && !loginList.isEmpty()) {
  94. executorService = Executors.newFixedThreadPool(5);
  95. countDownLatch = new CountDownLatch(loginList.size());
  96. loginList.forEach(login -> executorService.submit(() -> {
  97. try {
  98. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  99. } catch (Exception e) {
  100. log.error(e.getMessage(), e);
  101. } finally {
  102. countDownLatch.countDown();
  103. }
  104. }));
  105. try {
  106. countDownLatch.await();
  107. } catch (InterruptedException e) {
  108. e.printStackTrace();
  109. }
  110. Long end = System.currentTimeMillis();
  111. log.info("快手删评论所用时长:{}毫秒", end - start);
  112. }
  113. }
  114. @Test
  115. public void loadBytedanceVideoReportData() {
  116. CtopOauthToken token = tokenService.getTokenByAccountId(1696831659659278L);
  117. advertiserDataService.getMaterialList(token);
  118. }
  119. @Test
  120. public void etlBytedanceVideoInfo() {
  121. String startDate = "2021-02-01";
  122. for (int i = 0; i < 100; i++) {
  123. bytedanceVideoService.cleanData(DateUtils.addDay(startDate, i));
  124. }
  125. }
  126. @Test
  127. public void getData() {
  128. //汇创 人员
  129. // wechatUserInfoService.getUserList();
  130. // //考勤记录
  131. // wechatCheckinDataService.getCheckinData("2021-03-01 00:00:00", "2021-03-31 23:59:59");
  132. //异常记录
  133. wechatNoListService.getNoDateByNo("2021-03-01 00:00:00", "2021-03-31 23:59:59", "0");
  134. //优容
  135. // wechatUserInfoService.getYRUserList();
  136. // wechatCheckinDataService.getYRCheckinData("2021-03-01 00:00:00", "2021-03-31 23:59:59");
  137. wechatNoListService.getNoDateByNo("2021-03-01 00:00:00", "2021-03-31 23:59:59", "1");
  138. }
  139. @Test
  140. public void formatVideoReportData() {
  141. for (int i = 1; i < 45; i++) {
  142. Date getDate = DateUtils.addDay(new Date(), -i);
  143. String date = DateUtils.formatDate(getDate);
  144. videoReportDailyService.videoInfoList(date, date);
  145. }
  146. }
  147. @Test
  148. public void loadBDAccoutData() {
  149. Date startDate = DateUtils.addDay(new Date(), -2000);
  150. for (int i = 0; i <= 2000; i++) {
  151. Date getDate = DateUtils.addDay(startDate, i);
  152. bytedanceVideoEtlInfoService.etlBytedanceVideoInfo(getDate);
  153. }
  154. }
  155. @Test
  156. public void etlKuaishouVideoInfo() {
  157. etlKuaishouAccountMaterialReportDailyMapper.etlKuaishouAccountMaterialReportDailyData(DateUtils.formatDate());
  158. }
  159. @Test
  160. public void testLoadBytedanceCampaign() {
  161. CtopOauthToken token = tokenService.getTokenByAccountId(1681669009084429L);
  162. bytedanceReportService.bytedanceMaterialReport(token, "2021-05-01", "2021-05-06");
  163. }
  164. @Test
  165. public void etlBytedanceVideoReportInfo() throws Exception {
  166. etlBytedanceReportVideoDailyService.etlBytedanceVideo();
  167. }
  168. @Test
  169. public void loadBytedanceAccountReport() {
  170. CtopOauthToken token1 = tokenService.getTokenByAccountId(1693648201498637L);
  171. reportService.getAdvertiserReport(token1, DateUtils.parseDate("2021-04-01", "yyyy-MM-dd"), DateUtils.parseDate("2021-04-12", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  172. }
  173. @Test
  174. public void checkCostData() {
  175. String date = "2021-06-11";
  176. for (int i = 0; i < 7; i++) {
  177. String getDate = DateUtils.addDay(date, i);
  178. //1:初始化
  179. checkReportTaskInfoService.initTask(getDate);
  180. //2: checkCost
  181. List<BytedanceCheckReportTaskInfo> taskInfos = checkReportTaskInfoService.getListByParams(null, getDate, 0);
  182. if (null != taskInfos && !taskInfos.isEmpty()) {
  183. for (BytedanceCheckReportTaskInfo task : taskInfos) {
  184. checkReportTaskInfoService.checkCost(task);
  185. }
  186. log.info("{}:数据获取完成", getDate);
  187. }
  188. }
  189. }
  190. @Test
  191. public void refreshReportData() throws Exception {
  192. //1:查询异常任务数据
  193. List<BytedanceCheckReportTaskInfo> taskInfos = checkReportTaskInfoService.getListByParams(null, null, 50001);
  194. if (null != taskInfos && !taskInfos.isEmpty()) {
  195. countDownLatch = new CountDownLatch(taskInfos.size());
  196. taskInfos.forEach(taskInfo -> {
  197. try {
  198. checkReportTaskInfoService.reloadData(taskInfo);
  199. checkReportTaskInfoService.checkCost(taskInfo);
  200. } catch (Exception e) {
  201. } finally {
  202. countDownLatch.countDown();
  203. }
  204. });
  205. countDownLatch.await();
  206. XxlJobHelper.log("{}数据更新完成");
  207. }
  208. }
  209. @Test
  210. public void testfreshBytedanceUrl() {
  211. etlReportBytedanceVideoService.etlBytedanceVideoClipIdJob();
  212. etlReportBytedanceVideoService.etlBytedanceVideoPlanInfoJob();
  213. etlReportBytedanceVideoService.etlBytedanceVideoShotInfoJob();
  214. }
  215. }