SampleTest.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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.*;
  10. import cn.com.ctop.common.module.utils.CtopAdConstant;
  11. import cn.com.ctop.crawler.modules.core.service.IKuaishouCrawlerService;
  12. import cn.com.ctop.crawler.modules.music.service.IMusicKuaishouTypeService;
  13. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  14. import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
  15. import cn.com.ctop.toutiao.modules.material.entity.ByteDanceAdvertisePlan;
  16. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertisePlanService;
  17. import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
  18. import cn.com.ctop.toutiao.modules.material.service.IByteDanceCreativeService;
  19. import cn.com.ctop.toutiao.modules.report.service.IReportService;
  20. import com.alibaba.fastjson.JSONObject;
  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.util.Date;
  30. import java.util.HashMap;
  31. import java.util.List;
  32. import java.util.Map;
  33. import java.util.concurrent.CountDownLatch;
  34. import java.util.concurrent.ExecutorService;
  35. import java.util.concurrent.Executors;
  36. @RunWith(SpringRunner.class)
  37. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  38. @ActiveProfiles("wps")
  39. @Slf4j
  40. public class SampleTest {
  41. @Autowired
  42. private ICtopOauthTokenService oauthTokenService;
  43. @Autowired
  44. private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
  45. @Autowired
  46. private IReportService reportService;
  47. @Autowired
  48. private IUserAllocationService userAllocationService;
  49. @Autowired
  50. private IByteDanceAdvertiserDataService advertiserDataService;
  51. @Test
  52. public void loadBytedanceCreativeData() {
  53. // List<UserAllocation>allocations = userAllocationService.getByParams(633L,null,0);
  54. //
  55. // if(null!=allocations&&!allocations.isEmpty()){
  56. // for (UserAllocation allocation:allocations) {
  57. // CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId());
  58. // advertiserDataService.getAdvertiserPlan(token, "", null, null);
  59. // }
  60. // }
  61. UserAllocation allocation = userAllocationService.getByAccountId(1648083559613447L);
  62. CtopOauthToken token = oauthTokenService.getTokenByAccountId(1648083559613447L);
  63. // advertiserDataService.getAdvertiserPlan(token, "", null, null);
  64. List<ByteDanceAdvertisePlan> plans = advertisePlanService.getAllPlans(token.getAccountId(),DateUtils.formatDate(new Date()));
  65. if(null!=plans&&!plans.isEmpty()){
  66. for (ByteDanceAdvertisePlan plan:plans) {
  67. Map<String, Object> creativeDetail = creativeService.getCreativeDetail(token.getAccountId(), plan.getId());
  68. if(null!=creativeDetail.get("data")){
  69. JSONObject data = (JSONObject) creativeDetail.get("data");
  70. checkMonitorLink(data,plan,allocation);
  71. }
  72. }
  73. }
  74. }
  75. private void checkMonitorLink(JSONObject data, ByteDanceAdvertisePlan plan, UserAllocation allocation) {
  76. String downloadUrl = plan.getDownloadUrl();
  77. boolean errorflag = false;
  78. String errorMsg = "";
  79. String token = plan.getName().split("-")[0];
  80. String tokenInfo = "surl_token="+token;
  81. String appType = plan.getAppType();
  82. if(null!=downloadUrl){
  83. if(null!=appType&&appType.equals("APP_IOS")){
  84. if(!downloadUrl.equals("https://apps.apple.com/cn/app/id1468454200")){
  85. errorMsg+= "应用下载链接填写异常;";
  86. errorflag = true;
  87. }
  88. }
  89. if(null!=appType&&appType.equals("APP_ANDROID")){
  90. if(!downloadUrl.contains(token)){
  91. errorMsg+= "应用下载链接填写异常;";
  92. errorflag = true;
  93. }
  94. }
  95. }
  96. //展示监测链接
  97. String trackUrl = data.getString("trackUrl");
  98. if(null!=trackUrl&&!trackUrl.trim().equals("")){
  99. if(!trackUrl.contains(tokenInfo)){
  100. errorMsg+= "展示监测链接填写异常;";
  101. errorflag = true;
  102. }
  103. }
  104. //点击监测链接
  105. String actionTrackUrl = data.getString("actionTrackUrl");
  106. if(null!=actionTrackUrl&&!actionTrackUrl.trim().equals("")){
  107. if(null!=appType&&appType.equals("APP_IOS")){
  108. if(!actionTrackUrl.contains(tokenInfo)||!actionTrackUrl.contains("app_platform=ios")){
  109. errorMsg+= "点击监测链接填写异常;";
  110. errorflag = true;
  111. }
  112. }
  113. if(null!=appType&&appType.equals("APP_ANDROID")){
  114. if(!actionTrackUrl.contains(tokenInfo)||!actionTrackUrl.contains("tt/1967")){
  115. errorMsg+= "点击监测链接填写异常;";
  116. errorflag = true;
  117. }
  118. }
  119. }
  120. //视频有效播放监测链接
  121. String videoPlayEffectiveTrackUrl = data.getString("videoPlayEffectiveTrackUrl");
  122. if(null!=videoPlayEffectiveTrackUrl&&!videoPlayEffectiveTrackUrl.trim().equals("")){
  123. if(!videoPlayEffectiveTrackUrl.contains(tokenInfo)){
  124. errorMsg+= "视频有效播放监测链接填写异常;";
  125. errorflag = true;
  126. }
  127. }
  128. if(errorflag){
  129. sendMessage(allocation,"警告:账户:"+allocation.getAuthName()+"(id:"+allocation.getAccountId()+")下的广告计划:"+plan.getName()+"(id:"+plan.getId()+")"+"监测链接异常>>"+errorMsg);
  130. }
  131. }
  132. private void sendMessage(UserAllocation allocation, String errorMsg) {
  133. sendMessageService.sendMessage(allocation.getUserId(),errorMsg);
  134. }
  135. @Autowired
  136. private IUserAllocationService allocationService;
  137. @Autowired
  138. private IByteDanceAdvertisePlanService advertisePlanService;
  139. @Autowired
  140. private IByteDanceCreativeService creativeService;
  141. @Autowired
  142. private ISendMessageService sendMessageService;
  143. @Autowired
  144. private IBindAccountLoginService bindAccountLoginService;
  145. @Autowired
  146. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  147. @Test
  148. public void loadKuaishouCookie() {
  149. List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  150. if (list != null && !list.isEmpty()) {
  151. int i = 0;
  152. for (BindAccountLogin login : list) {
  153. if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
  154. if (i > 5) {
  155. break;
  156. }
  157. kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
  158. i++;
  159. }
  160. }
  161. }
  162. }
  163. static ExecutorService executorService = null;
  164. //线程计数器
  165. static CountDownLatch countDownLatch = null;
  166. @Test
  167. public void deleteKuaishouComment() {
  168. Long start = System.currentTimeMillis();
  169. List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
  170. if (loginList != null && !loginList.isEmpty()) {
  171. executorService = Executors.newFixedThreadPool(5);
  172. countDownLatch = new CountDownLatch(loginList.size());
  173. loginList.forEach(login -> executorService.submit(() -> {
  174. try {
  175. kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
  176. } catch (Exception e) {
  177. log.error(e.getMessage(), e);
  178. } finally {
  179. countDownLatch.countDown();
  180. }
  181. }));
  182. try {
  183. countDownLatch.await();
  184. } catch (InterruptedException e) {
  185. e.printStackTrace();
  186. }
  187. Long end = System.currentTimeMillis();
  188. log.info("快手删评论所用时长:{}毫秒", end - start);
  189. }
  190. }
  191. @Test
  192. public void testLoadBytedanceData() {
  193. List<UserAllocation> allocations = allocationService.getByParams(435L, null, 0);
  194. for (UserAllocation allocation : allocations) {
  195. for (int i = 2; i < 10; i++) {
  196. CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId());
  197. Date getDate = DateUtils.addDay(new Date(), -i);
  198. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  199. }
  200. }
  201. }
  202. @Test
  203. public void loadKuaishouAgentData() {
  204. kuaishouReportDailyAgentService.loginAgent();
  205. // for(int i=0;i<20;i++){
  206. // String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(),-i));
  207. // kuaishouReportDailyAgentService.getReport(currentDate,DateUtils.getNowDate("yyyy-MM-dd"));
  208. // }
  209. //
  210. try {
  211. for (int i = 1; i < 30; i++) {
  212. kuaishouReportDailyAgentService.getAccount(i);
  213. }
  214. } catch (Exception e) {
  215. e.printStackTrace();
  216. }
  217. }
  218. @Autowired
  219. private GroovyScriptExecutor groovyScriptExecutor;
  220. @Autowired
  221. private ICtopCheckTaskListService checkTaskListService;
  222. @Test
  223. public void checkDataStateJobTest() {
  224. //查询需要检查的任务列表
  225. List<CtopCheckTaskList> ctopCheckTaskList = checkTaskListService.queryExecuteList("checkDataStateJob");
  226. if (ctopCheckTaskList != null) {
  227. ctopCheckTaskList.forEach(it -> groovyScriptExecutor.execute(it));
  228. }
  229. }
  230. @Test
  231. public void loadAccountData() {
  232. CtopOauthToken token = oauthTokenService.getTokenByAccountId(1665922219192387L);
  233. reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-09-01", "yy-MM-dd"), DateUtils.parseDate("2020-09-01", "yy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  234. }
  235. @Autowired
  236. IUReportExportService uReportExportService;
  237. @Autowired
  238. EmailSendMsgHandle emailSendMsgHandle;
  239. @Autowired
  240. IUReportService uReportService;
  241. @Autowired
  242. private IKuaishouCrawlerService crawlerService;
  243. @Autowired
  244. private IMusicKuaishouTypeService musicKuaishouTypeService;
  245. @Test
  246. public void loadKuaishouMusicInfo(){
  247. // String musicTypeString = crawlerService.getMusicTypeList("");
  248. // String llsid = JSONObject.parseObject(musicTypeString).getString("llsid");
  249. // System.out.println(llsid);
  250. // JSONArray channels = JSONObject.parseObject(musicTypeString).getJSONArray("channels");
  251. // if (null!=channels&&!channels.isEmpty()){
  252. // for(int i=0;i<channels.size();i++){
  253. // JSONObject object = channels.getJSONObject(i);
  254. // MusicKuaishouType kuaishouType = new MusicKuaishouType(object);
  255. // musicKuaishouTypeService.save(kuaishouType);
  256. // }
  257. // }
  258. String llsid = "2000106667298730337";
  259. String musicTypeString = crawlerService.getMusicList("200032",llsid);
  260. System.out.println(musicTypeString);
  261. }
  262. }