Rename statistic to statistics
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user