SampleTest.java 13 KB

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