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

接入辅助探索接口

zhaoxian 4 éve
szülő
commit
e3ebd6337a

+ 4 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java

@@ -358,5 +358,9 @@ public class KuaishouInterfaceConstant {
      * 查询广告组的加速探索报表接口
      */
     public static final String QUERY_SPEED_EXPLORE_REPORT = "/rest/openapi/v1/report/speed_explore";
+  /**
+     * 辅助探索
+     */
+    public static final String AD_UNIT_EXPLORE_SUPPORT = "/rest/openapi/v1/ad_unit/explore/support";
 
 }

+ 16 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KuaishouGroupExploreController.java

@@ -118,6 +118,22 @@ public class KuaishouGroupExploreController {
         }
     }
 
+    /**
+     * 辅助探索
+     *
+     * @param data
+     * @return
+     */
+    @PostMapping(value = "/adUnitExploreSupport")
+    public Result<Object> adUnitExploreSupport(@RequestBody JSONObject data) {
+        try {
+            return kuaishouGroupExploreService.adUnitExploreSupport(data);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return Result.error("操作失败");
+        }
+    }
+
 
     /**
      * 添加

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKuaishouGroupExploreService.java

@@ -27,4 +27,6 @@ public interface IKuaishouGroupExploreService extends IService<KuaishouGroupExpl
     void unitOpenSpeedExplore(Long accountId, Long unitId, BigDecimal groupAccount,Long accountExploreId);
 
     void getReportByAccount(CtopOauthToken token);
+
+    Result<Object> adUnitExploreSupport(JSONObject data);
 }

+ 49 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouGroupExploreServiceImpl.java

@@ -2,12 +2,17 @@ package cn.com.ctop.kuaishou.modules.report.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.*;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.common.module.utils.StatusCode;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouGroupSpeedExploreLog;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouGroupSpeedExploreLogService;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouGroupExplore;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouGroupExploreMapper;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouGroupExploreService;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -226,7 +231,7 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
     }
 
     @Override
-    public void unitOpenSpeedExplore(Long accountId, Long unitId, BigDecimal groupAccount,Long accountExploreId) {
+    public void unitOpenSpeedExplore(Long accountId, Long unitId, BigDecimal groupAccount, Long accountExploreId) {
         KuaishouGroupSpeedExploreLog groupSpeedExploreLog = new KuaishouGroupSpeedExploreLog();
         groupSpeedExploreLog.setAccountExploreId(accountExploreId);
         groupSpeedExploreLog.setAccountId(accountId);
@@ -247,7 +252,7 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
                 String message = resultJson.getString("message");
                 groupSpeedExploreLog.setStatus(code);
                 groupSpeedExploreLog.setMessage(message);
-            }else{
+            } else {
                 groupSpeedExploreLog.setStatus(StatusCode.KUAISHOU_SPEED_EXPLORE_FAIL.getCode());
                 groupSpeedExploreLog.setMessage(StatusCode.KUAISHOU_SPEED_EXPLORE_FAIL.getDesc());
             }
@@ -264,5 +269,46 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
         //1:查询此账户下设置了加速探索的组
     }
 
+    @Override
+    public Result<Object> adUnitExploreSupport(JSONObject data) {
+        try {
+            Long accountId = data.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                return Result.error("请选择广告主");
+            }
+            JSONArray supportUnitIds = data.getJSONArray("supportUnitIds");
+            if (Check.isNull(supportUnitIds)) {
+                return Result.error("请填写辅助探索广告组集");
+            }
+            Long unitId = data.getLong("unitId");
+            if (Check.isNull(unitId)) {
+                return Result.error("请填写要设置辅助探索的广告组");
+            }
+            CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.AD_UNIT_EXPLORE_SUPPORT;
+            Map<String, String> header = new HashMap<>();
+            header.put("Access-Token", token.getAccessToken());
+            header.put("Content-Type", "application/json");
+            JSONObject params = new JSONObject();
+            params.put("advertiser_id", accountId);
+            params.put("support_unit_ids", supportUnitIds);
+            params.put("unit_id", unitId);
+            String result = HttpUtils.httpPostRequest(url, params, header);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            if (!Check.isNull(resultJson)) {
+                Integer code = resultJson.getInteger("code");
+                if (code == 0) {
+                    return Result.ok(resultJson.getJSONObject("data"));
+                } else {
+                    log.info("辅助探索失败,accountId:{},返回信息:{}", accountId, resultJson);
+                    return Result.error("辅助探索失败," + resultJson.getString("message"));
+                }
+            }
+        } catch (Exception e) {
+            log.error("辅助探索失败", e);
+        }
+        return Result.error("辅助探索失败");
+    }
+
 
 }