SampleTest.java 20 KB

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