SampleTest.java 19 KB

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