SampleTest.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. package org.jeecg;
  2. import cn.com.ctop.check.component.execute.GroovyScriptExecutor;
  3. import cn.com.ctop.check.entity.CtopCheckTaskList;
  4. import cn.com.ctop.check.service.ICtopCheckTaskListService;
  5. import cn.com.ctop.common.module.entity.BindAccountLogin;
  6. import cn.com.ctop.common.module.entity.CtopOauthToken;
  7. import cn.com.ctop.common.module.entity.UserAllocation;
  8. import cn.com.ctop.common.module.message.handle.impl.EmailSendMsgHandle;
  9. import cn.com.ctop.common.module.service.IBindAccountLoginService;
  10. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  11. import cn.com.ctop.common.module.service.IUReportExportService;
  12. import cn.com.ctop.common.module.service.IUReportService;
  13. import cn.com.ctop.common.module.service.IUserAllocationService;
  14. import cn.com.ctop.common.module.utils.CtopAdConstant;
  15. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
  16. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
  17. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  18. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
  19. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  20. import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
  21. import cn.com.ctop.toutiao.modules.report.service.IBytedanceFundDailyService;
  22. import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
  23. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  24. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  25. import com.xxl.job.core.log.XxlJobLogger;
  26. import lombok.extern.slf4j.Slf4j;
  27. import org.jeecg.common.util.DateUtils;
  28. import org.junit.Test;
  29. import org.junit.runner.RunWith;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.boot.test.context.SpringBootTest;
  32. import org.springframework.test.context.ActiveProfiles;
  33. import org.springframework.test.context.junit4.SpringRunner;
  34. import java.io.IOException;
  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 IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  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. @Test
  69. public void getTaskList() {
  70. kuaiShouHistoryReportTaskService.getTaskList();
  71. }
  72. @Autowired
  73. private IBindAccountLoginService bindAccountLoginService;
  74. @Autowired
  75. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  76. @Test
  77. public void loadKuaishouCookie() {
  78. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  79. if (list != null && !list.isEmpty()) {
  80. int i = 0;
  81. for (BindAccountLogin login : list) {
  82. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  83. if (i > 5) {
  84. break;
  85. }
  86. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  87. i++;
  88. }
  89. }
  90. }
  91. }
  92. static ExecutorService executorService = null;
  93. //线程计数器/bytedance/bytedanceMaterialReport
  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. for (UserAllocation allocation : allocations) {
  126. System.out.println(allocation.getAccountId());
  127. for (int i = 0; i < 1; i++) {
  128. CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId());
  129. Date getDate = DateUtils.addDay(new Date(), -i);
  130. // reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  131. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  132. // reportService.getAdvertiserCampaignReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  133. // reportService.getAdvertiserCampaignReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  134. }
  135. }
  136. }
  137. @Test
  138. public void loadBytedancePlanData(){
  139. CtopOauthToken token = tokenService.getTokenByAccountId(100198696723L);
  140. // advertiserDataService.getAdvertiserPlan(token, "", null, null);
  141. Date getDate = DateUtils.addDay(new Date(), 0);
  142. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  143. }
  144. @Autowired
  145. private IBytedanceFundDailyService bytedanceFundDailyService;
  146. @Test
  147. public void loadFoudData() {
  148. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  149. for (CtopOauthToken token : tokens) {
  150. System.out.println(token.getAccountId()+"############################");
  151. for(int i=20;i<130;i++){
  152. Date date = DateUtils.addDay(new Date(),-i);
  153. bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date),1);
  154. System.out.println(i+"############################");
  155. }
  156. }
  157. }
  158. @Autowired
  159. private IKuaiShouHistoryReportTaskService reportTaskService;
  160. /**
  161. * 测试获取快手图片消耗数据任务
  162. */
  163. @Test
  164. public void loadKuaishouImageTask(){
  165. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  166. for(int i=1;i<130;i++) {
  167. Date getDate = DateUtils.addDay(new Date(), -i);
  168. String getDateStr = DateUtils.formatDate(getDate);
  169. tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
  170. }
  171. }
  172. @Autowired
  173. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  174. /**
  175. * 测试获取快手图片消耗数据入库
  176. */
  177. @Test
  178. public void loadKuaishouImageTaskFile(){
  179. String nowDate = DateUtils.getDate("yyyy-MM-dd");
  180. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  181. for(int i=1;i<15;i++){
  182. String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -i);
  183. tokens.forEach(token -> dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate));
  184. }
  185. // 查询快手token
  186. }
  187. @Test
  188. public void loadKuaishouAgentData() {
  189. kuaishouReportDailyAgentService.loginAgent();
  190. // for (int i = 0; i < 20; i++) {
  191. // String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -i));
  192. // kuaishouReportDailyAgentService.getReport(currentDate, DateUtils.getNowDate("yyyy-MM-dd"));
  193. // }
  194. //
  195. try {
  196. for (int i = 1; i < 30; i++) {
  197. kuaishouReportDailyAgentService.getAccount(i);
  198. }
  199. } catch (Exception e) {
  200. e.printStackTrace();
  201. }
  202. }
  203. @Autowired
  204. private GroovyScriptExecutor groovyScriptExecutor;
  205. @Autowired
  206. private ICtopCheckTaskListService checkTaskListService;
  207. @Test
  208. public void checkDataStateJobTest() {
  209. //查询需要检查的任务列表
  210. List<CtopCheckTaskList> ctopCheckTaskList = checkTaskListService.queryExecuteList("checkDataStateJob");
  211. if (ctopCheckTaskList != null) {
  212. ctopCheckTaskList.forEach(it -> groovyScriptExecutor.execute(it));
  213. }
  214. }
  215. @Test
  216. public void loadAccountData() {
  217. // List<UserAllocation> allocations = allocationService.getByParams(776L,null,0);
  218. // for (UserAllocation allocation:allocations) {
  219. CtopOauthToken token = tokenService.getTokenByAccountId(93238965516L);
  220. for(int i=92;i<100;i++){
  221. Date getDate = DateUtils.addDay(new Date(),-i);
  222. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  223. }
  224. // }
  225. }
  226. @Autowired
  227. IUReportExportService uReportExportService;
  228. @Autowired
  229. EmailSendMsgHandle emailSendMsgHandle;
  230. @Autowired
  231. IUReportService uReportService;
  232. @Test
  233. public void loadBytedanceData(){
  234. List<UserAllocation>allocations = allocationService.getByParams(289L,null,0);
  235. for (int i=0;i<allocations.size();i++) {
  236. CtopOauthToken token = tokenService.getTokenByAccountId(allocations.get(i).getAccountId());
  237. for(int j=0;j<10;j++){
  238. String getDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -j));
  239. bytedanceReportService.bytedanceVideoMaterialReport(token, getDate, getDate);
  240. }
  241. }
  242. }
  243. @Autowired
  244. private IBytedanceReportService bytedanceReportService;
  245. @Test
  246. public void loaddata(){
  247. for(int i=0;i<30;i++){
  248. Date getDate = DateUtils.addDay(new Date(), -i);
  249. String date = DateUtils.formatDate(getDate);
  250. videoReportDailyService.videoInfoList(date, date);
  251. }
  252. }
  253. @Autowired
  254. private IByteDanceVideoReportDailyService videoReportDailyService;
  255. @Test
  256. public void loadMatData(){
  257. List<UserAllocation> allocations = allocationService.getByParams(289L,null,0);
  258. countDownLatch = new CountDownLatch(allocations.size());
  259. executorService = Executors.newFixedThreadPool(2);
  260. allocations.forEach(allocation -> {
  261. executorService.submit(new Runnable() {
  262. @Override
  263. public void run() {
  264. try {
  265. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  266. //获取全量视频素材数据
  267. advertiserDataService.getMaterialList(token);
  268. } catch (Exception e) {
  269. e.printStackTrace();
  270. } finally {
  271. countDownLatch.countDown();
  272. }
  273. }
  274. });
  275. });
  276. try {
  277. countDownLatch.await();
  278. } catch (InterruptedException e) {
  279. e.printStackTrace();
  280. }
  281. XxlJobLogger.log("物料数据同步完成");
  282. }
  283. }