123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- package org.jeecg;
- import cn.com.ctop.common.module.entity.BindAccountLogin;
- import cn.com.ctop.common.module.entity.CtopOauthToken;
- import cn.com.ctop.common.module.entity.UserAllocation;
- import cn.com.ctop.common.module.message.handle.impl.EmailSendMsgHandle;
- import cn.com.ctop.common.module.service.*;
- import cn.com.ctop.common.module.utils.CtopAdConstant;
- import cn.com.ctop.common.module.utils.HttpUtils;
- import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
- import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
- import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
- import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
- import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
- import cn.com.ctop.toutiao.modules.report.service.IBytedanceFundDailyService;
- import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
- import cn.com.ctop.toutiao.modules.report.service.IReportService;
- import cn.com.ctop.toutiao.modules.report.service.IRuleByteDanceAccountService;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.xxl.job.core.log.XxlJobLogger;
- import lombok.extern.slf4j.Slf4j;
- import org.jeecg.common.util.DateUtils;
- 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.ActiveProfiles;
- import org.springframework.test.context.junit4.SpringRunner;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.concurrent.CountDownLatch;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- @RunWith(SpringRunner.class)
- @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
- @ActiveProfiles("wps")
- @Slf4j
- public class SampleTest {
- @Autowired
- private ICtopOauthTokenService oauthTokenService;
- @Autowired
- private IReportService reportService;
- @Autowired
- private IByteDanceAdvertiserDataService advertiserDataService;
- @Autowired
- private IKuaiShouHistoryReportTaskService kuaiShouHistoryReportTaskService;
- @Autowired
- private ICtopOauthTokenService tokenService;
- @Test
- public void loadBytedanceCreativeData() {
- QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("media_id", 2);
- List<CtopOauthToken> list = oauthTokenService.list(queryWrapper);
- for (CtopOauthToken token : list) {
- kuaiShouHistoryReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-20", "2020-09-20", "daily");
- }
- }
- @Autowired
- private IBindAccountLoginService bindAccountLoginService;
- @Autowired
- private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
- @Test
- public void loadKuaishouCookie() {
- List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
- if (list != null && !list.isEmpty()) {
- int i = 0;
- for (BindAccountLogin login : list) {
- if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
- if (i > 5) {
- break;
- }
- kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
- i++;
- }
- }
- }
- }
- static ExecutorService executorService = null;
- //线程计数器/bytedance/bytedanceMaterialReport
- static CountDownLatch countDownLatch = null;
- @Test
- public void deleteKuaishouComment() {
- Long start = System.currentTimeMillis();
- List<BindAccountLogin> loginList = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
- if (loginList != null && !loginList.isEmpty()) {
- executorService = Executors.newFixedThreadPool(5);
- countDownLatch = new CountDownLatch(loginList.size());
- loginList.forEach(login -> executorService.submit(() -> {
- try {
- kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- } finally {
- countDownLatch.countDown();
- }
- }));
- try {
- countDownLatch.await();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- Long end = System.currentTimeMillis();
- log.info("快手删评论所用时长:{}毫秒", end - start);
- }
- }
- @Test
- public void testXxlJobDistribute(){
- String url = "http://127.0.0.1:8090/xxl-job-admin/jobinfo/trigger?id=88&executorParam=";
- for(int i=0;i<100;i++){
- String result = HttpUtils.httpPostRequest(url+i,new HashMap<>(),new HashMap<>());
- System.out.println(result);
- }
- }
- @Test
- public void testLoadRulePlanData(){
- Date date = new Date();
- List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
- executorService = Executors.newFixedThreadPool(10);
- countDownLatch = new CountDownLatch(tokens.size());
- tokens.forEach(token -> executorService.submit(()->{
- try {
- Long start = System.currentTimeMillis();
- reportService.getAdvertiserPlanRuleData(token,date,date,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
- Long end = System.currentTimeMillis();
- log.info("账户数据获取完成:accountId=>{},耗时{}毫秒",token.getAccountId(),end-start);
- }catch (Exception e){
- e.printStackTrace();
- }finally {
- countDownLatch.countDown();
- }
- }));
- try {
- countDownLatch.await();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- @Autowired
- private IUserAllocationService allocationService;
- @Test
- public void testLoadBytedanceData() {
- List<UserAllocation>allocations = allocationService.getByParams(273L,null,0);
- if(null!=allocations&&!allocations.isEmpty()){
- for(UserAllocation allocation:allocations){
- CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
- String startDate = "2020-11-05";
- String endDate = "2020-11-09";
- reportService.getAdvertiserPlanReport(token, DateUtils.parseDate(startDate,"yyyy-MM-dd"), DateUtils.parseDate(endDate,"yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
- }
- }
- System.out.println("任务结束");
- }
- @Test
- public void loadBytedancePlanData(){
- CtopOauthToken token = tokenService.getTokenByAccountId(100198696723L);
- // advertiserDataService.getAdvertiserPlan(token, "", null, null);
- Date getDate = DateUtils.addDay(new Date(), 0);
- reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
- }
- @Autowired
- private IBytedanceFundDailyService bytedanceFundDailyService;
- @Test
- public void loadFoudData() {
- List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
- for (CtopOauthToken token : tokens) {
- System.out.println(token.getAccountId()+"############################");
- for(int i=20;i<130;i++){
- Date date = DateUtils.addDay(new Date(),-i);
- bytedanceFundDailyService.loadFundDataByPage(token, DateUtils.formatDate(date), DateUtils.formatDate(date),1);
- System.out.println(i+"############################");
- }
- }
- }
- @Autowired
- private IKuaiShouHistoryReportTaskService reportTaskService;
- /**
- * 测试获取快手图片消耗数据任务
- */
- @Test
- public void loadKuaishouImageTask(){
- List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
- for(int i=1;i<130;i++) {
- Date getDate = DateUtils.addDay(new Date(), -i);
- String getDateStr = DateUtils.formatDate(getDate);
- tokens.forEach(token -> reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY));
- }
- }
- @Test
- public void testLoadBytedanceImageData(){
- List<CtopOauthToken>tokens = tokenService.selectToutiaoToken();
- countDownLatch = new CountDownLatch(tokens.size());
- executorService = Executors.newFixedThreadPool(8);
- tokens.forEach(token->executorService.submit(()->{
- try {
- advertiserDataService.getMaterialList(token);
- }catch (Exception e){
- }finally {
- countDownLatch.countDown();
- }
- }));
- try {
- countDownLatch.await();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("素材数据获取完成");
- }
- @Autowired
- private IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
- @Test
- public void loadKuaishouAgentData() throws JsonProcessingException {
- kuaishouReportDailyAgentService.loginAgent();
- // for (int i = 0; i < 20; i++) {
- // String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(), -i));
- // kuaishouReportDailyAgentService.getReport(currentDate, DateUtils.getNowDate("yyyy-MM-dd"));
- // }
- //
- try {
- for (int i = 1; i < 30; i++) {
- kuaishouReportDailyAgentService.getAccount(i);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Autowired
- private IKuaishouInterfaceService kuaishouInterfaceService;
- @Test
- public void loadKuaishouGroupData() throws ParseException {
- Date endDate = new Date();
- String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.formatDate(endDate), -1);
- SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
- Date startDate = sim.parse(anotherDay);
- CtopOauthToken token = tokenService.getTokenByAccountId(7087890L);
- kuaishouInterfaceService.getGroupList(token, startDate, endDate);
- }
- @Autowired
- IUReportExportService uReportExportService;
- @Autowired
- EmailSendMsgHandle emailSendMsgHandle;
- @Autowired
- IUReportService uReportService;
- @Autowired
- private IBytedanceReportService bytedanceReportService;
- @Test
- public void loadMatData(){
- List<UserAllocation> allocations = allocationService.getByParams(289L,null,0);
- countDownLatch = new CountDownLatch(allocations.size());
- executorService = Executors.newFixedThreadPool(2);
- allocations.forEach(allocation -> {
- executorService.submit(new Runnable() {
- @Override
- public void run() {
- try {
- CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
- //获取全量视频素材数据
- advertiserDataService.getMaterialList(token);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- countDownLatch.countDown();
- }
- }
- });
- });
- try {
- countDownLatch.await();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- XxlJobLogger.log("物料数据同步完成");
- }
- @Autowired
- IRuleByteDanceAccountService ruleByteDanceAccountService;
- @Test
- public void cleanRuleDataAccount(){
- List<CtopOauthToken> tokens = oauthTokenService.selectToutiaoToken();
- for(CtopOauthToken oauthToken:tokens){
- ruleByteDanceAccountService.cleanRuleDataAccount(oauthToken.getAccountId());
- }
- }
- }
|