|
@@ -3,9 +3,11 @@ package cn.com.ctop.kuaishou.modules.ai.controller;
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouCreateService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -28,6 +30,8 @@ public class KuaiShouCreateController {
|
|
|
private IKuaishouInterfaceService iKuaishouInterfaceService;
|
|
|
@Autowired
|
|
|
private IKuaiShouCampaignService campaignService;
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouCreateService kuaiShouCreateService;
|
|
|
|
|
|
/**
|
|
|
* 创建计划
|
|
@@ -98,32 +102,24 @@ public class KuaiShouCreateController {
|
|
|
JSONObject result = new JSONObject();
|
|
|
try {
|
|
|
Long accountId = requestJson.getLong("account_id");
|
|
|
+ if (Check.isNull(accountId)) {
|
|
|
+ throw new Exception("请填写账户id进行创建");
|
|
|
+ }
|
|
|
CtopOauthToken oauthToken = tokenService.getTokenByAccountId(accountId);
|
|
|
if (Check.isNull(oauthToken)) {
|
|
|
throw new Exception("未获取到账户信息");
|
|
|
}
|
|
|
- JSONObject campaignJson = new JSONObject();
|
|
|
-
|
|
|
- campaignJson.put("campaign_name", requestJson.getString("campaign_name"));
|
|
|
- campaignJson.put("type", requestJson.getInteger("type"));
|
|
|
|
|
|
- if (!Check.isNull(requestJson.getLong("day_budget"))) {
|
|
|
- campaignJson.put("day_budget", requestJson.getLong("day_budget"));
|
|
|
+ Long campaign_id = requestJson.getLong("campaign_id");
|
|
|
+ if (Check.isNull(campaign_id)) {
|
|
|
+ throw new Exception("请填写需要创建的计划id");
|
|
|
}
|
|
|
- if (!Check.isNull(requestJson.getJSONArray("day_budget_schedule"))) {
|
|
|
- campaignJson.put("day_budget_schedule", requestJson.getJSONArray("day_budget_schedule"));
|
|
|
+ JSONArray group_list = requestJson.getJSONArray("group_list");
|
|
|
+ if (Check.isNull(group_list)) {
|
|
|
+ throw new Exception("请填写需要创建的组信息");
|
|
|
}
|
|
|
- Map<String, Object> campaignMap = iKuaishouInterfaceService.campaignCreate(oauthToken.getAccessToken(), accountId, campaignJson);
|
|
|
- Integer code = (Integer) campaignMap.get("code");
|
|
|
- if (code != 0) {
|
|
|
- throw new Exception((String) campaignMap.get("message"));
|
|
|
- }
|
|
|
- result.put("code", 0);
|
|
|
- result.put("message", "SUCCESS");
|
|
|
- JSONObject data = new JSONObject();
|
|
|
- data.put("campaign_id", campaignMap.get("campaignId"));
|
|
|
- data.put("account_id", requestJson.getLong("account_id"));
|
|
|
- result.put("data", data);
|
|
|
+ kuaiShouCreateService.createUnitAndCreative(oauthToken, campaign_id, group_list);
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
result.put("code", -1);
|