From 60353906adf7c93cce445057e436bf67c52bef83 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 20 Dec 2023 11:32:47 +0800 Subject: [PATCH] Rename statistic to statistics --- ...cController.kt => StatisticsController.kt} | 19 +++++++---- .../{StatisticCron.kt => StatisticsCron.kt} | 12 +++---- .../{StatisticLog.kt => StatisticsLog.kt} | 8 ++--- .../top/fatweb/api/entity/system/SysLog.kt | 2 +- .../api/interceptor/SysLogInterceptor.kt | 2 +- ...ticLogMapper.kt => StatisticsLogMapper.kt} | 4 +-- .../service/system/IStatisticLogService.kt | 6 ---- .../service/system/IStatisticsLogService.kt | 6 ++++ ...tisticService.kt => IStatisticsService.kt} | 4 +-- .../system/impl/StatisticLogServiceImpl.kt | 12 ------- .../system/impl/StatisticsLogServiceImpl.kt | 12 +++++++ ...erviceImpl.kt => StatisticsServiceImpl.kt} | 24 ++++++------- .../db/migration/master/R__Basic_data.sql | 34 ++++++++++++------- ..._0_0_231214__Add_table_'t_statistics'.sql} | 4 +-- 14 files changed, 83 insertions(+), 66 deletions(-) rename src/main/kotlin/top/fatweb/api/controller/system/{StatisticController.kt => StatisticsController.kt} (78%) rename src/main/kotlin/top/fatweb/api/cron/{StatisticCron.kt => StatisticsCron.kt} (64%) rename src/main/kotlin/top/fatweb/api/entity/system/{StatisticLog.kt => StatisticsLog.kt} (88%) rename src/main/kotlin/top/fatweb/api/mapper/system/{StatisticLogMapper.kt => StatisticsLogMapper.kt} (57%) delete mode 100644 src/main/kotlin/top/fatweb/api/service/system/IStatisticLogService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/system/IStatisticsLogService.kt rename src/main/kotlin/top/fatweb/api/service/system/{IStatisticService.kt => IStatisticsService.kt} (96%) delete mode 100644 src/main/kotlin/top/fatweb/api/service/system/impl/StatisticLogServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsLogServiceImpl.kt rename src/main/kotlin/top/fatweb/api/service/system/impl/{StatisticServiceImpl.kt => StatisticsServiceImpl.kt} (94%) rename src/main/resources/db/migration/sqlite/{V1_0_0_231214__Add_table_'t_statistic'.sql => V1_0_0_231214__Add_table_'t_statistics'.sql} (77%) diff --git a/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt b/src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt similarity index 78% rename from src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt rename to src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt index 0b207db..107e6d4 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt @@ -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 = ResponseResult.success(data = statisticService.software()) /** @@ -44,6 +46,7 @@ class StatisticController( */ @Operation(summary = "获取硬件信息") @GetMapping("/hardware") + @PreAuthorize("hasAnyAuthority('system:statistics:query:base')") fun hardware(): ResponseResult = 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 = ResponseResult.success(data = statisticService.cpu()) /** @@ -70,6 +74,7 @@ class StatisticController( */ @Operation(summary = "获取存储信息") @GetMapping("/storage") + @PreAuthorize("hasAnyAuthority('system:statistics:query:real')") fun storage(): ResponseResult = 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 = 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 = ResponseResult.success(data = statisticService.active(activeInfoGetParam)) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/cron/StatisticCron.kt b/src/main/kotlin/top/fatweb/api/cron/StatisticsCron.kt similarity index 64% rename from src/main/kotlin/top/fatweb/api/cron/StatisticCron.kt rename to src/main/kotlin/top/fatweb/api/cron/StatisticsCron.kt index d22e6e9..5408c4c 100644 --- a/src/main/kotlin/top/fatweb/api/cron/StatisticCron.kt +++ b/src/main/kotlin/top/fatweb/api/cron/StatisticsCron.kt @@ -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() }) diff --git a/src/main/kotlin/top/fatweb/api/entity/system/StatisticLog.kt b/src/main/kotlin/top/fatweb/api/entity/system/StatisticsLog.kt similarity index 88% rename from src/main/kotlin/top/fatweb/api/entity/system/StatisticLog.kt rename to src/main/kotlin/top/fatweb/api/entity/system/StatisticsLog.kt index 1ea02cd..b8c1426 100644 --- a/src/main/kotlin/top/fatweb/api/entity/system/StatisticLog.kt +++ b/src/main/kotlin/top/fatweb/api/entity/system/StatisticsLog.kt @@ -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)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt b/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt index 80b8c1e..98fbdf4 100644 --- a/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt +++ b/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt @@ -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" ) } diff --git a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt index ab10b5b..e91bc78 100644 --- a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt +++ b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt @@ -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 } diff --git a/src/main/kotlin/top/fatweb/api/mapper/system/StatisticLogMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/system/StatisticsLogMapper.kt similarity index 57% rename from src/main/kotlin/top/fatweb/api/mapper/system/StatisticLogMapper.kt rename to src/main/kotlin/top/fatweb/api/mapper/system/StatisticsLogMapper.kt index a970d8e..85bd9ce 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/system/StatisticLogMapper.kt +++ b/src/main/kotlin/top/fatweb/api/mapper/system/StatisticsLogMapper.kt @@ -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 \ No newline at end of file +interface StatisticsLogMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/IStatisticLogService.kt b/src/main/kotlin/top/fatweb/api/service/system/IStatisticLogService.kt deleted file mode 100644 index 4ad89b1..0000000 --- a/src/main/kotlin/top/fatweb/api/service/system/IStatisticLogService.kt +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/IStatisticsLogService.kt b/src/main/kotlin/top/fatweb/api/service/system/IStatisticsLogService.kt new file mode 100644 index 0000000..56136c8 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/system/IStatisticsLogService.kt @@ -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 \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt b/src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt rename to src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt index a84c741..b28ee1d 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt @@ -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 * diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticLogServiceImpl.kt deleted file mode 100644 index 479b142..0000000 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticLogServiceImpl.kt +++ /dev/null @@ -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(), IStatisticLogService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsLogServiceImpl.kt new file mode 100644 index 0000000..212ceee --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsLogServiceImpl.kt @@ -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(), IStatisticsLogService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt rename to src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt index cf93c3a..49289a9 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt @@ -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 = statisticLogService.list( - KtQueryWrapper(StatisticLog()) - .select(StatisticLog::value, StatisticLog::recordTime) - .eq(StatisticLog::key, StatisticLog.KeyItem.ONLINE_USERS_COUNT) + val history: List = 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) diff --git a/src/main/resources/db/migration/master/R__Basic_data.sql b/src/main/resources/db/migration/master/R__Basic_data.sql index 22d3fdd..0199971 100644 --- a/src/main/resources/db/migration/master/R__Basic_data.sql +++ b/src/main/resources/db/migration/master/R__Basic_data.sql @@ -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; \ No newline at end of file diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistic'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics'.sql similarity index 77% rename from src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistic'.sql rename to src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics'.sql index 423ce81..22a14de 100644 --- a/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistic'.sql +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics'.sql @@ -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, -- 记录键