SampleTest.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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.common.module.utils.HttpUtils;
  9. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
  10. import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
  11. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  12. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
  13. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  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 cn.com.ctop.toutiao.modules.report.service.IRuleByteDanceAccountService;
  18. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  19. import com.fasterxml.jackson.core.JsonProcessingException;
  20. import com.xxl.job.core.log.XxlJobLogger;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.jeecg.common.util.DateUtils;
  23. import org.junit.Test;
  24. import org.junit.runner.RunWith;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.boot.test.context.SpringBootTest;
  27. import org.springframework.test.context.ActiveProfiles;
  28. import org.springframework.test.context.junit4.SpringRunner;
  29. import java.text.ParseException;
  30. import java.text.SimpleDateFormat;
  31. import java.util.Date;
  32. import java.util.HashMap;
  33. import java.util.List;
  34. import java.util.concurrent.CountDownLatch;
  35. import java.util.concurrent.ExecutorService;
  36. import java.util.concurrent.Executors;
  37. @RunWith(SpringRunner.class)
  38. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  39. @ActiveProfiles("wps")
  40. @Slf4j
  41. public class SampleTest {
  42. @Autowired
  43. private ICtopOauthTokenService oauthTokenService;
  44. @Autowired
  45. private IReportService reportService;
  46. @Autowired
  47. private IByteDanceAdvertiserDataService advertiserDataService;
  48. @Autowired
  49. private IKuaiShouHistoryReportTaskService kuaiShouHistoryReportTaskService;
  50. @Autowired
  51. private ICtopOauthTokenService tokenService;
  52. @Test
  53. public void loadBytedanceCreativeData() {
  54. QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  55. queryWrapper.eq("media_id", 2);
  56. List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
  57. for (CtopOauthToken token : list) {
  58. kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-20", "2020-09-20", "daily");
  59. }
  60. }
  61. @Autowired
  62. private IBindAccountLoginService bindAccountLoginService;
  63. @Autowired
  64. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  65. @Test
  66. public void loadKuaishouCookie() {
  67. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  68. if (list != null && !list.isEmpty()) {
  69. int i = 0;
  70. for (BindAccountLogin login : list) {
  71. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  72. if (i > 5) {
  73. break;
  74. }
  75. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  76. i++;
  77. }
  78. }
  79. }
  80. }
  81. static ExecutorService executorService = null;
  82. //线程计数器/bytedance/bytedanceMaterialReport
  83. static CountDownLatch countDownLatch = null;
  84. @Test
  85. public void deleteKuaishouComment() {
  86. Long start = System.currentTimeMillis();
  87. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  88. if (loginList != null && !loginList.isEmpty()) {
  89. executorService = Executors.newFixedThreadPool(5);
  90. countDownLatch = new CountDownLatch(loginList.size());
  91. loginList.forEach(login -> executorService.submit(() -> {
  92. try {
  93. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  94. } catch (Exception e) {
  95. log.error(e.getMessage(), e);
  96. } finally {
  97. countDownLatch.countDown();
  98. }
  99. }));
  100. try {
  101. countDownLatch.await();
  102. } catch (InterruptedException e) {
  103. e.printStackTrace();
  104. }
  105. Long end = System.currentTimeMillis();
  106. log.info("快手删评论所用时长:{}毫秒", end - start);
  107. }
  108. }
  109. @Test
  110. public void testXxlJobDistribute(){
  111. String url = "http://127.0.0.1:8090/xxl-job-admin/jobinfo/trigger?id=88&executorParam=";
  112. for(int i=0;i<100;i++){
  113. String result = HttpUtils.httpPostRequest(url+i,new HashMap<>(),new HashMap<>());
  114. System.out.println(result);
  115. }
  116. }
  117. @Test
  118. public void testLoadRulePlanData(){
  119. Date date = new Date();
  120. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  121. executorService = Executors.newFixedThreadPool(10);
  122. countDownLatch = new CountDownLatch(tokens.size());
  123. tokens.forEach(token -> executorService.submit(()->{
  124. try {
  125. Long start = System.currentTimeMillis();
  126. reportService.getAdvertiserPlanRuleData(token,date,date,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  127. Long end = System.currentTimeMillis();
  128. log.info("账户数据获取完成:accountId=>{},耗时{}毫秒",token.getAccountId(),end-start);
  129. }catch (Exception e){
  130. e.printStackTrace();
  131. }finally {
  132. countDownLatch.countDown();
  133. }
  134. }));
  135. try {
  136. countDownLatch.await();
  137. } catch (InterruptedException e) {
  138. e.printStackTrace();
  139. }
  140. }
  141. @Autowired
  142. private IUserAllocationService allocationService;
  143. @Test
  144. public void testLoadBytedanceData() {
  145. List<UserAllocation>allocations = allocationService.getByParams(273L,null,0);
  146. if(null!=allocations&&!allocations.isEmpty()){
  147. for(UserAllocation allocation:allocations){
  148. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  149. String startDate = "2020-11-05";
  150. String endDate = "2020-11-09";
  151. reportService.getAdvertiserPlanReport(token, DateUtils.parseDate(startDate,"yyyy-MM-dd"), DateUtils.parseDate(endDate,"yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  152. }
  153. }
  154. System.out.println("任务结束");
  155. }
  156. @Test
  157. public void loadBytedancePlanData(){
  158. CtopOauthToken token = tokenService.getTokenByAccountId(100198696723L);
  159. // advertiserDataService.getAdvertiserPlan(token, "", null, null);
  160. Date getDate = DateUtils.addDay(new Date(), 0);
  161. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  162. }
  163. @Autowired
  164. private IBytedanceFundDailyService bytedanceFundDailyService;
  165. @Test
  166. public void loadFoudData() {
  167. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  168. for (CtopOauthToken token : tokens) {
  169. System.out.println(token.getAccountId()+"############################");
  170. for(int i=20;i<130;i++){
  171. Date date = DateUtils.addDay(new Date(),-i);
  172. bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date),1);
  173. System.out.println(i+"############################");
  174. }
  175. }
  176. }
  177. @Autowired
  178. private IKuaiShouHistoryReportTaskService reportTaskService;
  179. /**
  180. * 测试获取快手图片消耗数据任务
  181. */
  182. @Test
  183. public void loadKuaishouImageTask(){
  184. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  185. for(int i=1;i<130;i++) {
  186. Date getDate = DateUtils.addDay(new Date(), -i);
  187. String getDateStr = DateUtils.formatDate(getDate);
  188. tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
  189. }
  190. }
  191. @Test
  192. public void testLoadBytedanceImageData(){
  193. List<CtopOauthToken>tokens = tokenService.selectToutiaoToken();
  194. countDownLatch = new CountDownLatch(tokens.size());
  195. executorService = Executors.newFixedThreadPool(8);
  196. tokens.forEach(token->executorService.submit(()->{
  197. try {
  198. advertiserDataService.getMaterialList(token);
  199. }catch (Exception e){
  200. }finally {
  201. countDownLatch.countDown();
  202. }
  203. }));
  204. try {
  205. countDownLatch.await();
  206. } catch (InterruptedException e) {
  207. e.printStackTrace();
  208. }
  209. System.out.println("素材数据获取完成");
  210. }
  211. @Autowired
  212. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  213. @Test
  214. public void loadKuaishouAgentData() throws JsonProcessingException {
  215. kuaishouReportDailyAgentService.loginAgent();
  216. // for (int i = 0; i < 20; i++) {
  217. // String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -i));
  218. // kuaishouReportDailyAgentService.getReport(currentDate, DateUtils.getNowDate("yyyy-MM-dd"));
  219. // }
  220. //
  221. try {
  222. for (int i = 1; i < 30; i++) {
  223. kuaishouReportDailyAgentService.getAccount(i);
  224. }
  225. } catch (Exception e) {
  226. e.printStackTrace();
  227. }
  228. }
  229. @Autowired
  230. private IKuaishouInterfaceService kuaishouInterfaceService;
  231. @Test
  232. public void loadKuaishouGroupData() throws ParseException {
  233. Date endDate = new Date();
  234. String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.formatDate(endDate), -1);
  235. SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
  236. Date startDate = sim.parse(anotherDay);
  237. CtopOauthToken token = tokenService.getTokenByAccountId(7087890L);
  238. kuaishouInterfaceService.getGroupList(token, startDate, endDate);
  239. }
  240. @Autowired
  241. IUReportExportService uReportExportService;
  242. @Autowired
  243. EmailSendMsgHandle emailSendMsgHandle;
  244. @Autowired
  245. IUReportService uReportService;
  246. @Autowired
  247. private IBytedanceReportService bytedanceReportService;
  248. @Test
  249. public void loadMatData(){
  250. List<UserAllocation> allocations = allocationService.getByParams(289L,null,0);
  251. countDownLatch = new CountDownLatch(allocations.size());
  252. executorService = Executors.newFixedThreadPool(2);
  253. allocations.forEach(allocation -> {
  254. executorService.submit(new Runnable() {
  255. @Override
  256. public void run() {
  257. try {
  258. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  259. //获取全量视频素材数据
  260. advertiserDataService.getMaterialList(token);
  261. } catch (Exception e) {
  262. e.printStackTrace();
  263. } finally {
  264. countDownLatch.countDown();
  265. }
  266. }
  267. });
  268. });
  269. try {
  270. countDownLatch.await();
  271. } catch (InterruptedException e) {
  272. e.printStackTrace();
  273. }
  274. XxlJobLogger.log("物料数据同步完成");
  275. }
  276. @Autowired
  277. IRuleByteDanceAccountService ruleByteDanceAccountService;
  278. @Test
  279. public void cleanRuleDataAccount(){
  280. List<CtopOauthToken> tokens = oauthTokenService.selectToutiaoToken();
  281. for(CtopOauthToken oauthToken:tokens){
  282. ruleByteDanceAccountService.cleanRuleDataAccount(oauthToken.getAccountId());
  283. }
  284. }
  285. }