|
@@ -0,0 +1,397 @@
|
|
|
|
|
+package com.fs.admin.controller;
|
|
|
|
|
+
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+import com.fs.common.core.controller.BaseController;
|
|
|
|
|
+import com.fs.common.core.domain.AjaxResult;
|
|
|
|
|
+import com.fs.common.core.page.TableDataInfo;
|
|
|
|
|
+import com.fs.proxy.domain.PlatformStatistics;
|
|
|
|
|
+import com.fs.proxy.domain.Proxy;
|
|
|
|
|
+import com.fs.proxy.domain.ProxyServicePrice;
|
|
|
|
|
+import com.fs.proxy.domain.ProxyTenantRel;
|
|
|
|
|
+import com.fs.proxy.domain.TenantConsumeRecord;
|
|
|
|
|
+import com.fs.proxy.service.*;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 总后台统计控制器(统一使用 platform_statistics 表)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author fs
|
|
|
|
|
+ * @date 2024-01-01
|
|
|
|
|
+ */
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/admin/statistics")
|
|
|
|
|
+public class AdminStatisticsController extends BaseController
|
|
|
|
|
+{
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ProxyTenantRelService proxyTenantRelService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TenantConsumeService tenantConsumeService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ProxyServicePriceService proxyServicePriceService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PlatformStatisticsService platformStatisticsService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ProxyService proxyService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取平台总览统计
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:overview')")
|
|
|
|
|
+ @GetMapping("/overview")
|
|
|
|
|
+ public AjaxResult getOverview() {
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ List<ProxyTenantRel> allRelations = proxyTenantRelService.selectProxyTenantRelList(null);
|
|
|
|
|
+ result.put("totalTenantCount", allRelations.size());
|
|
|
|
|
+
|
|
|
|
|
+ long proxyCount = allRelations.stream().map(ProxyTenantRel::getProxyId).distinct().count();
|
|
|
|
|
+ result.put("totalProxyCount", proxyCount);
|
|
|
|
|
+
|
|
|
|
|
+ Date today = new java.sql.Date(System.currentTimeMillis());
|
|
|
|
|
+ List<PlatformStatistics> todayStats = platformStatisticsService.getHourlyStats(today, null);
|
|
|
|
|
+ BigDecimal todayConsume = todayStats.stream()
|
|
|
|
|
+ .map(s -> s.getConsumeAmount() != null ? s.getConsumeAmount() : BigDecimal.ZERO)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ BigDecimal todayProfit = todayStats.stream()
|
|
|
|
|
+ .map(s -> s.getProxyProfit() != null ? s.getProxyProfit() : BigDecimal.ZERO)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ result.put("todayConsume", todayConsume);
|
|
|
|
|
+ result.put("todayProfit", todayProfit);
|
|
|
|
|
+
|
|
|
|
|
+ // 成本配置数
|
|
|
|
|
+ List<ProxyServicePrice> priceList = proxyServicePriceService.selectProxyServicePriceList(null);
|
|
|
|
|
+ result.put("serviceTypeCount", priceList.size());
|
|
|
|
|
+
|
|
|
|
|
+ return AjaxResult.success(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取代理分佣统计
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:proxyProfit')")
|
|
|
|
|
+ @GetMapping("/proxyProfit")
|
|
|
|
|
+ public TableDataInfo getProxyProfitStatistics(@RequestParam(required = false) String startDate,
|
|
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
|
|
+ Date start = startDate != null ? java.sql.Date.valueOf(startDate) : null;
|
|
|
|
|
+ Date end = endDate != null ? java.sql.Date.valueOf(endDate) : null;
|
|
|
|
|
+ List<PlatformStatistics> stats = platformStatisticsService.getProxyProfitStats(start, end);
|
|
|
|
|
+ return getDataTable(stats);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取租户消费统计
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:tenantConsume')")
|
|
|
|
|
+ @GetMapping("/tenantConsume")
|
|
|
|
|
+ public TableDataInfo getTenantConsumeStatistics(@RequestParam(required = false) String startDate,
|
|
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
|
|
+ Date start = startDate != null ? java.sql.Date.valueOf(startDate) : null;
|
|
|
|
|
+ Date end = endDate != null ? java.sql.Date.valueOf(endDate) : null;
|
|
|
|
|
+ List<PlatformStatistics> stats = platformStatisticsService.getTenantConsumeStats(start, end);
|
|
|
|
|
+ return getDataTable(stats);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取消费类型统计
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:consumeType')")
|
|
|
|
|
+ @GetMapping("/consumeType")
|
|
|
|
|
+ public AjaxResult getConsumeTypeStatistics(@RequestParam(required = false) String startDate,
|
|
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
|
|
+ Date start = startDate != null ? java.sql.Date.valueOf(startDate) : null;
|
|
|
|
|
+ Date end = endDate != null ? java.sql.Date.valueOf(endDate) : null;
|
|
|
|
|
+ List<PlatformStatistics> stats = platformStatisticsService.getConsumeTypeStats(start, end);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ Map<String, BigDecimal> consume = new HashMap<>();
|
|
|
|
|
+ Map<String, BigDecimal> cost = new HashMap<>();
|
|
|
|
|
+ Map<String, BigDecimal> profit = new HashMap<>();
|
|
|
|
|
+ for (PlatformStatistics s : stats) {
|
|
|
|
|
+ String t = s.getConsumeType() != null ? s.getConsumeType() : "未知";
|
|
|
|
|
+ consume.put(t, s.getConsumeAmount());
|
|
|
|
|
+ cost.put(t, s.getPlatformCost());
|
|
|
|
|
+ profit.put(t, s.getProxyProfit());
|
|
|
|
|
+ }
|
|
|
|
|
+ result.put("consumeByType", consume);
|
|
|
|
|
+ result.put("costByType", cost);
|
|
|
|
|
+ result.put("profitByType", profit);
|
|
|
|
|
+ return AjaxResult.success(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取平台成本汇总
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:costSummary')")
|
|
|
|
|
+ @GetMapping("/costSummary")
|
|
|
|
|
+ public AjaxResult getCostSummary(@RequestParam(required = false) String startDate,
|
|
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
|
|
+ Date start = startDate != null ? java.sql.Date.valueOf(startDate) : null;
|
|
|
|
|
+ Date end = endDate != null ? java.sql.Date.valueOf(endDate) : null;
|
|
|
|
|
+
|
|
|
|
|
+ List<PlatformStatistics> typeStats = platformStatisticsService.getConsumeTypeStats(start, end);
|
|
|
|
|
+ List<PlatformStatistics> proxyStats = platformStatisticsService.getProxyProfitStats(start, end);
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal totalCost = typeStats.stream()
|
|
|
|
|
+ .map(s -> s.getPlatformCost() != null ? s.getPlatformCost() : BigDecimal.ZERO)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ BigDecimal totalConsume = typeStats.stream()
|
|
|
|
|
+ .map(s -> s.getConsumeAmount() != null ? s.getConsumeAmount() : BigDecimal.ZERO)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ BigDecimal totalProfit = proxyStats.stream()
|
|
|
|
|
+ .map(s -> s.getProxyProfit() != null ? s.getProxyProfit() : BigDecimal.ZERO)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("totalCost", totalCost);
|
|
|
|
|
+ result.put("totalConsume", totalConsume);
|
|
|
|
|
+ result.put("totalProfit", totalProfit);
|
|
|
|
|
+ result.put("platformRevenue", totalConsume.subtract(totalCost).subtract(totalProfit));
|
|
|
|
|
+ return AjaxResult.success(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取代理分佣详情
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:proxyProfit')")
|
|
|
|
|
+ @GetMapping("/proxyProfit/{proxyId}")
|
|
|
|
|
+ public AjaxResult getProxyProfitDetail(@PathVariable Long proxyId,
|
|
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
|
|
+ Date start = startDate != null ? java.sql.Date.valueOf(startDate) : null;
|
|
|
|
|
+ Date end = endDate != null ? java.sql.Date.valueOf(endDate) : null;
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ List<ProxyTenantRel> tenantList = proxyTenantRelService.selectProxyTenantRelByProxyId(proxyId);
|
|
|
|
|
+ result.put("tenantList", tenantList);
|
|
|
|
|
+
|
|
|
|
|
+ List<PlatformStatistics> detail = platformStatisticsService.getProxyDetail(proxyId, start, end);
|
|
|
|
|
+ BigDecimal total = detail.stream()
|
|
|
|
|
+ .map(s -> s.getProxyProfit() != null ? s.getProxyProfit() : BigDecimal.ZERO)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ result.put("totalProfit", total);
|
|
|
|
|
+ result.put("details", detail);
|
|
|
|
|
+ return AjaxResult.success(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取租户消费详情
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:tenantConsume')")
|
|
|
|
|
+ @GetMapping("/tenantDetail/{tenantId}")
|
|
|
|
|
+ public AjaxResult getTenantDetail(@PathVariable Long tenantId,
|
|
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
|
|
+ Date start = startDate != null ? java.sql.Date.valueOf(startDate) : null;
|
|
|
|
|
+ Date end = endDate != null ? java.sql.Date.valueOf(endDate) : null;
|
|
|
|
|
+ List<PlatformStatistics> detail = platformStatisticsService.getTenantDetail(tenantId, start, end);
|
|
|
|
|
+ return AjaxResult.success(detail);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取平台趋势
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:trend')")
|
|
|
|
|
+ @GetMapping("/trend")
|
|
|
|
|
+ public AjaxResult getPlatformTrend(@RequestParam(required = false) String startDate,
|
|
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
|
|
+ Date start = startDate != null ? java.sql.Date.valueOf(startDate) : null;
|
|
|
|
|
+ Date end = endDate != null ? java.sql.Date.valueOf(endDate) : null;
|
|
|
|
|
+ List<PlatformStatistics> trend = platformStatisticsService.getTrend(start, end);
|
|
|
|
|
+ return AjaxResult.success(trend);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取小时统计
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:hourly')")
|
|
|
|
|
+ @GetMapping("/hourly")
|
|
|
|
|
+ public AjaxResult getHourlyStatistics(@RequestParam(required = false) String statDate,
|
|
|
|
|
+ @RequestParam(required = false) String dimension) {
|
|
|
|
|
+ if (statDate == null || statDate.isEmpty()) {
|
|
|
|
|
+ statDate = java.time.LocalDate.now().toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ Date date = java.sql.Date.valueOf(statDate);
|
|
|
|
|
+ List<PlatformStatistics> stats = platformStatisticsService.getHourlyStats(date, dimension);
|
|
|
|
|
+ return AjaxResult.success(stats);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取服务成本配置
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:costConfig')")
|
|
|
|
|
+ @GetMapping("/costConfig")
|
|
|
|
|
+ public AjaxResult getCostConfigList() {
|
|
|
|
|
+ return AjaxResult.success(proxyServicePriceService.selectProxyServicePriceList(null));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取原始消费记录列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:tenantConsume')")
|
|
|
|
|
+ @GetMapping("/consumeRecords")
|
|
|
|
|
+ public TableDataInfo getConsumeRecords(TenantConsumeRecord query) {
|
|
|
|
|
+ startPage();
|
|
|
|
|
+ List<TenantConsumeRecord> list = tenantConsumeService.selectTenantConsumeRecordList(query);
|
|
|
|
|
+ return getDataTable(list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 手动执行统计
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:execute')")
|
|
|
|
|
+ @PostMapping("/execute")
|
|
|
|
|
+ public AjaxResult executeStatistics(@RequestParam(required = false) String type) {
|
|
|
|
|
+ if ("daily".equals(type)) {
|
|
|
|
|
+ platformStatisticsService.executeDailySummary();
|
|
|
|
|
+ return AjaxResult.success("日汇总执行成功");
|
|
|
|
|
+ } else if ("monthly".equals(type)) {
|
|
|
|
|
+ platformStatisticsService.executeMonthlySummary();
|
|
|
|
|
+ return AjaxResult.success("月汇总执行成功");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ platformStatisticsService.executeHourlyStats();
|
|
|
|
|
+ return AjaxResult.success("小时统计执行成功");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== 每日统计(代理维度) ====================
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 每日统计 - 代理下租户消费明细
|
|
|
|
|
+ * 按天统计指定代理下每个租户的消费金额、成本、利润
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:daily')")
|
|
|
|
|
+ @GetMapping("/daily/agentTenants")
|
|
|
|
|
+ public AjaxResult getDailyAgentTenants(
|
|
|
|
|
+ @RequestParam(required = false) Long proxyId,
|
|
|
|
|
+ @RequestParam(required = false) String statDate) {
|
|
|
|
|
+ Date date = statDate != null ? java.sql.Date.valueOf(statDate)
|
|
|
|
|
+ : new java.sql.Date(System.currentTimeMillis());
|
|
|
|
|
+
|
|
|
|
|
+ // 获取该代理下的所有租户
|
|
|
|
|
+ List<ProxyTenantRel> tenantRels = proxyTenantRelService.selectProxyTenantRelByProxyId(proxyId);
|
|
|
|
|
+ List<Long> tenantIds = new java.util.ArrayList<>();
|
|
|
|
|
+ for (ProxyTenantRel rel : tenantRels) {
|
|
|
|
|
+ tenantIds.add(rel.getTenantId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询这些租户的日统计
|
|
|
|
|
+ List<PlatformStatistics> stats = platformStatisticsService.getTenantDailyByProxy(proxyId, tenantIds, date);
|
|
|
|
|
+
|
|
|
|
|
+ // 补充租户名称
|
|
|
|
|
+ Map<Long, String> tenantNameMap = new java.util.HashMap<>();
|
|
|
|
|
+ for (ProxyTenantRel rel : tenantRels) {
|
|
|
|
|
+ tenantNameMap.put(rel.getTenantId(), rel.getTenantName());
|
|
|
|
|
+ }
|
|
|
|
|
+ for (PlatformStatistics s : stats) {
|
|
|
|
|
+ if (s.getTenantId() != null && tenantNameMap.containsKey(s.getTenantId())) {
|
|
|
|
|
+ s.setRemark(tenantNameMap.get(s.getTenantId()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 计算汇总
|
|
|
|
|
+ BigDecimal totalConsume = stats.stream()
|
|
|
|
|
+ .map(s -> s.getConsumeAmount() != null ? s.getConsumeAmount() : BigDecimal.ZERO)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ BigDecimal totalCost = stats.stream()
|
|
|
|
|
+ .map(s -> s.getPlatformCost() != null ? s.getPlatformCost() : BigDecimal.ZERO)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ BigDecimal totalProfit = stats.stream()
|
|
|
|
|
+ .map(s -> s.getTenantPrice() != null ? s.getTenantPrice() : BigDecimal.ZERO)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
|
|
+ .subtract(totalCost);
|
|
|
|
|
+ BigDecimal totalAgentProfit = stats.stream()
|
|
|
|
|
+ .map(s -> s.getProxyProfit() != null ? s.getProxyProfit() : BigDecimal.ZERO)
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("statDate", statDate);
|
|
|
|
|
+ result.put("proxyId", proxyId);
|
|
|
|
|
+ result.put("tenantCount", tenantRels.size());
|
|
|
|
|
+ result.put("totalConsume", totalConsume);
|
|
|
|
|
+ result.put("totalCost", totalCost);
|
|
|
|
|
+ result.put("totalProfit", totalProfit);
|
|
|
|
|
+ result.put("totalAgentProfit", totalAgentProfit);
|
|
|
|
|
+ result.put("items", stats);
|
|
|
|
|
+ result.put("tenantNames", tenantNameMap);
|
|
|
|
|
+ return AjaxResult.success(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 每日统计 - 各服务类型利润
|
|
|
|
|
+ * 按天统计指定代理下各服务类型的消费、成本、利润
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:daily')")
|
|
|
|
|
+ @GetMapping("/daily/serviceTypeProfit")
|
|
|
|
|
+ public AjaxResult getDailyServiceTypeProfit(
|
|
|
|
|
+ @RequestParam(required = false) Long proxyId,
|
|
|
|
|
+ @RequestParam(required = false) String statDate) {
|
|
|
|
|
+ Date date = statDate != null ? java.sql.Date.valueOf(statDate)
|
|
|
|
|
+ : new java.sql.Date(System.currentTimeMillis());
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> tenantIds = null;
|
|
|
|
|
+ if (proxyId != null) {
|
|
|
|
|
+ List<ProxyTenantRel> tenantRels = proxyTenantRelService.selectProxyTenantRelByProxyId(proxyId);
|
|
|
|
|
+ tenantIds = new java.util.ArrayList<>();
|
|
|
|
|
+ for (ProxyTenantRel rel : tenantRels) {
|
|
|
|
|
+ tenantIds.add(rel.getTenantId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<PlatformStatistics> stats = platformStatisticsService.getTypeDailyByProxyTenants(tenantIds, date);
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal totalProfit = stats.stream()
|
|
|
|
|
+ .map(s -> {
|
|
|
|
|
+ BigDecimal ca = s.getConsumeAmount() != null ? s.getConsumeAmount() : BigDecimal.ZERO;
|
|
|
|
|
+ BigDecimal pc = s.getPlatformCost() != null ? s.getPlatformCost() : BigDecimal.ZERO;
|
|
|
|
|
+ return ca.subtract(pc);
|
|
|
|
|
+ })
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("statDate", statDate);
|
|
|
|
|
+ result.put("proxyId", proxyId);
|
|
|
|
|
+ result.put("totalProfit", totalProfit);
|
|
|
|
|
+ result.put("items", stats);
|
|
|
|
|
+ return AjaxResult.success(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 每日统计 - 代理汇总
|
|
|
|
|
+ * 按天汇总所有代理的消费、成本、利润
|
|
|
|
|
+ */
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermi('admin:statistics:daily')")
|
|
|
|
|
+ @GetMapping("/daily/agentSummary")
|
|
|
|
|
+ public AjaxResult getDailyAgentSummary(
|
|
|
|
|
+ @RequestParam(required = false) String statDate) {
|
|
|
|
|
+ Date date = statDate != null ? java.sql.Date.valueOf(statDate)
|
|
|
|
|
+ : new java.sql.Date(System.currentTimeMillis());
|
|
|
|
|
+
|
|
|
|
|
+ List<PlatformStatistics> stats = platformStatisticsService.getAgentDailySummary(date);
|
|
|
|
|
+
|
|
|
|
|
+ // 补充代理名称
|
|
|
|
|
+ List<Proxy> allProxies = proxyService.selectProxyList(null);
|
|
|
|
|
+ Map<Long, String> proxyNameMap = new java.util.HashMap<>();
|
|
|
|
|
+ for (Proxy p : allProxies) {
|
|
|
|
|
+ proxyNameMap.put(p.getProxyId(), p.getProxyName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("statDate", statDate);
|
|
|
|
|
+ result.put("proxyCount", stats.size());
|
|
|
|
|
+ result.put("items", stats);
|
|
|
|
|
+ result.put("proxyNames", proxyNameMap);
|
|
|
|
|
+ return AjaxResult.success(result);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|