|
@@ -1,11 +1,24 @@
|
|
|
package cn.com.ctop.toutiao.modules.material.service.impl;
|
|
|
|
|
|
+import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
+import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
+import cn.com.ctop.common.module.utils.PropertiesUtils;
|
|
|
+import cn.com.ctop.common.module.utils.ResultMapUtils;
|
|
|
+import cn.com.ctop.common.module.utils.StatusCode;
|
|
|
import cn.com.ctop.toutiao.modules.material.entity.ByteDanceCampaign;
|
|
|
import cn.com.ctop.toutiao.modules.material.mapper.ByteDanceCampaignMapper;
|
|
|
import cn.com.ctop.toutiao.modules.material.service.IByteDanceCampaignService;
|
|
|
+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.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 今日头条广告组信息
|
|
|
* @Author: jeecg-boot
|
|
@@ -14,6 +27,126 @@ import org.springframework.stereotype.Service;
|
|
|
*/
|
|
|
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignMapper, ByteDanceCampaign> implements IByteDanceCampaignService {
|
|
|
+ @Override
|
|
|
+ /**
|
|
|
+ * 获取广告组数据
|
|
|
+ */
|
|
|
+ public List<ByteDanceCampaign> getGroupListByParams(CtopOauthToken token, JSONArray ids, String campaignName, String landingType, String status, String campaignCreateTime, Integer page, Integer pageSize) {
|
|
|
+ List<ByteDanceCampaign> campaigns = new ArrayList<>();
|
|
|
+ // 请求地址
|
|
|
+ String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_get");
|
|
|
+ // 请求参数
|
|
|
+ JSONObject filtering = new JSONObject();
|
|
|
+ if(null!=ids&&!ids.isEmpty()){
|
|
|
+ filtering.put("ids",ids);
|
|
|
+ }
|
|
|
+ if(null!=campaignName&&!campaignName.equals("")){
|
|
|
+ filtering.put("campaign_name",campaignName);
|
|
|
+ }
|
|
|
+ if(null!=landingType&&!landingType.equals("")){
|
|
|
+ filtering.put("landing_type",landingType);
|
|
|
+ }
|
|
|
+ if(null!=status&&!status.equals("")){
|
|
|
+ filtering.put("status",status);
|
|
|
+ }
|
|
|
+ if(null!=campaignCreateTime&&!campaignCreateTime.equals("")){
|
|
|
+ filtering.put("campaign_create_time",landingType);
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("advertiser_id", token.getAccountId());
|
|
|
+ params.put("page", page);
|
|
|
+ params.put("page_size", pageSize);
|
|
|
+ params.put("filtering", filtering);
|
|
|
+ JSONObject result = HttpUtils.bytedanceGetRequest(token.getAccessToken(),url,params);
|
|
|
+ if(result == null){
|
|
|
+ log.error("获取广告组数据异常=>param:{}",params.toJSONString());
|
|
|
+ return campaigns;
|
|
|
+ }
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
+ String message = result.getString("message");
|
|
|
+ if(null == code||!code.equals(0)){
|
|
|
+ log.error("获取广告组数据异常=>{},param:{}",message,params.toJSONString());
|
|
|
+ return campaigns;
|
|
|
+ }
|
|
|
+ JSONArray dataList = result.getJSONObject("data").getJSONArray("list");
|
|
|
+ if(null == dataList||dataList.isEmpty()){
|
|
|
+ log.info("获取广告组数据为空=>param:{}",params.toJSONString());
|
|
|
+ return campaigns;
|
|
|
+ }
|
|
|
+ for(int i=0;i<dataList.size();i++){
|
|
|
+ JSONObject data = dataList.getJSONObject(i);
|
|
|
+ ByteDanceCampaign campaign = new ByteDanceCampaign(data,token.getAccountId());
|
|
|
+ this.saveOrUpdate(campaign);
|
|
|
+ campaigns.add(campaign);
|
|
|
+ }
|
|
|
+ return campaigns;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每个广告主账号下最多可允许创建500个广告组,如超出需要先删除一部分广告组后才可继续创建。
|
|
|
+ * @param token
|
|
|
+ * @param campaignName
|
|
|
+ * @param operation
|
|
|
+ * @param budgetMode
|
|
|
+ * @param budget
|
|
|
+ * @param landingType
|
|
|
+ * @param uniqueFk
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> createGroup(CtopOauthToken token, String campaignName, String operation, String budgetMode, String budget, String landingType, String uniqueFk) {
|
|
|
+ Map<String,Object>result = new HashMap<>();
|
|
|
+ // 请求地址
|
|
|
+ String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_create");
|
|
|
+ // 请求参数
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("advertiser_id",token.getAccountId());
|
|
|
+ param.put("campaign_name",campaignName);
|
|
|
+ if(null!=operation&&!operation.trim().equals("")){
|
|
|
+ param.put("operation",operation);
|
|
|
+ }
|
|
|
+ param.put("budget_mode", budgetMode);
|
|
|
+ if(null != budget&&!budget.trim().equals("")){
|
|
|
+ param.put("budget",budget);
|
|
|
+ }
|
|
|
+ param.put("landing_type", landingType);
|
|
|
+ if(null != uniqueFk&&!uniqueFk.trim().equals("")){
|
|
|
+ param.put("unique_fk",uniqueFk);
|
|
|
+ }
|
|
|
+ JSONObject data = HttpUtils.bytedancePostRequest(url,token.getAccessToken(),param);
|
|
|
+ if(data == null){
|
|
|
+ log.error("创建广告组异常=>param:{}",param.toJSONString());
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.BYTEDACNE_API_GROUP_CREATE_ERROR);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ Integer code = data.getInteger("code");
|
|
|
+ String message = data.getString("message");
|
|
|
+ if(null == code||!code.equals(0)){
|
|
|
+ log.error("获取广告组数据异常=>{},parmas:{}",message,param.toJSONString());
|
|
|
+ ResultMapUtils.setResultMap(result,-1,message,false);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ Long campaignId = data.getJSONObject("data").getLong("campaign_id");
|
|
|
+ ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);
|
|
|
+ result.put("campaign_id",campaignId);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> updateGroup(CtopOauthToken token, String campaignId, String campaignName, String modifyTime,String budget) {
|
|
|
+ // 请求地址
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/campaign/update/";
|
|
|
+ // 请求参数
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("advertiser_id",token.getAccountId());
|
|
|
+ data.put("campaign_name",campaignName);
|
|
|
+ data.put("budget",budget);
|
|
|
+ data.put("campaign_id", campaignId);
|
|
|
+ data.put("modify_time", modifyTime);
|
|
|
+ JSONObject result = HttpUtils.bytedancePostRequest(token.getAccessToken(),url,data);
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
}
|