package org.jeecg; import cn.com.ctop.bytedance.service.IReportService; import cn.com.ctop.common.module.entity.CtopOauthToken; import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper; 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.common.module.utils.HttpUtils; import cn.com.ctop.common.module.utils.OSSUtils; import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService; import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService; 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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.ctop.service.IBytedanceFundDailyService; import org.jeecg.modules.ctop.service.IPerformanceSaleService; 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.FileInputStream; import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; 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 IKuaishouInterfaceService kuaishouInterfaceService; @Autowired private IKuaiShouHistoryReportTaskService reportTaskService; @Autowired private CtopOauthTokenMapper tokenMapper; @Test public void kuaisShouReport() { try { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("account_id", 3727345L); CtopOauthToken token = tokenMapper.selectOne(queryWrapper); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date parse = simpleDateFormat.parse("2020-03-12"); kuaishouInterfaceService.getAdvertiserReportDaily(token, parse, parse); // reportTaskService.createTask(3727345L, "871fc2c248782a94ad2962c941555abc", ""); // reportTaskService.getTaskList(); /* reportTaskService.createTask(3727345L, "871fc2c248782a94ad2962c941555abc"); reportTaskService.getTaskList();*/ /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/async_task/list"; Map headers = new HashMap<>(); headers.put("Content-Type", " application/json"); headers.put("Access-Token", "eb9a0d18072eabc339ee26ad010ecd6b"); JSONObject param = new JSONObject(); param.put("advertiser_id", 142402); JSONArray taskIds = new JSONArray(); taskIds.add(1229917); param.put("task_ids", taskIds); String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers); JSONObject resultJson = JSONObject.parseObject(result); /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/async_task/download"; Map headers = new HashMap<>(); headers.put("Access-Token", "eb9a0d18072eabc339ee26ad010ecd6b"); Map param = new HashMap<>(); param.put("advertiser_id", 142402); param.put("task_id", "1229917"); String result = HttpUtils.KuaiShouttpGetRequest(url, param,headers);*/ /*URL url = new URL("https://ad.e.kuaishou.com/rest/openapi/v1/async_task/download?task_id=1229917&advertiser_id=142402"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //设置超时间为3秒 conn.setConnectTimeout(10 * 1000); //防止屏蔽程序抓取而返回403错误 conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); conn.setRequestProperty("Access-Token", "6a1fbe20e49fe519ec8120aac5c9e55a"); //得到输入流 InputStream inputStream = conn.getInputStream(); //获取自己数组 byte[] getData = readInputStream(inputStream); //文件保存位置 File saveDir = new File("D:\\file"); if (!saveDir.exists()) { saveDir.mkdirs(); } String fileName = "123.csv"; File file = new File(saveDir + File.separator + fileName); FileOutputStream fos = new FileOutputStream(file); fos.write(getData); if (fos != null) { fos.close(); } if (inputStream != null) { inputStream.close(); }*/ /* String localPath = "D:\\file\\123.csv"; reportDailyAccountMapper.loadAccountDailyReport(142402L,localPath);*/ } catch (Exception e) { e.printStackTrace(); } } @Autowired private ICtopOauthTokenService tokenService; private static ExecutorService executorService = Executors.newFixedThreadPool(10); private static CountDownLatch countDownLatch = null; @Autowired private IBytedanceFundDailyService fundDailyService; @Test public void testLoadJob() { String endDate = "2020-04-07"; String startDate = "2019-09-01"; CtopOauthToken token = tokenService.getTokenByAccountId(1654676647522317L); // List tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE); List tokens = new ArrayList<>(); tokens.add(token); if (null != tokens && tokens.size() > 0) { countDownLatch = new CountDownLatch(tokens.size()); tokens.forEach(getToken -> { //拉取往期数据 executorService.submit(new Runnable() { @Override public void run() { try { fundDailyService.loadFundDataByPage(getToken, startDate, endDate, 1); countDownLatch.countDown(); } catch (Exception e) { e.printStackTrace(); } } }); }); try { countDownLatch.await(); System.out.println("数据获取完成"); } catch (InterruptedException e) { e.printStackTrace(); } } } @Test public void loadCampaignDate() { Date endDate = DateUtils.addDay(new Date(), -1); Date startDate = DateUtils.addDay(new Date(), -10); //1:查询当日数据 List tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE); if (null == tokens || tokens.size() <= 0) { log.info("定时获取头条数据异常:为获取到可用的token"); return; } // executorService = Executors.newFixedThreadPool(10); tokens.forEach(token -> { // executorService.submit(new Runnable() { // @Override // public void run() { //获取广告主信息数据 reportService.getCampaignReportByPage(token, startDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY, 1); // } // }); }); } @Autowired private IReportService reportService; @Autowired private IUserAllocationService userAllocationService; @Test public void wanHuaTong() { String url = "https://ad.oceanengine.com/open_api/2/kaleidoscope/job/smart_cut/submit/"; JSONObject conditions = new JSONObject(); // 1629785592929294 conditions.put("advertiser_id", "1659671533108238"); JSONObject job = new JSONObject(); job.put("job_conf_id", 10); JSONArray input = new JSONArray(); JSONObject inputJson = new JSONObject(); inputJson.put("task_id", 1); JSONArray videoIds = new JSONArray(); videoIds.add("v02033aa0000bpspgippskdk4jcuso80"); inputJson.put("video_ids", videoIds); JSONArray music_id = new JSONArray(); JSONArray image_urls = new JSONArray(); JSONArray texts = new JSONArray(); texts.add("哈哈哈哈,这是一个测试文案"); inputJson.put("texts", texts); JSONArray tts = new JSONArray(); tts.add("true"); inputJson.put("tts", tts); JSONArray video_ratio = new JSONArray(); video_ratio.add("1"); inputJson.put("video_ratio", video_ratio); JSONArray music_style = new JSONArray(); music_style.add("1"); inputJson.put("music_style", music_style); JSONArray video_duration = new JSONArray(); video_duration.add("8"); inputJson.put("video_duration", video_duration); JSONArray speed = new JSONArray(); speed.add("1.2"); inputJson.put("speed", speed); job.put("input", inputJson); job.put("mesg", "测试万花筒"); conditions.put("job", job); JSONObject jsonObject = HttpUtils.bytedancePostRequest("f925c180e05d585f7a9fce048ba62eecc5dab7c2", url, conditions); System.err.println(jsonObject); } @Autowired private IKuaiShouCreativeService creativeService; @Test public void testSalePerformance() { performanceSaleService.loadSalsePerformance(); } @Test public void loadBtPlanData() { List tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE); tokens.forEach(token -> { advertiserDataService.getAdvertiserPlan(token, "", null, null); }); } @Autowired private IByteDanceAdvertiserDataService advertiserDataService; @Autowired private IPerformanceSaleService performanceSaleService; @Autowired private IKuaiShouHistoryReportTaskService historyReportTaskService; @Test public void testLoadData() throws Exception { CtopOauthToken token = tokenService.getTokenByAccountId(5473041L); String endDateStr = DateUtils.getDate("yyyy-MM-dd"); String startDate = DateUtils.addMonth(endDateStr, -6); historyReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), startDate, endDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_HISTORY); } @Test public void suZhao() { Long accountId = 3917130L; String token = "0a42e23921e486108105263e75561404"; kuaishouInterfaceService.getVideoList("e91c778d7de1bd0e9d8f3213d1e0e57c",3820093L, null,null,1); } @Test public void test() throws Exception { InputStream file = new FileInputStream("D:\\data\\模板视频\\原始模板4.mp4"); OSSUtils.uploadFile2OSS(file, "/model/video/", "123.mp4"); } }