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.text.SimpleDateFormat; 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 = new Date(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH"); String hour = simpleDateFormat.format(getDate); if (null != hour && hour.equals("00")) { getDate = DateUtils.addDay(getDate, -1); } //1:查询当日数据 List tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU); if (null == tokens || tokens.size() <= 0) { log.info("定时获取头条数据异常:为获取到可用的token"); return; } executorService = Executors.newFixedThreadPool(10); countDownLatch = new CountDownLatch(tokens.size()); Date finalGetDate = getDate; tokens.forEach(token -> { executorService.submit(new Runnable() { @Override public void run() { try { kuaishouInterfaceService.getAdvertiserReportHourly(token, finalGetDate, finalGetDate); //2:获取广告计划信息数据 kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, finalGetDate, finalGetDate); //3:获取广告组信息数据 kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, finalGetDate, finalGetDate); //4: 获取广告创意信息数据 kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, finalGetDate, finalGetDate); } catch (Exception e) { e.printStackTrace(); } finally { countDownLatch.countDown(); } } }); }); try { countDownLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } for (CtopOauthToken token : tokens) { kuaishouInterfaceService.updateCreativeReportHourlyStatistic(token, getDate); } executorService.shutdown(); } @Test public void loadAllMetiaralInfo() throws InterruptedException { Long start = System.currentTimeMillis(); Date getDate = new Date(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH"); String hour = simpleDateFormat.format(getDate); if (null != hour && hour.equals("00")) { getDate = DateUtils.addDay(getDate, -1); } //1:查询当日数据 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); tokens.forEach(token -> { executorService.submit(new Runnable() { @Override public void run() { try { Long start = System.currentTimeMillis(); //1:获取全量广告计划数据 kuaishouInterfaceService.getCampaignList(token); Long end1 = System.currentTimeMillis(); //1:获取全量广告组数据 kuaishouInterfaceService.getGroupList(token); Long end2 = System.currentTimeMillis(); //1:获取全量创意数据 kuaishouInterfaceService.getCreativeList(token); Long end3 = System.currentTimeMillis(); //2:获取全量视频素材数据 kuaishouInterfaceService.getVideoList(token); } catch (Exception e) { e.printStackTrace(); } finally { countDownLatch.countDown(); } } }); }); countDownLatch.await(); System.out.println("数据获取完成"); //关掉线程池 executorService.shutdown(); Long end1 = System.currentTimeMillis(); System.out.println("#######################" + (end1 - start) + "#################"); log.info("物料数据同步完成"); // for (CtopOauthToken token : tokens) { // kuaishouInterfaceService.getAdvertiserReportHourly(token, getDate, getDate); // } // for (CtopOauthToken token : tokens) { // //2:获取广告计划信息数据 // kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getDate, getDate); // } // for (CtopOauthToken token : tokens) { // //3:获取广告组信息数据 // kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getDate, getDate); // } // for (CtopOauthToken token : tokens) { // //4: 获取广告创意信息数据 // kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate); // kuaishouInterfaceService.updateCreativeReportHourlyStatistic(token, getDate); // } // // Long end2 = System.currentTimeMillis(); // System.out.println("#######################"+(end2-end1)+"#################"); } @Autowired private ICtopOauthTokenService tokenService; }