mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-15 02:57:10 +08:00
feat: 新增查询仪表盘数据总览相关接口, 重构仪表盘相关代码
This commit is contained in:
@@ -31,7 +31,7 @@ import java.util.Set;
|
||||
/**
|
||||
* 内部生成配置信息
|
||||
*
|
||||
* @author zhangqcc
|
||||
* @author Charles7c
|
||||
* @since 2024/8/30 19:35
|
||||
*/
|
||||
@Data
|
||||
|
@@ -16,17 +16,21 @@
|
||||
|
||||
package top.continew.admin.system.mapper;
|
||||
|
||||
import com.alicp.jetcache.anno.Cached;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import top.continew.admin.common.constant.CacheConstants;
|
||||
import top.continew.admin.system.model.entity.LogDO;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardAccessTrendResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardTotalResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardOverviewCommonResp;
|
||||
import top.continew.admin.system.model.resp.log.LogResp;
|
||||
import top.continew.starter.data.mp.base.BaseMapper;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -56,19 +60,54 @@ public interface LogMapper extends BaseMapper<LogDO> {
|
||||
List<LogResp> selectLogList(@Param(Constants.WRAPPER) QueryWrapper<LogDO> queryWrapper);
|
||||
|
||||
/**
|
||||
* 查询仪表盘总计信息
|
||||
* 查询总数量
|
||||
*
|
||||
* @return 仪表盘总计信息
|
||||
* @return 总数量
|
||||
*/
|
||||
DashboardTotalResp selectDashboardTotal();
|
||||
@Select("SELECT COUNT(*) FROM sys_log")
|
||||
Long selectTotalCount();
|
||||
|
||||
/**
|
||||
* 查询仪表盘 PV 总览
|
||||
*
|
||||
* @return 仪表盘 PV 总览
|
||||
*/
|
||||
DashboardOverviewCommonResp selectDashboardOverviewPv();
|
||||
|
||||
/**
|
||||
* 查询仪表盘 IP 总览
|
||||
*
|
||||
* @return 仪表盘 IP 总览
|
||||
*/
|
||||
DashboardOverviewCommonResp selectDashboardOverviewIp();
|
||||
|
||||
/**
|
||||
* 查询仪表盘 PV 近 N 月各月份信息
|
||||
*
|
||||
* @param months 近 N 月月份列表
|
||||
* @return 仪表盘 PV 近 N 月各月份信息
|
||||
*/
|
||||
@Cached(key = "#months[0]", name = CacheConstants.DASHBOARD_KEY_PREFIX + "PV:")
|
||||
List<DashboardChartCommonResp> selectListDashboardAnalysisPv(@Param("months") List<String> months);
|
||||
|
||||
/**
|
||||
* 查询仪表盘 IP 近 N 月各月份信息
|
||||
*
|
||||
* @param months 近 N 月月份列表
|
||||
* @return 仪表盘 IP 近 N 月各月份信息
|
||||
*/
|
||||
@Cached(key = "#months[0]", name = CacheConstants.DASHBOARD_KEY_PREFIX + "IP:")
|
||||
List<DashboardChartCommonResp> selectListDashboardAnalysisIp(@Param("months") List<String> months);
|
||||
|
||||
/**
|
||||
* 查询仪表盘访问趋势信息
|
||||
*
|
||||
* @param days 日期数
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 仪表盘访问趋势信息
|
||||
*/
|
||||
List<DashboardAccessTrendResp> selectListDashboardAccessTrend(@Param("days") Integer days);
|
||||
List<DashboardAccessTrendResp> selectListDashboardAccessTrend(@Param("startTime") Date startTime,
|
||||
@Param("endTime") Date endTime);
|
||||
|
||||
/**
|
||||
* 查询仪表盘访问时段分析信息
|
||||
|
@@ -17,7 +17,9 @@
|
||||
package top.continew.admin.system.model.resp.dashboard;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@@ -29,6 +31,8 @@ import java.io.Serializable;
|
||||
* @since 2023/9/9 20:20
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "仪表盘-访问趋势信息")
|
||||
public class DashboardAccessTrendResp implements Serializable {
|
||||
|
||||
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp.dashboard;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 仪表盘-通用总览信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2024/10/19 12:19
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "仪表盘-通用总览信息")
|
||||
public class DashboardOverviewCommonResp implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 总数
|
||||
*/
|
||||
@Schema(description = "总数", example = "888888")
|
||||
private Long total;
|
||||
|
||||
/**
|
||||
* 今日数量
|
||||
*/
|
||||
@Schema(description = "今日数量", example = "888")
|
||||
private Long today;
|
||||
|
||||
/**
|
||||
* 较昨日新增(百分比)
|
||||
*/
|
||||
@Schema(description = "较昨日新增(百分比)", example = "23.4")
|
||||
private BigDecimal growth;
|
||||
|
||||
/**
|
||||
* 图表数据
|
||||
*/
|
||||
@Schema(description = "图表数据")
|
||||
private List<DashboardChartCommonResp> dataList;
|
||||
|
||||
/**
|
||||
* 昨日数量
|
||||
*/
|
||||
@JsonIgnore
|
||||
private Long yesterday;
|
||||
}
|
@@ -29,11 +29,25 @@ import java.util.List;
|
||||
public interface DashboardService {
|
||||
|
||||
/**
|
||||
* 查询总计信息
|
||||
* 查询公告列表
|
||||
*
|
||||
* @return 总计信息
|
||||
* @return 公告列表
|
||||
*/
|
||||
DashboardTotalResp getTotal();
|
||||
List<DashboardNoticeResp> listNotice();
|
||||
|
||||
/**
|
||||
* 查询 PV 总览
|
||||
*
|
||||
* @return PV 总览
|
||||
*/
|
||||
DashboardOverviewCommonResp getOverviewPv();
|
||||
|
||||
/**
|
||||
* 查询 IP 总览
|
||||
*
|
||||
* @return IP 总览
|
||||
*/
|
||||
DashboardOverviewCommonResp getOverviewIp();
|
||||
|
||||
/**
|
||||
* 查询访问趋势信息
|
||||
@@ -43,13 +57,6 @@ public interface DashboardService {
|
||||
*/
|
||||
List<DashboardAccessTrendResp> listAccessTrend(Integer days);
|
||||
|
||||
/**
|
||||
* 查询公告列表
|
||||
*
|
||||
* @return 公告列表
|
||||
*/
|
||||
List<DashboardNoticeResp> listNotice();
|
||||
|
||||
/**
|
||||
* 查询访问时段分析信息
|
||||
*
|
||||
|
@@ -18,17 +18,12 @@ package top.continew.admin.system.service;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import top.continew.admin.system.model.query.LogQuery;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardAccessTrendResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardTotalResp;
|
||||
import top.continew.admin.system.model.resp.log.LogDetailResp;
|
||||
import top.continew.admin.system.model.resp.log.LogResp;
|
||||
import top.continew.starter.extension.crud.model.query.PageQuery;
|
||||
import top.continew.starter.extension.crud.model.query.SortQuery;
|
||||
import top.continew.starter.extension.crud.model.resp.PageResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统日志业务接口
|
||||
*
|
||||
@@ -71,58 +66,4 @@ public interface LogService {
|
||||
* @param response 响应对象
|
||||
*/
|
||||
void exportOperationLog(LogQuery query, SortQuery sortQuery, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 查询仪表盘总计信息
|
||||
*
|
||||
* @return 仪表盘总计信息
|
||||
*/
|
||||
DashboardTotalResp getDashboardTotal();
|
||||
|
||||
/**
|
||||
* 查询仪表盘访问趋势信息
|
||||
*
|
||||
* @param days 日期数
|
||||
* @return 仪表盘访问趋势信息
|
||||
*/
|
||||
List<DashboardAccessTrendResp> listDashboardAccessTrend(Integer days);
|
||||
|
||||
/**
|
||||
* 查询仪表盘访问时段分析信息
|
||||
*
|
||||
* @return 仪表盘访问时段分析信息
|
||||
*/
|
||||
List<DashboardChartCommonResp> listDashboardAnalysisTimeslot();
|
||||
|
||||
/**
|
||||
* 查询仪表盘地域分析信息
|
||||
*
|
||||
* @param top 显示数量
|
||||
* @return 仪表盘地域分析信息
|
||||
*/
|
||||
List<DashboardChartCommonResp> listDashboardAnalysisGeo(int top);
|
||||
|
||||
/**
|
||||
* 查询仪表盘模块分析信息
|
||||
*
|
||||
* @param top 显示数量
|
||||
* @return 仪表盘模块分析信息
|
||||
*/
|
||||
List<DashboardChartCommonResp> listDashboardAnalysisModule(int top);
|
||||
|
||||
/**
|
||||
* 查询仪表盘终端分析信息
|
||||
*
|
||||
* @param top 显示数量
|
||||
* @return 仪表盘终端分析信息
|
||||
*/
|
||||
List<DashboardChartCommonResp> listDashboardAnalysisOs(int top);
|
||||
|
||||
/**
|
||||
* 查询仪表盘浏览器分析信息
|
||||
*
|
||||
* @param top 显示数量
|
||||
* @return 仪表盘浏览器分析信息
|
||||
*/
|
||||
List<DashboardChartCommonResp> listDashboardAnalysisBrowser(int top);
|
||||
}
|
||||
|
@@ -16,16 +16,21 @@
|
||||
|
||||
package top.continew.admin.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.*;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.continew.admin.system.model.resp.dashboard.*;
|
||||
import top.continew.admin.system.mapper.LogMapper;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardAccessTrendResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardOverviewCommonResp;
|
||||
import top.continew.admin.system.service.DashboardService;
|
||||
import top.continew.admin.system.service.LogService;
|
||||
import top.continew.admin.system.service.NoticeService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 仪表盘业务实现
|
||||
@@ -37,54 +42,153 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class DashboardServiceImpl implements DashboardService {
|
||||
|
||||
private final LogService logService;
|
||||
private final LogMapper logMapper;
|
||||
private final NoticeService noticeService;
|
||||
|
||||
@Override
|
||||
public DashboardTotalResp getTotal() {
|
||||
DashboardTotalResp totalResp = logService.getDashboardTotal();
|
||||
Long todayPvCount = totalResp.getTodayPvCount();
|
||||
Long yesterdayPvCount = totalResp.getYesterdayPvCount();
|
||||
BigDecimal newPvCountFromYesterday = NumberUtil.sub(todayPvCount, yesterdayPvCount);
|
||||
BigDecimal newPvFromYesterday = (0 == yesterdayPvCount)
|
||||
? BigDecimal.valueOf(100)
|
||||
: NumberUtil.round(NumberUtil.mul(NumberUtil.div(newPvCountFromYesterday, yesterdayPvCount), 100), 1);
|
||||
totalResp.setNewPvFromYesterday(newPvFromYesterday);
|
||||
return totalResp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardAccessTrendResp> listAccessTrend(Integer days) {
|
||||
return logService.listDashboardAccessTrend(days);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardNoticeResp> listNotice() {
|
||||
return noticeService.listDashboard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardOverviewCommonResp getOverviewPv() {
|
||||
DashboardOverviewCommonResp resp = logMapper.selectDashboardOverviewPv();
|
||||
resp.setGrowth(this.calcGrowthFromYesterday(resp.getToday(), resp.getYesterday()));
|
||||
List<String> last12MonthList = this.getLast12Months();
|
||||
List<DashboardChartCommonResp> dataList = logMapper.selectListDashboardAnalysisPv(last12MonthList);
|
||||
if (dataList.size() < 12) {
|
||||
// 填充缺失的数据
|
||||
this.fillMissingDateData(last12MonthList, dataList);
|
||||
}
|
||||
resp.setDataList(dataList);
|
||||
return resp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardOverviewCommonResp getOverviewIp() {
|
||||
DashboardOverviewCommonResp resp = logMapper.selectDashboardOverviewIp();
|
||||
resp.setGrowth(this.calcGrowthFromYesterday(resp.getToday(), resp.getYesterday()));
|
||||
List<String> last12MonthList = this.getLast12Months();
|
||||
List<DashboardChartCommonResp> dataList = logMapper.selectListDashboardAnalysisIp(last12MonthList);
|
||||
if (dataList.size() < 12) {
|
||||
// 填充缺失的数据
|
||||
this.fillMissingDateData(last12MonthList, dataList);
|
||||
}
|
||||
resp.setDataList(dataList);
|
||||
return resp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardAccessTrendResp> listAccessTrend(Integer days) {
|
||||
DateTime currentDate = DateUtil.date();
|
||||
Date startTime = DateUtil.beginOfDay(DateUtil.offsetDay(currentDate, -days)).toJdkDate();
|
||||
Date endTime = DateUtil.endOfDay(DateUtil.offsetDay(currentDate, -1)).toJdkDate();
|
||||
List<DashboardAccessTrendResp> list = logMapper.selectListDashboardAccessTrend(startTime, endTime);
|
||||
if (list.size() < days) {
|
||||
List<String> all = DateUtil.rangeToList(startTime, endTime, DateField.DAY_OF_MONTH)
|
||||
.stream()
|
||||
.map(date -> date.toString(DatePattern.NORM_DATE_FORMAT))
|
||||
.toList();
|
||||
Collection<String> missings = CollUtil.disjunction(all, list.stream()
|
||||
.map(DashboardAccessTrendResp::getDate)
|
||||
.toList());
|
||||
list.addAll(missings.stream().map(missing -> new DashboardAccessTrendResp(missing, 0L, 0L)).toList());
|
||||
list.sort(Comparator.comparing(DashboardAccessTrendResp::getDate));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> getAnalysisTimeslot() {
|
||||
return logService.listDashboardAnalysisTimeslot();
|
||||
List<DashboardChartCommonResp> list = logMapper.selectListDashboardAnalysisTimeslot();
|
||||
if (list.size() < 12) {
|
||||
// 获取所有时间段
|
||||
List<String> allTimeSlotList = new ArrayList<>(12);
|
||||
for (int hour = 0; hour < 24; hour += 2) {
|
||||
allTimeSlotList.add(String.format("%02d:00", hour));
|
||||
}
|
||||
// 填充缺失的数据
|
||||
this.fillMissingDateData(allTimeSlotList, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> getAnalysisGeo() {
|
||||
return logService.listDashboardAnalysisGeo(10);
|
||||
List<DashboardChartCommonResp> list = logMapper.selectListDashboardAnalysisGeo(9);
|
||||
return this.buildOtherPieChartData(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> getAnalysisModule() {
|
||||
return logService.listDashboardAnalysisModule(5);
|
||||
return logMapper.selectListDashboardAnalysisModule(10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> getAnalysisOs() {
|
||||
return logService.listDashboardAnalysisOs(5);
|
||||
List<DashboardChartCommonResp> list = logMapper.selectListDashboardAnalysisOs(4);
|
||||
return this.buildOtherPieChartData(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> getAnalysisBrowser() {
|
||||
return logService.listDashboardAnalysisBrowser(5);
|
||||
List<DashboardChartCommonResp> list = logMapper.selectListDashboardAnalysisBrowser(4);
|
||||
return this.buildOtherPieChartData(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算增长百分比
|
||||
*
|
||||
* @param today 今日数量
|
||||
* @param yesterday 昨日数量
|
||||
* @return 增长百分比
|
||||
*/
|
||||
private BigDecimal calcGrowthFromYesterday(Long today, Long yesterday) {
|
||||
return (0 == yesterday)
|
||||
? BigDecimal.valueOf(100)
|
||||
: NumberUtil.round(NumberUtil.mul(NumberUtil.div(NumberUtil.sub(today, yesterday), yesterday), 100), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建其他饼图数据
|
||||
*
|
||||
* @param list 饼图数据列表
|
||||
* @return 饼图数据列表
|
||||
*/
|
||||
private List<DashboardChartCommonResp> buildOtherPieChartData(List<DashboardChartCommonResp> list) {
|
||||
Long totalCount = logMapper.selectTotalCount();
|
||||
long sumCount = list.stream().mapToLong(DashboardChartCommonResp::getValue).sum();
|
||||
if (sumCount < totalCount) {
|
||||
list.add(new DashboardChartCommonResp("其他", totalCount - sumCount));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充缺失时间段的数据
|
||||
*
|
||||
* @param all 所有时间段
|
||||
* @param list 待填充数据
|
||||
*/
|
||||
private void fillMissingDateData(List<String> all, List<DashboardChartCommonResp> list) {
|
||||
Collection<String> missings = CollUtil.disjunction(all, list.stream()
|
||||
.map(DashboardChartCommonResp::getName)
|
||||
.toList());
|
||||
list.addAll(missings.stream().map(missing -> new DashboardChartCommonResp(missing, 0L)).toList());
|
||||
list.sort(Comparator.comparing(DashboardChartCommonResp::getName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最近12个月的月份列表
|
||||
*
|
||||
* @return 月份列表
|
||||
*/
|
||||
private List<String> getLast12Months() {
|
||||
DateTime currentMonth = DateUtil.beginOfMonth(DateUtil.date());
|
||||
return DateUtil.rangeToList(DateUtil.offsetMonth(currentMonth, -12), DateUtil
|
||||
.offsetMonth(currentMonth, -1), DateField.MONTH)
|
||||
.stream()
|
||||
.map(dateTime -> DateUtil.format(dateTime, DatePattern.NORM_MONTH_FORMAT))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
@@ -33,9 +33,6 @@ import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.continew.admin.system.mapper.LogMapper;
|
||||
import top.continew.admin.system.model.entity.LogDO;
|
||||
import top.continew.admin.system.model.query.LogQuery;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardAccessTrendResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp;
|
||||
import top.continew.admin.system.model.resp.dashboard.DashboardTotalResp;
|
||||
import top.continew.admin.system.model.resp.log.LogDetailResp;
|
||||
import top.continew.admin.system.model.resp.log.LogResp;
|
||||
import top.continew.admin.system.model.resp.log.LoginLogExportResp;
|
||||
@@ -47,8 +44,6 @@ import top.continew.starter.extension.crud.model.query.SortQuery;
|
||||
import top.continew.starter.extension.crud.model.resp.PageResp;
|
||||
import top.continew.starter.file.excel.util.ExcelUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -95,75 +90,6 @@ public class LogServiceImpl implements LogService {
|
||||
ExcelUtils.export(list, "导出操作日志数据", OperationLogExportResp.class, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardTotalResp getDashboardTotal() {
|
||||
return baseMapper.selectDashboardTotal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardAccessTrendResp> listDashboardAccessTrend(Integer days) {
|
||||
return baseMapper.selectListDashboardAccessTrend(days);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> listDashboardAnalysisTimeslot() {
|
||||
List<DashboardChartCommonResp> list = baseMapper.selectListDashboardAnalysisTimeslot();
|
||||
if (list.size() < 12) {
|
||||
// 获取所有时间段
|
||||
List<String> allTimeSlots = new ArrayList<>();
|
||||
for (int hour = 0; hour < 24; hour += 2) {
|
||||
String timeSlot = String.format("%02d:00", hour);
|
||||
allTimeSlots.add(timeSlot);
|
||||
}
|
||||
// 补充缺失的时间段
|
||||
List<String> missingTimeSlots = allTimeSlots.stream()
|
||||
.filter(timeSlot -> list.stream().noneMatch(item -> item.getName().equals(timeSlot)))
|
||||
.toList();
|
||||
list.addAll(missingTimeSlots.stream().map(timeSlot -> new DashboardChartCommonResp(timeSlot, 0L)).toList());
|
||||
list.sort(Comparator.comparing(DashboardChartCommonResp::getName));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> listDashboardAnalysisGeo(int top) {
|
||||
List<DashboardChartCommonResp> list = baseMapper.selectListDashboardAnalysisGeo(top > 1 ? top - 1 : top);
|
||||
return this.buildOtherPieChartData(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> listDashboardAnalysisModule(int top) {
|
||||
List<DashboardChartCommonResp> list = baseMapper.selectListDashboardAnalysisModule(top > 1 ? top - 1 : top);
|
||||
return this.buildOtherPieChartData(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> listDashboardAnalysisOs(int top) {
|
||||
List<DashboardChartCommonResp> list = baseMapper.selectListDashboardAnalysisOs(top > 1 ? top - 1 : top);
|
||||
return this.buildOtherPieChartData(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardChartCommonResp> listDashboardAnalysisBrowser(int top) {
|
||||
List<DashboardChartCommonResp> list = baseMapper.selectListDashboardAnalysisBrowser(top > 1 ? top - 1 : top);
|
||||
return this.buildOtherPieChartData(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建其他饼图数据
|
||||
*
|
||||
* @param list 饼图数据列表
|
||||
* @return 饼图数据列表
|
||||
*/
|
||||
private List<DashboardChartCommonResp> buildOtherPieChartData(List<DashboardChartCommonResp> list) {
|
||||
Long totalCount = baseMapper.lambdaQuery().count();
|
||||
long sumCount = list.stream().mapToLong(DashboardChartCommonResp::getValue).sum();
|
||||
if (sumCount < totalCount) {
|
||||
list.add(new DashboardChartCommonResp("其他", totalCount - sumCount));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*
|
||||
|
@@ -41,12 +41,46 @@
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
<select id="selectDashboardTotal" resultType="top.continew.admin.system.model.resp.dashboard.DashboardTotalResp">
|
||||
<select id="selectDashboardOverviewPv" resultType="top.continew.admin.system.model.resp.dashboard.DashboardOverviewCommonResp">
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM sys_log) AS pvCount,
|
||||
(SELECT COUNT(DISTINCT ip) FROM sys_log) AS ipCount,
|
||||
(SELECT COUNT(*) FROM sys_log WHERE DATE(create_time) = CURRENT_DATE) AS todayPvCount,
|
||||
(SELECT COUNT(*) FROM sys_log WHERE DATE(create_time) = CURRENT_DATE - 1) AS yesterdayPvCount
|
||||
(SELECT COUNT(*) FROM sys_log) AS total,
|
||||
(SELECT COUNT(*) FROM sys_log WHERE DATE(create_time) = CURRENT_DATE) AS today,
|
||||
(SELECT COUNT(*) FROM sys_log WHERE DATE(create_time) = CURRENT_DATE - 1) AS yesterday
|
||||
</select>
|
||||
|
||||
<select id="selectDashboardOverviewIp" resultType="top.continew.admin.system.model.resp.dashboard.DashboardOverviewCommonResp">
|
||||
SELECT
|
||||
(SELECT COUNT(DISTINCT ip) FROM sys_log) AS total,
|
||||
(SELECT COUNT(DISTINCT ip) FROM sys_log WHERE DATE(create_time) = CURRENT_DATE) AS today,
|
||||
(SELECT COUNT(DISTINCT ip) FROM sys_log WHERE DATE(create_time) = CURRENT_DATE - 1) AS yesterday
|
||||
</select>
|
||||
|
||||
<select id="selectListDashboardAnalysisPv"
|
||||
resultType="top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp">
|
||||
SELECT
|
||||
DATE_FORMAT(create_time, '%Y-%m') AS name,
|
||||
COUNT(*) AS value
|
||||
FROM sys_log
|
||||
WHERE DATE_FORMAT(create_time, '%Y-%m' ) IN
|
||||
<foreach collection="months" item="month" separator="," open="(" close=")">
|
||||
#{month}
|
||||
</foreach>
|
||||
GROUP BY name
|
||||
ORDER BY name
|
||||
</select>
|
||||
|
||||
<select id="selectListDashboardAnalysisIp"
|
||||
resultType="top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp">
|
||||
SELECT
|
||||
DATE_FORMAT(create_time, '%Y-%m') AS name,
|
||||
COUNT(DISTINCT ip) AS value
|
||||
FROM sys_log
|
||||
WHERE DATE_FORMAT(create_time, '%Y-%m' ) IN
|
||||
<foreach collection="months" item="month" separator="," open="(" close=")">
|
||||
#{month}
|
||||
</foreach>
|
||||
GROUP BY name
|
||||
ORDER BY name
|
||||
</select>
|
||||
|
||||
<select id="selectListDashboardAccessTrend"
|
||||
@@ -56,10 +90,9 @@
|
||||
COUNT(*) AS pvCount,
|
||||
COUNT(DISTINCT ip) AS ipCount
|
||||
FROM sys_log
|
||||
WHERE DATE(create_time) != CURRENT_DATE
|
||||
GROUP BY DATE(create_time)
|
||||
ORDER BY DATE(create_time) DESC
|
||||
LIMIT #{days}
|
||||
WHERE create_time BETWEEN #{startTime} AND #{endTime}
|
||||
GROUP BY date
|
||||
ORDER BY date
|
||||
</select>
|
||||
|
||||
<select id="selectListDashboardAnalysisTimeslot"
|
||||
|
@@ -54,18 +54,24 @@ public class DashboardController {
|
||||
|
||||
private final DashboardService dashboardService;
|
||||
|
||||
@Operation(summary = "查询总计信息", description = "查询总计信息")
|
||||
@GetMapping("/total")
|
||||
public DashboardTotalResp getTotal() {
|
||||
return dashboardService.getTotal();
|
||||
}
|
||||
|
||||
@Operation(summary = "查询公告列表", description = "查询公告列表")
|
||||
@GetMapping("/notice")
|
||||
public List<DashboardNoticeResp> listNotice() {
|
||||
return dashboardService.listNotice();
|
||||
}
|
||||
|
||||
@Operation(summary = "查询PV总览", description = "查询PV总览")
|
||||
@GetMapping("/analysis/overview/pv")
|
||||
public DashboardOverviewCommonResp getOverviewPv() {
|
||||
return dashboardService.getOverviewPv();
|
||||
}
|
||||
|
||||
@Operation(summary = "查询IP总览", description = "查询IP总览")
|
||||
@GetMapping("/analysis/overview/ip")
|
||||
public DashboardOverviewCommonResp getOverviewIp() {
|
||||
return dashboardService.getOverviewIp();
|
||||
}
|
||||
|
||||
@Operation(summary = "查询访问趋势信息", description = "查询访问趋势信息")
|
||||
@Parameter(name = "days", description = "日期数", example = "30", in = ParameterIn.PATH)
|
||||
@GetMapping("/access/trend/{days}")
|
||||
|
Reference in New Issue
Block a user