|
|
@@ -1,21 +1,27 @@
|
|
|
package com.ytpm.controller;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.ytpm.advertise.enums.AdPlatformTypeEnum;
|
|
|
import com.ytpm.advertise.param.ComprehensiveReportParam;
|
|
|
+import com.ytpm.advertise.param.ConcurrentHourReportsParams;
|
|
|
import com.ytpm.advertise.param.HourReportParam;
|
|
|
import com.ytpm.advertise.view.ComprehensiveAppReport;
|
|
|
+import com.ytpm.advertise.view.HourReportRes;
|
|
|
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.app.model.YtDyzUser;
|
|
|
+import com.ytpm.app.param.AppUserQueryParam;
|
|
|
import com.ytpm.dao.ChannelMapper;
|
|
|
import com.ytpm.feign.AdvertiseFeign;
|
|
|
+import com.ytpm.feign.AppFeign;
|
|
|
+import com.ytpm.feign.RiskFeign;
|
|
|
import com.ytpm.general.Result;
|
|
|
-import com.ytpm.general.ResultTable;
|
|
|
-import com.ytpm.service.impl.ChannelServiceImpl;
|
|
|
+import com.ytpm.util.DateUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
@@ -31,6 +37,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
@Api(tags = "首页数据统计模块")
|
|
|
@RestController
|
|
|
+@Slf4j
|
|
|
@RequestMapping("/index")
|
|
|
public class AgentIndexController {
|
|
|
|
|
|
@@ -40,6 +47,12 @@ public class AgentIndexController {
|
|
|
@Resource
|
|
|
private ChannelMapper channelMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private AppFeign appFeign;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RiskFeign riskFeign;
|
|
|
+
|
|
|
/**
|
|
|
* 查询广告平台收益
|
|
|
*/
|
|
|
@@ -75,7 +88,10 @@ public class AgentIndexController {
|
|
|
param.setGroup_by(Arrays.asList("date", "network_firm_id"));
|
|
|
|
|
|
// 3. 获取报表数据
|
|
|
+ long currentTime = System.currentTimeMillis();
|
|
|
List<ComprehensiveAppReport> appReport = advertiseFeign.getAppReport(param);
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ log.info("调用api接口时间{}", endTime - currentTime);
|
|
|
|
|
|
// 4. 按平台分类统计
|
|
|
List<IndexResParam> result = Arrays.stream(AdPlatformTypeEnum.values())
|
|
|
@@ -146,6 +162,8 @@ public class AgentIndexController {
|
|
|
return resParam;
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
+ long endResolve = System.currentTimeMillis();
|
|
|
+ log.debug("stream执行时间{}", endResolve - endTime);
|
|
|
|
|
|
return Result.resultObjOk(result);
|
|
|
}
|
|
|
@@ -157,7 +175,7 @@ public class AgentIndexController {
|
|
|
@ApiOperation("查询分小时报表")
|
|
|
@PostMapping("/hourReport")
|
|
|
public Result<?> hourReport() {
|
|
|
- HourReportParam param = new HourReportParam();
|
|
|
+
|
|
|
// 1. 准备日期参数
|
|
|
LocalDate today = LocalDate.now();
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
@@ -167,47 +185,111 @@ public class AgentIndexController {
|
|
|
Integer todayInt = Integer.valueOf(todayStr);
|
|
|
List<AgentChannelView> agentChannelViews = channelMapper.channelList();
|
|
|
ArrayList<IndexHourReportView> indexHourReportViews = new ArrayList<>();
|
|
|
-
|
|
|
+ ArrayList<HourReportParam> hourReportParams = new ArrayList<>();
|
|
|
+ ConcurrentHourReportsParams concurrentHourReportsParams = new ConcurrentHourReportsParams();
|
|
|
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);
|
|
|
- }
|
|
|
+ HourReportParam param = new HourReportParam();
|
|
|
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.setLimit(1000);
|
|
|
param.setStart(0);
|
|
|
param.setTime_zone("UTC+8");
|
|
|
+ param.setChannelName(agentChannelView.getChannelName());
|
|
|
+ hourReportParams.add(param);
|
|
|
+ }
|
|
|
+ concurrentHourReportsParams.setParam(hourReportParams);
|
|
|
+ //进行远程调用获取数据
|
|
|
+ Result<List<HourReportRes>> listResult = advertiseFeign.concurrentHourReports(concurrentHourReportsParams);
|
|
|
+ List<HourReportRes> hourReportResList = listResult.getData();
|
|
|
+ for (HourReportRes hourReportRes : hourReportResList) {
|
|
|
+ //处理数据
|
|
|
+ IndexHourReportView indexHourReportView = buildIndexHourReportView(hourReportRes);
|
|
|
+ //加入数组中
|
|
|
+ indexHourReportViews.add(indexHourReportView);
|
|
|
+ }
|
|
|
+ return Result.resultObjOk(indexHourReportViews);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 对返回的小时报表数据进行处理
|
|
|
+ * @param hourReportRes 小时数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private IndexHourReportView buildIndexHourReportView(HourReportRes hourReportRes) {
|
|
|
+ IndexHourReportView indexHourReportView = new IndexHourReportView();
|
|
|
+ indexHourReportView.setChannelName(hourReportRes.getChannelName());
|
|
|
+ List<BigDecimal> hourlyData = new ArrayList<>(Collections.nCopies(24, BigDecimal.ZERO));
|
|
|
+ List<BigDecimal> ecpmData = new ArrayList<>(Collections.nCopies(24, BigDecimal.ZERO));
|
|
|
+ if (CollUtil.isNotEmpty(hourReportRes.getList())) {
|
|
|
+ for (HourReportView hourReport : hourReportRes.getList()) {
|
|
|
+ int hour = hourReport.getHour();
|
|
|
+ if (hour >= 0 && hour < 24) {
|
|
|
+ BigDecimal revenue = hourReport.getEstimated_revenue();
|
|
|
+ BigDecimal ecpm = hourReport.getEstimated_revenue_ecpm();
|
|
|
|
|
|
- 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());
|
|
|
- }
|
|
|
+ hourlyData.set(hour, revenue != null ? revenue : BigDecimal.ZERO);
|
|
|
+ ecpmData.set(hour, ecpm != null ? ecpm : BigDecimal.ZERO);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- indexHourReportView.setEstimatedRevenueList(hourlyData);
|
|
|
- indexHourReportView.setEstimatedRevenueEcpmList(ecpmData);
|
|
|
- indexHourReportViews.add(indexHourReportView);
|
|
|
}
|
|
|
+ indexHourReportView.setEstimatedRevenueList(hourlyData);
|
|
|
+ indexHourReportView.setEstimatedRevenueEcpmList(ecpmData);
|
|
|
+ return indexHourReportView;
|
|
|
+ }
|
|
|
|
|
|
- return Result.resultObjOk(indexHourReportViews);
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("查询用户行为数据统计")
|
|
|
+ @PostMapping("/userStatistic")
|
|
|
+ public Result<?> userStatistic() {
|
|
|
+ HashMap<String, Object> result = new HashMap<>();
|
|
|
+ AppUserQueryParam param = new AppUserQueryParam();
|
|
|
+ // 1. 查询今日数据
|
|
|
+ param.setStartTime(DateUtil.getTodayStart());
|
|
|
+ param.setEndTime(DateUtil.getTodayEnd());
|
|
|
+ List<YtDyzUser> todayUsers = appFeign.queryUserByTime(param);
|
|
|
+ //每个小时的用户数
|
|
|
+ int[] todayUser = appFeign.queryUserByTodayTime();
|
|
|
+ List<String> todayLogin = appFeign.queryLoginRecords(param);
|
|
|
+ Result<Map<String, Integer>> mapResult = riskFeign.queryBanned(param);
|
|
|
+ Map<String, int[]> data = riskFeign.queryBannedByHourToday().getData();
|
|
|
+ Map<String, Integer> todayMap = mapResult.getData();
|
|
|
+ //用户新增数
|
|
|
+ result.put("today", todayUsers.size());
|
|
|
+ result.put("todayLogin", todayLogin.size());
|
|
|
+ result.put("todayRisk", todayMap.get("risk"));
|
|
|
+ result.put("todayLock", todayMap.get("lock"));
|
|
|
+ result.put("todayRiskHour", data.get("riskHour"));
|
|
|
+ result.put("todayLockHour", data.get("lockHour"));
|
|
|
+ //每个小时的用户数
|
|
|
+ result.put("todayUser", todayUser);
|
|
|
+ // 2. 查询昨日数据
|
|
|
+ param.setStartTime(DateUtil.getYesterdayStart());
|
|
|
+ param.setEndTime(DateUtil.getYesterdayEnd());
|
|
|
+ List<YtDyzUser> yesterdayUsers = appFeign.queryUserByTime(param);
|
|
|
+ List<String> yesterdayLogin = appFeign.queryLoginRecords(param);
|
|
|
+ Map<String, Integer> yesterdayMap = riskFeign.queryBanned(param).getData();
|
|
|
+ result.put("yesterday", yesterdayUsers.size());
|
|
|
+ result.put("yesterdayLogin", yesterdayLogin.size());
|
|
|
+ //封禁数
|
|
|
+ result.put("yesterdayRisk", yesterdayMap.get("risk"));
|
|
|
+ //锁定数
|
|
|
+ result.put("yesterdayLock", yesterdayMap.get("lock"));
|
|
|
+ // 3. 查询本月数据
|
|
|
+ param.setStartTime(DateUtil.getMonthStart());
|
|
|
+ param.setEndTime(DateUtil.getMonthEnd());
|
|
|
+ List<String> monthLogin = appFeign.queryLoginRecords(param);
|
|
|
+ List<YtDyzUser> monthUsers = appFeign.queryUserByTime(param);
|
|
|
+ Map<String, Integer> monthMap = riskFeign.queryBanned(param).getData();
|
|
|
+
|
|
|
+ result.put("month", monthUsers.size());
|
|
|
+ result.put("monthLogin", monthLogin.size());
|
|
|
+ result.put("monthRisk", monthMap.get("risk"));
|
|
|
+ result.put("monthLock", monthMap.get("lock"));
|
|
|
+ return Result.resultObjOk(result);
|
|
|
}
|
|
|
|
|
|
|