syh 5 rokov pred
rodič
commit
39546674a3

+ 3 - 183
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -1,202 +1,22 @@
 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.kuaishou.modules.batch.service.IKuaishouInterfaceService;
-import com.alibaba.fastjson.JSONObject;
+import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskService;
 import lombok.extern.slf4j.Slf4j;
-import org.jeecg.common.util.DateUtils;
-import org.jeecg.modules.ctop.service.ICreateInternalService;
 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.IOException;
-import java.text.SimpleDateFormat;
-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 ICreateInternalService createInternalService;
-    @Autowired
-    private IKuaishouInterfaceService kuaishouInterfaceService;
-
-    @Autowired
-    private IReportService reportService;
-
+    private IAppiumTaskService taskService;
     @Test
     public void testJob() {
-
-        Date getDate = DateUtils.addDay(new Date(), -1);
-        //1:查询当日数据
-        List<CtopOauthToken> tokens = tokenService.getTokenListByType(2 + "");
-        if (null == tokens || tokens.size() <= 0) {
-            log.info("定时获取头条数据异常:为获取到可用的token");
-            return;
-        }
-        tokens.forEach(token -> {
-//            //2:获取广告计划信息数据
-            kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getDate, getDate);
-//            //3:获取广告组信息数据
-            kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getDate, getDate);
-//            //4: 获取广告创意信息数据
-            kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate);
-        });
-    }
-
-    @Autowired
-    IFileInfoService fileInfoService;
-    @Test
-    public void testVideoList() throws IOException {
-        CtopOauthToken token = tokenService.getOauthTokenByAccountId("1232598");
-        kuaishouInterfaceService.getVideoList(token);
-    }
-
-
-    @Test
-    public void testNg() {
-        JSONObject json = new JSONObject();
-        createInternalService.createInternal(json);
+        taskService.runTask(1, 1);
     }
 
-    static ExecutorService executorService = null;
-    static CountDownLatch countDownLatch = null; //线程计数器
-
-    @Test
-    public void loadData() throws InterruptedException {
-        Date getDate = new Date();
-        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
-        String hour = simpleDateFormat.format(getDate);
-        if (null != hour && hour.equals("00")) {
-            getDate = DateUtils.addDay(getDate, -1);
-        }
-        //1:查询当日数据
-        List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
-        if (null == tokens || tokens.size() <= 0) {
-            log.info("定时获取头条数据异常:为获取到可用的token");
-            return;
-        }
-
-        executorService = Executors.newFixedThreadPool(10);
-        countDownLatch = new CountDownLatch(tokens.size());
-        Date finalGetDate = getDate;
-        tokens.forEach(token -> {
-            executorService.submit(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        kuaishouInterfaceService.getAdvertiserReportHourly(token, finalGetDate, finalGetDate);
-                        //2:获取广告计划信息数据
-                        kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, finalGetDate, finalGetDate);
-                        //3:获取广告组信息数据
-                        kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, finalGetDate, finalGetDate);
-                        //4: 获取广告创意信息数据
-                        kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, finalGetDate, finalGetDate);
-
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    } finally {
-                        countDownLatch.countDown();
-                    }
-                }
-            });
-        });
-        try {
-            countDownLatch.await();
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-        for (CtopOauthToken token : tokens) {
-            kuaishouInterfaceService.updateCreativeReportHourlyStatistic(token, getDate);
-        }
-        executorService.shutdown();
-    }
-    @Test
-    public void loadAllMetiaralInfo() throws InterruptedException {
-        Long start = System.currentTimeMillis();
-        Date getDate = new Date();
-        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
-        String hour = simpleDateFormat.format(getDate);
-        if (null != hour && hour.equals("00")) {
-            getDate = DateUtils.addDay(getDate, -1);
-        }
-        //1:查询当日数据
-        List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
-        if (null == tokens || tokens.size() <= 0) {
-            log.info("定时获取头条数据异常:为获取到可用的token");
-            return;
-        }
-        int times = tokens.size();
-        executorService = Executors.newFixedThreadPool(10);
-        countDownLatch = new CountDownLatch(times);
-        tokens.forEach(token -> {
-            executorService.submit(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        Long start = System.currentTimeMillis();
-                        //1:获取全量广告计划数据
-                        kuaishouInterfaceService.getCampaignList(token);
-                        Long end1 = System.currentTimeMillis();
-                        //1:获取全量广告组数据
-                        kuaishouInterfaceService.getGroupList(token);
-                        Long end2 = System.currentTimeMillis();
-                        //1:获取全量创意数据
-                        kuaishouInterfaceService.getCreativeList(token);
-                        Long end3 = System.currentTimeMillis();
-                        //2:获取全量视频素材数据
-                        kuaishouInterfaceService.getVideoList(token);
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    } finally {
-                        countDownLatch.countDown();
-                    }
-
-                }
-            });
-        });
-        countDownLatch.await();
-        System.out.println("数据获取完成");
-        //关掉线程池
-        executorService.shutdown();
-        Long end1 = System.currentTimeMillis();
-        System.out.println("#######################" + (end1 - start) + "#################");
-        log.info("物料数据同步完成");
-
-//        for (CtopOauthToken token : tokens) {
-//            kuaishouInterfaceService.getAdvertiserReportHourly(token, getDate, getDate);
-//        }
-//        for (CtopOauthToken token : tokens) {
-//            //2:获取广告计划信息数据
-//            kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getDate, getDate);
-//        }
-//        for (CtopOauthToken token : tokens) {
-//            //3:获取广告组信息数据
-//            kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getDate, getDate);
-//        }
-//        for (CtopOauthToken token : tokens) {
-//            //4: 获取广告创意信息数据
-//            kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate);
-//            kuaishouInterfaceService.updateCreativeReportHourlyStatistic(token, getDate);
-//        }
-//
-//        Long end2 = System.currentTimeMillis();
-//        System.out.println("#######################"+(end2-end1)+"#################");
-    }
-
-    @Autowired
-    private ICtopOauthTokenService tokenService;
 }

+ 1 - 1
module-crawler/src/main/java/cn/com/ctop/crawler/modules/appium/service/IAppiumTaskItemService.java

@@ -12,5 +12,5 @@ import java.util.List;
  * @version V1.0
  */
 public interface IAppiumTaskItemService extends IService<AppiumTaskItem> {
-    public List<AppiumTaskItem> initTaskItemList(Integer taskId, Integer parentId);
+    List<AppiumTaskItem> initTaskItemList(Integer taskId, Integer parentId);
 }

+ 3 - 5
module-crawler/src/main/java/cn/com/ctop/crawler/modules/appium/service/impl/AppiumTaskItemServiceImpl.java

@@ -4,11 +4,9 @@ import cn.com.ctop.crawler.modules.appium.entity.AppiumTaskItem;
 import cn.com.ctop.crawler.modules.appium.mapper.AppiumTaskItemMapper;
 import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskItemService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import org.springframework.stereotype.Service;
-
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -19,8 +17,8 @@ import java.util.List;
  */
 @Service
 public class AppiumTaskItemServiceImpl extends ServiceImpl<AppiumTaskItemMapper, AppiumTaskItem> implements IAppiumTaskItemService {
+    @Override
     public List<AppiumTaskItem> initTaskItemList(Integer taskId, Integer parentId) {
-        List<AppiumTaskItem> list = new ArrayList<>();
         QueryWrapper<AppiumTaskItem> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("task_id", taskId);
         if (parentId == null) {
@@ -30,7 +28,7 @@ public class AppiumTaskItemServiceImpl extends ServiceImpl<AppiumTaskItemMapper,
         }
 
         queryWrapper.orderByAsc("seq");
-        list = this.list(queryWrapper);
+        List<AppiumTaskItem> list = this.list(queryWrapper);
         if (list != null && list.size() > 0) {
             for (int i = 0; i < list.size(); i++) {
                 AppiumTaskItem taskItem = list.get(i);

+ 4 - 7
module-crawler/src/main/java/cn/com/ctop/crawler/modules/appium/service/impl/AppiumTaskServiceImpl.java

@@ -4,23 +4,17 @@ import cn.com.ctop.crawler.modules.appium.entity.AppiumDevice;
 import cn.com.ctop.crawler.modules.appium.entity.AppiumTask;
 import cn.com.ctop.crawler.modules.appium.entity.AppiumTaskItem;
 import cn.com.ctop.crawler.modules.appium.entity.AppiumTaskLog;
-import cn.com.ctop.crawler.modules.appium.mapper.AppiumTaskItemMapper;
 import cn.com.ctop.crawler.modules.appium.mapper.AppiumTaskLogMapper;
 import cn.com.ctop.crawler.modules.appium.mapper.AppiumTaskMapper;
 import cn.com.ctop.crawler.modules.appium.service.IAppiumDeviceService;
 import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskItemService;
-import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskLogService;
 import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskService;
 import cn.com.ctop.crawler.modules.core.util.AppiumUtil;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import io.appium.java_client.android.AndroidDriver;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-
-import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.List;
 
 /**
@@ -38,8 +32,11 @@ public class AppiumTaskServiceImpl extends ServiceImpl<AppiumTaskMapper, AppiumT
     @Autowired
     private AppiumTaskLogMapper appiumTaskLogMapper;
 
+    @Override
     public void runTask(Integer taskId, Integer deviceId) {
+        //获取当前需要执行的任务信息
         AppiumTask task = this.getById(taskId);
+        //获取手机设备信息
         AppiumDevice appiumDevice = iAppiumDeviceService.getById(deviceId);
         appiumDevice.setStatus(2);
         iAppiumDeviceService.updateById(appiumDevice);

+ 17 - 0
module-crawler/src/main/java/cn/com/ctop/crawler/modules/core/util/AppiumUtil.java

@@ -159,6 +159,23 @@ public class AppiumUtil {
         }
     }
 
+    public void backToMain(AndroidDriver androidDriver) {
+        WebElement element = getElementById(androidDriver, "com.smile.gifmaker:id/back_btn");
+        if (null != element) {
+            element.click();
+        }
+    }
+
+    public void checkAdvertiser(AndroidDriver androidDriver, String advertiserName) {
+        WebElement label = getElementById(androidDriver, "com.smile.gifmaker:id/label");
+        String text = label.getText().substring(0, label.getText().indexOf(":") - 1);
+        if (null != label && null != text && text.equals(advertiserName)) {
+            //表示广告筛选成功
+        } else {
+            backToMain(androidDriver);
+        }
+    }
+
 
 
     public WebElement getElementById(AndroidDriver androidDriver, String id) {

+ 10 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouReportHourlyCampaignServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Service
@@ -18,4 +19,13 @@ public class KuaishouReportHourlyCampaignServiceImpl extends ServiceImpl<Kuaisho
     public void replaceBatch(List<KuaishouReportHourlyCampaign> campaigns) {
         campaignMapper.replaceBatch(campaigns);
     }
+
+    public static void main(String[] args) {
+        List<String> list = new ArrayList<>();
+        if (list == null) {
+            return;
+        }
+        List<String> getList = new ArrayList<>(list.size());
+        System.out.println(list.size());
+    }
 }