zhaoxian пре 4 година
родитељ
комит
4840df9688

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

@@ -1,13 +1,16 @@
 package cn.com.ctop.kuaishou.modules.batch.service;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouAccountBudget;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 /**
  * 账户日预算
+ *
  * @author jeecg-boot
- * @date   2020-04-26
  * @version V1.0
+ * @date 2020-04-26
  */
 public interface IKuaishouAccountBudgetService extends IService<KuaishouAccountBudget> {
 
@@ -18,6 +21,8 @@ public interface IKuaishouAccountBudgetService extends IService<KuaishouAccountB
      * @param advertiserId
      * @param accessToken
      */
-    void getAccountBudget(Long advertiserId, String accessToken);
+    JSONObject getAccountBudget(CtopOauthToken oauthToken);
+
+    void insertAccountBudget(Long advertiserId, String accessToken);
 
 }

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

@@ -1,6 +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.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
@@ -10,21 +11,21 @@ import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouAccountBudgetMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouAccountBudgetService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
 /**
  * 账户日预算
+ *
  * @author jeecg-boot
- * @date   2020-04-26
  * @version V1.0
+ * @date 2020-04-26
  */
 @Slf4j
 @Service
@@ -37,12 +38,13 @@ public class KuaishouAccountBudgetServiceImpl extends ServiceImpl<KuaishouAccoun
 
     /**
      * 获取账户日预算结果
+     *
      * @param advertiserId
      * @param accessToken
      * @return
      */
     @Override
-    public void getAccountBudget(Long advertiserId, String accessToken) {
+    public void insertAccountBudget(Long advertiserId, String accessToken) {
         try {
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.ACCOUNT_BUDGET;
             Map<String, String> headers = new HashMap<>();
@@ -82,4 +84,28 @@ public class KuaishouAccountBudgetServiceImpl extends ServiceImpl<KuaishouAccoun
         }
 
     }
+
+    @Override
+    public JSONObject getAccountBudget(CtopOauthToken oauthToken) {
+        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.ACCOUNT_BUDGET;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", oauthToken.getAccessToken());
+        headers.put("Content-Type", "application/json");
+        JSONObject json = new JSONObject();
+        json.put("advertiser_id", oauthToken.getAccountId());
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, json.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                JSONObject dataJson = resultJson.getJSONObject("data");
+                if (!Check.isNull(dataJson)) {
+                    return dataJson;
+                }
+            } else {
+                log.error("获取账户日预算失败,返回信息:{}", resultJson);
+            }
+        }
+        return null;
+    }
 }