syh 5 лет назад
Родитель
Сommit
1e3a44ec51

+ 5 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CrawlerController.java

@@ -17,4 +17,9 @@ public class CrawlerController {
     public Map<String, Object> loadInspiration() {
         return crawlerService.loadInspiration();
     }
+
+//    @PostMapping("startJob")
+//    public Map<String, Object> runTask(Long jobId, Long num, String creativeName, String accountId, String publishName) {
+//        return crawlerService.startJob(jobId, num, creativeName, accountId, publishName);
+//    }
 }

+ 3 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/ICrawlerService.java

@@ -1,7 +1,10 @@
 package org.jeecg.modules.ctop.service;
 
+import org.jeecg.modules.ctop.vo.KuaishouAppiumJobVO;
+
 import java.util.Map;
 
 public interface ICrawlerService {
     Map<String, Object> loadInspiration();
+    Map<String, Object> startJob(KuaishouAppiumJobVO jobVO);
 }

+ 94 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CrawlerServiceImpl.java

@@ -1,7 +1,16 @@
 package org.jeecg.modules.ctop.service.impl;
 
+import cn.com.ctop.common.module.entity.BindAccountLogin;
 import cn.com.ctop.common.module.service.IBindAccountLoginService;
 import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.ResultMapUtils;
+import cn.com.ctop.common.module.utils.StatusCode;
+import cn.com.ctop.crawler.modules.appium.entity.AppiumDevice;
+import cn.com.ctop.crawler.modules.appium.entity.AppiumTaskLog;
+import cn.com.ctop.crawler.modules.appium.mapper.AppiumTaskLogMapper;
+import cn.com.ctop.crawler.modules.appium.service.IAppiumDeviceService;
+import cn.com.ctop.crawler.modules.appium.service.IAppiumJobService;
+import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskService;
 import cn.com.ctop.crawler.modules.kuaishoucce.entity.KuaishouEffectAdInfo;
 import cn.com.ctop.crawler.modules.kuaishoucce.entity.KuaishouHotPhotoInfo;
 import cn.com.ctop.crawler.modules.kuaishoucce.entity.KuaishouInspiredAd;
@@ -12,6 +21,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.modules.ctop.service.ICrawlerService;
+import org.jeecg.modules.ctop.vo.KuaishouAppiumJobVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -20,6 +30,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 @Service
 @Slf4j
@@ -141,4 +152,87 @@ public class CrawlerServiceImpl implements ICrawlerService {
         String result = HttpUtils.httpPostRequest(url, param, new HashMap<>());
         return JSONObject.parseObject(result);
     }
+
+    @Autowired
+    private IAppiumJobService jobService;
+    @Autowired
+    private IAppiumTaskService taskService;
+    @Autowired
+    private IAppiumDeviceService deviceService;
+    @Autowired
+    private AppiumTaskLogMapper taskLogMapper;
+
+    @Override
+    public Map<String, Object> startJob(KuaishouAppiumJobVO jobVO) {
+        Map<String, Object> result = new HashMap<>();
+        //1:根据id查询快手账号信息
+        BindAccountLogin accountLogin = bindAccountLoginService.getById(jobVO.getAccountId());
+        if (null == accountLogin) {
+            ResultMapUtils.setResultMap(result, StatusCode.COMMON_PARAM_ERROR.getCode());
+            return result;
+        }
+        if (jobVO.getJobId() == null || jobVO.getJobId() == 0 || jobVO.getNum() == null || jobVO.getNum() == 0 || jobVO.getCreativeName() == null || "".equals(jobVO.getCreativeName()) || jobVO.getPublishName() == null || "".equals(jobVO.getPublishName().trim())) {
+            ResultMapUtils.setResultMap(result, StatusCode.COMMON_PARAM_ERROR.getCode());
+            return result;
+        }
+        Long num = jobVO.getNum();
+        //获取手机设备信息
+        AppiumDevice device = deviceService.getEnabled();
+        if (null == device || device.getStatus() != 1) {
+            ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_NO_ENABLED_DEVICE.getCode());
+            return result;
+        }
+        executorService = Executors.newFixedThreadPool(2);
+        executorService.submit(new Runnable() {
+            @Override
+            public void run() {
+                int i = 0;
+                while (i < num) {
+                    if (i > num) {
+                        break;
+                    }
+                    deviceService.updateById(device);
+                    AppiumTaskLog log = new AppiumTaskLog();
+                    log.setDeviceId(device.getId());
+                    log.setDeviceIp(device.getIp());
+                    log.setDevicePort(device.getPort());
+                    log.setStatus(1 + "");
+                    log.setTaskId(jobVO.getJobId());
+                    log.setTaskName("快手刷量任务");
+                    taskLogMapper.insert(log);
+                    log.setId(log.getId());
+                    try {
+                        //一键新机
+                        boolean success = jobService.refreshWebPhone();
+                        if (!success) {
+                            jobService.updateStatus(device, log, -4, 1);
+                            continue;
+                        }
+                        Thread.sleep(10000L);
+                        String ksId = jobService.loginTask(2L, device);
+                        if (null == ksId) {
+                            i++;
+                            jobService.updateStatus(device, log, -1, 1);
+                            continue;
+                        }
+                        boolean isBind = jobService.bindCreative(accountLogin.getAccountName(), accountLogin.getPassword(), jobVO.getPublishName(), ksId);
+                        if (!isBind) {
+                            i++;
+                            jobService.updateStatus(device, log, -2, 1);
+                            continue;
+                        }
+                        taskService.runTask(1L, device.getId(), jobVO.getPublishName());
+                        jobService.updateStatus(device, log, 2, 1);
+                        i++;
+                    } catch (Exception e) {
+                        jobService.updateStatus(device, log, -3, 1);
+                        i++;
+                        continue;
+                    }
+                }
+            }
+        });
+        ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_JOB_StART.getCode());
+        return result;
+    }
 }

+ 2 - 2
jeecg-boot-module-system/src/main/resources/application-prod.yml

@@ -28,8 +28,8 @@ spring:
             enable: true
             required: true
   ## quartz定时任务,采用数据库方式
-  quartz:
-    job-store-type: jdbc
+#  quartz:
+#    job-store-type: jdbc
   #json 时间戳统一转换
   jackson:
     date-format:   yyyy-MM-dd HH:mm:ss

+ 36 - 0
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -1,6 +1,7 @@
 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.service.IBindAccountLoginService;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
@@ -24,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -190,6 +192,40 @@ public class SampleTest {
             }
         }
     }
+
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Test
+    public void loadHourly(){
+        List<CtopOauthToken>tokens = tokenService.selectToutiaoToken();
+        if(null!=tokens&&!tokens.isEmpty()){
+            executorService = Executors.newFixedThreadPool(10);
+            countDownLatch = new CountDownLatch(tokens.size());
+            tokens.forEach(token -> {
+                executorService.submit(()->{
+                    try {
+                        for(int i=0;i<7;i++){
+                            Date date = DateUtils.addDay(new Date(),-i);
+                            reportService.getAdvertiserReport(token,date,date,CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
+                        }
+                        System.out.println("账户:"+token.getAccountId()+"时报查询完毕");
+                    }catch (Exception e){
+
+                    }finally {
+                        countDownLatch.countDown();
+                    }
+                });
+            });
+            try {
+                countDownLatch.await();
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+             }
+
+            System.out.println("时报数据获取完成");
+
+        }
+    }
 }
 
 

+ 0 - 1
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/CtopOauthTokenMapper.xml

@@ -94,7 +94,6 @@
         on t1.account_id = t2.account_id
         where t2.account_status = 0
         and t1.media_id = 1
-        group by account_id
     </select>
 
     <select id="getAccessTokenByAccountIdAndMediaId" resultType="cn.com.ctop.common.module.entity.CtopOauthToken">

+ 0 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialCutFrameServiceImpl.java

@@ -67,7 +67,6 @@ public class MaterialCutFrameServiceImpl extends ServiceImpl<MaterialCutFrameMap
             if (!Check.isNull(checkCutFrame)) {
                 log.info("已存推荐封面");
                 return;
-
             }
 
             String zeroFrameUrl = url + "?x-oss-process=video/snapshot,t_00000,m_fast";

+ 1 - 6
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/BytedanceReportServiceImpl.java

@@ -773,12 +773,10 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
 
         JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
         if (json == null) {
-            //insertMaterialRetry(accountId, startDate, endDate, -2);
             log.error("请求有误:" + JSONObject.toJSONString(data));
             return -2;
         }
 
-        int returnCode = 200;
         try {
             if (!Check.isNull(json)) {
                 Integer code = json.getInteger("code");
@@ -799,7 +797,6 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                 JSONArray jsonArrayay = jsonData.getJSONArray("list");
                 if (jsonArrayay.size() == 0) {
                     log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
-                    //returnCode = 1;
                     return 1;
                 }
 
@@ -923,16 +920,14 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                     return pageCode;
                 }
             } else {
-                //returnCode = -1;
                 log.error("服务器返回为空,json:" + JSONObject.toJSONString(data));
                 return -1;
             }
         } catch (Exception e) {
             e.printStackTrace();
             log.error("头条报表其他错误,accountId:" + accountId + ",json:" + JSONObject.toJSONString(data));
-            returnCode = -3;
+            return -3;
         }
-        return returnCode;
     }
 
     @Override

+ 3 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/ReportServiceImpl.java

@@ -260,6 +260,9 @@ public class ReportServiceImpl implements IReportService {
             this.getAdvertiserCreativeReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
             this.getAdvertiserPlanReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
             this.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+            this.getAdvertiserCreativeReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
+            this.getAdvertiserPlanReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
+            this.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
         }
 
         try {