123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- package org.jeecg;
- import cn.com.ctop.check.component.execute.GroovyScriptExecutor;
- import cn.com.ctop.check.entity.CtopCheckTaskList;
- import cn.com.ctop.check.service.ICtopCheckTaskListService;
- import cn.com.ctop.common.module.entity.BindAccountLogin;
- import cn.com.ctop.common.module.entity.CtopOauthToken;
- import cn.com.ctop.common.module.entity.UReportSubscriber;
- 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.service.impl.UReportExportRest;
- import cn.com.ctop.common.module.utils.CtopAdConstant;
- import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
- import cn.com.ctop.kuaishou.modules.report.service.IKuaiShouDailyAgentService;
- import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
- import cn.com.ctop.toutiao.modules.report.service.IReportService;
- import lombok.Data;
- 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.io.File;
- 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 IKuaishouReportDailyAgentService kuaishouReportDailyAgentService;
- @Autowired
- private IKuaiShouDailyAgentService kuaiShouDailyAgentService;
- @Autowired
- private IReportService reportService;
- @Test
- public void loadBytedanceCreativeData() {
- // refreshTokenService.getKuaiShouAgentRefresh();
- String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
- String yesterday = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
- kuaiShouDailyAgentService.getAgentReportByPage(nowDate, nowDate);
- }
- @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()){
- for (BindAccountLogin login:list) {
- if(null==login.getCookie()||"".equals(login.getCookie().trim())){
- kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
- }
- }
- }
- }
- static ExecutorService executorService = null;
- //线程计数器
- 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);
- }
- }
- @Autowired
- private IUserAllocationService allocationService;
- @Test
- public void testLoadBytedanceData() {
- List<UserAllocation>allocations = allocationService.getByParams(435L,null,0);
- for (UserAllocation allocation:allocations) {
- for(int i=2;i<10;i++){
- CtopOauthToken token = oauthTokenService.getTokenByAccountId(allocation.getAccountId());
- Date getDate = DateUtils.addDay(new Date(),-i);
- reportService.getAdvertiserReport(token,getDate,getDate,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
- }
- }
- }
- @Test
- public void loadKuaishouAgentData() {
- for(int i=0;i<20;i++){
- String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(),-i));
- kuaishouReportDailyAgentService.getReport(currentDate,DateUtils.getNowDate("yyyy-MM-dd"));
- }
- int currentPage = 1;
- while (kuaishouReportDailyAgentService.getAccount(currentPage)){
- currentPage++;
- }
- }
- @Autowired
- private GroovyScriptExecutor groovyScriptExecutor;
- @Autowired
- private ICtopCheckTaskListService checkTaskListService;
- @Test
- public void checkDataStateJobTest(){
- //查询需要检查的任务列表
- List<CtopCheckTaskList> ctopCheckTaskList= checkTaskListService.queryExecuteList("checkDataStateJob");
- if(ctopCheckTaskList!=null){
- ctopCheckTaskList.forEach(it-> groovyScriptExecutor.execute(it));
- }
- }
- @Test
- public void loadAccountData() {
- CtopOauthToken token = oauthTokenService.getTokenByAccountId(1665922219192387L);
- reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-09-01","yy-MM-dd"), DateUtils.parseDate("2020-09-01","yy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
- }
- @Autowired
- IUReportExportService uReportExportService;
- @Autowired
- EmailSendMsgHandle emailSendMsgHandle;
- @Autowired
- IUReportService uReportService;
- @Test
- public void sendUReport(){
- uReportService.uReportList().forEach(uReport->{
- List<UReportSubscriber> uReportSubscriber = uReportService.getUReportSubscriberByFileId(uReport.getString("id"));
- if(!uReportSubscriber.isEmpty()){
- String title=uReport.getString("name").replace(".ureport.xml","");
- String content="您订阅的日报在附件中请注意查收》》》";
- //下载文件到本地
- uReportExportService.exportExcel(uReport.getString("name"));
- uReportSubscriber.forEach(sender->{
- emailSendMsgHandle.SendAttachment("bijiequan@c-top.com.cn",title,content,
- new File(System.getProperty("user.dir")+ File.separator + "uReport"+File.separator+uReport.getString("name").replace("ureport.xml","")+"xlsx"));
- }); }
- });
- //发完全部订阅,删除文件
- File file =new File(System.getProperty("user.dir")+ File.separator + "uReport");
- File[] files=file.listFiles();
- if(files!=null&&files.length>0){
- for (File f: files){
- f.delete();
- }
- }
- }
- }
|