feat: 新增仪表盘分析接口,查询访问时段分析、查询模块分析、查询终端分析、查询浏览器分析

This commit is contained in:
2024-10-18 00:19:29 +08:00
parent ffdc9712d4
commit dea8dbe131
16 changed files with 304 additions and 192 deletions

View File

@@ -21,14 +21,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import top.continew.admin.system.model.entity.LogDO; import top.continew.admin.system.model.entity.LogDO;
import top.continew.admin.system.model.resp.DashboardAccessTrendResp; import top.continew.admin.system.model.resp.dashboard.DashboardAccessTrendResp;
import top.continew.admin.system.model.resp.DashboardPopularModuleResp; import top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp;
import top.continew.admin.system.model.resp.DashboardTotalResp; import top.continew.admin.system.model.resp.dashboard.DashboardTotalResp;
import top.continew.admin.system.model.resp.log.LogResp; import top.continew.admin.system.model.resp.log.LogResp;
import top.continew.starter.data.mp.base.BaseMapper; import top.continew.starter.data.mp.base.BaseMapper;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 系统日志 Mapper * 系统日志 Mapper
@@ -72,16 +71,41 @@ public interface LogMapper extends BaseMapper<LogDO> {
List<DashboardAccessTrendResp> selectListDashboardAccessTrend(@Param("days") Integer days); List<DashboardAccessTrendResp> selectListDashboardAccessTrend(@Param("days") Integer days);
/** /**
* 查询仪表盘热门模块列表 * 查询仪表盘访问时段分析信息
* *
* @return 仪表盘热门模块列表 * @return 仪表盘访问时段分析信息
*/ */
List<DashboardPopularModuleResp> selectListDashboardPopularModule(); List<DashboardChartCommonResp> selectListDashboardAnalysisTimeslot();
/** /**
* 查询仪表盘访客地域分信息 * 查询仪表盘地域分信息
* *
* @return 仪表盘访客地域分布信息 * @param top 显示数量
* @return 仪表盘地域分析信息
*/ */
List<Map<String, Object>> selectListDashboardGeoDistribution(); List<DashboardChartCommonResp> selectListDashboardAnalysisGeo(@Param("top") Integer top);
/**
* 查询仪表盘模块分析信息
*
* @param top 显示数量
* @return 仪表盘模块分析信息
*/
List<DashboardChartCommonResp> selectListDashboardAnalysisModule(@Param("top") Integer top);
/**
* 查询仪表盘终端分析信息
*
* @param top 显示数量
* @return 仪表盘终端分析信息
*/
List<DashboardChartCommonResp> selectListDashboardAnalysisOs(@Param("top") Integer top);
/**
* 查询仪表盘浏览器分析信息
*
* @param top 显示数量
* @return 仪表盘浏览器分析信息
*/
List<DashboardChartCommonResp> selectListDashboardAnalysisBrowser(@Param("top") Integer top);
} }

View File

@@ -17,7 +17,7 @@
package top.continew.admin.system.mapper; package top.continew.admin.system.mapper;
import top.continew.admin.system.model.entity.NoticeDO; import top.continew.admin.system.model.entity.NoticeDO;
import top.continew.admin.system.model.resp.DashboardNoticeResp; import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp;
import top.continew.starter.data.mp.base.BaseMapper; import top.continew.starter.data.mp.base.BaseMapper;
import java.util.List; import java.util.List;

View File

@@ -1,69 +0,0 @@
/*
* 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;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 仪表盘-热门模块信息
*
* @author Charles7c
* @since 2023/9/9 9:52
*/
@Data
@Schema(description = "仪表盘-热门模块信息")
public class DashboardPopularModuleResp implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 模块
*/
@Schema(description = "模块", example = "角色管理")
private String module;
/**
* 浏览量PV
*/
@Schema(description = "浏览量PV", example = "1234")
private Long pvCount;
/**
* 较昨日新增 PV百分比
*/
@Schema(description = "较昨日新增(百分比)", example = "23.4")
private BigDecimal newPvFromYesterday;
/**
* 今日浏览量PV
*/
@JsonIgnore
private Long todayPvCount;
/**
* 昨日浏览量PV
*/
@JsonIgnore
private Long yesterdayPvCount;
}

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package top.continew.admin.system.model.resp; package top.continew.admin.system.model.resp.dashboard;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;

View File

@@ -14,38 +14,40 @@
* limitations under the License. * limitations under the License.
*/ */
package top.continew.admin.system.model.resp; package top.continew.admin.system.model.resp.dashboard;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
import java.util.Map;
/** /**
* 仪表盘-访客地域分布信息 * 仪表盘-通用图表信息
* *
* @author Charles7c * @author Charles7c
* @since 2023/9/9 12:07 * @since 2024/10/17 21:37
*/ */
@Data @Data
@Schema(description = "仪表盘-访客地域分布信息") @NoArgsConstructor
public class DashboardGeoDistributionResp implements Serializable { @AllArgsConstructor
@Schema(description = "仪表盘-通用图表信息")
public class DashboardChartCommonResp implements Serializable {
@Serial @Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* 地点列表 * 名称
*/ */
@Schema(description = "地点列表", example = "[\"中国北京北京市\",\"中国广东省深圳市\"]") @Schema(description = "名称", example = "Windows 10")
private List<String> locations; private String name;
/** /**
* 地点 IP 统计信息 * 数量
*/ */
@Schema(description = "地点 IP 统计信息", example = "[{\"name\":\"中国北京北京市\",\"value\":1000},{\"name\":\"中国广东省深圳市\",\"value\": 500}]") @Schema(description = "数量", example = "1234")
private List<Map<String, Object>> locationIpStatistics; private Long value;
} }

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package top.continew.admin.system.model.resp; package top.continew.admin.system.model.resp.dashboard;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package top.continew.admin.system.model.resp; package top.continew.admin.system.model.resp.dashboard;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;

View File

@@ -16,7 +16,7 @@
package top.continew.admin.system.service; package top.continew.admin.system.service;
import top.continew.admin.system.model.resp.*; import top.continew.admin.system.model.resp.dashboard.*;
import java.util.List; import java.util.List;
@@ -43,24 +43,45 @@ public interface DashboardService {
*/ */
List<DashboardAccessTrendResp> listAccessTrend(Integer days); List<DashboardAccessTrendResp> listAccessTrend(Integer days);
/**
* 查询热门模块列表
*
* @return 热门模块列表
*/
List<DashboardPopularModuleResp> listPopularModule();
/**
* 查询访客地域分布信息
*
* @return 访客地域分布信息
*/
DashboardGeoDistributionResp getGeoDistribution();
/** /**
* 查询公告列表 * 查询公告列表
* *
* @return 公告列表 * @return 公告列表
*/ */
List<DashboardNoticeResp> listNotice(); List<DashboardNoticeResp> listNotice();
/**
* 查询访问时段分析信息
*
* @return 访问时段分析信息
*/
List<DashboardChartCommonResp> getAnalysisTimeslot();
/**
* 查询地域分析信息
*
* @return 地域分析信息
*/
List<DashboardChartCommonResp> getAnalysisGeo();
/**
* 查询模块分析信息
*
* @return 模块分析信息
*/
List<DashboardChartCommonResp> getAnalysisModule();
/**
* 查询终端分析信息
*
* @return 终端分析信息
*/
List<DashboardChartCommonResp> getAnalysisOs();
/**
* 查询浏览器分析信息
*
* @return 浏览器分析信息
*/
List<DashboardChartCommonResp> getAnalysisBrowser();
} }

View File

@@ -18,9 +18,9 @@ package top.continew.admin.system.service;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import top.continew.admin.system.model.query.LogQuery; import top.continew.admin.system.model.query.LogQuery;
import top.continew.admin.system.model.resp.DashboardAccessTrendResp; import top.continew.admin.system.model.resp.dashboard.DashboardAccessTrendResp;
import top.continew.admin.system.model.resp.DashboardPopularModuleResp; import top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp;
import top.continew.admin.system.model.resp.DashboardTotalResp; 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.LogDetailResp;
import top.continew.admin.system.model.resp.log.LogResp; 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.PageQuery;
@@ -28,7 +28,6 @@ import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.PageResp; import top.continew.starter.extension.crud.model.resp.PageResp;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 系统日志业务接口 * 系统日志业务接口
@@ -89,16 +88,41 @@ public interface LogService {
List<DashboardAccessTrendResp> listDashboardAccessTrend(Integer days); List<DashboardAccessTrendResp> listDashboardAccessTrend(Integer days);
/** /**
* 查询仪表盘热门模块列表 * 查询仪表盘访问时段分析信息
* *
* @return 仪表盘热门模块列表 * @return 仪表盘访问时段分析信息
*/ */
List<DashboardPopularModuleResp> listDashboardPopularModule(); List<DashboardChartCommonResp> listDashboardAnalysisTimeslot();
/** /**
* 查询仪表盘访客地域分信息 * 查询仪表盘地域分信息
* *
* @return 仪表盘访客地域分布信息 * @param top 显示数量
* @return 仪表盘地域分析信息
*/ */
List<Map<String, Object>> listDashboardGeoDistribution(); 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);
} }

View File

@@ -21,7 +21,7 @@ import top.continew.admin.system.model.query.NoticeQuery;
import top.continew.admin.system.model.req.NoticeReq; import top.continew.admin.system.model.req.NoticeReq;
import top.continew.admin.system.model.resp.NoticeDetailResp; import top.continew.admin.system.model.resp.NoticeDetailResp;
import top.continew.admin.system.model.resp.NoticeResp; import top.continew.admin.system.model.resp.NoticeResp;
import top.continew.admin.system.model.resp.DashboardNoticeResp; import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp;
import top.continew.starter.extension.crud.service.BaseService; import top.continew.starter.extension.crud.service.BaseService;
import top.continew.starter.data.mp.service.IService; import top.continew.starter.data.mp.service.IService;

View File

@@ -16,18 +16,16 @@
package top.continew.admin.system.service.impl; package top.continew.admin.system.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.NumberUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import top.continew.admin.system.service.NoticeService; import top.continew.admin.system.model.resp.dashboard.*;
import top.continew.admin.system.service.DashboardService; import top.continew.admin.system.service.DashboardService;
import top.continew.admin.system.service.LogService; import top.continew.admin.system.service.LogService;
import top.continew.admin.system.model.resp.*; import top.continew.admin.system.service.NoticeService;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 仪表盘业务实现 * 仪表盘业务实现
@@ -60,32 +58,33 @@ public class DashboardServiceImpl implements DashboardService {
return logService.listDashboardAccessTrend(days); return logService.listDashboardAccessTrend(days);
} }
@Override
public List<DashboardPopularModuleResp> listPopularModule() {
List<DashboardPopularModuleResp> popularModuleList = logService.listDashboardPopularModule();
for (DashboardPopularModuleResp popularModule : popularModuleList) {
Long todayPvCount = popularModule.getTodayPvCount();
Long yesterdayPvCount = popularModule.getYesterdayPvCount();
BigDecimal newPvCountFromYesterday = NumberUtil.sub(todayPvCount, yesterdayPvCount);
BigDecimal newPvFromYesterday = (0 == yesterdayPvCount)
? BigDecimal.valueOf(100)
: NumberUtil.round(NumberUtil.mul(NumberUtil.div(newPvCountFromYesterday, yesterdayPvCount), 100), 1);
popularModule.setNewPvFromYesterday(newPvFromYesterday);
}
return popularModuleList;
}
@Override
public DashboardGeoDistributionResp getGeoDistribution() {
List<Map<String, Object>> locationIpStatistics = logService.listDashboardGeoDistribution();
DashboardGeoDistributionResp geoDistribution = new DashboardGeoDistributionResp();
geoDistribution.setLocationIpStatistics(locationIpStatistics);
geoDistribution.setLocations(locationIpStatistics.stream().map(m -> Convert.toStr(m.get("name"))).toList());
return geoDistribution;
}
@Override @Override
public List<DashboardNoticeResp> listNotice() { public List<DashboardNoticeResp> listNotice() {
return noticeService.listDashboard(); return noticeService.listDashboard();
} }
@Override
public List<DashboardChartCommonResp> getAnalysisTimeslot() {
return logService.listDashboardAnalysisTimeslot();
}
@Override
public List<DashboardChartCommonResp> getAnalysisGeo() {
return logService.listDashboardAnalysisGeo(10);
}
@Override
public List<DashboardChartCommonResp> getAnalysisModule() {
return logService.listDashboardAnalysisModule(5);
}
@Override
public List<DashboardChartCommonResp> getAnalysisOs() {
return logService.listDashboardAnalysisOs(5);
}
@Override
public List<DashboardChartCommonResp> getAnalysisBrowser() {
return logService.listDashboardAnalysisBrowser(5);
}
} }

View File

@@ -33,9 +33,9 @@ import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.admin.system.mapper.LogMapper; import top.continew.admin.system.mapper.LogMapper;
import top.continew.admin.system.model.entity.LogDO; import top.continew.admin.system.model.entity.LogDO;
import top.continew.admin.system.model.query.LogQuery; import top.continew.admin.system.model.query.LogQuery;
import top.continew.admin.system.model.resp.DashboardAccessTrendResp; import top.continew.admin.system.model.resp.dashboard.DashboardAccessTrendResp;
import top.continew.admin.system.model.resp.DashboardPopularModuleResp; import top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp;
import top.continew.admin.system.model.resp.DashboardTotalResp; 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.LogDetailResp;
import top.continew.admin.system.model.resp.log.LogResp; import top.continew.admin.system.model.resp.log.LogResp;
import top.continew.admin.system.model.resp.log.LoginLogExportResp; import top.continew.admin.system.model.resp.log.LoginLogExportResp;
@@ -47,9 +47,10 @@ import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.PageResp; import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.file.excel.util.ExcelUtils; import top.continew.starter.file.excel.util.ExcelUtils;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 系统日志业务实现 * 系统日志业务实现
@@ -105,13 +106,62 @@ public class LogServiceImpl implements LogService {
} }
@Override @Override
public List<DashboardPopularModuleResp> listDashboardPopularModule() { public List<DashboardChartCommonResp> listDashboardAnalysisTimeslot() {
return baseMapper.selectListDashboardPopularModule(); 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 @Override
public List<Map<String, Object>> listDashboardGeoDistribution() { public List<DashboardChartCommonResp> listDashboardAnalysisGeo(int top) {
return baseMapper.selectListDashboardGeoDistribution(); 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;
} }
/** /**

View File

@@ -22,7 +22,7 @@ import top.continew.admin.system.mapper.NoticeMapper;
import top.continew.admin.system.model.entity.NoticeDO; import top.continew.admin.system.model.entity.NoticeDO;
import top.continew.admin.system.model.query.NoticeQuery; import top.continew.admin.system.model.query.NoticeQuery;
import top.continew.admin.system.model.req.NoticeReq; import top.continew.admin.system.model.req.NoticeReq;
import top.continew.admin.system.model.resp.DashboardNoticeResp; import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp;
import top.continew.admin.system.model.resp.NoticeDetailResp; import top.continew.admin.system.model.resp.NoticeDetailResp;
import top.continew.admin.system.model.resp.NoticeResp; import top.continew.admin.system.model.resp.NoticeResp;
import top.continew.admin.system.service.NoticeService; import top.continew.admin.system.service.NoticeService;

View File

@@ -41,7 +41,7 @@
${ew.customSqlSegment} ${ew.customSqlSegment}
</select> </select>
<select id="selectDashboardTotal" resultType="top.continew.admin.system.model.resp.DashboardTotalResp"> <select id="selectDashboardTotal" resultType="top.continew.admin.system.model.resp.dashboard.DashboardTotalResp">
SELECT SELECT
(SELECT COUNT(*) FROM sys_log) AS pvCount, (SELECT COUNT(*) FROM sys_log) AS pvCount,
(SELECT COUNT(DISTINCT ip) FROM sys_log) AS ipCount, (SELECT COUNT(DISTINCT ip) FROM sys_log) AS ipCount,
@@ -50,7 +50,7 @@
</select> </select>
<select id="selectListDashboardAccessTrend" <select id="selectListDashboardAccessTrend"
resultType="top.continew.admin.system.model.resp.DashboardAccessTrendResp"> resultType="top.continew.admin.system.model.resp.dashboard.DashboardAccessTrendResp">
SELECT SELECT
DATE(create_time) AS date, DATE(create_time) AS date,
COUNT(*) AS pvCount, COUNT(*) AS pvCount,
@@ -62,21 +62,17 @@
LIMIT #{days} LIMIT #{days}
</select> </select>
<select id="selectListDashboardPopularModule" <select id="selectListDashboardAnalysisTimeslot"
resultType="top.continew.admin.system.model.resp.DashboardPopularModuleResp"> resultType="top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp">
SELECT SELECT
module, LPAD(CONCAT(FLOOR(HOUR(create_time) / 2) * 2, ':00'), 5, '0') AS name,
COUNT(*) AS pvCount, COUNT(*) AS value
SUM(CASE WHEN DATE(create_time) = CURRENT_DATE THEN 1 ELSE 0 END) AS todayPvCount,
SUM(CASE WHEN DATE(create_time) = CURRENT_DATE - 1 THEN 1 ELSE 0 END) AS yesterdayPvCount
FROM sys_log FROM sys_log
WHERE module != '验证码' AND module != '登录' GROUP BY name
GROUP BY module ORDER BY name
ORDER BY pvCount DESC
LIMIT 10
</select> </select>
<select id="selectListDashboardGeoDistribution" resultType="java.util.Map"> <select id="selectListDashboardAnalysisGeo" resultType="top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp">
SELECT SELECT
CASE CASE
WHEN POSITION(' ' IN address) > 0 THEN SUBSTRING(address FROM 1 FOR POSITION(' ' IN address) - 1) WHEN POSITION(' ' IN address) > 0 THEN SUBSTRING(address FROM 1 FOR POSITION(' ' IN address) - 1)
@@ -86,6 +82,42 @@
FROM sys_log FROM sys_log
GROUP BY name GROUP BY name
ORDER BY value DESC ORDER BY value DESC
LIMIT 10 LIMIT #{top}
</select>
<select id="selectListDashboardAnalysisModule"
resultType="top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp">
SELECT
module AS name,
COUNT(*) AS value
FROM sys_log
WHERE module != '验证码' AND module != '登录'
GROUP BY name
ORDER BY value DESC
LIMIT #{top}
</select>
<select id="selectListDashboardAnalysisOs"
resultType="top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp">
SELECT
os AS name,
COUNT(*) AS value
FROM sys_log
WHERE os IS NOT NULL
GROUP BY name
ORDER BY value DESC
LIMIT #{top}
</select>
<select id="selectListDashboardAnalysisBrowser"
resultType="top.continew.admin.system.model.resp.dashboard.DashboardChartCommonResp">
SELECT
SUBSTRING_INDEX(browser, ' ', 1) AS name,
COUNT(*) AS value
FROM sys_log
WHERE browser IS NOT NULL
GROUP BY name
ORDER BY value DESC
LIMIT #{top}
</select> </select>
</mapper> </mapper>

View File

@@ -3,7 +3,7 @@
<mapper namespace="top.continew.admin.system.mapper.NoticeMapper"> <mapper namespace="top.continew.admin.system.mapper.NoticeMapper">
<select id="selectDashboardList" <select id="selectDashboardList"
resultType="top.continew.admin.system.model.resp.DashboardNoticeResp"> resultType="top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp">
SELECT SELECT
id, title, type id, title, type
FROM sys_notice FROM sys_notice

View File

@@ -31,12 +31,8 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import top.continew.admin.common.constant.CacheConstants; import top.continew.admin.common.constant.CacheConstants;
import top.continew.admin.system.model.resp.DashboardAccessTrendResp; import top.continew.admin.system.model.resp.dashboard.*;
import top.continew.admin.system.model.resp.DashboardGeoDistributionResp;
import top.continew.admin.system.model.resp.DashboardPopularModuleResp;
import top.continew.admin.system.model.resp.DashboardTotalResp;
import top.continew.admin.system.service.DashboardService; import top.continew.admin.system.service.DashboardService;
import top.continew.admin.system.model.resp.DashboardNoticeResp;
import top.continew.starter.core.util.validate.ValidationUtils; import top.continew.starter.core.util.validate.ValidationUtils;
import top.continew.starter.log.core.annotation.Log; import top.continew.starter.log.core.annotation.Log;
@@ -64,6 +60,12 @@ public class DashboardController {
return dashboardService.getTotal(); return dashboardService.getTotal();
} }
@Operation(summary = "查询公告列表", description = "查询公告列表")
@GetMapping("/notice")
public List<DashboardNoticeResp> listNotice() {
return dashboardService.listNotice();
}
@Operation(summary = "查询访问趋势信息", description = "查询访问趋势信息") @Operation(summary = "查询访问趋势信息", description = "查询访问趋势信息")
@Parameter(name = "days", description = "日期数", example = "30", in = ParameterIn.PATH) @Parameter(name = "days", description = "日期数", example = "30", in = ParameterIn.PATH)
@GetMapping("/access/trend/{days}") @GetMapping("/access/trend/{days}")
@@ -75,21 +77,48 @@ public class DashboardController {
return dashboardService.listAccessTrend(days); return dashboardService.listAccessTrend(days);
} }
@Operation(summary = "查询热门模块列表", description = "查询热门模块列表") @Operation(summary = "查询访问时段分析", description = "查询访问时段分析")
@GetMapping("/popular/module") @GetMapping("/analysis/timeslot")
public List<DashboardPopularModuleResp> listPopularModule() { @CachePenetrationProtect
return dashboardService.listPopularModule(); @CacheRefresh(refresh = 7200)
@Cached(key = "'TIMESLOT'", name = CacheConstants.DASHBOARD_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true)
public List<DashboardChartCommonResp> getAnalysisTimeslot() {
return dashboardService.getAnalysisTimeslot();
} }
@Operation(summary = "查询访客地域分布信息", description = "查询访客地域分布信息") @Operation(summary = "查询地域分", description = "查询地域分")
@GetMapping("/geo/distribution") @GetMapping("/analysis/geo")
public DashboardGeoDistributionResp getGeoDistribution() { @CachePenetrationProtect
return dashboardService.getGeoDistribution(); @CacheRefresh(refresh = 7200)
@Cached(key = "'GEO'", name = CacheConstants.DASHBOARD_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true)
public List<DashboardChartCommonResp> getAnalysisGeo() {
return dashboardService.getAnalysisGeo();
} }
@Operation(summary = "查询公告列表", description = "查询公告列表") @Operation(summary = "查询模块分析", description = "查询模块分析")
@GetMapping("/notice") @GetMapping("/analysis/module")
public List<DashboardNoticeResp> listNotice() { @CachePenetrationProtect
return dashboardService.listNotice(); @CacheRefresh(refresh = 7200)
@Cached(key = "'MODULE'", name = CacheConstants.DASHBOARD_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true)
public List<DashboardChartCommonResp> getAnalysisModule() {
return dashboardService.getAnalysisModule();
}
@Operation(summary = "查询终端分析", description = "查询终端分析")
@GetMapping("/analysis/os")
@CachePenetrationProtect
@CacheRefresh(refresh = 7200)
@Cached(key = "'OS'", name = CacheConstants.DASHBOARD_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true)
public List<DashboardChartCommonResp> getAnalysisOs() {
return dashboardService.getAnalysisOs();
}
@Operation(summary = "查询浏览器分析", description = "查询浏览器分析")
@GetMapping("/analysis/browser")
@CachePenetrationProtect
@CacheRefresh(refresh = 7200)
@Cached(key = "'BROWSER'", name = CacheConstants.DASHBOARD_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true)
public List<DashboardChartCommonResp> getAnalysisBrowser() {
return dashboardService.getAnalysisBrowser();
} }
} }