SampleTest.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. package org.jeecg;
  2. import cn.com.ctop.common.module.entity.BindAccountLogin;
  3. import cn.com.ctop.common.module.entity.CtopOauthToken;
  4. import cn.com.ctop.common.module.entity.UserAllocation;
  5. import cn.com.ctop.common.module.message.handle.impl.EmailSendMsgHandle;
  6. import cn.com.ctop.common.module.service.*;
  7. import cn.com.ctop.common.module.utils.CtopAdConstant;
  8. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
  9. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
  10. import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
  11. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  12. import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouAgentAccountMapper;
  13. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
  14. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  15. import cn.com.ctop.toutiao.modules.report.service.IBytedanceFundDailyService;
  16. import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
  17. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  18. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  19. import com.fasterxml.jackson.core.JsonProcessingException;
  20. import com.xxl.job.core.log.XxlJobLogger;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.jeecg.common.util.DateUtils;
  23. import org.junit.Test;
  24. import org.junit.runner.RunWith;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.boot.test.context.SpringBootTest;
  27. import org.springframework.test.context.ActiveProfiles;
  28. import org.springframework.test.context.junit4.SpringRunner;
  29. import java.text.ParseException;
  30. import java.text.SimpleDateFormat;
  31. import java.util.Date;
  32. import java.util.HashMap;
  33. import java.util.List;
  34. import java.util.concurrent.CountDownLatch;
  35. import java.util.concurrent.ExecutorService;
  36. import java.util.concurrent.Executors;
  37. import static org.jeecg.common.util.DateUtils.getAnotherDay;
  38. @RunWith(SpringRunner.class)
  39. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  40. @ActiveProfiles("wps")
  41. @Slf4j
  42. public class SampleTest {
  43. @Autowired
  44. private ICtopOauthTokenService oauthTokenService;
  45. @Autowired
  46. private IReportService reportService;
  47. @Autowired
  48. private IByteDanceAdvertiserDataService advertiserDataService;
  49. @Autowired
  50. private IKuaiShouHistoryReportTaskService kuaiShouHistoryReportTaskService;
  51. @Autowired
  52. private ICtopOauthTokenService tokenService;
  53. @Test
  54. public void loadBytedanceCreativeData() {
  55. QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  56. queryWrapper.eq("media_id", 2);
  57. List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
  58. for (CtopOauthToken token : list) {
  59. kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-20", "2020-09-20", "daily");
  60. }
  61. }
  62. @Autowired
  63. private IBindAccountLoginService bindAccountLoginService;
  64. @Autowired
  65. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  66. @Test
  67. public void loadKuaishouCookie() {
  68. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  69. if (list != null && !list.isEmpty()) {
  70. int i = 0;
  71. for (BindAccountLogin login : list) {
  72. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  73. if (i > 5) {
  74. break;
  75. }
  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. @Test
  111. public void testLoadRulePlanData(){
  112. Date date = new Date();
  113. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  114. executorService = Executors.newFixedThreadPool(10);
  115. countDownLatch = new CountDownLatch(tokens.size());
  116. tokens.forEach(token -> executorService.submit(()->{
  117. try {
  118. Long start = System.currentTimeMillis();
  119. reportService.getAdvertiserPlanRuleData(token,date,date,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  120. Long end = System.currentTimeMillis();
  121. log.info("账户数据获取完成:accountId=>{},耗时{}毫秒",token.getAccountId(),end-start);
  122. }catch (Exception e){
  123. e.printStackTrace();
  124. }finally {
  125. countDownLatch.countDown();
  126. }
  127. }));
  128. try {
  129. countDownLatch.await();
  130. } catch (InterruptedException e) {
  131. e.printStackTrace();
  132. }
  133. }
  134. @Autowired
  135. private IUserAllocationService allocationService;
  136. @Test
  137. public void testLoadBytedanceData() {
  138. List<UserAllocation>allocations = allocationService.getByParams(273L,null,0);
  139. if(null!=allocations&&!allocations.isEmpty()){
  140. for(UserAllocation allocation:allocations){
  141. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  142. String startDate = "2020-11-05";
  143. String endDate = "2020-11-09";
  144. reportService.getAdvertiserPlanReport(token, DateUtils.parseDate(startDate,"yyyy-MM-dd"), DateUtils.parseDate(endDate,"yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  145. }
  146. }
  147. System.out.println("任务结束");
  148. }
  149. @Test
  150. public void loadBytedancePlanData(){
  151. CtopOauthToken token = tokenService.getTokenByAccountId(100198696723L);
  152. // advertiserDataService.getAdvertiserPlan(token, "", null, null);
  153. Date getDate = DateUtils.addDay(new Date(), 0);
  154. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  155. }
  156. @Autowired
  157. private IBytedanceFundDailyService bytedanceFundDailyService;
  158. @Test
  159. public void loadFoudData() {
  160. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  161. for (CtopOauthToken token : tokens) {
  162. System.out.println(token.getAccountId()+"############################");
  163. for(int i=20;i<130;i++){
  164. Date date = DateUtils.addDay(new Date(),-i);
  165. bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date),1);
  166. System.out.println(i+"############################");
  167. }
  168. }
  169. }
  170. @Autowired
  171. private IKuaiShouHistoryReportTaskService reportTaskService;
  172. /**
  173. * 测试获取快手图片消耗数据任务
  174. */
  175. @Test
  176. public void loadKuaishouImageTask(){
  177. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  178. for(int i=1;i<130;i++) {
  179. Date getDate = DateUtils.addDay(new Date(), -i);
  180. String getDateStr = DateUtils.formatDate(getDate);
  181. tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
  182. }
  183. }
  184. @Autowired
  185. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  186. /**
  187. * 测试获取快手图片消耗数据入库
  188. */
  189. @Test
  190. public void loadKuaishouImageTaskFile(){
  191. String nowDate = DateUtils.getDate("yyyy-MM-dd");
  192. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  193. for(int i=1;i<15;i++){
  194. String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -i);
  195. tokens.forEach(token -> dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate));
  196. }
  197. // 查询快手token
  198. }
  199. @Test
  200. public void testLoadBytedanceImageData(){
  201. List<CtopOauthToken>tokens = tokenService.selectToutiaoToken();
  202. countDownLatch = new CountDownLatch(tokens.size());
  203. executorService = Executors.newFixedThreadPool(8);
  204. tokens.forEach(token->executorService.submit(()->{
  205. try {
  206. advertiserDataService.getMaterialList(token);
  207. }catch (Exception e){
  208. }finally {
  209. countDownLatch.countDown();
  210. }
  211. }));
  212. try {
  213. countDownLatch.await();
  214. } catch (InterruptedException e) {
  215. e.printStackTrace();
  216. }
  217. System.out.println("素材数据获取完成");
  218. }
  219. @Autowired
  220. private KuaishouAgentAccountMapper kuaishouAgentAccountMapper;
  221. @Autowired
  222. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  223. @Test
  224. public void loadKuaishouAgentData() throws JsonProcessingException {
  225. kuaishouReportDailyAgentService.loginAgent();
  226. // for (int i = 0; i < 20; i++) {
  227. // String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -i));
  228. // kuaishouReportDailyAgentService.getReport(currentDate, DateUtils.getNowDate("yyyy-MM-dd"));
  229. // }
  230. //
  231. try {
  232. for (int i = 1; i < 30; i++) {
  233. kuaishouReportDailyAgentService.getAccount(i);
  234. }
  235. } catch (Exception e) {
  236. e.printStackTrace();
  237. }
  238. }
  239. @Autowired
  240. private IKuaishouInterfaceService kuaishouInterfaceService;
  241. @Test
  242. public void loadKuaishouGroupData() throws ParseException {
  243. Date endDate = new Date();
  244. String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.formatDate(endDate), -1);
  245. SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
  246. Date startDate = sim.parse(anotherDay);
  247. CtopOauthToken token = tokenService.getTokenByAccountId(7087890L);
  248. kuaishouInterfaceService.getGroupList(token, startDate, endDate);
  249. }
  250. @Autowired
  251. IUReportExportService uReportExportService;
  252. @Autowired
  253. EmailSendMsgHandle emailSendMsgHandle;
  254. @Autowired
  255. IUReportService uReportService;
  256. @Test
  257. public void loadBytedanceData(){
  258. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  259. for (int i=0;i<tokens.size();i++) {
  260. for(int j=0;j<4;j++){
  261. String getDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -j));
  262. bytedanceReportService.bytedanceVideoMaterialReport(tokens.get(i), getDate, getDate);
  263. }
  264. }
  265. }
  266. @Autowired
  267. private IBytedanceReportService bytedanceReportService;
  268. @Test
  269. public void loadMatData(){
  270. List<UserAllocation> allocations = allocationService.getByParams(289L,null,0);
  271. countDownLatch = new CountDownLatch(allocations.size());
  272. executorService = Executors.newFixedThreadPool(2);
  273. allocations.forEach(allocation -> {
  274. executorService.submit(new Runnable() {
  275. @Override
  276. public void run() {
  277. try {
  278. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  279. //获取全量视频素材数据
  280. advertiserDataService.getMaterialList(token);
  281. } catch (Exception e) {
  282. e.printStackTrace();
  283. } finally {
  284. countDownLatch.countDown();
  285. }
  286. }
  287. });
  288. });
  289. try {
  290. countDownLatch.await();
  291. } catch (InterruptedException e) {
  292. e.printStackTrace();
  293. }
  294. XxlJobLogger.log("物料数据同步完成");
  295. }
  296. }