SampleTest.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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.IByteDanceVideoReportDailyService;
  25. import cn.com.ctop.toutiao.modules.report.service.IBytedanceFundDailyService;
  26. import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
  27. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  28. import com.alibaba.fastjson.JSONObject;
  29. import lombok.extern.slf4j.Slf4j;
  30. import org.jeecg.common.util.DateUtils;
  31. import org.junit.Test;
  32. import org.junit.runner.RunWith;
  33. import org.springframework.beans.factory.annotation.Autowired;
  34. import org.springframework.boot.test.context.SpringBootTest;
  35. import org.springframework.test.context.ActiveProfiles;
  36. import org.springframework.test.context.junit4.SpringRunner;
  37. import java.text.ParseException;
  38. import java.text.SimpleDateFormat;
  39. import java.util.Date;
  40. import java.util.HashMap;
  41. import java.util.List;
  42. import java.util.concurrent.CountDownLatch;
  43. import java.util.concurrent.ExecutorService;
  44. import java.util.concurrent.Executors;
  45. import static org.jeecg.common.util.DateUtils.getAnotherDay;
  46. @RunWith(SpringRunner.class)
  47. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  48. @ActiveProfiles("wps")
  49. @Slf4j
  50. public class SampleTest {
  51. @Autowired
  52. private ICtopOauthTokenService oauthTokenService;
  53. @Autowired
  54. private IReportService reportService;
  55. @Autowired
  56. private IByteDanceAdvertiserDataService advertiserDataService;
  57. @Autowired
  58. private IKuaiShouHistoryReportTaskService kuaiShouHistoryReportTaskService;
  59. @Autowired
  60. private ICtopOauthTokenService tokenService;
  61. @Autowired
  62. private IKuaishouInterfaceService iKuaishouInterfaceService;
  63. @Test
  64. public void loadBytedanceCreativeData() throws ParseException {
  65. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  66. Date parse = simpleDateFormat.parse("2020-12-11");
  67. CtopOauthToken tokenByAccountId = oauthTokenService.getTokenByAccountId(5982133L);
  68. iKuaishouInterfaceService.getAdvertiserGroupReportDaily(tokenByAccountId, parse, parse);
  69. /* QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  70. queryWrapper.eq("media_id", 2);
  71. List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
  72. for (CtopOauthToken token : list) {
  73. kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-20", "2020-09-20", "daily");
  74. }*/
  75. }
  76. @Autowired
  77. private IBindAccountLoginService bindAccountLoginService;
  78. @Autowired
  79. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  80. @Test
  81. public void loadKuaishouCookie() {
  82. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  83. if (list != null && !list.isEmpty()) {
  84. int i = 0;
  85. for (BindAccountLogin login : list) {
  86. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  87. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  88. i++;
  89. }
  90. }
  91. }
  92. }
  93. static ExecutorService executorService = null;
  94. static CountDownLatch countDownLatch = null;
  95. @Test
  96. public void deleteKuaishouComment() {
  97. Long start = System.currentTimeMillis();
  98. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  99. if (loginList != null && !loginList.isEmpty()) {
  100. executorService = Executors.newFixedThreadPool(5);
  101. countDownLatch = new CountDownLatch(loginList.size());
  102. loginList.forEach(login -> executorService.submit(() -> {
  103. try {
  104. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  105. } catch (Exception e) {
  106. log.error(e.getMessage(), e);
  107. } finally {
  108. countDownLatch.countDown();
  109. }
  110. }));
  111. try {
  112. countDownLatch.await();
  113. } catch (InterruptedException e) {
  114. e.printStackTrace();
  115. }
  116. Long end = System.currentTimeMillis();
  117. log.info("快手删评论所用时长:{}毫秒", end - start);
  118. }
  119. }
  120. @Autowired
  121. private IUserAllocationService allocationService;
  122. @Test
  123. public void testLoadBytedanceData() {
  124. List<UserAllocation> allocations = allocationService.getByParams(633L, null, 0);
  125. if (null != allocations && !allocations.isEmpty()) {
  126. for (UserAllocation allocation : allocations) {
  127. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  128. String startDate = "2020-11-10";
  129. String endDate = "2020-11-10";
  130. reportService.getAdvertiserReport(token, DateUtils.parseDate(startDate, "yyyy-MM-dd"), DateUtils.parseDate(endDate, "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  131. }
  132. }
  133. System.out.println("任务结束");
  134. }
  135. @Test
  136. public void loadKuaishouPlanData() {
  137. Date getDate = DateUtils.addDay(new Date(), -1);
  138. //1:查询当日数据
  139. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  140. tokens.forEach(token -> kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getDate, getDate));
  141. }
  142. @Autowired
  143. private IBytedanceFundDailyService bytedanceFundDailyService;
  144. @Test
  145. public void loadFoudData() {
  146. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  147. for (CtopOauthToken token : tokens) {
  148. System.out.println(token.getAccountId() + "############################");
  149. for (int i = 20; i < 130; i++) {
  150. Date date = DateUtils.addDay(new Date(), -i);
  151. bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date), 1);
  152. System.out.println(i + "############################");
  153. }
  154. }
  155. }
  156. @Autowired
  157. private IKuaiShouHistoryReportTaskService reportTaskService;
  158. /**
  159. * 测试获取快手图片消耗数据任务
  160. */
  161. @Test
  162. public void loadKuaishouImageTask() {
  163. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  164. for (int i = 1; i < 130; i++) {
  165. Date getDate = DateUtils.addDay(new Date(), -i);
  166. String getDateStr = DateUtils.formatDate(getDate);
  167. tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
  168. }
  169. }
  170. @Autowired
  171. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  172. /**
  173. * 测试获取快手图片消耗数据入库
  174. */
  175. @Test
  176. public void loadKuaishouImageTaskFile() {
  177. String nowDate = DateUtils.getDate("yyyy-MM-dd");
  178. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  179. for (int i = 1; i < 15; i++) {
  180. String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -i);
  181. tokens.forEach(token -> dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate));
  182. }
  183. // 查询快手token
  184. }
  185. @Test
  186. public void testLoadBytedanceImageData() {
  187. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  188. countDownLatch = new CountDownLatch(tokens.size());
  189. executorService = Executors.newFixedThreadPool(8);
  190. tokens.forEach(token -> executorService.submit(() -> {
  191. try {
  192. advertiserDataService.getMaterialList(token);
  193. } catch (Exception e) {
  194. } finally {
  195. countDownLatch.countDown();
  196. }
  197. }));
  198. try {
  199. countDownLatch.await();
  200. } catch (InterruptedException e) {
  201. e.printStackTrace();
  202. }
  203. System.out.println("素材数据获取完成");
  204. }
  205. @Autowired
  206. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  207. @Test
  208. public void testData() {
  209. Date date = new Date();
  210. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  211. executorService = Executors.newFixedThreadPool(10);
  212. countDownLatch = new CountDownLatch(tokens.size());
  213. tokens.forEach(token -> executorService.submit(() -> {
  214. try {
  215. reportService.getAdvertiserPlanRuleData(token, date, date, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  216. } catch (Exception e) {
  217. } finally {
  218. countDownLatch.countDown();
  219. }
  220. }));
  221. try {
  222. countDownLatch.await();
  223. } catch (InterruptedException e) {
  224. e.printStackTrace();
  225. }
  226. }
  227. @Test
  228. public void testData11(){
  229. CtopOauthToken token =tokenService.getTokenByAccountId(1683711016125448L);
  230. reportService.getAdvertiserPlanRuleData(token,new Date(),new Date(), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  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. IRuleKuaiShouPlanService kuaiShouPlanService;
  319. @Test
  320. public void kuaishouRuleData() {
  321. kuaiShouPlanService.cleanRuleDataUnit(3429620L, "2020-12-07", "2020-12-07", 1);
  322. }
  323. @Autowired
  324. private IKuaiShouCommentService kuaiShouCommentService;
  325. @Test
  326. public void kuaishouDeleteComment() {
  327. kuaiShouCommentService.shieldComment(8018853L);
  328. }
  329. @Autowired
  330. private IByteDanceVideoReportDailyService videoReportDailyService;
  331. @Test
  332. public void formatVideoReportData() {
  333. for (int i = 1; i < 45; i++) {
  334. Date getDate = DateUtils.addDay(new Date(), -i);
  335. String date = DateUtils.formatDate(getDate);
  336. videoReportDailyService.videoInfoList(date, date);
  337. }
  338. }
  339. @Autowired
  340. private org.jeecg.modules.ads.service.Test test;
  341. @Test
  342. public void test(){
  343. test.f();
  344. }
  345. @Autowired
  346. private IRuleKuaiShouPlanService ruleKuaiShouPlanService;
  347. @Test
  348. public void execute() {
  349. CtopOauthToken token = tokenService.getTokenByAccountId(9589905L);
  350. ruleKuaiShouPlanService.cleanRuleDataTarget(token.getAccountId(), 1);
  351. }
  352. @Autowired
  353. private IKuaishouVideoEtlInfoService etlInfoService;
  354. @Test
  355. public void etlKuaishouData(){
  356. String dateString = "2020-05-25";
  357. Date startDate = DateUtils.parseDate(dateString,"yyyy-MM-dd");
  358. for(int i=0;i<=277;i++){
  359. Date getDate = DateUtils.addDay(startDate,i);
  360. etlInfoService.etlKuaishouVideoInfo(getDate);
  361. }
  362. }
  363. @Test
  364. public void loadBytedanceVideo(){
  365. CtopOauthToken token = tokenService.getTokenByAccountId(1673731601820686L);
  366. for(int i=15;i<60;i++){
  367. reportService.getAdvertiserReport(token,DateUtils.addDay(new Date(),-i),DateUtils.addDay(new Date(),-i),CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  368. }
  369. }
  370. @Test
  371. public void loadKuaishouVideo(){
  372. String endDate = DateUtils.getNowDate("yyyy-MM-dd");
  373. CtopOauthToken token = tokenService.getTokenByAccountId(9743023L);
  374. // kuaishouInterfaceService.getVideoList(token, endDate, endDate);
  375. kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token, new Date(), new Date(), null, null);
  376. }
  377. }