Browse Source

重试机制

yumeng 5 years ago
parent
commit
f5e6573672

+ 6 - 0
jeecg-boot-module-system/pom.xml

@@ -232,6 +232,12 @@
             </properties>
         </profile>
         <profile>
+            <id>prod2</id>
+            <properties>
+                <activatedProperties>prod2</activatedProperties>
+            </properties>
+        </profile>
+        <profile>
             <id>wps</id>
             <properties>
                 <activatedProperties>wps</activatedProperties>

+ 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

+ 168 - 0
jeecg-boot-module-system/src/main/resources/application-prod2.yml

@@ -0,0 +1,168 @@
+server:
+  port: 8804
+  ip: 39.97.120.42
+  servlet:
+    context-path: /jeecg-boot
+    compression:
+      enabled: true
+      mime-types: application/javascript,application/json,application/xml,text/html,text/xml,text/plain,text/css,image/*
+management:
+  endpoints:
+    web:
+      exposure:
+        include: metrics,httptrace
+spring:
+  servlet:
+    multipart:
+      max-file-size: -1
+      max-request-size: -1
+  mail:
+    host: smtp.163.com
+    username: jeecgos@163.com
+    password: ??
+    properties:
+      mail:
+        smtp:
+          auth: true
+          starttls:
+            enable: true
+            required: true
+  ## quartz定时任务,采用数据库方式
+  quartz:
+    job-store-type: jdbc
+  #json 时间戳统一转换
+  jackson:
+    date-format:   yyyy-MM-dd HH:mm:ss
+    time-zone:   GMT+8
+  aop:
+    proxy-target-class: true
+  #配置freemarker
+  freemarker:
+    # 设置模板后缀名
+    suffix: .ftl
+    # 设置文档类型
+    content-type: text/html
+    # 设置页面编码格式
+    charset: UTF-8
+    # 设置页面缓存
+    cache: false
+    prefer-file-system-access: false
+    # 设置ftl文件路径
+    template-loader-path:
+      - classpath:/templates
+  # 设置静态文件路径,js,css等
+  mvc:
+    static-path-pattern: /**
+  resource:
+    static-locations: classpath:/static/,classpath:/public/
+  autoconfigure:
+    exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
+  datasource:
+    url: jdbc:mysql://172.30.0.4:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+    username: hcst
+    password: test@20190531
+    driver-class-name: com.mysql.jdbc.Driver
+    druid:
+      stat-view-servlet:
+        loginUsername: admin
+        loginPassword: hcst2016
+        enabled: true
+      web-stat-filter:
+        enabled: true
+    #      remove-abandoned: false
+    dynamic:
+      druid: # 全局druid参数,绝大部分值和默认保持一致。(现已支持的参数如下,不清楚含义不要乱设置)
+        # 连接池的配置信息
+        # 初始化大小,最小,最大
+        connection-init-sql: set names utf8mb4
+        initial-size: 5
+        min-idle: 5
+        maxActive: 20
+        # 配置获取连接等待超时的时间
+        maxWait: 60000
+        # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+        timeBetweenEvictionRunsMillis: 60000
+        # 配置一个连接在池中最小生存的时间,单位是毫秒
+        minEvictableIdleTimeMillis: 300000
+        validationQuery: SELECT 1 FROM DUAL
+        testWhileIdle: true
+        testOnBorrow: false
+        testOnReturn: false
+        # 打开PSCache,并且指定每个连接上PSCache的大小
+        poolPreparedStatements: true
+        maxPoolPreparedStatementPerConnectionSize: 20
+        # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
+        filters: stat,slf4j
+        # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
+        connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
+      datasource:
+        master:
+          url: jdbc:mysql://172.30.0.4:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+          username: hcst
+          password: test@20190531
+          driver-class-name: com.mysql.jdbc.Driver
+          # 多数据源配置
+          #multi-datasource1:
+          #url: jdbc:mysql://localhost:3306/jeecg-boot2?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
+          #username: root
+          #password: root
+          #driver-class-name: com.mysql.jdbc.Driver
+  #redis 配置
+  redis:
+    database: 0
+    host: 172.30.0.17
+    lettuce:
+      pool:
+        max-active: 8   #最大连接数据库连接数,设 0 为没有限制
+        max-idle: 8     #最大等待连接中的数量,设 0 为没有限制
+        max-wait: -1ms  #最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。
+        min-idle: 0     #最小等待连接中的数量,设 0 为没有限制
+      shutdown-timeout: 100ms
+    password: foobared
+    port: 6379
+#mybatis plus 设置
+mybatis-plus:
+  mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml,classpath*:cn/com/ctop/**/xml/*Mapper.xml
+  global-config:
+    # 关闭MP3.0自带的banner
+    banner: false
+    db-config:
+      #主键类型  0:"数据库ID自增",1:"该类型为未设置主键类型", 2:"用户输入ID",3:"全局唯一ID (数字类型唯一ID)", 4:"全局唯一ID UUID",5:"字符串全局唯一ID (idWorker 的字符串表示)";
+      id-type: 4
+      # 默认数据库表下划线命名
+      table-underline: true
+#  configuration:
+#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+#jeecg专用配置
+jeecg:
+  ffmpeg:
+    bin: ffmpeg
+  path:
+    #文件上传根目录 设置
+    upload: /data/upload
+    #webapp文件路径
+    webapp: /data/webapp
+    video-upload: /data/upload/video/
+    image-upload: /data/upload/image/
+    chrome-driver: /usr/bin/chromedriver
+    csv-upload: /data/upload/csv/
+    bak-database-file: /data/data/bak/
+    report-history: /data/upload/report/history/
+    report-daily: /data/upload/report/daily/
+kuaishou:
+  group-control:
+    path: http://39.106.184.70
+    port: 4723
+logging:
+  level:
+    root: info
+  config: classpath:logback-prod.xml
+chrome:
+  script:
+    clean: sh /data/webapp/cleanProcess.sh
+
+oss:
+  replace:
+    replace-value: oss-cn-beijing
+    replace-old-value: oss-cn-beijing
+    download: /data/file/video/

+ 13 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/RandomUtil.java

@@ -18,6 +18,19 @@ public class RandomUtil {
     }
 
 
+    public static String verifyCodeV2() {
+
+        char[] c = charArray();//获取包含26个字母大小写和数字的字符数组
+
+        Random rd = new Random();
+        String code = "";
+        for (int k = 0; k < 4; k++) {
+            int index = rd.nextInt(c.length);//随机获取数组长度作为索引
+            code += c[index];//循环添加到字符串后面
+        }
+        return code;
+    }
+
     private static char[] charArray() {
         int i = 1234567890;
         String s = "qwertyuiopasdfghjklzxcvbnm";

+ 78 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java

@@ -1798,6 +1798,84 @@ public class BatchController {
         return result;
     }
 
+
+    /**
+     * 复制组
+     *
+     * @param requestJson
+     * @return
+     */
+/*    @PostMapping(value = "/copyUnitUpdate")
+    public Result<JSONObject> copyUnitUpdate(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        try {
+            Long accountId = requestJson.getLong("accountId");
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            JSONObject returnJson = new JSONObject();
+
+            Long unitId = requestJson.getLong("unitId");
+            kuaiShouGroupService.getGroupByUnitId(oauthToken.getAccessToken(), oauthToken.getAccountId(), unitId);
+            Long copyToCampaignId = requestJson.getLong("copyToCampaignId");
+            JSONArray failArr = new JSONArray();
+            //  Integer createCount = requestJson.getInteger("createCount");
+
+
+            Integer createType = requestJson.getInteger("createType");
+            if (createType == 1) { //系统生成
+                // 需要获取创建条数
+                Integer createCount = requestJson.getInteger("createCount");
+                String unitName = requestJson.getString("unitName");
+                if (unitName.contains("#")) {
+                    int lastIndexOf = unitName.lastIndexOf("#");
+                    unitName = unitName.substring(0, lastIndexOf);
+                }
+                requestJson.remove("unitName");
+                for (int i = 0; i < createCount; i++) {
+                    String randomName = unitName + RandomUtil.verifyCodeV2() + i;
+                    requestJson.put("unitName", randomName);
+                    JSONObject createJson = batchService.createUnit(requestJson, oauthToken);
+                    if (createJson.getInteger("code") != 0) {
+                        JSONObject errJson = new JSONObject();
+                        errJson.put("message", createJson.getString("message"));
+                        returnJson.put("unitName", randomName);
+                        failArr.add(errJson);
+                    }
+                }
+
+            } else if (createType == 2) { // 自定义
+                JSONArray unitNames = requestJson.getJSONArray("unitNames");
+                for (int i = 0; i < unitNames.size(); i++) {
+                    String unitName = unitNames.getString(i);
+                    requestJson.put("unitName", unitName);
+                    JSONObject createJson = batchService.createUnit(requestJson, oauthToken);
+                    if (createJson.getInteger("code") != 0) {
+                        JSONObject errJson = new JSONObject();
+                        errJson.put("message", createJson.getString("message"));
+                        returnJson.put("unitName", unitName);
+                        failArr.add(errJson);
+                    }
+
+                }
+            }
+
+
+            returnJson.put("failCount", failArr.size());
+            returnJson.put("failInfo", failArr);
+            result.setResult(returnJson);
+            result.setSuccess(true);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }*/
+
+
     /**
      * 获取人群包
      *

+ 2 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java

@@ -126,7 +126,7 @@ public interface IKuaishouInterfaceService {
      * @param requestJson
      * @return
      */
-    Map<String, Object> adUnitCreate(String accessToken, Long advertiserId, JSONObject requestJson);
+    Map<String, Object> adUnitCreate(String accessToken, Long advertiserId, JSONObject requestJson, Integer count);
 
 
     /**
@@ -191,7 +191,7 @@ public interface IKuaishouInterfaceService {
      * @param advertiserId
      * @param requestJson
      */
-    Map<String, Object> creativeCreate(String accessToken, Long advertiserId, JSONObject requestJson);
+    Map<String, Object> creativeCreate(String accessToken, Long advertiserId, JSONObject requestJson, Integer count);
 
     /**
      * 根据创意id 获取创意信息

+ 5 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java

@@ -404,7 +404,7 @@ public class BatchServiceImpl implements IBatchService {
                     unitJson.put("unit_name", unitName);
                 }
 
-                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), unitJson);
+                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), unitJson,1);
                 if (!Check.isNullMap(returnUnitMap)) {
                     Integer code = (Integer) returnUnitMap.get("code");
                     if (code == 0) {
@@ -683,7 +683,7 @@ public class BatchServiceImpl implements IBatchService {
                     unitJson.put("unit_name", unitName);
                 }
 
-                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), group.getAccountId(), unitJson);
+                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), group.getAccountId(), unitJson,1);
                 if (!Check.isNullMap(returnUnitMap)) {
                     Integer code = (Integer) returnUnitMap.get("code");
                     if (code == 0) {
@@ -786,7 +786,7 @@ public class BatchServiceImpl implements IBatchService {
                 }*/
 
 
-                Map<String, Object> returnCreativeMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson);
+                Map<String, Object> returnCreativeMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson,1);
                 if (!Check.isNullMap(returnCreativeMap)) {
                     Integer code = (Integer) returnCreativeMap.get("code");
                     if (code == 0) {
@@ -804,6 +804,7 @@ public class BatchServiceImpl implements IBatchService {
         }
     }
 
+
     /**
      * 获取广告组信息
      *
@@ -907,7 +908,7 @@ public class BatchServiceImpl implements IBatchService {
                                     }
                                 }
                                 creativeJson.put("image_token", imageToken);
-                                Map<String, Object> returnUnitMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson);
+                                Map<String, Object> returnUnitMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson,1);
                                 if (!Check.isNullMap(returnUnitMap)) {
                                     Integer code = (Integer) returnUnitMap.get("code");
                                     if (code == 0) {

+ 6 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouCreateServiceImpl.java

@@ -1,5 +1,7 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaignCreate;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaignTemplate;
@@ -17,8 +19,6 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
-import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -244,7 +244,7 @@ public class KuaiShouCreateServiceImpl implements IKuaiShouCreateService {
                     name = unitName;
                 }
                 groupJson.put("unit_name", name);
-                Map<String, Object> groupMap = kuaishouInterfaceService.adUnitCreate(accessToken, accountId, groupJson);
+                Map<String, Object> groupMap = kuaishouInterfaceService.adUnitCreate(accessToken, accountId, groupJson, 1);
                 if ((Integer) groupMap.get("code") != 0) {
                     log.error("创建广告组失败,accountId:{},unitName:{}", accountId, unitName);
                     return groupMap;
@@ -391,7 +391,7 @@ public class KuaiShouCreateServiceImpl implements IKuaiShouCreateService {
                     } else {
                         createJson.put("creative_name", creativeName + "_" + i);
                     }
-                    Map<String, Object> creativeMap = kuaishouInterfaceService.creativeCreate(accessToken, accountId, createJson);
+                    Map<String, Object> creativeMap = kuaishouInterfaceService.creativeCreate(accessToken, accountId, createJson, 1);
                     if ((Integer) creativeMap.get("code") != 0) {
                         return creativeMap;
                     }
@@ -451,7 +451,7 @@ public class KuaiShouCreateServiceImpl implements IKuaiShouCreateService {
                         } else {
                             createJson.put("creative_name", creativeName + "_" + i);
                         }
-                        Map<String, Object> creativeMap = kuaishouInterfaceService.creativeCreate(accessToken, accountId, createJson);
+                        Map<String, Object> creativeMap = kuaishouInterfaceService.creativeCreate(accessToken, accountId, createJson, 1);
                         if ((Integer) creativeMap.get("code") != 0) {
                             log.error("后贴片视频素材批量创建创意失败,accountId:{},creativeName:{}", accountId, creativeName + "_" + i);
                             return creativeMap;
@@ -492,7 +492,7 @@ public class KuaiShouCreateServiceImpl implements IKuaiShouCreateService {
                         JSONArray imageTokens = new JSONArray();
                         imageTokens.add(imageMap.get("imageToken"));
                         createJson.put("image_tokens", imageTokens);
-                        Map<String, Object> creativeMap = kuaishouInterfaceService.creativeCreate(accessToken, accountId, createJson);
+                        Map<String, Object> creativeMap = kuaishouInterfaceService.creativeCreate(accessToken, accountId, createJson, 1);
                         if ((Integer) creativeMap.get("code") != 0) {
                             log.error("后贴片素材单张图片批量创建创意失败,accountId:{}", accountId);
                             return creativeMap;

+ 21 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -223,7 +223,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 kuaiShouVideoGet.setId(token.getAccountId() + kuaiShouVideoGet.getPhotoId());
 
                 Date videoTime = videoTimeService.getVideoTime(kuaiShouVideoGet.getPhotoId(), token.getAccountId());
-                if(!Check.isNull(videoTime)){
+                if (!Check.isNull(videoTime)) {
                     kuaiShouVideoGet.setUploadDate(videoTime);
                 }
 
@@ -995,7 +995,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
 
     @Override
-    public Map<String, Object> adUnitCreate(String accessToken, Long advertiserId, JSONObject requestJson) {
+    public Map<String, Object> adUnitCreate(String accessToken, Long advertiserId, JSONObject requestJson, Integer count) {
         Map<String, Object> returnMap = new HashMap<>();
         try {
             if (Check.isNull(requestJson)) {
@@ -1039,6 +1039,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     }
 
                 } else {
+
+                    if (code == 500000 && count <= 4) {
+
+                        adUnitCreate(accessToken, advertiserId, requestJson, count + 1);
+                    }
                     log.error("创建广告信息失败,advertiser_id:{},返回信息:{},入参:{}", advertiserId, resultJson, requestJson);
                     returnMap.put("code", -1);
                     returnMap.put("message", resultJson.getString("message"));
@@ -1046,6 +1051,10 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     returnMap.put("success", false);
                 }
             } else {
+                if (count <= 4) {
+                    log.info("创建组失败,重试,入参:{}", requestJson);
+                    adUnitCreate(accessToken, advertiserId, requestJson, count + 1);
+                }
                 log.error("快手创建广告计划返回内容为空,advertiser_id:{},入参:{}", advertiserId, requestJson);
                 returnMap.put("code", -1);
                 returnMap.put("message", "创建广告组异常");
@@ -1713,7 +1722,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
      * @param requestJson
      */
     @Override
-    public Map<String, Object> creativeCreate(String accessToken, Long advertiserId, JSONObject requestJson) {
+    public Map<String, Object> creativeCreate(String accessToken, Long advertiserId, JSONObject requestJson, Integer count) {
         Map<String, Object> returnMap = new HashMap<>();
         try {
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.AD_CREATIVE_CREATE;
@@ -1750,13 +1759,20 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                         returnMap.put("success", true);
                     }
                 } else {
-                    log.error("创建广告创意失败,advertiser_id:{},返回信息:{},入参:{}", advertiserId, resultJson, requestJson);
+                    if (code == 500000 && count <= 4) {
+                        creativeCreate(accessToken, advertiserId, requestJson, count + 1);
+                    }
+                    log.error("创建广告创意失败,advertiser_id:{},返回信息:{},入参:{}", advertiserId, resultJson, requestJson, count + 1);
                     returnMap.put("code", -1);
                     returnMap.put("message", resultJson.getString("message"));
                     returnMap.put("desc", "创意创建失败");
                     returnMap.put("success", false);
                 }
             } else {
+                if (count <= 4) {
+                    creativeCreate(accessToken, advertiserId, requestJson, count + 1);
+                }
+
                 log.error("快手创建广告创意返回内容为空,advertiser_id:{},入参:{}", advertiserId, requestJson);
                 returnMap.put("code", -1);
                 returnMap.put("message", "上传图片异常");
@@ -2892,7 +2908,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 }
                 var kuaiShouVideoGet = JSONObject.toJavaObject(detailJson, KuaiShouVideoGet.class);
                 Date videoTime = videoTimeService.getVideoTime(kuaiShouVideoGet.getPhotoId(), accountId);
-                if(!Check.isNull(videoTime)){
+                if (!Check.isNull(videoTime)) {
                     kuaiShouVideoGet.setUploadDate(videoTime);
                 }
                 kuaiShouVideoGet.setAccountId(accountId);