SampleTest.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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.service.IBindAccountLoginService;
  6. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  7. import cn.com.ctop.common.module.service.IUserAllocationService;
  8. import cn.com.ctop.common.module.utils.CtopAdConstant;
  9. import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountTargetTemplate;
  10. import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAccountTargetTemplateService;
  11. import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouNewCreateCampaign;
  12. import cn.com.ctop.kuaishou.modules.batch.service.*;
  13. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  14. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
  15. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouVideoEtlInfoService;
  16. import cn.com.ctop.kuaishou.modules.report.service.IRuleKuaiShouPlanService;
  17. import cn.com.ctop.oa.modules.service.IWechatCheckinDataService;
  18. import cn.com.ctop.oa.modules.service.IWechatNoListService;
  19. import cn.com.ctop.oa.modules.service.IWechatUserListService;
  20. import cn.com.ctop.toutiao.modules.link.service.IETLReportBytedanceVideoService;
  21. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  22. import cn.com.ctop.toutiao.modules.report.entity.BytedanceAccountReportTaskRecord;
  23. import cn.com.ctop.toutiao.modules.report.mapper.BytedanceReportMaterialDailyMapper;
  24. import cn.com.ctop.toutiao.modules.report.service.*;
  25. import lombok.extern.slf4j.Slf4j;
  26. import org.jeecg.common.util.DateUtils;
  27. import org.junit.Test;
  28. import org.junit.runner.RunWith;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.boot.test.context.SpringBootTest;
  31. import org.springframework.test.context.ActiveProfiles;
  32. import org.springframework.test.context.junit4.SpringRunner;
  33. import javax.annotation.Resource;
  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("dev")
  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 ICtopOauthTokenService tokenService;
  56. @Autowired
  57. private IKuaiShouVideoGetService videoGetService;
  58. @Autowired
  59. private IKuaishouVideoRelateCreativesService kuaishouVideoRelateCreativesService;
  60. @Autowired
  61. private IBindAccountLoginService bindAccountLoginService;
  62. @Autowired
  63. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  64. /* @Autowired
  65. private IByteDanceAdvertiserDataService advertiserDataService;
  66. */
  67. @Test
  68. public void loadBytedanceCreativeData() throws ParseException {
  69. // 1662234704806924
  70. /* CtopOauthToken token = new CtopOauthToken();
  71. token.setAccountId(9549277L);
  72. token.setAccessToken("bc5327c8f2bd8a67513e51148c9206c8");
  73. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  74. Date parse = simpleDateFormat.parse("2021-02-02");
  75. kuaishouInterfaceService.getAdvertiserReportDaily(token, parse, parse);*/
  76. CtopOauthToken token = new CtopOauthToken();
  77. token.setAccountId(9767055L);
  78. token.setAccessToken("28e4e6b124e1443d6971ba4c699de6c9");
  79. kuaishouInterfaceService.getVideoList(token, null, null);
  80. kuaishouInterfaceService.getVideoInfo("28e4e6b124e1443d6971ba4c699de6c9",9767055L,"5208131540349742192");
  81. /* CtopOauthToken tokenByAccountId = tokenService.getTokenByAccountId(1662234704806924L);
  82. advertiserDataService.getMaterialList(tokenByAccountId);*/
  83. /* getVideoByPage(token, "", 1);
  84. List<KuaiShouVideoGet> KuaiShouVideoGets = videoGetService.selectPhotoIdsByAccountId(9743746L);
  85. if (!Check.isNull(KuaiShouVideoGets)) {
  86. JSONArray dateList = new JSONArray();
  87. JSONArray photoIds = new JSONArray();
  88. Map<String, Object> statdateMap = new HashMap<>();
  89. int count = 0;
  90. for (KuaiShouVideoGet video : KuaiShouVideoGets) {
  91. count++;
  92. if (count < 10) {
  93. photoIds.add(video.getPhotoId());
  94. statdateMap.put(video.getPhotoId(), video.getStatDate());
  95. } else {
  96. photoIds.add(video.getPhotoId());
  97. statdateMap.put(video.getPhotoId(), video.getStatDate());
  98. dateList.add(photoIds);
  99. photoIds = new JSONArray();
  100. count = 0;
  101. }
  102. }
  103. dateList.add(photoIds);
  104. kuaishouVideoRelateCreativesService.videoRelateCreatives(9743746L, dateList, statdateMap);
  105. }*/
  106. }
  107. @Test
  108. public void loadKuaishouCookie() {
  109. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  110. if (list != null && !list.isEmpty()) {
  111. int i = 0;
  112. for (BindAccountLogin login : list) {
  113. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  114. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  115. i++;
  116. }
  117. }
  118. }
  119. }
  120. static ExecutorService executorService = null;
  121. static CountDownLatch countDownLatch = null;
  122. @Test
  123. public void deleteKuaishouComment() {
  124. Long start = System.currentTimeMillis();
  125. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  126. if (loginList != null && !loginList.isEmpty()) {
  127. executorService = Executors.newFixedThreadPool(5);
  128. countDownLatch = new CountDownLatch(loginList.size());
  129. loginList.forEach(login -> executorService.submit(() -> {
  130. try {
  131. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  132. } catch (Exception e) {
  133. log.error(e.getMessage(), e);
  134. } finally {
  135. countDownLatch.countDown();
  136. }
  137. }));
  138. try {
  139. countDownLatch.await();
  140. } catch (InterruptedException e) {
  141. e.printStackTrace();
  142. }
  143. Long end = System.currentTimeMillis();
  144. log.info("快手删评论所用时长:{}毫秒", end - start);
  145. }
  146. }
  147. @Autowired
  148. private IUserAllocationService allocationService;
  149. @Test
  150. public void testLoadBytedanceData() {
  151. List<UserAllocation> allocations = allocationService.getByParams(633L, null, 0);
  152. if (null != allocations && !allocations.isEmpty()) {
  153. for (UserAllocation allocation : allocations) {
  154. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  155. String startDate = "2020-11-10";
  156. String endDate = "2020-11-10";
  157. reportService.getAdvertiserReport(token, DateUtils.parseDate(startDate, "yyyy-MM-dd"), DateUtils.parseDate(endDate, "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  158. }
  159. }
  160. System.out.println("任务结束");
  161. }
  162. @Test
  163. public void loadKuaishouPlanData() {
  164. Date getDate = DateUtils.addDay(new Date(), -1);
  165. //1:查询当日数据
  166. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  167. tokens.forEach(token -> kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getDate, getDate));
  168. }
  169. @Autowired
  170. private IBytedanceFundDailyService bytedanceFundDailyService;
  171. @Test
  172. public void loadFoudData() {
  173. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  174. for (CtopOauthToken token : tokens) {
  175. System.out.println(token.getAccountId() + "############################");
  176. for (int i = 20; i < 130; i++) {
  177. Date date = DateUtils.addDay(new Date(), -i);
  178. bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date), 1);
  179. System.out.println(i + "############################");
  180. }
  181. }
  182. }
  183. @Autowired
  184. private IKuaiShouHistoryReportTaskService reportTaskService;
  185. /**
  186. * 测试获取快手图片消耗数据任务
  187. */
  188. @Test
  189. public void loadKuaishouImageTask() {
  190. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  191. for (int i = 1; i < 130; i++) {
  192. Date getDate = DateUtils.addDay(new Date(), -i);
  193. String getDateStr = DateUtils.formatDate(getDate);
  194. tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
  195. }
  196. }
  197. @Autowired
  198. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  199. /**
  200. * 测试获取快手图片消耗数据入库
  201. */
  202. @Test
  203. public void loadKuaishouImageTaskFile() {
  204. String nowDate = DateUtils.getDate("yyyy-MM-dd");
  205. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  206. for (int i = 1; i < 15; i++) {
  207. String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -i);
  208. tokens.forEach(token -> dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate));
  209. }
  210. // 查询快手token
  211. }
  212. @Test
  213. public void testLoadBytedanceImageData() {
  214. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  215. countDownLatch = new CountDownLatch(tokens.size());
  216. executorService = Executors.newFixedThreadPool(8);
  217. tokens.forEach(token -> executorService.submit(() -> {
  218. try {
  219. advertiserDataService.getMaterialList(token);
  220. } catch (Exception e) {
  221. } finally {
  222. countDownLatch.countDown();
  223. }
  224. }));
  225. try {
  226. countDownLatch.await();
  227. } catch (InterruptedException e) {
  228. e.printStackTrace();
  229. }
  230. System.out.println("素材数据获取完成");
  231. }
  232. @Autowired
  233. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  234. @Test
  235. public void testData() {
  236. Date date = new Date();
  237. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  238. executorService = Executors.newFixedThreadPool(10);
  239. countDownLatch = new CountDownLatch(tokens.size());
  240. tokens.forEach(token -> executorService.submit(() -> {
  241. try {
  242. reportService.getAdvertiserPlanRuleData(token, date, date, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  243. } catch (Exception e) {
  244. } finally {
  245. countDownLatch.countDown();
  246. }
  247. }));
  248. try {
  249. countDownLatch.await();
  250. } catch (InterruptedException e) {
  251. e.printStackTrace();
  252. }
  253. }
  254. @Test
  255. public void loadKuaishouAgentData() {
  256. kuaishouReportDailyAgentService.loginAgent();
  257. try {
  258. for (int i = 1; i < 30; i++) {
  259. kuaishouReportDailyAgentService.getAccount(i);
  260. }
  261. } catch (Exception e) {
  262. e.printStackTrace();
  263. }
  264. }
  265. @Test
  266. public void loadKuaishouData() {
  267. Date getDate = DateUtils.addDay(new Date(), -1);
  268. //1:查询当日数据
  269. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  270. for (CtopOauthToken token : tokens) {
  271. kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getDate, getDate);
  272. }
  273. }
  274. @Autowired
  275. private IBytedanceReportService bytedanceReportService;
  276. @Test
  277. public void loadBytedanceVideoReportData() {
  278. Date getDate = DateUtils.addDay(new Date(), -1);
  279. String date = DateUtils.formatDate(getDate);
  280. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  281. for (CtopOauthToken token : tokens) {
  282. bytedanceReportService.bytedanceVideoMaterialReport(token, date, date);
  283. }
  284. }
  285. @Test
  286. public void loadKuaishouHourlyReportData() {
  287. Date getDate = new Date();
  288. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
  289. String hour = simpleDateFormat.format(getDate);
  290. if ("00".equals(hour)) {
  291. getDate = DateUtils.addDay(getDate, -1);
  292. }
  293. //1:查询当日数据
  294. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  295. Date finalGetDate = getDate;
  296. tokens.forEach(token -> kuaishouInterfaceService.getAdvertiserReportHourly(token, finalGetDate, finalGetDate));
  297. }
  298. @Autowired
  299. private IKuaishouInterfaceService kuaishouInterfaceService;
  300. @Test
  301. public void loadKuaishouGroupData() throws ParseException {
  302. Date endDate = new Date();
  303. String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.formatDate(endDate), -1);
  304. SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
  305. Date startDate = sim.parse(anotherDay);
  306. CtopOauthToken token = tokenService.getTokenByAccountId(7087890L);
  307. kuaishouInterfaceService.getGroupList(token, startDate, endDate);
  308. }
  309. @Test
  310. public void loadAccountData() {
  311. // List<UserAllocation> allocations = allocationService.getByParams(776L,null,0);
  312. // for (UserAllocation allocation:allocations) {
  313. CtopOauthToken token = tokenService.getTokenByAccountId(93238965516L);
  314. for (int i = 92; i < 100; i++) {
  315. Date getDate = DateUtils.addDay(new Date(), -i);
  316. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  317. }
  318. // }
  319. }
  320. @Autowired
  321. private IWechatCheckinDataService wechatCheckinDataService;
  322. @Autowired
  323. private IWechatUserListService wechatUserInfoService;
  324. @Autowired
  325. private IWechatNoListService wechatNoListService;
  326. @Test
  327. public void getData() {
  328. //汇创 人员
  329. // wechatUserInfoService.getUserList();
  330. // //考勤记录
  331. // wechatCheckinDataService.getCheckinData("2020-11-01 00:00:00", "2020-12-01 23:59:59");
  332. //异常记录
  333. // wechatNoListService.getNoDateByNo("2020-11-01 00:00:00", "2020-12-01 23:59:59", "0");
  334. //优容
  335. wechatUserInfoService.getYRUserList();
  336. wechatCheckinDataService.getYRCheckinData("2020-11-01 00:00:00", "2020-11-30 23:59:59");
  337. wechatNoListService.getNoDateByNo("2020-11-01 00:00:00", "2020-12-01 23:59:59", "1");
  338. }
  339. @Autowired
  340. private IKuaiShouCommentService kuaiShouCommentService;
  341. @Test
  342. public void kuaishouDeleteComment() {
  343. kuaiShouCommentService.shieldComment(8018853L);
  344. }
  345. @Autowired
  346. private IByteDanceVideoReportDailyService videoReportDailyService;
  347. @Test
  348. public void formatVideoReportData() {
  349. for (int i = 1; i < 45; i++) {
  350. Date getDate = DateUtils.addDay(new Date(), -i);
  351. String date = DateUtils.formatDate(getDate);
  352. videoReportDailyService.videoInfoList(date, date);
  353. }
  354. }
  355. @Autowired
  356. private IRuleKuaiShouPlanService ruleKuaiShouPlanService;
  357. @Autowired
  358. private IBytedanceAccountReportTaskRecordService reportTaskRecordService;
  359. @Test
  360. public void execute() {
  361. List<UserAllocation> allocations = allocationService.listByMediaId("3", 0);
  362. for (UserAllocation allocation : allocations) {
  363. BytedanceAccountReportTaskRecord reportTaskRecord1 = new BytedanceAccountReportTaskRecord(allocation.getAccountId(), "2020-10-01", "2020-10-31");
  364. reportTaskRecordService.save(reportTaskRecord1);
  365. BytedanceAccountReportTaskRecord reportTaskRecord2 = new BytedanceAccountReportTaskRecord(allocation.getAccountId(), "2020-11-01", "2020-11-30");
  366. reportTaskRecordService.save(reportTaskRecord2);
  367. BytedanceAccountReportTaskRecord reportTaskRecord3 = new BytedanceAccountReportTaskRecord(allocation.getAccountId(), "2020-12-01", "2020-12-31");
  368. reportTaskRecordService.save(reportTaskRecord3);
  369. }
  370. }
  371. @Test
  372. public void loadBDAccoutData() {
  373. CtopOauthToken token2 = tokenService.getTokenByAccountId(1674206482908163L);
  374. bytedanceReportService.bytedanceMaterialReport(token2, "2020-10-14", "2020-10-14");
  375. bytedanceReportMaterialDailyMapper.updateImageReportCode();
  376. bytedanceReportMaterialDailyMapper.updateImageReportProjectId();
  377. bytedanceReportMaterialDailyMapper.updateImageReportProjectName();
  378. bytedanceReportMaterialDailyMapper.updateImageReportPlaneId();
  379. bytedanceReportMaterialDailyMapper.updateImageReportPlaneName();
  380. }
  381. @Resource
  382. private BytedanceReportMaterialDailyMapper bytedanceReportMaterialDailyMapper;
  383. private void load12AccountData(CtopOauthToken token) {
  384. reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-10-01", "yyyy-MM-dd"), DateUtils.parseDate("2020-10-31", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  385. reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-11-01", "yyyy-MM-dd"), DateUtils.parseDate("2020-11-30", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  386. reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-12-01", "yyyy-MM-dd"), DateUtils.parseDate("2020-12-31", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  387. }
  388. private void load12Data(CtopOauthToken token) {
  389. bytedanceReportService.bytedanceMaterialReport(token, "2020-10-11", "2020-10-13");
  390. bytedanceReportService.bytedanceMaterialReport(token, "2020-10-14", "2020-10-16");
  391. bytedanceReportService.bytedanceMaterialReport(token, "2020-10-17", "2020-10-19");
  392. bytedanceReportService.bytedanceMaterialReport(token, "2020-10-20", "2020-10-21");
  393. }
  394. @Autowired
  395. private IKuaishouVideoEtlInfoService kuaishouVideoEtlInfoService;
  396. @Test
  397. public void etlKuaishouData() {
  398. String dateString = "2021-01-05";
  399. Date startDate = DateUtils.parseDate(dateString, "yyyy-MM-dd");
  400. for (int i = 0; i <= 10; i++) {
  401. Date getDate = DateUtils.addDay(startDate, i);
  402. kuaishouVideoEtlInfoService.etlKuaishouVideoInfo(getDate);
  403. bytedanceVideoEtlInfoService.etlBytedanceVideoInfo(getDate);
  404. }
  405. }
  406. @Autowired
  407. private IBytedanceVideoEtlInfoService bytedanceVideoEtlInfoService;
  408. @Test
  409. public void loadBytedanceVideo() {
  410. CtopOauthToken token = tokenService.getTokenByAccountId(1673731601820686L);
  411. for (int i = 15; i < 60; i++) {
  412. reportService.getAdvertiserReport(token, DateUtils.addDay(new Date(), -i), DateUtils.addDay(new Date(), -i), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  413. }
  414. }
  415. @Test
  416. public void loadKuaishouVideo() {
  417. Date date = new Date();
  418. CtopOauthToken token = tokenService.getTokenByAccountId(9556344L);
  419. // kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token, new Date(), new Date(), null, null);
  420. kuaishouInterfaceService.getVideoList(token, DateUtils.formatDate(DateUtils.addDay(date, -5)), DateUtils.formatDate(date));
  421. // 获取图片信息数据
  422. // kuaishouInterfaceService.getImageList(token, DateUtils.getNowDate("yyyy-MM-dd"));
  423. }
  424. @Autowired
  425. IRuleByteDanceAccountService ruleByteDanceAccountService;
  426. @Test
  427. public void cleanRuleDataAccount() {
  428. List<CtopOauthToken> tokens = oauthTokenService.selectKuaiShouToken();
  429. for (CtopOauthToken oauthToken : tokens) {
  430. ruleKuaiShouPlanService.cleanRuleDataTarget(oauthToken.getAccountId(), 1);
  431. }
  432. }
  433. @Autowired
  434. IAiKuaishouNewCreateCampaign aiKuaishouNewCreateCampaign;
  435. @Autowired
  436. private IAiKuaishouAccountTargetTemplateService aiKuaishouAccountTargetTemplateService;
  437. @Test
  438. public void createPlan() {
  439. List<AiKuaishouAccountTargetTemplate> accountTargetTemplates = aiKuaishouAccountTargetTemplateService.getAllEffectTemplate();
  440. if (null == accountTargetTemplates || accountTargetTemplates.isEmpty()) {
  441. return;
  442. }
  443. accountTargetTemplates.forEach(targetTemplate -> aiKuaishouNewCreateCampaign.kuaishouAiAdsNewMaterialCreativity(targetTemplate));
  444. }
  445. @Test
  446. public void testCreatePlan() {
  447. // List<AiKuaishouAccountTargetTemplate> accountTargetTemplates = aiKuaishouAccountTargetTemplateService.getAllEffectTemplate();
  448. // if (null == accountTargetTemplates || accountTargetTemplates.isEmpty()) {
  449. // return;
  450. // }
  451. // for (AiKuaishouAccountTargetTemplate template:accountTargetTemplates){
  452. // if(template.getAccountId()!=9556344L){
  453. // AiKuaishouAccountTargetTemplate accountTargetTemplate2 = aiKuaishouAccountTargetTemplateService.getByAccountId(template.getAccountId());
  454. // aiKuaishouNewCreateCampaign.kuaishouAiAddNewMaterialCreativity(accountTargetTemplate2,50);
  455. // }
  456. // }
  457. /**
  458. * 120002
  459. * 150001
  460. * 150002
  461. * 150003
  462. * 150004
  463. */
  464. AiKuaishouAccountTargetTemplate accountTargetTemplate2 = aiKuaishouAccountTargetTemplateService.getById(120002);
  465. aiKuaishouNewCreateCampaign.kuaishouAiAddNewMaterialCreativity(accountTargetTemplate2, 250);
  466. accountTargetTemplate2 = aiKuaishouAccountTargetTemplateService.getById(150001);
  467. aiKuaishouNewCreateCampaign.kuaishouAiAddNewMaterialCreativity(accountTargetTemplate2, 250);
  468. accountTargetTemplate2 = aiKuaishouAccountTargetTemplateService.getById(150002);
  469. aiKuaishouNewCreateCampaign.kuaishouAiAddNewMaterialCreativity(accountTargetTemplate2, 250);
  470. accountTargetTemplate2 = aiKuaishouAccountTargetTemplateService.getById(150003);
  471. aiKuaishouNewCreateCampaign.kuaishouAiAddNewMaterialCreativity(accountTargetTemplate2, 250);
  472. accountTargetTemplate2 = aiKuaishouAccountTargetTemplateService.getById(150004);
  473. aiKuaishouNewCreateCampaign.kuaishouAiAddNewMaterialCreativity(accountTargetTemplate2, 250);
  474. }
  475. @Test
  476. public void testLoadBytedanceDataV2(){
  477. String accountIds=
  478. "1675440464386062," +
  479. "1688606248211533," +
  480. "1669181787105294," +
  481. "1687571097467912," +
  482. "1650079154438157," +
  483. "1680697900744711," +
  484. "1678156679964680," +
  485. "1670727177043982," +
  486. "1676160388944910," +
  487. "1687559760306190," +
  488. "1687382871519240," +
  489. "1680312075164686," +
  490. "1675440465991688," +
  491. "1664657972166663," +
  492. "1688193173408782," +
  493. "1675616147056647," +
  494. "1687308848716814," +
  495. "1686394621234247," +
  496. "1683594409340935," +
  497. "1683676478859341," +
  498. "1686384860112904," +
  499. "1668290872519693," +
  500. "1674063202781191," +
  501. "1685024266033160," +
  502. "1669714891201544," +
  503. "1687758256277512," +
  504. "1675434231118856," +
  505. "1686394621807687," +
  506. "1678411706704903," +
  507. "1686223489547271," +
  508. "1660120711467022," +
  509. "1686833795211278," +
  510. "1680697899143175," +
  511. "1661313994984462," +
  512. "1661313995480077," +
  513. "1636295780727820," +
  514. "1676540490482759," +
  515. "1675342904713223," +
  516. "1686771461984327," +
  517. "1685841129360391," +
  518. "1683676477736973," +
  519. "1661313994470413," +
  520. "1663465141771272," +
  521. "1687758256732174," +
  522. "1686223482927117," +
  523. "1686835166313479," +
  524. "1642648003678215," +
  525. "1639753233213454," +
  526. "1675239584963662," +
  527. "1674634579279885," +
  528. "1650263841162253," +
  529. "1672178052130888";
  530. String [] accountArray = accountIds.split(",");
  531. for (int i=0;i<accountArray.length;i++){
  532. CtopOauthToken token = tokenService.getTokenByAccountId(Long.parseLong(accountArray[i]));
  533. reportService.getAdvertiserReport(token, DateUtils.parseDate("2021-01-14","yyyy-MM-dd"), DateUtils.parseDate("2021-01-14","yyyy-MM-dd"),CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  534. }
  535. }
  536. @Test
  537. public void checkBytedanceReport(){
  538. CtopOauthToken token = tokenService.getTokenByAccountId(1678959391271949L);
  539. String startDate = "2021-01-01 00:00:00";
  540. String endDate = "2021-01-31 00:00:00";
  541. bytedanceReportService.checkoutData(token,startDate,endDate);
  542. }
  543. @Test
  544. public void etlKuaishouProjectData() {
  545. CtopOauthToken token = tokenService.getTokenByAccountId(1660666858777607L);
  546. reportService.getAdvertiserPlanReport(token, DateUtils.parseDate("2021-01-25", "yyyy-MM-dd"), DateUtils.parseDate("2021-01-25", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  547. }
  548. @Autowired
  549. IBytedanceVideoReportService bytedanceVideoReportService;
  550. @Test
  551. public void etlBytedanceVideoReport() {
  552. // for (int i = 1; i <= 62; i++) {
  553. // etlBytedanceVideo(DateUtils.formatDate(DateUtils.addDay(new Date(), -i)));
  554. // }
  555. etlBytedanceVideo("2021-02-03");
  556. }
  557. private void etlBytedanceVideo(String statDate) {
  558. List<CtopOauthToken> tokens = oauthTokenService.selectToutiaoToken();
  559. executorService = Executors.newFixedThreadPool(10);
  560. countDownLatch = new CountDownLatch(tokens.size());
  561. tokens.forEach(token -> executorService.submit(() -> {
  562. try {
  563. bytedanceVideoReportService.pullVideoReport(token, statDate, statDate, 1);
  564. } catch (Exception e) {
  565. } finally {
  566. countDownLatch.countDown();
  567. }
  568. }));
  569. try {
  570. countDownLatch.await();
  571. } catch (InterruptedException e) {
  572. e.printStackTrace();
  573. }
  574. }
  575. @Autowired
  576. IETLReportBytedanceVideoService ietlReportBytedanceVideoService;
  577. @Test
  578. public void etlBytedanceVideoReportClean() {
  579. //for (int i = 1; i <= 1; i++) {
  580. // String statDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -i));
  581. ietlReportBytedanceVideoService.cleanETL("2020-12-31");
  582. //}
  583. }
  584. @Test
  585. public void etlBytedanceVideoReportClean1() {
  586. //executorService = Executors.newFixedThreadPool(31);
  587. //countDownLatch = new CountDownLatch(31);
  588. for (int i = 3; i <= 31; i++) {
  589. String statDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -i));
  590. ietlReportBytedanceVideoService.cleanETL(statDate);
  591. }
  592. }
  593. }