package org.jeecg; import cn.com.ctop.check.component.execute.GroovyScriptExecutor; import cn.com.ctop.check.entity.CtopCheckTaskList; import cn.com.ctop.check.service.ICtopCheckTaskListService; import cn.com.ctop.common.module.entity.BindAccountLogin; import cn.com.ctop.common.module.entity.CtopOauthToken; import cn.com.ctop.common.module.entity.UserAllocation; import cn.com.ctop.common.module.message.handle.impl.EmailSendMsgHandle; import cn.com.ctop.common.module.service.*; import cn.com.ctop.common.module.utils.CtopAdConstant; import cn.com.ctop.crawler.modules.core.service.IKuaishouCrawlerService; import cn.com.ctop.crawler.modules.music.service.IMusicKuaishouTypeService; import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService; import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService; import cn.com.ctop.toutiao.modules.material.entity.ByteDanceAdvertisePlan; import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertisePlanService; import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService; import cn.com.ctop.toutiao.modules.material.service.IByteDanceCreativeService; import cn.com.ctop.toutiao.modules.report.service.IReportService; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.DateUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("wps") @Slf4j public class SampleTest { @Autowired private ICtopOauthTokenService oauthTokenService; @Autowired private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService; @Autowired private IReportService reportService; @Autowired private IUserAllocationService userAllocationService; @Autowired private IByteDanceAdvertiserDataService advertiserDataService; @Test public void loadBytedanceCreativeData() { // Listallocations = userAllocationService.getByParams(633L,null,0); // // if(null!=allocations&&!allocations.isEmpty()){ // for (UserAllocation allocation:allocations) { // CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId()); // advertiserDataService.getAdvertiserPlan(token, "", null, null); // } // } UserAllocation allocation = userAllocationService.getByAccountId(1648083559613447L); CtopOauthToken token = oauthTokenService.getTokenByAccountId(1648083559613447L); // advertiserDataService.getAdvertiserPlan(token, "", null, null); List plans = advertisePlanService.getAllPlans(token.getAccountId(),DateUtils.formatDate(new Date())); if(null!=plans&&!plans.isEmpty()){ for (ByteDanceAdvertisePlan plan:plans) { Map creativeDetail = creativeService.getCreativeDetail(token.getAccountId(), plan.getId()); if(null!=creativeDetail.get("data")){ JSONObject data = (JSONObject) creativeDetail.get("data"); checkMonitorLink(data,plan,allocation); } } } } private void checkMonitorLink(JSONObject data, ByteDanceAdvertisePlan plan, UserAllocation allocation) { String downloadUrl = plan.getDownloadUrl(); boolean errorflag = false; String errorMsg = ""; String token = plan.getName().split("-")[0]; String tokenInfo = "surl_token="+token; String appType = plan.getAppType(); if(null!=downloadUrl){ if(null!=appType&&appType.equals("APP_IOS")){ if(!downloadUrl.equals("https://apps.apple.com/cn/app/id1468454200")){ errorMsg+= "应用下载链接填写异常;"; errorflag = true; } } if(null!=appType&&appType.equals("APP_ANDROID")){ if(!downloadUrl.contains(token)){ errorMsg+= "应用下载链接填写异常;"; errorflag = true; } } } //展示监测链接 String trackUrl = data.getString("trackUrl"); if(null!=trackUrl&&!trackUrl.trim().equals("")){ if(!trackUrl.contains(tokenInfo)){ errorMsg+= "展示监测链接填写异常;"; errorflag = true; } } //点击监测链接 String actionTrackUrl = data.getString("actionTrackUrl"); if(null!=actionTrackUrl&&!actionTrackUrl.trim().equals("")){ if(null!=appType&&appType.equals("APP_IOS")){ if(!actionTrackUrl.contains(tokenInfo)||!actionTrackUrl.contains("app_platform=ios")){ errorMsg+= "点击监测链接填写异常;"; errorflag = true; } } if(null!=appType&&appType.equals("APP_ANDROID")){ if(!actionTrackUrl.contains(tokenInfo)||!actionTrackUrl.contains("tt/1967")){ errorMsg+= "点击监测链接填写异常;"; errorflag = true; } } } //视频有效播放监测链接 String videoPlayEffectiveTrackUrl = data.getString("videoPlayEffectiveTrackUrl"); if(null!=videoPlayEffectiveTrackUrl&&!videoPlayEffectiveTrackUrl.trim().equals("")){ if(!videoPlayEffectiveTrackUrl.contains(tokenInfo)){ errorMsg+= "视频有效播放监测链接填写异常;"; errorflag = true; } } if(errorflag){ sendMessage(allocation,"警告:账户:"+allocation.getAuthName()+"(id:"+allocation.getAccountId()+")下的广告计划:"+plan.getName()+"(id:"+plan.getId()+")"+"监测链接异常>>"+errorMsg); } } private void sendMessage(UserAllocation allocation, String errorMsg) { sendMessageService.sendMessage(allocation.getUserId(),errorMsg); } @Autowired private IUserAllocationService allocationService; @Autowired private IByteDanceAdvertisePlanService advertisePlanService; @Autowired private IByteDanceCreativeService creativeService; @Autowired private ISendMessageService sendMessageService; @Autowired private IBindAccountLoginService bindAccountLoginService; @Autowired private IKuaishouWebInterfaceService kuaishouWebInterfaceService; @Test public void loadKuaishouCookie() { List list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1); if (list != null && !list.isEmpty()) { int i = 0; for (BindAccountLogin login : list) { if (null == login.getCookie() || "".equals(login.getCookie().trim())) { if (i > 5) { break; } kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login); i++; } } } } static ExecutorService executorService = null; //线程计数器 static CountDownLatch countDownLatch = null; @Test public void deleteKuaishouComment() { Long start = System.currentTimeMillis(); List loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1); if (loginList != null && !loginList.isEmpty()) { executorService = Executors.newFixedThreadPool(5); countDownLatch = new CountDownLatch(loginList.size()); loginList.forEach(login -> executorService.submit(() -> { try { kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login); } catch (Exception e) { log.error(e.getMessage(), e); } finally { countDownLatch.countDown(); } })); try { countDownLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } Long end = System.currentTimeMillis(); log.info("快手删评论所用时长:{}毫秒", end - start); } } @Test public void testLoadBytedanceData() { List allocations = allocationService.getByParams(435L, null, 0); for (UserAllocation allocation : allocations) { for (int i = 2; i < 10; i++) { CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId()); Date getDate = DateUtils.addDay(new Date(), -i); reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY); } } } @Test public void loadKuaishouAgentData() { kuaishouReportDailyAgentService.loginAgent(); // for(int i=0;i<20;i++){ // String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(),-i)); // kuaishouReportDailyAgentService.getReport(currentDate,DateUtils.getNowDate("yyyy-MM-dd")); // } // try { for (int i = 1; i < 30; i++) { kuaishouReportDailyAgentService.getAccount(i); } } catch (Exception e) { e.printStackTrace(); } } @Autowired private GroovyScriptExecutor groovyScriptExecutor; @Autowired private ICtopCheckTaskListService checkTaskListService; @Test public void checkDataStateJobTest() { //查询需要检查的任务列表 List ctopCheckTaskList = checkTaskListService.queryExecuteList("checkDataStateJob"); if (ctopCheckTaskList != null) { ctopCheckTaskList.forEach(it -> groovyScriptExecutor.execute(it)); } } @Test public void loadAccountData() { CtopOauthToken token = oauthTokenService.getTokenByAccountId(1665922219192387L); reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-09-01", "yy-MM-dd"), DateUtils.parseDate("2020-09-01", "yy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY); } @Autowired IUReportExportService uReportExportService; @Autowired EmailSendMsgHandle emailSendMsgHandle; @Autowired IUReportService uReportService; @Autowired private IKuaishouCrawlerService crawlerService; @Autowired private IMusicKuaishouTypeService musicKuaishouTypeService; @Test public void loadKuaishouMusicInfo(){ // String musicTypeString = crawlerService.getMusicTypeList(""); // String llsid = JSONObject.parseObject(musicTypeString).getString("llsid"); // System.out.println(llsid); // JSONArray channels = JSONObject.parseObject(musicTypeString).getJSONArray("channels"); // if (null!=channels&&!channels.isEmpty()){ // for(int i=0;i