SampleTest.java 18 KB

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