yumeng vor 9 Monaten
Ursprung
Commit
9e30c1f623

+ 1 - 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -263,6 +263,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/ctop/byteDanceVideoInfo/*", "anon");
         filterChainDefinitionMap.put("/first/delivery/*", "anon");
         filterChainDefinitionMap.put("/budget/**", "anon");
+        filterChainDefinitionMap.put("/duanju/report/**", "anon");
 
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);

+ 102 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/DuanJUReportController.java

@@ -1,6 +1,11 @@
 package cn.com.ctop.kuaishou.modules.report.controller;
 
+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.kuaishou.modules.report.service.IDuanJUReportService;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
@@ -11,6 +16,7 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -71,6 +77,21 @@ public class DuanJUReportController {
         return Result.error("查询失败");
     }
 
+    @GetMapping("/stopList")
+    public Result<Object> stopList(Long accountId) {
+        try {
+
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("accountId", accountId);
+
+            List<JSONObject> data = duanJUReportService.stopList(requestMap);
+            return Result.OK(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
     @GetMapping("/getViodeoList")
     public Result<Object> getViodeoList(String startDate, String endDate) {
         try {
@@ -88,4 +109,85 @@ public class DuanJUReportController {
     }
 
 
+    @GetMapping("/stopPlan")
+    public Result<Object> stopPlan(Long accountId) {
+        try {
+
+            if (Check.isNull(accountId)) {
+                throw new Exception("请传入账户ID");
+            }
+            String token = duanJUReportService.getAgentToken(165893351L);
+            getPlan(accountId, token, 1);
+            return Result.OK();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
+    /*   @GetMapping("/getPlan")*/
+    public void getPlan(Long accountId, String token, Integer page) {
+        String url = "https://ad.e.kuaishou.com/rest/openapi/gw/dsp/campaign/list";
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", token);
+        headers.put("Content-Type", " application/json");
+        JSONObject param = new JSONObject();
+        param.put("advertiser_id", accountId);
+        param.put("page", page);
+        param.put("page_size", 500);
+        param.put("status", 4);
+
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (Check.isNull(resultJson)) {
+            log.error("获取广告计划信息返回结果异常,advertiserId:{}", accountId);
+            return;
+        }
+        Integer code = resultJson.getInteger("code");
+        if (null == code || code != 0) {
+            log.error("获取广告计划信息返回结果异常,advertiserId:{},异常信息:{}", accountId, resultJson);
+            return;
+        }
+        JSONObject dataJson = resultJson.getJSONObject("data");
+        JSONArray details = dataJson.getJSONArray("details");
+        List<JSONObject> adds = new ArrayList<>();
+        if (!Check.isNull(details)) {
+            for (int i = 0; i < details.size(); i++) {
+                JSONObject addJson = new JSONObject();
+                JSONObject planInfo = details.getJSONObject(i);
+                String campaignName = planInfo.getString("campaign_name");
+                Long campaignId = planInfo.getLong("campaign_id");
+                addJson.put("accountId", accountId);
+                addJson.put("campaignId", campaignId);
+                addJson.put("campaignName", campaignName);
+                String updateUrl = "https://ad.e.kuaishou.com/rest/openapi/v1/campaign/update/status";
+                JSONObject updateParam = new JSONObject();
+                updateParam.put("advertiser_id", accountId);
+                updateParam.put("put_status", 2);
+                updateParam.put("campaign_id", campaignId);
+                String updateResult = HttpUtils.kuaiShouhttpPostRequest(updateUrl, updateParam.toJSONString(), headers);
+                JSONObject updateJson = JSONObject.parseObject(updateResult);
+                if (!Check.isNull(updateJson)) {
+                    addJson.put("updateMessage", "暂停失败,返回为空");
+                }
+                Integer code1 = updateJson.getInteger("code");
+                if (code1 == 0) {
+                    addJson.put("updateMessage", "暂停成功");
+                } else {
+                    addJson.put("updateMessage", "暂停失败," + updateJson.getString("message"));
+                }
+                adds.add(addJson);
+            }
+        }
+
+        if (!Check.isNull(adds)) {
+            duanJUReportService.replaceDatas(adds);
+        }
+
+        if (details.size() >= 500) {
+            getPlan(accountId, token, page + 1);
+        }
+
+    }
+
 }

+ 7 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/DuanJUReportMapper.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.kuaishou.modules.report.mapper;
 
 import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
@@ -13,4 +14,10 @@ public interface DuanJUReportMapper {
     List<JSONObject> getDuanJuList(Map<String, Object> requestMap);
 
     List<JSONObject> getViodeoList(Map<String, Object> requestMap);
+
+    String getAgentToken(@Param("appId") Long appId);
+
+    void replaceDatas(@Param("adds") List<JSONObject> adds);
+
+    List<JSONObject> stopList(Map<String, Object> requestMap);
 }

+ 29 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/DuanJUReportMapper.xml

@@ -1,6 +1,24 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.kuaishou.modules.report.mapper.DuanJUReportMapper">
+    <insert id="replaceDatas" >
+        replace into kuaishou_duanju_stop_plan(
+        account_id,
+        campaign_id,
+        campaign_name,
+        update_message
+        )
+        values
+        <foreach collection="adds" item="add" separator=",">
+            (
+            #{add.accountId},
+            #{add.campaignId},
+            #{add.campaignName},
+            #{add.updateMessage}
+            )
+        </foreach>
+
+    </insert>
 
 
     <select id="getTotalCharge" resultType="com.alibaba.fastjson.JSONObject">
@@ -82,4 +100,15 @@
               GROUP BY photo_id) t
         ORDER BY t.charge DESC
     </select>
+    <select id="getAgentToken" resultType="java.lang.String" parameterType="java.lang.Long">
+        SELECT access_token
+        FROM ctop_oauth_agent_token
+        WHERE app_id = #{appId}
+    </select>
+    <select id="stopList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT account_id AS 'accountId', campaign_id AS 'campaignId', campaign_name AS 'campaignName', update_message AS 'updateMessage', CAST(create_time AS char) AS 'createTime'
+        FROM kuaishou_duanju_stop_plan
+        WHERE account_id = #{accountId}
+        ORDER BY create_time DESC
+    </select>
 </mapper>

+ 6 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IDuanJUReportService.java

@@ -13,4 +13,10 @@ public interface IDuanJUReportService {
     List<JSONObject> getDuanJuList(Map<String, Object> requestMap);
 
     List<JSONObject> getViodeoList(Map<String, Object> requestMap);
+
+    String getAgentToken(Long appId);
+
+    void replaceDatas(List<JSONObject> adds);
+
+    List<JSONObject> stopList(Map<String, Object> requestMap);
 }

+ 15 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/DuanJUReportServiceImpl.java

@@ -33,4 +33,19 @@ public class DuanJUReportServiceImpl implements IDuanJUReportService {
     public List<JSONObject> getViodeoList(Map<String, Object> requestMap) {
         return duanJUReportMapper.getViodeoList(requestMap);
     }
+
+    @Override
+    public String getAgentToken(Long appId) {
+        return duanJUReportMapper.getAgentToken(appId);
+    }
+
+    @Override
+    public void replaceDatas(List<JSONObject> adds) {
+        duanJUReportMapper.replaceDatas(adds);
+    }
+
+    @Override
+    public List<JSONObject> stopList(Map<String, Object> requestMap) {
+        return duanJUReportMapper.stopList(requestMap);
+    }
 }