|
@@ -25,469 +25,489 @@ import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
-/** @author zzy */
|
|
|
+/**
|
|
|
+ * @author zzy
|
|
|
+ */
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@Primary
|
|
|
public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserDataService {
|
|
|
|
|
|
- @Value("${api.bytedance.api-prefix}")
|
|
|
- private String bytedanceApiUrl;
|
|
|
+ @Value("${api.bytedance.api-prefix}")
|
|
|
+ private String bytedanceApiUrl;
|
|
|
|
|
|
- private String urlPath = "http://192.168.0.202:8765/webhook/bytedance_account_report";
|
|
|
+ private String urlPath = "http://192.168.0.202:8765/webhook/bytedance_account_report";
|
|
|
|
|
|
- @Autowired private IByteDanceAdvertisePlanService advertisePlanService;
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceAdvertisePlanService advertisePlanService;
|
|
|
|
|
|
- @Autowired private IByteDanceAdvertiserPlanDailyService planDailyService;
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceAdvertiserPlanDailyService planDailyService;
|
|
|
|
|
|
- @Autowired private IByteDanceAdvertiserPlanHourlyService planHourlyService;
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceAdvertiserPlanHourlyService planHourlyService;
|
|
|
|
|
|
- @Autowired private IByteDanceAdvertiserDailyService advertiserDailyService;
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceAdvertiserDailyService advertiserDailyService;
|
|
|
|
|
|
- @Autowired private IByteDanceAdvertiserHourlyService advertiserHourlyService;
|
|
|
+ @Autowired
|
|
|
+ private IByteDanceAdvertiserHourlyService advertiserHourlyService;
|
|
|
|
|
|
- @Autowired private IBytedanceAgentReportDailyService agentDailyService;
|
|
|
+ @Autowired
|
|
|
+ private IBytedanceAgentReportDailyService agentDailyService;
|
|
|
|
|
|
- @Autowired private IBytedanceAgentReportHourlyService agentHourlyService;
|
|
|
+ @Autowired
|
|
|
+ private IBytedanceAgentReportHourlyService agentHourlyService;
|
|
|
|
|
|
- @Autowired DataMapper dataMapper;
|
|
|
+ @Autowired
|
|
|
+ DataMapper dataMapper;
|
|
|
|
|
|
- public void getAd(OauthToken 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);
|
|
|
+ public void getAd(OauthToken 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 = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_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);
|
|
|
- }
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_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);
|
|
|
- }
|
|
|
- advertisePlanService.saveOrUpdate(advertisePlan);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ advertisePlanService.saveOrUpdate(advertisePlan);
|
|
|
+ }
|
|
|
+ getAd(token, pageNum + 1, ids, date, updateDate);
|
|
|
}
|
|
|
- getAd(token, pageNum + 1, ids, date, updateDate);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<String, Object> getAdvertiserPlan(
|
|
|
- OauthToken token, String ids, String date, String updateDate) {
|
|
|
- getAd(token, 1, ids, date, updateDate);
|
|
|
- Map<String, Object> resultMap = new HashMap<>();
|
|
|
- resultMap.put("code", 0);
|
|
|
- resultMap.put("message", "获取广告计划信息成功");
|
|
|
- return resultMap;
|
|
|
- }
|
|
|
-
|
|
|
- /** ------------------------------------------------------------------获取广告计划 */
|
|
|
- @Override
|
|
|
- public void getAdvertiserPlanReport(
|
|
|
- OauthToken token, String startDate, String endDate, String bytedanceReportTypePl) {
|
|
|
-
|
|
|
- var conditions = getReportDTO(token, startDate, endDate, bytedanceReportTypePl);
|
|
|
- getPlanReportByPage(token, conditions, 1);
|
|
|
- }
|
|
|
-
|
|
|
- private ByteDanceAdvertiserReportDTO getReportDTO(
|
|
|
- OauthToken token, String startDate, String endDate, String bytedanceReportTypePl) {
|
|
|
- var conditions = new ByteDanceAdvertiserReportDTO();
|
|
|
- conditions.setAdvertiserId(token.getAccountId());
|
|
|
- conditions.setStartDate(startDate);
|
|
|
- conditions.setEndDate(endDate);
|
|
|
- conditions.setPageSize(1000);
|
|
|
- conditions.setTimeGranularity(bytedanceReportTypePl);
|
|
|
- return conditions;
|
|
|
- }
|
|
|
-
|
|
|
- private void getPlanReportByPage(
|
|
|
- OauthToken token, ByteDanceAdvertiserReportDTO conditions, int page) {
|
|
|
- SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
|
|
|
- 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;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getAdvertiserPlan(
|
|
|
+ OauthToken token, String ids, String date, String updateDate) {
|
|
|
+ getAd(token, 1, ids, date, updateDate);
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("code", 0);
|
|
|
+ resultMap.put("message", "获取广告计划信息成功");
|
|
|
+ return resultMap;
|
|
|
}
|
|
|
- Integer code = getObject.getInteger("code");
|
|
|
- var message = getObject.getString("message");
|
|
|
- if (null == code || code != 0) {
|
|
|
- log.error("广告计划报表数据获取异常=》account:{};message:{}", token.getAccountId(), message);
|
|
|
- return;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * ------------------------------------------------------------------获取广告计划
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getAdvertiserPlanReport(
|
|
|
+ OauthToken token, String startDate, String endDate, String bytedanceReportTypePl) {
|
|
|
+
|
|
|
+ var conditions = getReportDTO(token, startDate, endDate, bytedanceReportTypePl);
|
|
|
+ getPlanReportByPage(token, conditions, 1);
|
|
|
}
|
|
|
- var dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
- if (null == dataArray || dataArray.size() <= 0) {
|
|
|
- return;
|
|
|
+
|
|
|
+ private ByteDanceAdvertiserReportDTO getReportDTO(
|
|
|
+ OauthToken token, String startDate, String endDate, String bytedanceReportTypePl) {
|
|
|
+ var conditions = new ByteDanceAdvertiserReportDTO();
|
|
|
+ conditions.setAdvertiserId(token.getAccountId());
|
|
|
+ conditions.setStartDate(startDate);
|
|
|
+ conditions.setEndDate(endDate);
|
|
|
+ conditions.setPageSize(1000);
|
|
|
+ conditions.setTimeGranularity(bytedanceReportTypePl);
|
|
|
+ return conditions;
|
|
|
}
|
|
|
- List<ByteDanceAdvertisePlanHourlyReport> hourlyReports = new ArrayList<>();
|
|
|
- List<ByteDanceAdvertisePlanDailyReport> dailyReports = new ArrayList<>();
|
|
|
- for (var i = 0; i < dataArray.size(); i++) {
|
|
|
- var data = dataArray.getJSONObject(i);
|
|
|
- if (null != conditions.getTimeGranularity()
|
|
|
- && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
|
|
|
- // 时报
|
|
|
- ByteDanceAdvertisePlanHourlyReport hourlyReport =
|
|
|
- JSONObject.parseObject(data.toJSONString(), ByteDanceAdvertisePlanHourlyReport.class);
|
|
|
- hourlyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
- String hour = hourlyReport.getStatDatetime().substring(11, 13);
|
|
|
- hourlyReport.setStatDatetime(conditions.getStartDate().replace("-", ""));
|
|
|
- hourlyReport.setHour(Integer.parseInt(hour));
|
|
|
-
|
|
|
- ByteDanceAdvertisePlanHourlyReport hourlyByPrimaryKey =
|
|
|
- dataMapper.getHourlyByPrimaryKey(
|
|
|
- hourlyReport.getAdvertiserId(),
|
|
|
- hourlyReport.getCampaignId(),
|
|
|
- hourlyReport.getAdId(),
|
|
|
- Integer.parseInt(hourlyReport.getStatDatetime()),
|
|
|
- hourlyReport.getHour());
|
|
|
- if (hourlyByPrimaryKey != null && hourlyByPrimaryKey.getAdvertiserId() != null) {
|
|
|
- UpdateWrapper<ByteDanceAdvertisePlanHourlyReport> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper
|
|
|
- .eq("advertiser_id", hourlyReport.getAdvertiserId())
|
|
|
- .eq("campaign_id", hourlyReport.getCampaignId())
|
|
|
- .eq("ad_id", hourlyReport.getAdId())
|
|
|
- .eq("hour", hourlyReport.getHour())
|
|
|
- .eq("stat_datetime", hourlyReport.getStatDatetime());
|
|
|
- planHourlyService.update(hourlyReport, updateWrapper);
|
|
|
- } else {
|
|
|
- planHourlyService.save(hourlyReport);
|
|
|
+
|
|
|
+ private void getPlanReportByPage(
|
|
|
+ OauthToken token, ByteDanceAdvertiserReportDTO conditions, int page) {
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ 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;
|
|
|
}
|
|
|
- } else {
|
|
|
- // 日报
|
|
|
- if (data != null) {
|
|
|
- ByteDanceAdvertisePlanDailyReport dailyReport =
|
|
|
- JSONObject.parseObject(data.toJSONString(), ByteDanceAdvertisePlanDailyReport.class);
|
|
|
- dailyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
- dailyReport.setStatDatetime(conditions.getStartDate().replace("-", ""));
|
|
|
- ByteDanceAdvertisePlanDailyReport byPrimaryKey =
|
|
|
- dataMapper.getByPrimaryKey(
|
|
|
- dailyReport.getAdvertiserId(),
|
|
|
- dailyReport.getCampaignId(),
|
|
|
- dailyReport.getAdId(),
|
|
|
- Integer.parseInt(dailyReport.getStatDatetime()));
|
|
|
- if (byPrimaryKey != null && byPrimaryKey.getAdvertiserId() != null) {
|
|
|
- UpdateWrapper<ByteDanceAdvertisePlanDailyReport> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper
|
|
|
- .eq("advertiser_id", dailyReport.getAdvertiserId())
|
|
|
- .eq("campaign_id", dailyReport.getCampaignId())
|
|
|
- .eq("ad_id", dailyReport.getAdId())
|
|
|
- .eq("stat_datetime", dailyReport.getStatDatetime());
|
|
|
- planDailyService.update(dailyReport, updateWrapper);
|
|
|
- } else {
|
|
|
- planDailyService.save(dailyReport);
|
|
|
- }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ List<ByteDanceAdvertisePlanHourlyReport> hourlyReports = new ArrayList<>();
|
|
|
+ List<ByteDanceAdvertisePlanDailyReport> dailyReports = new ArrayList<>();
|
|
|
+ for (var i = 0; i < dataArray.size(); i++) {
|
|
|
+ var data = dataArray.getJSONObject(i);
|
|
|
+ if (null != conditions.getTimeGranularity()
|
|
|
+ && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
|
|
|
+ // 时报
|
|
|
+ ByteDanceAdvertisePlanHourlyReport hourlyReport =
|
|
|
+ JSONObject.parseObject(data.toJSONString(), ByteDanceAdvertisePlanHourlyReport.class);
|
|
|
+ hourlyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
+ String hour = hourlyReport.getStatDatetime().substring(11, 13);
|
|
|
+ hourlyReport.setStatDatetime(conditions.getStartDate().replace("-", ""));
|
|
|
+ hourlyReport.setHour(Integer.parseInt(hour));
|
|
|
+
|
|
|
+ ByteDanceAdvertisePlanHourlyReport hourlyByPrimaryKey =
|
|
|
+ dataMapper.getHourlyByPrimaryKey(
|
|
|
+ hourlyReport.getAdvertiserId(),
|
|
|
+ hourlyReport.getCampaignId(),
|
|
|
+ hourlyReport.getAdId(),
|
|
|
+ Integer.parseInt(hourlyReport.getStatDatetime()),
|
|
|
+ hourlyReport.getHour());
|
|
|
+ if (hourlyByPrimaryKey != null && hourlyByPrimaryKey.getAdvertiserId() != null) {
|
|
|
+ UpdateWrapper<ByteDanceAdvertisePlanHourlyReport> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper
|
|
|
+ .eq("advertiser_id", hourlyReport.getAdvertiserId())
|
|
|
+ .eq("campaign_id", hourlyReport.getCampaignId())
|
|
|
+ .eq("ad_id", hourlyReport.getAdId())
|
|
|
+ .eq("hour", hourlyReport.getHour())
|
|
|
+ .eq("stat_datetime", hourlyReport.getStatDatetime());
|
|
|
+ planHourlyService.update(hourlyReport, updateWrapper);
|
|
|
+ } else {
|
|
|
+ planHourlyService.save(hourlyReport);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 日报
|
|
|
+ if (data != null) {
|
|
|
+ ByteDanceAdvertisePlanDailyReport dailyReport =
|
|
|
+ JSONObject.parseObject(data.toJSONString(), ByteDanceAdvertisePlanDailyReport.class);
|
|
|
+ dailyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
+ dailyReport.setStatDatetime(conditions.getStartDate().replace("-", ""));
|
|
|
+ ByteDanceAdvertisePlanDailyReport byPrimaryKey =
|
|
|
+ dataMapper.getByPrimaryKey(
|
|
|
+ dailyReport.getAdvertiserId(),
|
|
|
+ dailyReport.getCampaignId(),
|
|
|
+ dailyReport.getAdId(),
|
|
|
+ Integer.parseInt(dailyReport.getStatDatetime()));
|
|
|
+ if (byPrimaryKey != null && byPrimaryKey.getAdvertiserId() != null) {
|
|
|
+ UpdateWrapper<ByteDanceAdvertisePlanDailyReport> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper
|
|
|
+ .eq("advertiser_id", dailyReport.getAdvertiserId())
|
|
|
+ .eq("campaign_id", dailyReport.getCampaignId())
|
|
|
+ .eq("ad_id", dailyReport.getAdId())
|
|
|
+ .eq("stat_datetime", dailyReport.getStatDatetime());
|
|
|
+ planDailyService.update(dailyReport, updateWrapper);
|
|
|
+ } else {
|
|
|
+ planDailyService.save(dailyReport);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- page++;
|
|
|
- int totalPage =
|
|
|
- getObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
- if (page <= totalPage) {
|
|
|
- getPlanReportByPage(token, conditions, page);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取广告计划报表信息
|
|
|
- *
|
|
|
- * @param token
|
|
|
- * @param conditions
|
|
|
- * @return
|
|
|
- */
|
|
|
- private JSONObject getAdStat(OauthToken token, JSONObject conditions) {
|
|
|
- // 请求地址
|
|
|
- String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_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);
|
|
|
- }
|
|
|
-
|
|
|
- /** -------------------------------------------------------------------------获取广告主 */
|
|
|
- @Override
|
|
|
- public void getAdvertiserReport(
|
|
|
- OauthToken token, String startDate, String endDate, String bytedanceReportTypePl) {
|
|
|
- var conditions = getReportDTO(token, startDate, endDate, bytedanceReportTypePl);
|
|
|
- getAdvertiserReportByPage(token, conditions, 1);
|
|
|
- }
|
|
|
-
|
|
|
- /** 获取广告主 */
|
|
|
- private void getAdvertiserReportByPage(
|
|
|
- OauthToken token, ByteDanceAdvertiserReportDTO conditions, Integer page) {
|
|
|
- log.info("获取账户报表,账户id:{}", token.getAccountId());
|
|
|
- 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;
|
|
|
+ page++;
|
|
|
+ int totalPage =
|
|
|
+ getObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
+ if (page <= totalPage) {
|
|
|
+ getPlanReportByPage(token, conditions, page);
|
|
|
+ }
|
|
|
}
|
|
|
- Integer code = getObject.getInteger("code");
|
|
|
- String message = getObject.getString("message");
|
|
|
- if (null == code || code != 0) {
|
|
|
- log.error("头条广告主数据获取异常:{}", message);
|
|
|
- return;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取广告计划报表信息
|
|
|
+ *
|
|
|
+ * @param token
|
|
|
+ * @param conditions
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private JSONObject getAdStat(OauthToken token, JSONObject conditions) {
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_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);
|
|
|
}
|
|
|
- JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
- if (null == dataArray || dataArray.isEmpty()) {
|
|
|
- return;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * -------------------------------------------------------------------------获取广告主
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getAdvertiserReport(
|
|
|
+ OauthToken token, String startDate, String endDate, String bytedanceReportTypePl) {
|
|
|
+ var conditions = getReportDTO(token, startDate, endDate, bytedanceReportTypePl);
|
|
|
+ getAdvertiserReportByPage(token, conditions, 1);
|
|
|
}
|
|
|
|
|
|
- for (int i = 0; i < dataArray.size(); i++) {
|
|
|
- JSONObject data = dataArray.getJSONObject(i);
|
|
|
- if (null != conditions.getTimeGranularity()
|
|
|
- && conditions.getTimeGranularity().equals(CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY)) {
|
|
|
- // 时报
|
|
|
- ByteDanceAdvertiseHourlyReport hourlyReport =
|
|
|
- JSONObject.parseObject(data.toJSONString(), ByteDanceAdvertiseHourlyReport.class);
|
|
|
- hourlyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
- String hour = hourlyReport.getStatDatetime().substring(11, 13);
|
|
|
- hourlyReport.setStatDatetime(conditions.getStartDate().replace("-", ""));
|
|
|
- hourlyReport.setHour(Integer.parseInt(hour));
|
|
|
-
|
|
|
- ByteDanceAdvertiseHourlyReport hourlyByPrimaryKey =
|
|
|
- dataMapper.getAdvertiseHourlyByPrimaryKey(
|
|
|
- hourlyReport.getAdvertiserId(),
|
|
|
- Integer.parseInt(hourlyReport.getStatDatetime()),
|
|
|
- hourlyReport.getHour());
|
|
|
- if (hourlyByPrimaryKey != null && hourlyByPrimaryKey.getAdvertiserId() != null) {
|
|
|
- UpdateWrapper<ByteDanceAdvertiseHourlyReport> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper
|
|
|
- .eq("advertiser_id", hourlyReport.getAdvertiserId())
|
|
|
- .eq("hour", hourlyReport.getHour())
|
|
|
- .eq("stat_datetime", hourlyReport.getStatDatetime());
|
|
|
- advertiserHourlyService.update(hourlyReport, updateWrapper);
|
|
|
- } else {
|
|
|
- advertiserHourlyService.save(hourlyReport);
|
|
|
+ /**
|
|
|
+ * 获取广告主
|
|
|
+ */
|
|
|
+ private void getAdvertiserReportByPage(
|
|
|
+ OauthToken token, ByteDanceAdvertiserReportDTO conditions, Integer page) {
|
|
|
+ log.info("获取账户报表,账户id:{}", token.getAccountId());
|
|
|
+ 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) {
|
|
|
+ log.error("头条广告主数据获取异常:{}", message);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
|
|
|
+ if (null == dataArray || dataArray.isEmpty()) {
|
|
|
+ return;
|
|
|
}
|
|
|
- } else {
|
|
|
- // 日报
|
|
|
- ByteDanceAdvertiseDailyReport dailyReport =
|
|
|
- JSONObject.parseObject(data.toJSONString(), ByteDanceAdvertiseDailyReport.class);
|
|
|
- dailyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
- dailyReport.setStatDatetime(conditions.getStartDate().replace("-", ""));
|
|
|
-
|
|
|
- ByteDanceAdvertiseDailyReport byPrimaryKey =
|
|
|
- dataMapper.getAdvertiseDailyByPrimaryKey(
|
|
|
- dailyReport.getAdvertiserId(), Integer.parseInt(dailyReport.getStatDatetime()));
|
|
|
- if (byPrimaryKey != null && byPrimaryKey.getAdvertiserId() != null) {
|
|
|
- UpdateWrapper<ByteDanceAdvertiseDailyReport> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper
|
|
|
- .eq("advertiser_id", dailyReport.getAdvertiserId())
|
|
|
- .eq("stat_datetime", dailyReport.getStatDatetime());
|
|
|
-
|
|
|
- advertiserDailyService.update(dailyReport, updateWrapper);
|
|
|
+
|
|
|
+ for (int i = 0; i < dataArray.size(); i++) {
|
|
|
+ JSONObject data = dataArray.getJSONObject(i);
|
|
|
+ if (null != conditions.getTimeGranularity()
|
|
|
+ && conditions.getTimeGranularity().equals(CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY)) {
|
|
|
+ // 时报
|
|
|
+ ByteDanceAdvertiseHourlyReport hourlyReport =
|
|
|
+ JSONObject.parseObject(data.toJSONString(), ByteDanceAdvertiseHourlyReport.class);
|
|
|
+ hourlyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
+ String hour = hourlyReport.getStatDatetime().substring(11, 13);
|
|
|
+ hourlyReport.setStatDatetime(conditions.getStartDate().replace("-", ""));
|
|
|
+ hourlyReport.setHour(Integer.parseInt(hour));
|
|
|
+
|
|
|
+ ByteDanceAdvertiseHourlyReport hourlyByPrimaryKey =
|
|
|
+ dataMapper.getAdvertiseHourlyByPrimaryKey(
|
|
|
+ hourlyReport.getAdvertiserId(),
|
|
|
+ Integer.parseInt(hourlyReport.getStatDatetime()),
|
|
|
+ hourlyReport.getHour());
|
|
|
+ if (hourlyByPrimaryKey != null && hourlyByPrimaryKey.getAdvertiserId() != null) {
|
|
|
+ UpdateWrapper<ByteDanceAdvertiseHourlyReport> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper
|
|
|
+ .eq("advertiser_id", hourlyReport.getAdvertiserId())
|
|
|
+ .eq("hour", hourlyReport.getHour())
|
|
|
+ .eq("stat_datetime", hourlyReport.getStatDatetime());
|
|
|
+ advertiserHourlyService.update(hourlyReport, updateWrapper);
|
|
|
+ } else {
|
|
|
+ advertiserHourlyService.save(hourlyReport);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 日报
|
|
|
+ ByteDanceAdvertiseDailyReport dailyReport =
|
|
|
+ JSONObject.parseObject(data.toJSONString(), ByteDanceAdvertiseDailyReport.class);
|
|
|
+ dailyReport.setAdvertiserId(conditions.getAdvertiserId());
|
|
|
+ dailyReport.setStatDatetime(conditions.getStartDate().replace("-", ""));
|
|
|
+
|
|
|
+ ByteDanceAdvertiseDailyReport byPrimaryKey =
|
|
|
+ dataMapper.getAdvertiseDailyByPrimaryKey(
|
|
|
+ dailyReport.getAdvertiserId(), Integer.parseInt(dailyReport.getStatDatetime()));
|
|
|
+ if (byPrimaryKey != null && byPrimaryKey.getAdvertiserId() != null) {
|
|
|
+ UpdateWrapper<ByteDanceAdvertiseDailyReport> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper
|
|
|
+ .eq("advertiser_id", dailyReport.getAdvertiserId())
|
|
|
+ .eq("stat_datetime", dailyReport.getStatDatetime());
|
|
|
+
|
|
|
+ advertiserDailyService.update(dailyReport, updateWrapper);
|
|
|
+ } else {
|
|
|
+ advertiserDailyService.save(dailyReport);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ page++;
|
|
|
+ int totalPage =
|
|
|
+ getObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
+ if (page <= totalPage) {
|
|
|
+ getAdvertiserReportByPage(token, conditions, page);
|
|
|
} else {
|
|
|
- advertiserDailyService.save(dailyReport);
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("advertiser_id", token.getAccountId());
|
|
|
+ param.put("start_date", conditions.getStartDate().replace("-", ""));
|
|
|
+ param.put("end_date", conditions.getEndDate().replace("-", ""));
|
|
|
+ if (null != conditions.getTimeGranularity()
|
|
|
+ && conditions.getTimeGranularity().equals(CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY)) {
|
|
|
+ param.put("date_type", "hourly");
|
|
|
+ } else {
|
|
|
+ param.put("date_type", "daily");
|
|
|
+ }
|
|
|
+
|
|
|
+ String s = HttpUtils.httpPostRequest(urlPath, param, null);
|
|
|
+ log.info("调用接口成功");
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- page++;
|
|
|
- int totalPage =
|
|
|
- getObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
- if (page <= totalPage) {
|
|
|
- getAdvertiserReportByPage(token, conditions, page);
|
|
|
- } else {
|
|
|
- JSONObject param = new JSONObject();
|
|
|
- param.put("advertiser_id", token.getAccountId());
|
|
|
- param.put("start_date", conditions.getStartDate().replace("-", ""));
|
|
|
- param.put("end_date", conditions.getEndDate().replace("-", ""));
|
|
|
- if (null != conditions.getTimeGranularity()
|
|
|
- && conditions.getTimeGranularity().equals(CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY)) {
|
|
|
- param.put("date_type", "hourly");
|
|
|
- } else {
|
|
|
- param.put("date_type", "daily");
|
|
|
- }
|
|
|
-
|
|
|
- String s = HttpUtils.httpPostRequest(urlPath, param, null);
|
|
|
- log.info("调用接口成功");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取广告主报表信息
|
|
|
- *
|
|
|
- * @param token
|
|
|
- * @param conditions
|
|
|
- * @return
|
|
|
- */
|
|
|
- public JSONObject getAdvertiserStat(OauthToken token, JSONObject conditions) {
|
|
|
- // 请求地址
|
|
|
- String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_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 getAgentReport(
|
|
|
- OauthToken token, String startDate, String endDate, String bytedanceReportTypePl) {
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- if (CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY.equals(bytedanceReportTypePl)) {
|
|
|
- // 日报
|
|
|
- jsonObject.put("agent_id", token.getAccountId());
|
|
|
- jsonObject.put("start_date", startDate);
|
|
|
- jsonObject.put("end_date", endDate);
|
|
|
- jsonObject.put("page_size", 1000);
|
|
|
- jsonObject.put("timeGranularity", bytedanceReportTypePl);
|
|
|
- } else {
|
|
|
- // 时报
|
|
|
- jsonObject.put("agent_id", token.getAccountId());
|
|
|
- jsonObject.put("page_size", 1000);
|
|
|
- jsonObject.put("timeGranularity", bytedanceReportTypePl);
|
|
|
}
|
|
|
|
|
|
- getAgentReportByPage(token, jsonObject, 1);
|
|
|
- }
|
|
|
-
|
|
|
- /** 获取代理商 */
|
|
|
- private void getAgentReportByPage(OauthToken token, JSONObject conditions, Integer page) {
|
|
|
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
|
|
|
- String hour = simpleDateFormat.format(new Date());
|
|
|
- String nowDate = DateUtils.getNowDate("yyyyMMdd");
|
|
|
- conditions.put("page", page);
|
|
|
- SerializeConfig config = new SerializeConfig();
|
|
|
- config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
- JSONObject getObject = getAgentStat(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;
|
|
|
+ /**
|
|
|
+ * 获取广告主报表信息
|
|
|
+ *
|
|
|
+ * @param token
|
|
|
+ * @param conditions
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getAdvertiserStat(OauthToken token, JSONObject conditions) {
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_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);
|
|
|
}
|
|
|
|
|
|
- for (int i = 0; i < dataArray.size(); i++) {
|
|
|
- JSONObject data = dataArray.getJSONObject(i);
|
|
|
- if (null != conditions.get("timeGranularity")
|
|
|
- && conditions
|
|
|
- .get("timeGranularity")
|
|
|
- .equals(CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY)) {
|
|
|
- // 时报
|
|
|
- BytedanceAgentReportHourly hourlyReport =
|
|
|
- JSONObject.parseObject(data.toJSONString(), BytedanceAgentReportHourly.class);
|
|
|
- hourlyReport.setStatDatetime(nowDate);
|
|
|
- hourlyReport.setHour(Integer.parseInt(hour));
|
|
|
- BytedanceAgentReportHourly hourlyByPrimaryKey =
|
|
|
- dataMapper.getAgentHourlyByPrimaryKey(
|
|
|
- hourlyReport.getAdvertiserId(),
|
|
|
- hourlyReport.getAgentId(),
|
|
|
- hourlyReport.getStatDatetime(),
|
|
|
- hourlyReport.getHour());
|
|
|
- if (hourlyByPrimaryKey != null && hourlyByPrimaryKey.getAdvertiserId() != null) {
|
|
|
- UpdateWrapper<BytedanceAgentReportHourly> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper
|
|
|
- .eq("advertiser_id", hourlyReport.getAdvertiserId())
|
|
|
- .eq("agent_id", hourlyReport.getAgentId())
|
|
|
- .eq("hour", hourlyReport.getHour())
|
|
|
- .eq("stat_datetime", hourlyReport.getStatDatetime());
|
|
|
- agentHourlyService.update(hourlyReport, updateWrapper);
|
|
|
+ /**
|
|
|
+ * -------------------------------------------------------------------------获取代理商
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getAgentReport(
|
|
|
+ OauthToken token, String startDate, String endDate, String bytedanceReportTypePl) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ if (CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY.equals(bytedanceReportTypePl)) {
|
|
|
+ // 日报
|
|
|
+ jsonObject.put("agent_id", token.getAccountId());
|
|
|
+ jsonObject.put("start_date", startDate);
|
|
|
+ jsonObject.put("end_date", endDate);
|
|
|
+ jsonObject.put("page_size", 1000);
|
|
|
+ jsonObject.put("timeGranularity", bytedanceReportTypePl);
|
|
|
} else {
|
|
|
- agentHourlyService.save(hourlyReport);
|
|
|
+ // 时报
|
|
|
+ jsonObject.put("agent_id", token.getAccountId());
|
|
|
+ jsonObject.put("page_size", 1000);
|
|
|
+ jsonObject.put("timeGranularity", bytedanceReportTypePl);
|
|
|
}
|
|
|
- } else {
|
|
|
- // 日报
|
|
|
- BytedanceAgentReportDaily dailyReport =
|
|
|
- JSONObject.parseObject(data.toJSONString(), BytedanceAgentReportDaily.class);
|
|
|
- dailyReport.setStatDatetime(((String) conditions.get("start_date")).replace("-", ""));
|
|
|
- BytedanceAgentReportDaily byPrimaryKey =
|
|
|
- dataMapper.getAgentDailyByPrimaryKey(
|
|
|
- dailyReport.getAdvertiserId(),
|
|
|
- dailyReport.getAgentId(),
|
|
|
- Integer.parseInt(dailyReport.getStatDatetime()));
|
|
|
- if (byPrimaryKey != null && byPrimaryKey.getAdvertiserId() != null) {
|
|
|
- UpdateWrapper<BytedanceAgentReportDaily> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper
|
|
|
- .eq("advertiser_id", dailyReport.getAdvertiserId())
|
|
|
- .eq("agent_id", dailyReport.getAgentId())
|
|
|
- .eq("stat_datetime", dailyReport.getStatDatetime());
|
|
|
- agentDailyService.update(dailyReport, updateWrapper);
|
|
|
- } else {
|
|
|
- agentDailyService.save(dailyReport);
|
|
|
+
|
|
|
+ getAgentReportByPage(token, jsonObject, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取代理商
|
|
|
+ */
|
|
|
+ private void getAgentReportByPage(OauthToken token, JSONObject conditions, Integer page) {
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
|
|
|
+ String hour = simpleDateFormat.format(new Date());
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyyMMdd");
|
|
|
+ conditions.put("page", page);
|
|
|
+ SerializeConfig config = new SerializeConfig();
|
|
|
+ config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
|
|
|
+ JSONObject getObject = getAgentStat(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.get("timeGranularity")
|
|
|
+ && conditions
|
|
|
+ .get("timeGranularity")
|
|
|
+ .equals(CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY)) {
|
|
|
+ // 时报
|
|
|
+ BytedanceAgentReportHourly hourlyReport =
|
|
|
+ JSONObject.parseObject(data.toJSONString(), BytedanceAgentReportHourly.class);
|
|
|
+ hourlyReport.setStatDatetime(nowDate);
|
|
|
+ hourlyReport.setHour(Integer.parseInt(hour));
|
|
|
+ BytedanceAgentReportHourly hourlyByPrimaryKey =
|
|
|
+ dataMapper.getAgentHourlyByPrimaryKey(
|
|
|
+ hourlyReport.getAdvertiserId(),
|
|
|
+ hourlyReport.getAgentId(),
|
|
|
+ hourlyReport.getStatDatetime(),
|
|
|
+ hourlyReport.getHour());
|
|
|
+ if (hourlyByPrimaryKey != null && hourlyByPrimaryKey.getAdvertiserId() != null) {
|
|
|
+ UpdateWrapper<BytedanceAgentReportHourly> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper
|
|
|
+ .eq("advertiser_id", hourlyReport.getAdvertiserId())
|
|
|
+ .eq("agent_id", hourlyReport.getAgentId())
|
|
|
+ .eq("hour", hourlyReport.getHour())
|
|
|
+ .eq("stat_datetime", hourlyReport.getStatDatetime());
|
|
|
+ agentHourlyService.update(hourlyReport, updateWrapper);
|
|
|
+ } else {
|
|
|
+ agentHourlyService.save(hourlyReport);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 日报
|
|
|
+ BytedanceAgentReportDaily dailyReport =
|
|
|
+ JSONObject.parseObject(data.toJSONString(), BytedanceAgentReportDaily.class);
|
|
|
+ dailyReport.setStatDatetime(((String) conditions.get("start_date")).replace("-", ""));
|
|
|
+ BytedanceAgentReportDaily byPrimaryKey =
|
|
|
+ dataMapper.getAgentDailyByPrimaryKey(
|
|
|
+ dailyReport.getAdvertiserId(),
|
|
|
+ dailyReport.getAgentId(),
|
|
|
+ Integer.parseInt(dailyReport.getStatDatetime()));
|
|
|
+ if (byPrimaryKey != null && byPrimaryKey.getAdvertiserId() != null) {
|
|
|
+ UpdateWrapper<BytedanceAgentReportDaily> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper
|
|
|
+ .eq("advertiser_id", dailyReport.getAdvertiserId())
|
|
|
+ .eq("agent_id", dailyReport.getAgentId())
|
|
|
+ .eq("stat_datetime", dailyReport.getStatDatetime());
|
|
|
+ agentDailyService.update(dailyReport, updateWrapper);
|
|
|
+ } else {
|
|
|
+ agentDailyService.save(dailyReport);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ page++;
|
|
|
+ int totalPage =
|
|
|
+ getObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
+ if (page <= totalPage) {
|
|
|
+ getAgentReportByPage(token, conditions, page);
|
|
|
}
|
|
|
- }
|
|
|
}
|
|
|
- page++;
|
|
|
- int totalPage =
|
|
|
- getObject.getJSONObject("data").getJSONObject("page_info").getInteger("total_page");
|
|
|
- if (page <= totalPage) {
|
|
|
- getAgentReportByPage(token, conditions, page);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取获取代理商报表信息
|
|
|
+ *
|
|
|
+ * @param token
|
|
|
+ * @param conditions
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getAgentStat(OauthToken token, JSONObject conditions) {
|
|
|
+ // 请求地址
|
|
|
+ String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_REPORT_AGENT_GET_V2;
|
|
|
+ return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, conditions);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取获取代理商报表信息
|
|
|
- *
|
|
|
- * @param token
|
|
|
- * @param conditions
|
|
|
- * @return
|
|
|
- */
|
|
|
- public JSONObject getAgentStat(OauthToken token, JSONObject conditions) {
|
|
|
- // 请求地址
|
|
|
- String url = bytedanceApiUrl + BytedanceConstant.BYTEDANCE_V2_REPORT_AGENT_GET_V2;
|
|
|
- return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, conditions);
|
|
|
- }
|
|
|
}
|