SampleTest.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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.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.IByteDanceVideoReportDailyService;
  23. import cn.com.ctop.toutiao.modules.report.service.IBytedanceFundDailyService;
  24. import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
  25. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  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 loadKuaishouAgentData() {
  226. kuaishouReportDailyAgentService.loginAgent();
  227. try {
  228. for (int i = 1; i < 30; i++) {
  229. kuaishouReportDailyAgentService.getAccount(i);
  230. }
  231. } catch (Exception e) {
  232. e.printStackTrace();
  233. }
  234. }
  235. @Test
  236. public void loadKuaishouData() {
  237. Date getDate = DateUtils.addDay(new Date(), -1);
  238. //1:查询当日数据
  239. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  240. for (CtopOauthToken token : tokens) {
  241. kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getDate, getDate);
  242. }
  243. }
  244. @Autowired
  245. private IBytedanceReportService bytedanceReportService;
  246. @Test
  247. public void loadBytedanceVideoReportData() {
  248. Date getDate = DateUtils.addDay(new Date(), -1);
  249. String date = DateUtils.formatDate(getDate);
  250. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  251. for (CtopOauthToken token : tokens) {
  252. bytedanceReportService.bytedanceVideoMaterialReport(token, date, date);
  253. }
  254. }
  255. @Test
  256. public void loadKuaishouHourlyReportData() {
  257. Date getDate = new Date();
  258. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
  259. String hour = simpleDateFormat.format(getDate);
  260. if ("00".equals(hour)) {
  261. getDate = DateUtils.addDay(getDate, -1);
  262. }
  263. //1:查询当日数据
  264. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  265. Date finalGetDate = getDate;
  266. tokens.forEach(token -> kuaishouInterfaceService.getAdvertiserReportHourly(token, finalGetDate, finalGetDate));
  267. }
  268. @Autowired
  269. private IKuaishouInterfaceService kuaishouInterfaceService;
  270. @Test
  271. public void loadKuaishouGroupData() throws ParseException {
  272. Date endDate = new Date();
  273. String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.formatDate(endDate), -1);
  274. SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
  275. Date startDate = sim.parse(anotherDay);
  276. CtopOauthToken token = tokenService.getTokenByAccountId(7087890L);
  277. kuaishouInterfaceService.getGroupList(token, startDate, endDate);
  278. }
  279. @Test
  280. public void loadAccountData() {
  281. // List<UserAllocation> allocations = allocationService.getByParams(776L,null,0);
  282. // for (UserAllocation allocation:allocations) {
  283. CtopOauthToken token = tokenService.getTokenByAccountId(93238965516L);
  284. for (int i = 92; i < 100; i++) {
  285. Date getDate = DateUtils.addDay(new Date(), -i);
  286. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  287. }
  288. // }
  289. }
  290. @Autowired
  291. private IKuaishouCostGroupService kuaishouCostGroupService;
  292. @Autowired
  293. private IAlarmEventSendService alarmEventSendService;
  294. @Autowired
  295. private IWechatCheckinDataService wechatCheckinDataService;
  296. @Autowired
  297. private IWechatUserListService wechatUserInfoService;
  298. @Autowired
  299. private IWechatNoListService wechatNoListService;
  300. @Test
  301. public void getData() {
  302. //汇创 人员
  303. // wechatUserInfoService.getUserList();
  304. // //考勤记录
  305. // wechatCheckinDataService.getCheckinData("2020-11-01 00:00:00", "2020-12-01 23:59:59");
  306. //异常记录
  307. // wechatNoListService.getNoDateByNo("2020-11-01 00:00:00", "2020-12-01 23:59:59", "0");
  308. //优容
  309. wechatUserInfoService.getYRUserList();
  310. wechatCheckinDataService.getYRCheckinData("2020-11-01 00:00:00", "2020-11-30 23:59:59");
  311. wechatNoListService.getNoDateByNo("2020-11-01 00:00:00", "2020-12-01 23:59:59", "1");
  312. }
  313. @Autowired
  314. IRuleKuaiShouPlanService kuaiShouPlanService;
  315. @Test
  316. public void kuaishouRuleData() {
  317. kuaiShouPlanService.cleanRuleDataUnit(3429620L, "2020-12-07", "2020-12-07", 1);
  318. }
  319. @Autowired
  320. private IKuaiShouCommentService kuaiShouCommentService;
  321. @Test
  322. public void kuaishouDeleteComment() {
  323. kuaiShouCommentService.shieldComment(8018853L);
  324. }
  325. @Autowired
  326. private IByteDanceVideoReportDailyService videoReportDailyService;
  327. @Test
  328. public void formatVideoReportData() {
  329. for (int i = 1; i < 45; i++) {
  330. Date getDate = DateUtils.addDay(new Date(), -i);
  331. String date = DateUtils.formatDate(getDate);
  332. videoReportDailyService.videoInfoList(date, date);
  333. }
  334. }
  335. @Autowired
  336. private IRuleKuaiShouPlanService ruleKuaiShouPlanService;
  337. @Test
  338. public void execute() {
  339. CtopOauthToken token = tokenService.getTokenByAccountId(9589905L);
  340. ruleKuaiShouPlanService.cleanRuleDataTarget(token.getAccountId(), 1);
  341. }
  342. }