|
|
@@ -2,12 +2,20 @@ package com.ytpm.controller;
|
|
|
|
|
|
import com.ytpm.advertise.enums.AdPlatformTypeEnum;
|
|
|
import com.ytpm.advertise.param.ComprehensiveReportParam;
|
|
|
+import com.ytpm.advertise.param.HourReportParam;
|
|
|
import com.ytpm.advertise.view.ComprehensiveAppReport;
|
|
|
+import com.ytpm.advertise.view.HourReportView;
|
|
|
import com.ytpm.agent.param.IndexResParam;
|
|
|
+import com.ytpm.agent.view.AgentChannelView;
|
|
|
+import com.ytpm.agent.view.IndexHourReportView;
|
|
|
+import com.ytpm.dao.ChannelMapper;
|
|
|
import com.ytpm.feign.AdvertiseFeign;
|
|
|
import com.ytpm.general.Result;
|
|
|
+import com.ytpm.general.ResultTable;
|
|
|
+import com.ytpm.service.impl.ChannelServiceImpl;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
@@ -18,10 +26,7 @@ import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Api(tags = "首页数据统计模块")
|
|
|
@@ -32,6 +37,9 @@ public class AgentIndexController {
|
|
|
@Resource
|
|
|
private AdvertiseFeign advertiseFeign;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ChannelMapper channelMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询广告平台收益
|
|
|
*/
|
|
|
@@ -86,7 +94,14 @@ public class AgentIndexController {
|
|
|
.map(ComprehensiveAppReport::getRevenue)
|
|
|
.filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //ecpm数据
|
|
|
+ BigDecimal todayEcpm = platformReports.stream()
|
|
|
+ .filter(item -> todayStr.equals(item.getDate()))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(ComprehensiveAppReport::getEcpm)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
resParam.setToday(todayRevenue.setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ resParam.setEcpmToday(todayEcpm.setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
|
|
|
// 统计昨日数据
|
|
|
BigDecimal yesterdayRevenue = platformReports.stream()
|
|
|
@@ -96,6 +111,14 @@ public class AgentIndexController {
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
resParam.setYesterday(yesterdayRevenue.setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
|
|
|
+ //昨天ecpm数据
|
|
|
+ BigDecimal yesterdayEcpm = platformReports.stream()
|
|
|
+ .filter(item -> yesterdayStr.equals(item.getDate()))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(ComprehensiveAppReport::getEcpm)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ resParam.setEcpmYesterday(yesterdayEcpm.setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+
|
|
|
// 统计本月数据
|
|
|
BigDecimal monthRevenue = platformReports.stream()
|
|
|
.filter(item -> {
|
|
|
@@ -106,7 +129,19 @@ public class AgentIndexController {
|
|
|
.map(ComprehensiveAppReport::getRevenue)
|
|
|
.filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ BigDecimal monthEcpm = platformReports.stream()
|
|
|
+ .filter(
|
|
|
+ item -> {
|
|
|
+ String date = item.getDate();
|
|
|
+ return date != null && date.compareTo(monthStartStr) >= 0
|
|
|
+ && date.compareTo(monthEndStr) <= 0;
|
|
|
+ })
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(ComprehensiveAppReport::getEcpm)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
resParam.setMonth(monthRevenue.setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ resParam.setEcpmMonth(monthEcpm.setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
|
|
|
return resParam;
|
|
|
})
|
|
|
@@ -115,5 +150,65 @@ public class AgentIndexController {
|
|
|
return Result.resultObjOk(result);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询分小时报表 折线图数据
|
|
|
+ * 预估收益以及ecpm
|
|
|
+ */
|
|
|
+ @ApiOperation("查询分小时报表")
|
|
|
+ @PostMapping("/hourReport")
|
|
|
+ public Result<?> hourReport() {
|
|
|
+ HourReportParam param = new HourReportParam();
|
|
|
+ // 1. 准备日期参数
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
+
|
|
|
+ // 今日和昨日日期
|
|
|
+ String todayStr = today.format(formatter);
|
|
|
+ Integer todayInt = Integer.valueOf(todayStr);
|
|
|
+ List<AgentChannelView> agentChannelViews = channelMapper.channelList();
|
|
|
+ ArrayList<IndexHourReportView> indexHourReportViews = new ArrayList<>();
|
|
|
+
|
|
|
+ for (AgentChannelView agentChannelView : agentChannelViews) {
|
|
|
+ IndexHourReportView indexHourReportView = new IndexHourReportView();
|
|
|
+ indexHourReportView.setChannelName(agentChannelView.getChannelName());
|
|
|
+
|
|
|
+ List<BigDecimal> hourlyData = new ArrayList<>(24);
|
|
|
+ for (int i = 0; i < 24; i++) {
|
|
|
+ hourlyData.add(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ List<BigDecimal> ecpmData = new ArrayList<>(24);
|
|
|
+ for (int i = 0; i < 24; i++) {
|
|
|
+ ecpmData.add(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ Integer networkId = agentChannelView.getNetworkId();
|
|
|
+ param.setNetwork_id_list(Collections.singletonList(networkId));
|
|
|
+ param.setStart_date(todayInt);
|
|
|
+ param.setEnd_date(todayInt);
|
|
|
+ param.setCurrency("CNY");
|
|
|
+ param.setLimit(100);
|
|
|
+ param.setStart(0);
|
|
|
+ param.setTime_zone("UTC+8");
|
|
|
+
|
|
|
+ ResultTable<HourReportView> hourReportViewResultTable = advertiseFeign.hourReport(param);
|
|
|
+ List<HourReportView> data = hourReportViewResultTable.getData();
|
|
|
+ if (!data.isEmpty()) {
|
|
|
+ for (HourReportView hourReport : data) {
|
|
|
+ int hour = hourReport.getHour();
|
|
|
+ if (hour >= 0 && hour < 24) {
|
|
|
+ BigDecimal revenue = hourReport.getEstimated_revenue();
|
|
|
+ hourlyData.set(hour, revenue);
|
|
|
+ ecpmData.set(hour, hourReport.getEstimated_revenue_ecpm());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ indexHourReportView.setEstimatedRevenueList(hourlyData);
|
|
|
+ indexHourReportView.setEstimatedRevenueEcpmList(ecpmData);
|
|
|
+ indexHourReportViews.add(indexHourReportView);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.resultObjOk(indexHourReportViews);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|