|
|
@@ -0,0 +1,119 @@
|
|
|
+package com.ytpm.controller;
|
|
|
+
|
|
|
+import com.ytpm.advertise.enums.AdPlatformTypeEnum;
|
|
|
+import com.ytpm.advertise.param.ComprehensiveReportParam;
|
|
|
+import com.ytpm.advertise.view.ComprehensiveAppReport;
|
|
|
+import com.ytpm.agent.param.IndexResParam;
|
|
|
+import com.ytpm.feign.AdvertiseFeign;
|
|
|
+import com.ytpm.general.Result;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+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.stream.Collectors;
|
|
|
+
|
|
|
+@Api(tags = "首页数据统计模块")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/index")
|
|
|
+public class AgentIndexController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AdvertiseFeign advertiseFeign;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询广告平台收益
|
|
|
+ */
|
|
|
+ @ApiOperation("查询广告平台收益")
|
|
|
+ @PostMapping("/profit")
|
|
|
+ public Result<?> profit() {
|
|
|
+ // 1. 准备日期参数
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
+
|
|
|
+ // 今日和昨日日期
|
|
|
+ String todayStr = today.format(formatter);
|
|
|
+ String yesterdayStr = today.minusDays(1).format(formatter);
|
|
|
+
|
|
|
+ // 本月日期范围
|
|
|
+ LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ String monthStartStr = firstDayOfMonth.format(formatter);
|
|
|
+ String monthEndStr = lastDayOfMonth.format(formatter);
|
|
|
+
|
|
|
+ // 2. 构建查询参数(查询本月所有平台数据)
|
|
|
+ ComprehensiveReportParam param = new ComprehensiveReportParam();
|
|
|
+ param.setStartdate(Integer.parseInt(monthStartStr));
|
|
|
+ param.setEnddate(Integer.parseInt(monthEndStr));
|
|
|
+
|
|
|
+ // 添加所有平台ID
|
|
|
+ List<Integer> platformIds = Arrays.stream(AdPlatformTypeEnum.values())
|
|
|
+ .map(AdPlatformTypeEnum::getCode)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ param.setNetwork_firm_id_list(new ArrayList<>(platformIds));
|
|
|
+
|
|
|
+ // 设置分组
|
|
|
+ param.setGroup_by(Arrays.asList("date", "network_firm_id"));
|
|
|
+
|
|
|
+ // 3. 获取报表数据
|
|
|
+ List<ComprehensiveAppReport> appReport = advertiseFeign.getAppReport(param);
|
|
|
+
|
|
|
+ // 4. 按平台分类统计
|
|
|
+ List<IndexResParam> result = Arrays.stream(AdPlatformTypeEnum.values())
|
|
|
+ .map(platform -> {
|
|
|
+ IndexResParam resParam = new IndexResParam();
|
|
|
+ resParam.setPlatform(platform.getDesc());
|
|
|
+
|
|
|
+ // 过滤当前平台的数据
|
|
|
+ List<ComprehensiveAppReport> platformReports = appReport.stream()
|
|
|
+ .filter(item -> String.valueOf(platform.getCode()).equals(item.getNetwork_firm_id()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 统计今日数据
|
|
|
+ BigDecimal todayRevenue = platformReports.stream()
|
|
|
+ .filter(item -> todayStr.equals(item.getDate()))
|
|
|
+ .map(ComprehensiveAppReport::getRevenue)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ resParam.setToday(todayRevenue.setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+
|
|
|
+ // 统计昨日数据
|
|
|
+ BigDecimal yesterdayRevenue = platformReports.stream()
|
|
|
+ .filter(item -> yesterdayStr.equals(item.getDate()))
|
|
|
+ .map(ComprehensiveAppReport::getRevenue)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ resParam.setYesterday(yesterdayRevenue.setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+
|
|
|
+ // 统计本月数据
|
|
|
+ BigDecimal monthRevenue = platformReports.stream()
|
|
|
+ .filter(item -> {
|
|
|
+ String date = item.getDate();
|
|
|
+ return date != null && date.compareTo(monthStartStr) >= 0
|
|
|
+ && date.compareTo(monthEndStr) <= 0;
|
|
|
+ })
|
|
|
+ .map(ComprehensiveAppReport::getRevenue)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ resParam.setMonth(monthRevenue.setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+
|
|
|
+ return resParam;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return Result.resultObjOk(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|