|
@@ -0,0 +1,939 @@
|
|
|
|
+package cn.com.ctop.job.bytedance.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.com.ctop.job.bytedance.entity.ByteDanceAdvertisePlan;
|
|
|
|
+import cn.com.ctop.job.bytedance.entity.ByteDanceAdvertiserReportDTO;
|
|
|
|
+import cn.com.ctop.job.bytedance.entity.BytedanceAdvertiserDailyReport;
|
|
|
|
+import cn.com.ctop.job.bytedance.entity.BytedanceAdvertiserHourlyReport;
|
|
|
|
+import cn.com.ctop.job.bytedance.entity.CtopOauthToken;
|
|
|
|
+import cn.com.ctop.job.bytedance.entity.RuleDataAccount;
|
|
|
|
+import cn.com.ctop.job.bytedance.entity.RuleDataCreative;
|
|
|
|
+import cn.com.ctop.job.bytedance.entity.RuleDataPlan;
|
|
|
|
+import cn.com.ctop.job.bytedance.entity.RuleDataTarget;
|
|
|
|
+import cn.com.ctop.job.bytedance.entity.TransactionDay;
|
|
|
|
+import cn.com.ctop.job.bytedance.entity.UserAllocation;
|
|
|
|
+import cn.com.ctop.job.bytedance.enums.BytedanceConvertType;
|
|
|
|
+import cn.com.ctop.job.bytedance.mapper.AccountInfoMapper;
|
|
|
|
+import cn.com.ctop.job.bytedance.mapper.ReportDataMapper;
|
|
|
|
+import cn.com.ctop.job.bytedance.mapper.TokenMapper;
|
|
|
|
+import cn.com.ctop.job.bytedance.service.ReportDataService;
|
|
|
|
+import cn.com.ctop.job.bytedance.utils.Check;
|
|
|
|
+import cn.com.ctop.job.bytedance.utils.DateUtils;
|
|
|
|
+import cn.com.ctop.job.bytedance.utils.HttpUtils;
|
|
|
|
+import cn.com.ctop.job.bytedance.utils.ResultMapUtils;
|
|
|
|
+import cn.com.ctop.job.bytedance.utils.StatusCode;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.alibaba.fastjson.PropertyNamingStrategy;
|
|
|
|
+import com.alibaba.fastjson.serializer.SerializeConfig;
|
|
|
|
+import com.xxl.job.core.context.XxlJobHelper;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import lombok.var;
|
|
|
|
+import org.apache.http.client.ClientProtocolException;
|
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
|
|
|
+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.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStreamReader;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.net.URI;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.Calendar;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class ReportDataServiceImpl implements ReportDataService {
|
|
|
|
+ @Autowired
|
|
|
|
+ private ReportDataMapper reportDataMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private AccountInfoMapper accountMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private TokenMapper tokenMapper;
|
|
|
|
+
|
|
|
|
+ static ExecutorService executorService = Executors.newFixedThreadPool(3);
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void insertAccountTransactionDayByProjectId(Long projectId, String startDate, String endDate) {
|
|
|
|
+ List<String> accountIdList = accountMapper.getAccountIdsByProjectId(projectId);
|
|
|
|
+ if (!Check.isNull(accountIdList)) {
|
|
|
|
+ accountIdList.forEach(accountId -> executorService.submit(() -> this.insertAccountTransactionDay(accountId, startDate, endDate, 1)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void insertAccountTransactionDay(String accountId, String startDate, String endDate, Integer page) {
|
|
|
|
+ try {
|
|
|
|
+ JSONObject obj = queryAccountTransactionDay(accountId, page, 1000, startDate, endDate);
|
|
|
|
+ if (!Check.isNull(obj) && obj.getInteger("code") == 0) {
|
|
|
|
+ JSONObject data = obj.getJSONObject("data");
|
|
|
|
+ JSONArray list = data.getJSONArray("list");
|
|
|
|
+ List<TransactionDay> transactionDays = JSONArray.parseArray(list.toJSONString(), TransactionDay.class);
|
|
|
|
+ if (!Check.isNull(transactionDays)) {
|
|
|
|
+ reportDataMapper.replaceBatchAccountTransactionDay(transactionDays);
|
|
|
|
+ }
|
|
|
|
+ JSONObject pageInfo = data.getJSONObject("page_info");
|
|
|
|
+ Integer totalPage = pageInfo.getInteger("total_page");
|
|
|
|
+ if (totalPage > page) {
|
|
|
|
+ insertAccountTransactionDay(accountId, startDate, endDate, page + 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ log.info("同步失败:{}", e.toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询账号日流水
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ * @author zzy
|
|
|
|
+ * @Param AccountId 账户id pageNum 当前页 pageSize 每页显示数量
|
|
|
|
+ * @create: 2021-07-14
|
|
|
|
+ */
|
|
|
|
+ public JSONObject queryAccountTransactionDay(String AccountId, int pageNum, int pageSize, String startDate, String endDate) {
|
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
|
|
|
|
+ Calendar ca = Calendar.getInstance();
|
|
|
|
+ ca.setTime(new Date());
|
|
|
|
+ ca.add(Calendar.DATE, -1);
|
|
|
|
+ // 请求参数
|
|
|
|
+ Map data = new HashMap() {
|
|
|
|
+ {
|
|
|
|
+ put("advertiser_id", AccountId);
|
|
|
|
+ put("start_date", startDate);
|
|
|
|
+ put("end_date", endDate);
|
|
|
|
+ put("page", pageNum);
|
|
|
|
+ put("page_size", pageSize);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ return sendHttpRequest(data, "advertiser/fund/daily_stat/");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据地址请求巨量殷勤,返回响应结果
|
|
|
|
+ *
|
|
|
|
+ * @author zzy
|
|
|
|
+ * @Param data 请求参数 apiUrl请求路径
|
|
|
|
+ * @create: 2021-07-14
|
|
|
|
+ */
|
|
|
|
+ public JSONObject sendHttpRequest(Map data, String apiUrl) {
|
|
|
|
+ String access_token = getToken(Long.parseLong(data.get("advertiser_id").toString()));
|
|
|
|
+ // 构造请求
|
|
|
|
+ HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
|
+ @Override
|
|
|
|
+ public String getMethod() {
|
|
|
|
+ return "GET";
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ httpEntity.setHeader("Access-Token", access_token);
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
|
+ CloseableHttpClient client = null;
|
|
|
|
+ try {
|
|
|
|
+ client = HttpClientBuilder.create().build();
|
|
|
|
+ httpEntity.setURI(URI.create("https://ad.oceanengine.com/open_api/2/" + apiUrl));
|
|
|
|
+ httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
|
|
+ response = client.execute(httpEntity);
|
|
|
|
+ if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
|
+ StringBuffer result = new StringBuffer();
|
|
|
|
+ String line = "";
|
|
|
|
+ while ((line = bufferedReader.readLine()) != null) {
|
|
|
|
+ result.append(line);
|
|
|
|
+ }
|
|
|
|
+ bufferedReader.close();
|
|
|
|
+ return JSONObject.parseObject(result.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (ClientProtocolException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (response != null) {
|
|
|
|
+ response.close();
|
|
|
|
+ }
|
|
|
|
+ client.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取token
|
|
|
|
+ *
|
|
|
|
+ * @author zzy
|
|
|
|
+ * @create: 2021-07-14
|
|
|
|
+ */
|
|
|
|
+ public String getToken(long accountId) {
|
|
|
|
+ CtopOauthToken ctopOauthToken = tokenMapper.getOneByAccountId(accountId);
|
|
|
|
+ if (ctopOauthToken != null) {
|
|
|
|
+ return ctopOauthToken.getAccessToken();
|
|
|
|
+ } else {
|
|
|
|
+ log.info("未查询到Token");
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void getAdvertiserReport(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl) {
|
|
|
|
+ var conditions = getReportDTO(token, startDate, endDate, bytedanceReportTypePl);
|
|
|
|
+ getAdvertiserReportByPage(token, conditions, 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getAdvertiserReportByPage(CtopOauthToken token, ByteDanceAdvertiserReportDTO conditions, Integer page) {
|
|
|
|
+ conditions.setPage(page);
|
|
|
|
+ SerializeConfig config = new SerializeConfig();
|
|
|
|
+ config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
|
+ JSONObject getObject = getAdvertiserStat(token, jsonObject);
|
|
|
|
+ if (null == getObject) {
|
|
|
|
+ XxlJobHelper.log("头条广告主数据获取异常");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Integer code = getObject.getInteger("code");
|
|
|
|
+ String message = getObject.getString("message");
|
|
|
|
+ if (null == code || code != 0) {
|
|
|
|
+ XxlJobHelper.log("头条广告主数据获取异常:{}", message);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
|
+ if (null == dataArray || dataArray.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < dataArray.size(); i++) {
|
|
|
|
+ JSONObject data = dataArray.getJSONObject(i);
|
|
|
|
+ if (null != conditions.getTimeGranularity() && conditions.getTimeGranularity().equals("STAT_TIME_GRANULARITY_HOURLY")) {
|
|
|
|
+ BytedanceAdvertiserHourlyReport hourlyReport = new BytedanceAdvertiserHourlyReport(data);
|
|
|
|
+ reportDataMapper.replaceBytedanceAdvertiserHourly(hourlyReport);
|
|
|
|
+ } else {
|
|
|
|
+ BytedanceAdvertiserDailyReport dailyReport = new BytedanceAdvertiserDailyReport(data);
|
|
|
|
+ reportDataMapper.replaceBytedanceAdvertiserDaily(dailyReport);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private ByteDanceAdvertiserReportDTO getReportDTO(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl) {
|
|
|
|
+ var conditions = new ByteDanceAdvertiserReportDTO();
|
|
|
|
+ conditions.setAdvertiserId(token.getAccountId());
|
|
|
|
+ conditions.setStartDate(DateUtils.formatDate(startDate));
|
|
|
|
+ conditions.setEndDate(DateUtils.formatDate(endDate));
|
|
|
|
+ conditions.setPageSize(1000);
|
|
|
|
+ conditions.setTimeGranularity(bytedanceReportTypePl);
|
|
|
|
+ conditions.setFields(conditions.getFieldsList());
|
|
|
|
+ return conditions;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取广告主报表信息
|
|
|
|
+ *
|
|
|
|
+ * @param token
|
|
|
|
+ * @param conditions
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public JSONObject getAdvertiserStat(CtopOauthToken token, JSONObject conditions) {
|
|
|
|
+ // 请求地址
|
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/report/advertiser/get/";
|
|
|
|
+ JSONArray groupBy = new JSONArray();
|
|
|
|
+ groupBy.add("STAT_GROUP_BY_FIELD_ID");
|
|
|
|
+ groupBy.add("STAT_GROUP_BY_FIELD_STAT_TIME");
|
|
|
|
+ conditions.put("group_by", groupBy);
|
|
|
|
+ return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, conditions);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void getAdvertiserPlan(CtopOauthToken token, int pageNum, String ids, String date, String updateDate) {
|
|
|
|
+ JSONArray getIds = null;
|
|
|
|
+ if (null != ids && !"".equals(ids)) {
|
|
|
|
+ String[] idString = ids.split(",");
|
|
|
|
+ if (idString.length > 0) {
|
|
|
|
+ for (int i = 0; i < idString.length; i++) {
|
|
|
|
+ Long getId = Long.parseLong(idString[i]);
|
|
|
|
+ getIds.add(getId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 请求地址
|
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/ad/get/";
|
|
|
|
+ // 请求参数
|
|
|
|
+ Map<String, Object> filtering = new HashMap<>();
|
|
|
|
+ if (null != getIds && getIds.size() > 0) {
|
|
|
|
+ filtering.put("ids", getIds);
|
|
|
|
+ }
|
|
|
|
+ if (null != date && !"".equals(date)) {
|
|
|
|
+ filtering.put("ad_create_time", date);
|
|
|
|
+ }
|
|
|
|
+ if (null != updateDate && !"".equals(updateDate)) {
|
|
|
|
+ filtering.put("ad_modify_time", updateDate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
|
+ 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:{}", token.getAccountId(), resultObject.getString("message"));
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
|
|
|
|
+ if (null == data || data.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
|
+ JSONObject dataObject = data.getJSONObject(i);
|
|
|
|
+ ByteDanceAdvertisePlan advertisePlan = new ByteDanceAdvertisePlan(dataObject, String.valueOf(token.getAccountId()));
|
|
|
|
+ BigDecimal deepCpabid = dataObject.getBigDecimal("deep_cpabid");
|
|
|
|
+ if (null != deepCpabid) {
|
|
|
|
+ advertisePlan.setDeepCpaBid(deepCpabid);
|
|
|
|
+ }
|
|
|
|
+ reportDataMapper.replaceByteDanceAdvertisePlan(advertisePlan);
|
|
|
|
+ //log.info("============保存头条计划=================");
|
|
|
|
+ }
|
|
|
|
+ getAdvertiserPlan(token, pageNum + 1, ids, date, updateDate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void deleteRuleData(Long accountId) {
|
|
|
|
+ reportDataMapper.delRuleDataPlan(accountId);
|
|
|
|
+ reportDataMapper.delRuleDataTarget(accountId);
|
|
|
|
+ reportDataMapper.delRuleDataCreative(accountId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void getAdvertiserPlanRuleData(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl) {
|
|
|
|
+ var conditions = getReportDTO(token, startDate, endDate, bytedanceReportTypePl);
|
|
|
|
+ getPlanRuleDataByPage(token, conditions, 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void getPlanRuleDataByPage(CtopOauthToken token, ByteDanceAdvertiserReportDTO conditions, int page) {
|
|
|
|
+ conditions.setPage(page);
|
|
|
|
+ var config = new SerializeConfig();
|
|
|
|
+ config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
|
+ var jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
|
+
|
|
|
|
+ JSONObject getObject = getAdStat(token, jsonObject);
|
|
|
|
+ if (null == getObject) {
|
|
|
|
+ log.error("广告计划报表数据获取异常=》account:{};message:{}", token.getAccountId(), "返回数据异常");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Integer code = getObject.getInteger("code");
|
|
|
|
+ var message = getObject.getString("message");
|
|
|
|
+ if (null == code || code != 0) {
|
|
|
|
+ log.error("广告计划报表数据获取异常=》account:{};message:{}", token.getAccountId(), message);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ var dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
|
+ if (null == dataArray || dataArray.size() <= 0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ UserAllocation allocation = accountMapper.getUserAllocationByAccountId(token.getAccountId());
|
|
|
|
+ for (var i = 0; i < dataArray.size(); i++) {
|
|
|
|
+ var data = dataArray.getJSONObject(i);
|
|
|
|
+ var ruleDataPlan = new RuleDataPlan(data, token.getAccountId());
|
|
|
|
+ ruleDataPlan.setAccountName(allocation.getAuthName());
|
|
|
|
+ ByteDanceAdvertisePlan plan = getSinglePlanById(token, ruleDataPlan.getId() + "");
|
|
|
|
+ if (null != plan) {
|
|
|
|
+ String status = plan.getToutiaoStatus();
|
|
|
|
+ String optStatus = plan.getOptStatus();
|
|
|
|
+ if (null == optStatus || optStatus.equals("AD_STATUS_DISABLE") || optStatus.trim().equals("")) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (null == status || status.trim().equals("") || status.equals("AD_STATUS_DISABLE")
|
|
|
|
+ || status.equals("AD_STATUS_DONE") || status.equals("AD_STATUS_AUDIT_DENY") || status.equals("AD_STATUS_BALANCE_EXCEED")
|
|
|
|
+ || status.equals("AD_STATUS_CAMPAIGN_DISABLE") || status.equals("AD_STATUS_CAMPAIGN_EXCEED") || status.equals("AD_STATUS_DELETE")) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ ruleDataPlan.setBudget(plan.getBudget());
|
|
|
|
+ ruleDataPlan.setDownloadUrl(plan.getDownloadUrl());
|
|
|
|
+ ruleDataPlan.setExternalUrl(plan.getExternalUrl());
|
|
|
|
+ ruleDataPlan.setPricing(plan.getPricing());
|
|
|
|
+ ruleDataPlan.setCpaBid(plan.getCpaBid());
|
|
|
|
+ ruleDataPlan.setDeepCpabid(plan.getDeepCpaBid());
|
|
|
|
+ Long convertId = plan.getConvertId();
|
|
|
|
+ if (null != convertId && convertId != 0) {
|
|
|
|
+ ruleDataPlan.setConvertId(plan.getConvertId());
|
|
|
|
+ JSONObject convertTargetObject = readAdConvert(token, plan.getConvertId());
|
|
|
|
+ if (null != convertTargetObject) {
|
|
|
|
+ ruleDataPlan.setConvertId(BytedanceConvertType.getNum(convertTargetObject.getString("convert_type")));
|
|
|
|
+ ruleDataPlan.setDeepConvertTarget(convertTargetObject.getString("deep_external_action"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ RuleDataTarget target = new RuleDataTarget();
|
|
|
|
+ JSONObject audienceObject = JSONObject.parseObject(plan.getAudience());
|
|
|
|
+ target.setAccountId(token.getAccountId());
|
|
|
|
+ target.setAccountName(allocation.getAuthName());
|
|
|
|
+ target.setDeepBidType(plan.getDeepBidType());
|
|
|
|
+ target.setPlanId(ruleDataPlan.getPlanId());
|
|
|
|
+ target.setId(ruleDataPlan.getPlanId());
|
|
|
|
+ target.setCreateTime(new Date());
|
|
|
|
+ target.setUpdateTime(new Date());
|
|
|
|
+ if (null != audienceObject.getString("retargeting_tags_exclude")) {
|
|
|
|
+ target.setRetargetingTagsExclude(audienceObject.getString("retargeting_tags_exclude"));
|
|
|
|
+ }
|
|
|
|
+ if (null != audienceObject.getString("retargeting_tags_include")) {
|
|
|
|
+ target.setRetargetingTagsExclude(audienceObject.getString("retargeting_tags_include"));
|
|
|
|
+ }
|
|
|
|
+ if (null != audienceObject.getString("retargeting_tags_include")) {
|
|
|
|
+ target.setRetargetingTagsInclude(audienceObject.getString("retargeting_tags_include"));
|
|
|
|
+ }
|
|
|
|
+ target.setHideIfConverted(plan.getHideIfConverted());
|
|
|
|
+ target.setHideIfExists(plan.getHideIfExists());
|
|
|
|
+
|
|
|
|
+ //target.setInventoryType(plan.getInventoryType());
|
|
|
|
+ if (null != audienceObject.getString("city")) {
|
|
|
|
+ target.setDistrict(audienceObject.getString("city"));
|
|
|
|
+ }
|
|
|
|
+ if (null != audienceObject.getString("gender")) {
|
|
|
|
+ target.setGender(audienceObject.getString("gender"));
|
|
|
|
+ }
|
|
|
|
+ if (null != audienceObject.getString("age")) {
|
|
|
|
+ target.setAge(audienceObject.getString("age"));
|
|
|
|
+ }
|
|
|
|
+ if (null != audienceObject.getString("exclude_flow_package")) {
|
|
|
|
+ target.setExcludeFlowPackage(audienceObject.getString("exclude_flow_package"));
|
|
|
|
+ }
|
|
|
|
+// this.flowPackage = audience.getString("flow_package");
|
|
|
|
+ if (null != audienceObject.getString("platform")) {
|
|
|
|
+ target.setPlatform(audienceObject.getString("platform"));
|
|
|
|
+ }
|
|
|
|
+ target.setDeepBidType(plan.getDeepBidType());
|
|
|
|
+ target.setScheduleTime(plan.getScheduleTime());
|
|
|
|
+
|
|
|
|
+ reportDataMapper.replaceRuleDataTarget(target);
|
|
|
|
+ Map<String, Object> creativeDetail = getCreativeDetail(token, plan.getId());
|
|
|
|
+ if (null != creativeDetail.get("data")) {
|
|
|
|
+ JSONObject detail = (JSONObject) creativeDetail.get("data");
|
|
|
|
+ formatCreativeData(detail, allocation, ruleDataPlan);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ reportDataMapper.replaceRuleDataPlan(ruleDataPlan);
|
|
|
|
+ }
|
|
|
|
+ getPlanRuleDataByPage(token, conditions, page + 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void formatCreativeData(JSONObject detail, UserAllocation allocation, RuleDataPlan plan) {
|
|
|
|
+ //广告来源
|
|
|
|
+ String source = detail.getString("source");
|
|
|
|
+ Integer isPresentedVideo = detail.getInteger("isPresentedVideo");
|
|
|
|
+ JSONArray creatives = detail.getJSONArray("creatives");
|
|
|
|
+ if (null != creatives && !creatives.isEmpty()) {
|
|
|
|
+ for (int i = 0; i < creatives.size(); i++) {
|
|
|
|
+ JSONObject data = creatives.getJSONObject(i);
|
|
|
|
+ Long creativeId = data.getLong("creative_id");
|
|
|
|
+ if (null != creativeId) {
|
|
|
|
+ String title = data.getString("title");
|
|
|
|
+ RuleDataCreative dataCreative = new RuleDataCreative();
|
|
|
|
+ dataCreative.setId(creativeId);
|
|
|
|
+ dataCreative.setCreativeId(creativeId);
|
|
|
|
+ dataCreative.setCreativeTitle(title);
|
|
|
|
+ dataCreative.setPlanId(plan.getId());
|
|
|
|
+ dataCreative.setPlanName(plan.getPlanName());
|
|
|
|
+ dataCreative.setAccountId(allocation.getAccountId());
|
|
|
|
+ dataCreative.setAccountName(allocation.getAuthName());
|
|
|
|
+ dataCreative.setSource(source);
|
|
|
|
+ dataCreative.setPresentedVideo(isPresentedVideo);
|
|
|
|
+ dataCreative.setCreateTime(new Date());
|
|
|
|
+ dataCreative.setUpdateTime(new Date());
|
|
|
|
+ reportDataMapper.replaceRuleDataCreative(dataCreative);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取广告计划报表信息
|
|
|
|
+ *
|
|
|
|
+ * @param token
|
|
|
|
+ * @param conditions
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private JSONObject getAdStat(CtopOauthToken token, JSONObject conditions) {
|
|
|
|
+ // 请求地址
|
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/report/ad/get/";
|
|
|
|
+ JSONArray groupBy = new JSONArray();
|
|
|
|
+ groupBy.add("STAT_GROUP_BY_FIELD_ID");
|
|
|
|
+ groupBy.add("STAT_GROUP_BY_FIELD_STAT_TIME");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ JSONObject status = new JSONObject();
|
|
|
|
+ status.put("status", "AD_STATUS_ALL");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ conditions.put("filtering", status);
|
|
|
|
+ conditions.put("group_by", groupBy);
|
|
|
|
+ return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, conditions);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public ByteDanceAdvertisePlan getSinglePlanById(CtopOauthToken token, String id) {
|
|
|
|
+ JSONArray getIds = new JSONArray();
|
|
|
|
+ getIds.add(id);
|
|
|
|
+ // 请求地址
|
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/ad/get/";
|
|
|
|
+ // 请求参数
|
|
|
|
+ Map<String, Object> filtering = new HashMap<>();
|
|
|
|
+ filtering.put("ids", getIds);
|
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
|
+ param.put("page", 1);
|
|
|
|
+ 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:{}", token.getAccountId(), resultObject.getString("message"));
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
|
|
|
|
+ if (null == data || data.isEmpty()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ JSONObject dataObject = data.getJSONObject(0);
|
|
|
|
+ ByteDanceAdvertisePlan advertisePlan = new ByteDanceAdvertisePlan(dataObject, String.valueOf(token.getAccountId()));
|
|
|
|
+ BigDecimal deepCpabid = dataObject.getBigDecimal("deep_cpabid");
|
|
|
|
+ if (null != deepCpabid) {
|
|
|
|
+ advertisePlan.setDeepCpaBid(deepCpabid);
|
|
|
|
+ }
|
|
|
|
+ return advertisePlan;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public JSONObject readAdConvert(CtopOauthToken token, Long convertId) {
|
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/tools/ad_convert/read/";
|
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
|
+ params.put("advertiser_id", token.getAccountId());
|
|
|
|
+ params.put("convert_id", convertId);
|
|
|
|
+ JSONObject result = HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
|
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
|
+ String message = result.getString("message");
|
|
|
|
+ if (null == code || code != 0) {
|
|
|
|
+ log.error("获取转化数据异常=》account:{};convertId:{};message:{}", token.getAccountId(), convertId, message);
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return result.getJSONObject("data");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, Object> getCreativeDetail(CtopOauthToken token, Long planId) {
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ if (null == planId || planId == 0 || null == token) {
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_PARAM_ERROR);
|
|
|
|
+ resultMap.put("data", null);
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ByteDanceAdvertisePlan plan = reportDataMapper.getByteDanceAdvertisePlanById(planId);
|
|
|
|
+ if (null == plan || "AD_STATUS_DELETE".equals(plan.getOptStatus())) {
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.BYTEDANCE_ACCOUNT_DATA_NOT_EXIST);
|
|
|
|
+ resultMap.put("data", null);
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+ // 请求地址
|
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/creative/get/";
|
|
|
|
+ // 请求参数
|
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
|
+ data.put("advertiser_id", token.getAccountId());
|
|
|
|
+ data.put("ad_id", planId);
|
|
|
|
+ JSONObject result = HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, data);
|
|
|
|
+ if (null == result) {
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_INTERNET_ERROR);
|
|
|
|
+ resultMap.put("data", null);
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+ Integer code = result.getInteger("code");
|
|
|
|
+ String message = result.getString("message");
|
|
|
|
+ if (null == code) {
|
|
|
|
+ log.info("广告创意获取详情失败,accountId:{},message:{}", token.getAccountId(), message);
|
|
|
|
+ resultMap.put("success", false);
|
|
|
|
+ resultMap.put("code", -1);
|
|
|
|
+ result.put("data", null);
|
|
|
|
+ resultMap.put("message", message);
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+ if (code == 40001) {
|
|
|
|
+ //尚未创建创意
|
|
|
|
+ resultMap.put("success", true);
|
|
|
|
+ resultMap.put("code", 0);
|
|
|
|
+ result.put("data", null);
|
|
|
|
+ resultMap.put("message", message);
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+ if (code != 0) {
|
|
|
|
+ log.info("广告创意获取详情失败,accountId:{},message:{}", token.getAccountId(), message);
|
|
|
|
+ resultMap.put("success", false);
|
|
|
|
+ resultMap.put("code", -1);
|
|
|
|
+ result.put("data", null);
|
|
|
|
+ resultMap.put("message", message);
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+ JSONObject getData = result.getJSONObject("data");
|
|
|
|
+ resultMap.put("data", formatData(getData));
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS);
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private JSONObject formatData(JSONObject getData) {
|
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
|
+ Long advertiserId = getData.getLong("advertiser_id");
|
|
|
|
+ if (null != advertiserId && advertiserId != 0) {
|
|
|
|
+ data.put("advertiserId", advertiserId);
|
|
|
|
+ }
|
|
|
|
+ Long adId = getData.getLong("ad_id");
|
|
|
|
+ if (null != adId && adId != 0) {
|
|
|
|
+ data.put("adId", adId);
|
|
|
|
+ }
|
|
|
|
+ String modifyTime = getData.getString("modify_time");
|
|
|
|
+ if (null != modifyTime && !"".equals(modifyTime.trim())) {
|
|
|
|
+ data.put("modifyTime", modifyTime);
|
|
|
|
+ }
|
|
|
|
+ String trackUrl = getData.getString("track_url");
|
|
|
|
+ if (null != trackUrl && !"".equals(trackUrl.trim())) {
|
|
|
|
+ data.put("trackUrl", trackUrl);
|
|
|
|
+ }
|
|
|
|
+ String actionTrackUrl = getData.getString("action_track_url");
|
|
|
|
+ if (null != actionTrackUrl && !"".equals(actionTrackUrl.trim())) {
|
|
|
|
+ data.put("actionTrackUrl", actionTrackUrl);
|
|
|
|
+ }
|
|
|
|
+ String videoPlayEffectiveTrackUrl = getData.getString("video_play_effective_track_url");
|
|
|
|
+ if (null != videoPlayEffectiveTrackUrl && !"".equals(videoPlayEffectiveTrackUrl.trim())) {
|
|
|
|
+ data.put("videoPlayEffectiveTrackUrl", videoPlayEffectiveTrackUrl);
|
|
|
|
+ }
|
|
|
|
+ String videoPlayDoneTrackUrl = getData.getString("video_play_done_track_url");
|
|
|
|
+ if (null != videoPlayDoneTrackUrl && !"".equals(videoPlayDoneTrackUrl.trim())) {
|
|
|
|
+ data.put("videoPlayDoneTrackUrl", videoPlayDoneTrackUrl);
|
|
|
|
+ }
|
|
|
|
+ String videoPlayTrackUrl = getData.getString("video_play_track_url");
|
|
|
|
+ if (null != videoPlayTrackUrl && !"".equals(videoPlayTrackUrl.trim())) {
|
|
|
|
+ data.put("videoPlayTrackUrl", videoPlayTrackUrl);
|
|
|
|
+ }
|
|
|
|
+ Integer isCommentDisable = getData.getInteger("is_comment_disable");
|
|
|
|
+ if (null != isCommentDisable) {
|
|
|
|
+ data.put("isCommentDisable", isCommentDisable);
|
|
|
|
+ }
|
|
|
|
+ Integer closeVideoDetail = getData.getInteger("close_video_detail");
|
|
|
|
+ if (null != closeVideoDetail) {
|
|
|
|
+ data.put("closeVideoDetail", closeVideoDetail);
|
|
|
|
+ }
|
|
|
|
+ String creativeDisplayMode = getData.getString("creative_display_mode");
|
|
|
|
+ if (null != creativeDisplayMode && !"".equals(creativeDisplayMode.trim())) {
|
|
|
|
+ data.put("creativeDisplayMode", creativeDisplayMode);
|
|
|
|
+ }
|
|
|
|
+ Long smartInventory = getData.getLong("smart_inventory");
|
|
|
|
+ if (null != smartInventory && smartInventory != 0) {
|
|
|
|
+ data.put("smartInventory", smartInventory);
|
|
|
|
+ }
|
|
|
|
+ String sceneInventory = getData.getString("scene_inventory");
|
|
|
|
+ if (null != sceneInventory && !"".equals(sceneInventory.trim())) {
|
|
|
|
+ data.put("sceneInventory", sceneInventory);
|
|
|
|
+ }
|
|
|
|
+ Long generateDerivedAd = getData.getLong("generate_derived_ad");
|
|
|
|
+ if (null != generateDerivedAd && generateDerivedAd != 0) {
|
|
|
|
+ data.put("generateDerivedAd", generateDerivedAd);
|
|
|
|
+ }
|
|
|
|
+ JSONArray inventoryType = getData.getJSONArray("inventory_type");
|
|
|
|
+ if (null != inventoryType && !inventoryType.isEmpty()) {
|
|
|
|
+ data.put("inventoryType", inventoryType);
|
|
|
|
+ }
|
|
|
|
+ String source = getData.getString("source");
|
|
|
|
+ if (null != source && !"".equals(source.trim())) {
|
|
|
|
+ data.put("source", source);
|
|
|
|
+ }
|
|
|
|
+ String appName = getData.getString("app_name");
|
|
|
|
+ if (null != appName && !"".equals(appName.trim())) {
|
|
|
|
+ data.put("appName", appName);
|
|
|
|
+ }
|
|
|
|
+ String webUrl = getData.getString("web_url");
|
|
|
|
+ if (null != webUrl && !"".equals(webUrl.trim())) {
|
|
|
|
+ data.put("webUrl", webUrl);
|
|
|
|
+ }
|
|
|
|
+ JSONArray adKeywords = getData.getJSONArray("ad_keywords");
|
|
|
|
+ if (null != adKeywords && !adKeywords.isEmpty()) {
|
|
|
|
+ data.put("adKeywords", adKeywords);
|
|
|
|
+ }
|
|
|
|
+ Long thirdIndustryId = getData.getLong("third_industry_id");
|
|
|
|
+ if (null != thirdIndustryId && thirdIndustryId != 0) {
|
|
|
|
+ data.put("thirdIndustryId", thirdIndustryId);
|
|
|
|
+ }
|
|
|
|
+ String advancedCreativeType = getData.getString("advanced_creative_type");
|
|
|
|
+ if (null != advancedCreativeType && !"".equals(advancedCreativeType.trim())) {
|
|
|
|
+ data.put("advancedCreativeType", advancedCreativeType);
|
|
|
|
+ }
|
|
|
|
+ String advancedCreativeTitle = getData.getString("advanced_creative_title");
|
|
|
|
+ if (null != advancedCreativeTitle && !"".equals(advancedCreativeTitle.trim())) {
|
|
|
|
+ data.put("advancedCreativeTitle", advancedCreativeTitle);
|
|
|
|
+ }
|
|
|
|
+ String phoneNumber = getData.getString("phone_number");
|
|
|
|
+ if (null != phoneNumber && !"".equals(phoneNumber.trim())) {
|
|
|
|
+ data.put("phoneNumber", phoneNumber);
|
|
|
|
+ }
|
|
|
|
+ String buttonText = getData.getString("button_text");
|
|
|
|
+ if (null != buttonText && !"".equals(buttonText.trim())) {
|
|
|
|
+ data.put("buttonText", buttonText);
|
|
|
|
+ }
|
|
|
|
+ String actionText = getData.getString("action_text");
|
|
|
|
+ if (null != actionText && !"".equals(actionText.trim())) {
|
|
|
|
+ data.put("actionText", actionText);
|
|
|
|
+ }
|
|
|
|
+ String formUrl = getData.getString("form_url");
|
|
|
|
+ if (null != formUrl && !"".equals(formUrl.trim())) {
|
|
|
|
+ data.put("formUrl", formUrl);
|
|
|
|
+ }
|
|
|
|
+ String creativeMaterialMode = getData.getString("creative_material_mode");
|
|
|
|
+ if (null != creativeMaterialMode && !"".equals(creativeMaterialMode.trim())) {
|
|
|
|
+ data.put("creativeMaterialMode", creativeMaterialMode);
|
|
|
|
+ }
|
|
|
|
+ String iesCoreUserId = getData.getString("ies_core_user_id");
|
|
|
|
+ if (null != iesCoreUserId && !"".equals(iesCoreUserId.trim())) {
|
|
|
|
+ data.put("iesCoreUserId", iesCoreUserId);
|
|
|
|
+ }
|
|
|
|
+ Long isFeedAndFavSee = getData.getLong("is_feed_and_fav_see");
|
|
|
|
+ if (null != isFeedAndFavSee) {
|
|
|
|
+ data.put("isFeedAndFavSee", isFeedAndFavSee);
|
|
|
|
+ }
|
|
|
|
+ JSONArray commerceCards = getData.getJSONArray("commerce_cards");
|
|
|
|
+ if (null != commerceCards && !commerceCards.isEmpty()) {
|
|
|
|
+ data.put("commerceCards", commerceCards);
|
|
|
|
+ }
|
|
|
|
+ String playableUrl = getData.getString("playable_url");
|
|
|
|
+ if (null != playableUrl && !"".equals(playableUrl.trim())) {
|
|
|
|
+ data.put("playableUrl", playableUrl);
|
|
|
|
+ }
|
|
|
|
+ Long proceduralPackageId = getData.getLong("procedural_package_id");
|
|
|
|
+ if (null != proceduralPackageId && proceduralPackageId != 0) {
|
|
|
|
+ data.put("proceduralPackageId", proceduralPackageId);
|
|
|
|
+ }
|
|
|
|
+ Long proceduralPackageVersion = getData.getLong("procedural_package_version");
|
|
|
|
+ if (null != proceduralPackageVersion && proceduralPackageVersion != 0) {
|
|
|
|
+ data.put("proceduralPackageVersion", proceduralPackageVersion);
|
|
|
|
+ }
|
|
|
|
+ Long isPresentedVideo = getData.getLong("is_presented_video");
|
|
|
|
+ if (null != isPresentedVideo) {
|
|
|
|
+ data.put("isPresentedVideo", isPresentedVideo);
|
|
|
|
+ }
|
|
|
|
+ String subTitle = getData.getString("sub_title");
|
|
|
|
+ if (null != subTitle && !"".equals(subTitle.trim())) {
|
|
|
|
+ data.put("subTitle", subTitle);
|
|
|
|
+ }
|
|
|
|
+ Long creativeAutoGenerateSwitch = getData.getLong("creative_auto_generate_switch");
|
|
|
|
+ if (null != creativeAutoGenerateSwitch) {
|
|
|
|
+ data.put("creativeAutoGenerateSwitch", creativeAutoGenerateSwitch);
|
|
|
|
+ }
|
|
|
|
+ String trackUrlSendType = getData.getString("track_url_send_type");
|
|
|
|
+ if (null != trackUrlSendType && !"".equals(trackUrlSendType.trim())) {
|
|
|
|
+ data.put("trackUrlSendType", trackUrlSendType);
|
|
|
|
+ }
|
|
|
|
+ JSONArray subLinkIdList = getData.getJSONArray("sub_link_id_list");
|
|
|
|
+ if (null != subLinkIdList && !subLinkIdList.isEmpty()) {
|
|
|
|
+ data.put("subLinkIdList", subLinkIdList);
|
|
|
|
+ }
|
|
|
|
+ JSONArray titleList = getData.getJSONArray("title_list");
|
|
|
|
+ if (null != titleList && !titleList.isEmpty()) {
|
|
|
|
+ JSONArray titleArray = new JSONArray();
|
|
|
|
+ for (int i = 0; i < titleList.size(); i++) {
|
|
|
|
+ JSONObject title = titleList.getJSONObject(i);
|
|
|
|
+ JSONArray creativeWordIds = title.getJSONArray("creative_word_ids");
|
|
|
|
+ JSONArray dpaDictIds = title.getJSONArray("dpa_dict_ids");
|
|
|
|
+ title.remove("creative_word_ids");
|
|
|
|
+ title.remove("dpa_dict_ids");
|
|
|
|
+ title.put("creativeWordIds", creativeWordIds);
|
|
|
|
+ title.put("dpaDictIds", dpaDictIds);
|
|
|
|
+ titleArray.add(title);
|
|
|
|
+ }
|
|
|
|
+ data.put("titleList", titleArray);
|
|
|
|
+ }
|
|
|
|
+ JSONArray imageList = getData.getJSONArray("image_list");
|
|
|
|
+ if (null != imageList && !imageList.isEmpty()) {
|
|
|
|
+ JSONArray imageArray = new JSONArray();
|
|
|
|
+ for (int i = 0; i < imageList.size(); i++) {
|
|
|
|
+ JSONObject getImage = imageList.getJSONObject(i);
|
|
|
|
+ JSONObject setImage = new JSONObject();
|
|
|
|
+ String imageMode = getImage.getString("image_mode");
|
|
|
|
+ setImage.put("imageMode", imageMode);
|
|
|
|
+ String imageId = getImage.getString("image_id");
|
|
|
|
+ if (null != imageId && !"".equals(imageId.trim())) {
|
|
|
|
+ setImage.put("imageId", imageId);
|
|
|
|
+ if (imageId.contains("web")) {
|
|
|
|
+ setImage.put("imageUrl", "https://sf6-ttcdn-tos.pstatp.com/obj/" + imageId);
|
|
|
|
+ } else {
|
|
|
|
+ setImage.put("imageUrl", "https://sf6-ttcdn-tos.pstatp.com/obj/mosaic-legacy/" + imageId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String videoId = getImage.getString("video_id");
|
|
|
|
+ if (null != videoId && !"".equals(videoId.trim())) {
|
|
|
|
+ setImage.put("videoId", videoId);
|
|
|
|
+ setImage.put("videoUrl", "https://aweme.snssdk.com/aweme/v1/playwm/?video_id=" + videoId + "&line=0");
|
|
|
|
+ }
|
|
|
|
+ JSONArray imageIds = getImage.getJSONArray("image_ids");
|
|
|
|
+ if (null != imageIds && !imageIds.isEmpty()) {
|
|
|
|
+ setImage.put("imageIds", imageIds);
|
|
|
|
+ }
|
|
|
|
+ String templateId = getImage.getString("template_id");
|
|
|
|
+ if (null != templateId && !"".equals(templateId.trim())) {
|
|
|
|
+ setImage.put("templateId", templateId);
|
|
|
|
+ }
|
|
|
|
+ imageArray.add(setImage);
|
|
|
|
+ }
|
|
|
|
+ data.put("imageList", imageArray);
|
|
|
|
+ }
|
|
|
|
+ JSONArray creativeList = getData.getJSONArray("creatives");
|
|
|
|
+ if (null != creativeList && !creativeList.isEmpty()) {
|
|
|
|
+ JSONArray creativeArray = new JSONArray();
|
|
|
|
+ for (int i = 0; i < creativeList.size(); i++) {
|
|
|
|
+ JSONObject getCreative = creativeList.getJSONObject(i);
|
|
|
|
+ JSONObject setCreative = new JSONObject();
|
|
|
|
+ String creative_id = getCreative.getString("creative_id");
|
|
|
|
+ if (null != creative_id && !"".equals(creative_id.trim())) {
|
|
|
|
+ setCreative.put("creative_id", creative_id);
|
|
|
|
+ }
|
|
|
|
+ String title = getCreative.getString("title");
|
|
|
|
+ if (null != title && !"".equals(title.trim())) {
|
|
|
|
+ setCreative.put("title", title);
|
|
|
|
+ }
|
|
|
|
+ JSONArray creativeWordIds = getCreative.getJSONArray("creative_word_ids");
|
|
|
|
+ if (null != creativeWordIds && !creativeWordIds.isEmpty()) {
|
|
|
|
+ setCreative.put("creativeWordIds", creativeWordIds);
|
|
|
|
+ }
|
|
|
|
+ JSONArray dpaDictIds = getCreative.getJSONArray("dpa_dict_ids");
|
|
|
|
+ if (null != dpaDictIds && !dpaDictIds.isEmpty()) {
|
|
|
|
+ setCreative.put("dpaDictIds", dpaDictIds);
|
|
|
|
+ }
|
|
|
|
+ String imageMode = getCreative.getString("image_mode");
|
|
|
|
+ if (null != imageMode && !"".equals(imageMode.trim())) {
|
|
|
|
+ setCreative.put("imageMode", imageMode);
|
|
|
|
+ }
|
|
|
|
+ JSONArray imageIds = getCreative.getJSONArray("imageIds");
|
|
|
|
+ if (null != imageIds && !imageIds.isEmpty()) {
|
|
|
|
+ setCreative.put("imageIds", imageIds);
|
|
|
|
+ }
|
|
|
|
+ String imageId = getCreative.getString("image_id");
|
|
|
|
+ if (null != imageId && !"".equals(imageId.trim())) {
|
|
|
|
+ setCreative.put("imageId", imageId);
|
|
|
|
+ setCreative.put("imageUrl", "https://sf6-ttcdn-tos.pstatp.com/obj/mosaic-legacy/" + imageId);
|
|
|
|
+ }
|
|
|
|
+ String videoId = getCreative.getString("video_id");
|
|
|
|
+ if (null != videoId && !"".equals(videoId.trim())) {
|
|
|
|
+ setCreative.put("videoId", videoId);
|
|
|
|
+ setCreative.put("videoUrl", "https://aweme.snssdk.com/aweme/v1/playwm/?video_id=" + videoId + "&line=0");
|
|
|
|
+ }
|
|
|
|
+ String thirdPartyId = getCreative.getString("third_party_id");
|
|
|
|
+ if (null != thirdPartyId && !"".equals(thirdPartyId.trim())) {
|
|
|
|
+ setCreative.put("thirdPartyId", thirdPartyId);
|
|
|
|
+ }
|
|
|
|
+ Long derivePosterCid = getCreative.getLong("derive_poster_cid");
|
|
|
|
+ if (null != derivePosterCid) {
|
|
|
|
+ setCreative.put("derivePosterCid", derivePosterCid);
|
|
|
|
+ }
|
|
|
|
+ Integer templateId = getCreative.getInteger("template_id");
|
|
|
|
+ if (null != templateId) {
|
|
|
|
+ setCreative.put("templateId", templateId);
|
|
|
|
+ }
|
|
|
|
+ String templateImageId = getCreative.getString("template_image_id");
|
|
|
|
+ if (null != templateImageId && !"".equals(templateImageId.trim())) {
|
|
|
|
+ setCreative.put("templateImageId", templateImageId);
|
|
|
|
+ }
|
|
|
|
+ Long dpaTemplate = getCreative.getLong("dpa_template");
|
|
|
|
+ if (null != dpaTemplate) {
|
|
|
|
+ setCreative.put("dpaTemplate", dpaTemplate);
|
|
|
|
+ }
|
|
|
|
+ String dpaVideoTemplateType = getCreative.getString("dpa_video_template_type");
|
|
|
|
+ if (null != dpaVideoTemplateType && !"".equals(dpaVideoTemplateType.trim())) {
|
|
|
|
+ setCreative.put("dpaVideoTemplateType", dpaVideoTemplateType);
|
|
|
|
+ }
|
|
|
|
+ JSONArray dpaVideoTaskIds = getCreative.getJSONArray("dpa_video_task_ids");
|
|
|
|
+ if (null != dpaVideoTaskIds && !dpaVideoTaskIds.isEmpty()) {
|
|
|
|
+ setCreative.put("dpaVideoTaskIds", dpaVideoTaskIds);
|
|
|
|
+ }
|
|
|
|
+ creativeArray.add(setCreative);
|
|
|
|
+ }
|
|
|
|
+ data.put("creatives", creativeArray);
|
|
|
|
+ }
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void deleteRuleAccount(Long accountId) {
|
|
|
|
+ reportDataMapper.delRuleDataAccount(accountId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void cleanRuleDataAccount(Long accountId) {
|
|
|
|
+ CtopOauthToken oauthToken = tokenMapper.getOneByAccountId(accountId);
|
|
|
|
+ //查询账户实时数据
|
|
|
|
+ JSONObject dataAccount = getAccountReportBy(oauthToken, accountId);
|
|
|
|
+ if (!dataAccount.isEmpty()) {
|
|
|
|
+ JSONObject fundData = getAccountFundBy(oauthToken, accountId);
|
|
|
|
+ RuleDataAccount ruleDataAccount = new RuleDataAccount();
|
|
|
|
+ ruleDataAccount.setId(accountId);
|
|
|
|
+ ruleDataAccount.setAccountId(accountId);
|
|
|
|
+ ruleDataAccount.setAccountName(fundData.getString("name"));
|
|
|
|
+ ruleDataAccount.setCost(dataAccount.getBigDecimal("cost"));
|
|
|
|
+ ruleDataAccount.setValidBalance(fundData.getBigDecimal("valid_balance"));
|
|
|
|
+ ruleDataAccount.setConvertNum(dataAccount.getLong("convert"));
|
|
|
|
+ ruleDataAccount.setConvertCost(dataAccount.getBigDecimal("convert_cost"));
|
|
|
|
+ ruleDataAccount.setNextDayOpenNum(dataAccount.getLong("next_day_open"));
|
|
|
|
+ ruleDataAccount.setNextDayOpenCost(dataAccount.getBigDecimal("next_day_open_cost"));
|
|
|
|
+ ruleDataAccount.setNextDayOpenRate(dataAccount.getBigDecimal("next_day_open_rate"));
|
|
|
|
+ reportDataMapper.replaceRuleDataAccount(ruleDataAccount);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public JSONObject getAccountReportBy(CtopOauthToken token, Long advertiserId) {
|
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/report/advertiser/get/";
|
|
|
|
+
|
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
|
+
|
|
|
|
+ String now = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
|
+ params.put("advertiser_id", advertiserId);
|
|
|
|
+ params.put("start_date", now);
|
|
|
|
+ params.put("end_date", now);
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(HttpUtils.httpGetRequest(url, headers, params));
|
|
|
|
+ if (jsonObject.getInteger("code") != 0) {
|
|
|
|
+ XxlJobHelper.log("账户{}获取实时数据失败---{}", advertiserId, jsonObject.getString("message"));
|
|
|
|
+ } else {
|
|
|
|
+ result = (JSONObject) jsonObject.getJSONObject("data").getJSONArray("list").get(0);
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public JSONObject getAccountFundBy(CtopOauthToken token, Long advertiserId) {
|
|
|
|
+ String url = "https://ad.oceanengine.com/open_api/2/advertiser/fund/get/";
|
|
|
|
+
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
|
+ headers.put("Access-Token", token.getAccessToken());
|
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
|
+ params.put("advertiser_id", advertiserId);
|
|
|
|
+
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(HttpUtils.httpGetRequest(url, headers, params));
|
|
|
|
+ if (jsonObject.getInteger("code") != 0) {
|
|
|
|
+ XxlJobHelper.log("查询账户余额失败==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return jsonObject.getJSONObject("data");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|