|
@@ -8,13 +8,16 @@ import io.swagger.annotations.ApiModelProperty;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.client.ClientProtocolException;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.modules.ctop.entity.*;
|
|
|
import org.jeecg.modules.ctop.mapper.*;
|
|
|
+import org.jeecg.modules.ctop.service.IByteDanceAdvertisePlanService;
|
|
|
import org.jeecg.modules.ctop.service.IByteDanceAdvertiserDataService;
|
|
|
import org.jeecg.modules.ctop.service.ICtopOauthTokenService;
|
|
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
|
@@ -25,9 +28,9 @@ import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.TreeMap;
|
|
|
+import java.net.URI;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author 宋英豪
|
|
@@ -98,55 +101,54 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
- private void getAdvertiserPlanByPageNumber(String accountId, Integer pageNumber, String ids) {
|
|
|
- CtopOauthToken cTopOauthToken = tokenService.getOauthTokenByAccountId(accountId);
|
|
|
- //2: 根据token以及用户id获取用户信息数据
|
|
|
- String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_get");
|
|
|
- Map<String, String> headers = new HashMap<>();
|
|
|
- headers.put("Content-Type", "application/json");
|
|
|
- headers.put("Access-Token", cTopOauthToken.getAccessToken());
|
|
|
-
|
|
|
- TreeMap<String, Object> params = new TreeMap<>();
|
|
|
- params.put("advertiser_id", cTopOauthToken.getAccountId());
|
|
|
- params.put("page", pageNumber + "");
|
|
|
- JSONObject filtering = new JSONObject();
|
|
|
- if (null != ids && !"".equals(ids.trim())) {
|
|
|
- String[] idsArray = ids.split(",");
|
|
|
- JSONArray filterIdsArray = new JSONArray();
|
|
|
- for (int i = 0; i < idsArray.length; i++) {
|
|
|
- Long id = Long.parseLong(idsArray[i]);
|
|
|
- filterIdsArray.add(id);
|
|
|
+ public void getAd(String accountId, int pageNum, String ids) {
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId);
|
|
|
+ String[] idString = ids.split(",");
|
|
|
+ JSONArray getIds = new JSONArray();
|
|
|
+ if (null != idString && idString.length > 0) {
|
|
|
+ for (int i = 0; i < idString.length; i++) {
|
|
|
+ Long getId = Long.parseLong(idString[i]);
|
|
|
+ getIds.add(getId);
|
|
|
}
|
|
|
- filtering.put("ids", filterIdsArray);
|
|
|
}
|
|
|
- params.put("filtering", filtering.toJSONString());
|
|
|
|
|
|
- String result = HttpUtils.httpGetRequest(url, headers, params);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- Integer code = jsonObject.getInteger("code");
|
|
|
+ // 请求地址
|
|
|
+ String url = "https://ad.toutiao.com/open_api/2/ad/get/";
|
|
|
+ // 请求参数
|
|
|
+ Map<String, Object> filtering = new HashMap<>();
|
|
|
+ filtering.put("ids", getIds);
|
|
|
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
+ param.put("page", pageNum);
|
|
|
+ param.put("page_size", 100);
|
|
|
+ param.put("filtering", filtering);
|
|
|
+
|
|
|
+ JSONObject resultObject = HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, param);
|
|
|
+ Integer code = resultObject.getInteger("code");
|
|
|
if (null == code || !code.equals(0)) {
|
|
|
- log.error("获取广告计划信息接口异常==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
|
|
|
+ log.error("获取广告计划信息接口异常==》accountId:{},message:{}", accountId, resultObject.getString("message"));
|
|
|
return;
|
|
|
}
|
|
|
- JSONArray data = jsonObject.getJSONObject("data").getJSONArray("list");
|
|
|
+ JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
|
|
|
if (null == data || data.size() <= 0) {
|
|
|
- log.error("获取广告计划信息不存在==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
|
|
|
+ log.error("获取广告计划信息不存在==》accountId:{},message:{}", accountId, resultObject.getString("message"));
|
|
|
return;
|
|
|
}
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
JSONObject dataObject = data.getJSONObject(i);
|
|
|
+ System.out.println(dataObject.toJSONString());
|
|
|
ByteDanceAdvertisePlan advertisePlan = new ByteDanceAdvertisePlan(dataObject, accountId);
|
|
|
//清除清数据,插入新数据
|
|
|
advertisePlanMapper.deleteById(advertisePlan.getId());
|
|
|
advertisePlanMapper.insert(advertisePlan);
|
|
|
}
|
|
|
- getAdvertiserPlanByPageNumber(accountId, pageNumber + 1, ids);
|
|
|
+ getAd(accountId, pageNum + 1, ids);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> getAdvertiserPlan(String accountId, String ids) {
|
|
|
- getAdvertiserPlanByPageNumber(accountId, 1, ids);
|
|
|
+ getAd(accountId, 1, ids);
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
resultMap.put("code", 0);
|
|
|
resultMap.put("message", "获取广告计划信息成功");
|
|
@@ -628,6 +630,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public JSONObject updateAd(CtopOauthToken token, Long adId, ByteDanceUserOrientationTemplate template) {
|
|
|
|
|
|
// 请求地址
|
|
@@ -636,12 +639,26 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.put("advertiser_id", token.getAccountId());
|
|
|
data.put("ad_id", adId);
|
|
|
- data = setUserOrentationData(data, template);
|
|
|
+ data = setUserOrentationData(data, template, adId);
|
|
|
return HttpUtils.bytedancePostRequest(token.getAccessToken(), url, data);
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceAdvertisePlanService advertisePlanService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject setUserOrentationData(JSONObject data, ByteDanceUserOrientationTemplate template, Long adId) {
|
|
|
+ //根据adId获取公告计划信息
|
|
|
+ ByteDanceAdvertisePlan advertisePlan = advertisePlanService.getById(adId);
|
|
|
+ data.put("modify_time", advertisePlan.getModifyTime());
|
|
|
+ data = setUserOrentationData(data, template);
|
|
|
+ System.out.println(data.toJSONString());
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public JSONObject setUserOrentationData(JSONObject data, ByteDanceUserOrientationTemplate template) {
|
|
|
+ //根据adId获取公告计划信息
|
|
|
if (null != template.getGender() && !"".equals(template.getGender().trim())) {
|
|
|
data.put("gender", template.getGender());
|
|
|
}
|
|
@@ -676,7 +693,8 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
data.put("activate_type", activateTypeArray);
|
|
|
}
|
|
|
if (null != template.getPlatform() && !"".equals(template.getPlatform().trim())) {
|
|
|
- JSONArray platformArray = JSONArray.parseArray(template.getPlatform());
|
|
|
+ JSONArray platformArray = new JSONArray();
|
|
|
+ platformArray.add(template.getPlatform());
|
|
|
data.put("platform", platformArray);
|
|
|
}
|
|
|
if (null != template.getCity() && !"".equals(template.getCity().trim())) {
|
|
@@ -743,12 +761,13 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
|
|
|
JSONArray excludeFlowPackageArray = JSONArray.parseArray(template.getExcludeFlowPackage());
|
|
|
data.put("exclude_flow_package", excludeFlowPackageArray);
|
|
|
}
|
|
|
+ if (null != template.getAutoExtendEnabled() && !"".equals(template.getAutoExtendEnabled().trim())) {
|
|
|
+ data.put("auto_extend_enabled", template.getAutoExtendEnabled());
|
|
|
+ }
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
private void getAdvertiserCreativeByPageNumber(String accountId, Integer pageNumber, String ids) {
|
|
|
CtopOauthToken cTopOauthToken = tokenService.getOauthTokenByAccountId(accountId);
|
|
|
//2: 根据token以及用户id获取用户信息数据
|