|
@@ -1,6 +1,11 @@
|
|
package cn.com.ctop.kuaishou.modules.report.controller;
|
|
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 cn.com.ctop.kuaishou.modules.report.service.IDuanJUReportService;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
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.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -71,6 +77,21 @@ public class DuanJUReportController {
|
|
return Result.error("查询失败");
|
|
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")
|
|
@GetMapping("/getViodeoList")
|
|
public Result<Object> getViodeoList(String startDate, String endDate) {
|
|
public Result<Object> getViodeoList(String startDate, String endDate) {
|
|
try {
|
|
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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|