Skip to content

Commit

Permalink
feat: 完善仪表盘总计区块内容
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Sep 8, 2023
1 parent 0ec5647 commit 3440aa4
Show file tree
Hide file tree
Showing 26 changed files with 320 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@

import top.charles7c.cnadmin.common.base.BaseMapper;
import top.charles7c.cnadmin.monitor.model.entity.LogDO;
import top.charles7c.cnadmin.monitor.model.vo.DashboardTotalVO;

/**
* 系统日志 Mapper
*
* @author Charles7c
* @since 2022/12/22 21:47
*/
public interface LogMapper extends BaseMapper<LogDO> {}
public interface LogMapper extends BaseMapper<LogDO> {

/**
* 查询仪表盘总计信息
*
* @return 总计信息
*/
DashboardTotalVO selectDashboardTotal();
}
Original file line number Diff line number Diff line change
@@ -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:https://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;
}
Original file line number Diff line number Diff line change
@@ -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:https://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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
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.*;

/**
* 系统日志业务接口
Expand Down Expand Up @@ -75,4 +72,11 @@ public interface LogService {
* @return 系统日志详情
*/
SystemLogDetailVO get(Long logId);

/**
* 查询仪表盘总计信息
*
* @return 仪表盘总计信息
*/
DashboardTotalVO getDashboardTotal();
}
Original file line number Diff line number Diff line change
@@ -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:https://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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ public SystemLogDetailVO get(Long id) {
return detailVO;
}

@Override
public DashboardTotalVO getDashboardTotal() {
return logMapper.selectDashboardTotal();
}

/**
* 填充数据
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http:https://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>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import top.charles7c.cnadmin.common.base.BaseMapper;
import top.charles7c.cnadmin.system.model.entity.AnnouncementDO;
import top.charles7c.cnadmin.system.model.vo.AnnouncementDashboardVO;
import top.charles7c.cnadmin.system.model.vo.DashboardAnnouncementVO;

/**
* 公告 Mapper
Expand All @@ -35,5 +35,5 @@ public interface AnnouncementMapper extends BaseMapper<AnnouncementDO> {
*
* @return 公告列表
*/
List<AnnouncementDashboardVO> selectDashboardList();
List<DashboardAnnouncementVO> selectDashboardList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
@Data
@Schema(description = "仪表盘公告信息")
public class AnnouncementDashboardVO implements Serializable {
public class DashboardAnnouncementVO implements Serializable {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import top.charles7c.cnadmin.common.base.BaseService;
import top.charles7c.cnadmin.system.model.query.AnnouncementQuery;
import top.charles7c.cnadmin.system.model.request.AnnouncementRequest;
import top.charles7c.cnadmin.system.model.vo.AnnouncementDashboardVO;
import top.charles7c.cnadmin.system.model.vo.AnnouncementDetailVO;
import top.charles7c.cnadmin.system.model.vo.AnnouncementVO;
import top.charles7c.cnadmin.system.model.vo.DashboardAnnouncementVO;

/**
* 公告业务接口
Expand All @@ -39,5 +39,5 @@ public interface AnnouncementService
*
* @return 公告列表
*/
List<AnnouncementDashboardVO> listDashboard();
List<DashboardAnnouncementVO> listDashboard();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import top.charles7c.cnadmin.system.model.entity.AnnouncementDO;
import top.charles7c.cnadmin.system.model.query.AnnouncementQuery;
import top.charles7c.cnadmin.system.model.request.AnnouncementRequest;
import top.charles7c.cnadmin.system.model.vo.AnnouncementDashboardVO;
import top.charles7c.cnadmin.system.model.vo.AnnouncementDetailVO;
import top.charles7c.cnadmin.system.model.vo.AnnouncementVO;
import top.charles7c.cnadmin.system.model.vo.DashboardAnnouncementVO;
import top.charles7c.cnadmin.system.service.AnnouncementService;

/**
Expand All @@ -44,7 +44,7 @@ public class AnnouncementServiceImpl extends BaseServiceImpl<AnnouncementMapper,
AnnouncementDetailVO, AnnouncementQuery, AnnouncementRequest> implements AnnouncementService {

@Override
public List<AnnouncementDashboardVO> listDashboard() {
public List<DashboardAnnouncementVO> listDashboard() {
return baseMapper.selectDashboardList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<mapper namespace="top.charles7c.cnadmin.system.mapper.AnnouncementMapper">

<select id="selectDashboardList"
resultType="top.charles7c.cnadmin.system.model.vo.AnnouncementDashboardVO">
resultType="top.charles7c.cnadmin.system.model.vo.DashboardAnnouncementVO">
SELECT
`id`, `title`, `type`
FROM `sys_announcement`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@ import type { TableData } from '@arco-design/web-vue/es/table/interface';

const BASE_URL = '/dashboard';

export interface AnnouncementDashboardRecord {
export interface DashboardTotalRecord {
pvCount: number;
ipCount: number;
todayPvCount: number;
newPvFromYesterday: number;
}

export interface DashboardAnnouncementRecord {
id: string;
title: string;
type: number;
}

export function getTotal() {
return axios.get<DashboardTotalRecord>(`${BASE_URL}/total`);
}

export function listAnnouncement() {
return axios.get<AnnouncementDashboardRecord[]>(`${BASE_URL}/announcement`);
return axios.get<DashboardAnnouncementRecord[]>(`${BASE_URL}/announcement`);
}

export interface ContentDataRecord {
Expand Down
1 change: 1 addition & 0 deletions continew-admin-ui/src/assets/icons/svg/data.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions continew-admin-ui/src/assets/icons/svg/hot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions continew-admin-ui/src/assets/icons/svg/popularity.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions continew-admin-ui/src/assets/icons/svg/same-city.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@
<script lang="ts" setup>
import { ref } from 'vue';
import {
AnnouncementDashboardRecord,
DashboardAnnouncementRecord,
listAnnouncement,
} from '@/api/dashboard';
} from '@/api/common/dashboard';
import { DataRecord, get } from '@/api/system/announcement';
const dataList = ref<AnnouncementDashboardRecord[]>([]);
const dataList = ref<DashboardAnnouncementRecord[]>([]);
const dataDetail = ref<DataRecord>({});
const detailLoading = ref(false);
const detailVisible = ref(false);
Expand Down
Loading

0 comments on commit 3440aa4

Please sign in to comment.