|
@@ -3,28 +3,33 @@ package com.fs.baidu.api;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.fs.ad.domain.AdHtmlClickLog;
|
|
import com.fs.ad.domain.AdHtmlClickLog;
|
|
|
|
+import com.fs.ad.domain.BdCreativeStatistics;
|
|
|
|
+import com.fs.ad.domain.BdReportData;
|
|
import com.fs.ad.mapper.AdHtmlClickLogMapper;
|
|
import com.fs.ad.mapper.AdHtmlClickLogMapper;
|
|
-import com.fs.baidu.domain.BdAccount;
|
|
|
|
-import com.fs.baidu.domain.BdCreative;
|
|
|
|
-import com.fs.baidu.domain.BdPlan;
|
|
|
|
-import com.fs.baidu.domain.BdUnit;
|
|
|
|
|
|
+import com.fs.ad.mapper.BdReportDataMapper;
|
|
|
|
+import com.fs.ad.service.IBdCreativeStatisticsService;
|
|
|
|
+import com.fs.ad.service.IBdReportDataService;
|
|
|
|
+import com.fs.baidu.domain.*;
|
|
import com.fs.baidu.param.*;
|
|
import com.fs.baidu.param.*;
|
|
-import com.fs.baidu.service.IBdAccountService;
|
|
|
|
-import com.fs.baidu.service.IBdCreativeService;
|
|
|
|
-import com.fs.baidu.service.IBdPlanService;
|
|
|
|
-import com.fs.baidu.service.IBdUnitService;
|
|
|
|
|
|
+import com.fs.baidu.service.*;
|
|
import com.fs.baidu.utils.BdApiRequest;
|
|
import com.fs.baidu.utils.BdApiRequest;
|
|
import com.fs.baidu.vo.*;
|
|
import com.fs.baidu.vo.*;
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.utils.PubFun;
|
|
import com.fs.common.utils.PubFun;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.function.Function;
|
|
|
|
+import java.util.function.Supplier;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -37,7 +42,10 @@ public class BaiduApis {
|
|
private final IBdPlanService planService;
|
|
private final IBdPlanService planService;
|
|
private final IBdCreativeService creativeService;
|
|
private final IBdCreativeService creativeService;
|
|
private final IBdUnitService unitService;
|
|
private final IBdUnitService unitService;
|
|
|
|
+ public final IBdApiService apiService;
|
|
private final AdHtmlClickLogMapper adHtmlClickLogMapper;
|
|
private final AdHtmlClickLogMapper adHtmlClickLogMapper;
|
|
|
|
+ private final BdReportDataMapper bdReportDataMapper;
|
|
|
|
+ private final IBdCreativeStatisticsService bdCreativeStatisticsService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询账户列表
|
|
* 查询账户列表
|
|
@@ -224,11 +232,117 @@ public class BaiduApis {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- public R getReportData(BdAccount account, QueryReportDataParam params){
|
|
|
|
|
|
+ public void getReportDataAll(BdAccount account, QueryReportDataParam paramData){
|
|
|
|
+ Supplier<Integer> getType = () -> {
|
|
|
|
+ if(paramData.getReportType() == 2324048) return 0;
|
|
|
|
+ if(paramData.getReportType() == 2503330) return 1;
|
|
|
|
+ if(paramData.getReportType() == 2510393) return 2;
|
|
|
|
+ if(paramData.getReportType() == 2532512) return 3;
|
|
|
|
+ if(paramData.getReportType() == 2094816) return 4;
|
|
|
|
+ return 99;
|
|
|
|
+ };
|
|
|
|
+ List<ReportDataVo> allData = new ArrayList<>();
|
|
|
|
+ BdApi byId = apiService.getById(account.getApiId());
|
|
|
|
+ boolean data = true;
|
|
|
|
+ String dataJson = JSON.toJSONString(paramData);
|
|
|
|
+ for (int page = 1 ; data ; page++) {
|
|
|
|
+ QueryReportDataParam params = JSON.parseObject(dataJson, QueryReportDataParam.class);
|
|
|
|
+ // 设置分页参数
|
|
|
|
+ params.setPage(page);
|
|
|
|
+ R result = getReportData(byId.getAccessToken(), account.getAccountName(), params);
|
|
|
|
+ // 处理第一次请求时获取总行数
|
|
|
|
+ List<ReportDataVo> list = (List<ReportDataVo>) result.get("data");
|
|
|
|
+ if(!list.isEmpty()){
|
|
|
|
+ list.forEach(e -> e.setType(getType.get()));
|
|
|
|
+ allData.addAll(list);
|
|
|
|
+ }
|
|
|
|
+ data = list.size() == paramData.getRowCount();
|
|
|
|
+ }
|
|
|
|
+ List<BdReportData> collect = allData.stream().map(e -> {
|
|
|
|
+ BdReportData bdReportData = new BdReportData();
|
|
|
|
+ bdReportData.setType(e.getType());
|
|
|
|
+ bdReportData.setDate(LocalDate.now());
|
|
|
|
+ bdReportData.setUserName(e.getUserName());
|
|
|
|
+ bdReportData.setUserId(e.getUserId());
|
|
|
|
+ bdReportData.setCampaignId(e.getCampaignId());
|
|
|
|
+ bdReportData.setCampaignName(e.getCampaignName());
|
|
|
|
+ if(e.getCampaignStatus() != null){
|
|
|
|
+ bdReportData.setCampaignStatus(e.getCampaignStatus().getCode());
|
|
|
|
+ bdReportData.setCampaignNameStatus(e.getCampaignStatus().getCode());
|
|
|
|
+ }
|
|
|
|
+ bdReportData.setAdGroupId(e.getAdGroupId());
|
|
|
|
+ bdReportData.setAdGroupName(e.getAdGroupName());
|
|
|
|
+ if(e.getAdGroupStatus() != null){
|
|
|
|
+ bdReportData.setAdGroupStatus(e.getAdGroupStatus().getCode());
|
|
|
|
+ }
|
|
|
|
+ bdReportData.setAdGroupNameStatus(e.getAdGroupNameStatus());
|
|
|
|
+ if(e.getProv() != null){
|
|
|
|
+ bdReportData.setProvinceId(Long.parseLong(e.getProv().getProvinceId()));
|
|
|
|
+ bdReportData.setProvinceName(e.getProv().getProvinceName());
|
|
|
|
+ }
|
|
|
|
+ bdReportData.setGenderName(e.getGenderName());
|
|
|
|
+ bdReportData.setAge(e.getAgeName());
|
|
|
|
+ bdReportData.setShowWord(e.getShowWord());
|
|
|
|
+ bdReportData.setFeedWord(e.getFeedWord());
|
|
|
|
+
|
|
|
|
+ bdReportData.setImpression(e.getImpression());
|
|
|
|
+ bdReportData.setClick(e.getClick());
|
|
|
|
+ bdReportData.setCost(e.getCost());
|
|
|
|
+ bdReportData.setCtr(e.getCtr());
|
|
|
|
+ bdReportData.setCpc(e.getCpc());
|
|
|
|
+ bdReportData.setCpm(e.getCpm());
|
|
|
|
+ return bdReportData;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ collect.parallelStream().forEach(bdReportDataMapper::insert);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void getCreativeStatisticsAll(BdAccount account, QueryReportDataParam params){
|
|
|
|
+ params.setColumns(Arrays.asList("date", "userId", "userName", "campaignNameStatus", "adGroupNameStatus", "ideaInfo", "ideaNameStatus", "feedSubjectEnum", "impression", "click", "cost", "ctr", "cpc", "cpm", "iaaCost", "iaaPayRoi", "phoneButtonClicks", "interaction"));
|
|
|
|
+ BdApi byId = apiService.getById(account.getApiId());
|
|
|
|
+ String url = "https://api.baidu.com/json/sms/service/OpenApiReportService/getReportData";
|
|
|
|
+ if(params.getPage() != null && params.getRowCount() != null){
|
|
|
|
+ params.setStartRow(params.getPage() * params.getRowCount());
|
|
|
|
+ }
|
|
|
|
+ String resultStr = request.requestToken(url, byId.getAccessToken(), account.getAccountName(), params);
|
|
|
|
+ JSONObject data = JSON.parseObject(resultStr).getJSONArray("data").getJSONObject(0);
|
|
|
|
+ Integer total = data.getInteger("totalRowCount");
|
|
|
|
+ List<ReportVO> list = data.getJSONArray("rows").toJavaList(ReportVO.class);
|
|
|
|
+ List<BdCreativeStatistics> collect = list.parallelStream().map(e -> {
|
|
|
|
+ BdCreativeStatistics entity = new BdCreativeStatistics();
|
|
|
|
+ entity.setDate(e.getDate());
|
|
|
|
+ entity.setUserId(e.getUserId());
|
|
|
|
+ entity.setUserName(e.getUserName());
|
|
|
|
+ entity.setCampaignNameStatus(e.getCampaignNameStatus());
|
|
|
|
+ entity.setAdGroupNameStatus(e.getAdGroupNameStatus());
|
|
|
|
+ entity.setIdeaInfo(e.getIdeaInfo());
|
|
|
|
+ entity.setIdeaNameStatus(e.getIdeaNameStatus());
|
|
|
|
+ if(e.getFeedSubjectEnum() != null){
|
|
|
|
+ entity.setFeedSubjectEnum(e.getFeedSubjectEnum().getValue());
|
|
|
|
+ }
|
|
|
|
+ entity.setImpression(e.getImpression());
|
|
|
|
+ entity.setClick(e.getClick());
|
|
|
|
+ entity.setCost(e.getCost());
|
|
|
|
+ entity.setCtr(e.getCtr());
|
|
|
|
+ entity.setCpc(e.getCpc());
|
|
|
|
+ entity.setCpm(e.getCpm());
|
|
|
|
+ entity.setIaaCost(e.getIaaCost());
|
|
|
|
+ entity.setIaaPayRoi(e.getIaaPayRoi());
|
|
|
|
+ entity.setPhoneButtonClicks(e.getPhoneButtonClicks());
|
|
|
|
+ entity.setInteraction(e.getInteraction());
|
|
|
|
+ return entity;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ boolean b = bdCreativeStatisticsService.saveBatch(collect);
|
|
|
|
+ log.info("是否添加成功:{}", b);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public R getReportData(String token, String name, QueryReportDataParam params){
|
|
String url = "https://api.baidu.com/json/sms/service/OpenApiReportService/getReportData";
|
|
String url = "https://api.baidu.com/json/sms/service/OpenApiReportService/getReportData";
|
|
if(params.getReportType() == 2324048){
|
|
if(params.getReportType() == 2324048){
|
|
params.getColumns().add("prov");
|
|
params.getColumns().add("prov");
|
|
- params.getColumns().add("city");
|
|
|
|
|
|
+// params.getColumns().add("city");
|
|
}
|
|
}
|
|
if(params.getReportType() == 2503330){
|
|
if(params.getReportType() == 2503330){
|
|
params.getColumns().add("genderName");
|
|
params.getColumns().add("genderName");
|
|
@@ -240,10 +354,22 @@ public class BaiduApis {
|
|
params.getColumns().add("showWord");
|
|
params.getColumns().add("showWord");
|
|
params.getColumns().add("feedWord");
|
|
params.getColumns().add("feedWord");
|
|
}
|
|
}
|
|
|
|
+ if(params.getReportType() == 114718){
|
|
|
|
+ params.getColumns().add("ideaId");
|
|
|
|
+ params.getColumns().add("videoId");
|
|
|
|
+ params.getColumns().add("videoNameStatus");
|
|
|
|
+ params.getColumns().add("videoInfo");
|
|
|
|
+ params.getColumns().add("ideaNameStatus");
|
|
|
|
+ }
|
|
|
|
+ if(params.getReportType() == 2094817){
|
|
|
|
+ params.getColumns().add("imageUrl");
|
|
|
|
+ params.getColumns().add("imageId");
|
|
|
|
+ params.getColumns().add("ideaNameStatus");
|
|
|
|
+ }
|
|
if(params.getPage() != null && params.getRowCount() != null){
|
|
if(params.getPage() != null && params.getRowCount() != null){
|
|
- params.setStartRow(params.getPage() * params.getRowCount());
|
|
|
|
|
|
+ params.setStartRow((params.getPage() - 1) * params.getRowCount());
|
|
}
|
|
}
|
|
- String resultStr = request.request(url, account.getApiId(), account.getAccountName(), params);
|
|
|
|
|
|
+ String resultStr = request.requestToken(url, token, name, params);
|
|
JSONObject data = JSON.parseObject(resultStr).getJSONArray("data").getJSONObject(0);
|
|
JSONObject data = JSON.parseObject(resultStr).getJSONArray("data").getJSONObject(0);
|
|
Integer total = data.getInteger("totalRowCount");
|
|
Integer total = data.getInteger("totalRowCount");
|
|
List<ReportDataVo> list = data.getJSONArray("rows").toJavaList(ReportDataVo.class);
|
|
List<ReportDataVo> list = data.getJSONArray("rows").toJavaList(ReportDataVo.class);
|
|
@@ -261,18 +387,24 @@ public class BaiduApis {
|
|
if(e.getCtr() != null){
|
|
if(e.getCtr() != null){
|
|
e.setCtr(e.getCtr().setScale(4, RoundingMode.HALF_UP));
|
|
e.setCtr(e.getCtr().setScale(4, RoundingMode.HALF_UP));
|
|
}
|
|
}
|
|
|
|
+ if(e.getWeixinFollowSuccessConversionsCost() != null){
|
|
|
|
+ e.setWeixinFollowSuccessConversionsCost(e.getWeixinFollowSuccessConversionsCost().setScale(2, RoundingMode.HALF_UP));
|
|
|
|
+ }
|
|
|
|
+ if(e.getFeedOCPCConversionsDetail133Cost() != null){
|
|
|
|
+ e.setFeedOCPCConversionsDetail133Cost(e.getFeedOCPCConversionsDetail133Cost().setScale(2, RoundingMode.HALF_UP));
|
|
|
|
+ }
|
|
});
|
|
});
|
|
list.stream().filter(e -> e.getCtr().doubleValue() > 0).forEach(e -> {
|
|
list.stream().filter(e -> e.getCtr().doubleValue() > 0).forEach(e -> {
|
|
e.setCtr(e.getCtr().multiply(BigDecimal.valueOf(100)));
|
|
e.setCtr(e.getCtr().multiply(BigDecimal.valueOf(100)));
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- if(!list.isEmpty()){
|
|
|
|
- List<Long> uidList = PubFun.listToNewList(list, ReportDataVo::getAdGroupId);
|
|
|
|
- List<AdHtmlClickLog> logList = adHtmlClickLogMapper.staticData(uidList);
|
|
|
|
- if(!logList.isEmpty()){
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+// if(!list.isEmpty()){
|
|
|
|
+// List<Long> uidList = PubFun.listToNewList(list, ReportDataVo::getAdGroupId);
|
|
|
|
+// List<AdHtmlClickLog> logList = adHtmlClickLogMapper.staticData(uidList);
|
|
|
|
+// if(!logList.isEmpty()){
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// }
|
|
return R.ok().put("data", list).put("total", total);
|
|
return R.ok().put("data", list).put("total", total);
|
|
}
|
|
}
|
|
|
|
|