SampleTest.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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.service.IBindAccountLoginService;
  5. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  6. import cn.com.ctop.common.module.utils.CtopAdConstant;
  7. import cn.com.ctop.common.module.utils.HttpUtils;
  8. import cn.com.ctop.crawler.modules.pangolin.entity.PangolinApp;
  9. import cn.com.ctop.crawler.modules.pangolin.service.PangolinAppService;
  10. import cn.com.ctop.crawler.modules.pangolin.service.PangolinCrawlerService;
  11. import cn.com.ctop.crawler.modules.pangolin.service.PangolinLoginService;
  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.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  15. import cn.com.ctop.toutiao.modules.material.service.IByteDanceCampaignService;
  16. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  17. import com.alibaba.fastjson.JSONObject;
  18. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.jeecg.common.util.DateUtils;
  21. import org.jeecg.modules.ctop.entity.KuaishouEffectVideoInfo;
  22. import org.jeecg.modules.ctop.service.IKuaishouEffectVideoInfoService;
  23. import org.jeecg.modules.ctop.service.IRuleEngineService;
  24. import org.jeecg.modules.ctop.vo.QueryParam;
  25. import org.jeecg.modules.ctop.vo.RuleResult;
  26. import org.junit.Test;
  27. import org.junit.runner.RunWith;
  28. import org.kie.api.runtime.KieSession;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.boot.test.context.SpringBootTest;
  31. import org.springframework.test.context.junit4.SpringRunner;
  32. import javax.annotation.Resource;
  33. import java.util.HashMap;
  34. import java.util.List;
  35. import java.util.concurrent.CountDownLatch;
  36. import java.util.concurrent.ExecutorService;
  37. import java.util.concurrent.Executors;
  38. @RunWith(SpringRunner.class)
  39. @SpringBootTest
  40. @Slf4j
  41. public class SampleTest {
  42. @Autowired
  43. private ICtopOauthTokenService oauthTokenService;
  44. @Autowired
  45. private IByteDanceAdvertiserDataService advertiserDataService;
  46. @Autowired
  47. private IReportService reportService;
  48. @Autowired
  49. private IKuaishouInterfaceService interfaceService;
  50. @Test
  51. public void loadBytedanceCampaignData() {
  52. // CorpWexinUtils.sendMessageByWeChatId("34585ddd4bd86e57756cf6a51b9443a5","测试消息发送");
  53. interfaceService.getAppList(23212L,"493aedfee07d9c500c50077e7c808145");
  54. }
  55. @Autowired
  56. private IBindAccountLoginService bindAccountLoginService;
  57. @Autowired
  58. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  59. @Test
  60. public void kuaishouLogin() {
  61. Long start = System.currentTimeMillis();
  62. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  63. if (list != null && !list.isEmpty()) {
  64. for (BindAccountLogin login : list) {
  65. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  66. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  67. }
  68. }
  69. }
  70. Long end = System.currentTimeMillis();
  71. log.info("总用时:{}毫秒", end - start);
  72. }
  73. static ExecutorService executorService = Executors.newFixedThreadPool(10);;
  74. static CountDownLatch countDownLatch = null;
  75. @Test
  76. public void kuaishouCommentDelete() {
  77. Long start = System.currentTimeMillis();
  78. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  79. if (list != null && !list.isEmpty()) {
  80. countDownLatch = new CountDownLatch(list.size());
  81. list.forEach(login -> {
  82. executorService.submit(() -> {
  83. try {
  84. if (null != login.getCookie() && !"".equals(login.getCookie().trim())) {
  85. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  86. }
  87. } catch (Exception e) {
  88. } finally {
  89. countDownLatch.countDown();
  90. }
  91. });
  92. });
  93. }
  94. try {
  95. countDownLatch.await();
  96. } catch (InterruptedException e) {
  97. e.printStackTrace();
  98. }
  99. Long end = System.currentTimeMillis();
  100. log.info("总用时:{}毫秒", end - start);
  101. }
  102. @Autowired
  103. private PangolinLoginService pangolinLoginService;
  104. @Autowired
  105. private PangolinCrawlerService pangolinCrawlerService;
  106. @Autowired
  107. private PangolinAppService pangolinAppService;
  108. @Test
  109. public void testPangolinLogin() {
  110. QueryWrapper<BindAccountLogin> queryWrapper = new QueryWrapper<>();
  111. queryWrapper.eq("login_type", "pangolin");
  112. queryWrapper.eq("status", 1);
  113. List<BindAccountLogin> list = bindAccountLoginService.list(queryWrapper);
  114. if (list != null && !list.isEmpty()) {
  115. for (BindAccountLogin login : list) {
  116. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  117. pangolinLoginService.pangolinLogin(login.getAccountName(), login.getPassword());
  118. }
  119. }
  120. }
  121. }
  122. @Test
  123. public void testPangolinData() {
  124. QueryWrapper<BindAccountLogin> queryWrapper = new QueryWrapper<>();
  125. queryWrapper.eq("login_type", "pangolin");
  126. queryWrapper.eq("status", 1);
  127. queryWrapper.isNotNull("cookie");
  128. List<BindAccountLogin> list = bindAccountLoginService.list(queryWrapper);
  129. if (list != null && !list.isEmpty()) {
  130. for (BindAccountLogin bindAccountLogin : list) {
  131. pangolinCrawlerService.getChannelList(bindAccountLogin);
  132. pangolinCrawlerService.getActivationList(bindAccountLogin, DateUtils.getNowDate("yyyy-MM-dd"), 1);
  133. pangolinCrawlerService.getCheckList(bindAccountLogin);
  134. QueryWrapper<PangolinApp> queryWrapper1 = new QueryWrapper<>();
  135. queryWrapper1.eq("account_name", bindAccountLogin.getAccountName());
  136. List<PangolinApp> appList = pangolinAppService.list(queryWrapper1);
  137. if (appList != null && !appList.isEmpty()) {
  138. appList.forEach(pangolinApp -> pangolinCrawlerService.getRealTimeList(bindAccountLogin, pangolinApp.getAppId()));
  139. }
  140. }
  141. }
  142. }
  143. @Autowired
  144. private IByteDanceCampaignService campaignService;
  145. @Test
  146. public void testGetCampaign(){
  147. CtopOauthToken token = oauthTokenService.getOauthTokenByAccountId("1649600126891015");
  148. campaignService.getAdvertiserCampaign(token,"1672261893872756",null);
  149. }
  150. @Autowired
  151. private IKuaishouEffectVideoInfoService effectVideoInfoService;
  152. @Test
  153. public void loadKuaishouEffectVideoInfo(){
  154. List<KuaishouEffectVideoInfo>videoInfos = effectVideoInfoService.list();
  155. for (KuaishouEffectVideoInfo video:videoInfos) {
  156. if(null!=video.getSignature()&&!"".equals(video.getSignature())){
  157. effectVideoInfoService.updateFinalCostDateBySignature(video.getSignature());
  158. effectVideoInfoService.updateInitialCostDateBySignature(video.getSignature());
  159. effectVideoInfoService.updateTotalCostBySignature(video.getSignature());
  160. // effectVideoInfoService.updateTowWeekCostBySignature(video.getSignature());
  161. }
  162. }
  163. }
  164. @Test
  165. public void getIndustryInfo(){
  166. String access_token = "cbdf6502c04978ae401cb92a64530fb73a8c7dbe";
  167. // 请求地址
  168. String url = "https://ad.oceanengine.com/open_api/2/tools/industry/get/";
  169. JSONObject jsonObject = HttpUtils.bytedanceGetRequest(access_token, url, new JSONObject());
  170. System.out.println(jsonObject.toJSONString());
  171. }
  172. @Test
  173. public void loadImageInfo()throws Exception{
  174. List<CtopOauthToken>tokens = oauthTokenService.selectToutiaoToken();
  175. for (CtopOauthToken token:tokens) {
  176. advertiserDataService.getImageByPage(token,null,1);
  177. Thread.sleep(1000L);
  178. }
  179. }
  180. @Resource
  181. private KieSession kieSession;
  182. @Autowired
  183. private IRuleEngineService ruleEngineService ;
  184. @Test
  185. public void testEngine(){
  186. QueryParam queryParam1 = new QueryParam() ;
  187. queryParam1.setParamId("1");
  188. queryParam1.setParamSign("+");
  189. QueryParam queryParam2 = new QueryParam() ;
  190. queryParam2.setParamId("2");
  191. queryParam2.setParamSign("-");
  192. // 入参
  193. kieSession.insert(queryParam1);
  194. kieSession.insert(queryParam2);
  195. kieSession.insert(this.ruleEngineService);
  196. // 返参
  197. RuleResult resultParam = new RuleResult();
  198. kieSession.insert(resultParam);
  199. kieSession.fireAllRules();
  200. }
  201. }