SampleTest.java 14 KB

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