123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- 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<CtopOauthToken> 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<CtopOauthToken> 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<CtopOauthToken> 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;
- }
|