SampleTest.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  113. for(CtopOauthToken token :tokens){
  114. reportService.getAdvertiserPlanRuleData(token,new Date(),new Date(),CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  115. }
  116. }
  117. @Autowired
  118. private IUserAllocationService allocationService;
  119. @Test
  120. public void testLoadBytedanceData() {
  121. List<UserAllocation>allocations = allocationService.getByParams(273L,null,0);
  122. if(null!=allocations&&!allocations.isEmpty()){
  123. for(UserAllocation allocation:allocations){
  124. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  125. String startDate = "2020-11-05";
  126. String endDate = "2020-11-09";
  127. reportService.getAdvertiserPlanReport(token, DateUtils.parseDate(startDate,"yyyy-MM-dd"), DateUtils.parseDate(endDate,"yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  128. }
  129. }
  130. System.out.println("任务结束");
  131. }
  132. @Test
  133. public void loadBytedancePlanData(){
  134. CtopOauthToken token = tokenService.getTokenByAccountId(100198696723L);
  135. // advertiserDataService.getAdvertiserPlan(token, "", null, null);
  136. Date getDate = DateUtils.addDay(new Date(), 0);
  137. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  138. }
  139. @Autowired
  140. private IBytedanceFundDailyService bytedanceFundDailyService;
  141. @Test
  142. public void loadFoudData() {
  143. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  144. for (CtopOauthToken token : tokens) {
  145. System.out.println(token.getAccountId()+"############################");
  146. for(int i=20;i<130;i++){
  147. Date date = DateUtils.addDay(new Date(),-i);
  148. bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date),1);
  149. System.out.println(i+"############################");
  150. }
  151. }
  152. }
  153. @Autowired
  154. private IKuaiShouHistoryReportTaskService reportTaskService;
  155. /**
  156. * 测试获取快手图片消耗数据任务
  157. */
  158. @Test
  159. public void loadKuaishouImageTask(){
  160. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  161. for(int i=1;i<130;i++) {
  162. Date getDate = DateUtils.addDay(new Date(), -i);
  163. String getDateStr = DateUtils.formatDate(getDate);
  164. tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
  165. }
  166. }
  167. @Autowired
  168. private IKuaiShouDailyReportTaskService dailyReportTaskService;
  169. /**
  170. * 测试获取快手图片消耗数据入库
  171. */
  172. @Test
  173. public void loadKuaishouImageTaskFile(){
  174. String nowDate = DateUtils.getDate("yyyy-MM-dd");
  175. List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
  176. for(int i=1;i<15;i++){
  177. String statDate = getAnotherDay("yyyy-MM-dd", nowDate, -i);
  178. tokens.forEach(token -> dailyReportTaskService.getTaskList(token.getAccountId(), token.getAccessToken(), statDate));
  179. }
  180. // 查询快手token
  181. }
  182. @Test
  183. public void testLoadBytedanceImageData(){
  184. List<CtopOauthToken>tokens = tokenService.selectToutiaoToken();
  185. countDownLatch = new CountDownLatch(tokens.size());
  186. executorService = Executors.newFixedThreadPool(8);
  187. tokens.forEach(token->executorService.submit(()->{
  188. try {
  189. advertiserDataService.getMaterialList(token);
  190. }catch (Exception e){
  191. }finally {
  192. countDownLatch.countDown();
  193. }
  194. }));
  195. try {
  196. countDownLatch.await();
  197. } catch (InterruptedException e) {
  198. e.printStackTrace();
  199. }
  200. System.out.println("素材数据获取完成");
  201. }
  202. @Autowired
  203. private KuaishouAgentAccountMapper kuaishouAgentAccountMapper;
  204. @Autowired
  205. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  206. @Test
  207. public void loadKuaishouAgentData() throws JsonProcessingException {
  208. kuaishouReportDailyAgentService.loginAgent();
  209. // for (int i = 0; i < 20; i++) {
  210. // String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -i));
  211. // kuaishouReportDailyAgentService.getReport(currentDate, DateUtils.getNowDate("yyyy-MM-dd"));
  212. // }
  213. //
  214. try {
  215. for (int i = 1; i < 30; i++) {
  216. kuaishouReportDailyAgentService.getAccount(i);
  217. }
  218. } catch (Exception e) {
  219. e.printStackTrace();
  220. }
  221. }
  222. @Autowired
  223. private IKuaishouInterfaceService kuaishouInterfaceService;
  224. @Test
  225. public void loadKuaishouGroupData() throws ParseException {
  226. Date endDate = new Date();
  227. String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.formatDate(endDate), -1);
  228. SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
  229. Date startDate = sim.parse(anotherDay);
  230. CtopOauthToken token = tokenService.getTokenByAccountId(7087890L);
  231. kuaishouInterfaceService.getGroupList(token, startDate, endDate);
  232. }
  233. @Autowired
  234. IUReportExportService uReportExportService;
  235. @Autowired
  236. EmailSendMsgHandle emailSendMsgHandle;
  237. @Autowired
  238. IUReportService uReportService;
  239. @Test
  240. public void loadBytedanceData(){
  241. List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
  242. for (int i=0;i<tokens.size();i++) {
  243. for(int j=0;j<4;j++){
  244. String getDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -j));
  245. bytedanceReportService.bytedanceVideoMaterialReport(tokens.get(i), getDate, getDate);
  246. }
  247. }
  248. }
  249. @Autowired
  250. private IBytedanceReportService bytedanceReportService;
  251. @Test
  252. public void loadMatData(){
  253. List<UserAllocation> allocations = allocationService.getByParams(289L,null,0);
  254. countDownLatch = new CountDownLatch(allocations.size());
  255. executorService = Executors.newFixedThreadPool(2);
  256. allocations.forEach(allocation -> {
  257. executorService.submit(new Runnable() {
  258. @Override
  259. public void run() {
  260. try {
  261. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  262. //获取全量视频素材数据
  263. advertiserDataService.getMaterialList(token);
  264. } catch (Exception e) {
  265. e.printStackTrace();
  266. } finally {
  267. countDownLatch.countDown();
  268. }
  269. }
  270. });
  271. });
  272. try {
  273. countDownLatch.await();
  274. } catch (InterruptedException e) {
  275. e.printStackTrace();
  276. }
  277. XxlJobLogger.log("物料数据同步完成");
  278. }
  279. }