|
|
@@ -150,7 +150,6 @@ public class AdPlanDailyReportService {
|
|
|
String jobNumber = conf.getJobNumber();
|
|
|
TencentAds tencentAds = clientFactory.getTencentAds(jobNumber, Constant.MAIN_ORG_ACCOUNT_ID);
|
|
|
|
|
|
- // 日期范围使用 conf.createTime 的日期
|
|
|
String startStr = startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
String endStr = endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
ReportDateRange dateRange = new ReportDateRange();
|
|
|
@@ -249,64 +248,70 @@ public class AdPlanDailyReportService {
|
|
|
null // modularDetailMode
|
|
|
);
|
|
|
|
|
|
- if (response == null || response.getList() == null || response.getList().isEmpty()) {
|
|
|
+ if (response == null) {
|
|
|
log.warn("[syncBatch] accountId={} 未返回日报数据", accountId);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
// 构建更新数据
|
|
|
List<AdPlan> toUpdate = new ArrayList<>();
|
|
|
- for (ReportStruct rs : response.getList()) {
|
|
|
- if (rs.getAdgroupId() == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- AdPlan update = new AdPlan();
|
|
|
- update.setAdgroupId(rs.getAdgroupId());
|
|
|
-
|
|
|
- if (isReqTime) {
|
|
|
- // REQUEST_TIME 口径:更新 cost, view_count, valid_click_count, ctr, conversions_cost, req_income_val_1, req_income_roi_1
|
|
|
- update.setCost(rs.getCost());
|
|
|
- update.setViewCount(rs.getViewCount());
|
|
|
- update.setValidClickCount(rs.getValidClickCount());
|
|
|
- update.setCtr(d2b(rs.getCtr()));
|
|
|
- update.setConversionsCost(rs.getConversionsCost());
|
|
|
- update.setReqIncomeVal1(rs.getIncomeVal1());
|
|
|
- update.setReqIncomeRoi1(d2b(rs.getIncomeRoi1()));
|
|
|
- update.setScanFollowUserCost(rs.getScanFollowUserCost());
|
|
|
- } else {
|
|
|
- // REPORTING_TIME 口径:更新 rep_income_val_1, rep_income_roi_1
|
|
|
- update.setRepIncomeVal1(rs.getIncomeVal1());
|
|
|
- update.setRepIncomeRoi1(d2b(rs.getIncomeRoi1()));
|
|
|
- }
|
|
|
- update.setUpdateTime(LocalDateTime.now());
|
|
|
- toUpdate.add(update);
|
|
|
+ if (response.getList() != null) {
|
|
|
+ for (ReportStruct rs : response.getList()) {
|
|
|
+ if (rs.getAdgroupId() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ AdPlan update = new AdPlan();
|
|
|
+ update.setAdgroupId(rs.getAdgroupId());
|
|
|
+
|
|
|
+ if (isReqTime) {
|
|
|
+ // REQUEST_TIME 口径:更新 cost, view_count, valid_click_count, ctr, conversions_cost, req_income_val_1, req_income_roi_1
|
|
|
+ update.setCost(rs.getCost());
|
|
|
+ update.setViewCount(rs.getViewCount());
|
|
|
+ update.setValidClickCount(rs.getValidClickCount());
|
|
|
+ update.setCtr(d2b(rs.getCtr()));
|
|
|
+ update.setConversionsCost(rs.getConversionsCost());
|
|
|
+ update.setReqIncomeVal1(rs.getIncomeVal1());
|
|
|
+ update.setReqIncomeRoi1(d2b(rs.getIncomeRoi1()));
|
|
|
+ update.setScanFollowUserCost(rs.getScanFollowUserCost());
|
|
|
+ } else {
|
|
|
+ // REPORTING_TIME 口径:更新 rep_income_val_1, rep_income_roi_1
|
|
|
+ update.setRepIncomeVal1(rs.getIncomeVal1());
|
|
|
+ update.setRepIncomeRoi1(d2b(rs.getIncomeRoi1()));
|
|
|
+ }
|
|
|
+ update.setUpdateTime(LocalDateTime.now());
|
|
|
+ toUpdate.add(update);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (toUpdate.isEmpty()) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- Map<Long, AdPlan> updateMap = toUpdate.stream().collect(Collectors.toMap(AdPlan::getId, p -> p));
|
|
|
+ //无报表数据的,填充0值
|
|
|
+ Map<Long, AdPlan> updateMap = toUpdate.stream().collect(Collectors.toMap(AdPlan::getAdgroupId, p -> p));
|
|
|
batch.forEach(p -> {
|
|
|
- if (!updateMap.containsKey(p.getId())) {
|
|
|
- AdPlan update = updateMap.get(p.getId());
|
|
|
+ if (!updateMap.containsKey(p.getAdgroupId())) {
|
|
|
+ AdPlan update = new AdPlan();
|
|
|
+ update.setAdgroupId(p.getAdgroupId());
|
|
|
+
|
|
|
if (isReqTime) {
|
|
|
- p.setCost(0L);
|
|
|
- p.setViewCount(0L);
|
|
|
- p.setValidClickCount(0L);
|
|
|
- p.setCtr(BigDecimal.ZERO);
|
|
|
- p.setConversionsCost(0L);
|
|
|
- p.setReqIncomeVal1(0L);
|
|
|
- p.setReqIncomeRoi1(BigDecimal.ZERO);
|
|
|
- p.setScanFollowUserCost(0L);
|
|
|
+ update.setCost(0L);
|
|
|
+ update.setViewCount(0L);
|
|
|
+ update.setValidClickCount(0L);
|
|
|
+ update.setCtr(BigDecimal.ZERO);
|
|
|
+ update.setConversionsCost(0L);
|
|
|
+ update.setReqIncomeVal1(0L);
|
|
|
+ update.setReqIncomeRoi1(BigDecimal.ZERO);
|
|
|
+ update.setScanFollowUserCost(0L);
|
|
|
} else {
|
|
|
- p.setRepIncomeVal1(0L);
|
|
|
- p.setRepIncomeRoi1(BigDecimal.ZERO);
|
|
|
+ update.setRepIncomeVal1(0L);
|
|
|
+ update.setRepIncomeRoi1(BigDecimal.ZERO);
|
|
|
}
|
|
|
- p.setUpdateTime(LocalDateTime.now());
|
|
|
+ update.setUpdateTime(LocalDateTime.now());
|
|
|
toUpdate.add(update);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ if (toUpdate.isEmpty()) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
// 批量更新
|
|
|
if (isReqTime) {
|
|
|
adPlanMapper.batchUpdateReqDailyReport(toUpdate);
|