Browse Source

V1.1.3 定向模板修改

yumeng 4 years ago
parent
commit
107c76ac69

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

@@ -143,6 +143,31 @@ public class KuaishouTemplateController {
     }
 
 
+    @PostMapping(value = "/updateTemplate")
+    public Result<JSONObject> updateTemplate(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        try {
+
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请选择账户id");
+            }
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            JSONObject returnJson = kuaishouTemplateService.updateTemplate(accountId, oauthToken.getAccessToken(), requestJson);
+            result.setSuccess(true);
+            result.setResult(returnJson);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
     /**
      * 添加
      *

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

@@ -16,6 +16,5 @@ public interface IKuaishouTemplateService extends IService<KuaishouTemplate> {
 
     JSONObject createTemplate(Long accountId, String accessToken, JSONObject requestJson);
 
-
     JSONObject updateTemplate(Long accountId, String accessToken, JSONObject requestJson);
 }

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

@@ -46,6 +46,9 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
         JSONObject resultJson = JSONObject.parseObject(result);
         if (!Check.isNull(resultJson)) {
             Integer code = resultJson.getInteger("code");
+         /*   Map<String, Object> deleteMap = new HashMap<>();
+            deleteMap.put("account_id", accountId);
+            this.removeByMap(deleteMap);*/
             if (code == 0) {
                 JSONObject dataJson = resultJson.getJSONObject("data");
                 if (Check.isNull(dataJson)) {
@@ -344,14 +347,16 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
             if (Check.isNull(requestJson.getString("templateName"))) {
                 throw new Exception("定向模板名称为必传项");
             }
+            if (Check.isNull(requestJson.getLong("templateId"))) {
+                throw new Exception("定向模板id为必传项");
+            }
 
             JSONObject param = new JSONObject();
             param.put("template_id", requestJson.getLong("templateId"));
             param.put("advertiser_id", accountId);
-            if(!Check.isNull(requestJson.getString("templateName"))){
+            if (!Check.isNull(requestJson.getString("templateName"))) {
                 param.put("template_name", requestJson.getString("templateName"));
             }
-
             JSONObject targetJson = new JSONObject();
             if (!Check.isNull(requestJson.getJSONArray("region"))) {
                 targetJson.put("region", requestJson.getJSONArray("region"));
@@ -449,15 +454,12 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
             if (!Check.isNull(targetJson)) {
                 param.put("target", targetJson);
             }
-
             Map<String, String> headers = new HashMap<String, String>();
             headers.put("Access-Token", accessToken);
             headers.put("Content-Type", " application/json");
-            System.err.println("入参:" + param.toJSONString());
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_UPDATE;
             String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
             JSONObject resultJson = JSONObject.parseObject(result);
-            System.err.println("返回:" + resultJson.toJSONString());
             if (!Check.isNull(resultJson)) {
                 Integer code = resultJson.getInteger("code");
                 if (code == 0) {