123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- 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<CtopOauthToken> 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<UserAllocation> yddWrapper = new QueryWrapper<>();
- yddWrapper.eq("project_id",113);
- List<UserAllocation> yddallocations = userAllocationService.list(yddWrapper);
- if(null!=yddallocations&&yddallocations.size()>0){
- yddallocations.forEach(allocation->{
- //根据accountId和时间,查询相关的日报表信息
- QueryWrapper<BytedancePlanDailyReport> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("advertiser_id",allocation.getAccountId())
- //.eq("stat_datetime",dateString)
- ;
- List<BytedancePlanDailyReport>bytedancePlanDailyReports = 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<UserAllocation> dsjyWrapper = new QueryWrapper<>();
- yddWrapper.eq("project_id",112);
- List<UserAllocation> dsjyAllocations = userAllocationService.list(dsjyWrapper);
- if(null!=dsjyAllocations&&dsjyAllocations.size()>0){
- dsjyAllocations.forEach(allocation->{
- //根据accountId和时间,查询相关的日报表信息
- QueryWrapper<BytedancePlanDailyReport> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("advertiser_id",allocation.getAccountId())
- //.eq("stat_datetime",dateString)
- ;
- List<BytedancePlanDailyReport>bytedancePlanDailyReports = 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<UserAllocation> fjyhWrapper = new QueryWrapper<>();
- yddWrapper.eq("project_id",222);
- List<UserAllocation> fjyhAllocations = userAllocationService.list(fjyhWrapper);
- if(null!=fjyhAllocations&&fjyhAllocations.size()>0){
- fjyhAllocations.forEach(allocation->{
- //根据accountId和时间,查询相关的日报表信息
- QueryWrapper<BytedancePlanDailyReport> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("advertiser_id",allocation.getAccountId())
- //.eq("stat_datetime",dateString)
- ;
- List<BytedancePlanDailyReport>bytedancePlanDailyReports = 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<UserAllocation> wrapper = new QueryWrapper<>();
- wrapper.eq("project_id",215);
- List<UserAllocation> 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<BytedancePlanDailyReport> 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)
- ;
- List<BytedancePlanDailyReport>bytedancePlanDailyReports = 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<CtopOauthToken> 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<CtopOauthToken> 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;
- }
|