SampleTest.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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.IKuaiShouDailyReportTaskService;
  11. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
  12. import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
  13. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  14. import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
  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. @Autowired
  57. private KuaishouReportDailyAccountMapper reportDailyAccountMapper;
  58. @Test
  59. public void loadBytedanceCreativeData() {
  60. QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  61. queryWrapper.eq("media_id", 2);
  62. List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
  63. for (CtopOauthToken token : list) {
  64. kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-20", "2020-09-20", "daily");
  65. }
  66. }
  67. @Autowired
  68. private IBindAccountLoginService bindAccountLoginService;
  69. @Autowired
  70. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  71. @Test
  72. public void loadKuaishouCookie() {
  73. reportDailyAccountMapper.loadAccountDailyReport(23212L, "D://report2//8206288_1.csv");
  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. //线程计数器/bytedance/bytedanceMaterialReport
  87. static CountDownLatch countDownLatch = null;
  88. @Test
  89. public void deleteKuaishouComment() {
  90. Long start = System.currentTimeMillis();
  91. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  92. if (loginList != null && !loginList.isEmpty()) {
  93. executorService = Executors.newFixedThreadPool(5);
  94. countDownLatch = new CountDownLatch(loginList.size());
  95. loginList.forEach(login -> executorService.submit(() -> {
  96. try {
  97. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  98. } catch (Exception e) {
  99. log.error(e.getMessage(), e);
  100. } finally {
  101. countDownLatch.countDown();
  102. }
  103. }));
  104. try {
  105. countDownLatch.await();
  106. } catch (InterruptedException e) {
  107. e.printStackTrace();
  108. }
  109. Long end = System.currentTimeMillis();
  110. log.info("快手删评论所用时长:{}毫秒", end - start);
  111. }
  112. }
  113. @Autowired
  114. private IUserAllocationService allocationService;
  115. @Test
  116. public void testLoadBytedanceData() {
  117. List<UserAllocation> allocations = allocationService.getByParams(633L, null, 0);
  118. if (null != allocations && !allocations.isEmpty()) {
  119. for (UserAllocation allocation : allocations) {
  120. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  121. String startDate = "2020-11-10";
  122. String endDate = "2020-11-10";
  123. reportService.getAdvertiserReport(token, DateUtils.parseDate(startDate, "yyyy-MM-dd"), DateUtils.parseDate(endDate, "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  124. }
  125. }
  126. System.out.println("任务结束");
  127. }
  128. @Test
  129. public void loadBytedancePlanData() {
  130. CtopOauthToken token = tokenService.getTokenByAccountId(100198696723L);
  131. // advertiserDataService.getAdvertiserPlan(token, "", null, null);
  132. Date getDate = DateUtils.addDay(new Date(), 0);
  133. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  134. }
  135. @Autowired
  136. private IBytedanceFundDailyService bytedanceFundDailyService;
  137. @Test
  138. public void loadFoudData() {
  139. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  140. for (CtopOauthToken token : tokens) {
  141. System.out.println(token.getAccountId() + "############################");
  142. for (int i = 20; i < 130; i++) {
  143. Date date = DateUtils.addDay(new Date(), -i);
  144. bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date), 1);
  145. System.out.println(i + "############################");
  146. }
  147. }
  148. }
  149. @Autowired
  150. private IKuaiShouHistoryReportTaskService reportTaskService;
  151. /**
  152. * 测试获取快手图片消耗数据任务
  153. */
  154. @Test
  155. public void loadKuaishouImageTask() {
  156. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  157. for (int i = 1; i < 130; i++) {
  158. Date getDate = DateUtils.addDay(new Date(), -i);
  159. String getDateStr = DateUtils.formatDate(getDate);
  160. tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
  161. }
  162. }
  163. @Autowired
  164. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  165. /**
  166. * 测试获取快手图片消耗数据入库
  167. */
  168. @Test
  169. public void loadKuaishouImageTaskFile() {
  170. String nowDate = DateUtils.getDate("yyyy-MM-dd");
  171. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  172. for (int i = 1; i < 15; i++) {
  173. String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -i);
  174. tokens.forEach(token -> dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate));
  175. }
  176. // 查询快手token
  177. }
  178. @Test
  179. public void testLoadBytedanceImageData() {
  180. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  181. countDownLatch = new CountDownLatch(tokens.size());
  182. executorService = Executors.newFixedThreadPool(8);
  183. tokens.forEach(token -> executorService.submit(() -> {
  184. try {
  185. advertiserDataService.getMaterialList(token);
  186. } catch (Exception e) {
  187. } finally {
  188. countDownLatch.countDown();
  189. }
  190. }));
  191. try {
  192. countDownLatch.await();
  193. } catch (InterruptedException e) {
  194. e.printStackTrace();
  195. }
  196. System.out.println("素材数据获取完成");
  197. }
  198. @Autowired
  199. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  200. @Test
  201. public void testData(){
  202. Date date = new Date();
  203. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  204. executorService = Executors.newFixedThreadPool(10);
  205. countDownLatch = new CountDownLatch(tokens.size());
  206. tokens.forEach(token -> executorService.submit(()->{
  207. try {
  208. reportService.getAdvertiserPlanRuleData(token,date,date,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  209. }catch (Exception e){
  210. }finally {
  211. countDownLatch.countDown();
  212. }
  213. }));
  214. try {
  215. countDownLatch.await();
  216. } catch (InterruptedException e) {
  217. e.printStackTrace();
  218. }
  219. }
  220. @Test
  221. public void loadKuaishouAgentData() {
  222. kuaishouReportDailyAgentService.loginAgent();
  223. try {
  224. for (int i = 1; i < 30; i++) {
  225. kuaishouReportDailyAgentService.getAccount(i);
  226. }
  227. } catch (Exception e) {
  228. e.printStackTrace();
  229. }
  230. }
  231. @Autowired
  232. private IKuaishouInterfaceService kuaishouInterfaceService;
  233. @Test
  234. public void loadKuaishouGroupData() throws ParseException {
  235. Date endDate = new Date();
  236. String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.formatDate(endDate), -1);
  237. SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
  238. Date startDate = sim.parse(anotherDay);
  239. CtopOauthToken token = tokenService.getTokenByAccountId(7087890L);
  240. kuaishouInterfaceService.getGroupList(token, startDate, endDate);
  241. }
  242. @Test
  243. public void loadAccountData() {
  244. // List<UserAllocation> allocations = allocationService.getByParams(776L,null,0);
  245. // for (UserAllocation allocation:allocations) {
  246. CtopOauthToken token = tokenService.getTokenByAccountId(93238965516L);
  247. for (int i = 92; i < 100; i++) {
  248. Date getDate = DateUtils.addDay(new Date(), -i);
  249. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  250. }
  251. // }
  252. }
  253. @Autowired
  254. private IKuaishouCostGroupService kuaishouCostGroupService;
  255. @Autowired
  256. private IAlarmEventSendService alarmEventSendService;
  257. @Test
  258. public void addTest() {
  259. kuaishouCostGroupService.saveInfo();
  260. }
  261. @Test
  262. public void sendTest() {
  263. //检查频率 HOUR - 每小时;HALF_HOUR-每半小时
  264. alarmEventSendService.matchAlarmRules("HOUR");
  265. }
  266. @Autowired
  267. private IWechatCheckinDataService wechatCheckinDataService;
  268. @Autowired
  269. private IWechatUserListService wechatUserInfoService;
  270. @Autowired
  271. private IWechatNoListService wechatNoListService;
  272. }