SampleTest.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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.Check;
  9. import cn.com.ctop.common.module.utils.CtopAdConstant;
  10. import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountTargetTemplate;
  11. import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAccountTargetTemplateService;
  12. import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouNewCreateCampaign;
  13. import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
  14. import cn.com.ctop.kuaishou.modules.batch.service.*;
  15. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  16. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
  17. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouVideoEtlInfoService;
  18. import cn.com.ctop.kuaishou.modules.report.service.IRuleKuaiShouPlanService;
  19. import cn.com.ctop.oa.modules.service.IWechatCheckinDataService;
  20. import cn.com.ctop.oa.modules.service.IWechatNoListService;
  21. import cn.com.ctop.oa.modules.service.IWechatUserListService;
  22. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  23. import cn.com.ctop.toutiao.modules.report.service.*;
  24. import com.alibaba.fastjson.JSONArray;
  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 java.text.ParseException;
  34. import java.text.SimpleDateFormat;
  35. import java.util.Date;
  36. import java.util.HashMap;
  37. import java.util.List;
  38. import java.util.Map;
  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. @Autowired
  59. private IKuaishouInterfaceService iKuaishouInterfaceService;
  60. @Autowired
  61. private IKuaiShouVideoGetService videoGetService;
  62. @Autowired
  63. private IKuaishouVideoRelateCreativesService kuaishouVideoRelateCreativesService;
  64. @Test
  65. public void loadBytedanceCreativeData() throws ParseException {
  66. List<KuaiShouVideoGet> KuaiShouVideoGets = videoGetService.selectPhotoIdsByAccountId(9743746L);
  67. if (!Check.isNull(KuaiShouVideoGets)) {
  68. JSONArray dateList = new JSONArray();
  69. JSONArray photoIds = new JSONArray();
  70. Map<String, Object> statdateMap = new HashMap<>();
  71. int count = 0;
  72. for (KuaiShouVideoGet video : KuaiShouVideoGets) {
  73. count++;
  74. if (count < 10) {
  75. photoIds.add(video.getPhotoId());
  76. statdateMap.put(video.getPhotoId(), video.getStatDate());
  77. } else {
  78. photoIds.add(video.getPhotoId());
  79. statdateMap.put(video.getPhotoId(), video.getStatDate());
  80. dateList.add(photoIds);
  81. photoIds = new JSONArray();
  82. count = 0;
  83. }
  84. }
  85. dateList.add(photoIds);
  86. kuaishouVideoRelateCreativesService.videoRelateCreatives(9743746L, dateList, statdateMap);
  87. }
  88. /* QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  89. queryWrapper.eq("media_id", 2);
  90. List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
  91. for (CtopOauthToken token : list) {
  92. kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-20", "2020-09-20", "daily");
  93. }*/
  94. }
  95. @Autowired
  96. private IBindAccountLoginService bindAccountLoginService;
  97. @Autowired
  98. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  99. @Test
  100. public void loadKuaishouCookie() {
  101. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  102. if (list != null && !list.isEmpty()) {
  103. int i = 0;
  104. for (BindAccountLogin login : list) {
  105. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  106. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  107. i++;
  108. }
  109. }
  110. }
  111. }
  112. static ExecutorService executorService = null;
  113. static CountDownLatch countDownLatch = null;
  114. @Test
  115. public void deleteKuaishouComment() {
  116. Long start = System.currentTimeMillis();
  117. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  118. if (loginList != null && !loginList.isEmpty()) {
  119. executorService = Executors.newFixedThreadPool(5);
  120. countDownLatch = new CountDownLatch(loginList.size());
  121. loginList.forEach(login -> executorService.submit(() -> {
  122. try {
  123. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  124. } catch (Exception e) {
  125. log.error(e.getMessage(), e);
  126. } finally {
  127. countDownLatch.countDown();
  128. }
  129. }));
  130. try {
  131. countDownLatch.await();
  132. } catch (InterruptedException e) {
  133. e.printStackTrace();
  134. }
  135. Long end = System.currentTimeMillis();
  136. log.info("快手删评论所用时长:{}毫秒", end - start);
  137. }
  138. }
  139. @Autowired
  140. private IUserAllocationService allocationService;
  141. @Test
  142. public void testLoadBytedanceData() {
  143. List<UserAllocation> allocations = allocationService.getByParams(633L, null, 0);
  144. if (null != allocations && !allocations.isEmpty()) {
  145. for (UserAllocation allocation : allocations) {
  146. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  147. String startDate = "2020-11-10";
  148. String endDate = "2020-11-10";
  149. reportService.getAdvertiserReport(token, DateUtils.parseDate(startDate, "yyyy-MM-dd"), DateUtils.parseDate(endDate, "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  150. }
  151. }
  152. System.out.println("任务结束");
  153. }
  154. @Test
  155. public void loadKuaishouPlanData() {
  156. Date getDate = DateUtils.addDay(new Date(), -1);
  157. //1:查询当日数据
  158. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  159. tokens.forEach(token -> kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getDate, getDate));
  160. }
  161. @Autowired
  162. private IBytedanceFundDailyService bytedanceFundDailyService;
  163. @Test
  164. public void loadFoudData() {
  165. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  166. for (CtopOauthToken token : tokens) {
  167. System.out.println(token.getAccountId() + "############################");
  168. for (int i = 20; i < 130; i++) {
  169. Date date = DateUtils.addDay(new Date(), -i);
  170. bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date), 1);
  171. System.out.println(i + "############################");
  172. }
  173. }
  174. }
  175. @Autowired
  176. private IKuaiShouHistoryReportTaskService reportTaskService;
  177. /**
  178. * 测试获取快手图片消耗数据任务
  179. */
  180. @Test
  181. public void loadKuaishouImageTask() {
  182. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  183. for (int i = 1; i < 130; i++) {
  184. Date getDate = DateUtils.addDay(new Date(), -i);
  185. String getDateStr = DateUtils.formatDate(getDate);
  186. tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
  187. }
  188. }
  189. @Autowired
  190. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  191. /**
  192. * 测试获取快手图片消耗数据入库
  193. */
  194. @Test
  195. public void loadKuaishouImageTaskFile() {
  196. String nowDate = DateUtils.getDate("yyyy-MM-dd");
  197. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  198. for (int i = 1; i < 15; i++) {
  199. String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -i);
  200. tokens.forEach(token -> dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate));
  201. }
  202. // 查询快手token
  203. }
  204. @Test
  205. public void testLoadBytedanceImageData() {
  206. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  207. countDownLatch = new CountDownLatch(tokens.size());
  208. executorService = Executors.newFixedThreadPool(8);
  209. tokens.forEach(token -> executorService.submit(() -> {
  210. try {
  211. advertiserDataService.getMaterialList(token);
  212. } catch (Exception e) {
  213. } finally {
  214. countDownLatch.countDown();
  215. }
  216. }));
  217. try {
  218. countDownLatch.await();
  219. } catch (InterruptedException e) {
  220. e.printStackTrace();
  221. }
  222. System.out.println("素材数据获取完成");
  223. }
  224. @Autowired
  225. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  226. @Test
  227. public void testData() {
  228. Date date = new Date();
  229. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  230. executorService = Executors.newFixedThreadPool(10);
  231. countDownLatch = new CountDownLatch(tokens.size());
  232. tokens.forEach(token -> executorService.submit(() -> {
  233. try {
  234. reportService.getAdvertiserPlanRuleData(token, date, date, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  235. } catch (Exception e) {
  236. } finally {
  237. countDownLatch.countDown();
  238. }
  239. }));
  240. try {
  241. countDownLatch.await();
  242. } catch (InterruptedException e) {
  243. e.printStackTrace();
  244. }
  245. }
  246. @Test
  247. public void testData11() {
  248. CtopOauthToken token = tokenService.getTokenByAccountId(9556344L);
  249. int dimeDiff = 5;
  250. Date now = new Date();
  251. String startTime = DateUtils.formatDate("2021-01-11 18:25:00");
  252. String endTime = DateUtils.formatDate(now, "2021-01-11 18:35:00");
  253. kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1, startTime, endTime);
  254. }
  255. @Test
  256. public void loadKuaishouAgentData() {
  257. kuaishouReportDailyAgentService.loginAgent();
  258. try {
  259. for (int i = 1; i < 30; i++) {
  260. kuaishouReportDailyAgentService.getAccount(i);
  261. }
  262. } catch (Exception e) {
  263. e.printStackTrace();
  264. }
  265. }
  266. @Test
  267. public void loadKuaishouData() {
  268. Date getDate = DateUtils.addDay(new Date(), -1);
  269. //1:查询当日数据
  270. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  271. for (CtopOauthToken token : tokens) {
  272. kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getDate, getDate);
  273. }
  274. }
  275. @Autowired
  276. private IBytedanceReportService bytedanceReportService;
  277. @Test
  278. public void loadBytedanceVideoReportData() {
  279. Date getDate = DateUtils.addDay(new Date(), -1);
  280. String date = DateUtils.formatDate(getDate);
  281. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  282. for (CtopOauthToken token : tokens) {
  283. bytedanceReportService.bytedanceVideoMaterialReport(token, date, date);
  284. }
  285. }
  286. @Test
  287. public void loadKuaishouHourlyReportData() {
  288. Date getDate = new Date();
  289. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
  290. String hour = simpleDateFormat.format(getDate);
  291. if ("00".equals(hour)) {
  292. getDate = DateUtils.addDay(getDate, -1);
  293. }
  294. //1:查询当日数据
  295. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  296. Date finalGetDate = getDate;
  297. tokens.forEach(token -> kuaishouInterfaceService.getAdvertiserReportHourly(token, finalGetDate, finalGetDate));
  298. }
  299. @Autowired
  300. private IKuaishouInterfaceService kuaishouInterfaceService;
  301. @Test
  302. public void loadKuaishouGroupData() throws ParseException {
  303. Date endDate = new Date();
  304. String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.formatDate(endDate), -1);
  305. SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
  306. Date startDate = sim.parse(anotherDay);
  307. CtopOauthToken token = tokenService.getTokenByAccountId(7087890L);
  308. kuaishouInterfaceService.getGroupList(token, startDate, endDate);
  309. }
  310. @Test
  311. public void loadAccountData() {
  312. // List<UserAllocation> allocations = allocationService.getByParams(776L,null,0);
  313. // for (UserAllocation allocation:allocations) {
  314. CtopOauthToken token = tokenService.getTokenByAccountId(93238965516L);
  315. for (int i = 92; i < 100; i++) {
  316. Date getDate = DateUtils.addDay(new Date(), -i);
  317. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  318. }
  319. // }
  320. }
  321. @Autowired
  322. private IWechatCheckinDataService wechatCheckinDataService;
  323. @Autowired
  324. private IWechatUserListService wechatUserInfoService;
  325. @Autowired
  326. private IWechatNoListService wechatNoListService;
  327. @Test
  328. public void getData() {
  329. //汇创 人员
  330. // wechatUserInfoService.getUserList();
  331. // //考勤记录
  332. // wechatCheckinDataService.getCheckinData("2020-11-01 00:00:00", "2020-12-01 23:59:59");
  333. //异常记录
  334. // wechatNoListService.getNoDateByNo("2020-11-01 00:00:00", "2020-12-01 23:59:59", "0");
  335. //优容
  336. wechatUserInfoService.getYRUserList();
  337. wechatCheckinDataService.getYRCheckinData("2020-11-01 00:00:00", "2020-11-30 23:59:59");
  338. wechatNoListService.getNoDateByNo("2020-11-01 00:00:00", "2020-12-01 23:59:59", "1");
  339. }
  340. @Autowired
  341. private IKuaiShouCommentService kuaiShouCommentService;
  342. @Test
  343. public void kuaishouDeleteComment() {
  344. kuaiShouCommentService.shieldComment(8018853L);
  345. }
  346. @Autowired
  347. private IByteDanceVideoReportDailyService videoReportDailyService;
  348. @Test
  349. public void formatVideoReportData() {
  350. for (int i = 1; i < 45; i++) {
  351. Date getDate = DateUtils.addDay(new Date(), -i);
  352. String date = DateUtils.formatDate(getDate);
  353. videoReportDailyService.videoInfoList(date, date);
  354. }
  355. }
  356. @Autowired
  357. private IRuleKuaiShouPlanService ruleKuaiShouPlanService;
  358. @Test
  359. public void execute() {
  360. String accountIds = "1675239584963662,1675237415468045";
  361. String[] arrays = accountIds.split(",");
  362. for (int i = 0; i < arrays.length; i++) {
  363. Long accountId = Long.parseLong(arrays[i]);
  364. CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
  365. load12Data(token);
  366. load12AccountData(token);
  367. }
  368. }
  369. private void load12AccountData(CtopOauthToken token) {
  370. reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-12-01", "yyyy-MM-dd"), DateUtils.parseDate("2020-12-11", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  371. reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-12-11", "yyyy-MM-dd"), DateUtils.parseDate("2020-12-21", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  372. reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-12-21", "yyyy-MM-dd"), DateUtils.parseDate("2020-12-31", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  373. }
  374. private void load12Data(CtopOauthToken token) {
  375. bytedanceReportService.bytedanceMaterialReport(token, "2020-12-01", "2020-12-11");
  376. bytedanceReportService.bytedanceMaterialReport(token, "2020-12-11", "2020-12-21");
  377. bytedanceReportService.bytedanceMaterialReport(token, "2020-12-21", "2020-12-31");
  378. }
  379. @Autowired
  380. private IKuaishouVideoEtlInfoService kuaishouVideoEtlInfoService;
  381. @Test
  382. public void etlKuaishouData() {
  383. String dateString = "2021-01-05";
  384. Date startDate = DateUtils.parseDate(dateString, "yyyy-MM-dd");
  385. for (int i = 0; i <= 10; i++) {
  386. Date getDate = DateUtils.addDay(startDate, i);
  387. kuaishouVideoEtlInfoService.etlKuaishouVideoInfo(getDate);
  388. bytedanceVideoEtlInfoService.etlBytedanceVideoInfo(getDate);
  389. }
  390. }
  391. @Autowired
  392. private IBytedanceVideoEtlInfoService bytedanceVideoEtlInfoService;
  393. @Test
  394. public void loadBytedanceVideo() {
  395. CtopOauthToken token = tokenService.getTokenByAccountId(1673731601820686L);
  396. for (int i = 15; i < 60; i++) {
  397. reportService.getAdvertiserReport(token, DateUtils.addDay(new Date(), -i), DateUtils.addDay(new Date(), -i), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  398. }
  399. }
  400. @Test
  401. public void loadKuaishouVideo() {
  402. Date date = new Date();
  403. CtopOauthToken token = tokenService.getTokenByAccountId(9556344L);
  404. // kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token, new Date(), new Date(), null, null);
  405. kuaishouInterfaceService.getVideoList(token, DateUtils.formatDate(DateUtils.addDay(date, -5)), DateUtils.formatDate(date));
  406. // 获取图片信息数据
  407. // kuaishouInterfaceService.getImageList(token, DateUtils.getNowDate("yyyy-MM-dd"));
  408. }
  409. @Autowired
  410. IRuleByteDanceAccountService ruleByteDanceAccountService;
  411. @Test
  412. public void cleanRuleDataAccount() {
  413. List<CtopOauthToken> tokens = oauthTokenService.selectKuaiShouToken();
  414. for (CtopOauthToken oauthToken : tokens) {
  415. ruleKuaiShouPlanService.cleanRuleDataTarget(oauthToken.getAccountId(), 1);
  416. }
  417. }
  418. @Autowired
  419. IAiKuaishouNewCreateCampaign aiKuaishouNewCreateCampaign;
  420. @Autowired
  421. private IAiKuaishouAccountTargetTemplateService aiKuaishouAccountTargetTemplateService;
  422. @Test
  423. public void createPlan() {
  424. List<AiKuaishouAccountTargetTemplate> accountTargetTemplates = aiKuaishouAccountTargetTemplateService.getAllEffectTemplate();
  425. if (null == accountTargetTemplates || accountTargetTemplates.isEmpty()) {
  426. return;
  427. }
  428. accountTargetTemplates.forEach(targetTemplate -> aiKuaishouNewCreateCampaign.kuaishouAiAdsNewMaterialCreativity(targetTemplate));
  429. }
  430. @Test
  431. public void etlKuaishouProjectData(){
  432. String dateString = "2020-03-17";
  433. Date startDate = DateUtils.parseDate(dateString,"yyyy-MM-dd");
  434. for(int i=0;i<=365;i++){
  435. Date getDate = DateUtils.addDay(startDate,i);
  436. kuaishouVideoEtlInfoService.etlKuaishouVideoInfoGroupByProjectId(getDate);
  437. }
  438. }
  439. }