Forráskód Böngészése

Merge remote-tracking branch 'origin/master'

syh 5 éve
szülő
commit
7f0dfe1fc9
22 módosított fájl, 572 hozzáadás és 105 törlés
  1. 0 48
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AuthController.java
  2. 2 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/BindAccountAuthController.java
  3. 5 8
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java
  4. 21 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java
  5. 4 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/RefreshTokenServiceImpl.java
  6. 3 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysUserController.java
  7. 4 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/CtopOauthToken.java
  8. 1 1
      module-common/src/main/java/cn/com/ctop/common/module/service/IBindAccountAuthService.java
  9. 2 1
      module-common/src/main/java/cn/com/ctop/common/module/service/ICtopOauthTokenService.java
  10. 22 8
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/BindAccountAuthServiceImpl.java
  11. 9 3
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/CtopOauthTokenServiceImpl.java
  12. 31 0
      module-common/src/main/java/cn/com/ctop/common/module/utils/RandomUtil.java
  13. 47 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java
  14. 1 7
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouController.java
  15. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroup.java
  16. 2 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouGroupMapper.xml
  17. 11 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IBatchService.java
  18. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java
  19. 387 10
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java
  20. 14 7
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java
  21. 2 2
      module-kuaishou/src/main/resources/kuaishou_config.properties
  22. 2 0
      moudule-eureca/src/main/java/cn/com/ctop/eureca/server/ServerApplication.java

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

@@ -1,48 +0,0 @@
-package org.jeecg.modules.ctop.controller;
-
-import cn.com.ctop.common.module.service.IBindAccountAuthService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.UUID;
-
-/**
- * TODO 可以删除
- */
-@Controller
-@RequestMapping("/auth")
-public class AuthController {
-    private static final Logger logger = LoggerFactory.getLogger(AuthController.class);
-
-    @Autowired
-    private IBindAccountAuthService bindAccountAuthService;
-
-
-    @RequestMapping("/begin")
-    public String authBegin(HttpServletRequest request,
-                            HttpServletResponse response,
-                            @RequestParam("auth_type") String authType) {
-        try {
-            String codeUrl = "";
-            switch (authType) {
-                case "bytedance":
-                    codeUrl = bindAccountAuthService.getByteDanceCodeUrl(UUID.randomUUID().toString());
-                    return "redirect:" + codeUrl;
-                case "kuaishou":
-                    codeUrl = bindAccountAuthService.getKuaishouCodeUrl(UUID.randomUUID().toString());
-                    return "redirect:" + codeUrl;
-                default:
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        return "auth_error";
-    }
-}

+ 2 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/BindAccountAuthController.java

@@ -69,9 +69,10 @@ public class BindAccountAuthController {
             }
 
             String authorizationType = json.getString("authorizationType");
+            Integer agentType = json.getInteger("agentType"); // 0 三方代理商 1 本代理商
 
             if ("kuaishou".equals(authorizationType)) {
-                codeUrl = bindAccountAuthService.getKuaishouCodeUrl(JSONObject.toJSONString(json));
+                codeUrl = bindAccountAuthService.getKuaishouCodeUrl(JSONObject.toJSONString(json), agentType);
             }
             if ("bytedance".equals(authorizationType)) {
                 codeUrl = bindAccountAuthService.getByteDanceCodeUrl(JSONObject.toJSONString(json));

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

@@ -16,13 +16,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.apache.commons.lang.StringUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.constant.CommonConstant;
-import org.jeecg.common.system.api.ISysBaseApi;
 import org.jeecg.common.system.util.JwtUtil;
 import org.jeecg.common.util.RedisUtil;
 import org.jeecg.modules.system.entity.SysDepart;
 import org.jeecg.modules.system.entity.SysUser;
 import org.jeecg.modules.system.service.ISysDepartService;
-import org.jeecg.modules.system.service.ISysLogService;
 import org.jeecg.modules.system.service.ISysUserService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -48,10 +46,7 @@ public class CallbackController {
     private static final Logger logger = LoggerFactory.getLogger(CallbackController.class);
     @Autowired
     private ISysUserService sysUserService;
-    @Autowired
-    private ISysBaseApi sysBaseApi;
-    @Autowired
-    private ISysLogService logService;
+
     @Autowired
     private RedisUtil redisUtil;
     @Autowired
@@ -132,8 +127,10 @@ public class CallbackController {
             if (Check.isNull(json)) {
                 throw new Exception("回调信息为空");
             }
+            logger.info("快手授权返回信息:{}", json);
+            Integer agentType = json.getInteger("agentType");
             if (StringUtils.isNotBlank(authCode)) {
-                KuaishouResultToken accessToken = kuaishouInterfaceService.getAccessToken(authCode);
+                KuaishouResultToken accessToken = kuaishouInterfaceService.getAccessToken(authCode, agentType);
                 if (accessToken.getCode() != 0) {
                     throw new Exception("快手回调token返回错误");
                 }
@@ -144,7 +141,6 @@ public class CallbackController {
                         return "授权绑定失败!";
                     }
 
-
                     String advertiserId = json.getString("advertiserId");
                     //指定分配人姓名
                     String userName = json.getString("userName");
@@ -164,6 +160,7 @@ public class CallbackController {
                     topOauthToken.setAccountId(accountId);
                     topOauthToken.setMediaId("2");
                     topOauthToken.setAdvertiserId(advertiserId);
+                    topOauthToken.setAgentType(agentType);
                     topOauthToken.setAccessToken(token.getAccessToken());
                     long accessTokenExpireIn = token.getAccessTokenExpiresIn() * 1000L;
                     long now = System.currentTimeMillis();

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

@@ -86,6 +86,27 @@ public class TestController {
     private IKuaishouInterfaceService kuaishouInterfaceService;
 
 
+    @GetMapping(value = "/createTask")
+    public String createTask(Long accountId) {
+        Result<String> result = new Result<String>();
+        try {
+            QueryWrapper<CtopOauthToken> oauthTokenQueryWrapper = new QueryWrapper<>();
+            oauthTokenQueryWrapper.eq("media_id", 2);
+            oauthTokenQueryWrapper.eq("account_id", accountId);
+            oauthTokenQueryWrapper.last("limit 1");
+            CtopOauthToken token = oauthTokenMapper.selectOne(oauthTokenQueryWrapper);
+            String endDateStr = DateUtils.getDate("yyyy-MM-dd");
+            String startDate = DateUtils.addMonth(endDateStr, -6);
+            historyReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), startDate, endDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_HISTORY);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+        }
+        return "success";
+    }
+
+
     @GetMapping(value = "/getHistoryData")
     public String getHistoryData() {
         Result<String> result = new Result<String>();

+ 4 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/RefreshTokenServiceImpl.java

@@ -1,10 +1,10 @@
 package org.jeecg.modules.ctop.service.impl;
 
-import cn.com.ctop.common.module.utils.Check;
-import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.CtopAdConstant;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.modules.ctop.service.IRefreshTokenService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +22,7 @@ public class RefreshTokenServiceImpl implements IRefreshTokenService {
 
     /**
      * 获取所有token
+     *
      * @return
      */
     @Override
@@ -36,7 +37,7 @@ public class RefreshTokenServiceImpl implements IRefreshTokenService {
                 }
                 //快手
                 if (CtopAdConstant.PLATFORM_TYPE_KUAISHOU.equals(oauthToken.getMediaId().trim())) {
-                    oauthTokenService.getKuaiShouRefreshToken(oauthToken.getAccountId(), oauthToken.getRefreshToken());
+                    oauthTokenService.getKuaiShouRefreshToken(oauthToken.getAccountId(), oauthToken.getRefreshToken(), oauthToken.getAgentType());
                 }
             }
         } else {

+ 3 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysUserController.java

@@ -112,7 +112,7 @@ public class SysUserController {
     public Result<List<SysUserVo>> getAllUserListByCompany(String userId) {
         Result<List<SysUserVo>> result = new Result<>();
         try {
-            List<SysUserVo> userList = new ArrayList<>();
+            /*List<SysUserVo> userList = new ArrayList<>();
             String roleCode = materialReportMapper.getRoleCodeByUserId(userId);
             if (!"admin".equals(roleCode)) {
                 QueryWrapper<UserCompany> userCompanyQueryWrapper = new QueryWrapper<>();
@@ -124,7 +124,8 @@ public class SysUserController {
             } else {
                 userList = sysUserService.getAllUser();
             }
-
+*/
+            List<SysUserVo> userList = sysUserService.getAllUser();
             result.setSuccess(true);
             result.setResult(userList);
         } catch (Exception e) {

+ 4 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/CtopOauthToken.java

@@ -73,6 +73,10 @@ public class CtopOauthToken {
     @Excel(name = "刷新令牌", width = 15)
     @ApiModelProperty(value = "刷新令牌")
     private String refreshToken;
+
+
+    private Integer agentType;
+
     /**
      * 刷新令牌有效期
      */

+ 1 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/IBindAccountAuthService.java

@@ -20,7 +20,7 @@ public interface IBindAccountAuthService extends IService<BindAccountAuth> {
      * @return
      * @throws UnsupportedEncodingException
      */
-    String getKuaishouCodeUrl(String state) throws UnsupportedEncodingException;
+    String getKuaishouCodeUrl(String state,Integer  agentType ) throws UnsupportedEncodingException;
 
     /**
      * 获取头条url

+ 2 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/ICtopOauthTokenService.java

@@ -2,6 +2,7 @@ package cn.com.ctop.common.module.service;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import com.baomidou.mybatisplus.extension.service.IService;
+import io.swagger.models.auth.In;
 
 import java.util.List;
 import java.util.Map;
@@ -20,7 +21,7 @@ public interface ICtopOauthTokenService extends IService<CtopOauthToken> {
 
     Map<String, Object> getByteDanceAccessToken(String accountId);
 
-    Map<String, Object> getKuaiShouRefreshToken(Long accountId, String refreshToken);
+    Map<String, Object> getKuaiShouRefreshToken(Long accountId, String refreshToken, Integer agentType);
 
     List<CtopOauthToken> getTokenListByType(String platformTypeBytedance);
 

+ 22 - 8
module-common/src/main/java/cn/com/ctop/common/module/service/impl/BindAccountAuthServiceImpl.java

@@ -6,7 +6,6 @@ import cn.com.ctop.common.module.service.IBindAccountAuthService;
 import cn.com.ctop.common.module.utils.BytedanceInterfaceConstant;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
-import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -57,20 +56,35 @@ public class BindAccountAuthServiceImpl extends ServiceImpl<BindAccountAuthMappe
 
 
     @Override
-    public String getKuaishouCodeUrl(String state) throws UnsupportedEncodingException {
+    public String getKuaishouCodeUrl(String state, Integer agentType) throws UnsupportedEncodingException {
         StringBuffer sb = new StringBuffer();
-        sb.append(PropertiesUtils.getValue("kuaishou_config", "kuaishou_auth_url"))
-                .append(KuaishouInterfaceConstant.AUTH_PATH)
-                .append("?app_id=" + PropertiesUtils.getValue("kuaishou_config", "kuaishou_appid"))
-                .append("&state=" + URLEncoder.encode(URLEncoder.encode(state)))
-                .append("&scope=%5B%22report_service%22%2C%22ad_query%22%2C%22account_service%22%2C%22ad_manage%22%5D")
-                .append("&redirect_uri=" + URLEncoder.encode(PropertiesUtils.getValue("kuaishou_config", "kuaishou_callback_url"), "UTF-8"));
+        if (agentType == 1) {
+            sb.append(PropertiesUtils.getValue("kuaishou_config", "kuaishou_auth_url"))
+                    .append(KuaishouInterfaceConstant.AUTH_PATH)
+                    .append("?app_id=" + PropertiesUtils.getValue("kuaishou_config", "kuaishou_appid"))
+                    .append("&state=" + URLEncoder.encode(URLEncoder.encode(state)))
+                    .append("&scope=%5B%22report_service%22%2C%22ad_query%22%2C%22account_service%22%2C%22ad_manage%22%5D")
+                    .append("&redirect_uri=" + URLEncoder.encode(PropertiesUtils.getValue("kuaishou_config", "kuaishou_callback_url"), "UTF-8"));
+        } else if (agentType == 0) {
+
+            // &scope=%5B%22ad_query%22%2C%22ad_manage%22%5D&
+            // &scope=%5B%22report_service%22%2C%22ad_query%22%2C%22account_service%22%2C%22ad_manage%22%5D
+            sb.append(PropertiesUtils.getValue("kuaishou_config", "kuaishou_auth_url"))
+                    .append(KuaishouInterfaceConstant.AUTH_PATH)
+                    .append("?app_id=" + PropertiesUtils.getValue("kuaishou_config", "kuaishou_third_appid"))
+                    .append("&state=" + URLEncoder.encode(URLEncoder.encode(state)))
+                    .append("&scope=%5B%22ad_query%22%2C%22ad_manage%22%5D&")
+                    .append("&redirect_uri=" + URLEncoder.encode(PropertiesUtils.getValue("kuaishou_config", "kuaishou_callback_url"), "UTF-8"));
+        }
+
         return sb.toString();
     }
 
     @Override
     public String getByteDanceCodeUrl(String state) throws UnsupportedEncodingException {
         StringBuffer sb = new StringBuffer();
+
+
         sb.append(PropertiesUtils.getValue("bytedance_config", "bytedance_auth_url"))
                 .append(BytedanceInterfaceConstant.AUTH_PATH)
                 .append("?app_id=" + PropertiesUtils.getValue("bytedance_config", "bytedance_appid"))

+ 9 - 3
module-common/src/main/java/cn/com/ctop/common/module/service/impl/CtopOauthTokenServiceImpl.java

@@ -102,13 +102,19 @@ public class CtopOauthTokenServiceImpl extends ServiceImpl<CtopOauthTokenMapper,
      * @return
      */
     @Override
-    public Map<String, Object> getKuaiShouRefreshToken(Long accountId, String refreshToken) {
+    public Map<String, Object> getKuaiShouRefreshToken(Long accountId, String refreshToken, Integer agentType) {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + "/rest/openapi/oauth2/authorize/refresh_token";
         Map<String, String> headers = new HashMap<String, String>();
         headers.put("Content-Type", " application/json");
         Map<String, Object> param = new HashMap<String, Object>();
-        param.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
-        param.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
+        if (agentType == 1) {
+            param.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
+            param.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
+        } else if (agentType == 0) {
+            param.put("app_id", PropertiesUtils.getConfig("kuaishou_third_appid"));
+            param.put("secret", PropertiesUtils.getConfig("kuaishou_third_secret"));
+        }
+
         param.put("refresh_token", refreshToken);
         try {
             String result = HttpUtils.httpPostRequest(url, param, headers);

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

@@ -0,0 +1,31 @@
+package cn.com.ctop.common.module.utils;
+
+import java.util.Random;
+
+public class RandomUtil {
+
+    public static String verifyCode() {
+
+        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";
+        String S = s.toUpperCase();
+        String word = s + S + i;
+        char[] c = word.toCharArray();
+
+        return c;
+    }
+
+}

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

@@ -1523,4 +1523,51 @@ public class BatchController {
         return result;
     }
 
+
+    @PostMapping(value = "/batchCopyUnit")
+    public Result<JSONObject> batchCopyUnit(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("入参为空");
+            }
+            JSONArray unitIds = requestJson.getJSONArray("unitIds");
+            if (Check.isNull(unitIds)) {
+                throw new Exception("请选择需要修改的广告组");
+            }
+            Long accountId = requestJson.getLong("accountId");
+            Long campaignId = requestJson.getLong("campaignId");
+            Long copyToCampaignId = requestJson.getLong("copyToCampaignId");
+            JSONObject returnJson = new JSONObject();
+            JSONArray failArr = new JSONArray();
+            for (int i = 0; i < unitIds.size(); i++) {
+                Long unitId = unitIds.getLong(i);
+                if (Check.isNull(unitId)) {
+                    continue;
+                }
+                JSONObject unitJson = batchService.copyUnit(accountId, campaignId, unitId, copyToCampaignId);
+                if (!Check.isNull(unitJson)) {
+                    Integer code = unitJson.getInteger("code");
+                    if (code != 0) {
+                        JSONObject failJson = new JSONObject();
+                        failJson.put("message", unitJson.get("message"));
+                        failJson.put("unitName", unitJson.get("unitName"));
+                        failArr.add(failJson);
+                    }
+                }
+                Thread.sleep(200);
+            }
+            returnJson.put("totalCount", unitIds.size());
+            returnJson.put("failCount", failArr.size());
+            returnJson.put("failInfo", failArr);
+            result.setSuccess(true);
+            result.setResult(returnJson);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
 }

+ 1 - 7
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouController.java

@@ -101,17 +101,11 @@ public class KuaiShouController {
         kuaishouInterfaceService.getAppList(advertiserId, accessToken);
 
     }
-    
+
 
     @Autowired
     private ICtopOauthTokenService tokenService;
 
-    @RequestMapping("/test")
-    public void test() throws IOException {
-        tokenService.getKuaiShouRefreshToken(23212L, "b51ce96a098299b04fa6cb70617e653d");
-
-    }
-
     @RequestMapping("report")
     public Map<String, Object> getReport(String accountId, String startDate, String endDate, Integer type, String temporalGranularity) {
         Map<String, Object> result = new HashMap<>();

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroup.java

@@ -130,7 +130,7 @@ public class KuaiShouGroup {
      */
     @Excel(name = "创意展现方式  0:未知, 1:轮播,", width = 15)
     @ApiModelProperty(value = "创意展现方式  0:未知, 1:轮播,")
-    private Integer showModel;
+    private Integer showMode;
     private Integer unitType;
     /**
      * url类型

+ 2 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouGroupMapper.xml

@@ -24,7 +24,7 @@
         end_time,
         schedule_time,
         scene_id,
-        show_model,
+        show_mode,
         unit_type,
         url_type,
         url,
@@ -59,7 +59,7 @@
             #{getGroup.endTime},
             #{getGroup.scheduleTime},
             #{getGroup.sceneId},
-            #{getGroup.showModel},
+            #{getGroup.showMode},
             #{getGroup.unitType},
             #{getGroup.urlType},
             #{getGroup.url},

+ 11 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IBatchService.java

@@ -59,6 +59,17 @@ public interface IBatchService {
      */
     JSONObject createUnit(JSONObject requestJson) throws Exception;
 
+    /**
+     * 批量复制广告组
+     *
+     * @param accountId
+     * @param campaignId
+     * @param unitId
+     * @param copyToCampaignId
+     * @return
+     */
+    JSONObject copyUnit(Long accountId, Long campaignId, Long unitId, Long copyToCampaignId);
+
 
     /**
      * 获取广告组信息

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

@@ -171,7 +171,7 @@ public interface IKuaishouInterfaceService {
      * @param authCode
      * @return
      */
-    KuaishouResultToken getAccessToken(String authCode);
+    KuaishouResultToken getAccessToken(String authCode,Integer agentType);
 
 
     /**

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

@@ -5,13 +5,12 @@ import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.RandomUtil;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
-import cn.com.ctop.kuaishou.modules.batch.mapper.BatchMapper;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCampaignMapper;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCreativeMapper;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroupTarget;
+import cn.com.ctop.kuaishou.modules.batch.mapper.*;
 import cn.com.ctop.kuaishou.modules.batch.service.IBatchService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
@@ -25,6 +24,7 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 @Slf4j
@@ -144,19 +144,27 @@ public class BatchServiceImpl implements IBatchService {
 
     @Override
     public JSONObject createUnit(JSONObject requestJson) throws Exception {
+        System.err.println(requestJson);
         Long accountId = requestJson.getLong("accountId");
         CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
         if (Check.isNull(oauthToken)) {
             throw new Exception("未获取到账户信息");
         }
 
+        JSONObject unitJson = new JSONObject();
+        String type = requestJson.getString("type");
+
         Long campaignId = requestJson.getLong("campaignId");
         if (Check.isNull(campaignId)) {
             throw new Exception("请选择广告计划");
         }
+        Long copyToCampaignId = requestJson.getLong("copyToCampaignId");
+        if (!Check.isNull(type) && "copy".equals(type)) {
+            unitJson.put("campaign_id", copyToCampaignId);
+        } else {
+            unitJson.put("campaign_id", campaignId);
+        }
 
-        JSONObject unitJson = new JSONObject();
-        unitJson.put("campaign_id", campaignId);
 
         // 资源位置
         JSONArray scene_id = requestJson.getJSONArray("sceneId");
@@ -310,8 +318,6 @@ public class BatchServiceImpl implements IBatchService {
         }
 
         unitJson.put("target", targetJson);
-
-
         JSONArray groupArr = requestJson.getJSONArray("groupArr");
         if (Check.isNull(groupArr)) {
             throw new Exception("请输入需要创建的广告组");
@@ -324,9 +330,11 @@ public class BatchServiceImpl implements IBatchService {
         JSONArray successArr = new JSONArray();
         JSONArray failArr = new JSONArray();
 
+
         for (int i = 0; i < groupArr.size(); i++) {
             JSONObject groupJson = groupArr.getJSONObject(i);
             if (!Check.isNull(groupJson)) {
+
                 // 出价
                 if (!Check.isNull(groupJson.getLong("bid"))) {
                     unitJson.put("bid", groupJson.getLong("bid"));
@@ -355,7 +363,7 @@ public class BatchServiceImpl implements IBatchService {
                 }
                 String unitName = groupJson.getString("unitName");
                 if (!Check.isNull(unitName)) {
-                    unitJson.put("unit_name", unitName);
+                    unitJson.put("unit_name", unitName + RandomUtil.verifyCode());
                 }
 
                 Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), accountId, unitJson);
@@ -363,11 +371,29 @@ public class BatchServiceImpl implements IBatchService {
                     Integer code = (Integer) returnUnitMap.get("code");
                     if (code == 0) {
                         JSONObject successJson = new JSONObject();
-                        successJson.put("unitId", returnUnitMap.get("unitId"));
+                        Long unitId = (Long) returnUnitMap.get("unitId");
+
+                        successJson.put("unitId", unitId);
                         successJson.put("unitName", unitName);
                         successJson.put("sceneId", scene_id);
                         successJson.put("ocpxActionType", ocpx_action_type);
                         successArr.add(successJson);
+                        if (!Check.isNull(type) && "copy".equals(type)) {
+                            Long copyUnitId = requestJson.getLong("copyUnitId");
+                            if (!Check.isNull(unitId) && !Check.isNull(copyUnitId)) {
+                                Thread thread = new Thread() {
+                                    @Override
+                                    public void run() {
+                                        try {
+                                            copyCreative(accountId, unitId, copyUnitId);
+                                        } catch (Exception e) {
+                                            e.printStackTrace();
+                                        }
+                                    }
+                                };
+                                thread.start();
+                            }
+                        }
                     } else {
                         JSONObject failJson = new JSONObject();
                         failJson.put("unitName", unitName);
@@ -386,6 +412,357 @@ public class BatchServiceImpl implements IBatchService {
         return returnJson;
     }
 
+
+    /**
+     * 复制组
+     *
+     * @param
+     * @throws Exception
+     */
+
+    @Autowired
+    private KuaiShouGroupTargetMapper targetMapper;
+
+
+    @Override
+    public JSONObject copyUnit(Long accountId, Long campaignId, Long unitId, Long copyToCampaignId) {
+        JSONObject returnJson = new JSONObject();
+
+        try {
+
+            QueryWrapper<KuaiShouGroup> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("account_id", accountId);
+            queryWrapper.eq("unit_id", unitId);
+            KuaiShouGroup group = groupMapper.selectOne(queryWrapper);
+            if (Check.isNull(group)) {
+                throw new Exception("未获取到广告组信息");
+
+            }
+
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到token信息");
+            }
+
+            JSONObject unitJson = new JSONObject();
+
+            unitJson.put("campaign_id", copyToCampaignId);
+
+            // 资源位置
+            JSONArray scene_id = JSONArray.parseArray(group.getSceneId());
+            if (!Check.isNull(scene_id)) {
+                unitJson.put("scene_id", scene_id);
+            }
+
+            // 资源创作方式
+            if (!Check.isNull(group.getUnitType())) {
+                if (!Check.isNull(group.getUnitType())) {
+                    unitJson.put("unit_type", group.getUnitType());
+                }
+
+                //投放开始时间
+                if (!Check.isNull(group.getBeginTime())) {
+                    unitJson.put("begin_time", group.getBeginTime());
+                }
+                // 投放结束时间
+                if (!Check.isNull(group.getEndTime())) {
+                    unitJson.put("end_time", group.getEndTime());
+                }
+                // 投放时间段
+                if (!Check.isNull(group.getScheduleTime())) {
+                    unitJson.put("schedule_time", group.getScheduleTime());
+                }
+                // 广告组单日预算
+                if (!Check.isNull(group.getDayBudget())) {
+                    unitJson.put("day_budget", group.getDayBudget());
+                }
+                // url类型
+                if (!Check.isNull(group.getUrlType())) {
+                    unitJson.put("url_type", group.getUrlType());
+                }
+                // url
+                if (!Check.isNull(group.getUrl())) {
+                    unitJson.put("url", group.getUrl());
+                }
+                // appId
+                if (!Check.isNull(group.getAppId())) {
+                    unitJson.put("app_id", group.getAppId());
+                }
+                // 创意展现方式
+                if (!Check.isNull(group.getShowMode())) {
+                    unitJson.put("show_mode", group.getShowMode());
+                }
+                if (!Check.isNull(group.getSpeed())) {
+                    unitJson.put("speed", group.getSpeed());
+                }
+
+
+                QueryWrapper<KuaiShouGroupTarget> targetQueryWrapper = new QueryWrapper<>();
+                targetQueryWrapper.eq("account_id", accountId);
+                targetQueryWrapper.eq("unit_id", unitId);
+                targetQueryWrapper.last("limit 1");
+                KuaiShouGroupTarget groupTarget = targetMapper.selectOne(targetQueryWrapper);
+                if (!Check.isNull(groupTarget)) {
+                    // -----------------用户定向-----------
+                    JSONObject targetJson = new JSONObject();
+
+                    // 地域
+                    if (!Check.isNull(groupTarget.getRegion())) {
+                        targetJson.put("region", JSONArray.parseArray(groupTarget.getRegion()));
+                    }
+
+                    // 自定义年龄段
+                    Integer ageMin = groupTarget.getAgeMin();
+                    Integer ageMax = groupTarget.getAgeMax();
+
+
+                    JSONObject ageJson = new JSONObject();
+                    if (!Check.isNull(ageMin)) {
+                        ageJson.put("min", ageMin);
+                    }
+                    if (!Check.isNull(ageMax)) {
+                        ageJson.put("max", ageMax);
+                    }
+
+                    targetJson.put("age", ageJson);
+
+                    // 固定年龄段
+                    if (!Check.isNull(groupTarget.getAgesRange())) {
+                        targetJson.put("ages_range", JSONArray.parseArray(groupTarget.getAgesRange()));
+                    }
+                    // 性别
+                    if (!Check.isNull(groupTarget.getGender())) {
+                        targetJson.put("gender", groupTarget.getGender());
+                    }
+                    //操作系统
+                    if (!Check.isNull(groupTarget.getPlatformOs())) {
+                        targetJson.put("platform_os", groupTarget.getPlatformOs());
+                    }
+                    //Android版本
+                    if (!Check.isNull(groupTarget.getAndroidOsv())) {
+                        targetJson.put("android_osv", groupTarget.getAndroidOsv());
+                    }
+                    // iOS版本
+                    if (!Check.isNull(groupTarget.getIosOsv())) {
+                        targetJson.put("ios_osv", groupTarget.getIosOsv());
+                    }
+                    //网络环境
+                    if (!Check.isNull(groupTarget.getNetwork())) {
+                        targetJson.put("network", groupTarget.getNetwork());
+                    }
+                    //设备品牌
+                    if (!Check.isNull(groupTarget.getDeviceBrand())) {
+                        targetJson.put("device_brand", JSONArray.parseArray(groupTarget.getDeviceBrand()));
+                    }
+                    //设备价格
+                    if (!Check.isNull(groupTarget.getDevicePrice())) {
+                        targetJson.put("device_price", JSONArray.parseArray(groupTarget.getDevicePrice()));
+                    }
+                    //商业兴趣类型
+                    if (!Check.isNull(groupTarget.getBusinessInterestType())) {
+                        targetJson.put("business_interest_type", groupTarget.getBusinessInterestType());
+                    }
+                    // 商业兴趣
+                    if (!Check.isNull(groupTarget.getBusinessInterest())) {
+                        targetJson.put("business_interest", JSONArray.parseArray(groupTarget.getBusinessInterest()));
+                    }
+                    //网红粉丝
+                    if (!Check.isNull(groupTarget.getFansStar())) {
+                        targetJson.put("fans_star", JSONArray.parseArray(groupTarget.getFansStar()));
+                    }
+                    //兴趣视频用户
+                    if (!Check.isNull(groupTarget.getInterestVideo())) {
+                        targetJson.put("interest_video", JSONArray.parseArray(groupTarget.getInterestVideo()));
+                    }
+                    // APP行为-按分类
+                    if (!Check.isNull(groupTarget.getAppInterest())) {
+                        targetJson.put("app_interest", JSONArray.parseArray(groupTarget.getAppInterest()));
+                    }
+                    // APP行为-按APP名称
+                    if (!Check.isNull(groupTarget.getAppIds())) {
+                        targetJson.put("app_ids", groupTarget.getAppIds());
+                    }
+                    // 人群包定向
+                    if (!Check.isNull(groupTarget.getPopulation())) {
+                        targetJson.put("population", JSONArray.parseArray(groupTarget.getPopulation()));
+                    }
+                    // 人群包排除
+                    if (!Check.isNull(groupTarget.getExcludePopulation())) {
+                        targetJson.put("exclude_population", JSONArray.parseArray(groupTarget.getExcludePopulation()));
+                    }
+
+                    JSONObject intelliExtendJson = new JSONObject();
+
+                    // 开启智能扩量
+                    if (!Check.isNull(groupTarget.getIsOpen())) {
+                        intelliExtendJson.put("is_open", groupTarget.getIsOpen());
+                    }
+                    //不可突破年龄
+                    if (!Check.isNull(groupTarget.getNoAgeBreak())) {
+                        intelliExtendJson.put("no_age_break", groupTarget.getNoAgeBreak());
+                    }
+                    //不可突破性别
+                    if (!Check.isNull(groupTarget.getNoGenderBreak())) {
+                        intelliExtendJson.put("no_gender_break", groupTarget.getNoGenderBreak());
+                    }
+                    // 不可突破地域
+                    if (!Check.isNull(groupTarget.getNoAreaBreak())) {
+                        intelliExtendJson.put("no_area_break", groupTarget.getNoAreaBreak());
+                    }
+                    if (!Check.isNull(intelliExtendJson)) {
+                        targetJson.put("intelli_extend", intelliExtendJson);
+                    }
+
+                    unitJson.put("target", targetJson);
+                }
+
+
+                // 出价
+                if (!Check.isNull(group.getBid())) {
+                    unitJson.put("bid", group.getBid());
+                }
+                // 出价类型
+                Integer bidType = group.getBidType();
+                if (!Check.isNull(bidType)) {
+                    unitJson.put("bid_type", bidType);
+                }
+                // 深度转化出价
+                if (!Check.isNull(group.getCpaBid())) {
+                    unitJson.put("cpa_bid", group.getCpaBid());
+                }
+                // 深度转化目标出价
+                if (!Check.isNull(group.getDeepConversionBid())) {
+                    unitJson.put("deep_conversion_bid", group.getDeepConversionBid());
+                }
+                // 深度转化目标
+                if (!Check.isNull(group.getDeepConversionType())) {
+                    unitJson.put("deep_conversion_type", group.getDeepConversionType());
+                }
+                // 优化目标
+                Integer ocpx_action_type = group.getOcpxActionType();
+                if (!Check.isNull(ocpx_action_type)) {
+                    unitJson.put("ocpx_action_type", ocpx_action_type);
+                }
+                String unitName = group.getUnitName();
+                if (!Check.isNull(unitName)) {
+                    if (campaignId == copyToCampaignId) {
+                        unitJson.put("unit_name", unitName + RandomUtil.verifyCode());
+                    } else {
+                        unitJson.put("unit_name", unitName);
+                    }
+                }
+
+                Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), accountId, unitJson);
+                if (!Check.isNullMap(returnUnitMap)) {
+                    Integer code = (Integer) returnUnitMap.get("code");
+                    if (code == 0) {
+                        Long copyUnitId = (Long) returnUnitMap.get("unitId");
+                        returnJson.put("unitId", copyUnitId);
+
+                        returnJson.put("unitName", unitName);
+                        returnJson.put("code", 0);
+                        Thread thread = new Thread() {
+                            @Override
+                            public void run() {
+                                try {
+                                    copyCreative(accountId, unitId, copyUnitId);
+                                } catch (Exception e) {
+                                    e.printStackTrace();
+                                }
+                            }
+                        };
+                        thread.start();
+                    } else {
+                        returnJson.put("code", -1);
+                        returnJson.put("unitName", unitJson.getString("unitName"));
+                        returnJson.put("message", returnUnitMap.get("message"));
+                    }
+
+                } else {
+                    returnJson.put("code", -1);
+                    returnJson.put("message", "快手接口返回数据为空");
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
+
+        return returnJson;
+
+    }
+
+
+    /**
+     * 复制创意
+     *
+     * @param accountId
+     * @param unitId
+     */
+    private void copyCreative(Long accountId, Long unitId, Long copyUnitId) throws Exception {
+        // 查询当前复制组下的所有非程序化创意
+
+        QueryWrapper<KuaiShouCreative> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("account_id", accountId);
+        queryWrapper.eq("unit_id", copyUnitId);
+        //   queryWrapper.eq("status", 52);
+        List<KuaiShouCreative> creativeList = creativeMapper.selectList(queryWrapper);
+        if (!Check.isNull(creativeList)) {
+            for (KuaiShouCreative creative : creativeList) {
+                if (Check.isNull(creative.getPhotoId())) {
+                    continue;
+                }
+                CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+                if (Check.isNull(oauthToken)) {
+                    throw new Exception("未获取到账户信息");
+                }
+                JSONObject creativeJson = new JSONObject();
+                creativeJson.put("advertiser_id", accountId);
+                creativeJson.put("unit_id", unitId);
+
+                // 素材类型
+                if (!Check.isNull(creative.getCreativeMaterialType())) {
+                    creativeJson.put("creative_material_type", creative.getCreativeMaterialType());
+                }
+                String action_bar_text = creative.getActionBarText();
+                // 视频id
+                String click_track_url = creative.getClickTrackUrl();
+                JSONArray successArr = new JSONArray();
+                JSONArray failArr = new JSONArray();
+                String description = creative.getDescription();
+                String photo_id = creative.getPhotoId();
+                String image = creative.getImageToken();
+                String name = creative.getCreativeName();
+                creativeJson.put("action_bar_text", action_bar_text);
+                creativeJson.put("description", description);
+                creativeJson.put("image_token", image);
+                creativeJson.put("creative_name", name + RandomUtil.verifyCode());
+                creativeJson.put("photo_id", photo_id);
+                creativeJson.put("click_track_url", click_track_url);
+
+                Map<String, Object> returnCreativeMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson);
+                if (!Check.isNullMap(returnCreativeMap)) {
+                    Integer code = (Integer) returnCreativeMap.get("code");
+                    if (code == 0) {
+                        JSONObject successJson = new JSONObject();
+                        successJson.put("creativeName", name);
+                        successArr.add(successJson);
+                    } else {
+                        JSONObject failJson = new JSONObject();
+                        failJson.put("creativeName", name);
+                        failJson.put("failMessage", returnCreativeMap.get("message"));
+                        failArr.add(failJson);
+                    }
+                }
+
+
+            }
+
+
+        }
+    }
+
     /**
      * 获取广告组信息
      *

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

@@ -871,11 +871,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             //1: 获取广告主信息数据
             getAdvertiserReportHourly(token, getStartDate, getStartDate);
             //2:获取广告计划信息数据
-            getAdvertiserCampaignReportHourly(token, getStartDate, getStartDate);
+            // getAdvertiserCampaignReportHourly(token, getStartDate, getStartDate);
             //3:获取广告组信息数据
-            getAdvertiserGroupReportHourly(token, getStartDate, getStartDate);
+            // getAdvertiserGroupReportHourly(token, getStartDate, getStartDate);
             //4: 获取广告创意信息数据
-            getAdvertiserCreativeReportHourly(token, getStartDate, getStartDate);
+            // getAdvertiserCreativeReportHourly(token, getStartDate, getStartDate);
         }
         //获取全量广告计划数据
         getCampaignList(token, null, null);
@@ -1268,7 +1268,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     group.setEndTime(detail.getString("end_time"));
                     group.setScheduleTime(detail.getString("schedule_time"));
                     group.setSceneId(detail.getJSONArray("scene_id") + "");
-                    group.setShowModel(detail.getInteger("show_mode"));
+                    group.setShowMode(detail.getInteger("show_mode"));
                     group.setUnitType(detail.getInteger("unit_type"));
                     group.setUrlType(detail.getInteger("url_type"));
                     group.setUrl(detail.getString("url"));
@@ -1685,12 +1685,19 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
      * @return
      */
     @Override
-    public KuaishouResultToken getAccessToken(String authCode) {
+    public KuaishouResultToken getAccessToken(String authCode, Integer agentType) {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.AUTH_TOKEN;
         JSONObject requestJson = new JSONObject();
         requestJson.put("auth_code", authCode);
-        requestJson.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
-        requestJson.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
+
+        if (agentType == 1) { // 本代理商开户
+            requestJson.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
+            requestJson.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
+        } else if (agentType == 0) {
+            requestJson.put("app_id", PropertiesUtils.getConfig("kuaishou_third_appid"));
+            requestJson.put("secret", PropertiesUtils.getConfig("kuaishou_third_secret"));
+        }
+
 
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", " application/json");

+ 2 - 2
module-kuaishou/src/main/resources/kuaishou_config.properties

@@ -1,11 +1,11 @@
 kuaishou_api_url=https://ad.e.kuaishou.com
 kuaishou_auth_url=https://ad.e.kuaishou.com
 kuaishou_appid=27
+kuaishou_third_appid=328
 oauth_type=agent
 kuaishou_secret=QovprB1tNhXptgDc
+kuaishou_third_secret=1iFTBiMdohkyEQQs
 kuaishou_callback_url=http://adsp.c-top.com.cn:8080/jeecg-boot/kuaishou
-
-
 apk_sava_path=/mnt/file/apk
 image_sava_path=/mnt/file/image
 video_sava_path=/mnt/file/video

+ 2 - 0
moudule-eureca/src/main/java/cn/com/ctop/eureca/server/ServerApplication.java

@@ -1,3 +1,4 @@
+/*
 package cn.com.ctop.eureca.server;
 
 import org.springframework.boot.SpringApplication;
@@ -12,3 +13,4 @@ public class ServerApplication {
         SpringApplication.run(ServerApplication.class, args);
     }
 }
+*/