SampleTest.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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.entity.UserAllocation;
  5. import cn.com.ctop.common.module.message.handle.impl.EmailSendMsgHandle;
  6. import cn.com.ctop.common.module.service.*;
  7. import cn.com.ctop.common.module.utils.CtopAdConstant;
  8. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
  9. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
  10. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  11. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
  12. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  13. import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
  14. import cn.com.ctop.toutiao.modules.report.service.IBytedanceFundDailyService;
  15. import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
  16. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  17. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  18. import com.xxl.job.core.log.XxlJobLogger;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.jeecg.common.util.DateUtils;
  21. import org.junit.Test;
  22. import org.junit.runner.RunWith;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.boot.test.context.SpringBootTest;
  25. import org.springframework.test.context.ActiveProfiles;
  26. import org.springframework.test.context.junit4.SpringRunner;
  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. import static org.jeecg.common.util.DateUtils.getAnotherDay;
  34. @RunWith(SpringRunner.class)
  35. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  36. @ActiveProfiles("wps")
  37. @Slf4j
  38. public class SampleTest {
  39. @Autowired
  40. private ICtopOauthTokenService oauthTokenService;
  41. @Autowired
  42. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  43. @Autowired
  44. private IReportService reportService;
  45. @Autowired
  46. private IByteDanceAdvertiserDataService advertiserDataService;
  47. @Autowired
  48. private IKuaiShouHistoryReportTaskService kuaiShouHistoryReportTaskService;
  49. @Autowired
  50. private ICtopOauthTokenService tokenService;
  51. @Test
  52. public void loadBytedanceCreativeData() {
  53. QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  54. queryWrapper.eq("media_id", 2);
  55. List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
  56. for (CtopOauthToken token : list) {
  57. kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-20", "2020-09-20", "daily");
  58. }
  59. }
  60. @Autowired
  61. private IBindAccountLoginService bindAccountLoginService;
  62. @Autowired
  63. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  64. @Test
  65. public void loadKuaishouCookie() {
  66. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  67. if (list != null && !list.isEmpty()) {
  68. int i = 0;
  69. for (BindAccountLogin login : list) {
  70. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  71. if (i > 5) {
  72. break;
  73. }
  74. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  75. i++;
  76. }
  77. }
  78. }
  79. }
  80. static ExecutorService executorService = null;
  81. //线程计数器/bytedance/bytedanceMaterialReport
  82. static CountDownLatch countDownLatch = null;
  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. @Autowired
  109. private IUserAllocationService allocationService;
  110. @Test
  111. public void testLoadBytedanceData() {
  112. List<UserAllocation> allocations = allocationService.getByParams(633L, null, 0);
  113. for (UserAllocation allocation : allocations) {
  114. System.out.println(allocation.getAccountId());
  115. for (int i = 0; i < 1; i++) {
  116. CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId());
  117. Date getDate = DateUtils.addDay(new Date(), -i);
  118. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  119. }
  120. }
  121. }
  122. @Test
  123. public void loadBytedancePlanData(){
  124. CtopOauthToken token = tokenService.getTokenByAccountId(100198696723L);
  125. // advertiserDataService.getAdvertiserPlan(token, "", null, null);
  126. Date getDate = DateUtils.addDay(new Date(), 0);
  127. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  128. }
  129. @Autowired
  130. private IBytedanceFundDailyService bytedanceFundDailyService;
  131. @Test
  132. public void loadFoudData() {
  133. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  134. for (CtopOauthToken token : tokens) {
  135. System.out.println(token.getAccountId()+"############################");
  136. for(int i=20;i<130;i++){
  137. Date date = DateUtils.addDay(new Date(),-i);
  138. bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date),1);
  139. System.out.println(i+"############################");
  140. }
  141. }
  142. }
  143. @Autowired
  144. private IKuaiShouHistoryReportTaskService reportTaskService;
  145. /**
  146. * 测试获取快手图片消耗数据任务
  147. */
  148. @Test
  149. public void loadKuaishouImageTask(){
  150. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  151. for(int i=1;i<130;i++) {
  152. Date getDate = DateUtils.addDay(new Date(), -i);
  153. String getDateStr = DateUtils.formatDate(getDate);
  154. tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
  155. }
  156. }
  157. @Autowired
  158. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  159. /**
  160. * 测试获取快手图片消耗数据入库
  161. */
  162. @Test
  163. public void loadKuaishouImageTaskFile(){
  164. String nowDate = DateUtils.getDate("yyyy-MM-dd");
  165. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  166. for(int i=1;i<15;i++){
  167. String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -i);
  168. tokens.forEach(token -> dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate));
  169. }
  170. // 查询快手token
  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. @Test
  189. public void loadAccountData() {
  190. // List<UserAllocation> allocations = allocationService.getByParams(776L,null,0);
  191. // for (UserAllocation allocation:allocations) {
  192. CtopOauthToken token = tokenService.getTokenByAccountId(93238965516L);
  193. for(int i=92;i<100;i++){
  194. Date getDate = DateUtils.addDay(new Date(),-i);
  195. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  196. }
  197. // }
  198. }
  199. @Autowired
  200. IUReportExportService uReportExportService;
  201. @Autowired
  202. EmailSendMsgHandle emailSendMsgHandle;
  203. @Autowired
  204. IUReportService uReportService;
  205. @Test
  206. public void loadBytedanceData(){
  207. List<UserAllocation>allocations = allocationService.getByParams(289L,null,0);
  208. for (int i=0;i<allocations.size();i++) {
  209. CtopOauthToken token = tokenService.getTokenByAccountId(allocations.get(i).getAccountId());
  210. for(int j=0;j<10;j++){
  211. String getDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -j));
  212. bytedanceReportService.bytedanceVideoMaterialReport(token, getDate, getDate);
  213. }
  214. }
  215. }
  216. @Autowired
  217. private IBytedanceReportService bytedanceReportService;
  218. @Autowired
  219. private IByteDanceVideoReportDailyService videoReportDailyService;
  220. @Test
  221. public void loadMatData(){
  222. List<UserAllocation> allocations = allocationService.getByParams(289L,null,0);
  223. countDownLatch = new CountDownLatch(allocations.size());
  224. executorService = Executors.newFixedThreadPool(2);
  225. allocations.forEach(allocation -> {
  226. executorService.submit(new Runnable() {
  227. @Override
  228. public void run() {
  229. try {
  230. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  231. //获取全量视频素材数据
  232. advertiserDataService.getMaterialList(token);
  233. } catch (Exception e) {
  234. e.printStackTrace();
  235. } finally {
  236. countDownLatch.countDown();
  237. }
  238. }
  239. });
  240. });
  241. try {
  242. countDownLatch.await();
  243. } catch (InterruptedException e) {
  244. e.printStackTrace();
  245. }
  246. XxlJobLogger.log("物料数据同步完成");
  247. }
  248. }