package org.jeecg; import cn.com.ctop.bytedance.entity.BytedancePlanDailyReport; import cn.com.ctop.bytedance.service.IBytedancePlanDailyReportService; import cn.com.ctop.bytedance.service.IReportService; import cn.com.ctop.common.module.entity.CtopOauthToken; import cn.com.ctop.common.module.entity.UserAllocation; import cn.com.ctop.common.module.service.ICtopOauthTokenService; import cn.com.ctop.common.module.service.IUserAllocationService; import cn.com.ctop.common.module.utils.CtopAdConstant; import cn.com.ctop.crawler.modules.appium.service.IAppiumJobService; import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService; import cn.com.ctop.toutiao.service.IByteDanceCreativeService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.mq.Sender; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @RunWith(SpringRunner.class) @SpringBootTest @Slf4j public class SampleTest { @Value("${jeecg.path.chrome-driver}") private String chromeDriver; @Autowired private IAppiumJobService jobService; @Test public void testMq() { Sender sender = new Sender(); sender.send(); } @Autowired private ICtopOauthTokenService tokenService; @Autowired private IReportService reportService; @Test public void getYddData()throws Exception{ String dateString = "2020-01-06"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date getDate = dateFormat.parse(dateString); List tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE); if (null == tokens || tokens.size() <= 0) { log.info("定时获取头条数据异常:为获取到可用的token"); return; } tokens.forEach(token -> { reportService.getAdvertiserPlanReport(token,getDate,getDate,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY); }); //清洗关于缘多多数据 //1:查询缘多多相关的用户数据 QueryWrapper yddWrapper = new QueryWrapper<>(); yddWrapper.eq("project_id",113); List yddallocations = userAllocationService.list(yddWrapper); if(null!=yddallocations&&yddallocations.size()>0){ yddallocations.forEach(allocation->{ //根据accountId和时间,查询相关的日报表信息 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("advertiser_id",allocation.getAccountId()) //.eq("stat_datetime",dateString) ; ListbytedancePlanDailyReports = planDailyReportService.list(queryWrapper); if(null!=bytedancePlanDailyReports&&bytedancePlanDailyReports.size()>0){ bytedancePlanDailyReports.forEach(report->{ String adName = report.getAdName(); String[] tags = adName.split("-"); report.setChannelCode(tags[0]); planDailyReportService.updateById(report); }); } }); } //清洗关于缘多多数据 //1:查询缘多多相关的用户数据 QueryWrapper dsjyWrapper = new QueryWrapper<>(); yddWrapper.eq("project_id",112); List dsjyAllocations = userAllocationService.list(dsjyWrapper); if(null!=dsjyAllocations&&dsjyAllocations.size()>0){ dsjyAllocations.forEach(allocation->{ //根据accountId和时间,查询相关的日报表信息 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("advertiser_id",allocation.getAccountId()) //.eq("stat_datetime",dateString) ; ListbytedancePlanDailyReports = planDailyReportService.list(queryWrapper); if(null!=bytedancePlanDailyReports&&bytedancePlanDailyReports.size()>0){ bytedancePlanDailyReports.forEach(report->{ String adName = report.getAdName(); String[] tags = adName.split("-"); report.setChannelCode(tags[0]); planDailyReportService.updateById(report); }); } }); } //清洗关于缘多多数据 //1:查询缘多多相关的用户数据 QueryWrapper fjyhWrapper = new QueryWrapper<>(); yddWrapper.eq("project_id",222); List fjyhAllocations = userAllocationService.list(fjyhWrapper); if(null!=fjyhAllocations&&fjyhAllocations.size()>0){ fjyhAllocations.forEach(allocation->{ //根据accountId和时间,查询相关的日报表信息 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("advertiser_id",allocation.getAccountId()) //.eq("stat_datetime",dateString) ; ListbytedancePlanDailyReports = planDailyReportService.list(queryWrapper); if(null!=bytedancePlanDailyReports&&bytedancePlanDailyReports.size()>0){ bytedancePlanDailyReports.forEach(report->{ String adName = report.getAdName(); String[] tags = adName.split("-"); report.setChannelCode(tags[0]); planDailyReportService.updateById(report); }); } }); } } @Test public void getZybBytedancePlanReport(){ // Date getDate = DateUtils.addDay(new Date(), -1); Date getDate = new Date(); //1:查询作业帮相关的用户数据 QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("project_id",215); List allocations = userAllocationService.list(wrapper); if(null!=allocations){ allocations.forEach(allocation->{ CtopOauthToken token = tokenService.getOauthTokenByAccountId(allocation.getAccountId()+""); //3:获取广告计划信息数据 reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY); }); } //清洗关于作业帮数据 if(null!=allocations&&allocations.size()>0){ allocations.forEach(allocation->{ //根据accountId和时间,查询相关的日报表信息 QueryWrapper queryWrapper = new QueryWrapper<>(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String dateString = dateFormat.format(getDate)+" 00:00:00"; System.out.println(dateString); queryWrapper.eq("advertiser_id",allocation.getAccountId()) // .eq("stat_datetime",dateString) ; ListbytedancePlanDailyReports = planDailyReportService.list(queryWrapper); if(null!=bytedancePlanDailyReports&&bytedancePlanDailyReports.size()>0){ bytedancePlanDailyReports.forEach(report->{ String adName = report.getAdName(); System.out.println(adName); String[] tags = adName.split("-"); report.setAdsense(tags[1]); report.setPlanCode(tags[2]); String tag = tags[3]; if(tag.contains("其他")){ report.setMaterialType("其他"); }else if (tag.contains("图片轮播")){ report.setMaterialType("图片轮播"); }else if(tag.contains("大字报")){ report.setMaterialType("大字报"); }else if(tag.contains("文字动画")){ report.setMaterialType("文字动画"); }else if(tag.contains("采访形式")){ report.setMaterialType("采访形式"); }else if(tag.contains("剧情")){ report.setMaterialType("剧情"); }else if(tag.contains("口播")){ report.setMaterialType("口播"); }else{ report.setMaterialType("其他"); } planDailyReportService.updateById(report); }); } }); } } @Test public void getByteDanceCreativeDate()throws Exception{ String dateString = "2020-01-06"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date getDate = dateFormat.parse(dateString); List tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE); if (null == tokens || tokens.size() <= 0) { log.info("定时获取头条数据异常:为获取到可用的token"); return; } tokens.forEach(token -> { //3:获取广告计划信息数据 // creativeService.getAdvertiserCreative(token.getAccountId() + "", "", null); //2:获取全量素材数据 // advertiserDataService.getMaterialList(token); reportService.getAdvertiserPlanReport(token,getDate,getDate,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY); }); } @Autowired private IByteDanceAdvertiserDataService advertiserDataService; @Autowired private IByteDanceCreativeService creativeService; @Test public void getBytedancePlanHourReport(){ Date getDate = DateUtils.addDay(new Date(), -1); //1:查询当日数据 List tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE); if (null == tokens || tokens.size() <= 0) { log.info("定时获取头条数据异常:为获取到可用的token"); return; } tokens.forEach(token -> { //3:获取广告计划信息数据 advertiserDataService.getAdvertiserPlan(token, "", null, null); }); } @Test public void loadRegistOrderData(){ } @Autowired private IUserAllocationService userAllocationService; @Autowired private IBytedancePlanDailyReportService planDailyReportService; }