浏览代码

修改广告创意

yumeng 5 年之前
父节点
当前提交
ebf2863125

+ 6 - 1
module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java

@@ -119,7 +119,12 @@ public class KuaishouInterfaceConstant {
     /**
      * 快手-广告主信息
      */
-    public static final String ADVERTISER_INFO = "//rest/openapi/v1/advertiser/info";
+    public static final String ADVERTISER_INFO = "/rest/openapi/v1/advertiser/info";
+
+    /**
+     * 修改广告创意
+     */
+    public static final String UPDATE_CREATIVE = "/rest/openapi/v2/creative/update";
 
 
     /**

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

@@ -1,7 +1,14 @@
 package cn.com.ctop.kuaishou.modules.batch.controller;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCreativeMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
 import cn.com.ctop.kuaishou.modules.batch.service.IMaterialRefuseService;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -17,6 +24,12 @@ import java.util.Map;
 public class MaterialRefuseController {
     @Autowired
     private IMaterialRefuseService materialRefuseService;
+    @Autowired
+    private CtopOauthTokenMapper oauthTokenMapper;
+    @Autowired
+    private IKuaiShouUpdateService updateService;
+    @Autowired
+    private KuaiShouCreativeMapper creativeMapper;
 
 
     @PostMapping(value = "/getRefuseCreative")
@@ -31,9 +44,60 @@ public class MaterialRefuseController {
             e.printStackTrace();
         }
 
-
         return map;
     }
 
+    @PostMapping(value = "/updateCreative")
+    public Map<String, Object> updateCreative(@RequestBody JSONObject jsonObject) {
+        Map<String, Object> map = new HashMap<>();
+        if (Check.isNull(jsonObject)) {
+            map.put("code", -1);
+            map.put("message", "入参为空");
+            return map;
+        }
+
+        Long accountId = jsonObject.getLong("accountId");
+        QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("account_id", accountId);
+        queryWrapper.eq("media_id", 2);
+        queryWrapper.orderByDesc("create_time");
+        queryWrapper.last("limit 1");
+        CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(queryWrapper);
+        if (Check.isNull(ctopOauthToken)) {
+            map.put("code", -1);
+            map.put("message", "未获取授权信息");
+            return map;
+        }
+
+        Map<String, Object> creativeMap = updateService.updateCreative(ctopOauthToken.getAccessToken(), accountId, jsonObject);
+        if (Check.isNullMap(creativeMap)) {
+            map.put("code", -1);
+            map.put("message", "修改失败,返回为空");
+            return map;
+
+        }
+
+        if ((Integer) creativeMap.get("code") != 0) {
+            map.put("code", -1);
+            map.put("message", creativeMap.get("message"));
+            return map;
+        }
+
+        QueryWrapper<KuaiShouCreative> creativeQueryWrapper = new QueryWrapper<>();
+        creativeQueryWrapper.eq("account_id", accountId);
+        creativeQueryWrapper.eq("creative_id", jsonObject.getString("creativeId"));
+        creativeQueryWrapper.eq("unit_id", jsonObject.getString("unitId"));
+        creativeQueryWrapper.eq("campaign_id", jsonObject.getString("campaignId"));
+        int i = creativeMapper.delete(creativeQueryWrapper);
+        if (i > 0) {
+            map.put("code", 0);
+            map.put("message", "重审成功");
+            return map;
+        }
+
+
+        return null;
+    }
+
 
 }

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

@@ -1,5 +1,7 @@
 package cn.com.ctop.kuaishou.modules.batch.service;
 
+import com.alibaba.fastjson.JSONObject;
+
 import java.util.Map;
 
 public interface IKuaiShouUpdateService {
@@ -73,4 +75,15 @@ public interface IKuaiShouUpdateService {
      */
     Map<String, Object> updateCreativeStatus(String token, Long advertiserId, Long creativeId, int putStatus, String loginId);
 
+
+    /**
+     * 修改创意
+     *
+     * @param token
+     * @param advertiserId
+     * @param requestJson
+     * @return
+     */
+    Map<String, Object> updateCreative(String token, Long advertiserId, JSONObject requestJson);
+
 }

+ 62 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouUpdateServiceImpl.java

@@ -421,4 +421,66 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
 
         return returnMap;
     }
+
+
+    /**
+     * 修改创意
+     *
+     * @param token
+     * @param advertiserId
+     * @param requestJson
+     * @return
+     */
+    @Override
+    public Map<String, Object> updateCreative(String token, Long advertiserId, JSONObject requestJson) {
+        Map<String, Object> returnMap = new HashMap<>();
+        try {
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.UPDATE_CREATIVE;
+            Map<String, String> header = new HashMap<>();
+            header.put("Access-Token", token);
+            header.put("Content-Type", "application/json");
+            JSONObject params = new JSONObject();
+
+
+            String creativeId = requestJson.getString("creativeId");
+            String creativeName = requestJson.getString("creativeName");
+            String description = requestJson.getString("description");
+
+
+            params.put("advertiser_id", advertiserId);
+            params.put("creative_id", creativeId);
+            params.put("creative_name", creativeName);
+            params.put("description", description);
+            String result = HttpUtils.httpPostRequest(url, params, header);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            System.err.println("返回结果: " + resultJson);
+            if (!Check.isNull(resultJson)) {
+                Integer code = resultJson.getInteger("code");
+                if (code == 0) {
+                    returnMap.put("code", 0);
+                    returnMap.put("success", true);
+                    returnMap.put("message", "修改成功");
+                } else {
+                    log.error("修改广告创意状态失败,advertiserId:{},creativeId:{},返回信息:{}", advertiserId, creativeId, resultJson);
+                    returnMap.put("code", -1);
+                    returnMap.put("success", false);
+                    returnMap.put("message", resultJson.getString("message"));
+                }
+            } else {
+                log.error("修改广告创意返回结果为空,advertiserId:{},creativeId:{}", advertiserId, creativeId);
+                returnMap.put("code", -1);
+                returnMap.put("success", false);
+                returnMap.put("message", "修改广告组预算返回结果为空");
+            }
+
+        } catch (Exception e) {
+            log.error("修改广告创意异常,advertiserId:{}", advertiserId);
+            e.printStackTrace();
+            returnMap.put("code", -1);
+            returnMap.put("success", false);
+            returnMap.put("message", "修改广告创意异常");
+        }
+
+        return returnMap;
+    }
 }