|
@@ -1,14 +1,17 @@
|
|
package cn.com.ctop.toutiao.modules.material.service.impl;
|
|
package cn.com.ctop.toutiao.modules.material.service.impl;
|
|
|
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
|
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
import cn.com.ctop.common.module.utils.*;
|
|
import cn.com.ctop.common.module.utils.*;
|
|
import cn.com.ctop.toutiao.modules.material.entity.ByteDanceCampaign;
|
|
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.mapper.ByteDanceCampaignMapper;
|
|
import cn.com.ctop.toutiao.modules.material.service.IByteDanceCampaignService;
|
|
import cn.com.ctop.toutiao.modules.material.service.IByteDanceCampaignService;
|
|
|
|
+import cn.com.ctop.toutiao.modules.material.vo.BytedanceCampaignEditVo;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
@@ -24,9 +27,13 @@ import java.util.*;
|
|
@Service
|
|
@Service
|
|
@Slf4j
|
|
@Slf4j
|
|
public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignMapper, ByteDanceCampaign> implements IByteDanceCampaignService {
|
|
public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignMapper, ByteDanceCampaign> implements IByteDanceCampaignService {
|
|
|
|
+ @Autowired
|
|
|
|
+ private ByteDanceCampaignMapper campaignMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICtopOauthTokenService tokenService;
|
|
/**
|
|
/**
|
|
* 每个广告主账号下最多可允许创建500个广告组,如超出需要先删除一部分广告组后才可继续创建。
|
|
* 每个广告主账号下最多可允许创建500个广告组,如超出需要先删除一部分广告组后才可继续创建。
|
|
- * @param token
|
|
|
|
|
|
+ * @param accountId
|
|
* @param campaignName
|
|
* @param campaignName
|
|
* @param operation
|
|
* @param operation
|
|
* @param budgetMode
|
|
* @param budgetMode
|
|
@@ -36,8 +43,9 @@ public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignM
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public Map<String, Object> createCampaign(CtopOauthToken token, String campaignName, String operation, String budgetMode, String budget, String landingType, String uniqueFk) {
|
|
|
|
|
|
+ public Map<String, Object> createCampaign(Long accountId, String campaignName, String operation, String budgetMode, Integer budget, String landingType, String uniqueFk) {
|
|
Map<String,Object>result = new HashMap<>();
|
|
Map<String,Object>result = new HashMap<>();
|
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
|
|
// 请求地址
|
|
// 请求地址
|
|
String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_create");
|
|
String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_create");
|
|
// 请求参数
|
|
// 请求参数
|
|
@@ -48,14 +56,14 @@ public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignM
|
|
param.put("operation",operation);
|
|
param.put("operation",operation);
|
|
}
|
|
}
|
|
param.put("budget_mode", budgetMode);
|
|
param.put("budget_mode", budgetMode);
|
|
- if(null != budget&&!budget.trim().equals("")){
|
|
|
|
|
|
+ if(null != budget){
|
|
param.put("budget",budget);
|
|
param.put("budget",budget);
|
|
}
|
|
}
|
|
param.put("landing_type", landingType);
|
|
param.put("landing_type", landingType);
|
|
if(null != uniqueFk&&!uniqueFk.trim().equals("")){
|
|
if(null != uniqueFk&&!uniqueFk.trim().equals("")){
|
|
param.put("unique_fk",uniqueFk);
|
|
param.put("unique_fk",uniqueFk);
|
|
}
|
|
}
|
|
- JSONObject data = HttpUtils.bytedancePostRequest(url,token.getAccessToken(),param);
|
|
|
|
|
|
+ JSONObject data = HttpUtils.bytedancePostRequest(token.getAccessToken(),url,param);
|
|
if(data == null){
|
|
if(data == null){
|
|
log.error("创建广告组异常=>param:{}",param.toJSONString());
|
|
log.error("创建广告组异常=>param:{}",param.toJSONString());
|
|
ResultMapUtils.setResultMap(result, StatusCode.BYTEDACNE_API_GROUP_CREATE_ERROR);
|
|
ResultMapUtils.setResultMap(result, StatusCode.BYTEDACNE_API_GROUP_CREATE_ERROR);
|
|
@@ -68,14 +76,16 @@ public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignM
|
|
ResultMapUtils.setResultMap(result,-1,message,false);
|
|
ResultMapUtils.setResultMap(result,-1,message,false);
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
+ System.out.println(data.toJSONString());
|
|
Long campaignId = data.getJSONObject("data").getLong("campaign_id");
|
|
Long campaignId = data.getJSONObject("data").getLong("campaign_id");
|
|
|
|
+ this.getAdvertiserCampaign(token,null,null);
|
|
ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);
|
|
ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);
|
|
result.put("campaign_id",campaignId);
|
|
result.put("campaign_id",campaignId);
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Map<String, Object> updateCampaign(CtopOauthToken token, String campaignId, String campaignName,String budgetMode, String budget) {
|
|
|
|
|
|
+ public Map<String, Object> updateCampaign(CtopOauthToken token, Long campaignId, String campaignName,String budgetMode, Integer budget) {
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
ByteDanceCampaign campaign = this.getById(campaignId);
|
|
ByteDanceCampaign campaign = this.getById(campaignId);
|
|
//2: 根据token以及用户id获取用户信息数据
|
|
//2: 根据token以及用户id获取用户信息数据
|
|
@@ -100,7 +110,6 @@ public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignM
|
|
String result = HttpUtils.httpPostRequest(url, params, headers);
|
|
String result = HttpUtils.httpPostRequest(url, params, headers);
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
Integer code = jsonObject.getInteger("code");
|
|
Integer code = jsonObject.getInteger("code");
|
|
-
|
|
|
|
if (null == code || !code.equals(0)) {
|
|
if (null == code || !code.equals(0)) {
|
|
log.info("广告组更新接口异常==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
|
|
log.info("广告组更新接口异常==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
|
|
resultMap.put("code", -1);
|
|
resultMap.put("code", -1);
|
|
@@ -114,17 +123,7 @@ public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignM
|
|
resultMap.put("message", "广告组更新异常");
|
|
resultMap.put("message", "广告组更新异常");
|
|
return resultMap;
|
|
return resultMap;
|
|
}
|
|
}
|
|
- if (null != campaignName && !"".equals(campaignName.trim())) {
|
|
|
|
- campaign.setName(campaignName);
|
|
|
|
- }
|
|
|
|
- if (null != budgetMode && !"".equals(budgetMode.trim())) {
|
|
|
|
- params.put("budget_mode", budgetMode);
|
|
|
|
- campaign.setBudgetMode(budgetMode);
|
|
|
|
- }
|
|
|
|
- if (null != budget) {
|
|
|
|
- campaign.setBudget(new BigDecimal(budget));
|
|
|
|
- }
|
|
|
|
- this.updateById(campaign);
|
|
|
|
|
|
+ this.getAdvertiserCampaign(token,campaignId+"",null);
|
|
|
|
|
|
resultMap.put("code", 0);
|
|
resultMap.put("code", 0);
|
|
resultMap.put("message", "广告组信息修改成功");
|
|
resultMap.put("message", "广告组信息修改成功");
|
|
@@ -140,6 +139,19 @@ public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignM
|
|
return resultMap;
|
|
return resultMap;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> updateCampaign(BytedanceCampaignEditVo editVo) {
|
|
|
|
+ Map<String,Object>result = new HashMap<>();
|
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(editVo.getAccountId());
|
|
|
|
+ if(null == token){
|
|
|
|
+ ResultMapUtils.setResultMap(result,StatusCode.COMMON_PARAM_ERROR);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ this.getAdvertiserCampaign(token,editVo.getId()+"",null);
|
|
|
|
+ this.updateCampaign(token,editVo.getId(),editVo.getCampaignName(),editVo.getBudgetMode(),editVo.getBudget());
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
private void getAdvertiserCampaignByPageNumber(CtopOauthToken token, Integer pageNumber, String ids, String date) {
|
|
private void getAdvertiserCampaignByPageNumber(CtopOauthToken token, Integer pageNumber, String ids, String date) {
|
|
//2: 根据token以及用户id获取用户信息数据
|
|
//2: 根据token以及用户id获取用户信息数据
|
|
String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_get");
|
|
String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_get");
|
|
@@ -165,8 +177,8 @@ public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignM
|
|
params.put("filtering", filtering.toJSONString());
|
|
params.put("filtering", filtering.toJSONString());
|
|
params.put("advertiser_id", token.getAccountId());
|
|
params.put("advertiser_id", token.getAccountId());
|
|
params.put("page", pageNumber + "");
|
|
params.put("page", pageNumber + "");
|
|
|
|
+ params.put("page_size", 100);
|
|
String result = HttpUtils.httpGetRequest(url, headers, params);
|
|
String result = HttpUtils.httpGetRequest(url, headers, params);
|
|
- System.out.println(result);
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
Integer code = jsonObject.getInteger("code");
|
|
Integer code = jsonObject.getInteger("code");
|
|
if (null == code || !code.equals(0)) {
|
|
if (null == code || !code.equals(0)) {
|
|
@@ -175,20 +187,23 @@ public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignM
|
|
}
|
|
}
|
|
JSONArray data = jsonObject.getJSONObject("data").getJSONArray("list");
|
|
JSONArray data = jsonObject.getJSONObject("data").getJSONArray("list");
|
|
if (null == data || data.isEmpty()) {
|
|
if (null == data || data.isEmpty()) {
|
|
- log.error("获取广告组信息不存在==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ List<ByteDanceCampaign> campaigns = new ArrayList<>();
|
|
for (int i = 0; i < data.size(); i++) {
|
|
for (int i = 0; i < data.size(); i++) {
|
|
JSONObject dataObject = data.getJSONObject(i);
|
|
JSONObject dataObject = data.getJSONObject(i);
|
|
ByteDanceCampaign campaign = new ByteDanceCampaign(dataObject,token.getAccountId());
|
|
ByteDanceCampaign campaign = new ByteDanceCampaign(dataObject,token.getAccountId());
|
|
- this.saveOrUpdate(campaign);
|
|
|
|
|
|
+ campaigns.add(campaign);
|
|
}
|
|
}
|
|
|
|
+ campaignMapper.replaceBatch(campaigns);
|
|
getAdvertiserCampaignByPageNumber(token, pageNumber + 1, ids, date);
|
|
getAdvertiserCampaignByPageNumber(token, pageNumber + 1, ids, date);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Map<String, Object> updateCampaignStatus(CtopOauthToken token, String campaignIds, String optStatus) {
|
|
|
|
|
|
+ public Map<String, Object> updateCampaignStatus(Long accountId, String campaignIds, String optStatus) {
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
|
|
|
|
+ this.getAdvertiserCampaign(token,null,null);
|
|
JSONArray ids = new JSONArray();
|
|
JSONArray ids = new JSONArray();
|
|
String[] getIds = campaignIds.split(StringUtils.COMMA);
|
|
String[] getIds = campaignIds.split(StringUtils.COMMA);
|
|
if (null != getIds && getIds.length > 0) {
|
|
if (null != getIds && getIds.length > 0) {
|
|
@@ -223,13 +238,7 @@ public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignM
|
|
resultMap.put("message", "广告组更新状态异常");
|
|
resultMap.put("message", "广告组更新状态异常");
|
|
return resultMap;
|
|
return resultMap;
|
|
}
|
|
}
|
|
- JSONArray getCampaignIds = data.getJSONArray("campaign_ids");
|
|
|
|
- if (null != getCampaignIds && !getCampaignIds.isEmpty()) {
|
|
|
|
- for (int i = 0; i < getCampaignIds.size(); i++) {
|
|
|
|
- Long id = getCampaignIds.getLong(i);
|
|
|
|
- getAdvertiserCampaign(token,id+"",null);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ this.getAdvertiserCampaign(token,null,null);
|
|
resultMap.put("code", 0);
|
|
resultMap.put("code", 0);
|
|
resultMap.put("message", "广告组状态修改成功");
|
|
resultMap.put("message", "广告组状态修改成功");
|
|
return resultMap;
|
|
return resultMap;
|