Complete core functions #9
@@ -1,24 +1,25 @@
|
||||
package top.fatweb.api.controller.system
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation
|
||||
import org.springframework.security.access.prepost.PreAuthorize
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import top.fatweb.api.annotation.BaseController
|
||||
import top.fatweb.api.entity.common.ResponseResult
|
||||
import top.fatweb.api.param.system.ActiveInfoGetParam
|
||||
import top.fatweb.api.param.system.OnlineInfoGetParam
|
||||
import top.fatweb.api.service.system.IStatisticService
|
||||
import top.fatweb.api.service.system.IStatisticsService
|
||||
import top.fatweb.api.vo.system.*
|
||||
|
||||
/**
|
||||
* Statistic controller
|
||||
* Statistics controller
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
* @see IStatisticService
|
||||
* @see IStatisticsService
|
||||
*/
|
||||
@BaseController(path = ["/system/statistic"], name = "统计接口", description = "系统信息统计相关接口")
|
||||
class StatisticController(
|
||||
private val statisticService: IStatisticService
|
||||
@BaseController(path = ["/system/statistics"], name = "统计接口", description = "系统信息统计相关接口")
|
||||
class StatisticsController(
|
||||
private val statisticService: IStatisticsService
|
||||
) {
|
||||
/**
|
||||
* Get software information
|
||||
@@ -31,6 +32,7 @@ class StatisticController(
|
||||
*/
|
||||
@Operation(summary = "获取软件信息")
|
||||
@GetMapping("/software")
|
||||
@PreAuthorize("hasAnyAuthority('system:statistics:query:base')")
|
||||
fun software(): ResponseResult<SoftwareInfoVo> = ResponseResult.success(data = statisticService.software())
|
||||
|
||||
/**
|
||||
@@ -44,6 +46,7 @@ class StatisticController(
|
||||
*/
|
||||
@Operation(summary = "获取硬件信息")
|
||||
@GetMapping("/hardware")
|
||||
@PreAuthorize("hasAnyAuthority('system:statistics:query:base')")
|
||||
fun hardware(): ResponseResult<HardwareInfoVo> = ResponseResult.success(data = statisticService.hardware())
|
||||
|
||||
/**
|
||||
@@ -57,6 +60,7 @@ class StatisticController(
|
||||
*/
|
||||
@Operation(summary = "获取 CPU 信息")
|
||||
@GetMapping("/cpu")
|
||||
@PreAuthorize("hasAnyAuthority('system:statistics:query:real')")
|
||||
fun cpu(): ResponseResult<CpuInfoVo> = ResponseResult.success(data = statisticService.cpu())
|
||||
|
||||
/**
|
||||
@@ -70,6 +74,7 @@ class StatisticController(
|
||||
*/
|
||||
@Operation(summary = "获取存储信息")
|
||||
@GetMapping("/storage")
|
||||
@PreAuthorize("hasAnyAuthority('system:statistics:query:real')")
|
||||
fun storage(): ResponseResult<StorageInfoVo> = ResponseResult.success(data = statisticService.storage())
|
||||
|
||||
/**
|
||||
@@ -80,6 +85,7 @@ class StatisticController(
|
||||
*/
|
||||
@Operation(summary = "获取在线用户数量信息")
|
||||
@GetMapping("/online")
|
||||
@PreAuthorize("hasAnyAuthority('system:statistics:query:usage')")
|
||||
fun online(onlineInfoGetParam: OnlineInfoGetParam?): ResponseResult<OnlineInfoVo> =
|
||||
ResponseResult.success(data = statisticService.online(onlineInfoGetParam))
|
||||
|
||||
@@ -91,6 +97,7 @@ class StatisticController(
|
||||
*/
|
||||
@Operation(summary = "获取用户活跃信息")
|
||||
@GetMapping("/active")
|
||||
@PreAuthorize("hasAnyAuthority('system:statistics:query:usage')")
|
||||
fun active(activeInfoGetParam: ActiveInfoGetParam): ResponseResult<ActiveInfoVo> =
|
||||
ResponseResult.success(data = statisticService.active(activeInfoGetParam))
|
||||
}
|
||||
@@ -2,20 +2,20 @@ package top.fatweb.api.cron
|
||||
|
||||
import org.springframework.scheduling.annotation.Scheduled
|
||||
import org.springframework.stereotype.Component
|
||||
import top.fatweb.api.entity.system.StatisticLog
|
||||
import top.fatweb.api.entity.system.StatisticsLog
|
||||
import top.fatweb.api.properties.SecurityProperties
|
||||
import top.fatweb.api.service.system.IStatisticLogService
|
||||
import top.fatweb.api.service.system.IStatisticsLogService
|
||||
import top.fatweb.api.util.RedisUtil
|
||||
|
||||
@Component
|
||||
class StatisticCron(
|
||||
class StatisticsCron(
|
||||
private val redisUtil: RedisUtil,
|
||||
private val statisticLogService: IStatisticLogService
|
||||
private val statisticsLogService: IStatisticsLogService
|
||||
) {
|
||||
@Scheduled(cron = "0 * * * * *")
|
||||
fun onlineUserCount() {
|
||||
statisticLogService.save(StatisticLog().apply {
|
||||
key = StatisticLog.KeyItem.ONLINE_USERS_COUNT
|
||||
statisticsLogService.save(StatisticsLog().apply {
|
||||
key = StatisticsLog.KeyItem.ONLINE_USERS_COUNT
|
||||
value = redisUtil.keys("${SecurityProperties.jwtIssuer}_login_*")
|
||||
.distinctBy { Regex("FatWeb_login_(.*):.*").matchEntire(it)?.groupValues?.getOrNull(1) }.size.toString()
|
||||
})
|
||||
@@ -10,13 +10,13 @@ import java.io.Serializable
|
||||
import java.time.LocalDateTime
|
||||
|
||||
/**
|
||||
* Statistic log entity
|
||||
* Statistics log entity
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@TableName("t_statistic_log")
|
||||
class StatisticLog : Serializable {
|
||||
@TableName("t_statistics_log")
|
||||
class StatisticsLog : Serializable {
|
||||
enum class KeyItem(@field:EnumValue @field:JsonValue val code: String) {
|
||||
ONLINE_USERS_COUNT("ONLINE_USER_COUNT")
|
||||
}
|
||||
@@ -59,6 +59,6 @@ class StatisticLog : Serializable {
|
||||
var recordTime: LocalDateTime?= null
|
||||
|
||||
override fun toString(): String {
|
||||
return "StatisticLog(id=$id, key=$key, value=$value, recordTime=$recordTime)"
|
||||
return "StatisticsLog(id=$id, key=$key, value=$value, recordTime=$recordTime)"
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class SysLog : Serializable {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
enum class LogType(@field:EnumValue @field:JsonValue val code: String) {
|
||||
INFO("INFO"), ERROR("ERROR"), LOGIN("LOGIN"), LOGOUT("LOGOUT"), REGISTER("REGISTER"), STATISTIC("STATISTIC"), API(
|
||||
INFO("INFO"), ERROR("ERROR"), LOGIN("LOGIN"), LOGOUT("LOGOUT"), REGISTER("REGISTER"), STATISTICS("STATISTICS"), API(
|
||||
"API"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class SysLogInterceptor(
|
||||
it.startsWith("/login") -> SysLog.LogType.LOGIN
|
||||
it.startsWith("/logout") -> SysLog.LogType.LOGOUT
|
||||
it.startsWith("/register") -> SysLog.LogType.REGISTER
|
||||
it.startsWith("/system/statistic/") -> SysLog.LogType.STATISTIC
|
||||
it.startsWith("/system/statistics/") -> SysLog.LogType.STATISTICS
|
||||
it.startsWith("/api/") -> SysLog.LogType.API
|
||||
else -> SysLog.LogType.INFO
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package top.fatweb.api.mapper.system
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper
|
||||
import org.apache.ibatis.annotations.Mapper
|
||||
import top.fatweb.api.entity.system.StatisticLog
|
||||
import top.fatweb.api.entity.system.StatisticsLog
|
||||
|
||||
@Mapper
|
||||
interface StatisticLogMapper : BaseMapper<StatisticLog>
|
||||
interface StatisticsLogMapper : BaseMapper<StatisticsLog>
|
||||
@@ -1,6 +0,0 @@
|
||||
package top.fatweb.api.service.system
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService
|
||||
import top.fatweb.api.entity.system.StatisticLog
|
||||
|
||||
interface IStatisticLogService : IService<StatisticLog>
|
||||
@@ -0,0 +1,6 @@
|
||||
package top.fatweb.api.service.system
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService
|
||||
import top.fatweb.api.entity.system.StatisticsLog
|
||||
|
||||
interface IStatisticsLogService : IService<StatisticsLog>
|
||||
@@ -5,12 +5,12 @@ import top.fatweb.api.param.system.OnlineInfoGetParam
|
||||
import top.fatweb.api.vo.system.*
|
||||
|
||||
/**
|
||||
* Statistic service interface
|
||||
* Statistics service interface
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
interface IStatisticService {
|
||||
interface IStatisticsService {
|
||||
/**
|
||||
* Get software information
|
||||
*
|
||||
@@ -1,12 +0,0 @@
|
||||
package top.fatweb.api.service.system.impl
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
|
||||
import org.springframework.stereotype.Service
|
||||
import top.fatweb.api.entity.system.StatisticLog
|
||||
import top.fatweb.api.mapper.system.StatisticLogMapper
|
||||
import top.fatweb.api.service.system.IStatisticLogService
|
||||
|
||||
@DS("sqlite")
|
||||
@Service
|
||||
class StatisticLogServiceImpl : ServiceImpl<StatisticLogMapper, StatisticLog>(), IStatisticLogService
|
||||
@@ -0,0 +1,12 @@
|
||||
package top.fatweb.api.service.system.impl
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
|
||||
import org.springframework.stereotype.Service
|
||||
import top.fatweb.api.entity.system.StatisticsLog
|
||||
import top.fatweb.api.mapper.system.StatisticsLogMapper
|
||||
import top.fatweb.api.service.system.IStatisticsLogService
|
||||
|
||||
@DS("sqlite")
|
||||
@Service
|
||||
class StatisticsLogServiceImpl : ServiceImpl<StatisticsLogMapper, StatisticsLog>(), IStatisticsLogService
|
||||
@@ -6,14 +6,14 @@ import org.springframework.stereotype.Service
|
||||
import oshi.SystemInfo
|
||||
import oshi.hardware.CentralProcessor
|
||||
import top.fatweb.api.entity.system.EventLog
|
||||
import top.fatweb.api.entity.system.StatisticLog
|
||||
import top.fatweb.api.entity.system.StatisticsLog
|
||||
import top.fatweb.api.param.system.ActiveInfoGetParam
|
||||
import top.fatweb.api.param.system.OnlineInfoGetParam
|
||||
import top.fatweb.api.properties.SecurityProperties
|
||||
import top.fatweb.api.properties.ServerProperties
|
||||
import top.fatweb.api.service.system.IEventLogService
|
||||
import top.fatweb.api.service.system.IStatisticLogService
|
||||
import top.fatweb.api.service.system.IStatisticService
|
||||
import top.fatweb.api.service.system.IStatisticsLogService
|
||||
import top.fatweb.api.service.system.IStatisticsService
|
||||
import top.fatweb.api.util.ByteUtil
|
||||
import top.fatweb.api.util.RedisUtil
|
||||
import top.fatweb.api.vo.system.*
|
||||
@@ -25,17 +25,17 @@ import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* Statistic service implement
|
||||
* Statistics service implement
|
||||
*
|
||||
* @author FatttSnake, fatttsnake@gmail.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Service
|
||||
class StatisticServiceImpl(
|
||||
class StatisticsServiceImpl(
|
||||
private val redisUtil: RedisUtil,
|
||||
private val statisticLogService: IStatisticLogService,
|
||||
private val statisticsLogService: IStatisticsLogService,
|
||||
private val eventLogService: IEventLogService
|
||||
) : IStatisticService {
|
||||
) : IStatisticsService {
|
||||
private val systemProperties: Properties = System.getProperties()
|
||||
private val systemInfo: SystemInfo = SystemInfo()
|
||||
private val runtime: Runtime = Runtime.getRuntime()
|
||||
@@ -160,13 +160,13 @@ class StatisticServiceImpl(
|
||||
)
|
||||
|
||||
override fun online(onlineInfoGetParam: OnlineInfoGetParam?): OnlineInfoVo {
|
||||
val history: List<OnlineInfoVo.HistoryVo> = statisticLogService.list(
|
||||
KtQueryWrapper(StatisticLog())
|
||||
.select(StatisticLog::value, StatisticLog::recordTime)
|
||||
.eq(StatisticLog::key, StatisticLog.KeyItem.ONLINE_USERS_COUNT)
|
||||
val history: List<OnlineInfoVo.HistoryVo> = statisticsLogService.list(
|
||||
KtQueryWrapper(StatisticsLog())
|
||||
.select(StatisticsLog::value, StatisticsLog::recordTime)
|
||||
.eq(StatisticsLog::key, StatisticsLog.KeyItem.ONLINE_USERS_COUNT)
|
||||
.between(
|
||||
onlineInfoGetParam?.scope != OnlineInfoGetParam.Scope.ALL,
|
||||
StatisticLog::recordTime,
|
||||
StatisticsLog::recordTime,
|
||||
LocalDateTime.now(ZoneOffset.UTC).run {
|
||||
when (onlineInfoGetParam?.scope) {
|
||||
OnlineInfoGetParam.Scope.DAY -> minusDays(1)
|
||||
@@ -14,6 +14,7 @@ insert into t_power (id, type_id)
|
||||
(1040000, 2),
|
||||
(1510000, 2),
|
||||
(1520000, 2),
|
||||
(1530000, 2),
|
||||
(1010100, 3),
|
||||
(1010200, 3),
|
||||
(1010300, 3),
|
||||
@@ -29,7 +30,8 @@ insert into t_power (id, type_id)
|
||||
(1040100, 3),
|
||||
(1510100, 3),
|
||||
(1520100, 3),
|
||||
(1520300, 3),
|
||||
(1530100, 3),
|
||||
(1530300, 3),
|
||||
(1010101, 4),
|
||||
(1010102, 4),
|
||||
(1010103, 4),
|
||||
@@ -56,10 +58,13 @@ insert into t_power (id, type_id)
|
||||
(1030402, 4),
|
||||
(1040103, 4),
|
||||
(1510101, 4),
|
||||
(1510102, 4),
|
||||
(1510103, 4),
|
||||
(1520101, 4),
|
||||
(1520102, 4),
|
||||
(1520301, 4),
|
||||
(1520302, 4)
|
||||
(1530101, 4),
|
||||
(1530102, 4),
|
||||
(1530301, 4),
|
||||
(1530302, 4)
|
||||
as new_value
|
||||
on duplicate key update type_id = new_value.type_id;
|
||||
|
||||
@@ -73,8 +78,9 @@ insert into t_menu (id, name, url, parent_id, module_id)
|
||||
(1020000, '角色管理', '/system/role', 1990000, 1000000),
|
||||
(1030000, '用户组管理', '/system/group', 1990000, 1000000),
|
||||
(1040000, '权限管理', '/system/power', 1990000, 1000000),
|
||||
(1510000, '日志管理', '/system/log', 1990000, 1000000),
|
||||
(1520000, '系统设置', '/system/settings', 1990000, 1000000) as new_value
|
||||
(1510000, '系统概况', '/system/statistics', 1990000, 1000000),
|
||||
(1520000, '日志管理', '/system/log', 1990000, 1000000),
|
||||
(1530000, '系统设置', '/system/settings', 1990000, 1000000) as new_value
|
||||
on duplicate key update name =new_value.name,
|
||||
url =new_value.url,
|
||||
parent_id =new_value.parent_id;
|
||||
@@ -95,7 +101,8 @@ insert into t_func(id, name, menu_id, parent_id)
|
||||
(1040100, '查询', 1040000, null),
|
||||
(1510100, '查询', 1510000, null),
|
||||
(1520100, '查询', 1520000, null),
|
||||
(1520300, '修改', 1520000, null) as new_value
|
||||
(1530100, '查询', 1530000, null),
|
||||
(1530300, '修改', 1530000, null) as new_value
|
||||
on duplicate key update name = new_value.name,
|
||||
menu_id = new_value.menu_id,
|
||||
parent_id = new_value.parent_id;
|
||||
@@ -126,11 +133,14 @@ insert into t_operation(id, name, code, func_id)
|
||||
(1030401, '单个', 'system:group:delete:one', 1030400),
|
||||
(1030402, '多个', 'system:group:delete:multiple', 1030400),
|
||||
(1040103, '列表', 'system:power:query:list', 1040100),
|
||||
(1510101, '全部', 'system:log:query:all', 1510100),
|
||||
(1520101, '基础', 'system:settings:query:base', 1520100),
|
||||
(1520102, '邮件', 'system:settings:query:mail', 1520100),
|
||||
(1520301, '基础', 'system:settings:modify:base', 1520300),
|
||||
(1520302, '邮件', 'system:settings:modify:mail', 1520300) as new_value
|
||||
(1510101, '使用情况', 'system:statistics:query:usage', 1510100),
|
||||
(1510102, '基础信息', 'system:statistics:query:base', 1510100),
|
||||
(1510103, '实时信息', 'system:statistics:query:real', 1510100),
|
||||
(1520101, '全部', 'system:log:query:all', 1520100),
|
||||
(1530101, '基础', 'system:settings:query:base', 1530100),
|
||||
(1530102, '邮件', 'system:settings:query:mail', 1530100),
|
||||
(1530301, '基础', 'system:settings:modify:base', 1530300),
|
||||
(1530302, '邮件', 'system:settings:modify:mail', 1530300) as new_value
|
||||
on duplicate key update name=new_value.name,
|
||||
code=new_value.code,
|
||||
func_id=new_value.func_id;
|
||||
@@ -1,6 +1,6 @@
|
||||
drop table if exists t_statistic_log;
|
||||
drop table if exists t_statistics_log;
|
||||
|
||||
create table if not exists t_statistic_log -- 统计日志表
|
||||
create table if not exists t_statistics_log -- 统计日志表
|
||||
(
|
||||
id bigint not null primary key,
|
||||
key varchar(50) not null, -- 记录键
|
||||
Reference in New Issue
Block a user