mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-26 06:57:08 +08:00
feat: 完善仪表盘总计区块内容
This commit is contained in:
@@ -18,6 +18,7 @@ package top.charles7c.cnadmin.monitor.mapper;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseMapper;
|
||||
import top.charles7c.cnadmin.monitor.model.entity.LogDO;
|
||||
import top.charles7c.cnadmin.monitor.model.vo.DashboardTotalVO;
|
||||
|
||||
/**
|
||||
* 系统日志 Mapper
|
||||
@@ -25,4 +26,12 @@ import top.charles7c.cnadmin.monitor.model.entity.LogDO;
|
||||
* @author Charles7c
|
||||
* @since 2022/12/22 21:47
|
||||
*/
|
||||
public interface LogMapper extends BaseMapper<LogDO> {}
|
||||
public interface LogMapper extends BaseMapper<LogDO> {
|
||||
|
||||
/**
|
||||
* 查询仪表盘总计信息
|
||||
*
|
||||
* @return 总计信息
|
||||
*/
|
||||
DashboardTotalVO selectDashboardTotal();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.charles7c.cnadmin.monitor.model.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
/**
|
||||
* 仪表盘总计信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/9/8 21:32
|
||||
*/
|
||||
@Data
|
||||
public class DashboardTotalVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 浏览量(PV)
|
||||
*/
|
||||
@Schema(description = "浏览量(PV)", example = "88888")
|
||||
private Long pvCount;
|
||||
|
||||
/**
|
||||
* IP 数
|
||||
*/
|
||||
@Schema(description = "IP 数", example = "66666")
|
||||
private Long ipCount;
|
||||
|
||||
/**
|
||||
* 今日浏览量(PV)
|
||||
*/
|
||||
@Schema(description = "今日浏览量", example = "1234")
|
||||
private Long todayPvCount;
|
||||
|
||||
/**
|
||||
* 较昨日新增 PV(百分比)
|
||||
*/
|
||||
@Schema(description = "较昨日新增(百分比)", example = "23.4")
|
||||
private BigDecimal newPvFromYesterday;
|
||||
|
||||
/**
|
||||
* 昨日浏览量(PV)
|
||||
*/
|
||||
@JsonIgnore
|
||||
private Long yesterdayPvCount;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.charles7c.cnadmin.monitor.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import top.charles7c.cnadmin.monitor.model.vo.DashboardTotalVO;
|
||||
import top.charles7c.cnadmin.system.model.vo.DashboardAnnouncementVO;
|
||||
|
||||
/**
|
||||
* 仪表盘业务接口
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/9/8 21:32
|
||||
*/
|
||||
public interface DashboardService {
|
||||
|
||||
/**
|
||||
* 查询总计信息
|
||||
*
|
||||
* @return 总计信息
|
||||
*/
|
||||
DashboardTotalVO getTotal();
|
||||
|
||||
/**
|
||||
* 查询公告列表
|
||||
*
|
||||
* @return 公告列表
|
||||
*/
|
||||
List<DashboardAnnouncementVO> listAnnouncement();
|
||||
}
|
||||
@@ -21,10 +21,7 @@ import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
||||
import top.charles7c.cnadmin.monitor.model.query.LoginLogQuery;
|
||||
import top.charles7c.cnadmin.monitor.model.query.OperationLogQuery;
|
||||
import top.charles7c.cnadmin.monitor.model.query.SystemLogQuery;
|
||||
import top.charles7c.cnadmin.monitor.model.vo.LoginLogVO;
|
||||
import top.charles7c.cnadmin.monitor.model.vo.OperationLogVO;
|
||||
import top.charles7c.cnadmin.monitor.model.vo.SystemLogDetailVO;
|
||||
import top.charles7c.cnadmin.monitor.model.vo.SystemLogVO;
|
||||
import top.charles7c.cnadmin.monitor.model.vo.*;
|
||||
|
||||
/**
|
||||
* 系统日志业务接口
|
||||
@@ -75,4 +72,11 @@ public interface LogService {
|
||||
* @return 系统日志详情
|
||||
*/
|
||||
SystemLogDetailVO get(Long logId);
|
||||
|
||||
/**
|
||||
* 查询仪表盘总计信息
|
||||
*
|
||||
* @return 仪表盘总计信息
|
||||
*/
|
||||
DashboardTotalVO getDashboardTotal();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.charles7c.cnadmin.monitor.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
|
||||
import top.charles7c.cnadmin.monitor.model.vo.DashboardTotalVO;
|
||||
import top.charles7c.cnadmin.monitor.service.DashboardService;
|
||||
import top.charles7c.cnadmin.monitor.service.LogService;
|
||||
import top.charles7c.cnadmin.system.model.vo.DashboardAnnouncementVO;
|
||||
import top.charles7c.cnadmin.system.service.AnnouncementService;
|
||||
|
||||
/**
|
||||
* 仪表盘业务实现
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/9/8 21:32
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DashboardServiceImpl implements DashboardService {
|
||||
|
||||
private final LogService logService;
|
||||
private final AnnouncementService announcementService;
|
||||
|
||||
@Override
|
||||
public DashboardTotalVO getTotal() {
|
||||
DashboardTotalVO totalVO = logService.getDashboardTotal();
|
||||
Long todayPvCount = totalVO.getTodayPvCount();
|
||||
Long yesterdayPvCount = totalVO.getYesterdayPvCount();
|
||||
BigDecimal newPvCountFromYesterday = NumberUtil.sub(todayPvCount, yesterdayPvCount);
|
||||
BigDecimal newPvFromYesterday = (0 == yesterdayPvCount) ? BigDecimal.valueOf(100)
|
||||
: NumberUtil.round(NumberUtil.mul(NumberUtil.div(newPvCountFromYesterday, yesterdayPvCount), 100), 1);
|
||||
totalVO.setNewPvFromYesterday(newPvFromYesterday);
|
||||
return totalVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardAnnouncementVO> listAnnouncement() {
|
||||
return announcementService.listDashboard();
|
||||
}
|
||||
}
|
||||
@@ -145,6 +145,11 @@ public class LogServiceImpl implements LogService {
|
||||
return detailVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardTotalVO getDashboardTotal() {
|
||||
return logMapper.selectDashboardTotal();
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
*
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="top.charles7c.cnadmin.monitor.mapper.LogMapper">
|
||||
<select id="selectDashboardTotal" resultType="top.charles7c.cnadmin.monitor.model.vo.DashboardTotalVO">
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM `sys_log`) AS pvCount,
|
||||
(SELECT COUNT(DISTINCT `client_ip`) FROM `sys_log`) AS ipCount,
|
||||
(SELECT COUNT(*) FROM `sys_log` WHERE DATE(`create_time`) = CURDATE()) AS todayPvCount,
|
||||
(SELECT COUNT(*) FROM `sys_log` WHERE DATE(`create_time`) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)) AS yesterdayPvCount
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user