SampleTest.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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.entity.EtlKuaishouAccountMaterialReportDaily;
  9. import cn.com.ctop.kuaishou.modules.report.mapper.EtlKuaishouAccountMaterialReportDailyMapper;
  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. @Test
  77. public void loadKuaishouCookie() throws ParseException {
  78. CtopOauthToken tokenByAccountId = tokenService.getTokenByAccountId(1700996735138951L);
  79. advertiserDataService.getMaterialList(tokenByAccountId);
  80. CtopOauthToken tokenByAccountId1 = tokenService.getTokenByAccountId(1700996735589383L);
  81. advertiserDataService.getMaterialList(tokenByAccountId1);
  82. }
  83. @Test
  84. public void deleteKuaishouComment() {
  85. Long start = System.currentTimeMillis();
  86. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  87. if (loginList != null && !loginList.isEmpty()) {
  88. executorService = Executors.newFixedThreadPool(5);
  89. countDownLatch = new CountDownLatch(loginList.size());
  90. loginList.forEach(login -> executorService.submit(() -> {
  91. try {
  92. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  93. } catch (Exception e) {
  94. log.error(e.getMessage(), e);
  95. } finally {
  96. countDownLatch.countDown();
  97. }
  98. }));
  99. try {
  100. countDownLatch.await();
  101. } catch (InterruptedException e) {
  102. e.printStackTrace();
  103. }
  104. Long end = System.currentTimeMillis();
  105. log.info("快手删评论所用时长:{}毫秒", end - start);
  106. }
  107. }
  108. @Test
  109. public void loadBytedanceVideoReportData() {
  110. CtopOauthToken token = tokenService.getTokenByAccountId(1696831659659278L);
  111. advertiserDataService.getMaterialList(token);
  112. }
  113. @Test
  114. public void etlBytedanceVideoInfo() {
  115. String startDate = "2021-02-01";
  116. for (int i = 0; i < 100; i++) {
  117. bytedanceVideoService.cleanData(DateUtils.addDay(startDate, i));
  118. }
  119. }
  120. @Test
  121. public void getData() {
  122. //汇创 人员
  123. // wechatUserInfoService.getUserList();
  124. // //考勤记录
  125. // wechatCheckinDataService.getCheckinData("2021-03-01 00:00:00", "2021-03-31 23:59:59");
  126. //异常记录
  127. wechatNoListService.getNoDateByNo("2021-03-01 00:00:00", "2021-03-31 23:59:59", "0");
  128. //优容
  129. // wechatUserInfoService.getYRUserList();
  130. // wechatCheckinDataService.getYRCheckinData("2021-03-01 00:00:00", "2021-03-31 23:59:59");
  131. wechatNoListService.getNoDateByNo("2021-03-01 00:00:00", "2021-03-31 23:59:59", "1");
  132. }
  133. @Test
  134. public void formatVideoReportData() {
  135. for (int i = 1; i < 45; i++) {
  136. Date getDate = DateUtils.addDay(new Date(), -i);
  137. String date = DateUtils.formatDate(getDate);
  138. videoReportDailyService.videoInfoList(date, date);
  139. }
  140. }
  141. @Test
  142. public void loadBDAccoutData() {
  143. Date startDate = DateUtils.addDay(new Date(), -2000);
  144. for (int i = 0; i <= 2000; i++) {
  145. Date getDate = DateUtils.addDay(startDate, i);
  146. bytedanceVideoEtlInfoService.etlBytedanceVideoInfo(getDate);
  147. }
  148. }
  149. @Test
  150. public void etlKuaishouVideoInfo() {
  151. etlKuaishouAccountMaterialReportDailyMapper.etlKuaishouAccountMaterialReportDailyData(DateUtils.formatDate());
  152. }
  153. @Test
  154. public void testLoadBytedanceCampaign() {
  155. CtopOauthToken token = tokenService.getTokenByAccountId(1681669009084429L);
  156. bytedanceReportService.bytedanceMaterialReport(token, "2021-05-01", "2021-05-06");
  157. }
  158. @Test
  159. public void etlBytedanceVideoReportInfo() throws Exception {
  160. etlBytedanceReportVideoDailyService.etlBytedanceVideo();
  161. }
  162. @Test
  163. public void loadBytedanceAccountReport() {
  164. CtopOauthToken token1 = tokenService.getTokenByAccountId(1693648201498637L);
  165. reportService.getAdvertiserReport(token1, DateUtils.parseDate("2021-04-01", "yyyy-MM-dd"), DateUtils.parseDate("2021-04-12", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  166. }
  167. @Test
  168. public void checkCostData(){
  169. String date = "2021-06-11";
  170. for (int i=0;i<7;i++){
  171. String getDate = DateUtils.addDay(date,i);
  172. //1:初始化
  173. checkReportTaskInfoService.initTask(getDate);
  174. //2: checkCost
  175. List<BytedanceCheckReportTaskInfo>taskInfos = checkReportTaskInfoService.getListByParams(null,getDate,0);
  176. if(null!=taskInfos&&!taskInfos.isEmpty()){
  177. for (BytedanceCheckReportTaskInfo task:taskInfos) {
  178. checkReportTaskInfoService.checkCost(task);
  179. }
  180. log.info("{}:数据获取完成",getDate);
  181. }
  182. }
  183. }
  184. @Test
  185. public void refreshReportData()throws Exception{
  186. //1:查询异常任务数据
  187. List<BytedanceCheckReportTaskInfo>taskInfos = checkReportTaskInfoService.getListByParams(null,null,50001);
  188. if(null!=taskInfos&&!taskInfos.isEmpty()){
  189. countDownLatch = new CountDownLatch(taskInfos.size());
  190. taskInfos.forEach(taskInfo -> {
  191. try {
  192. checkReportTaskInfoService.reloadData(taskInfo);
  193. checkReportTaskInfoService.checkCost(taskInfo);
  194. }catch (Exception e){
  195. }finally {
  196. countDownLatch.countDown();
  197. }
  198. });
  199. countDownLatch.await();
  200. XxlJobHelper.log("{}数据更新完成");
  201. }
  202. }
  203. @Test
  204. public void testfreshBytedanceUrl(){
  205. etlReportBytedanceVideoService.etlBytedanceVideoClipIdJob();
  206. etlReportBytedanceVideoService.etlBytedanceVideoPlanInfoJob();
  207. etlReportBytedanceVideoService.etlBytedanceVideoShotInfoJob();
  208. }
  209. }