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.common.module.utils.OSSUtils; import cn.com.ctop.common.module.utils.StringUtils; import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService; import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService; import com.alibaba.fastjson.JSONArray; 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.jeecg.modules.demo.mock.MockController; import org.jeecg.modules.demo.test.mapper.JeecgDemoMapper; import org.jeecg.modules.demo.test.service.IJeecgDemoService; import org.jeecg.modules.system.service.ISysDataLogService; 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 javax.annotation.Resource; import java.io.File; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; @RunWith(SpringRunner.class) @SpringBootTest @Slf4j public class SampleTest { @Resource private JeecgDemoMapper jeecgDemoMapper; @Resource private IJeecgDemoService jeecgDemoService; @Resource private ISysDataLogService sysDataLogService; @Resource private MockController mock; @Autowired private ICreateInternalService createInternalService; @Autowired private IKuaishouInterfaceService kuaishouInterfaceService; @Test public void testLogin() { Map map = createInternalService.checkAccountPassword("dcd_ad@bytedance.com", "typdDCD@2018"); } @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 -> { //1: 获取广告主信息数据 // kuaishouInterfaceService.getAdvertiserReportDaily(token,getDate); //2:获取广告计划信息数据 // kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token,getDate); //3:获取广告组信息数据 // kuaishouInterfaceService.getAdvertiserGroupReportDaily(token,getDate); //4: 获取广告创意信息数据 // kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token,getDate); // //1: 获取广告主信息数据 // kuaishouInterfaceService.getAdvertiserReportHourly(token, getDate); // //2:获取广告计划信息数据 kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getDate, getDate); // //3:获取广告组信息数据 kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getDate, getDate); // //4: 获取广告创意信息数据 kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate); }); } @Test public void testLoadDate180() { Date endDate = new Date(); Date hourlyStartDate = DateUtils.addDay(endDate, -7); Date startDate = DateUtils.addDay(endDate, -170); // List bytedanceTokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE); // if (null != bytedanceTokens && bytedanceTokens.size() > 0) { // bytedanceTokens.forEach(token -> { // //1: 获取广告主信息数据 // reportService.getAdvertiserReport(token, startDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY); // //2:获取广告组信息数据 // reportService.getAdvertiserCampaignReport(token, startDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY); // //3:获取广告计划信息数据 // reportService.getAdvertiserPlanReport(token, startDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY); // //4: 获取广告创意信息数据 // reportService.getAdvertiserCreativeReport(token, startDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY); // // //1: 获取广告主信息数据 // reportService.getAdvertiserReport(token, hourlyStartDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY); // //2:获取广告组信息数据 // reportService.getAdvertiserCampaignReport(token, hourlyStartDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY); // //3:获取广告计划信息数据 // reportService.getAdvertiserPlanReport(token, hourlyStartDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY); // //4: 获取广告创意信息数据 // reportService.getAdvertiserCreativeReport(token, hourlyStartDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY); // }); // } List kuaishouTokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU); if (null != kuaishouTokens && kuaishouTokens.size() > 0) { for (CtopOauthToken token : kuaishouTokens) { for (int i = 0; i < 7; i++) { Date getStartDate = DateUtils.addDay(endDate, -i); //1: 获取广告主信息数据 // kuaishouInterfaceService.getAdvertiserReportHourly(token, getStartDate, getStartDate); //2:获取广告计划信息数据 // kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getStartDate, getStartDate); //3:获取广告组信息数据 kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getStartDate, getStartDate); //4: 获取广告创意信息数据 // kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getStartDate, getStartDate); } // for (int i = 0; i < 6; i++) { // Date getStartDate = new Date(); // Date getEndDate = new Date(); // if (i == 0) { // getStartDate = DateUtils.addDay(endDate, -175 + i * 30); // getEndDate = DateUtils.addDay(endDate, -150 + i * 30); // } else { // getStartDate = DateUtils.addDay(endDate, -180 + i * 30); // getEndDate = DateUtils.addDay(endDate, -150 + i * 30); // } // //1: 获取广告主信息数据 // kuaishouInterfaceService.getAdvertiserReportDaily(token, getStartDate, getEndDate); // //2:获取广告计划信息数据 // kuaishouInterfaceService.getAdvertiserCampaignReportDaily(token, getStartDate, getEndDate); // //3:获取广告组信息数据 // kuaishouInterfaceService.getAdvertiserGroupReportDaily(token, getStartDate, getEndDate); // //4: 获取广告创意信息数据 // kuaishouInterfaceService.getAdvertiserCreativeReportDaily(token, getStartDate, getEndDate); // } } } } @Test public void testFileType() { File file = new File("D:\\工作文件\\360借条\\快手后台数据-户1.csv"); } @Test public void testFileUpload() { OSSUtils.uploadObject2Oss(new File("D:\\upload\\excel\\template.xlsx")); } @Test public void testNg() { JSONObject json = new JSONObject(); createInternalService.createInternal(json); } @Autowired private ICtopOauthTokenService tokenService; @Autowired private IByteDanceAdvertiserDataService advertiserDataService; @Autowired private IFileInfoService fileInfoService; @Test public void setJSONFile() { CtopOauthToken token = tokenService.getOauthTokenByAccountId("93289889842"); JSONObject wordsObject = fileInfoService.getCreativeWord(token, token.getAccountId()); String getTitle = "哈哈{日期}{男人女人}"; JSONArray ids = getCreativeWordIds(getTitle, wordsObject); } public JSONArray getCreativeWordIds(String getTitle, JSONObject wordsObject) { ArrayList wordsString = StringUtils.stringCutFromBrace(getTitle); JSONArray creativeWords = wordsObject.getJSONArray("creative_word"); JSONArray ids = new JSONArray(); wordsString.forEach(v -> { creativeWords.forEach(word -> { JSONObject wordObject = (JSONObject) word; String name = wordObject.getString("name"); Integer id = wordObject.getInteger("creative_word_id"); if (v.equals(name)) { ids.add(id); } }); }); return ids; } }