SampleTest.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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.IBytedanceFundDailyService;
  23. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  24. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  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. @Test
  58. public void loadBytedanceCreativeData() {
  59. QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  60. queryWrapper.eq("media_id", 2);
  61. List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
  62. for (CtopOauthToken token : list) {
  63. kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-20", "2020-09-20", "daily");
  64. }
  65. }
  66. @Autowired
  67. private IBindAccountLoginService bindAccountLoginService;
  68. @Autowired
  69. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  70. @Test
  71. public void loadKuaishouCookie() {
  72. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  73. if (list != null && !list.isEmpty()) {
  74. int i = 0;
  75. for (BindAccountLogin login : list) {
  76. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  77. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  78. i++;
  79. }
  80. }
  81. }
  82. }
  83. static ExecutorService executorService = null;
  84. static CountDownLatch countDownLatch = null;
  85. @Test
  86. public void deleteKuaishouComment() {
  87. Long start = System.currentTimeMillis();
  88. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  89. if (loginList != null && !loginList.isEmpty()) {
  90. executorService = Executors.newFixedThreadPool(5);
  91. countDownLatch = new CountDownLatch(loginList.size());
  92. loginList.forEach(login -> executorService.submit(() -> {
  93. try {
  94. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  95. } catch (Exception e) {
  96. log.error(e.getMessage(), e);
  97. } finally {
  98. countDownLatch.countDown();
  99. }
  100. }));
  101. try {
  102. countDownLatch.await();
  103. } catch (InterruptedException e) {
  104. e.printStackTrace();
  105. }
  106. Long end = System.currentTimeMillis();
  107. log.info("快手删评论所用时长:{}毫秒", end - start);
  108. }
  109. }
  110. @Autowired
  111. private IUserAllocationService allocationService;
  112. @Test
  113. public void testLoadBytedanceData() {
  114. List<UserAllocation> allocations = allocationService.getByParams(633L, null, 0);
  115. if (null != allocations && !allocations.isEmpty()) {
  116. for (UserAllocation allocation : allocations) {
  117. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  118. String startDate = "2020-11-10";
  119. String endDate = "2020-11-10";
  120. reportService.getAdvertiserReport(token, DateUtils.parseDate(startDate, "yyyy-MM-dd"), DateUtils.parseDate(endDate, "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  121. }
  122. }
  123. System.out.println("任务结束");
  124. }
  125. @Test
  126. public void loadKuaishouPlanData() {
  127. Date getDate = DateUtils.addDay(new Date(), -1);
  128. //1:查询当日数据
  129. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  130. tokens.forEach(token -> kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getDate, getDate));
  131. }
  132. @Autowired
  133. private IBytedanceFundDailyService bytedanceFundDailyService;
  134. @Test
  135. public void loadFoudData() {
  136. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  137. for (CtopOauthToken token : tokens) {
  138. System.out.println(token.getAccountId() + "############################");
  139. for (int i = 20; i < 130; i++) {
  140. Date date = DateUtils.addDay(new Date(), -i);
  141. bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date), 1);
  142. System.out.println(i + "############################");
  143. }
  144. }
  145. }
  146. @Autowired
  147. private IKuaiShouHistoryReportTaskService reportTaskService;
  148. /**
  149. * 测试获取快手图片消耗数据任务
  150. */
  151. @Test
  152. public void loadKuaishouImageTask() {
  153. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  154. for (int i = 1; i < 130; i++) {
  155. Date getDate = DateUtils.addDay(new Date(), -i);
  156. String getDateStr = DateUtils.formatDate(getDate);
  157. tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
  158. }
  159. }
  160. @Autowired
  161. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  162. /**
  163. * 测试获取快手图片消耗数据入库
  164. */
  165. @Test
  166. public void loadKuaishouImageTaskFile() {
  167. String nowDate = DateUtils.getDate("yyyy-MM-dd");
  168. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  169. for (int i = 1; i < 15; i++) {
  170. String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -i);
  171. tokens.forEach(token -> dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate));
  172. }
  173. // 查询快手token
  174. }
  175. @Test
  176. public void testLoadBytedanceImageData() {
  177. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  178. countDownLatch = new CountDownLatch(tokens.size());
  179. executorService = Executors.newFixedThreadPool(8);
  180. tokens.forEach(token -> executorService.submit(() -> {
  181. try {
  182. advertiserDataService.getMaterialList(token);
  183. } catch (Exception e) {
  184. } finally {
  185. countDownLatch.countDown();
  186. }
  187. }));
  188. try {
  189. countDownLatch.await();
  190. } catch (InterruptedException e) {
  191. e.printStackTrace();
  192. }
  193. System.out.println("素材数据获取完成");
  194. }
  195. @Autowired
  196. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  197. @Test
  198. public void testData() {
  199. Date date = new Date();
  200. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  201. executorService = Executors.newFixedThreadPool(10);
  202. countDownLatch = new CountDownLatch(tokens.size());
  203. tokens.forEach(token -> executorService.submit(() -> {
  204. try {
  205. reportService.getAdvertiserPlanRuleData(token, date, date, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  206. } catch (Exception e) {
  207. } finally {
  208. countDownLatch.countDown();
  209. }
  210. }));
  211. try {
  212. countDownLatch.await();
  213. } catch (InterruptedException e) {
  214. e.printStackTrace();
  215. }
  216. }
  217. @Test
  218. public void loadKuaishouAgentData() {
  219. kuaishouReportDailyAgentService.loginAgent();
  220. try {
  221. for (int i = 1; i < 30; i++) {
  222. kuaishouReportDailyAgentService.getAccount(i);
  223. }
  224. } catch (Exception e) {
  225. e.printStackTrace();
  226. }
  227. }
  228. @Test
  229. public void loadKuaishouData() {
  230. Date getDate = DateUtils.addDay(new Date(), -1);
  231. //1:查询当日数据
  232. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  233. for (CtopOauthToken token : tokens) {
  234. kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getDate, getDate);
  235. }
  236. }
  237. @Test
  238. public void loadKuaishouHourlyReportData() {
  239. Date getDate = new Date();
  240. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
  241. String hour = simpleDateFormat.format(getDate);
  242. if ("00".equals(hour)) {
  243. getDate = DateUtils.addDay(getDate, -1);
  244. }
  245. //1:查询当日数据
  246. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  247. Date finalGetDate = getDate;
  248. tokens.forEach(token -> kuaishouInterfaceService.getAdvertiserReportHourly(token, finalGetDate, finalGetDate));
  249. }
  250. @Autowired
  251. private IKuaishouInterfaceService kuaishouInterfaceService;
  252. @Test
  253. public void loadKuaishouGroupData() throws ParseException {
  254. Date endDate = new Date();
  255. String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.formatDate(endDate), -1);
  256. SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
  257. Date startDate = sim.parse(anotherDay);
  258. CtopOauthToken token = tokenService.getTokenByAccountId(7087890L);
  259. kuaishouInterfaceService.getGroupList(token, startDate, endDate);
  260. }
  261. @Test
  262. public void loadAccountData() {
  263. // List<UserAllocation> allocations = allocationService.getByParams(776L,null,0);
  264. // for (UserAllocation allocation:allocations) {
  265. CtopOauthToken token = tokenService.getTokenByAccountId(93238965516L);
  266. for (int i = 92; i < 100; i++) {
  267. Date getDate = DateUtils.addDay(new Date(), -i);
  268. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  269. }
  270. // }
  271. }
  272. @Autowired
  273. private IKuaishouCostGroupService kuaishouCostGroupService;
  274. @Autowired
  275. private IAlarmEventSendService alarmEventSendService;
  276. @Test
  277. public void addTest() {
  278. kuaishouCostGroupService.saveInfo();
  279. }
  280. @Test
  281. public void sendTest() {
  282. //检查频率 HOUR - 每小时;HALF_HOUR-每半小时
  283. alarmEventSendService.matchAlarmRules("HOUR");
  284. }
  285. @Autowired
  286. private IWechatCheckinDataService wechatCheckinDataService;
  287. @Autowired
  288. private IWechatUserListService wechatUserInfoService;
  289. @Autowired
  290. private IWechatNoListService wechatNoListService;
  291. @Test
  292. public void getData() {
  293. //汇创 人员
  294. // wechatUserInfoService.getUserList();
  295. // //考勤记录
  296. // wechatCheckinDataService.getCheckinData("2020-11-01 00:00:00", "2020-12-01 23:59:59");
  297. //异常记录
  298. // wechatNoListService.getNoDateByNo("2020-11-01 00:00:00", "2020-12-01 23:59:59", "0");
  299. //优容
  300. wechatUserInfoService.getYRUserList();
  301. wechatCheckinDataService.getYRCheckinData("2020-11-01 00:00:00", "2020-11-30 23:59:59");
  302. wechatNoListService.getNoDateByNo("2020-11-01 00:00:00", "2020-12-01 23:59:59", "1");
  303. }
  304. @Autowired
  305. IRuleKuaiShouPlanService kuaiShouPlanService;
  306. @Test
  307. public void kuaishouRuleData() {
  308. kuaiShouPlanService.cleanRuleDataUnit(3429620L, "2020-12-07", "2020-12-07", 1);
  309. }
  310. @Autowired
  311. private IKuaiShouCommentService kuaiShouCommentService;
  312. @Test
  313. public void kuaishouDeleteComment(){
  314. kuaiShouCommentService.shieldComment(8018853L);
  315. }
  316. }