package org.jeecg; import cn.com.ctop.bytedance.service.IReportService; import cn.com.ctop.common.module.entity.CtopOauthToken; import cn.com.ctop.common.module.service.ICtopOauthTokenService; import cn.com.ctop.common.module.service.IFileInfoService; import cn.com.ctop.common.module.utils.CtopAdConstant; import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.ctop.service.ICreateInternalService; 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.junit4.SpringRunner; import java.io.IOException; import java.util.Date; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @RunWith(SpringRunner.class) @SpringBootTest @Slf4j public class SampleTest { @Autowired private ICreateInternalService createInternalService; @Autowired private IKuaishouInterfaceService kuaishouInterfaceService; @Autowired private IReportService reportService; @Test public void testJob() { Date getDate = DateUtils.addDay(new Date(), -1); //1:查询当日数据 List tokens = tokenService.getTokenListByType(2 + ""); if (null == tokens || tokens.size() <= 0) { log.info("定时获取头条数据异常:为获取到可用的token"); return; } tokens.forEach(token -> { // //2:获取广告计划信息数据 kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getDate, getDate); // //3:获取广告组信息数据 kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getDate, getDate); // //4: 获取广告创意信息数据 kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate); }); } @Autowired IFileInfoService fileInfoService; @Test public void testVideoList() throws IOException { CtopOauthToken token = tokenService.getOauthTokenByAccountId("1232598"); kuaishouInterfaceService.getVideoList(token); } @Test public void testNg() { JSONObject json = new JSONObject(); createInternalService.createInternal(json); } static ExecutorService executorService = null; static CountDownLatch countDownLatch = null; //线程计数器 如果不用执行完后统一走流程,可以不要这个 @Test public void loadData() throws InterruptedException { Date getDate = DateUtils.addDay(new Date(), -1); // Date getDate = new Date(); List tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU); if (null == tokens || tokens.size() <= 0) { log.info("定时获取头条数据异常:为获取到可用的token"); return; } int times = tokens.size(); executorService = Executors.newFixedThreadPool(10); countDownLatch = new CountDownLatch(times); for (CtopOauthToken token : tokens) { executorService.submit(new Runnable() { @Override public void run() { if (token.getAccountId() == 2731757) { System.out.println("" + token.getAccountId() + "开始"); kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate); System.out.println("" + token.getAccountId() + "结束"); } countDownLatch.countDown(); } }); } countDownLatch.await(); System.out.println("Game Over"); //关掉线程池 executorService.shutdown(); } @Test public void loadAllMetiaralInfo() { Date getDate = DateUtils.addDay(new Date(), -1); List tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU); if (null == tokens || tokens.size() <= 0) { log.info("定时获取头条数据异常:为获取到可用的token"); return; } // tokens.forEach(token -> { // kuaishouInterfaceService.getCampaignList(token); // }); // tokens.forEach(token -> { // kuaishouInterfaceService.getGroupList(token); // }); tokens.forEach(token -> { kuaishouInterfaceService.getCreativeList(token); }); tokens.forEach(token -> { kuaishouInterfaceService.getVideoList(token); }); log.info("快手物料数据同步完成"); tokens.forEach(token -> { kuaishouInterfaceService.getAdvertiserReportDaily(token, getDate, getDate); }); tokens.forEach(token -> { kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getDate, getDate); }); tokens.forEach(token -> { kuaishouInterfaceService.getAdvertiserGroupReportDaily(token, getDate, getDate); }); tokens.forEach(token -> { kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token, getDate, getDate); }); } @Autowired private ICtopOauthTokenService tokenService; }