SampleTest.java 17 KB

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