|
@@ -1,12 +1,19 @@
|
|
|
package cn.com.ctop.toutiao.modules.report.service.impl;
|
|
|
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
+import cn.com.ctop.common.module.entity.UserAllocation;
|
|
|
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
|
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
-import cn.com.ctop.common.module.utils.LoadFileUtil;
|
|
|
+import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyAccount;
|
|
|
+import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
|
|
|
+import cn.com.ctop.kuaishou.modules.utils.DownloadUtils;
|
|
|
+import cn.com.ctop.toutiao.modules.report.entity.BytedanceAdvertiserDailyReport;
|
|
|
import cn.com.ctop.toutiao.modules.report.entity.BytedanceDailyReportTask;
|
|
|
import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportMaterialDaily;
|
|
|
import cn.com.ctop.toutiao.modules.report.entity.BytedanceReportMaterialRetry;
|
|
|
+import cn.com.ctop.toutiao.modules.report.mapper.BytedanceAdvertiserDailyReportMapper;
|
|
|
import cn.com.ctop.toutiao.modules.report.mapper.BytedanceDailyReportTaskMapper;
|
|
|
import cn.com.ctop.toutiao.modules.report.mapper.BytedanceReportMapper;
|
|
|
import cn.com.ctop.toutiao.modules.report.mapper.BytedanceReportMaterialDailyMapper;
|
|
@@ -17,24 +24,14 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.http.client.ClientProtocolException;
|
|
|
-import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
-import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
|
|
-import org.apache.http.entity.ContentType;
|
|
|
-import org.apache.http.entity.StringEntity;
|
|
|
-import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
-import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStreamReader;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.net.URI;
|
|
|
+import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -43,20 +40,197 @@ import java.util.Map;
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
+
|
|
|
@Value("${jeecg.path.report-history}")
|
|
|
private String downloadPath;
|
|
|
@Autowired
|
|
|
+ private UserAllocationMapper userAllocationMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BytedanceAdvertiserDailyReportMapper bytedanceAdvertiserDailyReportMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private BytedanceReportMapper reportMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private KuaishouReportDailyAccountMapper kuaishouReportDailyAccountMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private BytedanceDailyReportTaskMapper bytedanceDailyReportTaskMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IBytedanceDailyReportTaskService bytedanceDailyReportTaskService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ICtopOauthTokenService ctopOauthTokenService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private BytedanceReportMaterialDailyMapper bytedanceReportMaterialDailyMapper;
|
|
|
|
|
|
- private static final String SIMPLE_DATE_FORMAT_YYYY_MM_DD = "yyyy-MM-dd";
|
|
|
+ /**
|
|
|
+ * 媒体昨日总消耗
|
|
|
+ *
|
|
|
+ * @param loginId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONObject getAccountReport(String loginId) {
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
+ QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("user_id", loginId);
|
|
|
+ queryWrapper.isNotNull("account_id");
|
|
|
+ queryWrapper.groupBy("account_id");
|
|
|
+ List<UserAllocation> userAllocations = userAllocationMapper.selectList(queryWrapper);
|
|
|
+ if (!Check.isNull(userAllocations)) {
|
|
|
+ // 头条相关
|
|
|
+ JSONObject bytedanceJson = new JSONObject();
|
|
|
+ BigDecimal byteDanceCost = new BigDecimal(0);
|
|
|
+ Long byteDanceClick = 0L;
|
|
|
+ Long byteDanceShow = 0L;
|
|
|
+ Long byteDanceConvert = 0L;
|
|
|
+ Long byteDanceForm = 0L;
|
|
|
+ Long byteDanceNextDayOpen = 0L;
|
|
|
+ Long byteDanceActive = 0L;
|
|
|
+ JSONArray bytedanceDetail = new JSONArray();
|
|
|
+
|
|
|
+ // 快手相关
|
|
|
+ JSONArray kuaishouDetail = new JSONArray();
|
|
|
+ JSONObject kuaishouJson = new JSONObject();
|
|
|
+ BigDecimal kuaishouCost = new BigDecimal(0);
|
|
|
+
|
|
|
+ Long kuaishouClick = 0L;
|
|
|
+ Long kuaishouShow = 0L;
|
|
|
+ Long kuaishouConvert = 0L;
|
|
|
+ Long kuaishouForm = 0L;
|
|
|
+ Long kuaishouNextDayOpen = 0L;
|
|
|
+ Long kuaishouActive = 0L;
|
|
|
+
|
|
|
+
|
|
|
+ for (UserAllocation userAllocation : userAllocations) {
|
|
|
+ if ("1".equals(userAllocation.getMediaId())) {
|
|
|
+ QueryWrapper<BytedanceAdvertiserDailyReport> bytedanceAdvertiserDailyReportQueryWrapper = new QueryWrapper<>();
|
|
|
+ bytedanceAdvertiserDailyReportQueryWrapper.eq("advertiser_id", userAllocation.getAccountId());
|
|
|
+ bytedanceAdvertiserDailyReportQueryWrapper.between("stat_datetime", "2019-07-01 00:00:00", "2019-07-01 23:59:59");
|
|
|
+ bytedanceAdvertiserDailyReportQueryWrapper.orderByDesc("create_time");
|
|
|
+ bytedanceAdvertiserDailyReportQueryWrapper.last("limit 1");
|
|
|
+ BytedanceAdvertiserDailyReport bytedanceAdvertiserDailyReport = bytedanceAdvertiserDailyReportMapper.selectOne(bytedanceAdvertiserDailyReportQueryWrapper);
|
|
|
+ if (!Check.isNull(bytedanceAdvertiserDailyReport)) {
|
|
|
+ JSONObject bytedanceDetailJson = new JSONObject();
|
|
|
+ BigDecimal cost = bytedanceAdvertiserDailyReport.getCost();
|
|
|
+ // 账号总消耗
|
|
|
+ bytedanceDetailJson.put("cost", cost);
|
|
|
+ byteDanceCost = byteDanceCost.add(cost);
|
|
|
+ Long click = bytedanceAdvertiserDailyReport.getClick();
|
|
|
+ // 账号总点击
|
|
|
+ bytedanceDetailJson.put("click", click);
|
|
|
+ byteDanceClick += click;
|
|
|
+ Long showNum = bytedanceAdvertiserDailyReport.getShowNum();
|
|
|
+ // 账号总展示
|
|
|
+ bytedanceDetailJson.put("show", showNum);
|
|
|
+ byteDanceShow += showNum;
|
|
|
+ Long convertNum = bytedanceAdvertiserDailyReport.getConvertNum();
|
|
|
+ // 账号总转化
|
|
|
+ bytedanceDetailJson.put("convert", convertNum);
|
|
|
+ byteDanceConvert += convertNum;
|
|
|
+ Long form = bytedanceAdvertiserDailyReport.getForm();
|
|
|
+ // 账号总表单提交
|
|
|
+ bytedanceDetailJson.put("form", form);
|
|
|
+ byteDanceForm += form;
|
|
|
+ Long nextDayOpen = bytedanceAdvertiserDailyReport.getNextDayOpen();
|
|
|
+ // 账号总次日留存
|
|
|
+ bytedanceDetailJson.put("nextDayOpen", nextDayOpen);
|
|
|
+ byteDanceNextDayOpen += nextDayOpen;
|
|
|
+ Long active = bytedanceAdvertiserDailyReport.getActive();
|
|
|
+ // 账号总激活
|
|
|
+ bytedanceDetailJson.put("active", active);
|
|
|
+ byteDanceActive += active;
|
|
|
+ // 账号
|
|
|
+ bytedanceDetailJson.put("accountId", userAllocation.getAccountId());
|
|
|
+ // 账号 名称
|
|
|
+ bytedanceDetailJson.put("accountName", userAllocation.getAuthName());
|
|
|
+ bytedanceDetail.add(bytedanceDetailJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if ("2".equals(userAllocation.getMediaId())) {
|
|
|
+ // 查询快手相关报表数据
|
|
|
+ QueryWrapper<KuaishouReportDailyAccount> kuaishouReportDailyAccountQueryWrapper = new QueryWrapper<>();
|
|
|
+ kuaishouReportDailyAccountQueryWrapper.eq("account_id", userAllocation.getAccountId());
|
|
|
+ kuaishouReportDailyAccountQueryWrapper.between("stat_date", "2019-10-08 00:00:00", "2019-10-08 23:59:59");
|
|
|
+ kuaishouReportDailyAccountQueryWrapper.orderByDesc("create_time");
|
|
|
+ kuaishouReportDailyAccountQueryWrapper.last("limit 1");
|
|
|
+ KuaishouReportDailyAccount reportDailyAccount = kuaishouReportDailyAccountMapper.selectOne(kuaishouReportDailyAccountQueryWrapper);
|
|
|
+ if (!Check.isNull(reportDailyAccount)) {
|
|
|
+ JSONObject kuaishouDetailJson = new JSONObject();
|
|
|
+ kuaishouDetailJson.put("accountId", userAllocation.getAccountId());
|
|
|
+ kuaishouDetailJson.put("accountName", userAllocation.getAuthName());
|
|
|
+
|
|
|
+ // 花费
|
|
|
+ BigDecimal cost = reportDailyAccount.getCharge();
|
|
|
+ kuaishouDetailJson.put("cost", cost);
|
|
|
+ kuaishouCost = kuaishouCost.add(cost);
|
|
|
+
|
|
|
+ Long click = reportDailyAccount.getAclick();
|
|
|
+ kuaishouDetailJson.put("click", click);
|
|
|
+ kuaishouClick += click;
|
|
|
+
|
|
|
+ Long show = reportDailyAccount.getPhotoShow();
|
|
|
+ kuaishouDetailJson.put("show", show);
|
|
|
+ kuaishouShow += show;
|
|
|
+
|
|
|
+ Long convert = reportDailyAccount.getBclick();
|
|
|
+ kuaishouDetailJson.put("convert", convert);
|
|
|
+ kuaishouConvert += convert;
|
|
|
+
|
|
|
+ Long form = reportDailyAccount.getSubmit();
|
|
|
+ kuaishouDetailJson.put("form", form);
|
|
|
+ kuaishouForm += form;
|
|
|
+
|
|
|
+
|
|
|
+ Long active = reportDailyAccount.getActivation();
|
|
|
+ kuaishouDetailJson.put("active", active);
|
|
|
+ kuaishouActive += active;
|
|
|
+
|
|
|
+ kuaishouDetail.add(kuaishouDetailJson);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 总消耗
|
|
|
+ bytedanceJson.put("cost", byteDanceCost);
|
|
|
+ // 总点击
|
|
|
+ bytedanceJson.put("click", byteDanceClick);
|
|
|
+ // 总展示
|
|
|
+ bytedanceJson.put("show", byteDanceShow);
|
|
|
+ // 总转化
|
|
|
+ bytedanceJson.put("convert", byteDanceConvert);
|
|
|
+ // 总表单提交
|
|
|
+ bytedanceJson.put("form", byteDanceForm);
|
|
|
+ // 总次留数
|
|
|
+ bytedanceJson.put("nextDayOpen", byteDanceNextDayOpen);
|
|
|
+ // 总激活
|
|
|
+ bytedanceJson.put("active", byteDanceActive);
|
|
|
+
|
|
|
+ returnJson.put("bytedance", bytedanceJson);
|
|
|
+ returnJson.put("bytedanceDetail", bytedanceDetail);
|
|
|
+
|
|
|
+
|
|
|
+ kuaishouJson.put("cost", kuaishouCost);
|
|
|
+ kuaishouJson.put("click", kuaishouClick);
|
|
|
+ kuaishouJson.put("show", kuaishouShow);
|
|
|
+ kuaishouJson.put("convert", kuaishouConvert);
|
|
|
+ kuaishouJson.put("form", kuaishouForm);
|
|
|
+ kuaishouJson.put("nextDayOpen", 0);
|
|
|
+ kuaishouJson.put("active", kuaishouActive);
|
|
|
+ returnJson.put("kuaishou", kuaishouJson);
|
|
|
+ returnJson.put("kuaishouDetail", kuaishouDetail);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return returnJson;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 快手-大盘报表
|
|
|
*
|
|
@@ -68,16 +242,16 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
Integer type = requestJson.getInteger("type");
|
|
|
JSONObject accountJson = new JSONObject();
|
|
|
try {
|
|
|
- String nowDate = DateUtils.getNowDate(SIMPLE_DATE_FORMAT_YYYY_MM_DD);
|
|
|
- String anotherDay = DateUtils.getAnotherDay(SIMPLE_DATE_FORMAT_YYYY_MM_DD, nowDate, -1);
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
+ String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
|
|
|
if (type == 1) {
|
|
|
// 今日总消耗
|
|
|
JSONObject nowJson = reportMapper.selectDayReport(nowDate);
|
|
|
- if (null == nowJson) {
|
|
|
+ if (Check.isNull(nowJson)) {
|
|
|
return accountJson;
|
|
|
}
|
|
|
- Integer maxHour = nowJson.getInteger("maxHour");
|
|
|
- if (null == maxHour || maxHour == 0) {
|
|
|
+ int maxHour = nowJson.getInteger("maxHour");
|
|
|
+ if (maxHour == 0 || Check.isNull(maxHour)) {
|
|
|
return accountJson;
|
|
|
}
|
|
|
String maxHourStr = String.valueOf(maxHour - 1);
|
|
@@ -138,19 +312,19 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
} else if (type == 2) {
|
|
|
accountJson = reportMapper.selectDayReport(anotherDay);
|
|
|
} else if (type == 3) {
|
|
|
- String endDate = DateUtils.getAnotherDay(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -6);
|
|
|
+ String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -6);
|
|
|
accountJson = reportMapper.selectByDate(anotherDay, endDate);
|
|
|
} else if (type == 4) {
|
|
|
- String endDate = DateUtils.getAnotherDay(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -14);
|
|
|
+ String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -14);
|
|
|
accountJson = reportMapper.selectByDate(anotherDay, endDate);
|
|
|
} else if (type == 5) {
|
|
|
- String endDate = DateUtils.getMonthBefore(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -1);
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -1);
|
|
|
accountJson = reportMapper.selectByDate(anotherDay, endDate);
|
|
|
} else if (type == 6) {
|
|
|
- String endDate = DateUtils.getMonthBefore(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -3);
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -3);
|
|
|
accountJson = reportMapper.selectByDate(anotherDay, endDate);
|
|
|
} else if (type == 7) {
|
|
|
- String endDate = DateUtils.getMonthBefore(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -6);
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -6);
|
|
|
accountJson = reportMapper.selectByDate(anotherDay, endDate);
|
|
|
} else if (type == 8) {
|
|
|
accountJson = reportMapper.selectAllAccount();
|
|
@@ -166,11 +340,11 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
JSONObject comparedJson = new JSONObject();
|
|
|
|
|
|
if ("month".equals(sign)) {
|
|
|
- Map<String, Object> dateMap = DateUtils.compareDate(SIMPLE_DATE_FORMAT_YYYY_MM_DD, bigDate, smallDate);
|
|
|
+ Map<String, Object> dateMap = DateUtils.compareDate("yyyy-MM", bigDate, smallDate);
|
|
|
beComparedJson = reportMapper.selectMonthReportByDate((String) dateMap.get("smallDate"));
|
|
|
comparedJson = reportMapper.selectMonthReportByDate((String) dateMap.get("bigDate"));
|
|
|
} else if ("day".equals(sign)) {
|
|
|
- Map<String, Object> dateMap = DateUtils.compareDate(SIMPLE_DATE_FORMAT_YYYY_MM_DD, bigDate, smallDate);
|
|
|
+ Map<String, Object> dateMap = DateUtils.compareDate("yyyy-MM-dd", bigDate, smallDate);
|
|
|
beComparedJson = reportMapper.selectDayReportByDate((String) dateMap.get("smallDate"));
|
|
|
comparedJson = reportMapper.selectDayReportByDate((String) dateMap.get("bigDate"));
|
|
|
}
|
|
@@ -226,8 +400,8 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
Integer type = requestJson.getInteger("type");
|
|
|
List<JSONObject> detail = new ArrayList<>();
|
|
|
try {
|
|
|
- String nowDate = DateUtils.getNowDate(SIMPLE_DATE_FORMAT_YYYY_MM_DD);
|
|
|
- String anotherDay = DateUtils.getAnotherDay(SIMPLE_DATE_FORMAT_YYYY_MM_DD, nowDate, -1);
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
+ String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
|
|
|
if (type == 1) {
|
|
|
// 今日明细
|
|
|
List<JSONObject> yesterdayDetail = reportMapper.selectReportDetail(anotherDay);
|
|
@@ -295,19 +469,19 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
} else if (type == 2) {
|
|
|
detail = reportMapper.selectReportDetail(anotherDay);
|
|
|
} else if (type == 3) {
|
|
|
- String endDate = DateUtils.getAnotherDay(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -6);
|
|
|
+ String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -6);
|
|
|
detail = reportMapper.selectDayDetailByDate(anotherDay, endDate);
|
|
|
} else if (type == 4) {
|
|
|
- String endDate = DateUtils.getAnotherDay(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -14);
|
|
|
+ String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -14);
|
|
|
detail = reportMapper.selectDayDetailByDate(anotherDay, endDate);
|
|
|
} else if (type == 5) {
|
|
|
- String endDate = DateUtils.getMonthBefore(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -1);
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -1);
|
|
|
detail = reportMapper.selectDayDetailByDate(anotherDay, endDate);
|
|
|
} else if (type == 6) {
|
|
|
- String endDate = DateUtils.getMonthBefore(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -3);
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -3);
|
|
|
detail = reportMapper.selectDayDetailByDate(anotherDay, endDate);
|
|
|
} else if (type == 7) {
|
|
|
- String endDate = DateUtils.getMonthBefore(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -6);
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -6);
|
|
|
detail = reportMapper.selectDayDetailByMonth(anotherDay, endDate);
|
|
|
} else if (type == 8) {
|
|
|
detail = reportMapper.selectAllDayDetailByMonth();
|
|
@@ -327,7 +501,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
comparedDate = (String) dateMap.get("smallDate");
|
|
|
comparedArr = reportMapper.selectDayDetailsByMonth((String) dateMap.get("bigDate"));
|
|
|
} else if ("day".equals(sign)) {
|
|
|
- Map<String, Object> dateMap = DateUtils.compareDate(SIMPLE_DATE_FORMAT_YYYY_MM_DD, bigDate, smallDate);
|
|
|
+ Map<String, Object> dateMap = DateUtils.compareDate("yyyy-MM-dd", bigDate, smallDate);
|
|
|
comparedDate = (String) dateMap.get("smallDate");
|
|
|
comparedArr = reportMapper.selectHourlyDetailsByDate((String) dateMap.get("bigDate"));
|
|
|
}
|
|
@@ -340,7 +514,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
String beComparedDate = "";
|
|
|
String statHour = "";
|
|
|
if ("month".equals(sign)) {
|
|
|
- String day = DateUtils.getDay(SIMPLE_DATE_FORMAT_YYYY_MM_DD, statDate);
|
|
|
+ String day = DateUtils.getDay("yyyy-MM-dd", statDate);
|
|
|
beComparedDate = comparedDate + "-" + day;
|
|
|
beComparedJson = reportMapper.selectDayDailyByDate(beComparedDate);
|
|
|
|
|
@@ -368,11 +542,11 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
BigDecimal comparedCost = beComparedJson.getBigDecimal("cost");
|
|
|
Long comparedPhotoShow = beComparedJson.getLong("photoShow");
|
|
|
Long comparedPhotoClick = beComparedJson.getLong("photoClick");
|
|
|
- Long comparedAclick = beComparedJson.getLong("aclick");
|
|
|
+ Long comparedAClick = beComparedJson.getLong("aclick");
|
|
|
json.put("beComparedCost", comparedCost);
|
|
|
json.put("beComparedPhotoShow", comparedPhotoShow);
|
|
|
json.put("beComparedPhotoClick", comparedPhotoClick);
|
|
|
- json.put("beComparedAClick", comparedAclick);
|
|
|
+ json.put("beComparedAClick", comparedAClick);
|
|
|
json.put("beComparedDate", beComparedDate);
|
|
|
|
|
|
if (comparedCost.compareTo(new BigDecimal(0)) != 0) {
|
|
@@ -393,8 +567,8 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
} else {
|
|
|
json.put("showProportion", 0);
|
|
|
}
|
|
|
- if (comparedAclick != 0L) {
|
|
|
- double aClickProportion = (aClick.doubleValue() - comparedAclick.doubleValue()) / comparedAclick.doubleValue();
|
|
|
+ if (comparedAClick != 0L) {
|
|
|
+ double aClickProportion = (aClick.doubleValue() - comparedAClick.doubleValue()) / comparedAClick.doubleValue();
|
|
|
json.put("comparedAclick", aClickProportion);
|
|
|
} else {
|
|
|
json.put("comparedAclick", 0);
|
|
@@ -422,8 +596,8 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
List<JSONObject> reportList = new ArrayList<>();
|
|
|
try {
|
|
|
Integer type = requestJson.getInteger("type");
|
|
|
- String nowDate = DateUtils.getNowDate(SIMPLE_DATE_FORMAT_YYYY_MM_DD);
|
|
|
- String anotherDay = DateUtils.getAnotherDay(SIMPLE_DATE_FORMAT_YYYY_MM_DD, nowDate, -1);
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
+ String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
|
|
|
if (type == 1) {
|
|
|
List<JSONObject> nowReportList = reportMapper.selectReportDetail(nowDate);
|
|
|
List<JSONObject> yesterdayReportList = reportMapper.selectReportDetail(anotherDay);
|
|
@@ -435,19 +609,19 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
} else if (type == 2) {
|
|
|
reportList = reportMapper.selectReportDetail(anotherDay);
|
|
|
} else if (type == 3) {
|
|
|
- String endDate = DateUtils.getAnotherDay(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -6);
|
|
|
+ String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -6);
|
|
|
reportList = reportMapper.selectDayDetailByDate(anotherDay, endDate);
|
|
|
} else if (type == 4) {
|
|
|
- String endDate = DateUtils.getAnotherDay(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -14);
|
|
|
+ String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -14);
|
|
|
reportList = reportMapper.selectDayDetailByDate(anotherDay, endDate);
|
|
|
} else if (type == 5) {
|
|
|
- String endDate = DateUtils.getMonthBefore(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -1);
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -1);
|
|
|
reportList = reportMapper.selectDayDetailByDate(anotherDay, endDate);
|
|
|
} else if (type == 6) {
|
|
|
- String endDate = DateUtils.getMonthBefore(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -3);
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -3);
|
|
|
reportList = reportMapper.selectDayDetailByDate(anotherDay, endDate);
|
|
|
} else if (type == 7) {
|
|
|
- String endDate = DateUtils.getMonthBefore(SIMPLE_DATE_FORMAT_YYYY_MM_DD, anotherDay, -6);
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -6);
|
|
|
reportList = reportMapper.selectDayDetailByMonth(anotherDay, endDate);
|
|
|
} else if (type == 8) {
|
|
|
reportList = reportMapper.selectAllDayDetailByMonth();
|
|
@@ -463,7 +637,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
if ("month".equals(sign)) {
|
|
|
dateMap = DateUtils.compareDate("yyyy-MM", bigDate, smallDate);
|
|
|
} else if ("day".equals(sign)) {
|
|
|
- dateMap = DateUtils.compareDate(SIMPLE_DATE_FORMAT_YYYY_MM_DD, bigDate, smallDate);
|
|
|
+ dateMap = DateUtils.compareDate("yyyy-MM-dd", bigDate, smallDate);
|
|
|
}
|
|
|
String comparedDate = (String) dateMap.get("bigDate");
|
|
|
String beComparedDate = (String) dateMap.get("smallDate");
|
|
@@ -493,25 +667,27 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
//创建异步任务
|
|
|
- @Override
|
|
|
- public void bytedanceAsyncTaskCreate(String startDate, String endDate, CtopOauthToken token, Integer type) {
|
|
|
- int diffMonths = DateUtils.calDiffMonth(DateUtils.parseDate(startDate, SIMPLE_DATE_FORMAT_YYYY_MM_DD), DateUtils.parseDate(endDate, SIMPLE_DATE_FORMAT_YYYY_MM_DD));
|
|
|
+ public void bytedanceAsyncTaskCreate(String startDate, String endDate, CtopOauthToken token, Integer type) throws ParseException {
|
|
|
+ int diffMonths = DateUtils.calDiffMonth(DateUtils.parseDate(startDate, "yyyy-MM-dd"), DateUtils.parseDate(endDate, "yyyy-MM-dd"));
|
|
|
if (diffMonths == 0) {
|
|
|
bytedanceAsyncTaskCreateByMonth(startDate, endDate, token, type);
|
|
|
}else{
|
|
|
for(int i=0; i<=diffMonths ; i++){
|
|
|
if (i == 0){
|
|
|
- Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, SIMPLE_DATE_FORMAT_YYYY_MM_DD, i);
|
|
|
+ Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
|
|
|
String end = dateMap.get("endDate");
|
|
|
+ //System.out.println(startDate + " ----- " + end);
|
|
|
bytedanceAsyncTaskCreateByMonth(startDate, end, token, type);
|
|
|
}else if(i == diffMonths){
|
|
|
- Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, SIMPLE_DATE_FORMAT_YYYY_MM_DD, i);
|
|
|
+ Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
|
|
|
String start = dateMap.get("startDate");
|
|
|
+ //System.out.println(start + " ----- " + endDate);
|
|
|
bytedanceAsyncTaskCreateByMonth(start, endDate, token, type);
|
|
|
}else{
|
|
|
- Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, SIMPLE_DATE_FORMAT_YYYY_MM_DD, i);
|
|
|
+ Map<String, String> dateMap = DateUtils.getMaxMinDaysOfAddMonth(startDate, "yyyy-MM-dd", i);
|
|
|
String start = dateMap.get("startDate");
|
|
|
String end = dateMap.get("endDate");
|
|
|
+ //System.out.println(start + " ----- " + end);
|
|
|
bytedanceAsyncTaskCreateByMonth(start, end, token, type);
|
|
|
}
|
|
|
}
|
|
@@ -525,110 +701,72 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
* @param token
|
|
|
*/
|
|
|
private void bytedanceAsyncTaskCreateByMonth(String startDate, String endDate, CtopOauthToken token, Integer type){
|
|
|
+ String access_token = token.getAccessToken();
|
|
|
+ Long accountId = token.getAccountId();
|
|
|
+
|
|
|
// 请求地址
|
|
|
String open_api_domain = "https://ad.toutiao.com";
|
|
|
String path = "/open_api/2/async_task/create/";
|
|
|
|
|
|
String taskName = System.currentTimeMillis() + "";
|
|
|
// 请求参数
|
|
|
- Map<String, Object> filtering = new HashMap<>();
|
|
|
- filtering.put("start_date", startDate);
|
|
|
- filtering.put("end_date", endDate);
|
|
|
- if (type == 1) {
|
|
|
- //素材
|
|
|
- filtering.put("group_by", new String[]{"STAT_GROUP_BY_CREATIVE_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_CREATIVE_MATERIAL_MODE"}); //按照创意分组、天分组、创意类型分组查询
|
|
|
- } else if (type == 2) {
|
|
|
- //广告主
|
|
|
- filtering.put("group_by", new String[]{"STAT_GROUP_BY_ADVERTISER_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_PRICING_CATEGORY"}); //按照广告主分组、天分组、广告类型类型分组查询
|
|
|
- } else if (type == 3) {
|
|
|
- //广告组
|
|
|
- filtering.put("group_by", new String[]{"STAT_GROUP_BY_CAMPAIGN_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_CAMPAIGN_TYPE"}); //按照广告组、天、广告组类型分组
|
|
|
- } else {
|
|
|
- //4广告计划
|
|
|
- filtering.put("group_by", new String[]{"STAT_GROUP_BY_AD_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_LANDING_TYPE"}); //按照广告计划、天、推广类型分组
|
|
|
- }
|
|
|
- Map<String, Object> data = new HashMap<>();
|
|
|
- data.put("advertiser_id", token.getAccountId());
|
|
|
- data.put("task_name", taskName);
|
|
|
- data.put("task_type", "REPORT");
|
|
|
- data.put("task_params", filtering);
|
|
|
-
|
|
|
- // 构造请求
|
|
|
- HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
- @Override
|
|
|
- public String getMethod() {
|
|
|
- return "POST";
|
|
|
+ final Map filtering = new HashMap() {
|
|
|
+ {
|
|
|
+ put("start_date", startDate);
|
|
|
+ put("end_date", endDate);
|
|
|
+ if (type == 1) {//创意
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_CREATIVE_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_CREATIVE_MATERIAL_MODE"}); //按照创意分组、天分组、创意类型分组查询
|
|
|
+ } else if (type == 2) {//广告主
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_ADVERTISER_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_PRICING_CATEGORY"}); //按照广告主分组、天分组、广告类型类型分组查询
|
|
|
+ } else if (type == 3) {//广告组
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_CAMPAIGN_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_CAMPAIGN_TYPE"}); //按照广告组、天、广告组类型分组
|
|
|
+ } else {//4广告计划
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_AD_ID", "STAT_GROUP_BY_TIME_DAY", "STAT_GROUP_BY_LANDING_TYPE"}); //按照广告计划、天、推广类型分组
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ final Map data = new HashMap() {
|
|
|
+ {
|
|
|
+ put("advertiser_id", accountId);
|
|
|
+ put("task_name", taskName);
|
|
|
+ put("task_type", "REPORT");
|
|
|
+ put("task_params", filtering);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- httpEntity.setHeader("Access-Token", token.getAccessToken());
|
|
|
-
|
|
|
- CloseableHttpResponse response = null;
|
|
|
- CloseableHttpClient client = null;
|
|
|
-
|
|
|
- try {
|
|
|
- client = HttpClientBuilder.create().build();
|
|
|
- httpEntity.setURI(URI.create(open_api_domain + path));
|
|
|
- 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()));
|
|
|
- StringBuilder result = new StringBuilder();
|
|
|
- String line = "";
|
|
|
- while ((line = bufferedReader.readLine()) != null) {
|
|
|
- result.append(line);
|
|
|
- }
|
|
|
- bufferedReader.close();
|
|
|
+ JSONObject json = HttpUtils.bytedancePostRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
+ if (json == null) {
|
|
|
+ log.error("请求有误:" + JSONObject.toJSONString(data));
|
|
|
+ }
|
|
|
|
|
|
- JSONObject json = JSONObject.parseObject(result.toString());
|
|
|
- String jsonString = JSON.toJSONString(json);
|
|
|
+ String jsonString = JSON.toJSONString(json);
|
|
|
|
|
|
- if(!Check.isNull(json)){
|
|
|
- Integer code = json.getInteger("code");
|
|
|
- if(code != 0){
|
|
|
- log.info("返回信息错误,错误码为:" + code + ",头条accountId:" + token.getAccountId() + ",message:" + json.getString("message"));
|
|
|
- return;
|
|
|
- }
|
|
|
- JSONObject dataJson = json.getJSONObject("data");
|
|
|
-
|
|
|
- //解析数据并入库
|
|
|
- BytedanceDailyReportTask task = new BytedanceDailyReportTask();
|
|
|
- task.setAccountId(token.getAccountId());
|
|
|
- task.setTaskCreateTime(dataJson.getDate("create_time") == null ? null : dataJson.getDate("create_time"));
|
|
|
- task.setTaskId(dataJson.getLong("task_id") == null ? null : dataJson.getLong("task_id") );
|
|
|
- task.setTaskName(dataJson.getString("task_name") == null ? null : dataJson.getString("task_name"));
|
|
|
- task.setTaskParams(JSON.toJSONString(dataJson.getJSONObject("task_params")));
|
|
|
- task.setJson(jsonString);
|
|
|
- task.setTaskStatus(dataJson.getString("task_status"));
|
|
|
- task.setTaskType(dataJson.getString("task_type"));
|
|
|
- task.setType(type);
|
|
|
- task.setIsDownload(0);
|
|
|
- task.setStatus(1); //状态1正常 0废弃
|
|
|
- bytedanceDailyReportTaskMapper.insert(task);
|
|
|
- }
|
|
|
-
|
|
|
- }else{
|
|
|
- log.error("请求有误:" + response );
|
|
|
- }
|
|
|
- } catch (ClientProtocolException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- if (response != null) {
|
|
|
- response.close();
|
|
|
- }
|
|
|
- client.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ if (!Check.isNull(json)) {
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
+ if (code != 0) {
|
|
|
+ log.error("返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ",message:" + json.getString("message"));
|
|
|
+ return;
|
|
|
}
|
|
|
+ JSONObject dataJson = json.getJSONObject("data");
|
|
|
+
|
|
|
+ //解析数据并入库
|
|
|
+ BytedanceDailyReportTask task = new BytedanceDailyReportTask();
|
|
|
+ task.setAccountId(accountId);
|
|
|
+ task.setTaskCreateTime(dataJson.getDate("create_time") == null ? null : dataJson.getDate("create_time"));
|
|
|
+ task.setTaskId(dataJson.getLong("task_id") == null ? null : dataJson.getLong("task_id"));
|
|
|
+ task.setTaskName(dataJson.getString("task_name") == null ? null : dataJson.getString("task_name"));
|
|
|
+ task.setTaskParams(JSON.toJSONString(dataJson.getJSONObject("task_params")));
|
|
|
+ task.setJson(jsonString);
|
|
|
+ task.setTaskStatus(dataJson.getString("task_status"));
|
|
|
+ task.setTaskType(dataJson.getString("task_type"));
|
|
|
+ task.setType(type);
|
|
|
+ task.setIsDownload(0);
|
|
|
+ task.setStatus(1); //状态1正常 0废弃
|
|
|
+ bytedanceDailyReportTaskMapper.insert(task);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//获取任务列表
|
|
|
- @Override
|
|
|
public void bytedanceAsyncTaskGet(){
|
|
|
QueryWrapper<BytedanceDailyReportTask> taskQueryWrapper = new QueryWrapper<>();
|
|
|
//查询三种状态的信息--任务已创建、任务执行中、任务处理中
|
|
@@ -665,86 +803,45 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- // 构造请求
|
|
|
- HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
- @Override
|
|
|
- public String getMethod() {
|
|
|
- return "GET";
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- httpEntity.setHeader("Access-Token",access_token);
|
|
|
-
|
|
|
- CloseableHttpResponse response = null;
|
|
|
- CloseableHttpClient client = null;
|
|
|
+ JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
+ if (json == null) {
|
|
|
+ log.error("请求有误:" + JSONObject.toJSONString(data));
|
|
|
+ }
|
|
|
|
|
|
try {
|
|
|
- client = HttpClientBuilder.create().build();
|
|
|
- httpEntity.setURI(URI.create(open_api_domain + path));
|
|
|
- httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
|
|
|
-
|
|
|
- response = client.execute(httpEntity);
|
|
|
- log.info("response为:" + response);
|
|
|
- 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);
|
|
|
+ String jsonString = JSON.toJSONString(json);
|
|
|
+ //log.info("返回json为" + jsonString);
|
|
|
+
|
|
|
+ if (!Check.isNull(json)) {
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
+ if (code != 0) {
|
|
|
+ log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + "taskId:" + task.getTaskId());
|
|
|
+ continue;
|
|
|
}
|
|
|
- bufferedReader.close();
|
|
|
|
|
|
- JSONObject json = JSONObject.parseObject(result.toString());
|
|
|
- String jsonString = JSON.toJSONString(json);
|
|
|
- log.info("返回json为" + jsonString);
|
|
|
+ JSONObject jsonData = json.getJSONObject("data");
|
|
|
+ if (Check.isNull(jsonData)) {
|
|
|
+ log.error("获取任务列表返回信息data内容为空");
|
|
|
+ }
|
|
|
+ JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
|
|
|
|
- if(!Check.isNull(json)){
|
|
|
- Integer code = json.getInteger("code");
|
|
|
- if(code != 0){
|
|
|
- log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + "taskId:" + task.getTaskId());
|
|
|
- return;
|
|
|
- }
|
|
|
+ for (int i = 0; i < jsonArrayay.size(); i++) {
|
|
|
+ JSONObject detailJson = jsonArrayay.getJSONObject(i);
|
|
|
+ if (!Check.isNull(detailJson)) {
|
|
|
+ String taskStatus = detailJson.getString("task_status");
|
|
|
|
|
|
- JSONObject jsonData = json.getJSONObject("data");
|
|
|
- if (Check.isNull(jsonData)){
|
|
|
- log.error("获取任务列表返回信息data内容为空");
|
|
|
- }
|
|
|
- JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
|
-
|
|
|
- for (int i = 0; i < jsonArrayay.size(); i++) {
|
|
|
- JSONObject detailJson = jsonArrayay.getJSONObject(i);
|
|
|
- if (!Check.isNull(detailJson)) {
|
|
|
- String taskStatus = detailJson.getString("task_status");
|
|
|
-
|
|
|
- if ("ASYNC_TASK_STATUS_COMPLETED".equals(taskStatus)) {
|
|
|
- bytedanceAsyncTaskDownload(task,token,task.getType());
|
|
|
- task.setIsDownload(1);
|
|
|
- }
|
|
|
- task.setTaskStatus(taskStatus);
|
|
|
- bytedanceDailyReportTaskMapper.updateById(task);
|
|
|
- }
|
|
|
+ if (taskStatus.equals("ASYNC_TASK_STATUS_COMPLETED")) {
|
|
|
+ bytedanceAsyncTaskDownload(task, token, task.getType());
|
|
|
+ task.setIsDownload(1);
|
|
|
}
|
|
|
+ task.setTaskStatus(taskStatus);
|
|
|
+ bytedanceDailyReportTaskMapper.updateById(task);
|
|
|
}
|
|
|
-
|
|
|
- }else{
|
|
|
- log.error("请求有误:" + response);
|
|
|
- }
|
|
|
-
|
|
|
- } catch (ClientProtocolException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- if (response != null) {
|
|
|
- response.close();
|
|
|
}
|
|
|
- client.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -757,11 +854,11 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
String path = "/open_api/2/async_task/download/";
|
|
|
|
|
|
String url = open_api_domain + path;
|
|
|
- String fileName = task.getAccountId() + "_" + "type" + type + "_" +System.currentTimeMillis() + ".csv";
|
|
|
+ String fileName = task.getAccountId() + "_" + "type" + type + "_" + task.getTaskId() + "_" + System.currentTimeMillis() + ".csv";
|
|
|
Map<String, Object> requestMap = new HashMap<>();
|
|
|
requestMap.put("advertiser_id", task.getAccountId());
|
|
|
requestMap.put("task_id", task.getTaskId());
|
|
|
- String localPath = LoadFileUtil.downloadByUrl(requestMap, downloadPath, url, token.getAccessToken(), fileName);
|
|
|
+ String localPath = DownloadUtils.downloadByUrl(requestMap, downloadPath, url, token.getAccessToken(), fileName);
|
|
|
if(type == 1){
|
|
|
//素材异步报表
|
|
|
bytedanceDailyReportTaskMapper.loadBytedanceDailyCreativeFileAsync(localPath);
|
|
@@ -781,10 +878,9 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
|
|
|
/////////////////////////////////////////////////////////\
|
|
|
//素材报表
|
|
|
- @Override
|
|
|
public void bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate){
|
|
|
Long accountId = token.getAccountId();
|
|
|
- log.info("头条素材报表当前accountId为:" + accountId);
|
|
|
+ // log.info("头条素材报表当前accountId为:" + accountId);
|
|
|
Integer page = 1;
|
|
|
Integer pageSize = 100;
|
|
|
int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
@@ -803,10 +899,9 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public void bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate){
|
|
|
Long accountId = token.getAccountId();
|
|
|
- log.info("头条素材报表当前accountId为:" + accountId);
|
|
|
+ // log.info("头条素材报表当前accountId为:" + accountId);
|
|
|
Integer page = 1;
|
|
|
Integer pageSize = 100;
|
|
|
int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
|
|
@@ -823,69 +918,44 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
|
|
|
private int bytedanceMaterialReportByPage(Integer page, Integer pageSize, CtopOauthToken token, Long accountId, String startDate, String endDate){
|
|
|
//log.info("当前页数:"+ page);
|
|
|
- String accessToken = token.getAccessToken();
|
|
|
+ String access_token = token.getAccessToken();
|
|
|
|
|
|
// 请求地址
|
|
|
String open_api_domain = "https://ad.oceanengine.com";
|
|
|
String path = "/open_api/2/report/integrated/get/";
|
|
|
|
|
|
// 请求参数
|
|
|
- Map<String, Object> filtering = new HashMap<>();
|
|
|
- filtering.put("image_mode", new String[]{"MATERIAL_IMAGE_MODE_TITLE"});
|
|
|
-
|
|
|
- Map<String, Object> data = new HashMap<>();
|
|
|
-
|
|
|
- data.put("advertiser_id", accountId);
|
|
|
- data.put("start_date", startDate);
|
|
|
- data.put("end_date", endDate);
|
|
|
- data.put("page", page);
|
|
|
- data.put("page_size", pageSize);
|
|
|
- data.put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID", "STAT_GROUP_BY_INVENTORY", "STAT_GROUP_BY_IMAGE_MODE", "STAT_GROUP_BY_TIME_DAY"});
|
|
|
-
|
|
|
-
|
|
|
- // 构造请求
|
|
|
- HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
|
- @Override
|
|
|
- public String getMethod() {
|
|
|
- return "GET";
|
|
|
+ Map data = new HashMap() {
|
|
|
+ {
|
|
|
+ put("advertiser_id", accountId);
|
|
|
+ put("start_date", startDate);
|
|
|
+ put("end_date", endDate);
|
|
|
+ put("page", page);
|
|
|
+ put("page_size", pageSize);
|
|
|
+ put("group_by", new String[]{"STAT_GROUP_BY_MATERIAL_ID", "STAT_GROUP_BY_INVENTORY", "STAT_GROUP_BY_IMAGE_MODE", "STAT_GROUP_BY_TIME_DAY"});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- httpEntity.setHeader("Access-Token", accessToken);
|
|
|
-
|
|
|
- CloseableHttpResponse response = null;
|
|
|
- CloseableHttpClient client = null;
|
|
|
+ JSONObject json = HttpUtils.bytedanceGetRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
|
|
|
+ if (json == null) {
|
|
|
+ //insertMaterialRetry(accountId, startDate, endDate, -2);
|
|
|
+ log.error("请求有误:" + JSONObject.toJSONString(data));
|
|
|
+ return -2;
|
|
|
+ }
|
|
|
|
|
|
int returnCode = 200;
|
|
|
try {
|
|
|
- client = HttpClientBuilder.create().build();
|
|
|
- httpEntity.setURI(URI.create(open_api_domain + path));
|
|
|
- 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();
|
|
|
-
|
|
|
- JSONObject json = JSONObject.parseObject(result.toString());
|
|
|
- String jsonString = JSON.toJSONString(json);
|
|
|
-
|
|
|
if(!Check.isNull(json)){
|
|
|
Integer code = json.getInteger("code");
|
|
|
if(code != 0){
|
|
|
- log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + jsonString);
|
|
|
+ log.error("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
JSONObject jsonData = json.getJSONObject("data");
|
|
|
if (Check.isNull(jsonData)){
|
|
|
- log.error("获取任务列表返回信息data内容为空");
|
|
|
+ log.error("获取任务列表返回信息data内容为空,头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
|
|
|
+ return -1;
|
|
|
}
|
|
|
JSONObject pageInfo = jsonData.getJSONObject("page_info");
|
|
|
Integer totalPage = pageInfo.getInteger("total_page");
|
|
@@ -894,6 +964,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
JSONArray jsonArrayay = jsonData.getJSONArray("list");
|
|
|
if(jsonArrayay.size() == 0){
|
|
|
log.info("accountId:" + accountId + ";没有数据。总页数为:" + totalPage + "当前页数为:" + currentPage);
|
|
|
+ //returnCode = 1;
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
@@ -1005,35 +1076,26 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
bytedanceReportMaterialDailyList.add(daily);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ //Long insertStartTime = System.currentTimeMillis();
|
|
|
bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportMaterialDailyList);
|
|
|
-
|
|
|
+ //Long insertEndTime = System.currentTimeMillis();
|
|
|
+ //log.info("头条获取素材报表插入数据结束,执行耗时:{}秒", (insertEndTime - insertStartTime) / 1000);
|
|
|
if(currentPage >= totalPage){
|
|
|
- log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:"+ endDate);
|
|
|
+ //log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:"+ endDate);
|
|
|
return 1;
|
|
|
}else{
|
|
|
- bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
|
+ int pageCode = bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
|
|
|
+ return pageCode;
|
|
|
}
|
|
|
}else{
|
|
|
- log.error("服务器返回为空,json:"+jsonString);
|
|
|
+ //returnCode = -1;
|
|
|
+ log.error("服务器返回为空,json:" + JSONObject.toJSONString(data));
|
|
|
return -1;
|
|
|
}
|
|
|
- }else{
|
|
|
- log.error("头条素材报表请求有误:accountId:" + accountId + ",开始时间:" + startDate + "结束时间:" + endDate + "错误返回:" +response);
|
|
|
- return 0;
|
|
|
- }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- returnCode = -2;
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- if (response != null) {
|
|
|
- response.close();
|
|
|
- }
|
|
|
- client.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ log.error("头条报表其他错误,accountId:" + accountId + ",json:" + JSONObject.toJSONString(data));
|
|
|
+ returnCode = -3;
|
|
|
}
|
|
|
return returnCode;
|
|
|
}
|
|
@@ -1044,19 +1106,3 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|