|
@@ -31,6 +31,7 @@ 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.bytedeco.javacpp.freenect2;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -676,28 +677,28 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
//创建异步任务
|
|
|
- public void bytedanceAsyncTaskCreate (String startDate, String endDate, CtopOauthToken token) throws ParseException {
|
|
|
+ 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);
|
|
|
+ bytedanceAsyncTaskCreateByMonth(startDate, endDate, token, type);
|
|
|
}else{
|
|
|
for(int i=0; i<=diffMonths ; i++){
|
|
|
if (i == 0){
|
|
|
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);
|
|
|
+ bytedanceAsyncTaskCreateByMonth(startDate, end, token, type);
|
|
|
}else if(i == diffMonths){
|
|
|
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);
|
|
|
+ bytedanceAsyncTaskCreateByMonth(start, endDate, token, type);
|
|
|
}else{
|
|
|
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);
|
|
|
+ bytedanceAsyncTaskCreateByMonth(start, end, token, type);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -709,7 +710,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
* @param endDate
|
|
|
* @param token
|
|
|
*/
|
|
|
- private void bytedanceAsyncTaskCreateByMonth(String startDate, String endDate, CtopOauthToken token){
|
|
|
+ private void bytedanceAsyncTaskCreateByMonth(String startDate, String endDate, CtopOauthToken token, Integer type){
|
|
|
String access_token = token.getAccessToken();
|
|
|
Long accountId = token.getAccountId();
|
|
|
|
|
@@ -723,7 +724,15 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
{
|
|
|
put("start_date", startDate);
|
|
|
put("end_date", endDate);
|
|
|
- put("group_by", new String[]{"STAT_GROUP_BY_CREATIVE_ID","STAT_GROUP_BY_TIME_DAY","STAT_GROUP_BY_CREATIVE_MATERIAL_MODE"}); //按照创意分组、天分组、创意类型分组查询
|
|
|
+ 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() {
|
|
@@ -784,7 +793,9 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
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);
|
|
|
}
|
|
|
|
|
@@ -896,7 +907,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
String taskStatus = detailJson.getString("task_status");
|
|
|
|
|
|
if (taskStatus .equals( "ASYNC_TASK_STATUS_COMPLETED")) {
|
|
|
- bytedanceAsyncTaskDownload(task,token);
|
|
|
+ bytedanceAsyncTaskDownload(task,token,task.getType());
|
|
|
task.setIsDownload(1);
|
|
|
}
|
|
|
task.setTaskStatus(taskStatus);
|
|
@@ -929,19 +940,33 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //下载任务结果
|
|
|
- private void bytedanceAsyncTaskDownload(BytedanceDailyReportTask task, CtopOauthToken token){
|
|
|
+ //下载任务结果 type 1.creative 2.account 3.campaign 4.plan
|
|
|
+ private void bytedanceAsyncTaskDownload(BytedanceDailyReportTask task, CtopOauthToken token, Integer type){
|
|
|
// 请求地址
|
|
|
String open_api_domain = "https://ad.toutiao.com";
|
|
|
String path = "/open_api/2/async_task/download/";
|
|
|
|
|
|
String url = open_api_domain + path;
|
|
|
- String fileName = task.getAccountId() + "_" + System.currentTimeMillis() + ".csv";
|
|
|
+ String fileName = task.getAccountId() + "_" + "type" + type + "_" +System.currentTimeMillis() + ".csv";
|
|
|
Map<String, Object> requestMap = new HashMap<>();
|
|
|
requestMap.put("advertiser_id", task.getAccountId());
|
|
|
requestMap.put("task_id", task.getTaskId());
|
|
|
String localPath = DownloadUtils.downloadByUrl(requestMap, downloadPath, url, token.getAccessToken(), fileName);
|
|
|
- bytedanceDailyReportTaskMapper.loadBytedanceDailyCreativeFileAsync(localPath);
|
|
|
+ if(type == 1){
|
|
|
+ //素材异步报表
|
|
|
+ bytedanceDailyReportTaskMapper.loadBytedanceDailyCreativeFileAsync(localPath);
|
|
|
+ }else if(type == 2){
|
|
|
+ //账户异步报表
|
|
|
+ bytedanceDailyReportTaskMapper.loadBytedanceDailyAccountFileAsync(localPath);
|
|
|
+ }else if(type == 3){
|
|
|
+ //campaign异步报表
|
|
|
+ bytedanceDailyReportTaskMapper.loadBytedanceDailyCampaignFileAsync(localPath);
|
|
|
+ }else if(type == 4){
|
|
|
+ //plan异步报表
|
|
|
+ bytedanceDailyReportTaskMapper.loadBytedanceDailyPlanFileAsync(localPath);
|
|
|
+ }else{
|
|
|
+ log.error("异步报表类型传入错误,task_id:" + task.getTaskId() + ";类型:" + type);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////\
|