|
|
@@ -9,26 +9,33 @@ 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.AppListParam;
|
|
|
import com.ytpm.agent.param.DateRangeParams;
|
|
|
import com.ytpm.agent.param.IndexResParam;
|
|
|
+import com.ytpm.agent.view.AgentAppView;
|
|
|
import com.ytpm.agent.view.AgentChannelView;
|
|
|
+import com.ytpm.agent.view.AgentUserInfo;
|
|
|
import com.ytpm.agent.view.IndexHourReportView;
|
|
|
import com.ytpm.app.model.YtDyzUser;
|
|
|
+import com.ytpm.app.param.AppQueryUserTodayTimeParam;
|
|
|
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.service.AgentAppService;
|
|
|
import com.ytpm.util.DateUtil;
|
|
|
import com.ytpm.util.RedisService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
@@ -74,17 +81,20 @@ public class AgentIndexController {
|
|
|
@Autowired
|
|
|
private RedisService redisService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private AgentAppService agentAppService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询广告平台收益
|
|
|
*/
|
|
|
@ApiOperation("查询广告平台收益")
|
|
|
@PostMapping("/profit")
|
|
|
- public Result<?> profit() {
|
|
|
+ public Result<?> profit(@ApiIgnore @AuthenticationPrincipal AgentUserInfo userInfo) {
|
|
|
// 1. 准备日期参数
|
|
|
DateRangeParams dateParams = prepareDateParams();
|
|
|
|
|
|
// 2. 构建查询参数
|
|
|
- ComprehensiveReportParam reportParam = buildReportParam(dateParams);
|
|
|
+ ComprehensiveReportParam reportParam = buildReportParam(dateParams, userInfo);
|
|
|
|
|
|
// 3. 获取报表数据
|
|
|
List<ComprehensiveAppReport> appReport = fetchReportData(reportParam);
|
|
|
@@ -113,7 +123,7 @@ public class AgentIndexController {
|
|
|
/**
|
|
|
* 构建报表查询参数
|
|
|
*/
|
|
|
- private ComprehensiveReportParam buildReportParam(DateRangeParams dateParams) {
|
|
|
+ private ComprehensiveReportParam buildReportParam(DateRangeParams dateParams, AgentUserInfo userInfo) {
|
|
|
ComprehensiveReportParam param = new ComprehensiveReportParam();
|
|
|
|
|
|
// 设置日期范围
|
|
|
@@ -124,9 +134,19 @@ public class AgentIndexController {
|
|
|
param.setNetwork_firm_id_list(Arrays.stream(AdPlatformTypeEnum.values())
|
|
|
.map(AdPlatformTypeEnum::getCode)
|
|
|
.collect(Collectors.toList()));
|
|
|
-
|
|
|
+ AppListParam appListParam = new AppListParam();
|
|
|
+ appListParam.setUserId(userInfo.getUserId());
|
|
|
+ //增加appId查询
|
|
|
+ List<AgentAppView> agentAppViews = agentAppService.searchAppIdList(appListParam);
|
|
|
+ ArrayList<String> list = new ArrayList<>();
|
|
|
+ if (CollUtil.isNotEmpty(agentAppViews)) {
|
|
|
+ param.setApp_id_list(agentAppViews.stream().map(AgentAppView::getAppId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ param.setApp_id_list(list);
|
|
|
+ }
|
|
|
// 设置分组
|
|
|
- param.setGroup_by(Arrays.asList("date", "network_firm_id"));
|
|
|
+ param.setGroup_by(Arrays.asList("date", "network_firm_id","app"));
|
|
|
|
|
|
return param;
|
|
|
}
|
|
|
@@ -136,8 +156,12 @@ public class AgentIndexController {
|
|
|
*/
|
|
|
private List<ComprehensiveAppReport> fetchReportData(ComprehensiveReportParam param) {
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
- List<ComprehensiveAppReport> appReport = advertiseFeign.getAppReport(param);
|
|
|
- log.info("调用API接口耗时: {}ms", System.currentTimeMillis() - startTime);
|
|
|
+ List<ComprehensiveAppReport> appReport = new ArrayList<>();
|
|
|
+ if (CollUtil.isNotEmpty(param.getApp_id_list())){
|
|
|
+ appReport=advertiseFeign.getAppReport(param);
|
|
|
+ log.info("调用API接口耗时: {}ms", System.currentTimeMillis() - startTime);
|
|
|
+ }
|
|
|
+ //appIdList为空 返回空数据
|
|
|
return appReport;
|
|
|
}
|
|
|
|
|
|
@@ -261,19 +285,17 @@ public class AgentIndexController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 查询分小时报表 折线图数据
|
|
|
* 预估收益以及ecpm
|
|
|
*/
|
|
|
@ApiOperation("查询分小时报表")
|
|
|
@PostMapping("/hourReport")
|
|
|
- public Result<?> hourReport() {
|
|
|
- if (redisService.hasKey("hourReport")) {
|
|
|
- List<IndexHourReportView> hourReportResList = JSON.parseArray(redisService.getStr("hourReport"), IndexHourReportView.class);
|
|
|
+ public Result<?> hourReport(@ApiIgnore @AuthenticationPrincipal AgentUserInfo userInfo) {
|
|
|
+ if (redisService.hasKey("hourReport"+userInfo.getUserId())) {
|
|
|
+ List<IndexHourReportView> hourReportResList = JSON.parseArray(redisService.getStr("hourReport"+userInfo.getUserId()), IndexHourReportView.class);
|
|
|
return Result.resultObjOk(hourReportResList);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
// 1. 准备日期参数
|
|
|
LocalDate today = LocalDate.now();
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
@@ -285,6 +307,16 @@ public class AgentIndexController {
|
|
|
ArrayList<IndexHourReportView> indexHourReportViews = new ArrayList<>();
|
|
|
ArrayList<HourReportParam> hourReportParams = new ArrayList<>();
|
|
|
ConcurrentHourReportsParams concurrentHourReportsParams = new ConcurrentHourReportsParams();
|
|
|
+ AppListParam appListParam = new AppListParam();
|
|
|
+ appListParam.setUserId(userInfo.getUserId());
|
|
|
+ List<AgentAppView> agentAppViews = agentAppService.searchAppIdList(appListParam);
|
|
|
+ List<String> appIdList;
|
|
|
+ if (CollUtil.isNotEmpty(agentAppViews)){
|
|
|
+ appIdList = agentAppViews.stream().map(AgentAppView::getAppId).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Result.resultObjOk(indexHourReportViews);
|
|
|
+ }
|
|
|
for (AgentChannelView agentChannelView : agentChannelViews) {
|
|
|
HourReportParam param = new HourReportParam();
|
|
|
Integer networkId = agentChannelView.getNetworkId();
|
|
|
@@ -296,6 +328,7 @@ public class AgentIndexController {
|
|
|
param.setStart(0);
|
|
|
param.setTime_zone("UTC+8");
|
|
|
param.setChannelName(agentChannelView.getChannelName());
|
|
|
+ param.setApp_id_list(appIdList);
|
|
|
hourReportParams.add(param);
|
|
|
}
|
|
|
concurrentHourReportsParams.setParam(hourReportParams);
|
|
|
@@ -309,7 +342,7 @@ public class AgentIndexController {
|
|
|
indexHourReportViews.add(indexHourReportView);
|
|
|
}
|
|
|
//50分钟过期
|
|
|
- redisService.setTimeOutStr("hourReport",JSON.toJSONString(indexHourReportViews),50*60*1000);
|
|
|
+ redisService.setTimeOutStr("hourReport"+userInfo.getUserId(), JSON.toJSONString(indexHourReportViews), 50 * 60 * 1000);
|
|
|
return Result.resultObjOk(indexHourReportViews);
|
|
|
}
|
|
|
|
|
|
@@ -317,6 +350,7 @@ public class AgentIndexController {
|
|
|
|
|
|
/**
|
|
|
* 对返回的小时报表数据进行处理
|
|
|
+ *
|
|
|
* @param hourReportRes 小时数据
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -343,26 +377,31 @@ public class AgentIndexController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@ApiOperation("查询用户行为数据统计")
|
|
|
@PostMapping("/userStatistic")
|
|
|
- public Result<Map<String, Object>> getDashboardData() throws InterruptedException {
|
|
|
+ public Result<Map<String, Object>> getDashboardData(@ApiIgnore @AuthenticationPrincipal AgentUserInfo userInfo) throws InterruptedException {
|
|
|
Map<String, Object> result = new ConcurrentHashMap<>();
|
|
|
-
|
|
|
+ AppListParam appListParam = new AppListParam();
|
|
|
+ appListParam.setUserId(userInfo.getUserId());
|
|
|
+ List<String> appIdList = null;
|
|
|
+ List<AgentAppView> agentAppViews = agentAppService.searchAppIdList(appListParam);
|
|
|
+ if (CollUtil.isNotEmpty(agentAppViews)){
|
|
|
+ appIdList = agentAppViews.stream().map(AgentAppView::getAppId).collect(Collectors.toList());
|
|
|
+ }
|
|
|
processPeriodData(result, "today",
|
|
|
DateUtil.getTodayStart(),
|
|
|
DateUtil.getTodayEnd(),
|
|
|
- true);
|
|
|
+ true,appIdList);
|
|
|
|
|
|
processPeriodData(result, "yesterday",
|
|
|
DateUtil.getYesterdayStart(),
|
|
|
DateUtil.getYesterdayEnd(),
|
|
|
- false);
|
|
|
+ false,appIdList);
|
|
|
|
|
|
processPeriodData(result, "month",
|
|
|
DateUtil.getMonthStart(),
|
|
|
DateUtil.getMonthEnd(),
|
|
|
- false);
|
|
|
+ false,appIdList);
|
|
|
|
|
|
return Result.resultObjOk(result);
|
|
|
|
|
|
@@ -373,10 +412,11 @@ public class AgentIndexController {
|
|
|
String prefix,
|
|
|
Date startTime,
|
|
|
Date endTime,
|
|
|
- boolean isToday) {
|
|
|
+ boolean isToday,List<String> appIdList) {
|
|
|
AppUserQueryParam param = new AppUserQueryParam();
|
|
|
param.setStartTime(startTime);
|
|
|
param.setEndTime(endTime);
|
|
|
+ param.setAppIdList(appIdList);
|
|
|
|
|
|
// 获取基础数据
|
|
|
int userCount = appFeign.queryUserByTime(param).size();
|
|
|
@@ -388,7 +428,7 @@ public class AgentIndexController {
|
|
|
// 拆解调用步骤
|
|
|
Result<Map<String, Integer>> response = riskFeign.queryBanned(param);
|
|
|
|
|
|
- if(response == null) {
|
|
|
+ if (response == null) {
|
|
|
log.error("Feign调用返回null!");
|
|
|
return;
|
|
|
}
|
|
|
@@ -397,14 +437,14 @@ public class AgentIndexController {
|
|
|
log.info("服务返回消息: {}", response.getMessage());
|
|
|
Map<String, Integer> riskMap = response.getData();
|
|
|
|
|
|
- if(riskMap == null) {
|
|
|
+ if (riskMap == null) {
|
|
|
log.warn("服务返回data字段为null");
|
|
|
} else {
|
|
|
log.info("获取风险数据: {}", riskMap);
|
|
|
}
|
|
|
result.put(prefix + "Risk", riskMap.get("risk"));
|
|
|
result.put(prefix + "Lock", riskMap.get("lock"));
|
|
|
- } catch(Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
log.error("Feign调用异常", e); // 捕获Feign异常
|
|
|
}
|
|
|
|
|
|
@@ -415,8 +455,10 @@ public class AgentIndexController {
|
|
|
|
|
|
// 今日特有逻辑
|
|
|
if (isToday) {
|
|
|
- int[] todayUser = appFeign.queryUserByTodayTime();
|
|
|
- Map<String, int[]> data = riskFeign.queryBannedByHourToday().getData();
|
|
|
+ AppQueryUserTodayTimeParam appQueryUserTodayTimeParam = new AppQueryUserTodayTimeParam();
|
|
|
+ appQueryUserTodayTimeParam.setAppIdList(appIdList);
|
|
|
+ int[] todayUser = appFeign.queryUserByTodayTime(appQueryUserTodayTimeParam);
|
|
|
+ Map<String, int[]> data = riskFeign.queryBannedByHourToday(appQueryUserTodayTimeParam).getData();
|
|
|
|
|
|
result.put("todayUser", todayUser);
|
|
|
result.put("todayRiskHour", data.get("riskHour"));
|