SampleTest.java 29 KB

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