SampleTest.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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.ISendMessageService;
  9. import cn.com.ctop.common.module.service.IUserAllocationService;
  10. import cn.com.ctop.common.module.utils.CtopAdConstant;
  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.oa.modules.service.IWechatCheckinDataService;
  18. import cn.com.ctop.oa.modules.service.IWechatNoListService;
  19. import cn.com.ctop.oa.modules.service.IWechatUserListService;
  20. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  21. import cn.com.ctop.toutiao.modules.report.service.IBytedanceFundDailyService;
  22. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  23. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  24. import lombok.extern.slf4j.Slf4j;
  25. import org.jeecg.common.util.DateUtils;
  26. import org.junit.Test;
  27. import org.junit.runner.RunWith;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.boot.test.context.SpringBootTest;
  30. import org.springframework.test.context.ActiveProfiles;
  31. import org.springframework.test.context.junit4.SpringRunner;
  32. import java.text.ParseException;
  33. import java.text.SimpleDateFormat;
  34. import java.util.Date;
  35. import java.util.HashMap;
  36. import java.util.List;
  37. import java.util.concurrent.CountDownLatch;
  38. import java.util.concurrent.ExecutorService;
  39. import java.util.concurrent.Executors;
  40. import static org.jeecg.common.util.DateUtils.getAnotherDay;
  41. @RunWith(SpringRunner.class)
  42. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  43. @ActiveProfiles("wps")
  44. @Slf4j
  45. public class SampleTest {
  46. @Autowired
  47. private ICtopOauthTokenService oauthTokenService;
  48. @Autowired
  49. private IReportService reportService;
  50. @Autowired
  51. private IByteDanceAdvertiserDataService advertiserDataService;
  52. @Autowired
  53. private IKuaiShouHistoryReportTaskService kuaiShouHistoryReportTaskService;
  54. @Autowired
  55. private ICtopOauthTokenService tokenService;
  56. @Test
  57. public void loadBytedanceCreativeData() {
  58. QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  59. queryWrapper.eq("media_id", 2);
  60. List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
  61. for (CtopOauthToken token : list) {
  62. kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-20", "2020-09-20", "daily");
  63. }
  64. }
  65. @Autowired
  66. private IBindAccountLoginService bindAccountLoginService;
  67. @Autowired
  68. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  69. @Test
  70. public void loadKuaishouCookie() {
  71. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  72. if (list != null && !list.isEmpty()) {
  73. int i = 0;
  74. for (BindAccountLogin login : list) {
  75. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  76. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  77. i++;
  78. }
  79. }
  80. }
  81. }
  82. static ExecutorService executorService = null;
  83. //线程计数器/bytedance/bytedanceMaterialReport
  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 loadBytedancePlanData() {
  127. CtopOauthToken token = tokenService.getTokenByAccountId(100198696723L);
  128. // advertiserDataService.getAdvertiserPlan(token, "", null, null);
  129. Date getDate = DateUtils.addDay(new Date(), 0);
  130. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  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. @Autowired
  229. private ISendMessageService sendMessageService;
  230. @Test
  231. public void testSendMessage() {
  232. sendMessageService.sendMessage("c445fec9a80347aea54e8db66692ec03", "测试信息发送!");
  233. }
  234. @Autowired
  235. private IKuaishouInterfaceService kuaishouInterfaceService;
  236. @Test
  237. public void loadKuaishouGroupData() throws ParseException {
  238. Date endDate = new Date();
  239. String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.formatDate(endDate), -1);
  240. SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
  241. Date startDate = sim.parse(anotherDay);
  242. CtopOauthToken token = tokenService.getTokenByAccountId(7087890L);
  243. kuaishouInterfaceService.getGroupList(token, startDate, endDate);
  244. }
  245. @Test
  246. public void loadAccountData() {
  247. // List<UserAllocation> allocations = allocationService.getByParams(776L,null,0);
  248. // for (UserAllocation allocation:allocations) {
  249. CtopOauthToken token = tokenService.getTokenByAccountId(93238965516L);
  250. for (int i = 92; i < 100; i++) {
  251. Date getDate = DateUtils.addDay(new Date(), -i);
  252. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  253. }
  254. // }
  255. }
  256. @Autowired
  257. private IKuaishouCostGroupService kuaishouCostGroupService;
  258. @Autowired
  259. private IAlarmEventSendService alarmEventSendService;
  260. @Test
  261. public void addTest() {
  262. kuaishouCostGroupService.saveInfo();
  263. }
  264. @Test
  265. public void sendTest() {
  266. //检查频率 HOUR - 每小时;HALF_HOUR-每半小时
  267. alarmEventSendService.matchAlarmRules("HOUR");
  268. }
  269. @Autowired
  270. private IWechatCheckinDataService wechatCheckinDataService;
  271. @Autowired
  272. private IWechatUserListService wechatUserInfoService;
  273. @Autowired
  274. private IWechatNoListService wechatNoListService;
  275. }