From af3746fe80cc04da362666dff0ab28fdf028a30a Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 28 Sep 2023 01:35:41 +0800 Subject: [PATCH 001/258] Add dependencies --- pom.xml | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/pom.xml b/pom.xml index ee5348b..63b530a 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,11 @@ runtime true + + com.mysql + mysql-connector-j + runtime + org.projectlombok lombok @@ -60,6 +65,50 @@ spring-security-test test + + + com.baomidou + mybatis-plus-boot-starter + 3.5.3.1 + + + com.baomidou + mybatis-plus-boot-starter-test + 3.5.3.1 + test + + + com.alibaba + druid-spring-boot-starter + 1.2.16 + + + com.baomidou + mybatis-plus-generator + 3.5.3.1 + + + org.apache.velocity + velocity-engine-core + 2.3 + + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + 4.1.0 + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-actuator + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + @@ -85,6 +134,21 @@ org.jetbrains.kotlin kotlin-maven-plugin + + + compile + compile + + compile + + + + src/main/kotlin + target/generated-sources/annotations + + + + -Xjsr305=strict From ec38de33f5c898432b6abd08936af88ac39fd9d1 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 28 Sep 2023 01:36:16 +0800 Subject: [PATCH 002/258] Add @EnableTransactionManagement --- src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index f77dbd7..d3741f1 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -2,8 +2,10 @@ package top.fatweb.api import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication +import org.springframework.transaction.annotation.EnableTransactionManagement @SpringBootApplication +@EnableTransactionManagement class FatWebApiApplication fun main(args: Array) { From 6be65c4496e98bad174ef5ac7b6e73c756f33492 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 28 Sep 2023 01:36:24 +0800 Subject: [PATCH 003/258] Add RedisUtil --- .../kotlin/top/fatweb/api/utils/RedisUtil.kt | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 src/main/kotlin/top/fatweb/api/utils/RedisUtil.kt diff --git a/src/main/kotlin/top/fatweb/api/utils/RedisUtil.kt b/src/main/kotlin/top/fatweb/api/utils/RedisUtil.kt new file mode 100644 index 0000000..426b772 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/utils/RedisUtil.kt @@ -0,0 +1,182 @@ +package top.fatweb.api.utils + +import org.springframework.data.redis.core.BoundSetOperations +import org.springframework.data.redis.core.RedisTemplate +import org.springframework.stereotype.Component +import java.util.concurrent.TimeUnit + +@Suppress("UNCHECKED_CAST") +@Component +class RedisUtil(private val redisTemplate: RedisTemplate) { + /** + * 设置有效时间 + * + * @param key 缓存的键 + * @param timeout 超时时间 + * @param timeUnit 时间颗粒度 + * @return true=设置成功;false=设置失败 + */ + fun setExpire(key: String, timeout: Long, timeUnit: TimeUnit = TimeUnit.SECONDS) = + redisTemplate.expire(key, timeout, timeUnit) + + /** + * 获取有效时间 + * + * @param key 缓存的键 + * @return 有效时间 + */ + fun getExpire(key: String, timeUnit: TimeUnit = TimeUnit.SECONDS) = redisTemplate.getExpire(key, timeUnit) + + /** + * 判断 key 是否存在 + * + * @param key 缓存的键 + * @return true=存在; false=不存在 + */ + fun hasKey(key: String) = redisTemplate.hasKey(key) + + /** + * 获得缓存的基本对象列表 + * + * @param pattern 字符串前缀 + * @return 对象列表 + */ + fun keys(pattern: String): Set = redisTemplate.keys(pattern) + + /** + * 缓存基本的对象,Integer、String、实体类等 + * + * @param key 缓存的键 + * @param value 缓存的值 + */ + fun setObject(key: String, value: Any) = redisTemplate.opsForValue().set(key, value) + + /** + * 缓存基本的对象,Integer、String、实体类等 + * + * @param key 缓存的键 + * @param value 缓存的值 + * @param timeout 超时时间 + * @param timeUnit 时间颗粒度 + */ + fun setObject(key: String, value: Any, timeout: Long, timeUnit: TimeUnit = TimeUnit.SECONDS) = + redisTemplate.opsForValue().set(key, value, timeout, timeUnit) + + + /** + * 获得缓存的基本对象 + * + * @param key 缓存的键 + * @return 缓存的值 + */ + fun getObject(key: String) = redisTemplate.opsForValue().get(key) as? T + + /** + * 删除单个对象 + * + * @param key 缓存的键 + * @return true=删除成功;false=删除失败 + */ + fun delObject(key: String) = redisTemplate.delete(key) + + /** + * 删除对象集合 + * + * @param collection 键集合 + * @return 删除个数 + */ + fun delObject(collection: Collection) = redisTemplate.delete(collection) + + /** + * 缓存 List 数据 + * + * @param key 缓存的键 + * @param dataList 缓存的 List 数据 + * @return 缓存的个数 + */ + fun setList(key: String, dataList: List) = redisTemplate.opsForList().rightPushAll(key, dataList) + + /** + * 获得缓存的 List 数据 + * + * @param key 缓存的键 + * @return 缓存的键对应的 List 数据 + */ + fun getList(key: String): List? = redisTemplate.opsForList().range(key, 0, -1) as? List + + /** + * 缓存 Set 数据 + * + * @param key 缓存的键 + * @param dataSet 缓存的 Set 数据 + * @return 缓存数据的对象 + */ + fun setSet(key: String, dataSet: Set): BoundSetOperations { + val boundSetOps: BoundSetOperations = redisTemplate.boundSetOps(key) + for (data in dataSet) { + boundSetOps.add(data) + } + return boundSetOps + } + + /** + * 获得缓存的 Set 数据 + * + * @param key 缓存的键 + * @return 缓存的键对应的 Set 数据 + */ + fun getSet(key: String): Set? = redisTemplate.opsForSet().members(key) as? Set + + /** + * 缓存 Map 数据 + * + * @param key 缓存的键 + * @param dataMap 缓存的 Map 数据 + */ + fun setMap(key: String, dataMap: Map) = redisTemplate.opsForHash().putAll(key, dataMap) + + /** + * 获得缓存的 Map 数据 + * + * @param key 缓存的键 + * @return 缓存的键对应的 Map 数据 + */ + fun getMap(key: String): Map? = redisTemplate.opsForHash().entries(key) as? Map + + /** + * 往 Hash 中存入数据 + * + * @param key Redis 键 + * @param hKey Hash 键 + * @param value 值 + */ + fun setMapValue(key: String, hKey: String, value: Any) = + redisTemplate.opsForHash().put(key, hKey, value) + + /** + * 获取 Hash 中的数据 + * + * @param key Redis 键 + * @param hKey Hash 键 + * @return Hash 中的对象 + */ + fun getMapValue(key: String, hKey: String) = redisTemplate.opsForHash().get(key, hKey) + + /** + * 删除 Hash 中的数据 + * + * @param key Redis 键 + * @param hKey Hash 键 + */ + fun delMapValue(key: String, hKey: String) = redisTemplate.opsForHash().delete(key, hKey) + + /** + * 获取多个 Hash 中的数据 + * + * @param key Redis 键 + * @param hKeys Hash 键集合 + * @return Hash 对象集合 + */ + fun getMultiMapValue(key: String, hKeys: Collection): List = + redisTemplate.opsForHash().multiGet(key, hKeys) +} \ No newline at end of file From ef3810c55f03673585565f14a763eb5ca9458677 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 28 Sep 2023 10:59:25 +0800 Subject: [PATCH 004/258] Rename FatwebApiApplicationTests to FatWebApiApplicationTests --- .../top/fatweb/api/FatwebApiApplicationTests.kt | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/test/kotlin/top/fatweb/api/FatwebApiApplicationTests.kt diff --git a/src/test/kotlin/top/fatweb/api/FatwebApiApplicationTests.kt b/src/test/kotlin/top/fatweb/api/FatwebApiApplicationTests.kt deleted file mode 100644 index 3c32b03..0000000 --- a/src/test/kotlin/top/fatweb/api/FatwebApiApplicationTests.kt +++ /dev/null @@ -1,13 +0,0 @@ -package top.fatweb.api - -import org.junit.jupiter.api.Test -import org.springframework.boot.test.context.SpringBootTest - -@SpringBootTest -class FatwebApiApplicationTests { - - @Test - fun contextLoads() { - } - -} From c57064d0f80f2fe497f6f746f9eb871049dc5d6d Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 28 Sep 2023 10:59:48 +0800 Subject: [PATCH 005/258] Rename FatwebApiApplicationTests to FatWebApiApplicationTests --- .../top/fatweb/api/FatWebApiApplicationTests.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt diff --git a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt new file mode 100644 index 0000000..a4324ff --- /dev/null +++ b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt @@ -0,0 +1,13 @@ +package top.fatweb.api + +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest + +@SpringBootTest +class FatWebApiApplicationTests { + + @Test + fun contextLoads() { + } + +} From 91555b8160e14175c3424a351b79df1062776a41 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 28 Sep 2023 18:02:06 +0800 Subject: [PATCH 006/258] Add configs and properties --- .gitignore | 1 + pom.xml | 4 ++- .../top/fatweb/api/FatWebApiApplication.kt | 12 ++++++- .../fatweb/api/config/MybatisPlusConfig.kt | 20 +++++++++++ .../top/fatweb/api/config/RedisConfig.kt | 34 +++++++++++++++++++ .../top/fatweb/api/config/SwaggerConfig.kt | 19 +++++++++++ .../fatweb/api/constants/SecurityConstants.kt | 29 ++++++++++++++++ .../fatweb/api/constants/ServerConstants.kt | 17 ++++++++++ .../top/fatweb/api/filter/ExceptionFilter.kt | 15 ++++++++ .../filter/JwtAuthenticationTokenFilter.kt | 26 ++++++++++++++ .../kotlin/top/fatweb/api/utils/JwtUtil.kt | 5 +++ .../resources/application-config-template.yml | 32 +++++++++++++++++ src/main/resources/application.yml | 14 ++++++++ .../fatweb/api/FatWebApiApplicationTests.kt | 4 +++ 14 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/config/MybatisPlusConfig.kt create mode 100644 src/main/kotlin/top/fatweb/api/config/RedisConfig.kt create mode 100644 src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt create mode 100644 src/main/kotlin/top/fatweb/api/constants/SecurityConstants.kt create mode 100644 src/main/kotlin/top/fatweb/api/constants/ServerConstants.kt create mode 100644 src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt create mode 100644 src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt create mode 100644 src/main/kotlin/top/fatweb/api/utils/JwtUtil.kt create mode 100644 src/main/resources/application-config-template.yml diff --git a/.gitignore b/.gitignore index 549e00a..ab4ff27 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ build/ ### VS Code ### .vscode/ +/application-config.yml diff --git a/pom.xml b/pom.xml index 63b530a..bff9773 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,8 @@ 17 1.8.22 + ${maven.build.timestamp} + yyyy-MM-dd'T'HH:mm:ss @@ -80,7 +82,7 @@ com.alibaba druid-spring-boot-starter - 1.2.16 + 1.2.19 com.baomidou diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index d3741f1..5dbcf42 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -1,13 +1,23 @@ package top.fatweb.api +import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication import org.springframework.transaction.annotation.EnableTransactionManagement +import java.io.File @SpringBootApplication @EnableTransactionManagement class FatWebApiApplication fun main(args: Array) { - runApplication(*args) + val logger = LoggerFactory.getLogger("main") + + if (File("application-config.yml").exists()) { + runApplication(*args) + } else { + logger.warn("File ‘application.yml’ cannot be found in the running path. The configuration file template 'application.example.yml' has been created. Please change the configuration file content and rename it to 'application.yml', and then restart the server.") + FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText() + ?.let { File("application-config.example.yml").writeText(it) } + } } diff --git a/src/main/kotlin/top/fatweb/api/config/MybatisPlusConfig.kt b/src/main/kotlin/top/fatweb/api/config/MybatisPlusConfig.kt new file mode 100644 index 0000000..2ce739c --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/config/MybatisPlusConfig.kt @@ -0,0 +1,20 @@ +package top.fatweb.api.config + +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor +import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class MybatisPlusConfig { + @Bean + fun mybatisPlusInterceptor(): MybatisPlusInterceptor { + val mybatisPlusInterceptor = MybatisPlusInterceptor() + mybatisPlusInterceptor.addInnerInterceptor(OptimisticLockerInnerInterceptor()) + mybatisPlusInterceptor.addInnerInterceptor(PaginationInnerInterceptor()) + + return mybatisPlusInterceptor + } + +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt b/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt new file mode 100644 index 0000000..fd13a65 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt @@ -0,0 +1,34 @@ +package top.fatweb.api.config + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.data.redis.connection.RedisConnectionFactory +import org.springframework.data.redis.core.RedisTemplate +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer +import org.springframework.data.redis.serializer.StringRedisSerializer + +@Configuration +class RedisConfig { + @Bean + fun redisTemplate(redisConnectionFactory: RedisConnectionFactory): RedisTemplate<*, *> { + val redisTemplate = RedisTemplate() + redisTemplate.connectionFactory = redisConnectionFactory + val stringRedisSerializer = StringRedisSerializer() + val objectMapper = ObjectMapper().registerModules(JavaTimeModule()) + val anyJackson2JsonRedisSerializer = Jackson2JsonRedisSerializer(objectMapper, Any::class.java) + + // 使用StringRedisSerializer来序列化和反序列化redis的key值 + redisTemplate.keySerializer = stringRedisSerializer + redisTemplate.valueSerializer = anyJackson2JsonRedisSerializer + + // Hash的key也采用StringRedisSerializer的序列化方式 + redisTemplate.hashKeySerializer = stringRedisSerializer + redisTemplate.hashValueSerializer = anyJackson2JsonRedisSerializer + + redisTemplate.afterPropertiesSet() + + return redisTemplate + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt b/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt new file mode 100644 index 0000000..6ce83a6 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt @@ -0,0 +1,19 @@ +package top.fatweb.api.config + +import io.swagger.v3.oas.models.OpenAPI +import io.swagger.v3.oas.models.info.Contact +import io.swagger.v3.oas.models.info.Info +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import top.fatweb.api.constants.ServerConstants + +@Configuration +class SwaggerConfig { + + @Bean + fun customOpenAPI(): OpenAPI? { + val contact = Contact().name("FatttSnake").url("https://fatweb.top").email("fatttsnake@fatweb.top") + return OpenAPI().info(Info().title("FatWeb API 文档").description("FatWeb 后端 API 文档,包含各个 Controller 调用信息").contact(contact).version( + ServerConstants.version)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/constants/SecurityConstants.kt b/src/main/kotlin/top/fatweb/api/constants/SecurityConstants.kt new file mode 100644 index 0000000..e92897a --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/constants/SecurityConstants.kt @@ -0,0 +1,29 @@ +package top.fatweb.api.constants + +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.stereotype.Component +import java.security.MessageDigest +import java.util.concurrent.TimeUnit + +@Component +@ConfigurationProperties("app.security") +object SecurityConstants { + var headerString = "Authorization" + + var tokenPrefix = "Bearer " + + var jwtTtl = 2L + + var jwtTtlUnit = TimeUnit.HOURS + + lateinit var jwtKey: String + + private fun ByteArray.hex(): String { + return joinToString("") { "%02X".format(it) } + } + + private fun String.md5(): String { + val bytes = MessageDigest.getInstance("MD5").digest(this.toByteArray()) + return bytes.hex() + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/constants/ServerConstants.kt b/src/main/kotlin/top/fatweb/api/constants/ServerConstants.kt new file mode 100644 index 0000000..adabb4e --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/constants/ServerConstants.kt @@ -0,0 +1,17 @@ +package top.fatweb.api.constants + +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.stereotype.Component +import java.time.LocalDateTime +import java.time.ZoneId +import java.time.ZonedDateTime + +@Component +@ConfigurationProperties("app") +object ServerConstants { + lateinit var version: String + + lateinit var buildTime: String + + fun buildZoneDateTime(zoneId: ZoneId = ZoneId.systemDefault()): ZonedDateTime = LocalDateTime.parse(buildTime).atZone(ZoneId.of("UTC")).withZoneSameInstant(zoneId) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt b/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt new file mode 100644 index 0000000..4fcfbc2 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt @@ -0,0 +1,15 @@ +package top.fatweb.api.filter + +import jakarta.servlet.* +import java.lang.Exception + +class ExceptionFilter : Filter { + override fun doFilter(servletRequest: ServletRequest?, servletResponse: ServletResponse?, filterChain: FilterChain?) { + try { + filterChain!!.doFilter(servletRequest, servletResponse) + } catch (e: Exception) { + servletRequest?.setAttribute("filter.error", e) + servletRequest?.getRequestDispatcher("/error/thrown")?.forward(servletRequest, servletResponse) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt b/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt new file mode 100644 index 0000000..9319248 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt @@ -0,0 +1,26 @@ +package top.fatweb.api.filter + +import jakarta.servlet.FilterChain +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse +import org.springframework.util.StringUtils +import org.springframework.web.filter.OncePerRequestFilter +import top.fatweb.api.constants.SecurityConstants +import top.fatweb.api.utils.RedisUtil + +class JwtAuthenticationTokenFilter(private val redisUtil: RedisUtil) : OncePerRequestFilter() { + override fun doFilterInternal( + request: HttpServletRequest, + response: HttpServletResponse, + filterChain: FilterChain + ) { + val token = request.getHeader(SecurityConstants.headerString) + + if (!StringUtils.hasText(token) || "/error/thrown" == request.servletPath) { + filterChain.doFilter(request, response) + return + } + + + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/utils/JwtUtil.kt b/src/main/kotlin/top/fatweb/api/utils/JwtUtil.kt new file mode 100644 index 0000000..9d18414 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/utils/JwtUtil.kt @@ -0,0 +1,5 @@ +package top.fatweb.api.utils + +class JwtUtil { + +} \ No newline at end of file diff --git a/src/main/resources/application-config-template.yml b/src/main/resources/application-config-template.yml new file mode 100644 index 0000000..88a4403 --- /dev/null +++ b/src/main/resources/application-config-template.yml @@ -0,0 +1,32 @@ +server: +# port: 8080 # Server port + +spring: + datasource: + url: jdbc:mysql://localhost # MySQL url + username: root # MySQL username + password: root # MySQL password + + druid: +# initial-size: 20 # Initial number of connections +# min-idle: 20 # Minimum number of connection pools +# max-active: 20 # Maximum number of connection pools +# max-wait: 3000 # Maximum connection timeout +# min-evictable-idle-time-millis: 300000 # Minimum time for a connection to live in the pool +# max-evictable-idle-time-millis: 900000 # Maximum time for a connection to live in the pool +# break-after-acquire-failure: true # Terminate the retry when the server fails to reconnect for the specified number of times +# connection-error-retry-attempts: 5 # Number of failed reconnections + + data: + redis: +# database: 0 # Redis database (default: 0) +# host: localhost # Redis host (default: localhost) +# port: 6379 # Redis port (default: 6379) +# password: # Password of redis +# connect-timeout: 3000 # Redis connect timeout +# lettuce: +# pool: +# min-idle: 0 +# max-idle: 8 +# max-active: 8 +# max-wait: -1ms \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8b13789..27104c4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1 +1,15 @@ +app: + version: @project.version@ + build-time: @build.timestamp@ + security: + header-string: "Authorization" + token-prefix: "Bearer " + jwt-ttl: 2 + jwt-ttl-unit: hours +spring: + profiles: + active: config + datasource: + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver \ No newline at end of file diff --git a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt index a4324ff..34fc696 100644 --- a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt +++ b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt @@ -2,12 +2,16 @@ package top.fatweb.api import org.junit.jupiter.api.Test import org.springframework.boot.test.context.SpringBootTest +import top.fatweb.api.constants.SecurityConstants +import java.security.MessageDigest +import java.util.* @SpringBootTest class FatWebApiApplicationTests { @Test fun contextLoads() { + SecurityConstants.jwtKey } } From 04f552275988bad7a7bb20adb948c7f1627efea5 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 5 Oct 2023 20:59:16 +0800 Subject: [PATCH 007/258] Add pom multiple profiles --- pom.xml | 61 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index bff9773..ddec85f 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,52 @@ 0.0.1-SNAPSHOT fatweb-api fatweb-api + + + + dev + + true + + env + dev + + + + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + 4.3.0 + + + + + prod + + + env + prod + + + + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + + + com.github.xiaoymin + knife4j-openapi3-ui + + + org.webjars + swagger-ui + + + + + + + 17 1.8.22 @@ -52,11 +98,6 @@ mysql-connector-j runtime - - org.projectlombok - lombok - true - org.springframework.boot spring-boot-starter-test @@ -94,15 +135,15 @@ velocity-engine-core 2.3 - - com.github.xiaoymin - knife4j-openapi3-jakarta-spring-boot-starter - 4.1.0 - org.springframework.boot spring-boot-starter-data-redis + + com.auth0 + java-jwt + 4.3.0 + org.springframework.boot spring-boot-starter-actuator From 86eca4918d9517f3ed04fe711b2295d961d4e588 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 5 Oct 2023 20:59:38 +0800 Subject: [PATCH 008/258] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ab4ff27..318632d 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ build/ ### VS Code ### .vscode/ /application-config.yml +/application-config.example.yml From 5e555569c25e668ff4820128b1508ae85523b99b Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 5 Oct 2023 21:00:01 +0800 Subject: [PATCH 009/258] Add t_user table schema --- db/schema.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 db/schema.sql diff --git a/db/schema.sql b/db/schema.sql new file mode 100644 index 0000000..a1140fd --- /dev/null +++ b/db/schema.sql @@ -0,0 +1,12 @@ +drop table if exists t_user; + +create table if not exists t_user +( + id bigint not null primary key, + username varchar(20) not null comment '用户名', + password char(70) not null comment '密码', + enable int not null comment '启用', + deleted bigint not null default 0, + version int not null default 0, + constraint t_user_unique unique (username, deleted) +) comment '用户'; From ca4fa261879d4db7c14dac20363995ad604ab8ac Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 5 Oct 2023 21:04:08 +0800 Subject: [PATCH 010/258] Update config file --- .../kotlin/top/fatweb/api/FatWebApiApplication.kt | 12 ++++++++++-- .../{constants => constant}/SecurityConstants.kt | 14 +++----------- .../{constants => constant}/ServerConstants.kt | 5 +++-- .../resources/application-config-template.yml | 9 +++++++++ src/main/resources/application.yml | 15 +++++++++------ 5 files changed, 34 insertions(+), 21 deletions(-) rename src/main/kotlin/top/fatweb/api/{constants => constant}/SecurityConstants.kt (51%) rename src/main/kotlin/top/fatweb/api/{constants => constant}/ServerConstants.kt (74%) diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index 5dbcf42..9d83e83 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication import org.springframework.transaction.annotation.EnableTransactionManagement import java.io.File +import java.util.* @SpringBootApplication @EnableTransactionManagement @@ -17,7 +18,14 @@ fun main(args: Array) { runApplication(*args) } else { logger.warn("File ‘application.yml’ cannot be found in the running path. The configuration file template 'application.example.yml' has been created. Please change the configuration file content and rename it to 'application.yml', and then restart the server.") - FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText() - ?.let { File("application-config.example.yml").writeText(it) } + FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText() + ?.let { + File("application-config.example.yml").writeText( + it.replace( + "\$uuid\$", + UUID.randomUUID().toString() + ) + ) + } } } diff --git a/src/main/kotlin/top/fatweb/api/constants/SecurityConstants.kt b/src/main/kotlin/top/fatweb/api/constant/SecurityConstants.kt similarity index 51% rename from src/main/kotlin/top/fatweb/api/constants/SecurityConstants.kt rename to src/main/kotlin/top/fatweb/api/constant/SecurityConstants.kt index e92897a..e868e1f 100644 --- a/src/main/kotlin/top/fatweb/api/constants/SecurityConstants.kt +++ b/src/main/kotlin/top/fatweb/api/constant/SecurityConstants.kt @@ -1,8 +1,7 @@ -package top.fatweb.api.constants +package top.fatweb.api.constant import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.stereotype.Component -import java.security.MessageDigest import java.util.concurrent.TimeUnit @Component @@ -16,14 +15,7 @@ object SecurityConstants { var jwtTtlUnit = TimeUnit.HOURS - lateinit var jwtKey: String + var jwtKey = "FatWeb" - private fun ByteArray.hex(): String { - return joinToString("") { "%02X".format(it) } - } - - private fun String.md5(): String { - val bytes = MessageDigest.getInstance("MD5").digest(this.toByteArray()) - return bytes.hex() - } + var jwtIssuer = "FatWeb" } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/constants/ServerConstants.kt b/src/main/kotlin/top/fatweb/api/constant/ServerConstants.kt similarity index 74% rename from src/main/kotlin/top/fatweb/api/constants/ServerConstants.kt rename to src/main/kotlin/top/fatweb/api/constant/ServerConstants.kt index adabb4e..5f55621 100644 --- a/src/main/kotlin/top/fatweb/api/constants/ServerConstants.kt +++ b/src/main/kotlin/top/fatweb/api/constant/ServerConstants.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.constants +package top.fatweb.api.constant import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.stereotype.Component @@ -13,5 +13,6 @@ object ServerConstants { lateinit var buildTime: String - fun buildZoneDateTime(zoneId: ZoneId = ZoneId.systemDefault()): ZonedDateTime = LocalDateTime.parse(buildTime).atZone(ZoneId.of("UTC")).withZoneSameInstant(zoneId) + fun buildZoneDateTime(zoneId: ZoneId = ZoneId.systemDefault()): ZonedDateTime = + LocalDateTime.parse(buildTime).atZone(ZoneId.of("UTC")).withZoneSameInstant(zoneId) } \ No newline at end of file diff --git a/src/main/resources/application-config-template.yml b/src/main/resources/application-config-template.yml index 88a4403..1e91da0 100644 --- a/src/main/resources/application-config-template.yml +++ b/src/main/resources/application-config-template.yml @@ -1,3 +1,12 @@ +app: + security: +# header-string: "Authorization" # The key of head to get token +# token-prefix: "Bearer " # Token prefix +# jwt-ttl: 2 # The life of token +# jwt-ttl-unit: hours # Unit of life of token + jwt-key: $uuid$ # Key to generate token +# jwt-issuer: FatWeb # Token issuer + server: # port: 8080 # Server port diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 27104c4..cec8de8 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,15 +1,18 @@ app: version: @project.version@ build-time: @build.timestamp@ - security: - header-string: "Authorization" - token-prefix: "Bearer " - jwt-ttl: 2 - jwt-ttl-unit: hours spring: profiles: active: config datasource: type: com.alibaba.druid.pool.DruidDataSource - driver-class-name: com.mysql.cj.jdbc.Driver \ No newline at end of file + driver-class-name: com.mysql.cj.jdbc.Driver +mybatis-plus: + global-config: + db-config: + logic-delete-field: deleted + logic-not-delete-value: 0 + logic-delete-value: id + id-type: assign_id + type-aliases-package: top.fatweb.api.entity From 6a9ad8d490821b3d40e25af3f8137fd2d3c6558d Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 5 Oct 2023 21:05:44 +0800 Subject: [PATCH 011/258] Reformat SwaggerConfig --- src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt b/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt index 6ce83a6..9b23066 100644 --- a/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt @@ -5,7 +5,7 @@ import io.swagger.v3.oas.models.info.Contact import io.swagger.v3.oas.models.info.Info import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration -import top.fatweb.api.constants.ServerConstants +import top.fatweb.api.constant.ServerConstants @Configuration class SwaggerConfig { @@ -13,7 +13,11 @@ class SwaggerConfig { @Bean fun customOpenAPI(): OpenAPI? { val contact = Contact().name("FatttSnake").url("https://fatweb.top").email("fatttsnake@fatweb.top") - return OpenAPI().info(Info().title("FatWeb API 文档").description("FatWeb 后端 API 文档,包含各个 Controller 调用信息").contact(contact).version( - ServerConstants.version)) + return OpenAPI().info( + Info().title("FatWeb API 文档").description("FatWeb 后端 API 文档,包含各个 Controller 调用信息") + .contact(contact).version( + ServerConstants.version + ) + ) } } \ No newline at end of file From 78de04713f3bf490036a8eaf1096ce9cdd447430 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 5 Oct 2023 21:10:05 +0800 Subject: [PATCH 012/258] Add exception handler --- .../top/fatweb/api/config/FilterConfig.kt | 18 ++++++++++ .../api/controller/ExceptionController.kt | 14 ++++++++ .../fatweb/api/entity/common/BusinessCode.kt | 6 ++++ .../fatweb/api/entity/common/ResponseCode.kt | 22 ++++++++++++ .../api/entity/common/ResponseResult.kt | 29 +++++++++++++++ .../top/fatweb/api/filter/ExceptionFilter.kt | 14 ++++++-- .../fatweb/api/handler/ExceptionHandler.kt | 35 +++++++++++++++++++ 7 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/config/FilterConfig.kt create mode 100644 src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/common/BusinessCode.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt create mode 100644 src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt diff --git a/src/main/kotlin/top/fatweb/api/config/FilterConfig.kt b/src/main/kotlin/top/fatweb/api/config/FilterConfig.kt new file mode 100644 index 0000000..71374f9 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/config/FilterConfig.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.config + +import org.springframework.boot.web.servlet.FilterRegistrationBean +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import top.fatweb.api.filter.ExceptionFilter + +@Configuration +class FilterConfig { + @Bean + fun exceptionFilterRegistrationBean(exceptionFilter: ExceptionFilter): FilterRegistrationBean { + val registrationBean = FilterRegistrationBean(exceptionFilter) + registrationBean.setBeanName("exceptionFilter") + registrationBean.order = -100 + + return registrationBean + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt b/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt new file mode 100644 index 0000000..dcb7833 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.controller + +import jakarta.servlet.http.HttpServletRequest +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/error") +class ExceptionController { + @RequestMapping("/thrown") + fun thrown(request: HttpServletRequest) { + throw request.getAttribute("filter.error") as RuntimeException + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/common/BusinessCode.kt b/src/main/kotlin/top/fatweb/api/entity/common/BusinessCode.kt new file mode 100644 index 0000000..02178f5 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/common/BusinessCode.kt @@ -0,0 +1,6 @@ +package top.fatweb.api.entity.common + +enum class BusinessCode(val code: Int) { + SYSTEM(100), + DATABASE(200) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt new file mode 100644 index 0000000..8749e68 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt @@ -0,0 +1,22 @@ +package top.fatweb.api.entity.common + +enum class ResponseCode(val code: Int) { + SYSTEM_OK(BusinessCode.SYSTEM, 0), + SYSTEM_LOGIN_SUCCESS(BusinessCode.SYSTEM, 20), + SYSTEM_PASSWORD_CHANGE_SUCCESS(BusinessCode.SYSTEM, 21), + SYSTEM_LOGOUT_SUCCESS(BusinessCode.SYSTEM, 22), + SYSTEM_TOKEN_RENEW_SUCCESS(BusinessCode.SYSTEM, 23), + SYSTEM_UNAUTHORIZED(BusinessCode.SYSTEM, 30), + SYSTEM_ACCESS_DENIED(BusinessCode.SYSTEM, 31), + SYSTEM_USER_DISABLE(BusinessCode.SYSTEM, 32), + SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR(BusinessCode.SYSTEM, 33), + SYSTEM_OLD_PASSWORD_NOT_MATCH(BusinessCode.SYSTEM, 34), + SYSTEM_LOGOUT_FAILED(BusinessCode.SYSTEM, 35), + SYSTEM_TOKEN_ILLEGAL(BusinessCode.SYSTEM, 36), + SYSTEM_TOKEN_HAS_EXPIRED(BusinessCode.SYSTEM, 37), + SYSTEM_REQUEST_ILLEGAL(BusinessCode.SYSTEM, 40), + SYSTEM_ERROR(BusinessCode.SYSTEM, 50), + SYSTEM_TIMEOUT(BusinessCode.SYSTEM, 51); + + constructor(businessCode: BusinessCode, code: Int) : this(businessCode.code * 100 + code) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt b/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt new file mode 100644 index 0000000..9559c1d --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt @@ -0,0 +1,29 @@ +package top.fatweb.api.entity.common + +import io.swagger.v3.oas.annotations.media.Schema +import java.io.Serializable + +class ResponseResult private constructor( + @Schema(description = "响应码", defaultValue = "200") + val code: Int, + + @Schema(description = "是否调用成功") + val success: Boolean, + + @Schema(description = "信息") + val msg: String, + + @Schema(description = "数据") + val data: T? +) : Serializable { + companion object { + fun build(code: ResponseCode, success: Boolean, msg: String, data: T?) = + ResponseResult(code.code, success, msg, data) + + fun success(code: ResponseCode = ResponseCode.SYSTEM_OK, msg: String = "success", data: T? = null) = + build(code, true, msg, data) + + fun fail(code: ResponseCode = ResponseCode.SYSTEM_ERROR, msg: String = "fail", data: T? = null) = + build(code, false, msg, data) + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt b/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt index 4fcfbc2..3097036 100644 --- a/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt +++ b/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt @@ -1,10 +1,18 @@ package top.fatweb.api.filter -import jakarta.servlet.* -import java.lang.Exception +import jakarta.servlet.Filter +import jakarta.servlet.FilterChain +import jakarta.servlet.ServletRequest +import jakarta.servlet.ServletResponse +import org.springframework.stereotype.Component +@Component class ExceptionFilter : Filter { - override fun doFilter(servletRequest: ServletRequest?, servletResponse: ServletResponse?, filterChain: FilterChain?) { + override fun doFilter( + servletRequest: ServletRequest?, + servletResponse: ServletResponse?, + filterChain: FilterChain? + ) { try { filterChain!!.doFilter(servletRequest, servletResponse) } catch (e: Exception) { diff --git a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt new file mode 100644 index 0000000..4d982d0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt @@ -0,0 +1,35 @@ +package top.fatweb.api.handler + +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.http.converter.HttpMessageNotReadableException +import org.springframework.security.authentication.InsufficientAuthenticationException +import org.springframework.web.bind.annotation.ExceptionHandler +import org.springframework.web.bind.annotation.RestControllerAdvice +import top.fatweb.api.entity.common.ResponseCode +import top.fatweb.api.entity.common.ResponseResult + +@RestControllerAdvice +class ExceptionHandler { + private val log: Logger = LoggerFactory.getLogger(this::class.java) + + @ExceptionHandler(value = [Exception::class]) + fun exceptionHandler(e: Exception): ResponseResult<*> { + return when (e) { + is InsufficientAuthenticationException -> { + log.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_UNAUTHORIZED, e.localizedMessage, null) + } + + is HttpMessageNotReadableException -> { + log.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage.split(":")[0], null) + } + + else -> { + log.error(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_ERROR, data = null) + } + } + } +} \ No newline at end of file From 8e5375ab30fa0c7f6c356b1a92b79ca337866eb9 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 5 Oct 2023 21:11:22 +0800 Subject: [PATCH 013/258] Add authentication --- .../top/fatweb/api/annotation/ApiVersion.kt | 14 +++ .../top/fatweb/api/config/SecurityConfig.kt | 92 +++++++++++++++++++ .../api/config/WebMvcRegistrationsConfig.kt | 11 +++ .../fatweb/api/controller/UserController.kt | 17 ++++ .../permission/AuthenticationController.kt | 21 +++++ .../fatweb/api/entity/permission/LoginUser.kt | 36 ++++++++ .../top/fatweb/api/entity/permission/User.kt | 56 +++++++++++ .../api/exception/TokenHasExpiredException.kt | 3 + .../filter/JwtAuthenticationTokenFilter.kt | 28 +++++- .../api/handler/JwtAccessDeniedHandler.kt | 19 ++++ .../JwtAuthenticationEntryPointHandler.kt | 19 ++++ .../top/fatweb/api/mapper/UserMapper.kt | 16 ++++ .../top/fatweb/api/service/IUserService.kt | 14 +++ .../api/service/impl/UserServiceImpl.kt | 18 ++++ .../permission/IAuthenticationService.kt | 11 +++ .../impl/AuthenticationServiceImpl.kt | 61 ++++++++++++ .../util/ApiResponseMappingHandlerMapping.kt | 31 +++++++ .../fatweb/api/util/ApiVersionCondition.kt | 26 ++++++ .../kotlin/top/fatweb/api/util/JwtUtil.kt | 67 ++++++++++++++ .../fatweb/api/{utils => util}/RedisUtil.kt | 5 +- .../kotlin/top/fatweb/api/util/WebUtil.kt | 10 ++ .../kotlin/top/fatweb/api/utils/JwtUtil.kt | 5 - src/main/resources/mapper/UserMapper.xml | 5 + .../fatweb/api/FatWebApiApplicationTests.kt | 10 +- 24 files changed, 580 insertions(+), 15 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt create mode 100644 src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt create mode 100644 src/main/kotlin/top/fatweb/api/config/WebMvcRegistrationsConfig.kt create mode 100644 src/main/kotlin/top/fatweb/api/controller/UserController.kt create mode 100644 src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/User.kt create mode 100644 src/main/kotlin/top/fatweb/api/exception/TokenHasExpiredException.kt create mode 100644 src/main/kotlin/top/fatweb/api/handler/JwtAccessDeniedHandler.kt create mode 100644 src/main/kotlin/top/fatweb/api/handler/JwtAuthenticationEntryPointHandler.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/UserMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/IUserService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/impl/UserServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/util/ApiResponseMappingHandlerMapping.kt create mode 100644 src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt create mode 100644 src/main/kotlin/top/fatweb/api/util/JwtUtil.kt rename src/main/kotlin/top/fatweb/api/{utils => util}/RedisUtil.kt (97%) create mode 100644 src/main/kotlin/top/fatweb/api/util/WebUtil.kt delete mode 100644 src/main/kotlin/top/fatweb/api/utils/JwtUtil.kt create mode 100644 src/main/resources/mapper/UserMapper.xml diff --git a/src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt b/src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt new file mode 100644 index 0000000..f087e97 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.annotation + +import org.springframework.core.annotation.AliasFor + + +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +annotation class ApiVersion( + @get:AliasFor("version") + val value: Int = 1, + + @get:AliasFor("value") + val version: Int = 1 +) diff --git a/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt b/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt new file mode 100644 index 0000000..5836f3d --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt @@ -0,0 +1,92 @@ +package top.fatweb.api.config + +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.security.authentication.AuthenticationManager +import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity +import org.springframework.security.config.annotation.web.builders.HttpSecurity +import org.springframework.security.config.annotation.web.configurers.* +import org.springframework.security.config.http.SessionCreationPolicy +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder +import org.springframework.security.web.SecurityFilterChain +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter +import org.springframework.web.cors.CorsConfiguration +import org.springframework.web.cors.UrlBasedCorsConfigurationSource +import top.fatweb.api.filter.JwtAuthenticationTokenFilter +import top.fatweb.api.handler.JwtAccessDeniedHandler +import top.fatweb.api.handler.JwtAuthenticationEntryPointHandler + +@Configuration +@EnableMethodSecurity +class SecurityConfig( + val jwtAuthenticationTokenFilter: JwtAuthenticationTokenFilter, + val authenticationEntryPointHandler: JwtAuthenticationEntryPointHandler, + val accessDeniedHandler: JwtAccessDeniedHandler +) { + @Bean + fun passwordEncoder() = BCryptPasswordEncoder() + + @Bean + fun authenticationManager(authenticationConfiguration: AuthenticationConfiguration): AuthenticationManager = + authenticationConfiguration.authenticationManager + + @Bean + fun corsConfigurationSource(): UrlBasedCorsConfigurationSource { + val corsConfiguration = CorsConfiguration() + corsConfiguration.allowedMethods = listOf("*") + corsConfiguration.allowedHeaders = listOf("*") + corsConfiguration.maxAge = 3600L + corsConfiguration.allowedOrigins = listOf("*") + val source = UrlBasedCorsConfigurationSource() + source.registerCorsConfiguration("/**", corsConfiguration) + + return source + } + + @Bean + fun securityFilterChain(httpSecurity: HttpSecurity): SecurityFilterChain = httpSecurity + // Disable CSRF + .csrf { csrfConfigurer: CsrfConfigurer -> csrfConfigurer.disable() } + // Do not get SecurityContent by Session + .sessionManagement { sessionManagementConfigurer: SessionManagementConfigurer -> + sessionManagementConfigurer.sessionCreationPolicy( + SessionCreationPolicy.STATELESS + ) + } + .authorizeHttpRequests { authorizeHttpRequests: AuthorizeHttpRequestsConfigurer.AuthorizationManagerRequestMatcherRegistry -> + authorizeHttpRequests + // Allow anonymous access + .requestMatchers( + "/api/v*/login", + "/error/thrown", + "/doc.html", + "/swagger-ui/**", + "/webjars/**", + "/v3/**", + "/swagger-ui.html", + "/favicon.ico" + ).anonymous() + // Authentication required + .anyRequest().authenticated() + } + + .logout { logoutConfigurer: LogoutConfigurer -> logoutConfigurer.disable() } + + .exceptionHandling { exceptionHandlingConfigurer: ExceptionHandlingConfigurer -> + exceptionHandlingConfigurer.authenticationEntryPoint( + authenticationEntryPointHandler + ) + exceptionHandlingConfigurer.accessDeniedHandler( + accessDeniedHandler + ) + } + + .cors { cors: CorsConfigurer -> + cors.configurationSource( + corsConfigurationSource() + ) + } + + .addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter::class.java).build() +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/config/WebMvcRegistrationsConfig.kt b/src/main/kotlin/top/fatweb/api/config/WebMvcRegistrationsConfig.kt new file mode 100644 index 0000000..1db6a0f --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/config/WebMvcRegistrationsConfig.kt @@ -0,0 +1,11 @@ +package top.fatweb.api.config + +import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations +import org.springframework.context.annotation.Configuration +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping +import top.fatweb.api.util.ApiResponseMappingHandlerMapping + +@Configuration +class WebMvcRegistrationsConfig : WebMvcRegistrations { + override fun getRequestMappingHandlerMapping(): RequestMappingHandlerMapping = ApiResponseMappingHandlerMapping() +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/controller/UserController.kt b/src/main/kotlin/top/fatweb/api/controller/UserController.kt new file mode 100644 index 0000000..188caf5 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/controller/UserController.kt @@ -0,0 +1,17 @@ +package top.fatweb.api.controller + +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +/** + *

+ * 用户 前端控制器 + *

+ * + * @author FatttSnake + * @since 2023-10-04 + */ +@RestController +@RequestMapping("/api/user") +class UserController + diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt new file mode 100644 index 0000000..c36bdac --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt @@ -0,0 +1,21 @@ +package top.fatweb.api.controller.permission + +import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.web.bind.annotation.* +import top.fatweb.api.annotation.ApiVersion +import top.fatweb.api.entity.common.ResponseCode +import top.fatweb.api.entity.common.ResponseResult +import top.fatweb.api.entity.permission.User +import top.fatweb.api.service.permission.IAuthenticationService + +@Tag(name = "身份认证", description = "身份认证相关接口") +@RestController +@RequestMapping("/api/{apiVersion}") +@ApiVersion(2) +class AuthenticationController(val loginService: IAuthenticationService) { + @Operation(summary = "登录") + @PostMapping("/login") + fun login(@PathVariable apiVersion: String, @RequestBody user: User) = + ResponseResult.success(ResponseCode.SYSTEM_LOGIN_SUCCESS, "Login success", loginService.login(user)) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt b/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt new file mode 100644 index 0000000..f160c2c --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt @@ -0,0 +1,36 @@ +package top.fatweb.api.entity.permission + +import com.fasterxml.jackson.annotation.JsonIgnore +import org.springframework.security.core.GrantedAuthority +import org.springframework.security.core.userdetails.UserDetails + +class LoginUser() : UserDetails { + lateinit var user: User + + @JsonIgnore + private var authorities: List? = null + + constructor(user: User) : this() { + this.user = user + } + + @JsonIgnore + override fun getAuthorities(): List { + authorities?.let { return it } + authorities = emptyList() + + return authorities as List + } + + override fun getPassword(): String? = user.password + + override fun getUsername(): String? = user.username + + override fun isAccountNonExpired(): Boolean = true + + override fun isAccountNonLocked(): Boolean = true + + override fun isCredentialsNonExpired(): Boolean = true + + override fun isEnabled(): Boolean = user.enable == 1 +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/User.kt b/src/main/kotlin/top/fatweb/api/entity/permission/User.kt new file mode 100644 index 0000000..3af3d08 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/User.kt @@ -0,0 +1,56 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable + +/** + *

+ * 用户 + *

+ * + * @author FatttSnake + * @since 2023-10-04 + */ +@TableName("t_user") +class User : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 用户名 + */ + @TableField("username") + var username: String? = null + + /** + * 密码 + */ + @TableField("password") + var password: String? = null + + /** + * 启用 + */ + @TableField("enable") + var enable: Int? = null + + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + @TableField("version") + @Version + var version: Int? = null + + override fun toString(): String { + return "User{" + + "id=" + id + + ", username=" + username + + ", password=" + password + + ", enable=" + enable + + ", deleted=" + deleted + + ", version=" + version + + "}" + } +} diff --git a/src/main/kotlin/top/fatweb/api/exception/TokenHasExpiredException.kt b/src/main/kotlin/top/fatweb/api/exception/TokenHasExpiredException.kt new file mode 100644 index 0000000..2b0521f --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/exception/TokenHasExpiredException.kt @@ -0,0 +1,3 @@ +package top.fatweb.api.exception + +class TokenHasExpiredException : RuntimeException("Token has expired") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt b/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt index 9319248..74f6ec0 100644 --- a/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt +++ b/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt @@ -3,24 +3,44 @@ package top.fatweb.api.filter import jakarta.servlet.FilterChain import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken +import org.springframework.security.core.context.SecurityContextHolder +import org.springframework.stereotype.Component import org.springframework.util.StringUtils import org.springframework.web.filter.OncePerRequestFilter -import top.fatweb.api.constants.SecurityConstants -import top.fatweb.api.utils.RedisUtil +import top.fatweb.api.constant.SecurityConstants +import top.fatweb.api.entity.permission.LoginUser +import top.fatweb.api.exception.TokenHasExpiredException +import top.fatweb.api.util.JwtUtil +import top.fatweb.api.util.RedisUtil +import java.util.concurrent.TimeUnit +@Component class JwtAuthenticationTokenFilter(private val redisUtil: RedisUtil) : OncePerRequestFilter() { override fun doFilterInternal( request: HttpServletRequest, response: HttpServletResponse, filterChain: FilterChain ) { - val token = request.getHeader(SecurityConstants.headerString) + val tokenWithPrefix = request.getHeader(SecurityConstants.headerString) - if (!StringUtils.hasText(token) || "/error/thrown" == request.servletPath) { + if (!StringUtils.hasText(tokenWithPrefix) || "/error/thrown" == request.servletPath) { filterChain.doFilter(request, response) return } + val token = tokenWithPrefix.removePrefix(SecurityConstants.tokenPrefix) + JwtUtil.parseJwt(token) + val redisKey = "${SecurityConstants.jwtIssuer}_login:" + token.substring(0, 32) + val loginUser = redisUtil.getObject(redisKey) + loginUser ?: let { throw TokenHasExpiredException() } + + redisUtil.setExpire(redisKey, 20, TimeUnit.MINUTES) + + val authenticationToken = UsernamePasswordAuthenticationToken(loginUser, null, loginUser.authorities) + SecurityContextHolder.getContext().authentication = authenticationToken + + filterChain.doFilter(request, response) } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/handler/JwtAccessDeniedHandler.kt b/src/main/kotlin/top/fatweb/api/handler/JwtAccessDeniedHandler.kt new file mode 100644 index 0000000..22e03c6 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/handler/JwtAccessDeniedHandler.kt @@ -0,0 +1,19 @@ +package top.fatweb.api.handler + +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse +import org.springframework.security.access.AccessDeniedException +import org.springframework.security.web.access.AccessDeniedHandler +import org.springframework.stereotype.Component + +@Component +class JwtAccessDeniedHandler : AccessDeniedHandler { + override fun handle( + request: HttpServletRequest?, + response: HttpServletResponse?, + accessDeniedException: AccessDeniedException? + ) { + request?.setAttribute("filter.error", accessDeniedException) + request?.getRequestDispatcher("/error/thrown")?.forward(request, response) + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/handler/JwtAuthenticationEntryPointHandler.kt b/src/main/kotlin/top/fatweb/api/handler/JwtAuthenticationEntryPointHandler.kt new file mode 100644 index 0000000..cf5b808 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/handler/JwtAuthenticationEntryPointHandler.kt @@ -0,0 +1,19 @@ +package top.fatweb.api.handler + +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse +import org.springframework.security.core.AuthenticationException +import org.springframework.security.web.AuthenticationEntryPoint +import org.springframework.stereotype.Component + +@Component +class JwtAuthenticationEntryPointHandler : AuthenticationEntryPoint { + override fun commence( + request: HttpServletRequest?, + response: HttpServletResponse?, + authException: AuthenticationException? + ) { + request?.setAttribute("filter.error", authException) + request?.getRequestDispatcher("/error/thrown")?.forward(request, response) + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/mapper/UserMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/UserMapper.kt new file mode 100644 index 0000000..8b37df3 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/UserMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.User + +/** + *

+ * 用户 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-04 + */ +@Mapper +interface UserMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/service/IUserService.kt b/src/main/kotlin/top/fatweb/api/service/IUserService.kt new file mode 100644 index 0000000..7bc58e9 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/IUserService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.User + +/** + *

+ * 用户 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-04 + */ +interface IUserService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/impl/UserServiceImpl.kt new file mode 100644 index 0000000..e522f6b --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/impl/UserServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.User +import top.fatweb.api.mapper.UserMapper +import top.fatweb.api.service.IUserService + +/** + *

+ * 用户 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-04 + */ +@Service +class UserServiceImpl : ServiceImpl(), IUserService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt new file mode 100644 index 0000000..b58a4b6 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt @@ -0,0 +1,11 @@ +package top.fatweb.api.service.permission + +import top.fatweb.api.entity.permission.User + +interface IAuthenticationService { + fun login(user: User): HashMap + + fun logout(token: String): Boolean + + fun renewToken(token: String): HashMap +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt new file mode 100644 index 0000000..b742f3d --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -0,0 +1,61 @@ +package top.fatweb.api.service.permission.impl + +import org.springframework.security.authentication.AuthenticationManager +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken +import org.springframework.stereotype.Service +import top.fatweb.api.constant.SecurityConstants +import top.fatweb.api.entity.permission.LoginUser +import top.fatweb.api.entity.permission.User +import top.fatweb.api.service.permission.IAuthenticationService +import top.fatweb.api.util.JwtUtil +import top.fatweb.api.util.RedisUtil +import top.fatweb.api.util.WebUtil +import java.util.concurrent.TimeUnit + +@Service +class AuthenticationServiceImpl( + private val authenticationManager: AuthenticationManager, + private val redisUtil: RedisUtil +) : IAuthenticationService { + override fun login(user: User): HashMap { + val usernamePasswordAuthenticationToken = UsernamePasswordAuthenticationToken(user.username, user.password) + val authentication = authenticationManager.authenticate(usernamePasswordAuthenticationToken) + authentication ?: let { + throw RuntimeException("Login failed") + } + + val loginUser = authentication.principal as LoginUser + loginUser.user.password = "" + val userId = loginUser.user.id.toString() + val jwt = JwtUtil.createJwt(userId) + + jwt ?: let { + throw RuntimeException("Login failed") + } + + val hashMap = hashMapOf("token" to jwt) + val redisKey = "${SecurityConstants.jwtIssuer}_login:" + jwt.substring(0, 32) + redisUtil.setObject(redisKey, loginUser, 20, TimeUnit.MINUTES) + + return hashMap + } + + override fun logout(token: String): Boolean = + redisUtil.delObject("${SecurityConstants.jwtIssuer}_login:" + token.substring(0, 32)) + + override fun renewToken(token: String): HashMap { + val oldRedisKey = "${SecurityConstants.jwtIssuer}_login:" + token.substring(0, 32) + redisUtil.delObject(oldRedisKey) + val jwt = JwtUtil.createJwt(WebUtil.getLoginUserId().toString()) + + jwt ?: let { + throw RuntimeException("Login failed") + } + + val hashMap = hashMapOf("token" to jwt) + val redisKey = "${SecurityConstants.jwtIssuer}_login:" + jwt.substring(0, 32) + redisUtil.setObject(redisKey, WebUtil.getLoginUser(), 20, TimeUnit.MINUTES) + + return hashMap + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/util/ApiResponseMappingHandlerMapping.kt b/src/main/kotlin/top/fatweb/api/util/ApiResponseMappingHandlerMapping.kt new file mode 100644 index 0000000..8dafc0e --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/util/ApiResponseMappingHandlerMapping.kt @@ -0,0 +1,31 @@ +package top.fatweb.api.util + +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.servlet.mvc.condition.RequestCondition +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping +import top.fatweb.api.annotation.ApiVersion +import java.lang.reflect.Method + +class ApiResponseMappingHandlerMapping : RequestMappingHandlerMapping() { + private val versionFlag = "{apiVersion}" + + private fun createCondition(clazz: Class<*>): RequestCondition? { + val classRequestMapping = clazz.getAnnotation(RequestMapping::class.java) + classRequestMapping ?: let { return null } + val mappingUrlBuilder = StringBuilder() + if (classRequestMapping.value.isNotEmpty()) { + mappingUrlBuilder.append(classRequestMapping.value[0]) + } + val mappingUrl = mappingUrlBuilder.toString() + if (!mappingUrl.contains(versionFlag)) { + return null + } + val apiVersion = clazz.getAnnotation(ApiVersion::class.java) + + return if (apiVersion == null) ApiVersionCondition(1) else ApiVersionCondition(apiVersion.version) + } + + override fun getCustomMethodCondition(method: Method): RequestCondition<*>? = createCondition(method.javaClass) + + override fun getCustomTypeCondition(handlerType: Class<*>): RequestCondition<*>? = createCondition(handlerType) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt b/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt new file mode 100644 index 0000000..381edaa --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt @@ -0,0 +1,26 @@ +package top.fatweb.api.util + +import jakarta.servlet.http.HttpServletRequest +import org.springframework.web.servlet.mvc.condition.RequestCondition +import java.util.regex.Pattern + +class ApiVersionCondition(private val apiVersion: Int) : RequestCondition { + private val versionPrefixPattern: Pattern = Pattern.compile(".*v(\\d+).*") + + override fun combine(other: ApiVersionCondition): ApiVersionCondition = ApiVersionCondition(other.apiVersion) + + override fun getMatchingCondition(request: HttpServletRequest): ApiVersionCondition? { + val matcher = versionPrefixPattern.matcher(request.requestURI) + if (matcher.find()) { + val version = matcher.group(1).toInt() + if (version >= this.apiVersion) { + return this + } + } + + return null + } + + override fun compareTo(other: ApiVersionCondition, request: HttpServletRequest): Int = + other.apiVersion - this.apiVersion +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/util/JwtUtil.kt b/src/main/kotlin/top/fatweb/api/util/JwtUtil.kt new file mode 100644 index 0000000..ea7c5aa --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/util/JwtUtil.kt @@ -0,0 +1,67 @@ +package top.fatweb.api.util + +import com.auth0.jwt.JWT +import com.auth0.jwt.algorithms.Algorithm +import com.auth0.jwt.interfaces.DecodedJWT +import top.fatweb.api.constant.SecurityConstants +import java.util.* +import java.util.concurrent.TimeUnit +import javax.crypto.spec.SecretKeySpec + +object JwtUtil { + private fun getUUID() = UUID.randomUUID().toString().replace("-", "") + + /** + * 生成加密后的秘钥 secretKey + * + * @return 密钥 + */ + private fun generalKey(): SecretKeySpec { + val encodeKey = Base64.getDecoder().decode(SecurityConstants.jwtKey) + return SecretKeySpec(encodeKey, 0, encodeKey.size, "AES") + } + + private fun algorithm(): Algorithm = Algorithm.HMAC256(generalKey().toString()) + + /** + * 创建 token + * + * @param subject token 中存放的数据(json格式) + * @param ttl token 生存时间 + * @param timeUnit ttl 时间单位 + * @param uuid 唯一 ID + * @return jwt 串 + */ + fun createJwt( + subject: String, + ttl: Long = SecurityConstants.jwtTtl, + timeUnit: TimeUnit = SecurityConstants.jwtTtlUnit, + uuid: String = getUUID() + ): String? { + val nowMillis = System.currentTimeMillis() + val nowDate = Date(nowMillis) + val unitTtl = (ttl * when (timeUnit) { + TimeUnit.DAYS -> 24 * 60 * 60 * 1000 + TimeUnit.HOURS -> 60 * 60 * 1000 + TimeUnit.MINUTES -> 60 * 1000 + TimeUnit.SECONDS -> 1000 + TimeUnit.MILLISECONDS -> 1 + TimeUnit.NANOSECONDS -> 1 / 1000 + TimeUnit.MICROSECONDS -> 1 / 1000 / 1000 + }) + val expMillis = nowMillis + unitTtl + val expDate = Date(expMillis) + + return JWT.create().withJWTId(uuid).withSubject(subject).withIssuer(SecurityConstants.jwtIssuer) + .withIssuedAt(nowDate).withExpiresAt(expDate).sign(algorithm()) + } + + /** + * 解析 jwt + * + * @param jwt jwt 串 + * @return 解析内容 + */ + fun parseJwt(jwt: String): DecodedJWT = + JWT.require(algorithm()).build().verify(jwt) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/utils/RedisUtil.kt b/src/main/kotlin/top/fatweb/api/util/RedisUtil.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/utils/RedisUtil.kt rename to src/main/kotlin/top/fatweb/api/util/RedisUtil.kt index 426b772..35991a8 100644 --- a/src/main/kotlin/top/fatweb/api/utils/RedisUtil.kt +++ b/src/main/kotlin/top/fatweb/api/util/RedisUtil.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.utils +package top.fatweb.api.util import org.springframework.data.redis.core.BoundSetOperations import org.springframework.data.redis.core.RedisTemplate @@ -141,7 +141,8 @@ class RedisUtil(private val redisTemplate: RedisTemplate) { * @param key 缓存的键 * @return 缓存的键对应的 Map 数据 */ - fun getMap(key: String): Map? = redisTemplate.opsForHash().entries(key) as? Map + fun getMap(key: String): Map? = + redisTemplate.opsForHash().entries(key) as? Map /** * 往 Hash 中存入数据 diff --git a/src/main/kotlin/top/fatweb/api/util/WebUtil.kt b/src/main/kotlin/top/fatweb/api/util/WebUtil.kt new file mode 100644 index 0000000..892c0c6 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/util/WebUtil.kt @@ -0,0 +1,10 @@ +package top.fatweb.api.util + +import org.springframework.security.core.context.SecurityContextHolder +import top.fatweb.api.entity.permission.LoginUser + +object WebUtil { + fun getLoginUser() = SecurityContextHolder.getContext().authentication.principal as LoginUser + + fun getLoginUserId() = getLoginUser().user.id +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/utils/JwtUtil.kt b/src/main/kotlin/top/fatweb/api/utils/JwtUtil.kt deleted file mode 100644 index 9d18414..0000000 --- a/src/main/kotlin/top/fatweb/api/utils/JwtUtil.kt +++ /dev/null @@ -1,5 +0,0 @@ -package top.fatweb.api.utils - -class JwtUtil { - -} \ No newline at end of file diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 0000000..cecc32c --- /dev/null +++ b/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt index 34fc696..9eb700d 100644 --- a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt +++ b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt @@ -1,17 +1,19 @@ package top.fatweb.api +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.springframework.boot.test.context.SpringBootTest -import top.fatweb.api.constants.SecurityConstants -import java.security.MessageDigest -import java.util.* +import top.fatweb.api.constant.SecurityConstants @SpringBootTest class FatWebApiApplicationTests { @Test fun contextLoads() { - SecurityConstants.jwtKey } + @Test + fun removePrefixTest() { + assertEquals("12312", "Bearer 12312".removePrefix(SecurityConstants.tokenPrefix)) + } } From 79e65f0785b6513085a2dac9b40cac39ffb5fbb1 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 6 Oct 2023 01:53:25 +0800 Subject: [PATCH 014/258] Add login --- pom.xml | 26 +++++++++++++++---- .../top/fatweb/api/FatWebApiApplication.kt | 14 +++++----- .../top/fatweb/api/annotation/ApiVersion.kt | 7 ++--- .../permission/AuthenticationController.kt | 22 +++++++++++----- .../fatweb/api/entity/common/ResponseCode.kt | 16 +++++++----- .../api/entity/converter/UserConverter.kt | 14 ++++++++++ .../top/fatweb/api/entity/param/LoginParam.kt | 16 ++++++++++++ .../top/fatweb/api/entity/permission/User.kt | 16 +++++------- .../fatweb/api/handler/ExceptionHandler.kt | 19 ++++++++++++++ .../permission/impl/UserDetailsServiceImpl.kt | 19 ++++++++++++++ .../resources/application-config-template.yml | 2 +- .../fatweb/api/FatWebApiApplicationTests.kt | 11 ++++++++ 12 files changed, 141 insertions(+), 41 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/entity/converter/UserConverter.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/param/LoginParam.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt diff --git a/pom.xml b/pom.xml index ddec85f..81e5aad 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,10 @@ org.springframework.boot spring-boot-starter-web
+ + org.springframework.boot + spring-boot-starter-validation + com.fasterxml.jackson.module jackson-module-kotlin @@ -112,12 +116,12 @@ com.baomidou mybatis-plus-boot-starter - 3.5.3.1 + 3.5.3.2 com.baomidou mybatis-plus-boot-starter-test - 3.5.3.1 + 3.5.3.2 test @@ -125,11 +129,13 @@ druid-spring-boot-starter 1.2.19 + org.apache.velocity velocity-engine-core @@ -142,7 +148,7 @@ com.auth0 java-jwt - 4.3.0 + 4.4.0 org.springframework.boot @@ -152,6 +158,16 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 + + org.mapstruct + mapstruct + 1.5.5.Final + + + org.mapstruct + mapstruct-processor + 1.5.5.Final +
@@ -180,7 +196,7 @@ compile - compile + process-sources compile diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index 9d83e83..1920cd3 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -18,14 +18,12 @@ fun main(args: Array) { runApplication(*args) } else { logger.warn("File ‘application.yml’ cannot be found in the running path. The configuration file template 'application.example.yml' has been created. Please change the configuration file content and rename it to 'application.yml', and then restart the server.") - FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText() - ?.let { - File("application-config.example.yml").writeText( - it.replace( - "\$uuid\$", - UUID.randomUUID().toString() - ) + FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText()?.let { + File("application-config.example.yml").writeText( + it.replace( + "\$uuid\$", UUID.randomUUID().toString().replace("-", "") ) - } + ) + } } } diff --git a/src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt b/src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt index f087e97..a0b064c 100644 --- a/src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt +++ b/src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt @@ -2,13 +2,10 @@ package top.fatweb.api.annotation import org.springframework.core.annotation.AliasFor - @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) annotation class ApiVersion( - @get:AliasFor("version") - val value: Int = 1, + @get:AliasFor("version") val value: Int = 1, - @get:AliasFor("value") - val version: Int = 1 + @get:AliasFor("value") val version: Int = 1 ) diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt index c36bdac..2d26a12 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt @@ -2,20 +2,30 @@ package top.fatweb.api.controller.permission import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag -import org.springframework.web.bind.annotation.* +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController import top.fatweb.api.annotation.ApiVersion import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.entity.permission.User +import top.fatweb.api.entity.converter.UserConverter +import top.fatweb.api.entity.param.LoginParam import top.fatweb.api.service.permission.IAuthenticationService @Tag(name = "身份认证", description = "身份认证相关接口") -@RestController +@Suppress("MVCPathVariableInspection") @RequestMapping("/api/{apiVersion}") @ApiVersion(2) -class AuthenticationController(val loginService: IAuthenticationService) { +@RestController +class AuthenticationController(val loginService: IAuthenticationService, val userConverter: UserConverter) { @Operation(summary = "登录") @PostMapping("/login") - fun login(@PathVariable apiVersion: String, @RequestBody user: User) = - ResponseResult.success(ResponseCode.SYSTEM_LOGIN_SUCCESS, "Login success", loginService.login(user)) + fun login(@Valid @RequestBody loginParam: LoginParam) = + ResponseResult.success( + ResponseCode.SYSTEM_LOGIN_SUCCESS, + "Login success", + loginService.login(userConverter.loginParamToUser(loginParam)) + ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt index 8749e68..f6095bb 100644 --- a/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt @@ -7,14 +7,16 @@ enum class ResponseCode(val code: Int) { SYSTEM_LOGOUT_SUCCESS(BusinessCode.SYSTEM, 22), SYSTEM_TOKEN_RENEW_SUCCESS(BusinessCode.SYSTEM, 23), SYSTEM_UNAUTHORIZED(BusinessCode.SYSTEM, 30), - SYSTEM_ACCESS_DENIED(BusinessCode.SYSTEM, 31), - SYSTEM_USER_DISABLE(BusinessCode.SYSTEM, 32), - SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR(BusinessCode.SYSTEM, 33), - SYSTEM_OLD_PASSWORD_NOT_MATCH(BusinessCode.SYSTEM, 34), - SYSTEM_LOGOUT_FAILED(BusinessCode.SYSTEM, 35), - SYSTEM_TOKEN_ILLEGAL(BusinessCode.SYSTEM, 36), - SYSTEM_TOKEN_HAS_EXPIRED(BusinessCode.SYSTEM, 37), + SYSTEM_USERNAME_NOT_FOUND(BusinessCode.SYSTEM, 31), + SYSTEM_ACCESS_DENIED(BusinessCode.SYSTEM, 32), + SYSTEM_USER_DISABLE(BusinessCode.SYSTEM, 33), + SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR(BusinessCode.SYSTEM, 34), + SYSTEM_OLD_PASSWORD_NOT_MATCH(BusinessCode.SYSTEM, 35), + SYSTEM_LOGOUT_FAILED(BusinessCode.SYSTEM, 36), + SYSTEM_TOKEN_ILLEGAL(BusinessCode.SYSTEM, 37), + SYSTEM_TOKEN_HAS_EXPIRED(BusinessCode.SYSTEM, 38), SYSTEM_REQUEST_ILLEGAL(BusinessCode.SYSTEM, 40), + SYSTEM_ARGUMENT_NOT_VALID(BusinessCode.SYSTEM, 41), SYSTEM_ERROR(BusinessCode.SYSTEM, 50), SYSTEM_TIMEOUT(BusinessCode.SYSTEM, 51); diff --git a/src/main/kotlin/top/fatweb/api/entity/converter/UserConverter.kt b/src/main/kotlin/top/fatweb/api/entity/converter/UserConverter.kt new file mode 100644 index 0000000..8d24463 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/converter/UserConverter.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.entity.converter + +import org.mapstruct.Mapper +import org.mapstruct.Mapping +import org.mapstruct.Mappings +import top.fatweb.api.entity.param.LoginParam +import top.fatweb.api.entity.permission.User + +@Mapper(componentModel = "spring") +interface UserConverter { + @Mappings(Mapping(source = "username", target = "username"), Mapping(source = "password", target = "password")) + fun loginParamToUser(loginParam: LoginParam): User + +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/param/LoginParam.kt b/src/main/kotlin/top/fatweb/api/entity/param/LoginParam.kt new file mode 100644 index 0000000..4ed8d0c --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/param/LoginParam.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.entity.param + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank +import java.io.Serializable + +class LoginParam : Serializable { + + @Schema(description = "用户名", example = "test", required = true) + @NotBlank(message = "Username can not be blank") + val username: String? = null + + @Schema(description = "密码", example = "test123456", required = true) + @NotBlank(message = "Password can not be blank") + val password: String? = null +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/User.kt b/src/main/kotlin/top/fatweb/api/entity/permission/User.kt index 3af3d08..bff63ab 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/User.kt +++ b/src/main/kotlin/top/fatweb/api/entity/permission/User.kt @@ -12,7 +12,12 @@ import java.io.Serializable * @since 2023-10-04 */ @TableName("t_user") -class User : Serializable { +class User() : Serializable { + constructor(username: String, password: String, enable: Boolean = true) : this() { + this.username = username + this.password = password + this.enable = if (enable) 1 else 0 + } @TableId("id") var id: Long? = null @@ -44,13 +49,6 @@ class User : Serializable { var version: Int? = null override fun toString(): String { - return "User{" + - "id=" + id + - ", username=" + username + - ", password=" + password + - ", enable=" + enable + - ", deleted=" + deleted + - ", version=" + version + - "}" + return "User{id=$id, username=$username, password=$password, enable=$enable, deleted=$deleted, version=$version}" } } diff --git a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt index 4d982d0..412c401 100644 --- a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt @@ -3,7 +3,10 @@ package top.fatweb.api.handler import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.http.converter.HttpMessageNotReadableException +import org.springframework.security.authentication.BadCredentialsException import org.springframework.security.authentication.InsufficientAuthenticationException +import org.springframework.security.authentication.InternalAuthenticationServiceException +import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.RestControllerAdvice import top.fatweb.api.entity.common.ResponseCode @@ -26,6 +29,22 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage.split(":")[0], null) } + is MethodArgumentNotValidException -> { + log.debug(e.localizedMessage, e) + val errorMessage = e.allErrors.map { error -> error.defaultMessage }.joinToString(". ") + ResponseResult.fail(ResponseCode.SYSTEM_ARGUMENT_NOT_VALID, errorMessage, null) + } + + is InternalAuthenticationServiceException -> { + log.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_USERNAME_NOT_FOUND, e.localizedMessage, null) + } + + is BadCredentialsException -> { + log.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR, e.localizedMessage, null) + } + else -> { log.error(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_ERROR, data = null) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt new file mode 100644 index 0000000..6b78e76 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt @@ -0,0 +1,19 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper +import org.springframework.security.core.userdetails.UserDetails +import org.springframework.security.core.userdetails.UserDetailsService +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.LoginUser +import top.fatweb.api.entity.permission.User +import top.fatweb.api.service.IUserService + +@Service +class UserDetailsServiceImpl(val userService: IUserService) : UserDetailsService { + override fun loadUserByUsername(username: String?): UserDetails { + val user = userService.getOne(KtQueryWrapper(User()).eq(User::username, username)) + user ?: let { throw Exception("Username not found") } + + return LoginUser(user) + } +} \ No newline at end of file diff --git a/src/main/resources/application-config-template.yml b/src/main/resources/application-config-template.yml index 1e91da0..5280697 100644 --- a/src/main/resources/application-config-template.yml +++ b/src/main/resources/application-config-template.yml @@ -4,7 +4,7 @@ app: # token-prefix: "Bearer " # Token prefix # jwt-ttl: 2 # The life of token # jwt-ttl-unit: hours # Unit of life of token - jwt-key: $uuid$ # Key to generate token + jwt-key: $uuid$ # Key to generate token (Only numbers and letters allow) # jwt-issuer: FatWeb # Token issuer server: diff --git a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt index 9eb700d..9dc0d31 100644 --- a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt +++ b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt @@ -16,4 +16,15 @@ class FatWebApiApplicationTests { fun removePrefixTest() { assertEquals("12312", "Bearer 12312".removePrefix(SecurityConstants.tokenPrefix)) } + + /* + @Test + fun addUser(@Autowired userService: IUserService, @Autowired passwordEncoder: PasswordEncoder) { + val username = "admin" + val rawPassword = "admin" + val encodedPassword = passwordEncoder.encode(rawPassword) + val user = User(username, encodedPassword) + userService.save(user) + } + */ } From 03534e4fa9d558410c62b9471fc540fb8995b927 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 6 Oct 2023 14:52:03 +0800 Subject: [PATCH 015/258] Finish authentication --- .../top/fatweb/api/config/RedisConfig.kt | 14 ++++++-- .../fatweb/api/constant/SecurityConstants.kt | 4 +++ .../permission/AuthenticationController.kt | 32 ++++++++++++++----- .../{entity => }/converter/UserConverter.kt | 4 +-- .../fatweb/api/entity/permission/LoginUser.kt | 8 +++++ .../filter/JwtAuthenticationTokenFilter.kt | 8 ++--- .../fatweb/api/handler/ExceptionHandler.kt | 13 ++++++++ .../api/{entity => }/param/LoginParam.kt | 3 +- .../permission/IAuthenticationService.kt | 6 ++-- .../impl/AuthenticationServiceImpl.kt | 30 +++++++++-------- .../kotlin/top/fatweb/api/util/WebUtil.kt | 6 ++++ src/main/kotlin/top/fatweb/api/vo/LoginVo.kt | 11 +++++++ src/main/kotlin/top/fatweb/api/vo/TokenVo.kt | 11 +++++++ .../resources/application-config-template.yml | 4 ++- 14 files changed, 121 insertions(+), 33 deletions(-) rename src/main/kotlin/top/fatweb/api/{entity => }/converter/UserConverter.kt (81%) rename src/main/kotlin/top/fatweb/api/{entity => }/param/LoginParam.kt (86%) create mode 100644 src/main/kotlin/top/fatweb/api/vo/LoginVo.kt create mode 100644 src/main/kotlin/top/fatweb/api/vo/TokenVo.kt diff --git a/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt b/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt index fd13a65..75eee51 100644 --- a/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt @@ -1,5 +1,8 @@ package top.fatweb.api.config +import com.fasterxml.jackson.annotation.JsonAutoDetect +import com.fasterxml.jackson.annotation.JsonTypeInfo +import com.fasterxml.jackson.annotation.PropertyAccessor import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import org.springframework.context.annotation.Bean @@ -16,8 +19,15 @@ class RedisConfig { val redisTemplate = RedisTemplate() redisTemplate.connectionFactory = redisConnectionFactory val stringRedisSerializer = StringRedisSerializer() - val objectMapper = ObjectMapper().registerModules(JavaTimeModule()) - val anyJackson2JsonRedisSerializer = Jackson2JsonRedisSerializer(objectMapper, Any::class.java) + val objectMapper = ObjectMapper().registerModules(JavaTimeModule()).apply { + setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY) + activateDefaultTyping( + this.polymorphicTypeValidator, + ObjectMapper.DefaultTyping.NON_FINAL, + JsonTypeInfo.As.PROPERTY + ) + } + val anyJackson2JsonRedisSerializer = Jackson2JsonRedisSerializer(objectMapper, Any::class.java) // 使用StringRedisSerializer来序列化和反序列化redis的key值 redisTemplate.keySerializer = stringRedisSerializer diff --git a/src/main/kotlin/top/fatweb/api/constant/SecurityConstants.kt b/src/main/kotlin/top/fatweb/api/constant/SecurityConstants.kt index e868e1f..c2b1738 100644 --- a/src/main/kotlin/top/fatweb/api/constant/SecurityConstants.kt +++ b/src/main/kotlin/top/fatweb/api/constant/SecurityConstants.kt @@ -18,4 +18,8 @@ object SecurityConstants { var jwtKey = "FatWeb" var jwtIssuer = "FatWeb" + + var redisTtl = 20L + + var redisTtlUnit = TimeUnit.MINUTES } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt index 2d26a12..63f68b4 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt @@ -2,30 +2,46 @@ package top.fatweb.api.controller.permission import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag +import jakarta.servlet.http.HttpServletRequest import jakarta.validation.Valid -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* import top.fatweb.api.annotation.ApiVersion +import top.fatweb.api.converter.UserConverter import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.entity.converter.UserConverter -import top.fatweb.api.entity.param.LoginParam +import top.fatweb.api.param.LoginParam import top.fatweb.api.service.permission.IAuthenticationService +import top.fatweb.api.util.WebUtil @Tag(name = "身份认证", description = "身份认证相关接口") @Suppress("MVCPathVariableInspection") @RequestMapping("/api/{apiVersion}") @ApiVersion(2) @RestController -class AuthenticationController(val loginService: IAuthenticationService, val userConverter: UserConverter) { +class AuthenticationController(val authenticationService: IAuthenticationService, val userConverter: UserConverter) { @Operation(summary = "登录") @PostMapping("/login") fun login(@Valid @RequestBody loginParam: LoginParam) = ResponseResult.success( ResponseCode.SYSTEM_LOGIN_SUCCESS, "Login success", - loginService.login(userConverter.loginParamToUser(loginParam)) + authenticationService.login(userConverter.loginParamToUser(loginParam)) + ) + + @Operation(summary = "登出") + @PostMapping("/logout") + fun logout(request: HttpServletRequest) = + when (authenticationService.logout(WebUtil.getToken(request))) { + true -> ResponseResult.success(ResponseCode.SYSTEM_LOGOUT_SUCCESS, "Logout success", null) + false -> ResponseResult.fail(ResponseCode.SYSTEM_LOGOUT_FAILED, "Logout failed", null) + } + + @Operation(summary = "更新 Token") + @GetMapping("/token") + fun renewToken(request: HttpServletRequest) = + ResponseResult.success( + ResponseCode.SYSTEM_TOKEN_RENEW_SUCCESS, + "Token renew success", + authenticationService.renewToken(WebUtil.getToken(request)) ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/converter/UserConverter.kt b/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt similarity index 81% rename from src/main/kotlin/top/fatweb/api/entity/converter/UserConverter.kt rename to src/main/kotlin/top/fatweb/api/converter/UserConverter.kt index 8d24463..71b980a 100644 --- a/src/main/kotlin/top/fatweb/api/entity/converter/UserConverter.kt +++ b/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.entity.converter +package top.fatweb.api.converter import org.mapstruct.Mapper import org.mapstruct.Mapping import org.mapstruct.Mappings -import top.fatweb.api.entity.param.LoginParam import top.fatweb.api.entity.permission.User +import top.fatweb.api.param.LoginParam @Mapper(componentModel = "spring") interface UserConverter { diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt b/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt index f160c2c..951d1e2 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt +++ b/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt @@ -1,9 +1,11 @@ package top.fatweb.api.entity.permission import com.fasterxml.jackson.annotation.JsonIgnore +import com.fasterxml.jackson.annotation.JsonTypeInfo import org.springframework.security.core.GrantedAuthority import org.springframework.security.core.userdetails.UserDetails +@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS) class LoginUser() : UserDetails { lateinit var user: User @@ -22,15 +24,21 @@ class LoginUser() : UserDetails { return authorities as List } + @JsonIgnore override fun getPassword(): String? = user.password + @JsonIgnore override fun getUsername(): String? = user.username + @JsonIgnore override fun isAccountNonExpired(): Boolean = true + @JsonIgnore override fun isAccountNonLocked(): Boolean = true + @JsonIgnore override fun isCredentialsNonExpired(): Boolean = true + @JsonIgnore override fun isEnabled(): Boolean = user.enable == 1 } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt b/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt index 74f6ec0..048aa39 100644 --- a/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt +++ b/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt @@ -13,7 +13,7 @@ import top.fatweb.api.entity.permission.LoginUser import top.fatweb.api.exception.TokenHasExpiredException import top.fatweb.api.util.JwtUtil import top.fatweb.api.util.RedisUtil -import java.util.concurrent.TimeUnit +import top.fatweb.api.util.WebUtil @Component class JwtAuthenticationTokenFilter(private val redisUtil: RedisUtil) : OncePerRequestFilter() { @@ -29,14 +29,14 @@ class JwtAuthenticationTokenFilter(private val redisUtil: RedisUtil) : OncePerRe return } - val token = tokenWithPrefix.removePrefix(SecurityConstants.tokenPrefix) + val token = WebUtil.getToken(tokenWithPrefix) JwtUtil.parseJwt(token) - val redisKey = "${SecurityConstants.jwtIssuer}_login:" + token.substring(0, 32) + val redisKey = "${SecurityConstants.jwtIssuer}_login:" + token val loginUser = redisUtil.getObject(redisKey) loginUser ?: let { throw TokenHasExpiredException() } - redisUtil.setExpire(redisKey, 20, TimeUnit.MINUTES) + redisUtil.setExpire(redisKey, SecurityConstants.redisTtl, SecurityConstants.redisTtlUnit) val authenticationToken = UsernamePasswordAuthenticationToken(loginUser, null, loginUser.authorities) SecurityContextHolder.getContext().authentication = authenticationToken diff --git a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt index 412c401..5e742e1 100644 --- a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt @@ -1,5 +1,7 @@ package top.fatweb.api.handler +import com.auth0.jwt.exceptions.JWTDecodeException +import com.auth0.jwt.exceptions.SignatureVerificationException import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.http.converter.HttpMessageNotReadableException @@ -11,6 +13,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.RestControllerAdvice import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult +import top.fatweb.api.exception.TokenHasExpiredException @RestControllerAdvice class ExceptionHandler { @@ -45,6 +48,16 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR, e.localizedMessage, null) } + is SignatureVerificationException, is JWTDecodeException -> { + log.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_TOKEN_ILLEGAL, "Token illegal", null) + } + + is TokenHasExpiredException -> { + log.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_TOKEN_HAS_EXPIRED, e.localizedMessage, null) + } + else -> { log.error(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_ERROR, data = null) diff --git a/src/main/kotlin/top/fatweb/api/entity/param/LoginParam.kt b/src/main/kotlin/top/fatweb/api/param/LoginParam.kt similarity index 86% rename from src/main/kotlin/top/fatweb/api/entity/param/LoginParam.kt rename to src/main/kotlin/top/fatweb/api/param/LoginParam.kt index 4ed8d0c..701ab12 100644 --- a/src/main/kotlin/top/fatweb/api/entity/param/LoginParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/LoginParam.kt @@ -1,9 +1,10 @@ -package top.fatweb.api.entity.param +package top.fatweb.api.param import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank import java.io.Serializable +@Schema(description = "登录请求参数") class LoginParam : Serializable { @Schema(description = "用户名", example = "test", required = true) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt index b58a4b6..28becfc 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt @@ -1,11 +1,13 @@ package top.fatweb.api.service.permission import top.fatweb.api.entity.permission.User +import top.fatweb.api.vo.LoginVo +import top.fatweb.api.vo.TokenVo interface IAuthenticationService { - fun login(user: User): HashMap + fun login(user: User): LoginVo fun logout(token: String): Boolean - fun renewToken(token: String): HashMap + fun renewToken(token: String): TokenVo } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index b742f3d..d08bc10 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -10,14 +10,15 @@ import top.fatweb.api.service.permission.IAuthenticationService import top.fatweb.api.util.JwtUtil import top.fatweb.api.util.RedisUtil import top.fatweb.api.util.WebUtil -import java.util.concurrent.TimeUnit +import top.fatweb.api.vo.LoginVo +import top.fatweb.api.vo.TokenVo @Service class AuthenticationServiceImpl( private val authenticationManager: AuthenticationManager, private val redisUtil: RedisUtil ) : IAuthenticationService { - override fun login(user: User): HashMap { + override fun login(user: User): LoginVo { val usernamePasswordAuthenticationToken = UsernamePasswordAuthenticationToken(user.username, user.password) val authentication = authenticationManager.authenticate(usernamePasswordAuthenticationToken) authentication ?: let { @@ -33,18 +34,17 @@ class AuthenticationServiceImpl( throw RuntimeException("Login failed") } - val hashMap = hashMapOf("token" to jwt) - val redisKey = "${SecurityConstants.jwtIssuer}_login:" + jwt.substring(0, 32) - redisUtil.setObject(redisKey, loginUser, 20, TimeUnit.MINUTES) + val redisKey = "${SecurityConstants.jwtIssuer}_login:" + jwt + redisUtil.setObject(redisKey, loginUser, SecurityConstants.redisTtl, SecurityConstants.redisTtlUnit) - return hashMap + return LoginVo(jwt) } override fun logout(token: String): Boolean = - redisUtil.delObject("${SecurityConstants.jwtIssuer}_login:" + token.substring(0, 32)) + redisUtil.delObject("${SecurityConstants.jwtIssuer}_login:" + token) - override fun renewToken(token: String): HashMap { - val oldRedisKey = "${SecurityConstants.jwtIssuer}_login:" + token.substring(0, 32) + override fun renewToken(token: String): TokenVo { + val oldRedisKey = "${SecurityConstants.jwtIssuer}_login:" + token redisUtil.delObject(oldRedisKey) val jwt = JwtUtil.createJwt(WebUtil.getLoginUserId().toString()) @@ -52,10 +52,14 @@ class AuthenticationServiceImpl( throw RuntimeException("Login failed") } - val hashMap = hashMapOf("token" to jwt) - val redisKey = "${SecurityConstants.jwtIssuer}_login:" + jwt.substring(0, 32) - redisUtil.setObject(redisKey, WebUtil.getLoginUser(), 20, TimeUnit.MINUTES) + val redisKey = "${SecurityConstants.jwtIssuer}_login:" + jwt + redisUtil.setObject( + redisKey, + WebUtil.getLoginUser(), + SecurityConstants.redisTtl, + SecurityConstants.redisTtlUnit + ) - return hashMap + return TokenVo(jwt) } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/util/WebUtil.kt b/src/main/kotlin/top/fatweb/api/util/WebUtil.kt index 892c0c6..da37681 100644 --- a/src/main/kotlin/top/fatweb/api/util/WebUtil.kt +++ b/src/main/kotlin/top/fatweb/api/util/WebUtil.kt @@ -1,10 +1,16 @@ package top.fatweb.api.util +import jakarta.servlet.http.HttpServletRequest import org.springframework.security.core.context.SecurityContextHolder +import top.fatweb.api.constant.SecurityConstants import top.fatweb.api.entity.permission.LoginUser object WebUtil { fun getLoginUser() = SecurityContextHolder.getContext().authentication.principal as LoginUser fun getLoginUserId() = getLoginUser().user.id + + fun getToken(tokenWithPrefix: String) = tokenWithPrefix.removePrefix(SecurityConstants.tokenPrefix) + + fun getToken(request: HttpServletRequest) = getToken(request.getHeader(SecurityConstants.headerString)) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/LoginVo.kt b/src/main/kotlin/top/fatweb/api/vo/LoginVo.kt new file mode 100644 index 0000000..8727d54 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/LoginVo.kt @@ -0,0 +1,11 @@ +package top.fatweb.api.vo + +import io.swagger.v3.oas.annotations.media.Schema + +@Schema(description = "登录返回参数") +data class LoginVo( + @Schema( + description = "Token", + example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYTllYjFkYmVmZDQ0OWRkOThlOGNjNzZlNzZkMDgyNSIsInN1YiI6IjE3MDk5ODYwNTg2Nzk5NzU5MzgiLCJpc3MiOiJGYXRXZWIiLCJpYXQiOjE2OTY1MjgxMTcsImV4cCI6MTY5NjUzNTMxN30.U2ZsyrGk7NbsP-DJfdz9xgWSfect5r2iKQnlEsscAA8" + ) val token: String +) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/TokenVo.kt b/src/main/kotlin/top/fatweb/api/vo/TokenVo.kt new file mode 100644 index 0000000..c17ea01 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/TokenVo.kt @@ -0,0 +1,11 @@ +package top.fatweb.api.vo + +import io.swagger.v3.oas.annotations.media.Schema + +@Schema(description = "Token") +data class TokenVo( + @Schema( + description = "Token", + example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYTllYjFkYmVmZDQ0OWRkOThlOGNjNzZlNzZkMDgyNSIsInN1YiI6IjE3MDk5ODYwNTg2Nzk5NzU5MzgiLCJpc3MiOiJGYXRXZWIiLCJpYXQiOjE2OTY1MjgxMTcsImV4cCI6MTY5NjUzNTMxN30.U2ZsyrGk7NbsP-DJfdz9xgWSfect5r2iKQnlEsscAA8" + ) val token: String +) \ No newline at end of file diff --git a/src/main/resources/application-config-template.yml b/src/main/resources/application-config-template.yml index 5280697..487ce6e 100644 --- a/src/main/resources/application-config-template.yml +++ b/src/main/resources/application-config-template.yml @@ -3,9 +3,11 @@ app: # header-string: "Authorization" # The key of head to get token # token-prefix: "Bearer " # Token prefix # jwt-ttl: 2 # The life of token -# jwt-ttl-unit: hours # Unit of life of token +# jwt-ttl-unit: hours # Unit of life of token [nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days] jwt-key: $uuid$ # Key to generate token (Only numbers and letters allow) # jwt-issuer: FatWeb # Token issuer +# redis-ttl: 20 # The life of token in redis +# redis-ttl-unit: minutes # Unit of life of token in redis [nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days] server: # port: 8080 # Server port From 243d7654e7c5082927ceb25094f5c3947154ba0c Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 6 Oct 2023 15:00:08 +0800 Subject: [PATCH 016/258] Hide ExceptionController in swagger --- .../kotlin/top/fatweb/api/controller/ExceptionController.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt b/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt index dcb7833..e5dfad2 100644 --- a/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt @@ -1,9 +1,11 @@ package top.fatweb.api.controller +import io.swagger.v3.oas.annotations.Hidden import jakarta.servlet.http.HttpServletRequest import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +@Hidden @RestController @RequestMapping("/error") class ExceptionController { From e085005f73213e922371de757a14681a417061fc Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sat, 7 Oct 2023 02:53:28 +0800 Subject: [PATCH 017/258] Remove mapstruct --- pom.xml | 33 ++++--------------- .../top/fatweb/api/converter/UserConverter.kt | 17 ++++++---- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index 81e5aad..f65cf62 100644 --- a/pom.xml +++ b/pom.xml @@ -129,13 +129,13 @@ druid-spring-boot-starter 1.2.19 - + org.apache.velocity velocity-engine-core @@ -158,16 +158,6 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 - - org.mapstruct - mapstruct - 1.5.5.Final - - - org.mapstruct - mapstruct-processor - 1.5.5.Final - @@ -181,14 +171,6 @@ org.springframework.boot spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - org.jetbrains.kotlin @@ -226,5 +208,4 @@ - diff --git a/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt b/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt index 71b980a..1bfd381 100644 --- a/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt +++ b/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt @@ -1,14 +1,17 @@ package top.fatweb.api.converter -import org.mapstruct.Mapper -import org.mapstruct.Mapping -import org.mapstruct.Mappings +import org.springframework.stereotype.Component import top.fatweb.api.entity.permission.User import top.fatweb.api.param.LoginParam -@Mapper(componentModel = "spring") -interface UserConverter { - @Mappings(Mapping(source = "username", target = "username"), Mapping(source = "password", target = "password")) - fun loginParamToUser(loginParam: LoginParam): User +@Component +object UserConverter { + fun loginParamToUser(loginParam: LoginParam): User { + val user = User().apply { + username = loginParam.username + password = loginParam.password + } + return user + } } \ No newline at end of file From 3b8069322a518a665ba27d9f952a530da10bd34d Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sat, 7 Oct 2023 02:54:04 +0800 Subject: [PATCH 018/258] Reformat code --- src/main/kotlin/top/fatweb/api/config/RedisConfig.kt | 4 +--- src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt b/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt index 75eee51..14d3ee0 100644 --- a/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt @@ -22,9 +22,7 @@ class RedisConfig { val objectMapper = ObjectMapper().registerModules(JavaTimeModule()).apply { setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY) activateDefaultTyping( - this.polymorphicTypeValidator, - ObjectMapper.DefaultTyping.NON_FINAL, - JsonTypeInfo.As.PROPERTY + this.polymorphicTypeValidator, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY ) } val anyJackson2JsonRedisSerializer = Jackson2JsonRedisSerializer(objectMapper, Any::class.java) diff --git a/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt b/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt index 9b23066..fde4588 100644 --- a/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt @@ -16,8 +16,8 @@ class SwaggerConfig { return OpenAPI().info( Info().title("FatWeb API 文档").description("FatWeb 后端 API 文档,包含各个 Controller 调用信息") .contact(contact).version( - ServerConstants.version - ) + ServerConstants.version + ) ) } } \ No newline at end of file From 723bdd4c29fb8d6b8d1e75902ce8475b5629dfca Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 8 Oct 2023 17:17:37 +0800 Subject: [PATCH 019/258] Recode unit test --- .../fatweb/api/FatWebApiApplicationTests.kt | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt index 9dc0d31..6d0c220 100644 --- a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt +++ b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt @@ -2,29 +2,33 @@ package top.fatweb.api import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test -import org.springframework.boot.test.context.SpringBootTest +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.test.context.junit.jupiter.SpringExtension import top.fatweb.api.constant.SecurityConstants +import top.fatweb.api.util.JwtUtil -@SpringBootTest +@ExtendWith(SpringExtension::class) class FatWebApiApplicationTests { - @Test - fun contextLoads() { - } - @Test fun removePrefixTest() { assertEquals("12312", "Bearer 12312".removePrefix(SecurityConstants.tokenPrefix)) } + @Test + fun jwtTest() { + val jwt = JwtUtil.createJwt("User") + assertEquals("User", jwt?.let { JwtUtil.parseJwt(it).subject }) + } + /* - @Test - fun addUser(@Autowired userService: IUserService, @Autowired passwordEncoder: PasswordEncoder) { - val username = "admin" - val rawPassword = "admin" - val encodedPassword = passwordEncoder.encode(rawPassword) - val user = User(username, encodedPassword) - userService.save(user) - } - */ + @Test + fun addUser(@Autowired userService: IUserService, @Autowired passwordEncoder: PasswordEncoder) { + val username = "admin" + val rawPassword = "admin" + val encodedPassword = passwordEncoder.encode(rawPassword) + val user = User(username, encodedPassword) + userService.save(user) + } + */ } From 82c9fcb10fb9b6cb394ccc231459e09ba287bce8 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 8 Oct 2023 23:33:59 +0800 Subject: [PATCH 020/258] Change the example config path --- .gitignore | 4 +++- .../kotlin/top/fatweb/api/FatWebApiApplication.kt | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 318632d..d65ea6e 100644 --- a/.gitignore +++ b/.gitignore @@ -31,5 +31,7 @@ build/ ### VS Code ### .vscode/ + +### Custom ### /application-config.yml -/application-config.example.yml +data diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index 1920cd3..3c635e2 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -14,12 +14,19 @@ class FatWebApiApplication fun main(args: Array) { val logger = LoggerFactory.getLogger("main") + if (!File("data").isDirectory) { + if (!File("data").mkdir()) { + logger.error("Can not create directory 'data', please try again later.") + return + } + } + if (File("application-config.yml").exists()) { runApplication(*args) } else { - logger.warn("File ‘application.yml’ cannot be found in the running path. The configuration file template 'application.example.yml' has been created. Please change the configuration file content and rename it to 'application.yml', and then restart the server.") + logger.warn("File ‘application.yml’ cannot be found in the running path. The configuration file template 'application.example.yml' has been created in directory 'data'. Please change the configuration file content, rename it to 'application.yml' and put it in the running path, and then restart the server.") FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText()?.let { - File("application-config.example.yml").writeText( + File("data/application-config.example.yml").writeText( it.replace( "\$uuid\$", UUID.randomUUID().toString().replace("-", "") ) From cfcbe8a40d051516bbea9531cfc9a50ad55cdebf Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 8 Oct 2023 23:34:19 +0800 Subject: [PATCH 021/258] Remove native-maven-plugin --- pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pom.xml b/pom.xml index f65cf62..abe9e27 100644 --- a/pom.xml +++ b/pom.xml @@ -164,10 +164,6 @@ ${project.basedir}/src/main/kotlin ${project.basedir}/src/test/kotlin - - org.graalvm.buildtools - native-maven-plugin - org.springframework.boot spring-boot-maven-plugin From 90cee680462079f6b278a41e094e981c994fd1cf Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 8 Oct 2023 23:34:34 +0800 Subject: [PATCH 022/258] Add docker builder --- Dockerfile | 12 ++++++++++++ build-docker.sh | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100644 Dockerfile create mode 100644 build-docker.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..332d586 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM eclipse-temurin:17-jdk-alpine +LABEL authors="FatttSnake" + +VOLUME /data + +ARG DEPENDENCY=target/extracted +COPY ${EXTRACTED}/dependencies/ / +COPY ${EXTRACTED}/spring-boot-loader/ / +COPY ${EXTRACTED}/snapshot-dependencies/ / +COPY ${EXTRACTED}/application/ / + +ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher", "${JAVA_OPTS}"] \ No newline at end of file diff --git a/build-docker.sh b/build-docker.sh new file mode 100644 index 0000000..6b42feb --- /dev/null +++ b/build-docker.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +JAR_NAME=`ls target | grep api-|grep -v original` +JAR_VERSION=${JAR_NAME%.*} +JAR_VERSION=${JAR_VERSION#*-} + +mkdir target/extracted +java -Djarmode=layertools -jar target/*.jar extract --destination target/extracted +docker build -t hub.fatweb.top/fatweb-api:latest -t hub.fatweb.top/fatweb-api:$JAR_VERSION -t hub.fatweb.top/fatweb-api:$JAR_VERSION-$(date "+%Y%m%d%H%M%S") . \ No newline at end of file From 477e11fb47a9a18b6d2b6c543f587204c51a77b4 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 9 Oct 2023 00:16:18 +0800 Subject: [PATCH 023/258] Fix Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 332d586..f50582a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ LABEL authors="FatttSnake" VOLUME /data -ARG DEPENDENCY=target/extracted +ARG EXTRACTED=target/extracted COPY ${EXTRACTED}/dependencies/ / COPY ${EXTRACTED}/spring-boot-loader/ / COPY ${EXTRACTED}/snapshot-dependencies/ / From 6a474492598a6a63633019eb0924e1048aa62fab Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 9 Oct 2023 00:25:18 +0800 Subject: [PATCH 024/258] Fix Dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index f50582a..957b824 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ ARG EXTRACTED=target/extracted COPY ${EXTRACTED}/dependencies/ / COPY ${EXTRACTED}/spring-boot-loader/ / COPY ${EXTRACTED}/snapshot-dependencies/ / +RUN true COPY ${EXTRACTED}/application/ / ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher", "${JAVA_OPTS}"] \ No newline at end of file From 46cb0afaaa795e52e98e5a605ced23fd734e5b89 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 9 Oct 2023 11:02:24 +0800 Subject: [PATCH 025/258] Run docker test --- run-docker.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 run-docker.sh diff --git a/run-docker.sh b/run-docker.sh new file mode 100644 index 0000000..8c4887a --- /dev/null +++ b/run-docker.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo ${KEYS_PATH} \ No newline at end of file From bb30e9add09eb0454906d203fefea9f4a5317bcd Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 9 Oct 2023 11:30:35 +0800 Subject: [PATCH 026/258] Rename run-docker.sh to push-docker.sh --- run-docker.sh => push-docker.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename run-docker.sh => push-docker.sh (100%) diff --git a/run-docker.sh b/push-docker.sh similarity index 100% rename from run-docker.sh rename to push-docker.sh From fad06ac96bf09fcd0d29961cac2dd5d5db7eb9e4 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 9 Oct 2023 11:46:58 +0800 Subject: [PATCH 027/258] Update build-docker.sh --- build-docker.sh | 7 ++++++- push-docker.sh | 3 --- 2 files changed, 6 insertions(+), 4 deletions(-) delete mode 100644 push-docker.sh diff --git a/build-docker.sh b/build-docker.sh index 6b42feb..64321b9 100644 --- a/build-docker.sh +++ b/build-docker.sh @@ -3,7 +3,12 @@ JAR_NAME=`ls target | grep api-|grep -v original` JAR_VERSION=${JAR_NAME%.*} JAR_VERSION=${JAR_VERSION#*-} +BUILD_TIME=$(date "+%Y%m%d%H%M%S") mkdir target/extracted java -Djarmode=layertools -jar target/*.jar extract --destination target/extracted -docker build -t hub.fatweb.top/fatweb-api:latest -t hub.fatweb.top/fatweb-api:$JAR_VERSION -t hub.fatweb.top/fatweb-api:$JAR_VERSION-$(date "+%Y%m%d%H%M%S") . \ No newline at end of file +docker build -t hub.fatweb.top/fatweb-api:latest -t hub.fatweb.top/fatweb-api:$JAR_VERSION -t hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} . +cat "${KEYS_PATH}/docker.password" | docker login hub.fatweb.top -u jenkins --password-stdin +docker push hub.fatweb.top/fatweb-api:latest +docker push hub.fatweb.top/fatweb-api:$JAR_VERSION +docker push hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} \ No newline at end of file diff --git a/push-docker.sh b/push-docker.sh deleted file mode 100644 index 8c4887a..0000000 --- a/push-docker.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -echo ${KEYS_PATH} \ No newline at end of file From 445b1f6c7408436759d9b887c06df6a624245a55 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 9 Oct 2023 13:52:09 +0800 Subject: [PATCH 028/258] Update build-docker.sh: add snapshot judgment --- build-docker.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/build-docker.sh b/build-docker.sh index 64321b9..3839b82 100644 --- a/build-docker.sh +++ b/build-docker.sh @@ -7,8 +7,18 @@ BUILD_TIME=$(date "+%Y%m%d%H%M%S") mkdir target/extracted java -Djarmode=layertools -jar target/*.jar extract --destination target/extracted -docker build -t hub.fatweb.top/fatweb-api:latest -t hub.fatweb.top/fatweb-api:$JAR_VERSION -t hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} . -cat "${KEYS_PATH}/docker.password" | docker login hub.fatweb.top -u jenkins --password-stdin -docker push hub.fatweb.top/fatweb-api:latest -docker push hub.fatweb.top/fatweb-api:$JAR_VERSION -docker push hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} \ No newline at end of file + +if [[ "${JAR_VERSION}" =~ ^.*SNAPSHOT$ ]] +then + docker build -t hub.fatweb.top/fatweb-api:snapshot-latest -t hub.fatweb.top/fatweb-api:$JAR_VERSION -t hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} . + cat "${KEYS_PATH}/docker.password" | docker login hub.fatweb.top -u jenkins --password-stdin + docker push hub.fatweb.top/fatweb-api:snapshot-latest + docker push hub.fatweb.top/fatweb-api:$JAR_VERSION + docker push hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} +else + docker build -t hub.fatweb.top/fatweb-api:latest -t hub.fatweb.top/fatweb-api:$JAR_VERSION -t hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} . + cat "${KEYS_PATH}/docker.password" | docker login hub.fatweb.top -u jenkins --password-stdin + docker push hub.fatweb.top/fatweb-api:latest + docker push hub.fatweb.top/fatweb-api:$JAR_VERSION + docker push hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} +fi \ No newline at end of file From 6de3f02171d57a7f41448f6e154cd7625f02d632 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 9 Oct 2023 16:52:57 +0800 Subject: [PATCH 029/258] Optimize profiles path in docker --- Dockerfile | 2 +- src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 957b824..5f96fac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ COPY ${EXTRACTED}/snapshot-dependencies/ / RUN true COPY ${EXTRACTED}/application/ / -ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher", "${JAVA_OPTS}"] \ No newline at end of file +ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher", "--spring.config.additional-location=file:data/", "${JAVA_OPTS}"] \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index 3c635e2..a2d2e01 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -21,10 +21,10 @@ fun main(args: Array) { } } - if (File("application-config.yml").exists()) { + if (File("application-config.yml").exists() || File("data/application-config.yml").exists()) { runApplication(*args) } else { - logger.warn("File ‘application.yml’ cannot be found in the running path. The configuration file template 'application.example.yml' has been created in directory 'data'. Please change the configuration file content, rename it to 'application.yml' and put it in the running path, and then restart the server.") + logger.warn("File ‘application.yml’ cannot be found in the running path. The configuration file template 'application.example.yml' has been created in directory 'data'. Please change the configuration file content, rename it to 'application.yml', and then restart the server.") FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText()?.let { File("data/application-config.example.yml").writeText( it.replace( From 4ac8711267b68a7f8b314022dfa56caba362ddc6 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 9 Oct 2023 18:16:41 +0800 Subject: [PATCH 030/258] Remove ${JAVA_OPTS} in Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5f96fac..2dca17c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,4 @@ COPY ${EXTRACTED}/snapshot-dependencies/ / RUN true COPY ${EXTRACTED}/application/ / -ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher", "--spring.config.additional-location=file:data/", "${JAVA_OPTS}"] \ No newline at end of file +ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher", "--spring.config.additional-location=file:data/"] \ No newline at end of file From 88341b50fd63573b98366458477c10610bc1da48 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 9 Oct 2023 18:17:06 +0800 Subject: [PATCH 031/258] Optimized username not found message --- src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt index 5e742e1..c4abedb 100644 --- a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt @@ -40,7 +40,7 @@ class ExceptionHandler { is InternalAuthenticationServiceException -> { log.debug(e.localizedMessage, e) - ResponseResult.fail(ResponseCode.SYSTEM_USERNAME_NOT_FOUND, e.localizedMessage, null) + ResponseResult.fail(ResponseCode.SYSTEM_USERNAME_NOT_FOUND, "Username not found", null) } is BadCredentialsException -> { From b34b7cd9e0b5c4ba2bae3db7b7f868de261173cf Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 10 Oct 2023 14:48:38 +0800 Subject: [PATCH 032/258] Remove add user test --- .../top/fatweb/api/FatWebApiApplicationTests.kt | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt index 6d0c220..5ed443f 100644 --- a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt +++ b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt @@ -20,15 +20,4 @@ class FatWebApiApplicationTests { val jwt = JwtUtil.createJwt("User") assertEquals("User", jwt?.let { JwtUtil.parseJwt(it).subject }) } - - /* - @Test - fun addUser(@Autowired userService: IUserService, @Autowired passwordEncoder: PasswordEncoder) { - val username = "admin" - val rawPassword = "admin" - val encodedPassword = passwordEncoder.encode(rawPassword) - val user = User(username, encodedPassword) - userService.save(user) - } - */ } From b1044b8beb2d4db1ef5eb9a3743d99e4524cdc23 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 10 Oct 2023 15:45:04 +0800 Subject: [PATCH 033/258] Change authentication request path --- src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt | 2 +- .../api/controller/permission/AuthenticationController.kt | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt b/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt index 5836f3d..4ab79bc 100644 --- a/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt @@ -58,7 +58,7 @@ class SecurityConfig( authorizeHttpRequests // Allow anonymous access .requestMatchers( - "/api/v*/login", + "/login", "/error/thrown", "/doc.html", "/swagger-ui/**", diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt index 63f68b4..2dd6960 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt @@ -14,8 +14,6 @@ import top.fatweb.api.service.permission.IAuthenticationService import top.fatweb.api.util.WebUtil @Tag(name = "身份认证", description = "身份认证相关接口") -@Suppress("MVCPathVariableInspection") -@RequestMapping("/api/{apiVersion}") @ApiVersion(2) @RestController class AuthenticationController(val authenticationService: IAuthenticationService, val userConverter: UserConverter) { From f6a7303fbaeee922e7257df0f7e5bd7456cd1345 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 10 Oct 2023 16:06:11 +0800 Subject: [PATCH 034/258] Add token has expired exception handler --- src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt index c4abedb..e4b41e0 100644 --- a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt @@ -2,6 +2,7 @@ package top.fatweb.api.handler import com.auth0.jwt.exceptions.JWTDecodeException import com.auth0.jwt.exceptions.SignatureVerificationException +import com.auth0.jwt.exceptions.TokenExpiredException import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.http.converter.HttpMessageNotReadableException @@ -32,6 +33,11 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage.split(":")[0], null) } + is TokenExpiredException -> { + log.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_TOKEN_HAS_EXPIRED, e.localizedMessage, null) + } + is MethodArgumentNotValidException -> { log.debug(e.localizedMessage, e) val errorMessage = e.allErrors.map { error -> error.defaultMessage }.joinToString(". ") From 1a3ae518dc7589941e2fec9ce5a13e67e70bdb18 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sat, 14 Oct 2023 20:41:12 +0800 Subject: [PATCH 035/258] Optimize log in FatWebApiApplication --- src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index a2d2e01..485fead 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -24,7 +24,7 @@ fun main(args: Array) { if (File("application-config.yml").exists() || File("data/application-config.yml").exists()) { runApplication(*args) } else { - logger.warn("File ‘application.yml’ cannot be found in the running path. The configuration file template 'application.example.yml' has been created in directory 'data'. Please change the configuration file content, rename it to 'application.yml', and then restart the server.") + logger.warn("File 'application.yml' cannot be found in data path. The configuration file template 'application.example.yml' has been created in directory 'data'. Please change the configuration file content, rename it to 'application.yml', and then restart the server.") FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText()?.let { File("data/application-config.example.yml").writeText( it.replace( From a3f02b130581b68f0017caaad5a37944e687c0af Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 15 Oct 2023 16:15:23 +0800 Subject: [PATCH 036/258] Add logging setting --- src/main/resources/application-config-template.yml | 12 +++++++++++- src/main/resources/application.yml | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application-config-template.yml b/src/main/resources/application-config-template.yml index 487ce6e..d160f35 100644 --- a/src/main/resources/application-config-template.yml +++ b/src/main/resources/application-config-template.yml @@ -40,4 +40,14 @@ spring: # min-idle: 0 # max-idle: 8 # max-active: 8 -# max-wait: -1ms \ No newline at end of file +# max-wait: -1ms + +logging: + level: + root: info # Logging level + file: + name: data/log/fat-api.log # Logging path and name + logback: + rollingpolicy: +# max-file-size: 10MB # Maximum log file size +# max-history: 7 # Maximum number of archive log files to keep \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index cec8de8..6c1d655 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,6 +8,7 @@ spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver + mybatis-plus: global-config: db-config: @@ -16,3 +17,9 @@ mybatis-plus: logic-delete-value: id id-type: assign_id type-aliases-package: top.fatweb.api.entity + +logging: + level: + root: info + file: + name: data/log/fat-api.log From 42c4a90f87cd2d71e36f845f6c5eabf1368dfde4 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 16 Oct 2023 15:32:31 +0800 Subject: [PATCH 037/258] Rename logger --- .../fatweb/api/handler/ExceptionHandler.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt index e4b41e0..585f04b 100644 --- a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt @@ -18,54 +18,54 @@ import top.fatweb.api.exception.TokenHasExpiredException @RestControllerAdvice class ExceptionHandler { - private val log: Logger = LoggerFactory.getLogger(this::class.java) + private val logger: Logger = LoggerFactory.getLogger(this::class.java) @ExceptionHandler(value = [Exception::class]) fun exceptionHandler(e: Exception): ResponseResult<*> { return when (e) { is InsufficientAuthenticationException -> { - log.debug(e.localizedMessage, e) + logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_UNAUTHORIZED, e.localizedMessage, null) } is HttpMessageNotReadableException -> { - log.debug(e.localizedMessage, e) + logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage.split(":")[0], null) } is TokenExpiredException -> { - log.debug(e.localizedMessage, e) + logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_TOKEN_HAS_EXPIRED, e.localizedMessage, null) } is MethodArgumentNotValidException -> { - log.debug(e.localizedMessage, e) + logger.debug(e.localizedMessage, e) val errorMessage = e.allErrors.map { error -> error.defaultMessage }.joinToString(". ") ResponseResult.fail(ResponseCode.SYSTEM_ARGUMENT_NOT_VALID, errorMessage, null) } is InternalAuthenticationServiceException -> { - log.debug(e.localizedMessage, e) + logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_USERNAME_NOT_FOUND, "Username not found", null) } is BadCredentialsException -> { - log.debug(e.localizedMessage, e) + logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR, e.localizedMessage, null) } is SignatureVerificationException, is JWTDecodeException -> { - log.debug(e.localizedMessage, e) + logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_TOKEN_ILLEGAL, "Token illegal", null) } is TokenHasExpiredException -> { - log.debug(e.localizedMessage, e) + logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_TOKEN_HAS_EXPIRED, e.localizedMessage, null) } else -> { - log.error(e.localizedMessage, e) + logger.error(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_ERROR, data = null) } } From 1fcd468581360611b518b553b1f4233e5e295d99 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 16 Oct 2023 15:32:45 +0800 Subject: [PATCH 038/258] optimize code --- src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt b/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt index 4ab79bc..017f2d4 100644 --- a/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt @@ -58,14 +58,14 @@ class SecurityConfig( authorizeHttpRequests // Allow anonymous access .requestMatchers( - "/login", "/error/thrown", "/doc.html", "/swagger-ui/**", "/webjars/**", "/v3/**", "/swagger-ui.html", - "/favicon.ico" + "/favicon.ico", + "/login", ).anonymous() // Authentication required .anyRequest().authenticated() From 8e3ceb16c1524addc7d2ad3003b4ce583a5f2085 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 16 Oct 2023 17:35:34 +0800 Subject: [PATCH 039/258] Add login IP record --- db/schema.sql | 23 ++++++--- .../permission/AuthenticationController.kt | 9 ++-- .../fatweb/api/entity/permission/LoginUser.kt | 16 +++--- .../top/fatweb/api/entity/permission/User.kt | 50 +++++++++++++++++-- .../permission/IAuthenticationService.kt | 3 +- .../impl/AuthenticationServiceImpl.kt | 20 +++++++- .../fatweb/api/FatWebApiApplicationTests.kt | 11 ++++ 7 files changed, 110 insertions(+), 22 deletions(-) diff --git a/db/schema.sql b/db/schema.sql index a1140fd..f75257c 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -2,11 +2,20 @@ drop table if exists t_user; create table if not exists t_user ( - id bigint not null primary key, - username varchar(20) not null comment '用户名', - password char(70) not null comment '密码', - enable int not null comment '启用', - deleted bigint not null default 0, - version int not null default 0, + id bigint not null primary key, + username varchar(20) not null comment '用户名', + password char(70) not null comment '密码', + locking int not null comment '锁定', + expiration datetime comment '过期时间', + credentials_expiration datetime comment '认证过期时间', + enable int not null comment '启用', + last_login_time datetime comment '上次登录时间', + last_login_ip varchar(128) comment '上次登录 IP', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, constraint t_user_unique unique (username, deleted) -) comment '用户'; +) comment '用户表'; + +insert into t_user (id, username, password, locking, enable) value (0, 'admin', '$2a$10$3wDGdzTZlC..7eY6u2XM5u78xUQo0z5Sj5yOpneD4QJ0q/TA5TY0S', 0, 1) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt index 2dd6960..2f04f9e 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt @@ -4,7 +4,10 @@ import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import jakarta.servlet.http.HttpServletRequest import jakarta.validation.Valid -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RestController import top.fatweb.api.annotation.ApiVersion import top.fatweb.api.converter.UserConverter import top.fatweb.api.entity.common.ResponseCode @@ -19,11 +22,11 @@ import top.fatweb.api.util.WebUtil class AuthenticationController(val authenticationService: IAuthenticationService, val userConverter: UserConverter) { @Operation(summary = "登录") @PostMapping("/login") - fun login(@Valid @RequestBody loginParam: LoginParam) = + fun login(request: HttpServletRequest, @Valid @RequestBody loginParam: LoginParam) = ResponseResult.success( ResponseCode.SYSTEM_LOGIN_SUCCESS, "Login success", - authenticationService.login(userConverter.loginParamToUser(loginParam)) + authenticationService.login(request, userConverter.loginParamToUser(loginParam)) ) @Operation(summary = "登出") diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt b/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt index 951d1e2..84837d7 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt +++ b/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonTypeInfo import org.springframework.security.core.GrantedAuthority import org.springframework.security.core.userdetails.UserDetails +import java.time.LocalDateTime +import java.time.ZoneOffset @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS) class LoginUser() : UserDetails { @@ -25,20 +27,22 @@ class LoginUser() : UserDetails { } @JsonIgnore - override fun getPassword(): String? = user.password + override fun getPassword() = user.password @JsonIgnore - override fun getUsername(): String? = user.username + override fun getUsername() = user.username @JsonIgnore - override fun isAccountNonExpired(): Boolean = true + override fun isAccountNonExpired() = + user.expiration == null || user.expiration!!.isAfter(LocalDateTime.now(ZoneOffset.UTC)) @JsonIgnore - override fun isAccountNonLocked(): Boolean = true + override fun isAccountNonLocked() = user.locking == 0 @JsonIgnore - override fun isCredentialsNonExpired(): Boolean = true + override fun isCredentialsNonExpired() = + user.credentialsExpiration == null || user.credentialsExpiration!!.isAfter(LocalDateTime.now(ZoneOffset.UTC)) @JsonIgnore - override fun isEnabled(): Boolean = user.enable == 1 + override fun isEnabled() = user.enable == 1 } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/User.kt b/src/main/kotlin/top/fatweb/api/entity/permission/User.kt index bff63ab..8277f73 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/User.kt +++ b/src/main/kotlin/top/fatweb/api/entity/permission/User.kt @@ -2,10 +2,11 @@ package top.fatweb.api.entity.permission import com.baomidou.mybatisplus.annotation.* import java.io.Serializable +import java.time.LocalDateTime /** *

- * 用户 + * 用户表 *

* * @author FatttSnake @@ -13,7 +14,8 @@ import java.io.Serializable */ @TableName("t_user") class User() : Serializable { - constructor(username: String, password: String, enable: Boolean = true) : this() { + constructor(id: Long?, username: String, password: String, enable: Boolean = true) : this() { + this.id = id this.username = username this.password = password this.enable = if (enable) 1 else 0 @@ -34,12 +36,54 @@ class User() : Serializable { @TableField("password") var password: String? = null + /** + * 锁定 + */ + @TableField("locking") + var locking: Int? = null + + /** + * 过期时间 + */ + @TableField("expiration") + var expiration: LocalDateTime? = null + + /** + * 认证过期时间 + */ + @TableField("credentials_expiration") + var credentialsExpiration: LocalDateTime? = null + /** * 启用 */ @TableField("enable") var enable: Int? = null + /** + * 上次登录时间 + */ + @TableField("last_login_time") + var lastLoginTime: LocalDateTime? = null + + /** + * 上次登录 IP + */ + @TableField("last_login_ip") + var lastLoginIp: String? = null + + /** + * 创建时间 + */ + @TableField("create_time") + var createTime: LocalDateTime? = null + + /** + * 修改时间 + */ + @TableField("update_time") + var updateTime: LocalDateTime? = null + @TableField("deleted") @TableLogic var deleted: Long? = null @@ -49,6 +93,6 @@ class User() : Serializable { var version: Int? = null override fun toString(): String { - return "User{id=$id, username=$username, password=$password, enable=$enable, deleted=$deleted, version=$version}" + return "User(id=$id, username=$username, password=$password, locking=$locking, expiration=$expiration, credentialsExpiration=$credentialsExpiration, enable=$enable, lastLoginTime=$lastLoginTime, lastLoginIp=$lastLoginIp, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)" } } diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt index 28becfc..5704e7d 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt @@ -1,11 +1,12 @@ package top.fatweb.api.service.permission +import jakarta.servlet.http.HttpServletRequest import top.fatweb.api.entity.permission.User import top.fatweb.api.vo.LoginVo import top.fatweb.api.vo.TokenVo interface IAuthenticationService { - fun login(user: User): LoginVo + fun login(request: HttpServletRequest, user: User): LoginVo fun logout(token: String): Boolean diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index d08bc10..6a173e3 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -1,30 +1,46 @@ package top.fatweb.api.service.permission.impl +import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper +import jakarta.servlet.http.HttpServletRequest +import org.slf4j.Logger +import org.slf4j.LoggerFactory import org.springframework.security.authentication.AuthenticationManager import org.springframework.security.authentication.UsernamePasswordAuthenticationToken import org.springframework.stereotype.Service import top.fatweb.api.constant.SecurityConstants import top.fatweb.api.entity.permission.LoginUser import top.fatweb.api.entity.permission.User +import top.fatweb.api.service.IUserService import top.fatweb.api.service.permission.IAuthenticationService import top.fatweb.api.util.JwtUtil import top.fatweb.api.util.RedisUtil import top.fatweb.api.util.WebUtil import top.fatweb.api.vo.LoginVo import top.fatweb.api.vo.TokenVo +import java.time.LocalDateTime +import java.time.ZoneOffset @Service class AuthenticationServiceImpl( private val authenticationManager: AuthenticationManager, - private val redisUtil: RedisUtil + private val redisUtil: RedisUtil, + private val userService: IUserService ) : IAuthenticationService { - override fun login(user: User): LoginVo { + private val logger: Logger = LoggerFactory.getLogger(this::class.java) + + override fun login(request: HttpServletRequest, user: User): LoginVo { val usernamePasswordAuthenticationToken = UsernamePasswordAuthenticationToken(user.username, user.password) val authentication = authenticationManager.authenticate(usernamePasswordAuthenticationToken) authentication ?: let { throw RuntimeException("Login failed") } + logger.info("用户登录 [用户名: '{}', IP: '{}']", user.username, request.remoteAddr) + userService.update(User().apply { + lastLoginIp = request.remoteAddr + lastLoginTime = LocalDateTime.now(ZoneOffset.UTC) + }, KtUpdateWrapper(User()).eq(User::username, user.username)) + val loginUser = authentication.principal as LoginUser loginUser.user.password = "" val userId = loginUser.user.id.toString() diff --git a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt index 5ed443f..c73504e 100644 --- a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt +++ b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt @@ -3,12 +3,15 @@ package top.fatweb.api import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import org.slf4j.Logger +import org.slf4j.LoggerFactory import org.springframework.test.context.junit.jupiter.SpringExtension import top.fatweb.api.constant.SecurityConstants import top.fatweb.api.util.JwtUtil @ExtendWith(SpringExtension::class) class FatWebApiApplicationTests { + private val logger: Logger = LoggerFactory.getLogger(this::class.java) @Test fun removePrefixTest() { @@ -20,4 +23,12 @@ class FatWebApiApplicationTests { val jwt = JwtUtil.createJwt("User") assertEquals("User", jwt?.let { JwtUtil.parseJwt(it).subject }) } + + /* + @Test + fun generatePassword() { + val passwordEncoder = BCryptPasswordEncoder() + logger.info(passwordEncoder.encode("admin@dev")) + } + */ } From 10047213bdd7258e78e97e1b19ffc68d106cdd26 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 16 Oct 2023 18:17:50 +0800 Subject: [PATCH 040/258] Add global data format --- .../top/fatweb/api/config/DataFormatConfig.kt | 45 +++++++++++++++++++ src/main/resources/application.yml | 3 ++ 2 files changed, 48 insertions(+) create mode 100644 src/main/kotlin/top/fatweb/api/config/DataFormatConfig.kt diff --git a/src/main/kotlin/top/fatweb/api/config/DataFormatConfig.kt b/src/main/kotlin/top/fatweb/api/config/DataFormatConfig.kt new file mode 100644 index 0000000..eaa73a7 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/config/DataFormatConfig.kt @@ -0,0 +1,45 @@ +package top.fatweb.api.config + +import com.fasterxml.jackson.databind.SerializationFeature +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer +import org.springframework.boot.jackson.JsonComponent +import org.springframework.context.annotation.Bean +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder +import java.text.DateFormat +import java.text.SimpleDateFormat +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter +import java.util.* + + +@JsonComponent +class DataFormatConfig { + @set:Value("\${spring.jackson.date-format}") + lateinit var dataFormat: String + + @set:Value("\${spring.jackson.time-zone}}") + lateinit var timeZone: TimeZone + + @Bean + fun jackson2ObjectMapperBuilder() = Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder -> + val tz = timeZone + val df: DateFormat = SimpleDateFormat(dataFormat) + df.timeZone = tz + builder.failOnEmptyBeans(false) + .failOnUnknownProperties(false) + .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .dateFormat(df) + } + + + @Bean + fun jackson2ObjectMapperBuilderCustomizer() = + Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder -> + builder.serializerByType( + LocalDateTime::class.java, LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dataFormat)) + ) + } + +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6c1d655..897ad44 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,6 +8,9 @@ spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver + jackson: + date-format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' + time-zone: GMT mybatis-plus: global-config: From 602683fee2be35cec6b49a680513f6dcda675963 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 16 Oct 2023 18:18:20 +0800 Subject: [PATCH 041/258] Add login time and login ip to LoginVo --- .../permission/impl/AuthenticationServiceImpl.kt | 2 +- src/main/kotlin/top/fatweb/api/vo/LoginVo.kt | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index 6a173e3..cc669c0 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -53,7 +53,7 @@ class AuthenticationServiceImpl( val redisKey = "${SecurityConstants.jwtIssuer}_login:" + jwt redisUtil.setObject(redisKey, loginUser, SecurityConstants.redisTtl, SecurityConstants.redisTtlUnit) - return LoginVo(jwt) + return LoginVo(jwt, loginUser.user.lastLoginTime, loginUser.user.lastLoginIp) } override fun logout(token: String): Boolean = diff --git a/src/main/kotlin/top/fatweb/api/vo/LoginVo.kt b/src/main/kotlin/top/fatweb/api/vo/LoginVo.kt index 8727d54..f3e76cc 100644 --- a/src/main/kotlin/top/fatweb/api/vo/LoginVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/LoginVo.kt @@ -1,11 +1,22 @@ package top.fatweb.api.vo import io.swagger.v3.oas.annotations.media.Schema +import java.time.LocalDateTime @Schema(description = "登录返回参数") data class LoginVo( @Schema( description = "Token", example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYTllYjFkYmVmZDQ0OWRkOThlOGNjNzZlNzZkMDgyNSIsInN1YiI6IjE3MDk5ODYwNTg2Nzk5NzU5MzgiLCJpc3MiOiJGYXRXZWIiLCJpYXQiOjE2OTY1MjgxMTcsImV4cCI6MTY5NjUzNTMxN30.U2ZsyrGk7NbsP-DJfdz9xgWSfect5r2iKQnlEsscAA8" - ) val token: String + ) val token: String, + + @Schema( + description = "上次登录时间", + example = "1900-01-01 00:00:00" + ) val lastLoginTime: LocalDateTime?, + + @Schema( + description = "上次登录 IP", + example = "10.0.0.1" + ) val lastLoginIp: String? ) \ No newline at end of file From 047178d70da376e281c62299805ea23782a2f601 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 17 Oct 2023 18:33:46 +0800 Subject: [PATCH 042/258] Add HttpRequestMethodNotSupportedException catch --- src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt index 585f04b..98c0bbf 100644 --- a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt @@ -9,6 +9,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException import org.springframework.security.authentication.BadCredentialsException import org.springframework.security.authentication.InsufficientAuthenticationException import org.springframework.security.authentication.InternalAuthenticationServiceException +import org.springframework.web.HttpRequestMethodNotSupportedException import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.RestControllerAdvice @@ -28,6 +29,11 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.SYSTEM_UNAUTHORIZED, e.localizedMessage, null) } + is HttpRequestMethodNotSupportedException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage, null) + } + is HttpMessageNotReadableException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage.split(":")[0], null) From 0efbdde2a79d9276c1f1344758f245fc46a6c70d Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 18 Oct 2023 01:47:05 +0800 Subject: [PATCH 043/258] Add ByteUtil --- .../kotlin/top/fatweb/api/util/ByteUtil.kt | 76 +++++++++++++++++++ .../fatweb/api/FatWebApiApplicationTests.kt | 8 ++ 2 files changed, 84 insertions(+) create mode 100644 src/main/kotlin/top/fatweb/api/util/ByteUtil.kt diff --git a/src/main/kotlin/top/fatweb/api/util/ByteUtil.kt b/src/main/kotlin/top/fatweb/api/util/ByteUtil.kt new file mode 100644 index 0000000..d8dbfef --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/util/ByteUtil.kt @@ -0,0 +1,76 @@ +package top.fatweb.api.util + +import kotlin.math.floor + +object ByteUtil { + private const val BASE = 1024 + + enum class ByteUnit { + B, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB + } + + fun formatByteSize(byteSize: Long): String { + if (byteSize <= -1) { + return byteSize.toString() + } + + var size = byteSize.toDouble() + if (floor(size / BASE) <= 0) { + return format(size, ByteUnit.B) + } + + size /= BASE + if (floor(size / BASE) <= 0) { + return format(size, ByteUnit.KiB) + } + + size /= BASE + if (floor(size / BASE) <= 0) { + return format(size, ByteUnit.MiB) + } + + size /= BASE + if (floor(size / BASE) <= 0) { + return format(size, ByteUnit.GiB) + } + + size /= BASE + if (floor(size / BASE) <= 0) { + return format(size, ByteUnit.TiB) + } + + size /= BASE + if (floor(size / BASE) <= 0) { + return format(size, ByteUnit.PiB) + } + + size /= BASE + if (floor(size / BASE) <= 0) { + return format(size, ByteUnit.EiB) + } + + size /= BASE + if (floor(size / BASE) <= 0) { + return format(size, ByteUnit.ZiB) + } + + size /= BASE + return format(size, ByteUnit.YiB) + } + + fun format(size: Double, unit: ByteUnit): String { + val precision = if (size * 1000 % 10 > 0) { + 3 + } else if (size * 100 % 10 > 0) { + 2 + } else if (size * 10 % 10 > 0) { + 1 + } else { + 0 + } + + val formatStr = "%.${precision}f" + + return String.format(formatStr, size) + unit.name + } +} \ No newline at end of file diff --git a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt index c73504e..5e4302b 100644 --- a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt +++ b/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt @@ -7,6 +7,7 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.test.context.junit.jupiter.SpringExtension import top.fatweb.api.constant.SecurityConstants +import top.fatweb.api.util.ByteUtil import top.fatweb.api.util.JwtUtil @ExtendWith(SpringExtension::class) @@ -31,4 +32,11 @@ class FatWebApiApplicationTests { logger.info(passwordEncoder.encode("admin@dev")) } */ + + @Test + fun byteUtilTest() { + assertEquals("512B", ByteUtil.formatByteSize(512)) + assertEquals("512KiB", ByteUtil.formatByteSize(512 * 1024)) + assertEquals("1.5MiB", ByteUtil.formatByteSize(1 * 1024 * 1024 + 512 * 1024)) + } } From 63daa8d8015e7ab8c997b4d7bef76de7048a1a30 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 18 Oct 2023 01:47:42 +0800 Subject: [PATCH 044/258] Add SysLog --- db/schema.sql | 31 ++++- .../fatweb/api/controller/SysLogController.kt | 17 +++ .../kotlin/top/fatweb/api/entity/SysLog.kt | 122 ++++++++++++++++++ .../top/fatweb/api/mapper/SysLogMapper.kt | 16 +++ .../top/fatweb/api/service/ISysLogService.kt | 14 ++ .../api/service/impl/SysLogServiceImpl.kt | 18 +++ src/main/resources/mapper/SysLogMapper.xml | 5 + 7 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/top/fatweb/api/controller/SysLogController.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/SysLog.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/SysLogMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/ISysLogService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/impl/SysLogServiceImpl.kt create mode 100644 src/main/resources/mapper/SysLogMapper.xml diff --git a/db/schema.sql b/db/schema.sql index f75257c..73ff84c 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -18,4 +18,33 @@ create table if not exists t_user constraint t_user_unique unique (username, deleted) ) comment '用户表'; -insert into t_user (id, username, password, locking, enable) value (0, 'admin', '$2a$10$3wDGdzTZlC..7eY6u2XM5u78xUQo0z5Sj5yOpneD4QJ0q/TA5TY0S', 0, 1) \ No newline at end of file +insert into t_user (id, username, password, locking, enable) value (0, 'admin', + '$2a$10$3wDGdzTZlC..7eY6u2XM5u78xUQo0z5Sj5yOpneD4QJ0q/TA5TY0S', + 0, 1); + +drop table if exists t_sys_log; +create table t_sys_log +( + id bigint not null, + log_type varchar(50) not null comment '日志类型', + operate_user_id bigint not null comment '操作用户', + operate_time datetime not null default (utc_timestamp()) comment '操作时间', + request_uri varchar(500) default null comment '请求 URI', + request_method varchar(10) default null comment '请求方式', + request_params text comment '请求参数', + request_ip varchar(20) not null comment '请求 IP', + request_server_address varchar(50) not null comment '请求服务器地址', + is_exception char(1) default null comment '是否异常', + exception_info text comment '异常信息', + start_time datetime not null comment '开始时间', + end_time datetime not null comment '结束时间', + execute_time int default null comment '执行时间', + user_agent varchar(500) default null comment '用户代理', + device_name varchar(100) default null comment '操作系统', + browser_name varchar(100) default null comment '浏览器名称', + primary key (id) using btree, + key idx_sys_log_log_type (log_type) using btree, + key idx_sys_log_operate_user_id (operate_user_id) using btree, + key idx_sys_log_is_exception (is_exception) using btree, + key idx_sys_log_operate_time (operate_time) using btree +) comment '系统日志表'; \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/controller/SysLogController.kt b/src/main/kotlin/top/fatweb/api/controller/SysLogController.kt new file mode 100644 index 0000000..9d58d09 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/controller/SysLogController.kt @@ -0,0 +1,17 @@ +package top.fatweb.api.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 系统日志表 前端控制器 + *

+ * + * @author FatttSnake + * @since 2023-10-18 + */ +@RestController +@RequestMapping("/api/sysLog") +class SysLogController + diff --git a/src/main/kotlin/top/fatweb/api/entity/SysLog.kt b/src/main/kotlin/top/fatweb/api/entity/SysLog.kt new file mode 100644 index 0000000..2fc1047 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/SysLog.kt @@ -0,0 +1,122 @@ +package top.fatweb.api.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + *

+ * 系统日志表 + *

+ * + * @author FatttSnake + * @since 2023-10-18 + */ +@TableName("t_sys_log") +class SysLog : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 日志类型 + */ + @TableField("log_type") + var logType: String? = null + + /** + * 操作用户 + */ + @TableField("operate_user_id") + var operateUserId: Long? = null + + /** + * 操作时间 + */ + @TableField("operate_time") + var operateTime: LocalDateTime? = null + + /** + * 请求 URI + */ + @TableField("request_uri") + var requestUri: String? = null + + /** + * 请求方式 + */ + @TableField("request_method") + var requestMethod: String? = null + + /** + * 请求参数 + */ + @TableField("request_params") + var requestParams: String? = null + + /** + * 请求 IP + */ + @TableField("request_ip") + var requestIp: String? = null + + /** + * 请求服务器地址 + */ + @TableField("request_server_address") + var requestServerAddress: String? = null + + /** + * 是否异常 + */ + @TableField("is_exception") + var isException: String? = null + + /** + * 异常信息 + */ + @TableField("exception_info") + var exceptionInfo: String? = null + + /** + * 开始时间 + */ + @TableField("start_time") + var startTime: LocalDateTime? = null + + /** + * 结束时间 + */ + @TableField("end_time") + var endTime: LocalDateTime? = null + + /** + * 执行时间 + */ + @TableField("execute_time") + var executeTime: Int? = null + + /** + * 用户代理 + */ + @TableField("user_agent") + var userAgent: String? = null + + /** + * 操作系统 + */ + @TableField("device_name") + var deviceName: String? = null + + /** + * 浏览器名称 + */ + @TableField("browser_name") + var browserName: String? = null + + override fun toString(): String { + return "SysLog(id=$id, logType=$logType, operateUserId=$operateUserId, operateTime=$operateTime, requestUri=$requestUri, requestMethod=$requestMethod, requestParams=$requestParams, requestIp=$requestIp, requestServerAddress=$requestServerAddress, isException=$isException, exceptionInfo=$exceptionInfo, startTime=$startTime, endTime=$endTime, executeTime=$executeTime, userAgent=$userAgent, deviceName=$deviceName, browserName=$browserName)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/mapper/SysLogMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/SysLogMapper.kt new file mode 100644 index 0000000..f913efc --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/SysLogMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper; + +import top.fatweb.api.entity.SysLog; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * 系统日志表 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-18 + */ +@Mapper +interface SysLogMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/service/ISysLogService.kt b/src/main/kotlin/top/fatweb/api/service/ISysLogService.kt new file mode 100644 index 0000000..206694c --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/ISysLogService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service; + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.SysLog + +/** + *

+ * 系统日志表 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-18 + */ +interface ISysLogService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/impl/SysLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/impl/SysLogServiceImpl.kt new file mode 100644 index 0000000..8df1569 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/impl/SysLogServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.SysLog +import top.fatweb.api.mapper.SysLogMapper +import top.fatweb.api.service.ISysLogService + +/** + *

+ * 系统日志表 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-18 + */ +@Service +class SysLogServiceImpl : ServiceImpl(), ISysLogService diff --git a/src/main/resources/mapper/SysLogMapper.xml b/src/main/resources/mapper/SysLogMapper.xml new file mode 100644 index 0000000..6dd14f3 --- /dev/null +++ b/src/main/resources/mapper/SysLogMapper.xml @@ -0,0 +1,5 @@ + + + + + From 1d77caf390474ae15dadf8e3c0cbaefab19ded5a Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 19 Oct 2023 16:01:42 +0800 Subject: [PATCH 045/258] Finish system log --- db/schema.sql | 10 +- .../top/fatweb/api/config/SysLogConfig.kt | 15 +++ .../kotlin/top/fatweb/api/entity/SysLog.kt | 28 ++--- .../api/interceptor/SysLogInterceptor.kt | 110 ++++++++++++++++++ .../impl/AuthenticationServiceImpl.kt | 11 +- .../kotlin/top/fatweb/api/util/WebUtil.kt | 5 +- 6 files changed, 145 insertions(+), 34 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/config/SysLogConfig.kt create mode 100644 src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt diff --git a/db/schema.sql b/db/schema.sql index 73ff84c..70cc8af 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -28,7 +28,7 @@ create table t_sys_log id bigint not null, log_type varchar(50) not null comment '日志类型', operate_user_id bigint not null comment '操作用户', - operate_time datetime not null default (utc_timestamp()) comment '操作时间', + operate_time datetime(3) not null default (utc_timestamp()) comment '操作时间', request_uri varchar(500) default null comment '请求 URI', request_method varchar(10) default null comment '请求方式', request_params text comment '请求参数', @@ -36,12 +36,10 @@ create table t_sys_log request_server_address varchar(50) not null comment '请求服务器地址', is_exception char(1) default null comment '是否异常', exception_info text comment '异常信息', - start_time datetime not null comment '开始时间', - end_time datetime not null comment '结束时间', - execute_time int default null comment '执行时间', + start_time datetime(3) not null comment '开始时间', + end_time datetime(3) not null comment '结束时间', + execute_time bigint default null comment '执行时间', user_agent varchar(500) default null comment '用户代理', - device_name varchar(100) default null comment '操作系统', - browser_name varchar(100) default null comment '浏览器名称', primary key (id) using btree, key idx_sys_log_log_type (log_type) using btree, key idx_sys_log_operate_user_id (operate_user_id) using btree, diff --git a/src/main/kotlin/top/fatweb/api/config/SysLogConfig.kt b/src/main/kotlin/top/fatweb/api/config/SysLogConfig.kt new file mode 100644 index 0000000..2288877 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/config/SysLogConfig.kt @@ -0,0 +1,15 @@ +package top.fatweb.api.config + +import org.springframework.context.annotation.Configuration +import org.springframework.web.servlet.config.annotation.InterceptorRegistry +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer +import top.fatweb.api.interceptor.SysLogInterceptor + +@Configuration +class SysLogConfig( + private val sysLogInterceptor: SysLogInterceptor +) : WebMvcConfigurer { + override fun addInterceptors(registry: InterceptorRegistry) { + registry.addInterceptor(sysLogInterceptor).addPathPatterns("/**").excludePathPatterns("/error/thrown") + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/SysLog.kt b/src/main/kotlin/top/fatweb/api/entity/SysLog.kt index 2fc1047..0e49aa2 100644 --- a/src/main/kotlin/top/fatweb/api/entity/SysLog.kt +++ b/src/main/kotlin/top/fatweb/api/entity/SysLog.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.entity; +package top.fatweb.api.entity -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; -import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableName +import java.io.Serializable +import java.time.LocalDateTime /** *

@@ -96,7 +96,7 @@ class SysLog : Serializable { * 执行时间 */ @TableField("execute_time") - var executeTime: Int? = null + var executeTime: Long? = null /** * 用户代理 @@ -104,19 +104,7 @@ class SysLog : Serializable { @TableField("user_agent") var userAgent: String? = null - /** - * 操作系统 - */ - @TableField("device_name") - var deviceName: String? = null - - /** - * 浏览器名称 - */ - @TableField("browser_name") - var browserName: String? = null - override fun toString(): String { - return "SysLog(id=$id, logType=$logType, operateUserId=$operateUserId, operateTime=$operateTime, requestUri=$requestUri, requestMethod=$requestMethod, requestParams=$requestParams, requestIp=$requestIp, requestServerAddress=$requestServerAddress, isException=$isException, exceptionInfo=$exceptionInfo, startTime=$startTime, endTime=$endTime, executeTime=$executeTime, userAgent=$userAgent, deviceName=$deviceName, browserName=$browserName)" + return "SysLog(id=$id, logType=$logType, operateUserId=$operateUserId, operateTime=$operateTime, requestUri=$requestUri, requestMethod=$requestMethod, requestParams=$requestParams, requestIp=$requestIp, requestServerAddress=$requestServerAddress, isException=$isException, exceptionInfo=$exceptionInfo, startTime=$startTime, endTime=$endTime, executeTime=$executeTime, userAgent=$userAgent)" } } diff --git a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt new file mode 100644 index 0000000..860c565 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt @@ -0,0 +1,110 @@ +package top.fatweb.api.interceptor + +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.core.MethodParameter +import org.springframework.http.MediaType +import org.springframework.http.converter.HttpMessageConverter +import org.springframework.http.server.ServerHttpRequest +import org.springframework.http.server.ServerHttpResponse +import org.springframework.web.bind.annotation.ControllerAdvice +import org.springframework.web.servlet.HandlerInterceptor +import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice +import top.fatweb.api.entity.SysLog +import top.fatweb.api.entity.common.ResponseResult +import top.fatweb.api.service.ISysLogService +import top.fatweb.api.util.WebUtil +import java.net.URI +import java.time.LocalDateTime +import java.time.ZoneOffset +import java.time.temporal.ChronoUnit +import java.util.* +import java.util.concurrent.Executor + +@ControllerAdvice +class SysLogInterceptor( + val customThreadPoolTaskExecutor: Executor, val sysLogService: ISysLogService +) : HandlerInterceptor, ResponseBodyAdvice { + private val logger: Logger = LoggerFactory.getLogger(this::class.java) + private val sysLogThreadLocal = ThreadLocal() + private val resultThreadLocal = ThreadLocal() + + override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean { + val sysLog = SysLog().apply { + operateUserId = WebUtil.getLoginUserId() ?: -1 + startTime = LocalDateTime.now(ZoneOffset.UTC) + requestUri = URI(request.requestURI).path + requestParams = formatParams(request.parameterMap) + requestMethod = request.method + requestIp = request.remoteAddr + requestServerAddress = "${request.scheme}://${request.serverName}:${request.serverPort}" + userAgent = request.getHeader("User-Agent") + } + + sysLogThreadLocal.set(sysLog) + + logger.info("开始计时: {} URI: {} IP: {}", sysLog.startTime, sysLog.requestUri, sysLog.requestIp) + + return true + } + + override fun afterCompletion( + request: HttpServletRequest, response: HttpServletResponse, handler: Any, ex: Exception? + ) { + val sysLog = sysLogThreadLocal.get() + val result = resultThreadLocal.get() + sysLog.endTime = LocalDateTime.now(ZoneOffset.UTC) + sysLog.executeTime = ChronoUnit.MILLIS.between(sysLog.startTime, sysLog.endTime) + if (result is ResponseResult<*>) { + if (result.success) { + sysLog.apply { + logType = "INFO" + isException = "N" + } + } else { + sysLog.apply { + logType = "ERROR" + isException = "Y" + exceptionInfo = result.msg + } + } + + customThreadPoolTaskExecutor.execute(SaveLogThread(sysLog, sysLogService)) + } + sysLogThreadLocal.remove() + } + + private fun formatParams(parameterMap: Map>): String { + val params = StringJoiner("&") + + parameterMap.forEach { + params.add("${it.key}=${if (it.key.endsWith("password", true)) "*" else it.value.joinToString(",")}") + } + + return params.toString() + } + + private class SaveLogThread(val sysLog: SysLog, val sysLogService: ISysLogService) : Thread() { + override fun run() { + sysLog.operateTime = LocalDateTime.now(ZoneOffset.UTC) + sysLogService.save(sysLog) + } + } + + override fun supports(returnType: MethodParameter, converterType: Class>): Boolean = + true + + override fun beforeBodyWrite( + body: Any?, + returnType: MethodParameter, + selectedContentType: MediaType, + selectedConverterType: Class>, + request: ServerHttpRequest, + response: ServerHttpResponse + ): Any? { + resultThreadLocal.set(body) + return body + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index cc669c0..139ab2b 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -10,6 +10,7 @@ import org.springframework.stereotype.Service import top.fatweb.api.constant.SecurityConstants import top.fatweb.api.entity.permission.LoginUser import top.fatweb.api.entity.permission.User +import top.fatweb.api.exception.TokenHasExpiredException import top.fatweb.api.service.IUserService import top.fatweb.api.service.permission.IAuthenticationService import top.fatweb.api.util.JwtUtil @@ -56,10 +57,11 @@ class AuthenticationServiceImpl( return LoginVo(jwt, loginUser.user.lastLoginTime, loginUser.user.lastLoginIp) } - override fun logout(token: String): Boolean = - redisUtil.delObject("${SecurityConstants.jwtIssuer}_login:" + token) + override fun logout(token: String): Boolean = redisUtil.delObject("${SecurityConstants.jwtIssuer}_login:" + token) override fun renewToken(token: String): TokenVo { + val loginUser = WebUtil.getLoginUser() ?: let { throw TokenHasExpiredException() } + val oldRedisKey = "${SecurityConstants.jwtIssuer}_login:" + token redisUtil.delObject(oldRedisKey) val jwt = JwtUtil.createJwt(WebUtil.getLoginUserId().toString()) @@ -70,10 +72,7 @@ class AuthenticationServiceImpl( val redisKey = "${SecurityConstants.jwtIssuer}_login:" + jwt redisUtil.setObject( - redisKey, - WebUtil.getLoginUser(), - SecurityConstants.redisTtl, - SecurityConstants.redisTtlUnit + redisKey, loginUser, SecurityConstants.redisTtl, SecurityConstants.redisTtlUnit ) return TokenVo(jwt) diff --git a/src/main/kotlin/top/fatweb/api/util/WebUtil.kt b/src/main/kotlin/top/fatweb/api/util/WebUtil.kt index da37681..ac280d8 100644 --- a/src/main/kotlin/top/fatweb/api/util/WebUtil.kt +++ b/src/main/kotlin/top/fatweb/api/util/WebUtil.kt @@ -6,9 +6,10 @@ import top.fatweb.api.constant.SecurityConstants import top.fatweb.api.entity.permission.LoginUser object WebUtil { - fun getLoginUser() = SecurityContextHolder.getContext().authentication.principal as LoginUser + fun getLoginUser() = if (SecurityContextHolder.getContext().authentication.principal is String) null + else SecurityContextHolder.getContext().authentication.principal as LoginUser - fun getLoginUserId() = getLoginUser().user.id + fun getLoginUserId() = getLoginUser()?.user?.id fun getToken(tokenWithPrefix: String) = tokenWithPrefix.removePrefix(SecurityConstants.tokenPrefix) From 4d6eecca726cbbe5848482c9d0504bf2e3ee5322 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 20 Oct 2023 17:57:15 +0800 Subject: [PATCH 046/258] Add auto create database table --- pom.xml | 11 +++++++++ src/main/resources/application.yml | 4 ++++ .../V1_0_0_231019__Add_table_'t_user'.sql | 19 +++++++++++++++ .../V1_0_0_231020__Add_table_'t_sys_log'.sql | 24 +++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 src/main/resources/db/migration/V1_0_0_231019__Add_table_'t_user'.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql diff --git a/pom.xml b/pom.xml index abe9e27..9372dfc 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,7 @@ 1.8.22 ${maven.build.timestamp} yyyy-MM-dd'T'HH:mm:ss + 9.22.3 @@ -158,6 +159,16 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 + + org.flywaydb + flyway-core + ${flyway.version} + + + org.flywaydb + flyway-mysql + ${flyway.version} + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 897ad44..7e4db33 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,6 +11,10 @@ spring: jackson: date-format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' time-zone: GMT + flyway: + baseline-on-migrate: true + baseline-version: 0 + clean-disabled: false mybatis-plus: global-config: diff --git a/src/main/resources/db/migration/V1_0_0_231019__Add_table_'t_user'.sql b/src/main/resources/db/migration/V1_0_0_231019__Add_table_'t_user'.sql new file mode 100644 index 0000000..659635e --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231019__Add_table_'t_user'.sql @@ -0,0 +1,19 @@ +drop table if exists t_user; + +create table if not exists t_user +( + id bigint not null primary key, + username varchar(20) not null comment '用户名', + password char(70) not null comment '密码', + locking int not null comment '锁定', + expiration datetime comment '过期时间', + credentials_expiration datetime comment '认证过期时间', + enable int not null comment '启用', + last_login_time datetime comment '上次登录时间', + last_login_ip varchar(128) comment '上次登录 IP', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, + constraint t_user_unique unique (username, deleted) +) comment '用户表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql b/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql new file mode 100644 index 0000000..01e04f1 --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql @@ -0,0 +1,24 @@ +drop table if exists t_sys_log; +create table t_sys_log +( + id bigint not null, + log_type varchar(50) not null comment '日志类型', + operate_user_id bigint not null comment '操作用户', + operate_time datetime(3) not null default (utc_timestamp()) comment '操作时间', + request_uri varchar(500) default null comment '请求 URI', + request_method varchar(10) default null comment '请求方式', + request_params text comment '请求参数', + request_ip varchar(20) not null comment '请求 IP', + request_server_address varchar(50) not null comment '请求服务器地址', + is_exception char(1) default null comment '是否异常', + exception_info text comment '异常信息', + start_time datetime(3) not null comment '开始时间', + end_time datetime(3) not null comment '结束时间', + execute_time bigint default null comment '执行时间', + user_agent varchar(500) default null comment '用户代理', + primary key (id) using btree, + key idx_sys_log_log_type (log_type) using btree, + key idx_sys_log_operate_user_id (operate_user_id) using btree, + key idx_sys_log_is_exception (is_exception) using btree, + key idx_sys_log_operate_time (operate_time) using btree +) comment '系统日志表'; \ No newline at end of file From 5e219636108313b538919a7282d8f78aff9db4c1 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 20 Oct 2023 17:58:02 +0800 Subject: [PATCH 047/258] Add auto create administrator when first startup --- .../top/fatweb/api/config/InitConfig.kt | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/kotlin/top/fatweb/api/config/InitConfig.kt diff --git a/src/main/kotlin/top/fatweb/api/config/InitConfig.kt b/src/main/kotlin/top/fatweb/api/config/InitConfig.kt new file mode 100644 index 0000000..14b6858 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/config/InitConfig.kt @@ -0,0 +1,52 @@ +package top.fatweb.api.config + +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper +import jakarta.annotation.PostConstruct +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.security.crypto.password.PasswordEncoder +import org.springframework.stereotype.Component +import top.fatweb.api.entity.permission.User +import top.fatweb.api.service.IUserService +import kotlin.random.Random + +@Component +class InitConfig( + private val userService: IUserService, private val passwordEncoder: PasswordEncoder +) { + private val logger: Logger = LoggerFactory.getLogger(this::class.java) + + @PostConstruct + fun init() { + if (!userService.exists(KtQueryWrapper(User()).eq(User::id, 0))) { + val rawPassword = getRandPassword(10) + val encodedPassword = passwordEncoder.encode(rawPassword) + val user = User().apply { + id = 0 + username = "admin" + password = encodedPassword + locking = 0 + enable = 1 + } + if (userService.save(user)) { + logger.warn("First startup, create administrator - username: admin, password: $rawPassword") + logger.warn("This information will only be shown once. Please change your password promptly after logging in.") + } + } + + } + + private fun getRandPassword(length: Int): String { + val characterSet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + + val random = Random(System.nanoTime()) + val password = StringBuilder() + + for (i in 0 until length) { + val rIndex = random.nextInt(characterSet.length) + password.append(characterSet[rIndex]) + } + + return password.toString() + } +} \ No newline at end of file From f927851cb0c8886c106bf6391e9f0aaa7e20657c Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 23 Oct 2023 15:39:54 +0800 Subject: [PATCH 048/258] Optimize code --- .../top/fatweb/api/config/DataFormatConfig.kt | 6 +-- .../top/fatweb/api/config/SecurityConfig.kt | 6 +-- .../permission/AuthenticationController.kt | 39 +++++++++---------- .../top/fatweb/api/converter/UserConverter.kt | 4 +- .../api/entity/common/ResponseResult.kt | 12 ++---- .../top/fatweb/api/filter/ExceptionFilter.kt | 4 +- .../filter/JwtAuthenticationTokenFilter.kt | 4 +- .../api/handler/JwtAccessDeniedHandler.kt | 4 +- .../JwtAuthenticationEntryPointHandler.kt | 4 +- .../param/{ => authentication}/LoginParam.kt | 2 +- .../permission/IAuthenticationService.kt | 4 +- .../impl/AuthenticationServiceImpl.kt | 4 +- .../kotlin/top/fatweb/api/util/JwtUtil.kt | 3 +- .../api/vo/{ => authentication}/LoginVo.kt | 2 +- .../api/vo/{ => authentication}/TokenVo.kt | 2 +- 15 files changed, 40 insertions(+), 60 deletions(-) rename src/main/kotlin/top/fatweb/api/param/{ => authentication}/LoginParam.kt (92%) rename src/main/kotlin/top/fatweb/api/vo/{ => authentication}/LoginVo.kt (94%) rename src/main/kotlin/top/fatweb/api/vo/{ => authentication}/TokenVo.kt (91%) diff --git a/src/main/kotlin/top/fatweb/api/config/DataFormatConfig.kt b/src/main/kotlin/top/fatweb/api/config/DataFormatConfig.kt index eaa73a7..3a7b76c 100644 --- a/src/main/kotlin/top/fatweb/api/config/DataFormatConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/DataFormatConfig.kt @@ -27,10 +27,8 @@ class DataFormatConfig { val tz = timeZone val df: DateFormat = SimpleDateFormat(dataFormat) df.timeZone = tz - builder.failOnEmptyBeans(false) - .failOnUnknownProperties(false) - .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) - .dateFormat(df) + builder.failOnEmptyBeans(false).failOnUnknownProperties(false) + .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).dateFormat(df) } diff --git a/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt b/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt index 017f2d4..3c9602d 100644 --- a/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt @@ -20,9 +20,9 @@ import top.fatweb.api.handler.JwtAuthenticationEntryPointHandler @Configuration @EnableMethodSecurity class SecurityConfig( - val jwtAuthenticationTokenFilter: JwtAuthenticationTokenFilter, - val authenticationEntryPointHandler: JwtAuthenticationEntryPointHandler, - val accessDeniedHandler: JwtAccessDeniedHandler + private val jwtAuthenticationTokenFilter: JwtAuthenticationTokenFilter, + private val authenticationEntryPointHandler: JwtAuthenticationEntryPointHandler, + private val accessDeniedHandler: JwtAccessDeniedHandler ) { @Bean fun passwordEncoder() = BCryptPasswordEncoder() diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt index 2f04f9e..0c75325 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt @@ -8,41 +8,38 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RestController -import top.fatweb.api.annotation.ApiVersion import top.fatweb.api.converter.UserConverter import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.param.LoginParam +import top.fatweb.api.param.authentication.LoginParam import top.fatweb.api.service.permission.IAuthenticationService import top.fatweb.api.util.WebUtil @Tag(name = "身份认证", description = "身份认证相关接口") -@ApiVersion(2) @RestController -class AuthenticationController(val authenticationService: IAuthenticationService, val userConverter: UserConverter) { +class AuthenticationController( + private val authenticationService: IAuthenticationService +) { @Operation(summary = "登录") @PostMapping("/login") - fun login(request: HttpServletRequest, @Valid @RequestBody loginParam: LoginParam) = - ResponseResult.success( - ResponseCode.SYSTEM_LOGIN_SUCCESS, - "Login success", - authenticationService.login(request, userConverter.loginParamToUser(loginParam)) - ) + fun login(request: HttpServletRequest, @Valid @RequestBody loginParam: LoginParam) = ResponseResult.success( + ResponseCode.SYSTEM_LOGIN_SUCCESS, + "Login success", + authenticationService.login(request, UserConverter.loginParamToUser(loginParam)) + ) @Operation(summary = "登出") @PostMapping("/logout") - fun logout(request: HttpServletRequest) = - when (authenticationService.logout(WebUtil.getToken(request))) { - true -> ResponseResult.success(ResponseCode.SYSTEM_LOGOUT_SUCCESS, "Logout success", null) - false -> ResponseResult.fail(ResponseCode.SYSTEM_LOGOUT_FAILED, "Logout failed", null) - } + fun logout(request: HttpServletRequest) = when (authenticationService.logout(WebUtil.getToken(request))) { + true -> ResponseResult.success(ResponseCode.SYSTEM_LOGOUT_SUCCESS, "Logout success", null) + false -> ResponseResult.fail(ResponseCode.SYSTEM_LOGOUT_FAILED, "Logout failed", null) + } @Operation(summary = "更新 Token") @GetMapping("/token") - fun renewToken(request: HttpServletRequest) = - ResponseResult.success( - ResponseCode.SYSTEM_TOKEN_RENEW_SUCCESS, - "Token renew success", - authenticationService.renewToken(WebUtil.getToken(request)) - ) + fun renewToken(request: HttpServletRequest) = ResponseResult.success( + ResponseCode.SYSTEM_TOKEN_RENEW_SUCCESS, + "Token renew success", + authenticationService.renewToken(WebUtil.getToken(request)) + ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt b/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt index 1bfd381..f975039 100644 --- a/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt +++ b/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt @@ -1,10 +1,8 @@ package top.fatweb.api.converter -import org.springframework.stereotype.Component import top.fatweb.api.entity.permission.User -import top.fatweb.api.param.LoginParam +import top.fatweb.api.param.authentication.LoginParam -@Component object UserConverter { fun loginParamToUser(loginParam: LoginParam): User { val user = User().apply { diff --git a/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt b/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt index 9559c1d..bbfde54 100644 --- a/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt +++ b/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt @@ -4,17 +4,13 @@ import io.swagger.v3.oas.annotations.media.Schema import java.io.Serializable class ResponseResult private constructor( - @Schema(description = "响应码", defaultValue = "200") - val code: Int, + @Schema(description = "响应码", defaultValue = "200") val code: Int, - @Schema(description = "是否调用成功") - val success: Boolean, + @Schema(description = "是否调用成功") val success: Boolean, - @Schema(description = "信息") - val msg: String, + @Schema(description = "信息") val msg: String, - @Schema(description = "数据") - val data: T? + @Schema(description = "数据") val data: T? ) : Serializable { companion object { fun build(code: ResponseCode, success: Boolean, msg: String, data: T?) = diff --git a/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt b/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt index 3097036..0d4ac53 100644 --- a/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt +++ b/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt @@ -9,9 +9,7 @@ import org.springframework.stereotype.Component @Component class ExceptionFilter : Filter { override fun doFilter( - servletRequest: ServletRequest?, - servletResponse: ServletResponse?, - filterChain: FilterChain? + servletRequest: ServletRequest?, servletResponse: ServletResponse?, filterChain: FilterChain? ) { try { filterChain!!.doFilter(servletRequest, servletResponse) diff --git a/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt b/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt index 048aa39..fbdf03b 100644 --- a/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt +++ b/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt @@ -18,9 +18,7 @@ import top.fatweb.api.util.WebUtil @Component class JwtAuthenticationTokenFilter(private val redisUtil: RedisUtil) : OncePerRequestFilter() { override fun doFilterInternal( - request: HttpServletRequest, - response: HttpServletResponse, - filterChain: FilterChain + request: HttpServletRequest, response: HttpServletResponse, filterChain: FilterChain ) { val tokenWithPrefix = request.getHeader(SecurityConstants.headerString) diff --git a/src/main/kotlin/top/fatweb/api/handler/JwtAccessDeniedHandler.kt b/src/main/kotlin/top/fatweb/api/handler/JwtAccessDeniedHandler.kt index 22e03c6..a47a8c9 100644 --- a/src/main/kotlin/top/fatweb/api/handler/JwtAccessDeniedHandler.kt +++ b/src/main/kotlin/top/fatweb/api/handler/JwtAccessDeniedHandler.kt @@ -9,9 +9,7 @@ import org.springframework.stereotype.Component @Component class JwtAccessDeniedHandler : AccessDeniedHandler { override fun handle( - request: HttpServletRequest?, - response: HttpServletResponse?, - accessDeniedException: AccessDeniedException? + request: HttpServletRequest?, response: HttpServletResponse?, accessDeniedException: AccessDeniedException? ) { request?.setAttribute("filter.error", accessDeniedException) request?.getRequestDispatcher("/error/thrown")?.forward(request, response) diff --git a/src/main/kotlin/top/fatweb/api/handler/JwtAuthenticationEntryPointHandler.kt b/src/main/kotlin/top/fatweb/api/handler/JwtAuthenticationEntryPointHandler.kt index cf5b808..4725a66 100644 --- a/src/main/kotlin/top/fatweb/api/handler/JwtAuthenticationEntryPointHandler.kt +++ b/src/main/kotlin/top/fatweb/api/handler/JwtAuthenticationEntryPointHandler.kt @@ -9,9 +9,7 @@ import org.springframework.stereotype.Component @Component class JwtAuthenticationEntryPointHandler : AuthenticationEntryPoint { override fun commence( - request: HttpServletRequest?, - response: HttpServletResponse?, - authException: AuthenticationException? + request: HttpServletRequest?, response: HttpServletResponse?, authException: AuthenticationException? ) { request?.setAttribute("filter.error", authException) request?.getRequestDispatcher("/error/thrown")?.forward(request, response) diff --git a/src/main/kotlin/top/fatweb/api/param/LoginParam.kt b/src/main/kotlin/top/fatweb/api/param/authentication/LoginParam.kt similarity index 92% rename from src/main/kotlin/top/fatweb/api/param/LoginParam.kt rename to src/main/kotlin/top/fatweb/api/param/authentication/LoginParam.kt index 701ab12..84d15e1 100644 --- a/src/main/kotlin/top/fatweb/api/param/LoginParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/authentication/LoginParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param +package top.fatweb.api.param.authentication import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt index 5704e7d..5fb8e07 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt @@ -2,8 +2,8 @@ package top.fatweb.api.service.permission import jakarta.servlet.http.HttpServletRequest import top.fatweb.api.entity.permission.User -import top.fatweb.api.vo.LoginVo -import top.fatweb.api.vo.TokenVo +import top.fatweb.api.vo.authentication.LoginVo +import top.fatweb.api.vo.authentication.TokenVo interface IAuthenticationService { fun login(request: HttpServletRequest, user: User): LoginVo diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index 139ab2b..eb8c765 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -16,8 +16,8 @@ import top.fatweb.api.service.permission.IAuthenticationService import top.fatweb.api.util.JwtUtil import top.fatweb.api.util.RedisUtil import top.fatweb.api.util.WebUtil -import top.fatweb.api.vo.LoginVo -import top.fatweb.api.vo.TokenVo +import top.fatweb.api.vo.authentication.LoginVo +import top.fatweb.api.vo.authentication.TokenVo import java.time.LocalDateTime import java.time.ZoneOffset diff --git a/src/main/kotlin/top/fatweb/api/util/JwtUtil.kt b/src/main/kotlin/top/fatweb/api/util/JwtUtil.kt index ea7c5aa..2e4f0f8 100644 --- a/src/main/kotlin/top/fatweb/api/util/JwtUtil.kt +++ b/src/main/kotlin/top/fatweb/api/util/JwtUtil.kt @@ -62,6 +62,5 @@ object JwtUtil { * @param jwt jwt 串 * @return 解析内容 */ - fun parseJwt(jwt: String): DecodedJWT = - JWT.require(algorithm()).build().verify(jwt) + fun parseJwt(jwt: String): DecodedJWT = JWT.require(algorithm()).build().verify(jwt) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/LoginVo.kt b/src/main/kotlin/top/fatweb/api/vo/authentication/LoginVo.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/vo/LoginVo.kt rename to src/main/kotlin/top/fatweb/api/vo/authentication/LoginVo.kt index f3e76cc..8d1d96b 100644 --- a/src/main/kotlin/top/fatweb/api/vo/LoginVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/authentication/LoginVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo +package top.fatweb.api.vo.authentication import io.swagger.v3.oas.annotations.media.Schema import java.time.LocalDateTime diff --git a/src/main/kotlin/top/fatweb/api/vo/TokenVo.kt b/src/main/kotlin/top/fatweb/api/vo/authentication/TokenVo.kt similarity index 91% rename from src/main/kotlin/top/fatweb/api/vo/TokenVo.kt rename to src/main/kotlin/top/fatweb/api/vo/authentication/TokenVo.kt index c17ea01..3dc7af1 100644 --- a/src/main/kotlin/top/fatweb/api/vo/TokenVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/authentication/TokenVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo +package top.fatweb.api.vo.authentication import io.swagger.v3.oas.annotations.media.Schema From 634e2f6a67e730dc7e8a515dd238ecb1050d9e75 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 23 Oct 2023 16:08:43 +0800 Subject: [PATCH 049/258] Add system log api --- .../top/fatweb/api/config/SysLogConfig.kt | 3 +- .../fatweb/api/controller/SysLogController.kt | 17 ------- .../api/controller/system/SysLogController.kt | 43 ++++++++++++++++ .../fatweb/api/converter/SysLogConverter.kt | 34 +++++++++++++ .../fatweb/api/entity/common/ResponseCode.kt | 11 +++- .../fatweb/api/entity/{ => system}/SysLog.kt | 4 +- .../api/interceptor/SysLogInterceptor.kt | 12 ++--- .../api/mapper/{ => system}/SysLogMapper.kt | 4 +- .../fatweb/api/param/system/SysLogGetParam.kt | 17 +++++++ .../top/fatweb/api/service/ISysLogService.kt | 14 ----- .../api/service/impl/SysLogServiceImpl.kt | 18 ------- .../api/service/system/ISysLogService.kt | 17 +++++++ .../service/system/impl/SysLogServiceImpl.kt | 30 +++++++++++ src/main/kotlin/top/fatweb/api/vo/PageVo.kt | 21 ++++++++ .../top/fatweb/api/vo/system/SysLogGetVo.kt | 51 +++++++++++++++++++ .../V1_0_0_231020__Add_table_'t_sys_log'.sql | 10 ++-- src/main/resources/mapper/SysLogMapper.xml | 2 +- 17 files changed, 240 insertions(+), 68 deletions(-) delete mode 100644 src/main/kotlin/top/fatweb/api/controller/SysLogController.kt create mode 100644 src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt create mode 100644 src/main/kotlin/top/fatweb/api/converter/SysLogConverter.kt rename src/main/kotlin/top/fatweb/api/entity/{ => system}/SysLog.kt (97%) rename src/main/kotlin/top/fatweb/api/mapper/{ => system}/SysLogMapper.kt (75%) create mode 100644 src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt delete mode 100644 src/main/kotlin/top/fatweb/api/service/ISysLogService.kt delete mode 100644 src/main/kotlin/top/fatweb/api/service/impl/SysLogServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/vo/PageVo.kt create mode 100644 src/main/kotlin/top/fatweb/api/vo/system/SysLogGetVo.kt diff --git a/src/main/kotlin/top/fatweb/api/config/SysLogConfig.kt b/src/main/kotlin/top/fatweb/api/config/SysLogConfig.kt index 2288877..ba1c40b 100644 --- a/src/main/kotlin/top/fatweb/api/config/SysLogConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/SysLogConfig.kt @@ -10,6 +10,7 @@ class SysLogConfig( private val sysLogInterceptor: SysLogInterceptor ) : WebMvcConfigurer { override fun addInterceptors(registry: InterceptorRegistry) { - registry.addInterceptor(sysLogInterceptor).addPathPatterns("/**").excludePathPatterns("/error/thrown") + registry.addInterceptor(sysLogInterceptor).addPathPatterns("/**") + .excludePathPatterns("/error/thrown", "/webjars/**") } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/controller/SysLogController.kt b/src/main/kotlin/top/fatweb/api/controller/SysLogController.kt deleted file mode 100644 index 9d58d09..0000000 --- a/src/main/kotlin/top/fatweb/api/controller/SysLogController.kt +++ /dev/null @@ -1,17 +0,0 @@ -package top.fatweb.api.controller; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - *

- * 系统日志表 前端控制器 - *

- * - * @author FatttSnake - * @since 2023-10-18 - */ -@RestController -@RequestMapping("/api/sysLog") -class SysLogController - diff --git a/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt b/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt new file mode 100644 index 0000000..af7533c --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt @@ -0,0 +1,43 @@ +package top.fatweb.api.controller.system; + +import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.tags.Tag +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController +import top.fatweb.api.converter.SysLogConverter +import top.fatweb.api.entity.common.ResponseCode +import top.fatweb.api.entity.common.ResponseResult +import top.fatweb.api.param.system.SysLogGetParam +import top.fatweb.api.service.system.ISysLogService +import top.fatweb.api.vo.PageVo +import top.fatweb.api.vo.system.SysLogGetVo + +/** + *

+ * 系统日志表 前端控制器 + *

+ * + * @author FatttSnake + * @since 2023-10-18 + */ +@RestController +@RequestMapping("/system/log") +@Tag(name = "系统日志", description = "系统日志相关接口") +class SysLogController( + private val sysLogService: ISysLogService +) { + @Operation(summary = "获取") + @GetMapping + fun get(@Valid @RequestBody sysLogGetParam: SysLogGetParam): ResponseResult> { + return ResponseResult.success( + ResponseCode.DATABASE_SELECT_SUCCESS, data = SysLogConverter.sysLogPageToSysLogPageVo( + sysLogService.getPage( + sysLogGetParam.page, sysLogGetParam.pageSize + ) + ) + ) + } +} diff --git a/src/main/kotlin/top/fatweb/api/converter/SysLogConverter.kt b/src/main/kotlin/top/fatweb/api/converter/SysLogConverter.kt new file mode 100644 index 0000000..cd2e475 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/converter/SysLogConverter.kt @@ -0,0 +1,34 @@ +package top.fatweb.api.converter + +import com.baomidou.mybatisplus.core.metadata.IPage +import top.fatweb.api.entity.system.SysLog +import top.fatweb.api.vo.PageVo +import top.fatweb.api.vo.system.SysLogGetVo + +object SysLogConverter { + fun sysLogPageToSysLogPageVo(syslogPage: IPage): PageVo = PageVo( + syslogPage.total, + syslogPage.pages, + syslogPage.size, + syslogPage.current, + syslogPage.records.map { + SysLogGetVo( + it.id, + it.logType, + it.operateUserId, + it.operateTime, + it.requestUri, + it.requestMethod, + it.requestParams, + it.requestIp, + it.requestServerAddress, + it.isException, + it.exceptionInfo, + it.startTime, + it.endTime, + it.executeTime, + it.userAgent + ) + }) + +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt index f6095bb..e536c40 100644 --- a/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt @@ -18,7 +18,16 @@ enum class ResponseCode(val code: Int) { SYSTEM_REQUEST_ILLEGAL(BusinessCode.SYSTEM, 40), SYSTEM_ARGUMENT_NOT_VALID(BusinessCode.SYSTEM, 41), SYSTEM_ERROR(BusinessCode.SYSTEM, 50), - SYSTEM_TIMEOUT(BusinessCode.SYSTEM, 51); + SYSTEM_TIMEOUT(BusinessCode.SYSTEM, 51), + + DATABASE_SELECT_SUCCESS(BusinessCode.DATABASE, 0), + DATABASE_SELECT_FAILED(BusinessCode.DATABASE, 5), + DATABASE_INSERT_SUCCESS(BusinessCode.DATABASE, 10), + DATABASE_INSERT_FAILED(BusinessCode.DATABASE, 15), + DATABASE_UPDATE_SUCCESS(BusinessCode.DATABASE, 20), + DATABASE_UPDATE_FILED(BusinessCode.DATABASE, 25), + DATABASE_DELETE_SUCCESS(BusinessCode.DATABASE, 30), + DATABASE_DELETE_FILED(BusinessCode.DATABASE, 35); constructor(businessCode: BusinessCode, code: Int) : this(businessCode.code * 100 + code) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/SysLog.kt b/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/entity/SysLog.kt rename to src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt index 0e49aa2..29b12e7 100644 --- a/src/main/kotlin/top/fatweb/api/entity/SysLog.kt +++ b/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity +package top.fatweb.api.entity.system import com.baomidou.mybatisplus.annotation.TableField import com.baomidou.mybatisplus.annotation.TableId @@ -72,7 +72,7 @@ class SysLog : Serializable { * 是否异常 */ @TableField("is_exception") - var isException: String? = null + var isException: Int? = null /** * 异常信息 diff --git a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt index 860c565..ce26b0e 100644 --- a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt +++ b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt @@ -12,9 +12,9 @@ import org.springframework.http.server.ServerHttpResponse import org.springframework.web.bind.annotation.ControllerAdvice import org.springframework.web.servlet.HandlerInterceptor import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice -import top.fatweb.api.entity.SysLog +import top.fatweb.api.entity.system.SysLog import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.service.ISysLogService +import top.fatweb.api.service.system.ISysLogService import top.fatweb.api.util.WebUtil import java.net.URI import java.time.LocalDateTime @@ -25,7 +25,7 @@ import java.util.concurrent.Executor @ControllerAdvice class SysLogInterceptor( - val customThreadPoolTaskExecutor: Executor, val sysLogService: ISysLogService + private val customThreadPoolTaskExecutor: Executor, private val sysLogService: ISysLogService ) : HandlerInterceptor, ResponseBodyAdvice { private val logger: Logger = LoggerFactory.getLogger(this::class.java) private val sysLogThreadLocal = ThreadLocal() @@ -45,8 +45,6 @@ class SysLogInterceptor( sysLogThreadLocal.set(sysLog) - logger.info("开始计时: {} URI: {} IP: {}", sysLog.startTime, sysLog.requestUri, sysLog.requestIp) - return true } @@ -61,12 +59,12 @@ class SysLogInterceptor( if (result.success) { sysLog.apply { logType = "INFO" - isException = "N" + isException = 0 } } else { sysLog.apply { logType = "ERROR" - isException = "Y" + isException = 1 exceptionInfo = result.msg } } diff --git a/src/main/kotlin/top/fatweb/api/mapper/SysLogMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt similarity index 75% rename from src/main/kotlin/top/fatweb/api/mapper/SysLogMapper.kt rename to src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt index f913efc..110ffce 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/SysLogMapper.kt +++ b/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt @@ -1,6 +1,6 @@ -package top.fatweb.api.mapper; +package top.fatweb.api.mapper.system; -import top.fatweb.api.entity.SysLog; +import top.fatweb.api.entity.system.SysLog; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; diff --git a/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt b/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt new file mode 100644 index 0000000..9fcb3a3 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt @@ -0,0 +1,17 @@ +package top.fatweb.api.param.system + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.Min +import java.io.Serializable + +@Schema(description = "获取系统日志请求参数") +class SysLogGetParam : Serializable { + + @Schema(description = "分页页码", example = "1", defaultValue = "1") + @Min(1, message = "Pagination page number must be a positive integer") + val page: Long = 1 + + @Schema(description = "分页大小", example = "20", defaultValue = "20") + @Min(1, message = "The number of data per page must be a positive integer") + val pageSize: Long = 20 +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/ISysLogService.kt b/src/main/kotlin/top/fatweb/api/service/ISysLogService.kt deleted file mode 100644 index 206694c..0000000 --- a/src/main/kotlin/top/fatweb/api/service/ISysLogService.kt +++ /dev/null @@ -1,14 +0,0 @@ -package top.fatweb.api.service; - -import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.SysLog - -/** - *

- * 系统日志表 服务类 - *

- * - * @author FatttSnake - * @since 2023-10-18 - */ -interface ISysLogService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/impl/SysLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/impl/SysLogServiceImpl.kt deleted file mode 100644 index 8df1569..0000000 --- a/src/main/kotlin/top/fatweb/api/service/impl/SysLogServiceImpl.kt +++ /dev/null @@ -1,18 +0,0 @@ -package top.fatweb.api.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl -import org.springframework.stereotype.Service -import top.fatweb.api.entity.SysLog -import top.fatweb.api.mapper.SysLogMapper -import top.fatweb.api.service.ISysLogService - -/** - *

- * 系统日志表 服务实现类 - *

- * - * @author FatttSnake - * @since 2023-10-18 - */ -@Service -class SysLogServiceImpl : ServiceImpl(), ISysLogService diff --git a/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt b/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt new file mode 100644 index 0000000..50287ec --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt @@ -0,0 +1,17 @@ +package top.fatweb.api.service.system; + +import com.baomidou.mybatisplus.core.metadata.IPage +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.system.SysLog + +/** + *

+ * 系统日志表 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-18 + */ +interface ISysLogService : IService { + fun getPage(page: Long, pageSize: Long): IPage +} diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt new file mode 100644 index 0000000..ec6c0d5 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt @@ -0,0 +1,30 @@ +package top.fatweb.api.service.system.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage +import com.baomidou.mybatisplus.core.toolkit.Wrappers +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper +import com.baomidou.mybatisplus.extension.plugins.pagination.Page +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.system.SysLog +import top.fatweb.api.mapper.system.SysLogMapper +import top.fatweb.api.service.system.ISysLogService + +/** + *

+ * 系统日志表 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-18 + */ +@Service +class SysLogServiceImpl : ServiceImpl(), ISysLogService { + override fun getPage(page: Long, pageSize: Long): IPage { + var sysLogPage = Page(page, pageSize) + + sysLogPage = baseMapper.selectPage(sysLogPage, KtQueryWrapper(SysLog()).orderByDesc(SysLog::id)) + + return sysLogPage + } +} diff --git a/src/main/kotlin/top/fatweb/api/vo/PageVo.kt b/src/main/kotlin/top/fatweb/api/vo/PageVo.kt new file mode 100644 index 0000000..b10c786 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/PageVo.kt @@ -0,0 +1,21 @@ +package top.fatweb.api.vo + +import io.swagger.v3.oas.annotations.media.Schema + +@Schema(description = "分页返回参数") +data class PageVo( + @Schema(description = "总数量", example = "100") + val total: Long, + + @Schema(description = "总页码", example = "10") + val pages: Long, + + @Schema(description = "分页大小", example = "10") + val size: Long, + + @Schema(description = "当前页码", example = "2") + val current: Long, + + @Schema(description = "数据") + val records: List +) diff --git a/src/main/kotlin/top/fatweb/api/vo/system/SysLogGetVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/SysLogGetVo.kt new file mode 100644 index 0000000..42fe7f7 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/system/SysLogGetVo.kt @@ -0,0 +1,51 @@ +package top.fatweb.api.vo.system + +import io.swagger.v3.oas.annotations.media.Schema +import java.time.LocalDateTime + +@Schema(description = "获取系统日志返回参数") +class SysLogGetVo( + val id: Long?, + + @Schema(description = "日志类型") + val logType: String?, + + @Schema(description = "操作用户 ID") + val operateUserId: Long?, + + @Schema(description = "操作时间") + val operateTime: LocalDateTime?, + + @Schema(description = "请求 Uri") + val requestUri: String?, + + @Schema(description = "请求方式") + val requestMethod: String?, + + @Schema(description = "请求参数") + val requestParams: String?, + + @Schema(description = "请求 IP") + val requestIp: String?, + + @Schema(description = "请求服务器地址") + val requestServerAddress: String?, + + @Schema(description = "是否异常") + val isException: Int?, + + @Schema(description = "异常信息") + val exceptionInfo: String?, + + @Schema(description = "开始时间") + val startTime: LocalDateTime?, + + @Schema(description = "结束时间") + val endTime: LocalDateTime?, + + @Schema(description = "执行时间") + val executeTime: Long?, + + @Schema(description = "用户代理") + val userAgent: String? +) diff --git a/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql b/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql index 01e04f1..5816ccb 100644 --- a/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql +++ b/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql @@ -4,17 +4,17 @@ create table t_sys_log id bigint not null, log_type varchar(50) not null comment '日志类型', operate_user_id bigint not null comment '操作用户', - operate_time datetime(3) not null default (utc_timestamp()) comment '操作时间', + operate_time datetime(3) not null default (utc_timestamp()) comment '操作时间', request_uri varchar(500) default null comment '请求 URI', request_method varchar(10) default null comment '请求方式', request_params text comment '请求参数', request_ip varchar(20) not null comment '请求 IP', request_server_address varchar(50) not null comment '请求服务器地址', - is_exception char(1) default null comment '是否异常', + is_exception int not null default 0 comment '是否异常', exception_info text comment '异常信息', - start_time datetime(3) not null comment '开始时间', - end_time datetime(3) not null comment '结束时间', - execute_time bigint default null comment '执行时间', + start_time datetime(3) not null comment '开始时间', + end_time datetime(3) not null comment '结束时间', + execute_time bigint default null comment '执行时间', user_agent varchar(500) default null comment '用户代理', primary key (id) using btree, key idx_sys_log_log_type (log_type) using btree, diff --git a/src/main/resources/mapper/SysLogMapper.xml b/src/main/resources/mapper/SysLogMapper.xml index 6dd14f3..208129b 100644 --- a/src/main/resources/mapper/SysLogMapper.xml +++ b/src/main/resources/mapper/SysLogMapper.xml @@ -1,5 +1,5 @@ - + From 33c865f03c984ff5ce120b37286e3fcf0050775b Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 23 Oct 2023 17:26:14 +0800 Subject: [PATCH 050/258] Add permission-related database tables --- .../resources/db/migration/R__Basic_data.sql | 70 +++++++++++++++++++ ...1_0_0_231023__Add_table_'t_power_type'.sql | 7 ++ .../V1_0_0_231024__Add_table_'t_power'.sql | 7 ++ .../V1_0_0_231025__Add_table_'t_menu'.sql | 10 +++ .../V1_0_0_231026__Add_table_'t_element'.sql | 9 +++ ...V1_0_0_231027__Add_table_'t_operation'.sql | 11 +++ 6 files changed, 114 insertions(+) create mode 100644 src/main/resources/db/migration/R__Basic_data.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231023__Add_table_'t_power_type'.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231024__Add_table_'t_power'.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231025__Add_table_'t_menu'.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231027__Add_table_'t_operation'.sql diff --git a/src/main/resources/db/migration/R__Basic_data.sql b/src/main/resources/db/migration/R__Basic_data.sql new file mode 100644 index 0000000..6dfc7db --- /dev/null +++ b/src/main/resources/db/migration/R__Basic_data.sql @@ -0,0 +1,70 @@ +insert into t_power_type (id, name) +values (1, 'menu'), + (2, 'element'), + (3, 'operation') +on duplicate key update name = values(name); + +insert into t_power (id, type_id) +values (1010000, 1), + (1010100, 2), + (1010101, 3), + (101010000, 1), + (101010100, 2), + (101010101, 3), + (101010102, 3), + (101010103, 3), + (101010104, 3), + (102010000, 1), + (102010100, 2), + (102010101, 3), + (102010102, 3), + (102010103, 3), + (102010104, 3), + (103010000, 1), + (103010100, 2), + (103010101, 3), + (103010102, 3), + (103010103, 3), + (103010104, 3), + (103010105, 3) +on duplicate key update type_id = values(type_id); + +insert into t_menu (id, name, url, power_id, parent_id) +values (1010000, '公用', '/', id, null), + (101010000, '角色管理(权限相关)', '/power/role', id, null), + (102010000, '用户组管理(权限相关)', '/power/group', id, null), + (103010000, '用户管理(权限相关)', '/power/user', id, null) +on duplicate key update name = values(name), + url = values(url), + power_id = values(power_id), + parent_id = values(parent_id); + +insert into t_element(id, name, power_id, menu_id) +values (1010100, '公用', id, 1010000), + (101010100, '基础', id, 101010000), + (102010100, '基础', id, 102010000), + (103010100, '基础', id, 103010000) +on duplicate key update name = values(name), + power_id=values(power_id), + menu_id = values(menu_id); + +insert into t_operation(id, name, code, power_id, element_id, parent_id) +values (1010101, '查询当前用户信息', 'common:user:self', id, 1010100, null), + (101010101, '查询所有角色', 'system:role:get', id, 101010100, null), + (101010102, '添加角色', 'system:role:add', id, 101010100, null), + (101010103, '删除角色', 'system:role:delete', id, 101010100, null), + (101010104, '修改角色', 'system:role:modify', id, 101010100, null), + (102010101, '查询所有用户组', 'system:group:get', id, 102010100, null), + (102010102, '添加用户组', 'system:group:add', id, 102010100, null), + (102010103, '删除用户组', 'system:group:delete', id, 102010100, null), + (102010104, '修改用户组', 'system:group:modify', id, 102010100, null), + (103010101, '查看所有用户', 'system:user:get', id, 103010100, null), + (103010102, '查看单个用户', 'system:user:one', id, 103010100, null), + (103010103, '添加用户', 'system:user:add', id, 103010100, null), + (103010104, '删除用户', 'system:user:delete', id, 103010100, null), + (103010105, '修改用户', 'system:user:modify', id, 103010100, null) +on duplicate key update name=values(name), + code=values(code), + power_id=values(power_id), + element_id=values(element_id), + parent_id=values(parent_id); \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231023__Add_table_'t_power_type'.sql b/src/main/resources/db/migration/V1_0_0_231023__Add_table_'t_power_type'.sql new file mode 100644 index 0000000..2096872 --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231023__Add_table_'t_power_type'.sql @@ -0,0 +1,7 @@ +drop table if exists t_power_type; + +create table if not exists t_power_type +( + id bigint not null primary key, + name varchar(50) not null comment '权限类型名' +) comment '权限类型'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231024__Add_table_'t_power'.sql b/src/main/resources/db/migration/V1_0_0_231024__Add_table_'t_power'.sql new file mode 100644 index 0000000..bd32054 --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231024__Add_table_'t_power'.sql @@ -0,0 +1,7 @@ +drop table if exists t_power; + +create table if not exists t_power +( + `id` bigint not null primary key, + `type_id` bigint not null comment '权限类型' +) comment '权限'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231025__Add_table_'t_menu'.sql b/src/main/resources/db/migration/V1_0_0_231025__Add_table_'t_menu'.sql new file mode 100644 index 0000000..d85e070 --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231025__Add_table_'t_menu'.sql @@ -0,0 +1,10 @@ +drop table if exists t_menu; + +create table if not exists t_menu +( + `id` bigint not null primary key, + `name` varchar(30) not null comment ' 菜单名', + `url` varchar(100) null comment 'URL', + `power_id` bigint not null comment '权限ID', + `parent_id` bigint null comment '父ID' +) comment '菜单'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql b/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql new file mode 100644 index 0000000..1175c69 --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql @@ -0,0 +1,9 @@ +drop table if exists t_element; + +create table if not exists t_element +( + `id` bigint not null primary key, + `name` varchar(100) not null comment '元素名', + `power_id` bigint not null comment '权限ID', + `menu_id` bigint not null comment '菜单ID' +) comment '页面元素'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231027__Add_table_'t_operation'.sql b/src/main/resources/db/migration/V1_0_0_231027__Add_table_'t_operation'.sql new file mode 100644 index 0000000..dc73326 --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231027__Add_table_'t_operation'.sql @@ -0,0 +1,11 @@ +drop table if exists t_operation; + +create table if not exists t_operation +( + `id` bigint not null primary key, + `name` varchar(50) not null comment '功能名', + `code` varchar(50) null comment '功能编码', + `power_id` bigint not null comment '权限ID', + `parent_id` bigint null comment '父ID', + `element_id` bigint not null comment '页面元素ID' +) comment '功能'; \ No newline at end of file From 087e6ae8c32ef4940bcd1ecd37b76238452334f2 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 23 Oct 2023 17:28:33 +0800 Subject: [PATCH 051/258] Optimize code --- .../top/fatweb/api/controller/system/SysLogController.kt | 2 +- .../kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt | 8 ++++---- .../top/fatweb/api/service/system/ISysLogService.kt | 2 +- .../fatweb/api/service/system/impl/SysLogServiceImpl.kt | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt b/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt index af7533c..1e8b0db 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.controller.system; +package top.fatweb.api.controller.system import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag diff --git a/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt index 110ffce..857a59a 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt +++ b/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.system; +package top.fatweb.api.mapper.system -import top.fatweb.api.entity.system.SysLog; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Mapper; +import top.fatweb.api.entity.system.SysLog +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper /** *

diff --git a/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt b/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt index 50287ec..4938d41 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.service.system; +package top.fatweb.api.service.system import com.baomidou.mybatisplus.core.metadata.IPage import com.baomidou.mybatisplus.extension.service.IService diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt index ec6c0d5..10cfa10 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt @@ -1,7 +1,6 @@ -package top.fatweb.api.service.system.impl; +package top.fatweb.api.service.system.impl import com.baomidou.mybatisplus.core.metadata.IPage -import com.baomidou.mybatisplus.core.toolkit.Wrappers import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl From 979d1d8fb89b5357f038e1631b4bd28e3eb544d4 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 25 Oct 2023 11:02:40 +0800 Subject: [PATCH 052/258] Add group role tables --- .../top/fatweb/api/config/InitConfig.kt | 2 +- .../fatweb/api/entity/permission/Element.kt | 43 +++++++++++++++ .../top/fatweb/api/entity/permission/Group.kt | 46 ++++++++++++++++ .../top/fatweb/api/entity/permission/Menu.kt | 49 +++++++++++++++++ .../fatweb/api/entity/permission/Operation.kt | 55 +++++++++++++++++++ .../top/fatweb/api/entity/permission/Power.kt | 31 +++++++++++ .../fatweb/api/entity/permission/PowerRole.kt | 43 +++++++++++++++ .../fatweb/api/entity/permission/PowerType.kt | 31 +++++++++++ .../top/fatweb/api/entity/permission/Role.kt | 55 +++++++++++++++++++ .../fatweb/api/entity/permission/RoleGroup.kt | 43 +++++++++++++++ .../top/fatweb/api/entity/permission/User.kt | 17 +++++- .../fatweb/api/entity/permission/UserGroup.kt | 43 +++++++++++++++ .../fatweb/api/entity/permission/UserRole.kt | 43 +++++++++++++++ .../api/mapper/permission/ElementMapper.kt | 16 ++++++ .../api/mapper/permission/GroupMapper.kt | 16 ++++++ .../api/mapper/permission/MenuMapper.kt | 16 ++++++ .../api/mapper/permission/OperationMapper.kt | 16 ++++++ .../api/mapper/permission/PowerMapper.kt | 16 ++++++ .../api/mapper/permission/PowerRoleMapper.kt | 16 ++++++ .../api/mapper/permission/PowerTypeMapper.kt | 16 ++++++ .../api/mapper/permission/RoleGroupMapper.kt | 16 ++++++ .../api/mapper/permission/RoleMapper.kt | 16 ++++++ .../api/mapper/permission/UserGroupMapper.kt | 16 ++++++ .../api/mapper/{ => permission}/UserMapper.kt | 2 +- .../api/mapper/permission/UserRoleMapper.kt | 16 ++++++ .../api/service/permission/IElementService.kt | 14 +++++ .../api/service/permission/IGroupService.kt | 14 +++++ .../api/service/permission/IMenuService.kt | 14 +++++ .../service/permission/IOperationService.kt | 14 +++++ .../service/permission/IPowerRoleService.kt | 14 +++++ .../api/service/permission/IPowerService.kt | 14 +++++ .../service/permission/IPowerTypeService.kt | 14 +++++ .../service/permission/IRoleGroupService.kt | 14 +++++ .../api/service/permission/IRoleService.kt | 14 +++++ .../service/permission/IUserGroupService.kt | 14 +++++ .../service/permission/IUserRoleService.kt | 14 +++++ .../service/{ => permission}/IUserService.kt | 2 +- .../impl/AuthenticationServiceImpl.kt | 2 +- .../permission/impl/ElementServiceImpl.kt | 18 ++++++ .../permission/impl/GroupServiceImpl.kt | 18 ++++++ .../permission/impl/MenuServiceImpl.kt | 18 ++++++ .../permission/impl/OperationServiceImpl.kt | 18 ++++++ .../permission/impl/PowerRoleServiceImpl.kt | 18 ++++++ .../permission/impl/PowerServiceImpl.kt | 18 ++++++ .../permission/impl/PowerTypeServiceImpl.kt | 18 ++++++ .../permission/impl/RoleGroupServiceImpl.kt | 18 ++++++ .../permission/impl/RoleServiceImpl.kt | 18 ++++++ .../permission/impl/UserDetailsServiceImpl.kt | 2 +- .../permission/impl/UserGroupServiceImpl.kt | 18 ++++++ .../permission/impl/UserRoleServiceImpl.kt | 18 ++++++ .../{ => permission}/impl/UserServiceImpl.kt | 6 +- .../resources/db/migration/R__Basic_data.sql | 6 +- .../V1_0_0_231024__Add_table_'t_power'.sql | 4 +- .../V1_0_0_231025__Add_table_'t_menu'.sql | 10 ++-- .../V1_0_0_231026__Add_table_'t_element'.sql | 8 +-- ...V1_0_0_231027__Add_table_'t_operation'.sql | 12 ++-- .../V1_0_0_231028__Add_table_'t_group'.sql | 11 ++++ ...1_0_0_231029__Add_table_'t_user_group'.sql | 10 ++++ .../V1_0_0_231030__Add_table_'t_role'.sql | 11 ++++ ...1_0_0_231031__Add_table_'t_role_group'.sql | 10 ++++ ...V1_0_0_231101__Add_table_'t_user_role'.sql | 10 ++++ ...1_0_0_231102__Add_table_'t_power_role'.sql | 10 ++++ .../mapper/permission/ElementMapper.xml | 5 ++ .../mapper/permission/GroupMapper.xml | 5 ++ .../mapper/permission/MenuMapper.xml | 5 ++ .../mapper/permission/OperationMapper.xml | 5 ++ .../mapper/permission/PowerMapper.xml | 5 ++ .../mapper/permission/PowerRoleMapper.xml | 5 ++ .../mapper/permission/PowerTypeMapper.xml | 5 ++ .../mapper/permission/RoleGroupMapper.xml | 5 ++ .../mapper/permission/RoleMapper.xml | 5 ++ .../mapper/permission/UserGroupMapper.xml | 5 ++ .../mapper/{ => permission}/UserMapper.xml | 2 +- .../mapper/permission/UserRoleMapper.xml | 5 ++ .../mapper/{ => system}/SysLogMapper.xml | 0 75 files changed, 1172 insertions(+), 30 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/Element.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/Group.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/Menu.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/Operation.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/Power.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/PowerRole.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/PowerType.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/Role.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/RoleGroup.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/UserGroup.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/permission/UserRole.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/permission/ElementMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/permission/GroupMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/permission/MenuMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/permission/OperationMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/permission/PowerMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/permission/PowerRoleMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/permission/PowerTypeMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/permission/RoleGroupMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/permission/RoleMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/permission/UserGroupMapper.kt rename src/main/kotlin/top/fatweb/api/mapper/{ => permission}/UserMapper.kt (87%) create mode 100644 src/main/kotlin/top/fatweb/api/mapper/permission/UserRoleMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IElementService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IGroupService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IMenuService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IOperationService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IPowerRoleService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IPowerService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IPowerTypeService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IRoleGroupService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IUserGroupService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/IUserRoleService.kt rename src/main/kotlin/top/fatweb/api/service/{ => permission}/IUserService.kt (84%) create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/ElementServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/GroupServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/MenuServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/OperationServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/PowerRoleServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/PowerServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/PowerTypeServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/RoleGroupServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/RoleServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/UserGroupServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/permission/impl/UserRoleServiceImpl.kt rename src/main/kotlin/top/fatweb/api/service/{ => permission}/impl/UserServiceImpl.kt (68%) create mode 100644 src/main/resources/db/migration/V1_0_0_231028__Add_table_'t_group'.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231029__Add_table_'t_user_group'.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231030__Add_table_'t_role'.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231031__Add_table_'t_role_group'.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231101__Add_table_'t_user_role'.sql create mode 100644 src/main/resources/db/migration/V1_0_0_231102__Add_table_'t_power_role'.sql create mode 100644 src/main/resources/mapper/permission/ElementMapper.xml create mode 100644 src/main/resources/mapper/permission/GroupMapper.xml create mode 100644 src/main/resources/mapper/permission/MenuMapper.xml create mode 100644 src/main/resources/mapper/permission/OperationMapper.xml create mode 100644 src/main/resources/mapper/permission/PowerMapper.xml create mode 100644 src/main/resources/mapper/permission/PowerRoleMapper.xml create mode 100644 src/main/resources/mapper/permission/PowerTypeMapper.xml create mode 100644 src/main/resources/mapper/permission/RoleGroupMapper.xml create mode 100644 src/main/resources/mapper/permission/RoleMapper.xml create mode 100644 src/main/resources/mapper/permission/UserGroupMapper.xml rename src/main/resources/mapper/{ => permission}/UserMapper.xml (70%) create mode 100644 src/main/resources/mapper/permission/UserRoleMapper.xml rename src/main/resources/mapper/{ => system}/SysLogMapper.xml (100%) diff --git a/src/main/kotlin/top/fatweb/api/config/InitConfig.kt b/src/main/kotlin/top/fatweb/api/config/InitConfig.kt index 14b6858..abb56fc 100644 --- a/src/main/kotlin/top/fatweb/api/config/InitConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/InitConfig.kt @@ -7,7 +7,7 @@ import org.slf4j.LoggerFactory import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Component import top.fatweb.api.entity.permission.User -import top.fatweb.api.service.IUserService +import top.fatweb.api.service.permission.IUserService import kotlin.random.Random @Component diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Element.kt b/src/main/kotlin/top/fatweb/api/entity/permission/Element.kt new file mode 100644 index 0000000..a285141 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/Element.kt @@ -0,0 +1,43 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableName +import java.io.Serializable + +/** + *

+ * 页面元素 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@TableName("t_element") +class Element : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 元素名 + */ + @TableField("name") + var name: String? = null + + /** + * 权限ID + */ + @TableField("power_id") + var powerId: Long? = null + + /** + * 菜单ID + */ + @TableField("menu_id") + var menuId: Long? = null + + override fun toString(): String { + return "Element(id=$id, name=$name, powerId=$powerId, menuId=$menuId)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Group.kt b/src/main/kotlin/top/fatweb/api/entity/permission/Group.kt new file mode 100644 index 0000000..3a1fc11 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/Group.kt @@ -0,0 +1,46 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable + +/** + *

+ * 用户组 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@TableName("t_group") +class Group : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 用户组名 + */ + @TableField("name") + var name: String? = null + + /** + * 启用 + */ + @TableField("enable") + var enable: Int? = null + + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + @TableField("version") + @Version + var version: Int? = null + + @TableField(exist = false) + var roles: List? = null + + override fun toString(): String { + return "Group(id=$id, name=$name, enable=$enable, deleted=$deleted, version=$version, roles=$roles)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Menu.kt b/src/main/kotlin/top/fatweb/api/entity/permission/Menu.kt new file mode 100644 index 0000000..a2559e7 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/Menu.kt @@ -0,0 +1,49 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableName +import java.io.Serializable + +/** + *

+ * 菜单 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@TableName("t_menu") +class Menu : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 菜单名 + */ + @TableField("name") + var name: String? = null + + /** + * URL + */ + @TableField("url") + var url: String? = null + + /** + * 权限ID + */ + @TableField("power_id") + var powerId: Long? = null + + /** + * 父ID + */ + @TableField("parent_id") + var parentId: Long? = null + + override fun toString(): String { + return "Menu(id=$id, name=$name, url=$url, powerId=$powerId, parentId=$parentId)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Operation.kt b/src/main/kotlin/top/fatweb/api/entity/permission/Operation.kt new file mode 100644 index 0000000..f9a713a --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/Operation.kt @@ -0,0 +1,55 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableName +import java.io.Serializable + +/** + *

+ * 功能 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@TableName("t_operation") +class Operation : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 功能名 + */ + @TableField("name") + var name: String? = null + + /** + * 功能编码 + */ + @TableField("code") + var code: String? = null + + /** + * 权限ID + */ + @TableField("power_id") + var powerId: Long? = null + + /** + * 父ID + */ + @TableField("parent_id") + var parentId: Long? = null + + /** + * 页面元素ID + */ + @TableField("element_id") + var elementId: Long? = null + + override fun toString(): String { + return "Operation(id=$id, name=$name, code=$code, powerId=$powerId, parentId=$parentId, elementId=$elementId)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Power.kt b/src/main/kotlin/top/fatweb/api/entity/permission/Power.kt new file mode 100644 index 0000000..4e52fdd --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/Power.kt @@ -0,0 +1,31 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableName +import java.io.Serializable + +/** + *

+ * 权限 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@TableName("t_power") +class Power : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 权限类型 + */ + @TableField("type_id") + var typeId: Long? = null + + override fun toString(): String { + return "Power(id=$id, typeId=$typeId)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/PowerRole.kt b/src/main/kotlin/top/fatweb/api/entity/permission/PowerRole.kt new file mode 100644 index 0000000..43c87af --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/PowerRole.kt @@ -0,0 +1,43 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable + +/** + *

+ * 中间表-权限-角色 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@TableName("t_power_role") +class PowerRole : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 权限 + */ + @TableField("power_id") + var powerId: Long? = null + + /** + * 角色 + */ + @TableField("role_id") + var roleId: Long? = null + + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + @TableField("version") + @Version + var version: Int? = null + + override fun toString(): String { + return "PowerRole(id=$id, powerId=$powerId, roleId=$roleId, deleted=$deleted, version=$version)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/PowerType.kt b/src/main/kotlin/top/fatweb/api/entity/permission/PowerType.kt new file mode 100644 index 0000000..1f69a83 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/PowerType.kt @@ -0,0 +1,31 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableName +import java.io.Serializable + +/** + *

+ * 权限类型 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@TableName("t_power_type") +class PowerType : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 权限类型名 + */ + @TableField("name") + var name: String? = null + + override fun toString(): String { + return "PowerType(id=$id, name=$name)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Role.kt b/src/main/kotlin/top/fatweb/api/entity/permission/Role.kt new file mode 100644 index 0000000..c55a604 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/Role.kt @@ -0,0 +1,55 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable + +/** + *

+ * 角色 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@TableName("t_role") +class Role : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 角色名 + */ + @TableField("name") + var name: String? = null + + /** + * 启用 + */ + @TableField("enable") + var enable: Int? = null + + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + @TableField("version") + @Version + var version: Int? = null + + @TableField(exist = false) + var menus: List? = null + + @TableField(exist = false) + var elements: List? = null + + @TableField(exist = false) + var operations: List? = null + + @TableField(exist = false) + var powers: List? = null + + override fun toString(): String { + return "Role(id=$id, name=$name, enable=$enable, deleted=$deleted, version=$version, menus=$menus, elements=$elements, operations=$operations, powers=$powers)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/RoleGroup.kt b/src/main/kotlin/top/fatweb/api/entity/permission/RoleGroup.kt new file mode 100644 index 0000000..2d780b5 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/RoleGroup.kt @@ -0,0 +1,43 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable + +/** + *

+ * 中间表-角色-用户组 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@TableName("t_role_group") +class RoleGroup : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 角色 + */ + @TableField("role_id") + var roleId: Long? = null + + /** + * 群组 + */ + @TableField("group_id") + var groupId: Long? = null + + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + @TableField("version") + @Version + var version: Int? = null + + override fun toString(): String { + return "RoleGroup(id=$id, roleId=$roleId, groupId=$groupId, deleted=$deleted, version=$version)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/User.kt b/src/main/kotlin/top/fatweb/api/entity/permission/User.kt index 8277f73..2956bf0 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/User.kt +++ b/src/main/kotlin/top/fatweb/api/entity/permission/User.kt @@ -92,7 +92,22 @@ class User() : Serializable { @Version var version: Int? = null + @TableField(exist = false) + var roles: List? = null + + @TableField(exist = false) + var groups: List? = null + + @TableField(exist = false) + var menus: List? = null + + @TableField(exist = false) + var elements: List? = null + + @TableField(exist = false) + var operations: List? = null + override fun toString(): String { - return "User(id=$id, username=$username, password=$password, locking=$locking, expiration=$expiration, credentialsExpiration=$credentialsExpiration, enable=$enable, lastLoginTime=$lastLoginTime, lastLoginIp=$lastLoginIp, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)" + return "User(id=$id, username=$username, password=$password, locking=$locking, expiration=$expiration, credentialsExpiration=$credentialsExpiration, enable=$enable, lastLoginTime=$lastLoginTime, lastLoginIp=$lastLoginIp, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, roles=$roles, groups=$groups, menus=$menus, elements=$elements, operations=$operations)" } } diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/UserGroup.kt b/src/main/kotlin/top/fatweb/api/entity/permission/UserGroup.kt new file mode 100644 index 0000000..ad2264f --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/UserGroup.kt @@ -0,0 +1,43 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable + +/** + *

+ * 中间表-用户-用户组 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@TableName("t_user_group") +class UserGroup : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 用户 + */ + @TableField("user_id") + var userId: Long? = null + + /** + * 用户组 + */ + @TableField("group_id") + var groupId: Long? = null + + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + @TableField("version") + @Version + var version: Int? = null + + override fun toString(): String { + return "UserGroup(id=$id, userId=$userId, groupId=$groupId, deleted=$deleted, version=$version)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/UserRole.kt b/src/main/kotlin/top/fatweb/api/entity/permission/UserRole.kt new file mode 100644 index 0000000..ffd6c49 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/UserRole.kt @@ -0,0 +1,43 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable + +/** + *

+ * 中间表-用户-角色 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@TableName("t_user_role") +class UserRole : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 用户 + */ + @TableField("user_id") + var userId: Long? = null + + /** + * 角色 + */ + @TableField("role_id") + var roleId: Long? = null + + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + @TableField("version") + @Version + var version: Int? = null + + override fun toString(): String { + return "UserRole(id=$id, userId=$userId, roleId=$roleId, deleted=$deleted, version=$version)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/ElementMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/ElementMapper.kt new file mode 100644 index 0000000..62d9ac3 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/ElementMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.Element + +/** + *

+ * 页面元素 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Mapper +interface ElementMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/GroupMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/GroupMapper.kt new file mode 100644 index 0000000..cba8e5f --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/GroupMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.Group + +/** + *

+ * 用户组 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Mapper +interface GroupMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/MenuMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/MenuMapper.kt new file mode 100644 index 0000000..c952d58 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/MenuMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.Menu + +/** + *

+ * 菜单 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Mapper +interface MenuMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/OperationMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/OperationMapper.kt new file mode 100644 index 0000000..169bb7d --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/OperationMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.Operation + +/** + *

+ * 功能 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Mapper +interface OperationMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/PowerMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/PowerMapper.kt new file mode 100644 index 0000000..fbeb8cd --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/PowerMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.Power + +/** + *

+ * 权限 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Mapper +interface PowerMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/PowerRoleMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/PowerRoleMapper.kt new file mode 100644 index 0000000..565416d --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/PowerRoleMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.PowerRole + +/** + *

+ * 中间表-权限-角色 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Mapper +interface PowerRoleMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/PowerTypeMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/PowerTypeMapper.kt new file mode 100644 index 0000000..6616e89 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/PowerTypeMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.PowerType + +/** + *

+ * 权限类型 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Mapper +interface PowerTypeMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/RoleGroupMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/RoleGroupMapper.kt new file mode 100644 index 0000000..6d8e73a --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/RoleGroupMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.RoleGroup + +/** + *

+ * 中间表-角色-用户组 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Mapper +interface RoleGroupMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/RoleMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/RoleMapper.kt new file mode 100644 index 0000000..36881ad --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/RoleMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.Role + +/** + *

+ * 角色 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Mapper +interface RoleMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/UserGroupMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/UserGroupMapper.kt new file mode 100644 index 0000000..5dac8dd --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/UserGroupMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.UserGroup + +/** + *

+ * 中间表-用户-用户组 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Mapper +interface UserGroupMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/UserMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt similarity index 87% rename from src/main/kotlin/top/fatweb/api/mapper/UserMapper.kt rename to src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt index 8b37df3..2dc6d5f 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/UserMapper.kt +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.mapper +package top.fatweb.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/UserRoleMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/UserRoleMapper.kt new file mode 100644 index 0000000..d6f5478 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/UserRoleMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.UserRole + +/** + *

+ * 中间表-用户-角色 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Mapper +interface UserRoleMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IElementService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IElementService.kt new file mode 100644 index 0000000..eaacea3 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IElementService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.Element + +/** + *

+ * 页面元素 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +interface IElementService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IGroupService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IGroupService.kt new file mode 100644 index 0000000..94f8aa0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IGroupService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.Group + +/** + *

+ * 用户组 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +interface IGroupService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IMenuService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IMenuService.kt new file mode 100644 index 0000000..6267758 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IMenuService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.Menu + +/** + *

+ * 菜单 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +interface IMenuService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IOperationService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IOperationService.kt new file mode 100644 index 0000000..0bac5b1 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IOperationService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.Operation + +/** + *

+ * 功能 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +interface IOperationService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IPowerRoleService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IPowerRoleService.kt new file mode 100644 index 0000000..8b8e0e3 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IPowerRoleService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.PowerRole + +/** + *

+ * 中间表-权限-角色 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +interface IPowerRoleService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IPowerService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IPowerService.kt new file mode 100644 index 0000000..03b0d45 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IPowerService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.Power + +/** + *

+ * 权限 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +interface IPowerService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IPowerTypeService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IPowerTypeService.kt new file mode 100644 index 0000000..ecc0491 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IPowerTypeService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.PowerType + +/** + *

+ * 权限类型 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +interface IPowerTypeService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IRoleGroupService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IRoleGroupService.kt new file mode 100644 index 0000000..30ce26b --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IRoleGroupService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.RoleGroup + +/** + *

+ * 中间表-角色-用户组 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +interface IRoleGroupService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt new file mode 100644 index 0000000..f9c46a0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.Role + +/** + *

+ * 角色 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +interface IRoleService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IUserGroupService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IUserGroupService.kt new file mode 100644 index 0000000..0356954 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IUserGroupService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.UserGroup + +/** + *

+ * 中间表-用户-用户组 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +interface IUserGroupService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IUserRoleService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IUserRoleService.kt new file mode 100644 index 0000000..be86fef --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IUserRoleService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.UserRole + +/** + *

+ * 中间表-用户-角色 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +interface IUserRoleService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/IUserService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt similarity index 84% rename from src/main/kotlin/top/fatweb/api/service/IUserService.kt rename to src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt index 7bc58e9..1e546ea 100644 --- a/src/main/kotlin/top/fatweb/api/service/IUserService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.service +package top.fatweb.api.service.permission import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.api.entity.permission.User diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index eb8c765..e7947ec 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -11,8 +11,8 @@ import top.fatweb.api.constant.SecurityConstants import top.fatweb.api.entity.permission.LoginUser import top.fatweb.api.entity.permission.User import top.fatweb.api.exception.TokenHasExpiredException -import top.fatweb.api.service.IUserService import top.fatweb.api.service.permission.IAuthenticationService +import top.fatweb.api.service.permission.IUserService import top.fatweb.api.util.JwtUtil import top.fatweb.api.util.RedisUtil import top.fatweb.api.util.WebUtil diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/ElementServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/ElementServiceImpl.kt new file mode 100644 index 0000000..70bb88f --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/ElementServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.Element +import top.fatweb.api.mapper.permission.ElementMapper +import top.fatweb.api.service.permission.IElementService + +/** + *

+ * 页面元素 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Service +class ElementServiceImpl : ServiceImpl(), IElementService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/GroupServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/GroupServiceImpl.kt new file mode 100644 index 0000000..92c06ae --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/GroupServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.Group +import top.fatweb.api.mapper.permission.GroupMapper +import top.fatweb.api.service.permission.IGroupService + +/** + *

+ * 用户组 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Service +class GroupServiceImpl : ServiceImpl(), IGroupService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/MenuServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/MenuServiceImpl.kt new file mode 100644 index 0000000..d431903 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/MenuServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.Menu +import top.fatweb.api.mapper.permission.MenuMapper +import top.fatweb.api.service.permission.IMenuService + +/** + *

+ * 菜单 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Service +class MenuServiceImpl : ServiceImpl(), IMenuService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/OperationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/OperationServiceImpl.kt new file mode 100644 index 0000000..44076ad --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/OperationServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.Operation +import top.fatweb.api.mapper.permission.OperationMapper +import top.fatweb.api.service.permission.IOperationService + +/** + *

+ * 功能 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Service +class OperationServiceImpl : ServiceImpl(), IOperationService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerRoleServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerRoleServiceImpl.kt new file mode 100644 index 0000000..1dafe8b --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerRoleServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.PowerRole +import top.fatweb.api.mapper.permission.PowerRoleMapper +import top.fatweb.api.service.permission.IPowerRoleService + +/** + *

+ * 中间表-权限-角色 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Service +class PowerRoleServiceImpl : ServiceImpl(), IPowerRoleService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerServiceImpl.kt new file mode 100644 index 0000000..70fdc17 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.Power +import top.fatweb.api.mapper.permission.PowerMapper +import top.fatweb.api.service.permission.IPowerService + +/** + *

+ * 权限 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Service +class PowerServiceImpl : ServiceImpl(), IPowerService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerTypeServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerTypeServiceImpl.kt new file mode 100644 index 0000000..481a0aa --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerTypeServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.PowerType +import top.fatweb.api.mapper.permission.PowerTypeMapper +import top.fatweb.api.service.permission.IPowerTypeService + +/** + *

+ * 权限类型 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Service +class PowerTypeServiceImpl : ServiceImpl(), IPowerTypeService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleGroupServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleGroupServiceImpl.kt new file mode 100644 index 0000000..002c299 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleGroupServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.RoleGroup +import top.fatweb.api.mapper.permission.RoleGroupMapper +import top.fatweb.api.service.permission.IRoleGroupService + +/** + *

+ * 中间表-角色-用户组 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Service +class RoleGroupServiceImpl : ServiceImpl(), IRoleGroupService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleServiceImpl.kt new file mode 100644 index 0000000..c75703d --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.Role +import top.fatweb.api.mapper.permission.RoleMapper +import top.fatweb.api.service.permission.IRoleService + +/** + *

+ * 角色 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Service +class RoleServiceImpl : ServiceImpl(), IRoleService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt index 6b78e76..db65f6b 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt @@ -6,7 +6,7 @@ import org.springframework.security.core.userdetails.UserDetailsService import org.springframework.stereotype.Service import top.fatweb.api.entity.permission.LoginUser import top.fatweb.api.entity.permission.User -import top.fatweb.api.service.IUserService +import top.fatweb.api.service.permission.IUserService @Service class UserDetailsServiceImpl(val userService: IUserService) : UserDetailsService { diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserGroupServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserGroupServiceImpl.kt new file mode 100644 index 0000000..7bcfd5d --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserGroupServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.UserGroup +import top.fatweb.api.mapper.permission.UserGroupMapper +import top.fatweb.api.service.permission.IUserGroupService + +/** + *

+ * 中间表-用户-用户组 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Service +class UserGroupServiceImpl : ServiceImpl(), IUserGroupService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserRoleServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserRoleServiceImpl.kt new file mode 100644 index 0000000..e89f64d --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserRoleServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.UserRole +import top.fatweb.api.mapper.permission.UserRoleMapper +import top.fatweb.api.service.permission.IUserRoleService + +/** + *

+ * 中间表-用户-角色 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-25 + */ +@Service +class UserRoleServiceImpl : ServiceImpl(), IUserRoleService diff --git a/src/main/kotlin/top/fatweb/api/service/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt similarity index 68% rename from src/main/kotlin/top/fatweb/api/service/impl/UserServiceImpl.kt rename to src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt index e522f6b..2b213b2 100644 --- a/src/main/kotlin/top/fatweb/api/service/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.impl +package top.fatweb.api.service.permission.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service import top.fatweb.api.entity.permission.User -import top.fatweb.api.mapper.UserMapper -import top.fatweb.api.service.IUserService +import top.fatweb.api.mapper.permission.UserMapper +import top.fatweb.api.service.permission.IUserService /** *

diff --git a/src/main/resources/db/migration/R__Basic_data.sql b/src/main/resources/db/migration/R__Basic_data.sql index 6dfc7db..e9d4747 100644 --- a/src/main/resources/db/migration/R__Basic_data.sql +++ b/src/main/resources/db/migration/R__Basic_data.sql @@ -41,9 +41,9 @@ on duplicate key update name = values(name), insert into t_element(id, name, power_id, menu_id) values (1010100, '公用', id, 1010000), - (101010100, '基础', id, 101010000), - (102010100, '基础', id, 102010000), - (103010100, '基础', id, 103010000) + (101010100, '角色基础', id, 101010000), + (102010100, '用户组基础', id, 102010000), + (103010100, '用户基础', id, 103010000) on duplicate key update name = values(name), power_id=values(power_id), menu_id = values(menu_id); diff --git a/src/main/resources/db/migration/V1_0_0_231024__Add_table_'t_power'.sql b/src/main/resources/db/migration/V1_0_0_231024__Add_table_'t_power'.sql index bd32054..b7ba089 100644 --- a/src/main/resources/db/migration/V1_0_0_231024__Add_table_'t_power'.sql +++ b/src/main/resources/db/migration/V1_0_0_231024__Add_table_'t_power'.sql @@ -2,6 +2,6 @@ drop table if exists t_power; create table if not exists t_power ( - `id` bigint not null primary key, - `type_id` bigint not null comment '权限类型' + id bigint not null primary key, + type_id bigint not null comment '权限类型' ) comment '权限'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231025__Add_table_'t_menu'.sql b/src/main/resources/db/migration/V1_0_0_231025__Add_table_'t_menu'.sql index d85e070..7d7e26f 100644 --- a/src/main/resources/db/migration/V1_0_0_231025__Add_table_'t_menu'.sql +++ b/src/main/resources/db/migration/V1_0_0_231025__Add_table_'t_menu'.sql @@ -2,9 +2,9 @@ drop table if exists t_menu; create table if not exists t_menu ( - `id` bigint not null primary key, - `name` varchar(30) not null comment ' 菜单名', - `url` varchar(100) null comment 'URL', - `power_id` bigint not null comment '权限ID', - `parent_id` bigint null comment '父ID' + id bigint not null primary key, + name varchar(30) not null comment ' 菜单名', + url varchar(100) null comment 'URL', + power_id bigint not null comment '权限ID', + parent_id bigint null comment '父ID' ) comment '菜单'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql b/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql index 1175c69..27bc46c 100644 --- a/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql +++ b/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql @@ -2,8 +2,8 @@ drop table if exists t_element; create table if not exists t_element ( - `id` bigint not null primary key, - `name` varchar(100) not null comment '元素名', - `power_id` bigint not null comment '权限ID', - `menu_id` bigint not null comment '菜单ID' + id bigint not null primary key, + name varchar(100) not null comment '元素名', + power_id bigint not null comment '权限ID', + menu_id bigint not null comment '菜单ID' ) comment '页面元素'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231027__Add_table_'t_operation'.sql b/src/main/resources/db/migration/V1_0_0_231027__Add_table_'t_operation'.sql index dc73326..b239e1b 100644 --- a/src/main/resources/db/migration/V1_0_0_231027__Add_table_'t_operation'.sql +++ b/src/main/resources/db/migration/V1_0_0_231027__Add_table_'t_operation'.sql @@ -2,10 +2,10 @@ drop table if exists t_operation; create table if not exists t_operation ( - `id` bigint not null primary key, - `name` varchar(50) not null comment '功能名', - `code` varchar(50) null comment '功能编码', - `power_id` bigint not null comment '权限ID', - `parent_id` bigint null comment '父ID', - `element_id` bigint not null comment '页面元素ID' + id bigint not null primary key, + name varchar(50) not null comment '功能名', + code varchar(50) null comment '功能编码', + power_id bigint not null comment '权限ID', + parent_id bigint null comment '父ID', + element_id bigint not null comment '页面元素ID' ) comment '功能'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231028__Add_table_'t_group'.sql b/src/main/resources/db/migration/V1_0_0_231028__Add_table_'t_group'.sql new file mode 100644 index 0000000..9a4d162 --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231028__Add_table_'t_group'.sql @@ -0,0 +1,11 @@ +drop table if exists t_group; + +create table if not exists t_group +( + id bigint not null primary key, + name varchar(30) not null comment '用户组名', + enable int not null comment '启用', + deleted bigint not null default 0, + version int not null default 0, + constraint t_group_unique unique (name, deleted) +) comment '用户组'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231029__Add_table_'t_user_group'.sql b/src/main/resources/db/migration/V1_0_0_231029__Add_table_'t_user_group'.sql new file mode 100644 index 0000000..27ede64 --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231029__Add_table_'t_user_group'.sql @@ -0,0 +1,10 @@ +drop table if exists t_user_group; + +create table if not exists t_user_group +( + id bigint not null primary key, + user_id bigint not null comment '用户', + group_id bigint not null comment '用户组', + deleted bigint not null default 0, + version int not null default 0 +) comment '中间表-用户-用户组'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231030__Add_table_'t_role'.sql b/src/main/resources/db/migration/V1_0_0_231030__Add_table_'t_role'.sql new file mode 100644 index 0000000..7ace525 --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231030__Add_table_'t_role'.sql @@ -0,0 +1,11 @@ +drop table if exists t_role; + +create table if not exists t_role +( + id bigint not null primary key, + name varchar(20) not null comment '角色名', + enable int not null comment '启用', + deleted bigint not null default 0, + version int not null default 0, + constraint t_role_unique unique (name, deleted) +) comment '角色'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231031__Add_table_'t_role_group'.sql b/src/main/resources/db/migration/V1_0_0_231031__Add_table_'t_role_group'.sql new file mode 100644 index 0000000..9492e35 --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231031__Add_table_'t_role_group'.sql @@ -0,0 +1,10 @@ +drop table if exists t_role_group; + +create table if not exists t_role_group +( + id bigint not null primary key, + role_id bigint not null comment '角色', + group_id bigint not null comment '群组', + deleted bigint not null default 0, + version int not null default 0 +) comment '中间表-角色-用户组'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231101__Add_table_'t_user_role'.sql b/src/main/resources/db/migration/V1_0_0_231101__Add_table_'t_user_role'.sql new file mode 100644 index 0000000..27d674d --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231101__Add_table_'t_user_role'.sql @@ -0,0 +1,10 @@ +drop table if exists t_user_role; + +create table if not exists t_user_role +( + id bigint not null primary key, + user_id bigint not null comment '用户', + role_id bigint not null comment '角色', + deleted bigint not null default 0, + version int not null default 0 +) comment '中间表-用户-角色'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231102__Add_table_'t_power_role'.sql b/src/main/resources/db/migration/V1_0_0_231102__Add_table_'t_power_role'.sql new file mode 100644 index 0000000..854e78b --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231102__Add_table_'t_power_role'.sql @@ -0,0 +1,10 @@ +drop table if exists t_power_role; + +create table if not exists t_power_role +( + id bigint not null primary key, + power_id bigint not null comment '权限', + role_id bigint not null comment '角色', + deleted bigint not null default 0, + version int not null default 0 +) comment '中间表-权限-角色'; \ No newline at end of file diff --git a/src/main/resources/mapper/permission/ElementMapper.xml b/src/main/resources/mapper/permission/ElementMapper.xml new file mode 100644 index 0000000..f29cb9f --- /dev/null +++ b/src/main/resources/mapper/permission/ElementMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/permission/GroupMapper.xml b/src/main/resources/mapper/permission/GroupMapper.xml new file mode 100644 index 0000000..861ee18 --- /dev/null +++ b/src/main/resources/mapper/permission/GroupMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/permission/MenuMapper.xml b/src/main/resources/mapper/permission/MenuMapper.xml new file mode 100644 index 0000000..aaf1664 --- /dev/null +++ b/src/main/resources/mapper/permission/MenuMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/permission/OperationMapper.xml b/src/main/resources/mapper/permission/OperationMapper.xml new file mode 100644 index 0000000..174b17b --- /dev/null +++ b/src/main/resources/mapper/permission/OperationMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/permission/PowerMapper.xml b/src/main/resources/mapper/permission/PowerMapper.xml new file mode 100644 index 0000000..c9854f0 --- /dev/null +++ b/src/main/resources/mapper/permission/PowerMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/permission/PowerRoleMapper.xml b/src/main/resources/mapper/permission/PowerRoleMapper.xml new file mode 100644 index 0000000..3004952 --- /dev/null +++ b/src/main/resources/mapper/permission/PowerRoleMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/permission/PowerTypeMapper.xml b/src/main/resources/mapper/permission/PowerTypeMapper.xml new file mode 100644 index 0000000..8c3fe6e --- /dev/null +++ b/src/main/resources/mapper/permission/PowerTypeMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/permission/RoleGroupMapper.xml b/src/main/resources/mapper/permission/RoleGroupMapper.xml new file mode 100644 index 0000000..678e1eb --- /dev/null +++ b/src/main/resources/mapper/permission/RoleGroupMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/permission/RoleMapper.xml b/src/main/resources/mapper/permission/RoleMapper.xml new file mode 100644 index 0000000..b84d046 --- /dev/null +++ b/src/main/resources/mapper/permission/RoleMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/permission/UserGroupMapper.xml b/src/main/resources/mapper/permission/UserGroupMapper.xml new file mode 100644 index 0000000..9eaaad8 --- /dev/null +++ b/src/main/resources/mapper/permission/UserGroupMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/permission/UserMapper.xml similarity index 70% rename from src/main/resources/mapper/UserMapper.xml rename to src/main/resources/mapper/permission/UserMapper.xml index cecc32c..668c8e5 100644 --- a/src/main/resources/mapper/UserMapper.xml +++ b/src/main/resources/mapper/permission/UserMapper.xml @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/mapper/permission/UserRoleMapper.xml b/src/main/resources/mapper/permission/UserRoleMapper.xml new file mode 100644 index 0000000..9884516 --- /dev/null +++ b/src/main/resources/mapper/permission/UserRoleMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/SysLogMapper.xml b/src/main/resources/mapper/system/SysLogMapper.xml similarity index 100% rename from src/main/resources/mapper/SysLogMapper.xml rename to src/main/resources/mapper/system/SysLogMapper.xml From 2a364cfcfe9d67faba2da427ed42162b5800dc59 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 25 Oct 2023 18:25:28 +0800 Subject: [PATCH 053/258] Add power to login --- .../api/mapper/permission/UserMapper.kt | 5 +- .../api/service/permission/IUserService.kt | 4 +- .../permission/impl/UserDetailsServiceImpl.kt | 6 +- .../permission/impl/UserServiceImpl.kt | 22 ++++- .../resources/db/migration/R__Basic_data.sql | 10 ++- .../mapper/permission/UserMapper.xml | 83 +++++++++++++++++++ 6 files changed, 119 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt index 2dc6d5f..0adc77b 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt @@ -2,6 +2,7 @@ package top.fatweb.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper +import org.apache.ibatis.annotations.Param import top.fatweb.api.entity.permission.User /** @@ -13,4 +14,6 @@ import top.fatweb.api.entity.permission.User * @since 2023-10-04 */ @Mapper -interface UserMapper : BaseMapper +interface UserMapper : BaseMapper { + fun getOneWithPowerByUsername(@Param("username")username: String): User? +} diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt index 1e546ea..f5d988d 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt @@ -11,4 +11,6 @@ import top.fatweb.api.entity.permission.User * @author FatttSnake * @since 2023-10-04 */ -interface IUserService : IService +interface IUserService : IService { + fun getUserWithPower(username: String): User? +} diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt index db65f6b..e6847d7 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt @@ -1,17 +1,15 @@ package top.fatweb.api.service.permission.impl -import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import org.springframework.security.core.userdetails.UserDetails import org.springframework.security.core.userdetails.UserDetailsService import org.springframework.stereotype.Service import top.fatweb.api.entity.permission.LoginUser -import top.fatweb.api.entity.permission.User import top.fatweb.api.service.permission.IUserService @Service class UserDetailsServiceImpl(val userService: IUserService) : UserDetailsService { - override fun loadUserByUsername(username: String?): UserDetails { - val user = userService.getOne(KtQueryWrapper(User()).eq(User::username, username)) + override fun loadUserByUsername(username: String): UserDetails { + val user = userService.getUserWithPower(username) user ?: let { throw Exception("Username not found") } return LoginUser(user) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt index 2b213b2..c0efd37 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt @@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service import top.fatweb.api.entity.permission.User import top.fatweb.api.mapper.permission.UserMapper +import top.fatweb.api.service.permission.IElementService +import top.fatweb.api.service.permission.IMenuService +import top.fatweb.api.service.permission.IOperationService import top.fatweb.api.service.permission.IUserService /** @@ -15,4 +18,21 @@ import top.fatweb.api.service.permission.IUserService * @since 2023-10-04 */ @Service -class UserServiceImpl : ServiceImpl(), IUserService +class UserServiceImpl( + private val menuService: IMenuService, + private val elementService: IElementService, + private val operationService: IOperationService +) : ServiceImpl(), IUserService { + override fun getUserWithPower(username: String): User? { + val user = baseMapper.getOneWithPowerByUsername(username) + user ?: let { return null } + + if (user.id == 0L) { + user.menus = menuService.list() + user.elements = elementService.list() + user.operations = operationService.list() + } + + return user + } +} diff --git a/src/main/resources/db/migration/R__Basic_data.sql b/src/main/resources/db/migration/R__Basic_data.sql index e9d4747..3b94441 100644 --- a/src/main/resources/db/migration/R__Basic_data.sql +++ b/src/main/resources/db/migration/R__Basic_data.sql @@ -8,6 +8,7 @@ insert into t_power (id, type_id) values (1010000, 1), (1010100, 2), (1010101, 3), + (100010000, 1), (101010000, 1), (101010100, 2), (101010101, 3), @@ -30,10 +31,11 @@ values (1010000, 1), on duplicate key update type_id = values(type_id); insert into t_menu (id, name, url, power_id, parent_id) -values (1010000, '公用', '/', id, null), - (101010000, '角色管理(权限相关)', '/power/role', id, null), - (102010000, '用户组管理(权限相关)', '/power/group', id, null), - (103010000, '用户管理(权限相关)', '/power/user', id, null) +values (001010000, '公用', '/', id, null), + (100010000, '系统管理', '/system', id, null), + (101010000, '角色管理(权限相关)', '/power/role', id, 100010000), + (102010000, '用户组管理(权限相关)', '/power/group', id, 100010000), + (103010000, '用户管理(权限相关)', '/power/user', id, 100010000) on duplicate key update name = values(name), url = values(url), power_id = values(power_id), diff --git a/src/main/resources/mapper/permission/UserMapper.xml b/src/main/resources/mapper/permission/UserMapper.xml index 668c8e5..b18c79e 100644 --- a/src/main/resources/mapper/permission/UserMapper.xml +++ b/src/main/resources/mapper/permission/UserMapper.xml @@ -1,5 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 7aa22129767b64b216285e398ceafa9a91666ee3 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 26 Oct 2023 23:47:41 +0800 Subject: [PATCH 054/258] Temp --- .../fatweb/api/controller/UserController.kt | 17 ------------- .../controller/permission/UserController.kt | 25 +++++++++++++++++++ .../api/entity/common/ResponseResult.kt | 8 ++++++ .../api/service/permission/IUserService.kt | 2 ++ 4 files changed, 35 insertions(+), 17 deletions(-) delete mode 100644 src/main/kotlin/top/fatweb/api/controller/UserController.kt create mode 100644 src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt diff --git a/src/main/kotlin/top/fatweb/api/controller/UserController.kt b/src/main/kotlin/top/fatweb/api/controller/UserController.kt deleted file mode 100644 index 188caf5..0000000 --- a/src/main/kotlin/top/fatweb/api/controller/UserController.kt +++ /dev/null @@ -1,17 +0,0 @@ -package top.fatweb.api.controller - -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController - -/** - *

- * 用户 前端控制器 - *

- * - * @author FatttSnake - * @since 2023-10-04 - */ -@RestController -@RequestMapping("/api/user") -class UserController - diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt new file mode 100644 index 0000000..3b5a191 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt @@ -0,0 +1,25 @@ +package top.fatweb.api.controller.permission + +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController +import top.fatweb.api.service.permission.IUserService + +/** + *

+ * 用户 前端控制器 + *

+ * + * @author FatttSnake + * @since 2023-10-04 + */ +@RestController +@RequestMapping("/system/user") +class UserController( + private val userService: IUserService +) { + @GetMapping("info") + fun getInfo() { + } +} + diff --git a/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt b/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt index bbfde54..022c4b9 100644 --- a/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt +++ b/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt @@ -21,5 +21,13 @@ class ResponseResult private constructor( fun fail(code: ResponseCode = ResponseCode.SYSTEM_ERROR, msg: String = "fail", data: T? = null) = build(code, false, msg, data) + + fun databaseSuccess( + code: ResponseCode = ResponseCode.DATABASE_SELECT_SUCCESS, msg: String = "success", data: T? = null + ) = build(code, true, msg, data) + + fun databaseFail( + code: ResponseCode = ResponseCode.DATABASE_SELECT_FAILED, msg: String = "fail", data: T? = null + ) = build(code, false, msg, data) } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt index f5d988d..1634122 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt @@ -13,4 +13,6 @@ import top.fatweb.api.entity.permission.User */ interface IUserService : IService { fun getUserWithPower(username: String): User? + + fun getInfo(): User } From 11ceb410c871a148be0abc010eeb484d4c173440 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 27 Oct 2023 18:20:15 +0800 Subject: [PATCH 055/258] Add GetUserInfo --- .../controller/permission/UserController.kt | 8 +++- .../fatweb/api/converter/SysLogConverter.kt | 2 +- .../top/fatweb/api/converter/UserConverter.kt | 45 +++++++++++++++++++ .../fatweb/api/entity/permission/Element.kt | 6 +++ .../api/service/permission/IUserService.kt | 2 +- .../permission/impl/UserServiceImpl.kt | 4 ++ .../kotlin/top/fatweb/api/util/WebUtil.kt | 2 + .../fatweb/api/vo/authentication/ElementVo.kt | 20 +++++++++ .../fatweb/api/vo/authentication/MenuVo.kt | 20 +++++++++ .../api/vo/authentication/OperationVo.kt | 23 ++++++++++ .../api/vo/authentication/UserInfoVo.kt | 45 +++++++++++++++++++ .../V1_0_0_231026__Add_table_'t_element'.sql | 9 ++-- .../mapper/permission/UserMapper.xml | 2 + 13 files changed, 181 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/vo/authentication/ElementVo.kt create mode 100644 src/main/kotlin/top/fatweb/api/vo/authentication/MenuVo.kt create mode 100644 src/main/kotlin/top/fatweb/api/vo/authentication/OperationVo.kt create mode 100644 src/main/kotlin/top/fatweb/api/vo/authentication/UserInfoVo.kt diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt index 3b5a191..e021d3b 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt @@ -3,7 +3,10 @@ package top.fatweb.api.controller.permission import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +import top.fatweb.api.converter.UserConverter +import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.service.permission.IUserService +import top.fatweb.api.vo.authentication.UserInfoVo /** *

@@ -19,7 +22,10 @@ class UserController( private val userService: IUserService ) { @GetMapping("info") - fun getInfo() { + fun getInfo(): ResponseResult { + userService.getInfo()?.let { + return ResponseResult.databaseSuccess(data = UserConverter.userToUserInfoVo(it)) + } ?: let { return ResponseResult.databaseFail() } } } diff --git a/src/main/kotlin/top/fatweb/api/converter/SysLogConverter.kt b/src/main/kotlin/top/fatweb/api/converter/SysLogConverter.kt index cd2e475..8d87b67 100644 --- a/src/main/kotlin/top/fatweb/api/converter/SysLogConverter.kt +++ b/src/main/kotlin/top/fatweb/api/converter/SysLogConverter.kt @@ -6,7 +6,7 @@ import top.fatweb.api.vo.PageVo import top.fatweb.api.vo.system.SysLogGetVo object SysLogConverter { - fun sysLogPageToSysLogPageVo(syslogPage: IPage): PageVo = PageVo( + fun sysLogPageToSysLogPageVo(syslogPage: IPage): PageVo = PageVo( syslogPage.total, syslogPage.pages, syslogPage.size, diff --git a/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt b/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt index f975039..2f15140 100644 --- a/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt +++ b/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt @@ -2,6 +2,10 @@ package top.fatweb.api.converter import top.fatweb.api.entity.permission.User import top.fatweb.api.param.authentication.LoginParam +import top.fatweb.api.vo.authentication.ElementVo +import top.fatweb.api.vo.authentication.MenuVo +import top.fatweb.api.vo.authentication.OperationVo +import top.fatweb.api.vo.authentication.UserInfoVo object UserConverter { fun loginParamToUser(loginParam: LoginParam): User { @@ -12,4 +16,45 @@ object UserConverter { return user } + + fun userToUserInfoVo(user: User) = UserInfoVo( + id = user.id, + username = user.username, + locking = user.locking?.let { it == 1 }, + expiration = user.expiration, + credentialsExpiration = user.credentialsExpiration, + enable = user.enable?.let { it == 1 }, + lastLoginTime = user.lastLoginTime, + lastLoginIp = user.lastLoginIp, + createTime = user.createTime, + updateTime = user.updateTime, + menus = user.menus?.map { + MenuVo( + id = it.id, + name = it.name, + url = it.url, + powerId = it.powerId, + parentId = it.parentId + ) + }, + elements = user.elements?.map { + ElementVo( + id = it.id, + name = it.name, + powerId = it.powerId, + parentId = it.parentId, + menuId = it.menuId + ) + }, + operations = user.operations?.map { + OperationVo( + id = it.id, + name = it.name, + code = it.code, + powerId = it.powerId, + parentId = it.parentId, + elementId = it.elementId + ) + } + ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Element.kt b/src/main/kotlin/top/fatweb/api/entity/permission/Element.kt index a285141..c168075 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/Element.kt +++ b/src/main/kotlin/top/fatweb/api/entity/permission/Element.kt @@ -31,6 +31,12 @@ class Element : Serializable { @TableField("power_id") var powerId: Long? = null + /** + * 父ID + */ + @TableField("parent_id") + var parentId: Long? = null + /** * 菜单ID */ diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt index 1634122..b4e9acb 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt @@ -14,5 +14,5 @@ import top.fatweb.api.entity.permission.User interface IUserService : IService { fun getUserWithPower(username: String): User? - fun getInfo(): User + fun getInfo(): User? } diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt index c0efd37..9537c90 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt @@ -8,6 +8,7 @@ import top.fatweb.api.service.permission.IElementService import top.fatweb.api.service.permission.IMenuService import top.fatweb.api.service.permission.IOperationService import top.fatweb.api.service.permission.IUserService +import top.fatweb.api.util.WebUtil /** *

@@ -35,4 +36,7 @@ class UserServiceImpl( return user } + + override fun getInfo() = WebUtil.getLoginUsername()?.let { getUserWithPower(it) } ?: let { null } + } diff --git a/src/main/kotlin/top/fatweb/api/util/WebUtil.kt b/src/main/kotlin/top/fatweb/api/util/WebUtil.kt index ac280d8..3be731b 100644 --- a/src/main/kotlin/top/fatweb/api/util/WebUtil.kt +++ b/src/main/kotlin/top/fatweb/api/util/WebUtil.kt @@ -11,6 +11,8 @@ object WebUtil { fun getLoginUserId() = getLoginUser()?.user?.id + fun getLoginUsername() = getLoginUser()?.user?.username + fun getToken(tokenWithPrefix: String) = tokenWithPrefix.removePrefix(SecurityConstants.tokenPrefix) fun getToken(request: HttpServletRequest) = getToken(request.getHeader(SecurityConstants.headerString)) diff --git a/src/main/kotlin/top/fatweb/api/vo/authentication/ElementVo.kt b/src/main/kotlin/top/fatweb/api/vo/authentication/ElementVo.kt new file mode 100644 index 0000000..ba2396a --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/authentication/ElementVo.kt @@ -0,0 +1,20 @@ +package top.fatweb.api.vo.authentication + +import io.swagger.v3.oas.annotations.media.Schema + +@Schema(description = "页面元素返回参数") +data class ElementVo( + val id: Long?, + + @Schema(description = "元素名", example = "AddButton") + val name: String?, + + @Schema(description = "权限 ID") + val powerId: Long?, + + @Schema(description = "父 ID") + val parentId: Long?, + + @Schema(description = "菜单 ID") + val menuId: Long? +) diff --git a/src/main/kotlin/top/fatweb/api/vo/authentication/MenuVo.kt b/src/main/kotlin/top/fatweb/api/vo/authentication/MenuVo.kt new file mode 100644 index 0000000..bfb0604 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/authentication/MenuVo.kt @@ -0,0 +1,20 @@ +package top.fatweb.api.vo.authentication + +import io.swagger.v3.oas.annotations.media.Schema + +@Schema(description = "菜单返回参数") +data class MenuVo( + val id: Long?, + + @Schema(description = "菜单名", example = "System") + val name: String?, + + @Schema(description = "URL", example = "/system") + val url: String?, + + @Schema(description = "权限 ID") + val powerId: Long?, + + @Schema(description = "父 ID") + val parentId: Long? +) diff --git a/src/main/kotlin/top/fatweb/api/vo/authentication/OperationVo.kt b/src/main/kotlin/top/fatweb/api/vo/authentication/OperationVo.kt new file mode 100644 index 0000000..1af9f65 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/authentication/OperationVo.kt @@ -0,0 +1,23 @@ +package top.fatweb.api.vo.authentication + +import io.swagger.v3.oas.annotations.media.Schema + +@Schema(description = "功能返回参数") +data class OperationVo( + val id: Long?, + + @Schema(description = "功能名", example = "Add User") + val name: String?, + + @Schema(description = "功能编码", example = "system:user:add") + val code: String?, + + @Schema(description = "权限 ID") + val powerId: Long?, + + @Schema(description = "父 ID") + val parentId: Long?, + + @Schema(description = "页面元素 ID") + val elementId: Long? +) diff --git a/src/main/kotlin/top/fatweb/api/vo/authentication/UserInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/authentication/UserInfoVo.kt new file mode 100644 index 0000000..58bed65 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/authentication/UserInfoVo.kt @@ -0,0 +1,45 @@ +package top.fatweb.api.vo.authentication + +import io.swagger.v3.oas.annotations.media.Schema +import java.time.LocalDateTime + +@Schema(description = "获取用户信息返回参数") +data class UserInfoVo( + val id: Long?, + + @Schema(description = "用户名", example = "User") + val username: String?, + + @Schema(description = "是否锁定", example = "false") + val locking: Boolean?, + + @Schema(description = "过期时间", example = "1900-01-01T00:00:00.000Z") + val expiration: LocalDateTime?, + + @Schema(description = "认证过期时间", example = "1900-01-01T00:00:00.000Z") + val credentialsExpiration: LocalDateTime?, + + @Schema(description = "是否启用", example = "true") + val enable: Boolean?, + + @Schema(description = "最后登录时间", example = "1900-01-01T00:00:00.000Z") + val lastLoginTime: LocalDateTime?, + + @Schema(description = "最后登录 IP", example = "1.1.1.1") + val lastLoginIp: String?, + + @Schema(description = "创建时间", example = "1900-01-01T00:00:00.000Z") + val createTime: LocalDateTime?, + + @Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z") + val updateTime: LocalDateTime?, + + @Schema(description = "菜单列表") + val menus: List?, + + @Schema(description = "页面元素列表") + val elements: List?, + + @Schema(description = "功能列表") + val operations: List? +) \ No newline at end of file diff --git a/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql b/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql index 27bc46c..812b0e6 100644 --- a/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql +++ b/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_element'.sql @@ -2,8 +2,9 @@ drop table if exists t_element; create table if not exists t_element ( - id bigint not null primary key, - name varchar(100) not null comment '元素名', - power_id bigint not null comment '权限ID', - menu_id bigint not null comment '菜单ID' + id bigint not null primary key, + name varchar(100) not null comment '元素名', + power_id bigint not null comment '权限ID', + parent_id bigint not null comment '父ID', + menu_id bigint not null comment '菜单ID' ) comment '页面元素'; \ No newline at end of file diff --git a/src/main/resources/mapper/permission/UserMapper.xml b/src/main/resources/mapper/permission/UserMapper.xml index b18c79e..050578e 100644 --- a/src/main/resources/mapper/permission/UserMapper.xml +++ b/src/main/resources/mapper/permission/UserMapper.xml @@ -23,6 +23,7 @@ te.id as element_id, te.name as element_name, te.power_id as element_power_id, + te.parent_id as element_parent_id, te.menu_id as element_menu_id, t.id as operation_id, t.name as operation_name, @@ -74,6 +75,7 @@ + From 1d74afd5cb1aaa94648a2f1641fe90b9f4583f3d Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 30 Oct 2023 00:22:44 +0800 Subject: [PATCH 056/258] Change data source to hikari --- pom.xml | 5 ----- .../resources/application-config-template.yml | 18 +++++++++--------- src/main/resources/application.yml | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 9372dfc..e08a7a2 100644 --- a/pom.xml +++ b/pom.xml @@ -125,11 +125,6 @@ 3.5.3.2 test - - com.alibaba - druid-spring-boot-starter - 1.2.19 - top.fatweb @@ -19,8 +19,12 @@ sonatype-oss-snapshots sonatype-oss-snapshots https://s01.oss.sonatype.org/content/repositories/snapshots - false - true + + false + + + true + @@ -38,7 +42,7 @@ com.github.xiaoymin knife4j-openapi3-jakarta-spring-boot-starter - 4.3.0 + 4.4.0 @@ -71,16 +75,12 @@ 17 - 1.8.22 + 1.9.21 ${maven.build.timestamp} yyyy-MM-dd'T'HH:mm:ss - 9.22.3 + 10.2.0 - - org.springframework.boot - spring-boot-starter-security - org.springframework.boot spring-boot-starter-web @@ -89,34 +89,24 @@ org.springframework.boot spring-boot-starter-validation + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-security + org.springframework.boot spring-boot-starter-mail - - com.fasterxml.jackson.module - jackson-module-kotlin - - - org.jetbrains.kotlin - kotlin-reflect - - - org.jetbrains.kotlin - kotlin-stdlib - - org.springframework.boot spring-boot-devtools runtime true - - com.mysql - mysql-connector-j - runtime - org.springframework.boot spring-boot-starter-test @@ -129,44 +119,46 @@ - com.baomidou - mybatis-plus-boot-starter - 3.5.3.2 + org.jetbrains.kotlin + kotlin-reflect - com.baomidou - mybatis-plus-boot-starter-test - 3.5.3.2 - test + org.jetbrains.kotlin + kotlin-stdlib - + + com.fasterxml.jackson.module + jackson-module-kotlin + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + org.apache.velocity velocity-engine-core 2.3 - org.springframework.boot - spring-boot-starter-data-redis + com.mysql + mysql-connector-j + runtime - com.auth0 - java-jwt - 4.4.0 + com.baomidou + mybatis-plus-boot-starter + 3.5.4.1 - org.springframework.boot - spring-boot-starter-actuator + org.xerial + sqlite-jdbc + 3.42.0.0 - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 + com.baomidou + dynamic-datasource-spring-boot3-starter + 4.2.0 org.flywaydb @@ -178,6 +170,29 @@ flyway-mysql ${flyway.version} + + org.springframework.boot + spring-boot-starter-data-redis + + + com.baomidou + mybatis-plus-boot-starter-test + 3.5.4.1 + test + + + + + com.auth0 + java-jwt + 4.4.0 + top.fatweb avatar-generator @@ -186,7 +201,7 @@ com.github.oshi oshi-core - 6.4.0 + 6.4.9 From 19d20a0f09fd78af9cbfcaa5e518384857e11c11 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 11 Dec 2023 18:32:48 +0800 Subject: [PATCH 132/258] Add multiple datasource --- pom.xml | 4 ++-- .../resources/application-config-template.yml | 9 ++++++--- src/main/resources/application.yml | 15 +++++++++++++-- src/main/resources/db/sqlite.db | 0 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/db/sqlite.db diff --git a/pom.xml b/pom.xml index 326ae44..36048df 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.0 + 3.1.4 top.fatweb @@ -78,7 +78,7 @@ 1.9.21 ${maven.build.timestamp} yyyy-MM-dd'T'HH:mm:ss - 10.2.0 + 9.22.3 diff --git a/src/main/resources/application-config-template.yml b/src/main/resources/application-config-template.yml index faf5524..1b87aa3 100644 --- a/src/main/resources/application-config-template.yml +++ b/src/main/resources/application-config-template.yml @@ -19,9 +19,12 @@ server: spring: datasource: - url: jdbc:mysql://localhost # MySQL url - username: root # MySQL username - password: root # MySQL password + dynamic: + datasource: + master: + url: jdbc:mysql://localhost # MySQL url + username: root # MySQL username + password: root # MySQL password hikari: # pool-name: HikariCP # Connection pool name # minimum-idle: 5 # Minimum number of connection in pool diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index dbf4f94..a273423 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,8 +7,19 @@ spring: profiles: active: config datasource: - type: com.zaxxer.hikari.HikariDataSource - driver-class-name: com.mysql.cj.jdbc.Driver + dynamic: + primary: master + strict: false + datasource: + master: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + local: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: org.sqlite.JDBC + url: jdbc:sqlite::resource:db/sqlite.db + + jackson: date-format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' time-zone: GMT diff --git a/src/main/resources/db/sqlite.db b/src/main/resources/db/sqlite.db new file mode 100644 index 0000000..e69de29 From e1e661988a44b43f3e5eb102b992862378553a3b Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 12 Dec 2023 17:55:23 +0800 Subject: [PATCH 133/258] Move table t_sys_log to sqlite --- db/schema.sql | 61 +++++------------- pom.xml | 2 +- .../top/fatweb/api/FatWebApiApplication.kt | 20 ++++++ .../api/controller/system/SysLogController.kt | 5 +- .../fatweb/api/mapper/system/SysLogMapper.kt | 2 - .../fatweb/api/param/system/SysLogGetParam.kt | 2 + .../permission/impl/UserServiceImpl.kt | 2 + .../api/service/system/ISysLogService.kt | 9 +-- .../service/system/impl/SysLogServiceImpl.kt | 22 +++++-- src/main/resources/application.yml | 4 +- .../V1_0_0_231020__Add_table_'t_sys_log'.sql | 24 ------- src/main/resources/db/sqlite.db | Bin 0 -> 8192 bytes .../resources/mapper/system/SysLogMapper.xml | 20 ++---- 13 files changed, 70 insertions(+), 103 deletions(-) delete mode 100644 src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql diff --git a/db/schema.sql b/db/schema.sql index 70cc8af..b1b9aa7 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -1,48 +1,19 @@ -drop table if exists t_user; - -create table if not exists t_user -( - id bigint not null primary key, - username varchar(20) not null comment '用户名', - password char(70) not null comment '密码', - locking int not null comment '锁定', - expiration datetime comment '过期时间', - credentials_expiration datetime comment '认证过期时间', - enable int not null comment '启用', - last_login_time datetime comment '上次登录时间', - last_login_ip varchar(128) comment '上次登录 IP', - create_time datetime not null default (utc_timestamp()) comment '创建时间', - update_time datetime not null default (utc_timestamp()) comment '修改时间', - deleted bigint not null default 0, - version int not null default 0, - constraint t_user_unique unique (username, deleted) -) comment '用户表'; - -insert into t_user (id, username, password, locking, enable) value (0, 'admin', - '$2a$10$3wDGdzTZlC..7eY6u2XM5u78xUQo0z5Sj5yOpneD4QJ0q/TA5TY0S', - 0, 1); - drop table if exists t_sys_log; -create table t_sys_log +create table t_sys_log -- 系统日志表 ( id bigint not null, - log_type varchar(50) not null comment '日志类型', - operate_user_id bigint not null comment '操作用户', - operate_time datetime(3) not null default (utc_timestamp()) comment '操作时间', - request_uri varchar(500) default null comment '请求 URI', - request_method varchar(10) default null comment '请求方式', - request_params text comment '请求参数', - request_ip varchar(20) not null comment '请求 IP', - request_server_address varchar(50) not null comment '请求服务器地址', - is_exception char(1) default null comment '是否异常', - exception_info text comment '异常信息', - start_time datetime(3) not null comment '开始时间', - end_time datetime(3) not null comment '结束时间', - execute_time bigint default null comment '执行时间', - user_agent varchar(500) default null comment '用户代理', - primary key (id) using btree, - key idx_sys_log_log_type (log_type) using btree, - key idx_sys_log_operate_user_id (operate_user_id) using btree, - key idx_sys_log_is_exception (is_exception) using btree, - key idx_sys_log_operate_time (operate_time) using btree -) comment '系统日志表'; \ No newline at end of file + log_type varchar(50) not null, -- 日志类型 + operate_user_id bigint not null, -- 操作用户 + operate_time datetime(3) not null default (strftime('%Y-%m-%d %H:%M:%f','now')), -- 操作时间 + request_uri varchar(500) default null, -- 请求 URI + request_method varchar(10) default null, -- 请求方式 + request_params text, -- 请求参数 + request_ip varchar(20) not null, -- 请求 IP + request_server_address varchar(50) not null, -- 请求服务器地址 + exception int not null default 0, -- 是否异常 + exception_info text, -- 异常信息 + start_time datetime(3) not null, -- 开始时间 + end_time datetime(3) not null, -- 结束时间 + execute_time bigint default null, -- 执行时间 + user_agent varchar(500) default null -- 用户代理 +); \ No newline at end of file diff --git a/pom.xml b/pom.xml index 36048df..096f298 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,7 @@ org.xerial sqlite-jdbc - 3.42.0.0 + 3.44.1.0 com.baomidou diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index 75a4be8..8f06f1f 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -34,6 +34,26 @@ fun main(args: Array) { } } + if (!File("data/db").isDirectory) { + if (!File("data/db").mkdir()) { + logger.error("Can not create directory 'data/db', please try again later.") + return + } + } + + if (!File("data/db/sqlite.db").isFile || File("data/db/sqlite.db").inputStream() + .use { it.readNBytes(15).toString(Charsets.UTF_8) != "SQLite format 3" } + ) { + logger.warn("The 'data/db/sqlite.db' database is lost or damaged, recreating...") + if (File("data/db/sqlite.db").exists() && !File("data/db/sqlite.db").delete()) { + logger.error("Can not recreate database 'data/db/sqlite.db', please try again later.") + } + + FatWebApiApplication::class.java.getResourceAsStream("/db/sqlite.db")?.let { + File("data/db/sqlite.db").writeBytes(it.readAllBytes()) + } + } + if (File("application-config.yml").exists() || File("data/application-config.yml").exists()) { runApplication(*args) } else { diff --git a/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt b/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt index c038a6c..8ba7c37 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt @@ -7,7 +7,6 @@ import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController -import top.fatweb.api.converter.system.SysLogConverter import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.param.system.SysLogGetParam @@ -44,9 +43,7 @@ class SysLogController( @PreAuthorize("hasAnyAuthority('system:log:query:all')") fun get(@Valid sysLogGetParam: SysLogGetParam?): ResponseResult> { return ResponseResult.success( - ResponseCode.DATABASE_SELECT_SUCCESS, data = SysLogConverter.sysLogPageToSysLogPageVo( - sysLogService.getPage(sysLogGetParam) - ) + ResponseCode.DATABASE_SELECT_SUCCESS, data = sysLogService.getPage(sysLogGetParam) ) } } diff --git a/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt index 19db9bd..3bb670d 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt +++ b/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt @@ -23,7 +23,6 @@ interface SysLogMapper : BaseMapper { * @param logType List of log types * @param requestMethod List of request methods * @param searchRequestUrl Request URL to search for - * @param searchRegex Use regex * @param searchStartTime Start time to search for * @param searchEndTime end time to search for * @return System log in page @@ -38,7 +37,6 @@ interface SysLogMapper : BaseMapper { logType: List?, requestMethod: List?, searchRequestUrl: String?, - searchRegex: Boolean, searchStartTime: LocalDateTime?, searchEndTime: LocalDateTime? ): IPage diff --git a/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt b/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt index c5083ad..0a44587 100644 --- a/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt @@ -51,8 +51,10 @@ data class SysLogGetParam( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +/* @Schema(description = "查询使用正则表达式", allowableValues = ["true", "false"], defaultValue = "false") val searchRegex: Boolean = false, +*/ /** * Start time to search for diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt index e7cc6e0..3dfa092 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt @@ -1,5 +1,6 @@ package top.fatweb.api.service.permission.impl +import com.baomidou.dynamic.datasource.annotation.DS import com.baomidou.mybatisplus.core.metadata.OrderItem import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper @@ -47,6 +48,7 @@ import java.time.ZoneOffset * @see User * @see IUserService */ +@DS("master") @Service class UserServiceImpl( private val passwordEncoder: PasswordEncoder, diff --git a/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt b/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt index 4b3a431..034450d 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt @@ -1,9 +1,10 @@ package top.fatweb.api.service.system -import com.baomidou.mybatisplus.core.metadata.IPage import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.api.entity.system.SysLog import top.fatweb.api.param.system.SysLogGetParam +import top.fatweb.api.vo.PageVo +import top.fatweb.api.vo.system.SysLogVo /** * System log service interface @@ -22,8 +23,8 @@ interface ISysLogService : IService { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see SysLogGetParam - * @see IPage - * @see SysLog + * @see PageVo + * @see SysLogVo */ - fun getPage(sysLogGetParam: SysLogGetParam?): IPage + fun getPage(sysLogGetParam: SysLogGetParam?): PageVo } diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt index 4ea58fa..066f0c1 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt @@ -1,15 +1,19 @@ package top.fatweb.api.service.system.impl -import com.baomidou.mybatisplus.core.metadata.IPage +import com.baomidou.dynamic.datasource.annotation.DS import com.baomidou.mybatisplus.core.metadata.OrderItem import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service +import top.fatweb.api.converter.system.SysLogConverter import top.fatweb.api.entity.system.SysLog import top.fatweb.api.mapper.system.SysLogMapper import top.fatweb.api.param.system.SysLogGetParam +import top.fatweb.api.service.permission.IUserService import top.fatweb.api.service.system.ISysLogService import top.fatweb.api.util.PageUtil +import top.fatweb.api.vo.PageVo +import top.fatweb.api.vo.system.SysLogVo /** * System log service implement @@ -21,21 +25,29 @@ import top.fatweb.api.util.PageUtil * @see SysLog * @see ISysLogService */ +@DS("sqlite") @Service -class SysLogServiceImpl : ServiceImpl(), ISysLogService { - override fun getPage(sysLogGetParam: SysLogGetParam?): IPage { +class SysLogServiceImpl( + private val userService: IUserService +) : ServiceImpl(), ISysLogService { + override fun getPage(sysLogGetParam: SysLogGetParam?): PageVo { val sysLogPage = Page(sysLogGetParam?.currentPage ?: 1, sysLogGetParam?.pageSize ?: 20) PageUtil.setPageSort(sysLogGetParam, sysLogPage, OrderItem.desc("start_time")) - return baseMapper.selectPage( + val sysLogIPage = baseMapper.selectPage( sysLogPage, sysLogGetParam?.logType?.split(","), sysLogGetParam?.requestMethod?.split(","), sysLogGetParam?.searchRequestUrl, - sysLogGetParam?.searchRegex ?: false, sysLogGetParam?.searchStartTime, sysLogGetParam?.searchEndTime ) + sysLogIPage.records.forEach { + it.operateUsername = + it.operateUserId?.let { it1 -> userService.getOne(it1)?.username } + } + + return SysLogConverter.sysLogPageToSysLogPageVo(sysLogIPage) } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a273423..f0dbc7f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -14,10 +14,10 @@ spring: master: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver - local: + sqlite: type: com.zaxxer.hikari.HikariDataSource driver-class-name: org.sqlite.JDBC - url: jdbc:sqlite::resource:db/sqlite.db + url: jdbc:sqlite:data/db/sqlite.db?date_string_format=yyyy-MM-dd'T'HH:mm:ss.SSS jackson: diff --git a/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql b/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql deleted file mode 100644 index 626377c..0000000 --- a/src/main/resources/db/migration/V1_0_0_231020__Add_table_'t_sys_log'.sql +++ /dev/null @@ -1,24 +0,0 @@ -drop table if exists t_sys_log; -create table t_sys_log -( - id bigint not null, - log_type varchar(50) not null comment '日志类型', - operate_user_id bigint not null comment '操作用户', - operate_time datetime(3) not null default (utc_timestamp()) comment '操作时间', - request_uri varchar(500) default null comment '请求 URI', - request_method varchar(10) default null comment '请求方式', - request_params text comment '请求参数', - request_ip varchar(20) not null comment '请求 IP', - request_server_address varchar(50) not null comment '请求服务器地址', - exception int not null default 0 comment '是否异常', - exception_info text comment '异常信息', - start_time datetime(3) not null comment '开始时间', - end_time datetime(3) not null comment '结束时间', - execute_time bigint default null comment '执行时间', - user_agent varchar(500) default null comment '用户代理', - primary key (id) using btree, - key idx_sys_log_log_type (log_type) using btree, - key idx_sys_log_operate_user_id (operate_user_id) using btree, - key idx_sys_log_exception (exception) using btree, - key idx_sys_log_operate_time (operate_time) using btree -) comment '系统日志表'; \ No newline at end of file diff --git a/src/main/resources/db/sqlite.db b/src/main/resources/db/sqlite.db index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c4467bb2003fe03fecd217607f90a61d35e92148 100644 GIT binary patch literal 8192 zcmeH~?`zXQ7{`+#2!*2We7SoQ+CnSS;hVj3%D}+{o%4k+BxKFC3$#g1F0*?#`$E(@ zHkhsool->Ccim82rIr0Ny`=sZUV6*rN5`gnIqsop?ykxA`Sz3N9>}AI3mSr;V3=hE zfob8YAd13m00co0$uU6=KfL)Re?rdQ{Hzd#>v}gyt`ZYZ1@hs+32*|O04Kl+Z~~kF zCvcGo)PZ>U+T^6Ta|J2OC5U8e&5}z-kqsv9F3!y^&4H!aI}3AwErVPRxZitj@3YhR zijNw@Ry&zUCli2#rh4CFv8)v}9nodoKtQ)kr7XRJB$Uxw1;*}KRm}W~Vy16RWdOS) zc1?InJW)69K@WebQ*EOHO$9;OwxB5o)=qR27K@EN?d^@h@22~%?YugSY9p;2_O6nA z-coux@C{U0Q0x){X$zT!(XT1#Nlq%~Bo#>aW~BQwQX!R1>BjR^CX@B}(tJ+i=by$8 zn$LvKY-l0bHnp(5fD-}bho5hR*d?O^x{>f>| z&dx8~-;8Qk6jLc%%nE{4lx4HC2h26ztU2%ZquN>}BH;VJ`R|o;Ol1B+RG3uFDk&UA zRZVDFz!(0HlBB{;a|6F=;g41UPJk2O1ULasfD_;ZH~~(86S%+x{sNbS Bu08+& literal 0 HcmV?d00001 diff --git a/src/main/resources/mapper/system/SysLogMapper.xml b/src/main/resources/mapper/system/SysLogMapper.xml index 5bde6d8..ee47c86 100644 --- a/src/main/resources/mapper/system/SysLogMapper.xml +++ b/src/main/resources/mapper/system/SysLogMapper.xml @@ -16,10 +16,8 @@ t_sys_log.start_time as sys_log_start_time, t_sys_log.end_time as sys_log_end_time, t_sys_log.execute_time as sys_log_execute_time, - t_sys_log.user_agent as sys_log_user_agent, - t_user.username as sys_log_operate_username + t_sys_log.user_agent as sys_log_user_agent from t_sys_log - left join t_user on t_user.id = t_sys_log.operate_user_id @@ -30,17 +28,9 @@ #{item} - - - and concat_ws('?', concat(t_sys_log.request_server_address, t_sys_log.request_uri), - if(length(t_sys_log.request_params) != 0, t_sys_log.request_params, null)) regexp #{searchRequestUrl} - - - and concat_ws('?', concat(t_sys_log.request_server_address, t_sys_log.request_uri), - if(length(t_sys_log.request_params) != 0, t_sys_log.request_params, null)) like concat('%', - #{searchRequestUrl}, '%') - - + and t_sys_log.request_server_address || t_sys_log.request_uri || + case when length(t_sys_log.request_params) != 0 then '?' || t_sys_log.request_params else '' end like + '%'||'mail'||'%' and t_sys_log.start_time between #{searchStartTime} and #{searchEndTime} @@ -64,7 +54,5 @@ - - From e23dde9fc7ce36e6dc4427aba85bef44e4df5822 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 12 Dec 2023 18:07:15 +0800 Subject: [PATCH 134/258] Optimize code --- .../api/service/system/impl/SysLogServiceImpl.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt index 066f0c1..1cfd886 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt @@ -2,10 +2,12 @@ package top.fatweb.api.service.system.impl import com.baomidou.dynamic.datasource.annotation.DS import com.baomidou.mybatisplus.core.metadata.OrderItem +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service import top.fatweb.api.converter.system.SysLogConverter +import top.fatweb.api.entity.permission.User import top.fatweb.api.entity.system.SysLog import top.fatweb.api.mapper.system.SysLogMapper import top.fatweb.api.param.system.SysLogGetParam @@ -47,6 +49,14 @@ class SysLogServiceImpl( it.operateUsername = it.operateUserId?.let { it1 -> userService.getOne(it1)?.username } } + val userIds = sysLogIPage.records.map { it.operateUserId } + userService.list(KtQueryWrapper(User()).select(User::id, User::username).`in`(User::id, userIds)).forEach { user -> + sysLogIPage.records.forEach { + if (it.operateUserId == user.id) { + it.operateUsername = user.username + } + } + } return SysLogConverter.sysLogPageToSysLogPageVo(sysLogIPage) } From e309ac67b623fb2b82bf8d807038ec59c60c8f54 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 12 Dec 2023 18:24:32 +0800 Subject: [PATCH 135/258] Update schema.sql --- db/schema.sql | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/db/schema.sql b/db/schema.sql index b1b9aa7..fc482b8 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -4,7 +4,7 @@ create table t_sys_log -- 系统日志表 id bigint not null, log_type varchar(50) not null, -- 日志类型 operate_user_id bigint not null, -- 操作用户 - operate_time datetime(3) not null default (strftime('%Y-%m-%d %H:%M:%f','now')), -- 操作时间 + operate_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f','now')), -- 操作时间 request_uri varchar(500) default null, -- 请求 URI request_method varchar(10) default null, -- 请求方式 request_params text, -- 请求参数 @@ -12,8 +12,17 @@ create table t_sys_log -- 系统日志表 request_server_address varchar(50) not null, -- 请求服务器地址 exception int not null default 0, -- 是否异常 exception_info text, -- 异常信息 - start_time datetime(3) not null, -- 开始时间 - end_time datetime(3) not null, -- 结束时间 + start_time datetime not null, -- 开始时间 + end_time datetime not null, -- 结束时间 execute_time bigint default null, -- 执行时间 user_agent varchar(500) default null -- 用户代理 +); + +drop table if exists t_active; +create table t_active_log -- 用户活跃日志表 +( + id bigint not null, + event varchar(50) not null, -- 事件, + operate_user_id bigint not null, -- 操作用户 + operate_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f','now')) -- 操作时间 ); \ No newline at end of file From 17bfb2feb4aad12a2f5d49903279c2baf7b44a24 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 14 Dec 2023 14:03:09 +0800 Subject: [PATCH 136/258] Use flyway to initialize sqlite database --- pom.xml | 9 +- .../top/fatweb/api/FatWebApiApplication.kt | 4 - .../top/fatweb/api/config/FlywayConfig.kt | 43 ++++++++ .../top/fatweb/api/entity/system/SysLog.kt | 4 + .../fatweb/api/properties/FlywayProperties.kt | 95 ++++++++++++++++++ .../service/system/impl/SysLogServiceImpl.kt | 13 ++- src/main/resources/application.yml | 4 +- .../migration/{ => master}/R__Basic_data.sql | 0 .../V1_0_0_231019__Add_table_'t_user'.sql | 0 ...1_0_0_231023__Add_table_'t_power_type'.sql | 0 .../V1_0_0_231024__Add_table_'t_power'.sql | 0 .../V1_0_0_231025__Add_table_'t_menu'.sql | 0 .../V1_0_0_231026__Add_table_'t_func'.sql | 0 ...V1_0_0_231027__Add_table_'t_operation'.sql | 0 .../V1_0_0_231028__Add_table_'t_group'.sql | 0 ...1_0_0_231029__Add_table_'t_user_group'.sql | 0 .../V1_0_0_231030__Add_table_'t_role'.sql | 0 ...1_0_0_231031__Add_table_'t_role_group'.sql | 0 ...V1_0_0_231101__Add_table_'t_user_role'.sql | 0 ...1_0_0_231102__Add_table_'t_power_role'.sql | 0 .../V1_0_0_231103__Add_table_'t_module'.sql | 0 ...V1_0_0_231104__Add_table_'t_user_info'.sql | 0 .../V1_0_0_231212__Add_table_'t_sys_log'.sql | 20 ++++ src/main/resources/db/sqlite.db | Bin 8192 -> 0 bytes 24 files changed, 174 insertions(+), 18 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/config/FlywayConfig.kt create mode 100644 src/main/kotlin/top/fatweb/api/properties/FlywayProperties.kt rename src/main/resources/db/migration/{ => master}/R__Basic_data.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231019__Add_table_'t_user'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231023__Add_table_'t_power_type'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231024__Add_table_'t_power'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231025__Add_table_'t_menu'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231026__Add_table_'t_func'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231027__Add_table_'t_operation'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231028__Add_table_'t_group'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231029__Add_table_'t_user_group'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231030__Add_table_'t_role'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231031__Add_table_'t_role_group'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231101__Add_table_'t_user_role'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231102__Add_table_'t_power_role'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231103__Add_table_'t_module'.sql (100%) rename src/main/resources/db/migration/{ => master}/V1_0_0_231104__Add_table_'t_user_info'.sql (100%) create mode 100644 src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_sys_log'.sql delete mode 100644 src/main/resources/db/sqlite.db diff --git a/pom.xml b/pom.xml index 096f298..4ab8946 100644 --- a/pom.xml +++ b/pom.xml @@ -147,7 +147,7 @@ com.baomidou - mybatis-plus-boot-starter + mybatis-plus-spring-boot3-starter 3.5.4.1 @@ -160,11 +160,6 @@ dynamic-datasource-spring-boot3-starter 4.2.0 - - org.flywaydb - flyway-core - ${flyway.version} - org.flywaydb flyway-mysql @@ -176,7 +171,7 @@ com.baomidou - mybatis-plus-boot-starter-test + mybatis-plus-spring-boot3-starter-test 3.5.4.1 test diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index 8f06f1f..9a5f335 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -48,10 +48,6 @@ fun main(args: Array) { if (File("data/db/sqlite.db").exists() && !File("data/db/sqlite.db").delete()) { logger.error("Can not recreate database 'data/db/sqlite.db', please try again later.") } - - FatWebApiApplication::class.java.getResourceAsStream("/db/sqlite.db")?.let { - File("data/db/sqlite.db").writeBytes(it.readAllBytes()) - } } if (File("application-config.yml").exists() || File("data/application-config.yml").exists()) { diff --git a/src/main/kotlin/top/fatweb/api/config/FlywayConfig.kt b/src/main/kotlin/top/fatweb/api/config/FlywayConfig.kt new file mode 100644 index 0000000..824b529 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/config/FlywayConfig.kt @@ -0,0 +1,43 @@ +package top.fatweb.api.config + +import com.baomidou.dynamic.datasource.DynamicRoutingDataSource +import jakarta.annotation.PostConstruct +import org.flywaydb.core.Flyway +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.DependsOn +import top.fatweb.api.properties.FlywayProperties +import javax.sql.DataSource + +/** + * Flyway configuration + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@DependsOn("flywayProperties") +@Configuration +class FlywayConfig( + private val dataSource: DataSource +) { + @PostConstruct + fun migrateOrder() { + val ds = dataSource as DynamicRoutingDataSource + ds.dataSources.forEach { (k: String, v: DataSource?) -> + val flyway = Flyway.configure() + .dataSource(v) + .locations(*FlywayProperties.locations.map { "$it/$k" }.toTypedArray()) + .baselineOnMigrate(FlywayProperties.baselineOnMigrate) + .table(FlywayProperties.table) + .outOfOrder(FlywayProperties.outOfOrder) + .validateOnMigrate(FlywayProperties.validateOnMigrate) + .encoding(FlywayProperties.encoding) + .sqlMigrationPrefix(FlywayProperties.sqlMigrationPrefix) + .sqlMigrationSeparator(FlywayProperties.sqlMigrationSeparator) + .sqlMigrationSuffixes(*FlywayProperties.sqlMigrationSuffixes.toTypedArray()) + .baselineVersion(FlywayProperties.baselineVersion) + .load() + flyway.migrate() + } + + } +} \ 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 4928382..7ab85a0 100644 --- a/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt +++ b/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt @@ -3,6 +3,7 @@ package top.fatweb.api.entity.system import com.baomidou.mybatisplus.annotation.TableField import com.baomidou.mybatisplus.annotation.TableId import com.baomidou.mybatisplus.annotation.TableName +import com.fasterxml.jackson.annotation.JsonFormat import java.io.Serializable import java.time.LocalDateTime @@ -48,6 +49,7 @@ class SysLog : Serializable { * @since 1.0.0 * @see LocalDateTime */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") @TableField("operate_time") var operateTime: LocalDateTime? = null @@ -121,6 +123,7 @@ class SysLog : Serializable { * @since 1.0.0 * @see LocalDateTime */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") @TableField("start_time") var startTime: LocalDateTime? = null @@ -131,6 +134,7 @@ class SysLog : Serializable { * @since 1.0.0 * @see LocalDateTime */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") @TableField("end_time") var endTime: LocalDateTime? = null diff --git a/src/main/kotlin/top/fatweb/api/properties/FlywayProperties.kt b/src/main/kotlin/top/fatweb/api/properties/FlywayProperties.kt new file mode 100644 index 0000000..9a2a31e --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/properties/FlywayProperties.kt @@ -0,0 +1,95 @@ +package top.fatweb.api.properties + +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.stereotype.Component + +/** + * Flyway properties + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Component +@ConfigurationProperties("spring.flyway") +object FlywayProperties { + /** + * Locations of migrations scripts. Can contain the special "{vendor}" placeholder to + * use vendor-specific locations. + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var locations = listOf("classpath:db/migration") + + /** + * Name of the schema history table that will be used by Flyway. + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var table = "flyway_schema_history" + + /** + * Whether to allow migrations to be run out of order. + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var outOfOrder = false + + /** + * Whether to automatically call validate when performing a migration. + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var validateOnMigrate = true + + /** + * Encoding of SQL migrations. + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var encoding = Charsets.UTF_8 + + /** + * File name prefix for SQL migrations. + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var sqlMigrationPrefix = "V" + + /** + * File name separator for SQL migrations. + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var sqlMigrationSeparator = "__" + + /** + * File name suffix for SQL migrations. + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var sqlMigrationSuffixes = listOf(".sql") + + /** + * Whether to automatically call baseline when migrating a non-empty schema. + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var baselineOnMigrate = true + + /** + * Version to tag an existing schema with when executing baseline. + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var baselineVersion = "0" +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt index 1cfd886..6f596a9 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt @@ -49,11 +49,14 @@ class SysLogServiceImpl( it.operateUsername = it.operateUserId?.let { it1 -> userService.getOne(it1)?.username } } - val userIds = sysLogIPage.records.map { it.operateUserId } - userService.list(KtQueryWrapper(User()).select(User::id, User::username).`in`(User::id, userIds)).forEach { user -> - sysLogIPage.records.forEach { - if (it.operateUserId == user.id) { - it.operateUsername = user.username + if (sysLogIPage.records.isNotEmpty()) { + val userIds = sysLogIPage.records.map { it.operateUserId } + + userService.list(KtQueryWrapper(User()).select(User::id, User::username).`in`(User::id, userIds)).forEach { user -> + sysLogIPage.records.forEach { + if (it.operateUserId == user.id) { + it.operateUsername = user.username + } } } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f0dbc7f..3117780 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -17,16 +17,16 @@ spring: sqlite: type: com.zaxxer.hikari.HikariDataSource driver-class-name: org.sqlite.JDBC - url: jdbc:sqlite:data/db/sqlite.db?date_string_format=yyyy-MM-dd'T'HH:mm:ss.SSS + url: jdbc:sqlite:data/db/sqlite.db jackson: date-format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' time-zone: GMT flyway: + enabled: false baseline-on-migrate: true baseline-version: 0 - clean-disabled: false mybatis-plus: global-config: diff --git a/src/main/resources/db/migration/R__Basic_data.sql b/src/main/resources/db/migration/master/R__Basic_data.sql similarity index 100% rename from src/main/resources/db/migration/R__Basic_data.sql rename to src/main/resources/db/migration/master/R__Basic_data.sql diff --git a/src/main/resources/db/migration/V1_0_0_231019__Add_table_'t_user'.sql b/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_user'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231019__Add_table_'t_user'.sql rename to src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_user'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231023__Add_table_'t_power_type'.sql b/src/main/resources/db/migration/master/V1_0_0_231023__Add_table_'t_power_type'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231023__Add_table_'t_power_type'.sql rename to src/main/resources/db/migration/master/V1_0_0_231023__Add_table_'t_power_type'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231024__Add_table_'t_power'.sql b/src/main/resources/db/migration/master/V1_0_0_231024__Add_table_'t_power'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231024__Add_table_'t_power'.sql rename to src/main/resources/db/migration/master/V1_0_0_231024__Add_table_'t_power'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231025__Add_table_'t_menu'.sql b/src/main/resources/db/migration/master/V1_0_0_231025__Add_table_'t_menu'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231025__Add_table_'t_menu'.sql rename to src/main/resources/db/migration/master/V1_0_0_231025__Add_table_'t_menu'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_func'.sql b/src/main/resources/db/migration/master/V1_0_0_231026__Add_table_'t_func'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231026__Add_table_'t_func'.sql rename to src/main/resources/db/migration/master/V1_0_0_231026__Add_table_'t_func'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231027__Add_table_'t_operation'.sql b/src/main/resources/db/migration/master/V1_0_0_231027__Add_table_'t_operation'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231027__Add_table_'t_operation'.sql rename to src/main/resources/db/migration/master/V1_0_0_231027__Add_table_'t_operation'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231028__Add_table_'t_group'.sql b/src/main/resources/db/migration/master/V1_0_0_231028__Add_table_'t_group'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231028__Add_table_'t_group'.sql rename to src/main/resources/db/migration/master/V1_0_0_231028__Add_table_'t_group'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231029__Add_table_'t_user_group'.sql b/src/main/resources/db/migration/master/V1_0_0_231029__Add_table_'t_user_group'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231029__Add_table_'t_user_group'.sql rename to src/main/resources/db/migration/master/V1_0_0_231029__Add_table_'t_user_group'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231030__Add_table_'t_role'.sql b/src/main/resources/db/migration/master/V1_0_0_231030__Add_table_'t_role'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231030__Add_table_'t_role'.sql rename to src/main/resources/db/migration/master/V1_0_0_231030__Add_table_'t_role'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231031__Add_table_'t_role_group'.sql b/src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_role_group'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231031__Add_table_'t_role_group'.sql rename to src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_role_group'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231101__Add_table_'t_user_role'.sql b/src/main/resources/db/migration/master/V1_0_0_231101__Add_table_'t_user_role'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231101__Add_table_'t_user_role'.sql rename to src/main/resources/db/migration/master/V1_0_0_231101__Add_table_'t_user_role'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231102__Add_table_'t_power_role'.sql b/src/main/resources/db/migration/master/V1_0_0_231102__Add_table_'t_power_role'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231102__Add_table_'t_power_role'.sql rename to src/main/resources/db/migration/master/V1_0_0_231102__Add_table_'t_power_role'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231103__Add_table_'t_module'.sql b/src/main/resources/db/migration/master/V1_0_0_231103__Add_table_'t_module'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231103__Add_table_'t_module'.sql rename to src/main/resources/db/migration/master/V1_0_0_231103__Add_table_'t_module'.sql diff --git a/src/main/resources/db/migration/V1_0_0_231104__Add_table_'t_user_info'.sql b/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql similarity index 100% rename from src/main/resources/db/migration/V1_0_0_231104__Add_table_'t_user_info'.sql rename to src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_sys_log'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_sys_log'.sql new file mode 100644 index 0000000..93c1301 --- /dev/null +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_sys_log'.sql @@ -0,0 +1,20 @@ +drop table if exists t_sys_log; + +create table t_sys_log -- 系统日志表 +( + id bigint not null, + log_type varchar(50) not null, -- 日志类型 + operate_user_id bigint not null, -- 操作用户 + operate_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f','now')), -- 操作时间 + request_uri varchar(500) default null, -- 请求 URI + request_method varchar(10) default null, -- 请求方式 + request_params text, -- 请求参数 + request_ip varchar(20) not null, -- 请求 IP + request_server_address varchar(50) not null, -- 请求服务器地址 + exception int not null default 0, -- 是否异常 + exception_info text, -- 异常信息 + start_time datetime not null, -- 开始时间 + end_time datetime not null, -- 结束时间 + execute_time bigint default null, -- 执行时间 + user_agent varchar(500) default null -- 用户代理 +); \ No newline at end of file diff --git a/src/main/resources/db/sqlite.db b/src/main/resources/db/sqlite.db deleted file mode 100644 index c4467bb2003fe03fecd217607f90a61d35e92148..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmeH~?`zXQ7{`+#2!*2We7SoQ+CnSS;hVj3%D}+{o%4k+BxKFC3$#g1F0*?#`$E(@ zHkhsool->Ccim82rIr0Ny`=sZUV6*rN5`gnIqsop?ykxA`Sz3N9>}AI3mSr;V3=hE zfob8YAd13m00co0$uU6=KfL)Re?rdQ{Hzd#>v}gyt`ZYZ1@hs+32*|O04Kl+Z~~kF zCvcGo)PZ>U+T^6Ta|J2OC5U8e&5}z-kqsv9F3!y^&4H!aI}3AwErVPRxZitj@3YhR zijNw@Ry&zUCli2#rh4CFv8)v}9nodoKtQ)kr7XRJB$Uxw1;*}KRm}W~Vy16RWdOS) zc1?InJW)69K@WebQ*EOHO$9;OwxB5o)=qR27K@EN?d^@h@22~%?YugSY9p;2_O6nA z-coux@C{U0Q0x){X$zT!(XT1#Nlq%~Bo#>aW~BQwQX!R1>BjR^CX@B}(tJ+i=by$8 zn$LvKY-l0bHnp(5fD-}bho5hR*d?O^x{>f>| z&dx8~-;8Qk6jLc%%nE{4lx4HC2h26ztU2%ZquN>}BH;VJ`R|o;Ol1B+RG3uFDk&UA zRZVDFz!(0HlBB{;a|6F=;g41UPJk2O1ULasfD_;ZH~~(86S%+x{sNbS Bu08+& From 1c4d28b916447cf5834552c8fb773b07fba26fa3 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 14 Dec 2023 15:30:18 +0800 Subject: [PATCH 137/258] Fix logout error --- .../service/permission/impl/AuthenticationServiceImpl.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index 6a9a0fe..e98291a 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -70,7 +70,11 @@ class AuthenticationServiceImpl( return LoginVo(jwt, loginUser.user.currentLoginTime, loginUser.user.currentLoginIp) } - override fun logout(token: String): Boolean = redisUtil.delObject("${SecurityProperties.jwtIssuer}_login:" + token) + override fun logout(token: String): Boolean { + val loginUser = WebUtil.getLoginUser() ?: let { throw TokenHasExpiredException() } + + return redisUtil.delObject("${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:" + token) + } override fun renewToken(token: String): TokenVo { val loginUser = WebUtil.getLoginUser() ?: let { throw TokenHasExpiredException() } From 1743b3d3d638227a3a2faa68f9e35eaf309be5c8 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 14 Dec 2023 15:31:23 +0800 Subject: [PATCH 138/258] Rename statistics to statistic --- ...csController.kt => StatisticController.kt} | 20 +++++++++---------- ...tisticsService.kt => IStatisticService.kt} | 4 ++-- ...ServiceImpl.kt => StatisticServiceImpl.kt} | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) rename src/main/kotlin/top/fatweb/api/controller/system/{StatisticsController.kt => StatisticController.kt} (83%) rename src/main/kotlin/top/fatweb/api/service/system/{IStatisticsService.kt => IStatisticService.kt} (94%) rename src/main/kotlin/top/fatweb/api/service/system/impl/{StatisticsServiceImpl.kt => StatisticServiceImpl.kt} (98%) diff --git a/src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt b/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt similarity index 83% rename from src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt rename to src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt index cbab4c8..017972a 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt @@ -6,21 +6,21 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.service.system.IStatisticsService +import top.fatweb.api.service.system.IStatisticService import top.fatweb.api.vo.system.* /** - * Statistics controller + * Statistic controller * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 - * @see IStatisticsService + * @see IStatisticService */ @Tag(name = "统计接口", description = "系统信息统计相关接口") -@RequestMapping("/system/statistics") +@RequestMapping("/system/statistic") @RestController -class StatisticsController( - private val statisticsService: IStatisticsService +class StatisticController( + private val statisticService: IStatisticService ) { /** * Get software information @@ -33,7 +33,7 @@ class StatisticsController( */ @Operation(summary = "获取软件信息") @GetMapping("/software") - fun software(): ResponseResult = ResponseResult.success(data = statisticsService.software()) + fun software(): ResponseResult = ResponseResult.success(data = statisticService.software()) /** * Get hardware information @@ -46,7 +46,7 @@ class StatisticsController( */ @Operation(summary = "获取硬件信息") @GetMapping("/hardware") - fun hardware(): ResponseResult = ResponseResult.success(data = statisticsService.hardware()) + fun hardware(): ResponseResult = ResponseResult.success(data = statisticService.hardware()) /** * Get CPU information @@ -59,7 +59,7 @@ class StatisticsController( */ @Operation(summary = "获取 CPU 信息") @GetMapping("/cpu") - fun cpu(): ResponseResult = ResponseResult.success(data = statisticsService.cpu()) + fun cpu(): ResponseResult = ResponseResult.success(data = statisticService.cpu()) /** * Get storage information @@ -72,5 +72,5 @@ class StatisticsController( */ @Operation(summary = "获取存储信息") @GetMapping("/storage") - fun storage(): ResponseResult = ResponseResult.success(data = statisticsService.storage()) + fun storage(): ResponseResult = ResponseResult.success(data = statisticService.storage()) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt b/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt rename to src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt index a6c9397..7f37b35 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt @@ -3,12 +3,12 @@ package top.fatweb.api.service.system import top.fatweb.api.vo.system.* /** - * Statistics service interface + * Statistic service interface * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -interface IStatisticsService { +interface IStatisticService { /** * Get software information * diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt rename to src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt index 771dcfe..fb141d9 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt @@ -4,7 +4,7 @@ import org.springframework.stereotype.Service import oshi.SystemInfo import oshi.hardware.CentralProcessor import top.fatweb.api.properties.ServerProperties -import top.fatweb.api.service.system.IStatisticsService +import top.fatweb.api.service.system.IStatisticService import top.fatweb.api.util.ByteUtil import top.fatweb.api.vo.system.* import java.time.LocalDateTime @@ -13,13 +13,13 @@ import java.util.* import java.util.concurrent.TimeUnit /** - * Statistics service implement + * Statistic service implement * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ @Service -class StatisticsServiceImpl : IStatisticsService { +class StatisticServiceImpl : IStatisticService { private val systemProperties: Properties = System.getProperties() private val systemInfo: SystemInfo = SystemInfo() private val runtime: Runtime = Runtime.getRuntime() From c059f85f62dfb68950925ed42f6d3f39367a0e46 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 14 Dec 2023 15:31:41 +0800 Subject: [PATCH 139/258] Add type of system log --- .../kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt index 911b929..f324d7f 100644 --- a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt +++ b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt @@ -66,7 +66,11 @@ class SysLogInterceptor( sysLog.apply { logType = requestUri?.let { when { - it.startsWith("/system/statistics/") -> "STATISTICS" + it.startsWith("/login") -> "LOGIN" + it.startsWith("/logout") -> "LOGOUT" + it.startsWith("/register") -> "REGISTER" + it.startsWith("/system/statistic/") -> "STATISTIC" + it.startsWith("/api/") -> "API" else -> "INFO" } } ?: "INFO" From 9ede33e005495d1040969bdb930ca89597bf69ed Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 14 Dec 2023 18:27:05 +0800 Subject: [PATCH 140/258] Optimize regex --- .../fatweb/api/util/ApiVersionCondition.kt | 9 ++---- .../kotlin/top/fatweb/api/util/StrUtil.kt | 29 ++++--------------- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt b/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt index 407c831..788a545 100644 --- a/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt +++ b/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt @@ -2,7 +2,6 @@ package top.fatweb.api.util import jakarta.servlet.http.HttpServletRequest import org.springframework.web.servlet.mvc.condition.RequestCondition -import java.util.regex.Pattern /** * Api version condition @@ -11,15 +10,13 @@ import java.util.regex.Pattern * @since 1.0.0 */ class ApiVersionCondition(private val apiVersion: Int) : RequestCondition { - private val versionPrefixPattern: Pattern = Pattern.compile(".*v(\\d+).*") + private val versionPrefixRegex = Regex(".*v(\\d+).*") override fun combine(other: ApiVersionCondition): ApiVersionCondition = ApiVersionCondition(other.apiVersion) override fun getMatchingCondition(request: HttpServletRequest): ApiVersionCondition? { - val matcher = versionPrefixPattern.matcher(request.requestURI) - if (matcher.find()) { - val version = matcher.group(1).toInt() - if (version >= this.apiVersion) { + versionPrefixRegex.matchAt(request.requestURI, 0)?.let { + if (it.groupValues[1].toInt() >= this.apiVersion) { return this } } diff --git a/src/main/kotlin/top/fatweb/api/util/StrUtil.kt b/src/main/kotlin/top/fatweb/api/util/StrUtil.kt index acc55fc..e9787cd 100644 --- a/src/main/kotlin/top/fatweb/api/util/StrUtil.kt +++ b/src/main/kotlin/top/fatweb/api/util/StrUtil.kt @@ -1,7 +1,6 @@ package top.fatweb.api.util import java.security.MessageDigest -import java.util.regex.Pattern /** * String util @@ -10,7 +9,7 @@ import java.util.regex.Pattern * @since 1.0.0 */ object StrUtil { - + /** * Convert CamelCase string to underscore-delimited string * @@ -22,16 +21,7 @@ object StrUtil { fun upperToUnderLetter(str: String?): String { str ?: let { return "" } - val matcher = Pattern.compile("([A-Z])").matcher(str) - val stringBuilder = StringBuilder() - - while (matcher.find()) { - matcher.appendReplacement(stringBuilder, "_" + matcher.group().lowercase()) - } - - matcher.appendTail(stringBuilder) - - return stringBuilder.toString() + return Regex("[A-Z]").replace(str) { matchResult -> "_${matchResult.value.lowercase()}" } } /** @@ -45,16 +35,7 @@ object StrUtil { fun underToUpperLetter(str: String?): String { str ?: let { return "" } - val matcher = Pattern.compile("(_)([a-z])").matcher(str) - val stringBuilder = StringBuilder() - - while (matcher.find()) { - matcher.appendReplacement(stringBuilder, matcher.group().replace("_", "").uppercase()) - } - - matcher.appendTail(stringBuilder) - - return stringBuilder.toString() + return Regex("_[a-z]").replace(str) { matchResult -> matchResult.value.removePrefix("_").uppercase() } } /** @@ -65,7 +46,7 @@ object StrUtil { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - fun getRandomPassword(length: Int): String { + fun getRandomPassword(length: Int): String { val characterSet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" val password = StringBuilder() @@ -92,7 +73,7 @@ object StrUtil { if (b < 0x10) { str = "0$str" } - hex.append(str.substring(str.length -2)) + hex.append(str.substring(str.length - 2)) } return hex.toString() } From c2e5248aa028d12e2d7a1e2fec4278b8c0461926 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 14 Dec 2023 18:28:59 +0800 Subject: [PATCH 141/258] Optimize code --- .../top/fatweb/api/entity/system/SysLog.kt | 17 ++++++++++++++++- .../api/interceptor/SysLogInterceptor.kt | 19 ++++++++++--------- .../fatweb/api/settings/MailSecurityType.kt | 2 +- .../top/fatweb/api/vo/system/SysLogVo.kt | 3 ++- 4 files changed, 29 insertions(+), 12 deletions(-) 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 7ab85a0..80b8c1e 100644 --- a/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt +++ b/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt @@ -1,9 +1,11 @@ package top.fatweb.api.entity.system +import com.baomidou.mybatisplus.annotation.EnumValue import com.baomidou.mybatisplus.annotation.TableField import com.baomidou.mybatisplus.annotation.TableId import com.baomidou.mybatisplus.annotation.TableName import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.annotation.JsonValue import java.io.Serializable import java.time.LocalDateTime @@ -15,6 +17,18 @@ import java.time.LocalDateTime */ @TableName("t_sys_log") class SysLog : Serializable { + /** + * Log type enum + * + * @author FatttSnake, fatttsnake@gmail.com + * @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( + "API" + ) + } + /** * ID * @@ -29,9 +43,10 @@ class SysLog : Serializable { * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see LogType */ @TableField("log_type") - var logType: String? = null + var logType: LogType? = null /** * Operate user ID diff --git a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt index f324d7f..d424d3c 100644 --- a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt +++ b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt @@ -2,6 +2,7 @@ package top.fatweb.api.interceptor import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse +import org.springframework.beans.factory.annotation.Qualifier import org.springframework.core.MethodParameter import org.springframework.http.MediaType import org.springframework.http.converter.HttpMessageConverter @@ -32,7 +33,7 @@ import java.util.concurrent.Executor */ @ControllerAdvice class SysLogInterceptor( - private val customThreadPoolTaskExecutor: Executor, private val sysLogService: ISysLogService + @Qualifier("applicationTaskExecutor") private val customThreadPoolTaskExecutor: Executor, private val sysLogService: ISysLogService ) : HandlerInterceptor, ResponseBodyAdvice { private val sysLogThreadLocal = ThreadLocal() private val resultThreadLocal = ThreadLocal() @@ -66,19 +67,19 @@ class SysLogInterceptor( sysLog.apply { logType = requestUri?.let { when { - it.startsWith("/login") -> "LOGIN" - it.startsWith("/logout") -> "LOGOUT" - it.startsWith("/register") -> "REGISTER" - it.startsWith("/system/statistic/") -> "STATISTIC" - it.startsWith("/api/") -> "API" - else -> "INFO" + 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("/api/") -> SysLog.LogType.API + else -> SysLog.LogType.INFO } - } ?: "INFO" + } ?: SysLog.LogType.INFO exception = 0 } } else { sysLog.apply { - logType = "ERROR" + logType = SysLog.LogType.ERROR exception = 1 exceptionInfo = result.msg } diff --git a/src/main/kotlin/top/fatweb/api/settings/MailSecurityType.kt b/src/main/kotlin/top/fatweb/api/settings/MailSecurityType.kt index 8288221..b7b1f85 100644 --- a/src/main/kotlin/top/fatweb/api/settings/MailSecurityType.kt +++ b/src/main/kotlin/top/fatweb/api/settings/MailSecurityType.kt @@ -10,7 +10,7 @@ enum class MailSecurityType(val code: String) { @JsonCreator fun fromCode(code: String): MailSecurityType? { - values().forEach { + entries.forEach { if (it.code == code) { return it } diff --git a/src/main/kotlin/top/fatweb/api/vo/system/SysLogVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/SysLogVo.kt index 184bbef..28e5483 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/SysLogVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/SysLogVo.kt @@ -3,6 +3,7 @@ package top.fatweb.api.vo.system import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema +import top.fatweb.api.entity.system.SysLog import java.time.LocalDateTime /** @@ -29,7 +30,7 @@ data class SysLogVo( * @since 1.0.0 */ @Schema(description = "日志类型") - val logType: String?, + val logType: SysLog.LogType?, /** * Operate user ID From ed1124380b0010fc876aed55b76de249acd09b7e Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 14 Dec 2023 18:29:24 +0800 Subject: [PATCH 142/258] Add event log and statistic log --- .../top/fatweb/api/FatWebApiApplication.kt | 2 + .../top/fatweb/api/cron/StatisticCron.kt | 23 +++++++ .../top/fatweb/api/entity/system/EventLog.kt | 64 +++++++++++++++++++ .../fatweb/api/entity/system/StatisticLog.kt | 64 +++++++++++++++++++ .../api/mapper/system/EventLogMapper.kt | 8 +++ .../api/mapper/system/StatisticLogMapper.kt | 8 +++ .../api/service/system/IEventLogService.kt | 6 ++ .../service/system/IStatisticLogService.kt | 6 ++ .../system/impl/EventLogServiceImpl.kt | 12 ++++ .../system/impl/StatisticLogServiceImpl.kt | 12 ++++ ...V1_0_0_231213__Add_table_'t_event_log'.sql | 9 +++ ...V1_0_0_231214__Add_table_'t_statistic'.sql | 9 +++ 12 files changed, 223 insertions(+) create mode 100644 src/main/kotlin/top/fatweb/api/cron/StatisticCron.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/system/EventLog.kt create mode 100644 src/main/kotlin/top/fatweb/api/entity/system/StatisticLog.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/system/EventLogMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/mapper/system/StatisticLogMapper.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/system/IEventLogService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/system/IStatisticLogService.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/system/impl/EventLogServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/api/service/system/impl/StatisticLogServiceImpl.kt create mode 100644 src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_event_log'.sql create mode 100644 src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistic'.sql diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index 9a5f335..5dda1ea 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -3,6 +3,7 @@ package top.fatweb.api import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication +import org.springframework.scheduling.annotation.EnableScheduling import org.springframework.transaction.annotation.EnableTransactionManagement import java.io.File import java.util.* @@ -15,6 +16,7 @@ import java.util.* */ @SpringBootApplication @EnableTransactionManagement +@EnableScheduling class FatWebApiApplication /** diff --git a/src/main/kotlin/top/fatweb/api/cron/StatisticCron.kt b/src/main/kotlin/top/fatweb/api/cron/StatisticCron.kt new file mode 100644 index 0000000..d22e6e9 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/cron/StatisticCron.kt @@ -0,0 +1,23 @@ +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.properties.SecurityProperties +import top.fatweb.api.service.system.IStatisticLogService +import top.fatweb.api.util.RedisUtil + +@Component +class StatisticCron( + private val redisUtil: RedisUtil, + private val statisticLogService: IStatisticLogService +) { + @Scheduled(cron = "0 * * * * *") + fun onlineUserCount() { + statisticLogService.save(StatisticLog().apply { + key = StatisticLog.KeyItem.ONLINE_USERS_COUNT + value = redisUtil.keys("${SecurityProperties.jwtIssuer}_login_*") + .distinctBy { Regex("FatWeb_login_(.*):.*").matchEntire(it)?.groupValues?.getOrNull(1) }.size.toString() + }) + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/system/EventLog.kt b/src/main/kotlin/top/fatweb/api/entity/system/EventLog.kt new file mode 100644 index 0000000..5d28307 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/system/EventLog.kt @@ -0,0 +1,64 @@ +package top.fatweb.api.entity.system + +import com.baomidou.mybatisplus.annotation.EnumValue +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableName +import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.annotation.JsonValue +import java.io.Serializable +import java.time.LocalDateTime + +/** + * Event log entity + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@TableName("t_event_log") +class EventLog : Serializable { + enum class Event(@field:EnumValue @field:JsonValue val code: String) { + LOGIN("LOGIN"), LOGOUT("LOGOUT"), REGISTER("REGISTER"), API("API") + } + + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableId("id") + var id: Long? = null + + /** + * Event + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("event") + var event: Event? = null + + /** + * Operate user ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("operate_user_id") + var operateUserId: Long? = null + + /** + * Operate time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") + @TableField("operate_time") + var operateTime: LocalDateTime? = null + + override fun toString(): String { + return "EventLog(id=$id, event=$event, operateUserId=$operateUserId, operateTime=$operateTime)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/entity/system/StatisticLog.kt b/src/main/kotlin/top/fatweb/api/entity/system/StatisticLog.kt new file mode 100644 index 0000000..1ea02cd --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/system/StatisticLog.kt @@ -0,0 +1,64 @@ +package top.fatweb.api.entity.system + +import com.baomidou.mybatisplus.annotation.EnumValue +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableName +import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.annotation.JsonValue +import java.io.Serializable +import java.time.LocalDateTime + +/** + * Statistic log entity + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@TableName("t_statistic_log") +class StatisticLog : Serializable { + enum class KeyItem(@field:EnumValue @field:JsonValue val code: String) { + ONLINE_USERS_COUNT("ONLINE_USER_COUNT") + } + + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableId("id") + var id: Long? = null + + /** + * Key + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("key") + var key: KeyItem? = null + + /** + * Value + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("value") + var value: String? = null + + /** + * Record time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") + @TableField("record_time") + var recordTime: LocalDateTime?= null + + override fun toString(): String { + return "StatisticLog(id=$id, key=$key, value=$value, recordTime=$recordTime)" + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/mapper/system/EventLogMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/system/EventLogMapper.kt new file mode 100644 index 0000000..11177ba --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/system/EventLogMapper.kt @@ -0,0 +1,8 @@ +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.EventLog + +@Mapper +interface EventLogMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/mapper/system/StatisticLogMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/system/StatisticLogMapper.kt new file mode 100644 index 0000000..a970d8e --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/system/StatisticLogMapper.kt @@ -0,0 +1,8 @@ +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 + +@Mapper +interface StatisticLogMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/IEventLogService.kt b/src/main/kotlin/top/fatweb/api/service/system/IEventLogService.kt new file mode 100644 index 0000000..481c946 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/system/IEventLogService.kt @@ -0,0 +1,6 @@ +package top.fatweb.api.service.system + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.system.EventLog + +interface IEventLogService : IService \ 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 new file mode 100644 index 0000000..4ad89b1 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/system/IStatisticLogService.kt @@ -0,0 +1,6 @@ +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/impl/EventLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/EventLogServiceImpl.kt new file mode 100644 index 0000000..b1e20d0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/EventLogServiceImpl.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.EventLog +import top.fatweb.api.mapper.system.EventLogMapper +import top.fatweb.api.service.system.IEventLogService + +@DS("sqlite") +@Service +class EventLogServiceImpl : ServiceImpl(), IEventLogService \ No newline at end of file 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 new file mode 100644 index 0000000..479b142 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticLogServiceImpl.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.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/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_event_log'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_event_log'.sql new file mode 100644 index 0000000..a2b97a6 --- /dev/null +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_event_log'.sql @@ -0,0 +1,9 @@ +drop table if exists t_event_log; + +create table if not exists t_event_log -- 事件日志表 +( + id bigint not null primary key, + event varchar(50) not null, -- 事件, + operate_user_id bigint not null, -- 操作用户 + operate_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f','now')) -- 操作时间 +); \ 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_statistic'.sql new file mode 100644 index 0000000..423ce81 --- /dev/null +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistic'.sql @@ -0,0 +1,9 @@ +drop table if exists t_statistic_log; + +create table if not exists t_statistic_log -- 统计日志表 +( + id bigint not null primary key, + key varchar(50) not null, -- 记录键 + value varchar(100) not null, -- 记录值 + record_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f', 'now')) -- 记录时间 +) \ No newline at end of file From 05bbd59eb05a1225a7dcb3ac88a4ea3d66717e81 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 17 Dec 2023 17:55:29 +0800 Subject: [PATCH 143/258] Optimize code --- src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt | 2 +- src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt index 5dda1ea..1bbf8aa 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt @@ -55,7 +55,7 @@ fun main(args: Array) { if (File("application-config.yml").exists() || File("data/application-config.yml").exists()) { runApplication(*args) } else { - logger.warn("File 'application.yml' cannot be found in data path. The configuration file template 'application.example.yml' has been created in directory 'data'. Please change the configuration file content, rename it to 'application.yml', and then restart the server.") + logger.warn("File 'application-config.yml' cannot be found in the running path or the data path. The configuration file template 'application-config.example.yml' has been created in directory 'data'. Please change the configuration file content, move it to the running path, rename it to 'application-config.yml', and then restart the server.") FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText()?.let { File("data/application-config.example.yml").writeText( it.replace( diff --git a/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt b/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt index d7892fa..7b4f23e 100644 --- a/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt +++ b/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt @@ -15,7 +15,7 @@ import kotlin.reflect.KMutableProperty1 * @since 1.0.0 */ object SettingsOperator { - private const val SETTINGS_FILE_NAME = "data/config/settings.yaml" + private const val SETTINGS_FILE_NAME = "data/config/settings.yml" private val yamlMapper = YAMLMapper() private val settingFile = File(SETTINGS_FILE_NAME) From e1970c8a03ca765915e6c0aa3d19fdd8676c44ed Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 17 Dec 2023 23:42:29 +0800 Subject: [PATCH 144/258] Add EventUtil --- .../kotlin/top/fatweb/api/util/EventUtil.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/kotlin/top/fatweb/api/util/EventUtil.kt diff --git a/src/main/kotlin/top/fatweb/api/util/EventUtil.kt b/src/main/kotlin/top/fatweb/api/util/EventUtil.kt new file mode 100644 index 0000000..75cc2c4 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/util/EventUtil.kt @@ -0,0 +1,25 @@ +package top.fatweb.api.util + +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Component +import top.fatweb.api.entity.system.EventLog +import top.fatweb.api.service.system.IEventLogService + +@Component +class EventUtil( + private val eventLogService: IEventLogService +) { + private val logger: Logger = LoggerFactory.getLogger(this::class.java) + + fun record(event: EventLog.Event) { + try { + eventLogService.save(EventLog().apply { + this.event = event + operateUserId = WebUtil.getLoginUserId() ?: -1 + }) + } catch (e: Exception) { + logger.error("Cannot record event!!!", e) + } + } +} \ No newline at end of file From 66146cb3b4e5519b9ff6e4022dd4487bee6cd0f5 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 18 Dec 2023 13:25:34 +0800 Subject: [PATCH 145/258] Optimize annotation in controller --- .../fatweb/api/annotation/ApiController.kt | 23 +++++++++++++ .../top/fatweb/api/annotation/ApiVersion.kt | 17 ---------- .../fatweb/api/annotation/BaseController.kt | 19 +++++++++++ .../fatweb/api/annotation/HiddenController.kt | 15 ++++++++ .../api/config/WebMvcConfigurerConfig.kt | 13 +++++++ .../api/controller/ExceptionController.kt | 7 ++-- .../api/controller/api/v1/AvatarController.kt | 34 ++++--------------- .../permission/AuthenticationController.kt | 15 ++++---- .../controller/permission/GroupController.kt | 6 ++-- .../controller/permission/PowerController.kt | 8 ++--- .../controller/permission/RoleController.kt | 6 ++-- .../controller/permission/UserController.kt | 6 ++-- .../controller/system/SettingsController.kt | 11 +++--- .../controller/system/StatisticController.kt | 13 ++++--- .../api/controller/system/SysLogController.kt | 8 ++--- .../util/ApiResponseMappingHandlerMapping.kt | 19 +++-------- .../fatweb/api/util/ApiVersionCondition.kt | 2 +- 17 files changed, 113 insertions(+), 109 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/annotation/ApiController.kt delete mode 100644 src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt create mode 100644 src/main/kotlin/top/fatweb/api/annotation/BaseController.kt create mode 100644 src/main/kotlin/top/fatweb/api/annotation/HiddenController.kt create mode 100644 src/main/kotlin/top/fatweb/api/config/WebMvcConfigurerConfig.kt diff --git a/src/main/kotlin/top/fatweb/api/annotation/ApiController.kt b/src/main/kotlin/top/fatweb/api/annotation/ApiController.kt new file mode 100644 index 0000000..5649f5e --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/annotation/ApiController.kt @@ -0,0 +1,23 @@ +package top.fatweb.api.annotation + +import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.core.annotation.AliasFor +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@Tag(name = "") +@RequestMapping +@RestController +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +annotation class ApiController( + val version: Int = 1, + + @get:AliasFor(annotation = RestController::class, attribute = "value") val value: String = "", + + @get:AliasFor(annotation = RequestMapping::class, attribute = "path") val path: Array = [""], + + @get:AliasFor(annotation = Tag::class, attribute = "name") val name: String, + + @get:AliasFor(annotation = Tag::class, attribute = "description") val description: String +) diff --git a/src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt b/src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt deleted file mode 100644 index d4277f4..0000000 --- a/src/main/kotlin/top/fatweb/api/annotation/ApiVersion.kt +++ /dev/null @@ -1,17 +0,0 @@ -package top.fatweb.api.annotation - -import org.springframework.core.annotation.AliasFor - -/** - * Api controller version annotation - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ -@Target(AnnotationTarget.CLASS) -@Retention(AnnotationRetention.RUNTIME) -annotation class ApiVersion( - @get:AliasFor("version") val value: Int = 1, - - @get:AliasFor("value") val version: Int = 1 -) diff --git a/src/main/kotlin/top/fatweb/api/annotation/BaseController.kt b/src/main/kotlin/top/fatweb/api/annotation/BaseController.kt new file mode 100644 index 0000000..1d810f5 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/annotation/BaseController.kt @@ -0,0 +1,19 @@ +package top.fatweb.api.annotation + +import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.core.annotation.AliasFor +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@Tag(name = "") +@RequestMapping +@RestController +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +annotation class BaseController( + @get:AliasFor(annotation = RequestMapping::class, attribute = "path") val path: Array = [""], + + @get:AliasFor(annotation = Tag::class, attribute = "name") val name: String, + + @get:AliasFor(annotation = Tag::class, attribute = "description") val description: String +) diff --git a/src/main/kotlin/top/fatweb/api/annotation/HiddenController.kt b/src/main/kotlin/top/fatweb/api/annotation/HiddenController.kt new file mode 100644 index 0000000..ef121b3 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/annotation/HiddenController.kt @@ -0,0 +1,15 @@ +package top.fatweb.api.annotation + +import io.swagger.v3.oas.annotations.Hidden +import org.springframework.core.annotation.AliasFor +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@Hidden +@RequestMapping +@RestController +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +annotation class HiddenController( + @get:AliasFor(annotation = RequestMapping::class, attribute = "path") val path: Array = [""] +) diff --git a/src/main/kotlin/top/fatweb/api/config/WebMvcConfigurerConfig.kt b/src/main/kotlin/top/fatweb/api/config/WebMvcConfigurerConfig.kt new file mode 100644 index 0000000..ceed4df --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/config/WebMvcConfigurerConfig.kt @@ -0,0 +1,13 @@ +package top.fatweb.api.config + +import org.springframework.context.annotation.Configuration +import org.springframework.web.servlet.config.annotation.PathMatchConfigurer +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer +import top.fatweb.api.annotation.ApiController + +@Configuration +class WebMvcConfigurerConfig : WebMvcConfigurer { + override fun configurePathMatch(configurer: PathMatchConfigurer) { + configurer.addPathPrefix("/api/{API_VERSION}") {it.isAnnotationPresent(ApiController::class.java)} + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt b/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt index 4ca92e7..3c2f76f 100644 --- a/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt @@ -1,9 +1,8 @@ package top.fatweb.api.controller -import io.swagger.v3.oas.annotations.Hidden import jakarta.servlet.http.HttpServletRequest import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import top.fatweb.api.annotation.HiddenController /** * Exception controller @@ -11,9 +10,7 @@ import org.springframework.web.bind.annotation.RestController * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@Hidden -@RestController -@RequestMapping("/error") +@HiddenController(["/error"]) class ExceptionController { @RequestMapping("/thrown") fun thrown(request: HttpServletRequest) { diff --git a/src/main/kotlin/top/fatweb/api/controller/api/v1/AvatarController.kt b/src/main/kotlin/top/fatweb/api/controller/api/v1/AvatarController.kt index eaf416f..a2bc7dc 100644 --- a/src/main/kotlin/top/fatweb/api/controller/api/v1/AvatarController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/api/v1/AvatarController.kt @@ -1,13 +1,10 @@ package top.fatweb.api.controller.api.v1 import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag import jakarta.validation.Valid import org.springframework.http.MediaType import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import top.fatweb.api.annotation.ApiController import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.param.api.v1.avatar.AvatarBaseParam @@ -22,16 +19,13 @@ import top.fatweb.api.vo.api.v1.avatar.AvatarBase64Vo * @since 1.0.0 * @see IAvatarService */ -@Tag(name = "随机头像", description = "随机头像相关接口") -@RequestMapping("/api/{apiVersion}/avatar") -@RestController +@ApiController(value = "avatarControllerV1", path = ["/avatar"], name = "随机头像 V1", description = "随机头像相关接口") class AvatarController( private val avatarService: IAvatarService ) { /** * Get random avatar * - * @param apiVersion Api version * @param avatarBaseParam Avatar base parameters * @return Avatar byte array * @author FatttSnake, fatttsnake@gmail.com @@ -41,7 +35,7 @@ class AvatarController( */ @Operation(summary = "获取随机头像") @GetMapping(produces = [MediaType.IMAGE_PNG_VALUE]) - fun getRandom(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray = + fun getRandom(@Valid avatarBaseParam: AvatarBaseParam?): ByteArray = when ((1..4).random()) { 1 -> avatarService.triangle(avatarBaseParam) 2 -> avatarService.square(avatarBaseParam) @@ -59,7 +53,6 @@ class AvatarController( /** * Get random avatar as base64 * - * @param apiVersion Api version * @param avatarBaseParam Avatar base parameters * @return Response object includes avatar base64 string * @author FatttSnake, fatttsnake@gmail.com @@ -71,7 +64,6 @@ class AvatarController( @Operation(summary = "获取随机头像 Base64") @GetMapping("base64") fun getRandomBase64( - @PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam? ): ResponseResult = ResponseResult.success( @@ -93,7 +85,6 @@ class AvatarController( /** * Get triangle avatar * - * @param apiVersion Api version * @param avatarBaseParam Avatar base parameters * @return Avatar byte array * @author FatttSnake, fatttsnake@gmail.com @@ -103,13 +94,12 @@ class AvatarController( */ @Operation(summary = "三角形头像") @GetMapping("/triangle", produces = [MediaType.IMAGE_PNG_VALUE]) - fun triangle(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray = + fun triangle(@Valid avatarBaseParam: AvatarBaseParam?): ByteArray = avatarService.triangle(avatarBaseParam) /** * Get triangle avatar as base64 * - * @param apiVersion Api version * @param avatarBaseParam Avatar base parameters * @return Response object includes avatar base64 string * @author FatttSnake, fatttsnake@gmail.com @@ -121,7 +111,6 @@ class AvatarController( @Operation(summary = "三角形头像 Base64") @GetMapping("/triangle/base64") fun triangleBase64( - @PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam? ): ResponseResult = ResponseResult.success( @@ -132,7 +121,6 @@ class AvatarController( /** * Get square avatar * - * @param apiVersion Api version * @param avatarBaseParam Avatar base parameters * @return Avatar byte array * @author FatttSnake, fatttsnake@gmail.com @@ -142,13 +130,12 @@ class AvatarController( */ @Operation(summary = "正方形头像") @GetMapping("/square", produces = [MediaType.IMAGE_PNG_VALUE]) - fun square(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray = + fun square(@Valid avatarBaseParam: AvatarBaseParam?): ByteArray = avatarService.square(avatarBaseParam) /** * Get square avatar as base64 * - * @param apiVersion Api version * @param avatarBaseParam Avatar base parameters * @return Response object includes avatar base64 string * @author FatttSnake, fatttsnake@gmail.com @@ -160,7 +147,6 @@ class AvatarController( @Operation(summary = "正方形头像 Base64") @GetMapping("/square/base64") fun squareBase64( - @PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam? ): ResponseResult = ResponseResult.success( @@ -171,7 +157,6 @@ class AvatarController( /** * Get identicon avatar * - * @param apiVersion Api version * @param avatarBaseParam Avatar base parameters * @return Avatar byte array * @author FatttSnake, fatttsnake@gmail.com @@ -181,13 +166,12 @@ class AvatarController( */ @Operation(summary = "Identicon 头像") @GetMapping("/identicon", produces = [MediaType.IMAGE_PNG_VALUE]) - fun identicon(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray = + fun identicon(@Valid avatarBaseParam: AvatarBaseParam?): ByteArray = avatarService.identicon(avatarBaseParam) /** * Get identicon avatar as base64 * - * @param apiVersion Api version * @param avatarBaseParam Avatar base parameters * @return Response object includes avatar base64 string * @author FatttSnake, fatttsnake@gmail.com @@ -199,7 +183,6 @@ class AvatarController( @Operation(summary = "Identicon 头像 Base64") @GetMapping("/identicon/base64") fun identiconBase64( - @PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam? ): ResponseResult = ResponseResult.success( @@ -210,7 +193,6 @@ class AvatarController( /** * Get GitHub avatar * - * @param apiVersion Api version * @param avatarGitHubParam Avatar base parameters * @return Avatar byte array * @author FatttSnake, fatttsnake@gmail.com @@ -220,13 +202,12 @@ class AvatarController( */ @Operation(summary = "GitHub 头像") @GetMapping("/github", produces = [MediaType.IMAGE_PNG_VALUE]) - fun github(@PathVariable apiVersion: String, @Valid avatarGitHubParam: AvatarGitHubParam?): ByteArray = + fun github(@Valid avatarGitHubParam: AvatarGitHubParam?): ByteArray = avatarService.github(avatarGitHubParam) /** * Get GitHub avatar as base64 * - * @param apiVersion Api version * @param avatarGitHubParam Avatar base parameters * @return Response object includes avatar base64 string * @author FatttSnake, fatttsnake@gmail.com @@ -238,7 +219,6 @@ class AvatarController( @Operation(summary = "GitHub 头像 Base64") @GetMapping("/github/base64") fun githubBase64( - @PathVariable apiVersion: String, @Valid avatarGitHubParam: AvatarGitHubParam? ): ResponseResult = ResponseResult.success( diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt index d12dda8..f5acf94 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt @@ -1,13 +1,12 @@ package top.fatweb.api.controller.permission import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag import jakarta.servlet.http.HttpServletRequest import jakarta.validation.Valid import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RestController +import top.fatweb.api.annotation.BaseController import top.fatweb.api.converter.permission.UserConverter import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult @@ -24,8 +23,7 @@ import top.fatweb.api.vo.permission.TokenVo * @since 1.0.0 * @see IAuthenticationService */ -@Tag(name = "身份认证", description = "身份认证相关接口") -@RestController +@BaseController(name = "身份认证", description = "身份认证相关接口") class AuthenticationController( private val authenticationService: IAuthenticationService ) { @@ -63,10 +61,11 @@ class AuthenticationController( */ @Operation(summary = "登出") @PostMapping("/logout") - fun logout(request: HttpServletRequest): ResponseResult = when (authenticationService.logout(WebUtil.getToken(request))) { - true -> ResponseResult.success(ResponseCode.PERMISSION_LOGOUT_SUCCESS, "Logout success", null) - false -> ResponseResult.fail(ResponseCode.PERMISSION_LOGOUT_FAILED, "Logout failed", null) - } + fun logout(request: HttpServletRequest): ResponseResult = + when (authenticationService.logout(WebUtil.getToken(request))) { + true -> ResponseResult.success(ResponseCode.PERMISSION_LOGOUT_SUCCESS, "Logout success", null) + false -> ResponseResult.fail(ResponseCode.PERMISSION_LOGOUT_FAILED, "Logout failed", null) + } /** * Renew token diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/GroupController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/GroupController.kt index f701a07..f52db31 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/GroupController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/GroupController.kt @@ -1,10 +1,10 @@ package top.fatweb.api.controller.permission import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag import jakarta.validation.Valid import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* +import top.fatweb.api.annotation.BaseController import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.param.permission.group.* @@ -20,9 +20,7 @@ import top.fatweb.api.vo.permission.base.GroupVo * @since 1.0.0 * @see IGroupService */ -@Tag(name = "用户组管理", description = "用户组管理相关接口") -@RequestMapping("/system/group") -@RestController +@BaseController(path = ["/system/group"], name = "用户组管理", description = "用户组管理相关接口") class GroupController( val groupService: IGroupService ) { diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/PowerController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/PowerController.kt index 68ef379..3da4c87 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/PowerController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/PowerController.kt @@ -1,11 +1,9 @@ package top.fatweb.api.controller.permission import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import top.fatweb.api.annotation.BaseController import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.service.permission.IPowerService import top.fatweb.api.vo.permission.PowerSetVo @@ -17,9 +15,7 @@ import top.fatweb.api.vo.permission.PowerSetVo * @since 1.0.0 * @see IPowerService */ -@Tag(name = "权限管理", description = "权限管理相关接口") -@RequestMapping("/system/power") -@RestController +@BaseController(path = ["/system/power"], name = "权限管理", description = "权限管理相关接口") class PowerController( private val powerService: IPowerService ) { diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/RoleController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/RoleController.kt index b591c1d..63a7015 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/RoleController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/RoleController.kt @@ -1,10 +1,10 @@ package top.fatweb.api.controller.permission import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag import jakarta.validation.Valid import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* +import top.fatweb.api.annotation.BaseController import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.param.permission.role.* @@ -20,9 +20,7 @@ import top.fatweb.api.vo.permission.base.RoleVo * @since 1.0.0 * @see IRoleService */ -@Tag(name = "角色管理", description = "角色管理相关接口") -@RequestMapping("/system/role") -@RestController +@BaseController(path = ["/system/role"], name = "角色管理", description = "角色管理相关接口") class RoleController( private val roleService: IRoleService ) { diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt index 1505c13..e2419e4 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt @@ -1,10 +1,10 @@ package top.fatweb.api.controller.permission import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag import jakarta.validation.Valid import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* +import top.fatweb.api.annotation.BaseController import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.exception.NoRecordFoundException @@ -22,9 +22,7 @@ import top.fatweb.api.vo.permission.UserWithRoleInfoVo * @since 1.0.0 * @see IUserService */ -@Tag(name = "用户管理", description = "用户管理相关接口") -@RequestMapping("/system/user") -@RestController +@BaseController(path = ["/system/user"], name = "用户管理", description = "用户管理相关接口") class UserController( private val userService: IUserService ) { diff --git a/src/main/kotlin/top/fatweb/api/controller/system/SettingsController.kt b/src/main/kotlin/top/fatweb/api/controller/system/SettingsController.kt index bd3e407..56dad25 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/SettingsController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/SettingsController.kt @@ -1,10 +1,13 @@ package top.fatweb.api.controller.system import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag import jakarta.validation.Valid import org.springframework.security.access.prepost.PreAuthorize -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.PutMapping +import org.springframework.web.bind.annotation.RequestBody +import top.fatweb.api.annotation.BaseController import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.param.system.MailSendParam import top.fatweb.api.param.system.MailSettingsParam @@ -18,9 +21,7 @@ import top.fatweb.api.vo.system.MailSettingsVo * @since 1.0.0 * @see ISettingsService */ -@Tag(name = "系统设置", description = "系统设置相关接口") -@RequestMapping("/system/settings") -@RestController +@BaseController(path = ["/system/settings"], name = "系统设置", description = "系统设置相关接口") class SettingsController( private val settingsService: ISettingsService ) { diff --git a/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt b/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt index 017972a..a279220 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt @@ -1,13 +1,14 @@ package top.fatweb.api.controller.system import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import top.fatweb.api.annotation.BaseController import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.service.system.IStatisticService -import top.fatweb.api.vo.system.* +import top.fatweb.api.vo.system.CpuInfoVo +import top.fatweb.api.vo.system.HardwareInfoVo +import top.fatweb.api.vo.system.SoftwareInfoVo +import top.fatweb.api.vo.system.StorageInfoVo /** * Statistic controller @@ -16,9 +17,7 @@ import top.fatweb.api.vo.system.* * @since 1.0.0 * @see IStatisticService */ -@Tag(name = "统计接口", description = "系统信息统计相关接口") -@RequestMapping("/system/statistic") -@RestController +@BaseController(path = ["/system/statistic"], name = "统计接口", description = "系统信息统计相关接口") class StatisticController( private val statisticService: IStatisticService ) { diff --git a/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt b/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt index 8ba7c37..80298aa 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt @@ -1,12 +1,10 @@ package top.fatweb.api.controller.system import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag import jakarta.validation.Valid import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import top.fatweb.api.annotation.BaseController import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.param.system.SysLogGetParam @@ -21,9 +19,7 @@ import top.fatweb.api.vo.system.SysLogVo * @since 1.0.0 * @see ISysLogService */ -@Tag(name = "系统日志", description = "系统日志相关接口") -@RequestMapping("/system/log") -@RestController +@BaseController(path = ["/system/log"], name = "系统日志", description = "系统日志相关接口") class SysLogController( private val sysLogService: ISysLogService ) { diff --git a/src/main/kotlin/top/fatweb/api/util/ApiResponseMappingHandlerMapping.kt b/src/main/kotlin/top/fatweb/api/util/ApiResponseMappingHandlerMapping.kt index 2ebac11..df7c23c 100644 --- a/src/main/kotlin/top/fatweb/api/util/ApiResponseMappingHandlerMapping.kt +++ b/src/main/kotlin/top/fatweb/api/util/ApiResponseMappingHandlerMapping.kt @@ -1,9 +1,8 @@ package top.fatweb.api.util -import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.servlet.mvc.condition.RequestCondition import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping -import top.fatweb.api.annotation.ApiVersion +import top.fatweb.api.annotation.ApiController import java.lang.reflect.Method /** @@ -13,22 +12,12 @@ import java.lang.reflect.Method * @since 1.0.0 */ class ApiResponseMappingHandlerMapping : RequestMappingHandlerMapping() { - private val versionFlag = "{apiVersion}" private fun createCondition(clazz: Class<*>): RequestCondition? { - val classRequestMapping = clazz.getAnnotation(RequestMapping::class.java) - classRequestMapping ?: let { return null } - val mappingUrlBuilder = StringBuilder() - if (classRequestMapping.value.isNotEmpty()) { - mappingUrlBuilder.append(classRequestMapping.value[0]) - } - val mappingUrl = mappingUrlBuilder.toString() - if (!mappingUrl.contains(versionFlag)) { - return null - } - val apiVersion = clazz.getAnnotation(ApiVersion::class.java) + val apiController = clazz.getAnnotation(ApiController::class.java) + apiController ?: let { return null } - return if (apiVersion == null) ApiVersionCondition(1) else ApiVersionCondition(apiVersion.version) + return ApiVersionCondition(apiController.version) } override fun getCustomMethodCondition(method: Method): RequestCondition<*>? = createCondition(method.javaClass) diff --git a/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt b/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt index 788a545..b5a4a83 100644 --- a/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt +++ b/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt @@ -10,7 +10,7 @@ import org.springframework.web.servlet.mvc.condition.RequestCondition * @since 1.0.0 */ class ApiVersionCondition(private val apiVersion: Int) : RequestCondition { - private val versionPrefixRegex = Regex(".*v(\\d+).*") + private val versionPrefixRegex = Regex("/api/v(\\d+)/.*") override fun combine(other: ApiVersionCondition): ApiVersionCondition = ApiVersionCondition(other.apiVersion) From e3d31bcc3879321ba4d8f713aa6e37f61fa2fa03 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 18 Dec 2023 14:35:55 +0800 Subject: [PATCH 146/258] Add aop to record event log --- pom.xml | 4 ++ .../fatweb/api/annotation/EventLogRecord.kt | 9 +++++ .../top/fatweb/api/aop/EventLogAspect.kt | 39 +++++++++++++++++++ .../impl/AuthenticationServiceImpl.kt | 4 ++ 4 files changed, 56 insertions(+) create mode 100644 src/main/kotlin/top/fatweb/api/annotation/EventLogRecord.kt create mode 100644 src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt diff --git a/pom.xml b/pom.xml index 4ab8946..225ece4 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,10 @@ org.springframework.boot spring-boot-starter-actuator + + org.springframework.boot + spring-boot-starter-aop + org.springframework.boot spring-boot-starter-security diff --git a/src/main/kotlin/top/fatweb/api/annotation/EventLogRecord.kt b/src/main/kotlin/top/fatweb/api/annotation/EventLogRecord.kt new file mode 100644 index 0000000..2cdda01 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/annotation/EventLogRecord.kt @@ -0,0 +1,9 @@ +package top.fatweb.api.annotation + +import top.fatweb.api.entity.system.EventLog + +@Target(AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.RUNTIME) +annotation class EventLogRecord( + val event: EventLog.Event +) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt b/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt new file mode 100644 index 0000000..87fb550 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt @@ -0,0 +1,39 @@ +package top.fatweb.api.aop + +import org.aspectj.lang.JoinPoint +import org.aspectj.lang.annotation.AfterReturning +import org.aspectj.lang.annotation.Aspect +import org.aspectj.lang.annotation.Pointcut +import org.aspectj.lang.reflect.MethodSignature +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Component +import top.fatweb.api.annotation.EventLogRecord +import top.fatweb.api.entity.system.EventLog +import top.fatweb.api.service.system.IEventLogService +import top.fatweb.api.util.WebUtil + +@Aspect +@Component +class EventLogAspect( + private val eventLogService: IEventLogService +) { + private val logger: Logger = LoggerFactory.getLogger(this::class.java) + + @Pointcut("@annotation(top.fatweb.api.annotation.EventLogRecord)") + fun eventLogPointcut() {} + + @AfterReturning("eventLogPointcut()") + fun doAfter(joinPoint: JoinPoint) { + val annotation = (joinPoint.signature as MethodSignature).method.getAnnotation(EventLogRecord::class.java) + + try { + eventLogService.save(EventLog().apply { + this.event = annotation.event + operateUserId = WebUtil.getLoginUserId() ?: -1 + }) + } catch (e: Exception) { + logger.error("Cannot record event!!!", e) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index e98291a..a9da6e0 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -7,8 +7,10 @@ import org.slf4j.LoggerFactory import org.springframework.security.authentication.AuthenticationManager import org.springframework.security.authentication.UsernamePasswordAuthenticationToken import org.springframework.stereotype.Service +import top.fatweb.api.annotation.EventLogRecord import top.fatweb.api.entity.permission.LoginUser import top.fatweb.api.entity.permission.User +import top.fatweb.api.entity.system.EventLog import top.fatweb.api.exception.TokenHasExpiredException import top.fatweb.api.properties.SecurityProperties import top.fatweb.api.service.permission.IAuthenticationService @@ -39,6 +41,7 @@ class AuthenticationServiceImpl( ) : IAuthenticationService { private val logger: Logger = LoggerFactory.getLogger(this::class.java) + @EventLogRecord(EventLog.Event.LOGIN) override fun login(request: HttpServletRequest, user: User): LoginVo { val usernamePasswordAuthenticationToken = UsernamePasswordAuthenticationToken(user.username, user.password) val authentication = authenticationManager.authenticate(usernamePasswordAuthenticationToken) @@ -70,6 +73,7 @@ class AuthenticationServiceImpl( return LoginVo(jwt, loginUser.user.currentLoginTime, loginUser.user.currentLoginIp) } + @EventLogRecord(EventLog.Event.LOGOUT) override fun logout(token: String): Boolean { val loginUser = WebUtil.getLoginUser() ?: let { throw TokenHasExpiredException() } From 0f5d1fad4b57c680a1a366748cb30a536f0ee9f8 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 18 Dec 2023 18:02:21 +0800 Subject: [PATCH 147/258] Add get online info api --- .../controller/system/StatisticController.kt | 15 +++++++--- .../api/service/system/IStatisticService.kt | 8 +++++ .../system/impl/StatisticServiceImpl.kt | 29 ++++++++++++++++++- .../top/fatweb/api/vo/system/OnlineInfoVo.kt | 13 +++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt diff --git a/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt b/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt index a279220..c67b55d 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt @@ -5,10 +5,7 @@ import org.springframework.web.bind.annotation.GetMapping import top.fatweb.api.annotation.BaseController import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.service.system.IStatisticService -import top.fatweb.api.vo.system.CpuInfoVo -import top.fatweb.api.vo.system.HardwareInfoVo -import top.fatweb.api.vo.system.SoftwareInfoVo -import top.fatweb.api.vo.system.StorageInfoVo +import top.fatweb.api.vo.system.* /** * Statistic controller @@ -72,4 +69,14 @@ class StatisticController( @Operation(summary = "获取存储信息") @GetMapping("/storage") fun storage(): ResponseResult = ResponseResult.success(data = statisticService.storage()) + + /** + * Get the number of online users information + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "获取在线用户数量信息") + @GetMapping("/online") + fun online(): ResponseResult = ResponseResult.success(data = statisticService.online()) } \ 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/IStatisticService.kt index 7f37b35..3f1d812 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt @@ -48,4 +48,12 @@ interface IStatisticService { * @see StorageInfoVo */ fun storage(): StorageInfoVo + + /** + * Get the number of online users information + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun online(): OnlineInfoVo } \ 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/StatisticServiceImpl.kt index fb141d9..9254ca3 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt @@ -1,11 +1,16 @@ package top.fatweb.api.service.system.impl +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import org.springframework.stereotype.Service import oshi.SystemInfo import oshi.hardware.CentralProcessor +import top.fatweb.api.entity.system.StatisticLog +import top.fatweb.api.properties.SecurityProperties import top.fatweb.api.properties.ServerProperties +import top.fatweb.api.service.system.IStatisticLogService import top.fatweb.api.service.system.IStatisticService import top.fatweb.api.util.ByteUtil +import top.fatweb.api.util.RedisUtil import top.fatweb.api.vo.system.* import java.time.LocalDateTime import java.time.ZoneOffset @@ -19,7 +24,10 @@ import java.util.concurrent.TimeUnit * @since 1.0.0 */ @Service -class StatisticServiceImpl : IStatisticService { +class StatisticServiceImpl( + private val redisUtil: RedisUtil, + private val statisticLogService: IStatisticLogService +) : IStatisticService { private val systemProperties: Properties = System.getProperties() private val systemInfo: SystemInfo = SystemInfo() private val runtime: Runtime = Runtime.getRuntime() @@ -142,4 +150,23 @@ class StatisticServiceImpl : IStatisticService { ) } ) + + override fun online(): OnlineInfoVo { + val history: List = statisticLogService.list( + KtQueryWrapper(StatisticLog()) + .select(StatisticLog::value, StatisticLog::recordTime) + .eq(StatisticLog::key, StatisticLog.KeyItem.ONLINE_USERS_COUNT) + ).map { + OnlineInfoVo.HistoryVo( + time = it.recordTime!!, + record = it.value!! + ) + } + + return OnlineInfoVo( + current = redisUtil.keys("${SecurityProperties.jwtIssuer}_login_*") + .distinctBy { Regex("FatWeb_login_(.*):.*").matchEntire(it)?.groupValues?.getOrNull(1) }.size.toLong(), + history = history + ) + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt new file mode 100644 index 0000000..9164ff3 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt @@ -0,0 +1,13 @@ +package top.fatweb.api.vo.system + +import java.time.LocalDateTime + +data class OnlineInfoVo( + val current: Long, + val history: List +) { + data class HistoryVo ( + val time: LocalDateTime, + val record: String + ) +} From aa4d70ce99ad4234d537727dfdab2e813a2e342f Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 18 Dec 2023 18:28:38 +0800 Subject: [PATCH 148/258] Add kdoc --- .../fatweb/api/annotation/ApiController.kt | 9 +++++ .../fatweb/api/annotation/BaseController.kt | 8 +++++ .../fatweb/api/annotation/EventLogRecord.kt | 6 ++++ .../fatweb/api/annotation/HiddenController.kt | 9 +++++ .../top/fatweb/api/aop/EventLogAspect.kt | 6 ++++ .../api/config/WebMvcConfigurerConfig.kt | 8 +++++ .../api/config/WebMvcRegistrationsConfig.kt | 2 +- .../top/fatweb/api/vo/system/OnlineInfoVo.kt | 34 +++++++++++++++++++ 8 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/top/fatweb/api/annotation/ApiController.kt b/src/main/kotlin/top/fatweb/api/annotation/ApiController.kt index 5649f5e..0382a56 100644 --- a/src/main/kotlin/top/fatweb/api/annotation/ApiController.kt +++ b/src/main/kotlin/top/fatweb/api/annotation/ApiController.kt @@ -5,6 +5,15 @@ import org.springframework.core.annotation.AliasFor import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +/** + * API controller annotation + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tag + * @see RequestMapping + * @see RestController + */ @Tag(name = "") @RequestMapping @RestController diff --git a/src/main/kotlin/top/fatweb/api/annotation/BaseController.kt b/src/main/kotlin/top/fatweb/api/annotation/BaseController.kt index 1d810f5..029fa05 100644 --- a/src/main/kotlin/top/fatweb/api/annotation/BaseController.kt +++ b/src/main/kotlin/top/fatweb/api/annotation/BaseController.kt @@ -5,6 +5,14 @@ import org.springframework.core.annotation.AliasFor import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +/** + * Base controller annotation + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RequestMapping + * @see RestController + */ @Tag(name = "") @RequestMapping @RestController diff --git a/src/main/kotlin/top/fatweb/api/annotation/EventLogRecord.kt b/src/main/kotlin/top/fatweb/api/annotation/EventLogRecord.kt index 2cdda01..4eb87e0 100644 --- a/src/main/kotlin/top/fatweb/api/annotation/EventLogRecord.kt +++ b/src/main/kotlin/top/fatweb/api/annotation/EventLogRecord.kt @@ -2,6 +2,12 @@ package top.fatweb.api.annotation import top.fatweb.api.entity.system.EventLog +/** + * Event log record annotation + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.RUNTIME) annotation class EventLogRecord( diff --git a/src/main/kotlin/top/fatweb/api/annotation/HiddenController.kt b/src/main/kotlin/top/fatweb/api/annotation/HiddenController.kt index ef121b3..5e593e5 100644 --- a/src/main/kotlin/top/fatweb/api/annotation/HiddenController.kt +++ b/src/main/kotlin/top/fatweb/api/annotation/HiddenController.kt @@ -5,6 +5,15 @@ import org.springframework.core.annotation.AliasFor import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +/** + * Hidden controller annotation + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Hidden + * @see RequestMapping + * @see RestController + */ @Hidden @RequestMapping @RestController diff --git a/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt b/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt index 87fb550..44c3a54 100644 --- a/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt +++ b/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt @@ -13,6 +13,12 @@ import top.fatweb.api.entity.system.EventLog import top.fatweb.api.service.system.IEventLogService import top.fatweb.api.util.WebUtil +/** + * Event log record aspect + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @Aspect @Component class EventLogAspect( diff --git a/src/main/kotlin/top/fatweb/api/config/WebMvcConfigurerConfig.kt b/src/main/kotlin/top/fatweb/api/config/WebMvcConfigurerConfig.kt index ceed4df..f2453a8 100644 --- a/src/main/kotlin/top/fatweb/api/config/WebMvcConfigurerConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/WebMvcConfigurerConfig.kt @@ -1,10 +1,18 @@ package top.fatweb.api.config +import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations import org.springframework.context.annotation.Configuration import org.springframework.web.servlet.config.annotation.PathMatchConfigurer import org.springframework.web.servlet.config.annotation.WebMvcConfigurer import top.fatweb.api.annotation.ApiController +/** + * Web MVC configurer configuration + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see WebMvcRegistrations + */ @Configuration class WebMvcConfigurerConfig : WebMvcConfigurer { override fun configurePathMatch(configurer: PathMatchConfigurer) { diff --git a/src/main/kotlin/top/fatweb/api/config/WebMvcRegistrationsConfig.kt b/src/main/kotlin/top/fatweb/api/config/WebMvcRegistrationsConfig.kt index 6fcf518..d5a1a26 100644 --- a/src/main/kotlin/top/fatweb/api/config/WebMvcRegistrationsConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/WebMvcRegistrationsConfig.kt @@ -6,7 +6,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl import top.fatweb.api.util.ApiResponseMappingHandlerMapping /** - * Web MVC configuration + * Web MVC registrations configuration * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt index 9164ff3..982671e 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt @@ -2,12 +2,46 @@ package top.fatweb.api.vo.system import java.time.LocalDateTime +/** + * Online information value object + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ data class OnlineInfoVo( + /** + * Number of user currently online + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ val current: Long, + + /** + * Online number history + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see HistoryVo + */ val history: List ) { data class HistoryVo ( + /** + * Time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ val time: LocalDateTime, + + /** + * Record + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ val record: String ) } From 7e792ca35dc2b9bc83e42f60df881cac099e62bb Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 19 Dec 2023 10:26:19 +0800 Subject: [PATCH 149/258] Add scope option to online info api --- .../controller/system/StatisticController.kt | 4 ++- .../api/param/system/OnlineInfoGetParam.kt | 28 +++++++++++++++++++ .../api/service/system/IStatisticService.kt | 3 +- .../system/impl/StatisticServiceImpl.kt | 20 ++++++++++++- .../kotlin/top/fatweb/api/util/EventUtil.kt | 25 ----------------- 5 files changed, 52 insertions(+), 28 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/param/system/OnlineInfoGetParam.kt delete mode 100644 src/main/kotlin/top/fatweb/api/util/EventUtil.kt diff --git a/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt b/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt index c67b55d..9aff799 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.Operation 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.OnlineInfoGetParam import top.fatweb.api.service.system.IStatisticService import top.fatweb.api.vo.system.* @@ -78,5 +79,6 @@ class StatisticController( */ @Operation(summary = "获取在线用户数量信息") @GetMapping("/online") - fun online(): ResponseResult = ResponseResult.success(data = statisticService.online()) + fun online(onlineInfoGetParam: OnlineInfoGetParam?): ResponseResult = + ResponseResult.success(data = statisticService.online(onlineInfoGetParam)) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/param/system/OnlineInfoGetParam.kt b/src/main/kotlin/top/fatweb/api/param/system/OnlineInfoGetParam.kt new file mode 100644 index 0000000..e3158d1 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/param/system/OnlineInfoGetParam.kt @@ -0,0 +1,28 @@ +package top.fatweb.api.param.system + +import com.baomidou.mybatisplus.annotation.EnumValue +import com.fasterxml.jackson.annotation.JsonValue + +data class OnlineInfoGetParam( + val scope: Scope = Scope.WEAK +) { + enum class Scope(@field:EnumValue @field:JsonValue val code: String) { + DAY("DAY"), + + WEAK("WEAK"), + + MONTH("MONTH"), + + QUARTER("QUARTER"), + + YEAR("YEAR"), + + TWO_YEARS("TWO_YEARS"), + + THREE_YEARS("THREE_YEARS"), + + FIVE_YEARS("FIVE_YEARS"), + + ALL("ALL") + } +} diff --git a/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt b/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt index 3f1d812..750b592 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt @@ -1,5 +1,6 @@ package top.fatweb.api.service.system +import top.fatweb.api.param.system.OnlineInfoGetParam import top.fatweb.api.vo.system.* /** @@ -55,5 +56,5 @@ interface IStatisticService { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - fun online(): OnlineInfoVo + fun online(onlineInfoGetParam: OnlineInfoGetParam?): OnlineInfoVo } \ 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/StatisticServiceImpl.kt index 9254ca3..c8aec6f 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service import oshi.SystemInfo import oshi.hardware.CentralProcessor import top.fatweb.api.entity.system.StatisticLog +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.IStatisticLogService @@ -151,11 +152,28 @@ class StatisticServiceImpl( } ) - override fun online(): OnlineInfoVo { + 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) + .between( + onlineInfoGetParam?.scope != OnlineInfoGetParam.Scope.ALL, + StatisticLog::recordTime, + LocalDateTime.now(ZoneOffset.UTC).run { + when (onlineInfoGetParam?.scope) { + OnlineInfoGetParam.Scope.DAY -> minusDays(1) + OnlineInfoGetParam.Scope.MONTH -> minusMonths(1) + OnlineInfoGetParam.Scope.QUARTER -> minusMonths(3) + OnlineInfoGetParam.Scope.YEAR -> minusYears(1) + OnlineInfoGetParam.Scope.TWO_YEARS -> minusYears(2) + OnlineInfoGetParam.Scope.THREE_YEARS -> minusYears(3) + OnlineInfoGetParam.Scope.FIVE_YEARS -> minusYears(5) + else -> minusWeeks(1) + } + }, + LocalDateTime.now(ZoneOffset.UTC) + ) ).map { OnlineInfoVo.HistoryVo( time = it.recordTime!!, diff --git a/src/main/kotlin/top/fatweb/api/util/EventUtil.kt b/src/main/kotlin/top/fatweb/api/util/EventUtil.kt deleted file mode 100644 index 75cc2c4..0000000 --- a/src/main/kotlin/top/fatweb/api/util/EventUtil.kt +++ /dev/null @@ -1,25 +0,0 @@ -package top.fatweb.api.util - -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Component -import top.fatweb.api.entity.system.EventLog -import top.fatweb.api.service.system.IEventLogService - -@Component -class EventUtil( - private val eventLogService: IEventLogService -) { - private val logger: Logger = LoggerFactory.getLogger(this::class.java) - - fun record(event: EventLog.Event) { - try { - eventLogService.save(EventLog().apply { - this.event = event - operateUserId = WebUtil.getLoginUserId() ?: -1 - }) - } catch (e: Exception) { - logger.error("Cannot record event!!!", e) - } - } -} \ No newline at end of file From b2b4ac530259b23522de49556d6ecd9a73506a55 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 19 Dec 2023 16:52:53 +0800 Subject: [PATCH 150/258] Add active information api --- .../top/fatweb/api/aop/EventLogAspect.kt | 11 +++-- .../controller/system/StatisticController.kt | 14 +++++- .../api/interceptor/SysLogInterceptor.kt | 7 ++- .../api/param/system/ActiveInfoGetParam.kt | 26 ++++++++++ .../impl/AuthenticationServiceImpl.kt | 2 +- .../api/service/system/IStatisticService.kt | 11 ++++- .../system/impl/StatisticServiceImpl.kt | 44 +++++++++++++++-- .../top/fatweb/api/vo/permission/LoginVo.kt | 15 ++++++ .../top/fatweb/api/vo/system/ActiveInfoVo.kt | 48 +++++++++++++++++++ .../top/fatweb/api/vo/system/OnlineInfoVo.kt | 3 +- 10 files changed, 169 insertions(+), 12 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/param/system/ActiveInfoGetParam.kt create mode 100644 src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt diff --git a/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt b/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt index 44c3a54..9d1fe2a 100644 --- a/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt +++ b/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt @@ -12,6 +12,7 @@ import top.fatweb.api.annotation.EventLogRecord import top.fatweb.api.entity.system.EventLog import top.fatweb.api.service.system.IEventLogService import top.fatweb.api.util.WebUtil +import top.fatweb.api.vo.permission.LoginVo /** * Event log record aspect @@ -27,16 +28,18 @@ class EventLogAspect( private val logger: Logger = LoggerFactory.getLogger(this::class.java) @Pointcut("@annotation(top.fatweb.api.annotation.EventLogRecord)") - fun eventLogPointcut() {} + fun eventLogPointcut() { + } - @AfterReturning("eventLogPointcut()") - fun doAfter(joinPoint: JoinPoint) { + @AfterReturning(value = "eventLogPointcut()", returning = "retValue") + fun doAfter(joinPoint: JoinPoint, retValue: Any) { val annotation = (joinPoint.signature as MethodSignature).method.getAnnotation(EventLogRecord::class.java) try { eventLogService.save(EventLog().apply { this.event = annotation.event - operateUserId = WebUtil.getLoginUserId() ?: -1 + operateUserId = WebUtil.getLoginUserId() + ?: if (retValue is LoginVo) retValue.userId else -1 }) } catch (e: Exception) { logger.error("Cannot record event!!!", e) diff --git a/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt b/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt index 9aff799..0b207db 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/StatisticController.kt @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.Operation 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.vo.system.* @@ -72,7 +73,7 @@ class StatisticController( fun storage(): ResponseResult = ResponseResult.success(data = statisticService.storage()) /** - * Get the number of online users information + * Get the history of online users information * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 @@ -81,4 +82,15 @@ class StatisticController( @GetMapping("/online") fun online(onlineInfoGetParam: OnlineInfoGetParam?): ResponseResult = ResponseResult.success(data = statisticService.online(onlineInfoGetParam)) + + /** + * Get the history of active information + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "获取用户活跃信息") + @GetMapping("/active") + 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/interceptor/SysLogInterceptor.kt b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt index d424d3c..ab10b5b 100644 --- a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt +++ b/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt @@ -16,6 +16,7 @@ import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.entity.system.SysLog import top.fatweb.api.service.system.ISysLogService import top.fatweb.api.util.WebUtil +import top.fatweb.api.vo.permission.LoginVo import java.net.URI import java.time.LocalDateTime import java.time.ZoneOffset @@ -33,7 +34,8 @@ import java.util.concurrent.Executor */ @ControllerAdvice class SysLogInterceptor( - @Qualifier("applicationTaskExecutor") private val customThreadPoolTaskExecutor: Executor, private val sysLogService: ISysLogService + @Qualifier("applicationTaskExecutor") private val customThreadPoolTaskExecutor: Executor, + private val sysLogService: ISysLogService ) : HandlerInterceptor, ResponseBodyAdvice { private val sysLogThreadLocal = ThreadLocal() private val resultThreadLocal = ThreadLocal() @@ -77,6 +79,9 @@ class SysLogInterceptor( } ?: SysLog.LogType.INFO exception = 0 } + if (result.data is LoginVo) { + sysLog.operateUserId = result.data.userId ?: -1 + } } else { sysLog.apply { logType = SysLog.LogType.ERROR diff --git a/src/main/kotlin/top/fatweb/api/param/system/ActiveInfoGetParam.kt b/src/main/kotlin/top/fatweb/api/param/system/ActiveInfoGetParam.kt new file mode 100644 index 0000000..7681e52 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/param/system/ActiveInfoGetParam.kt @@ -0,0 +1,26 @@ +package top.fatweb.api.param.system + +import com.baomidou.mybatisplus.annotation.EnumValue +import com.fasterxml.jackson.annotation.JsonValue + +data class ActiveInfoGetParam( + val scope: Scope = Scope.WEAK +) { + enum class Scope(@field:EnumValue @field:JsonValue val code: String) { + WEAK("WEAK"), + + MONTH("MONTH"), + + QUARTER("QUARTER"), + + YEAR("YEAR"), + + TWO_YEARS("TWO_YEARS"), + + THREE_YEARS("THREE_YEARS"), + + FIVE_YEARS("FIVE_YEARS"), + + ALL("ALL") + } +} diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index a9da6e0..2e4f5cb 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -70,7 +70,7 @@ class AuthenticationServiceImpl( val redisKey = "${SecurityProperties.jwtIssuer}_login_${userId}:" + jwt redisUtil.setObject(redisKey, loginUser, SecurityProperties.redisTtl, SecurityProperties.redisTtlUnit) - return LoginVo(jwt, loginUser.user.currentLoginTime, loginUser.user.currentLoginIp) + return LoginVo(jwt, loginUser.user.id, loginUser.user.currentLoginTime, loginUser.user.currentLoginIp) } @EventLogRecord(EventLog.Event.LOGOUT) diff --git a/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt b/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt index 750b592..a84c741 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/IStatisticService.kt @@ -1,5 +1,6 @@ package top.fatweb.api.service.system +import top.fatweb.api.param.system.ActiveInfoGetParam import top.fatweb.api.param.system.OnlineInfoGetParam import top.fatweb.api.vo.system.* @@ -51,10 +52,18 @@ interface IStatisticService { fun storage(): StorageInfoVo /** - * Get the number of online users information + * Get the history of online users information * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ fun online(onlineInfoGetParam: OnlineInfoGetParam?): OnlineInfoVo + + /** + * Get the history of active information + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun active(activeInfoGetParam: ActiveInfoGetParam?): ActiveInfoVo } \ 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/StatisticServiceImpl.kt index c8aec6f..cf93c3a 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticServiceImpl.kt @@ -1,20 +1,26 @@ package top.fatweb.api.service.system.impl +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper 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.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.util.ByteUtil import top.fatweb.api.util.RedisUtil import top.fatweb.api.vo.system.* +import java.time.LocalDate import java.time.LocalDateTime import java.time.ZoneOffset +import java.time.format.DateTimeFormatter import java.util.* import java.util.concurrent.TimeUnit @@ -27,7 +33,8 @@ import java.util.concurrent.TimeUnit @Service class StatisticServiceImpl( private val redisUtil: RedisUtil, - private val statisticLogService: IStatisticLogService + private val statisticLogService: IStatisticLogService, + private val eventLogService: IEventLogService ) : IStatisticService { private val systemProperties: Properties = System.getProperties() private val systemInfo: SystemInfo = SystemInfo() @@ -171,8 +178,8 @@ class StatisticServiceImpl( OnlineInfoGetParam.Scope.FIVE_YEARS -> minusYears(5) else -> minusWeeks(1) } - }, - LocalDateTime.now(ZoneOffset.UTC) + }.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), + LocalDateTime.now(ZoneOffset.UTC).plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) ) ).map { OnlineInfoVo.HistoryVo( @@ -187,4 +194,35 @@ class StatisticServiceImpl( history = history ) } + + override fun active(activeInfoGetParam: ActiveInfoGetParam?): ActiveInfoVo { + fun getHistory(event: String) = eventLogService.listMaps( + QueryWrapper().select("strftime('%Y-%m-%d', operate_time) time, count(distinct operate_user_id) count") + .eq("event", event).groupBy("time").between( + activeInfoGetParam?.scope != ActiveInfoGetParam.Scope.ALL, + "operate_time", + LocalDateTime.now(ZoneOffset.UTC).run { + when (activeInfoGetParam?.scope) { + ActiveInfoGetParam.Scope.MONTH -> minusMonths(1) + ActiveInfoGetParam.Scope.QUARTER -> minusMonths(3) + ActiveInfoGetParam.Scope.YEAR -> minusYears(1) + ActiveInfoGetParam.Scope.TWO_YEARS -> minusYears(2) + ActiveInfoGetParam.Scope.THREE_YEARS -> minusYears(3) + ActiveInfoGetParam.Scope.FIVE_YEARS -> minusYears(5) + else -> minusWeeks(1) + } + }.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), + LocalDateTime.now(ZoneOffset.UTC).plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ) + ).map { + ActiveInfoVo.HistoryVo( + LocalDate.parse( + it["time"] as String, + DateTimeFormatter.ofPattern("yyyy-MM-dd") + ), it["count"] as Int + ) + } + + return ActiveInfoVo(getHistory("REGISTER"), getHistory("LOGIN")) + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/LoginVo.kt b/src/main/kotlin/top/fatweb/api/vo/permission/LoginVo.kt index 2e724ba..8b130eb 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/LoginVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/permission/LoginVo.kt @@ -1,5 +1,7 @@ package top.fatweb.api.vo.permission +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema import java.time.LocalDateTime @@ -22,6 +24,19 @@ data class LoginVo( example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYTllYjFkYmVmZDQ0OWRkOThlOGNjNzZlNzZkMDgyNSIsInN1YiI6IjE3MDk5ODYwNTg2Nzk5NzU5MzgiLCJpc3MiOiJGYXRXZWIiLCJpYXQiOjE2OTY1MjgxMTcsImV4cCI6MTY5NjUzNTMxN30.U2ZsyrGk7NbsP-DJfdz9xgWSfect5r2iKQnlEsscAA8" ) val token: String, + /** + * User ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema( + description = "User ID", + example = "1709986058679975938" + ) + @JsonSerialize(using = ToStringSerializer::class) + val userId: Long?, + /** * Last login time * diff --git a/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt new file mode 100644 index 0000000..5aa59f7 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt @@ -0,0 +1,48 @@ +package top.fatweb.api.vo.system + +import top.fatweb.api.vo.system.ActiveInfoVo.HistoryVo +import java.time.LocalDate + +/** + * Active information value object + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class ActiveInfoVo( + /** + * Register user number history + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + val registerHistory: List, + + /** + * Login user number history + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see HistoryVo + */ + val loginHistory: List +) { + data class HistoryVo( + /** + * Time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDate + */ + val time: LocalDate, + + /** + * Count + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + val count: Int + ) +} diff --git a/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt index 982671e..d98ddf7 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt @@ -1,5 +1,6 @@ package top.fatweb.api.vo.system +import top.fatweb.api.vo.system.OnlineInfoVo.HistoryVo import java.time.LocalDateTime /** @@ -26,7 +27,7 @@ data class OnlineInfoVo( */ val history: List ) { - data class HistoryVo ( + data class HistoryVo( /** * Time * From 60353906adf7c93cce445057e436bf67c52bef83 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 20 Dec 2023 11:32:47 +0800 Subject: [PATCH 151/258] 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, -- 记录键 From e7c8311b833135317161cf2e70dfcb40dd53177d Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 20 Dec 2023 14:55:30 +0800 Subject: [PATCH 152/258] Support login with email --- .../permission/AuthenticationController.kt | 3 +-- .../api/converter/permission/UserConverter.kt | 16 ---------------- .../fatweb/api/mapper/permission/UserMapper.kt | 6 +++--- .../fatweb/api/param/permission/LoginParam.kt | 8 ++++---- .../api/param/permission/user/UserAddParam.kt | 2 ++ .../api/param/permission/user/UserUpdateParam.kt | 2 ++ .../service/permission/IAuthenticationService.kt | 5 +++-- .../api/service/permission/IUserService.kt | 6 +++--- .../permission/impl/AuthenticationServiceImpl.kt | 10 ++++++---- .../permission/impl/UserDetailsServiceImpl.kt | 4 ++-- .../service/permission/impl/UserServiceImpl.kt | 6 +++--- .../V1_0_0_231104__Add_table_'t_user_info'.sql | 5 +++-- .../resources/mapper/permission/UserMapper.xml | 4 ++-- 13 files changed, 34 insertions(+), 43 deletions(-) diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt index f5acf94..c6f52e0 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt @@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import top.fatweb.api.annotation.BaseController -import top.fatweb.api.converter.permission.UserConverter import top.fatweb.api.entity.common.ResponseCode import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.param.permission.LoginParam @@ -46,7 +45,7 @@ class AuthenticationController( ResponseResult.success( ResponseCode.PERMISSION_LOGIN_SUCCESS, "Login success", - authenticationService.login(request, UserConverter.loginParamToUser(loginParam)) + authenticationService.login(request, loginParam) ) /** diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/UserConverter.kt b/src/main/kotlin/top/fatweb/api/converter/permission/UserConverter.kt index 1d3cb5b..c488e3d 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/UserConverter.kt +++ b/src/main/kotlin/top/fatweb/api/converter/permission/UserConverter.kt @@ -5,7 +5,6 @@ import top.fatweb.api.entity.permission.Group import top.fatweb.api.entity.permission.Role import top.fatweb.api.entity.permission.User import top.fatweb.api.entity.permission.UserInfo -import top.fatweb.api.param.permission.LoginParam import top.fatweb.api.param.permission.user.UserAddParam import top.fatweb.api.param.permission.user.UserUpdateParam import top.fatweb.api.vo.PageVo @@ -22,21 +21,6 @@ import top.fatweb.avatargenerator.GitHubAvatar * @since 1.0.0 */ object UserConverter { - /** - * Convert LoginParam object into User object - * - * @param loginParam LoginParam object - * @return User object - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see LoginParam - * @see User - */ - fun loginParamToUser(loginParam: LoginParam) = User().apply { - username = loginParam.username - password = loginParam.password - } - /** * Convert User object into UserWithPowerInfoVo object * diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt index 88f3c39..5a3489f 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt @@ -17,15 +17,15 @@ import top.fatweb.api.entity.permission.User @Mapper interface UserMapper : BaseMapper { /** - * Select one user with power and information by username + * Select one user with power and information by username or email * - * @param username Username + * @param account Username or email * @return User object with power and information * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see User */ - fun selectOneWithPowerInfoByUsername(@Param("username") username: String): User? + fun selectOneWithPowerInfoByAccount(@Param("account") account: String): User? /** * Select user in page diff --git a/src/main/kotlin/top/fatweb/api/param/permission/LoginParam.kt b/src/main/kotlin/top/fatweb/api/param/permission/LoginParam.kt index b937123..a638d53 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/LoginParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/permission/LoginParam.kt @@ -12,14 +12,14 @@ import jakarta.validation.constraints.NotBlank @Schema(description = "登录请求参数") data class LoginParam( /** - * Username + * Account * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @Schema(description = "用户名", example = "test", required = true) - @field:NotBlank(message = "Username can not be blank") - val username: String? = null, + @Schema(description = "账户", example = "test", required = true) + @field:NotBlank(message = "Account can not be blank") + val account: String? = null, /** * Password diff --git a/src/main/kotlin/top/fatweb/api/param/permission/user/UserAddParam.kt b/src/main/kotlin/top/fatweb/api/param/permission/user/UserAddParam.kt index f4fc726..50e7f14 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/user/UserAddParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/permission/user/UserAddParam.kt @@ -2,6 +2,7 @@ package top.fatweb.api.param.permission.user import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.Pattern import java.time.LocalDateTime /** @@ -94,6 +95,7 @@ data class UserAddParam( * @since 1.0.0 */ @Schema(description = "邮箱") + @Pattern(regexp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\$", message = "Illegal email address") val email: String?, /** diff --git a/src/main/kotlin/top/fatweb/api/param/permission/user/UserUpdateParam.kt b/src/main/kotlin/top/fatweb/api/param/permission/user/UserUpdateParam.kt index 8d9f350..eb76dbe 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/user/UserUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/permission/user/UserUpdateParam.kt @@ -2,6 +2,7 @@ package top.fatweb.api.param.permission.user import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern import java.time.LocalDateTime /** @@ -94,6 +95,7 @@ data class UserUpdateParam( * @since 1.0.0 */ @Schema(description = "邮箱") + @Pattern(regexp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\$", message = "Illegal email address") val email: String?, /** diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt index b6d459b..3ec2c2b 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt @@ -2,6 +2,7 @@ package top.fatweb.api.service.permission import jakarta.servlet.http.HttpServletRequest import top.fatweb.api.entity.permission.User +import top.fatweb.api.param.permission.LoginParam import top.fatweb.api.vo.permission.LoginVo import top.fatweb.api.vo.permission.TokenVo @@ -16,7 +17,7 @@ interface IAuthenticationService { * Login * * @param request - * @param user User object + * @param loginParam Login parameters * @return LoginVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 @@ -24,7 +25,7 @@ interface IAuthenticationService { * @see User * @see LoginVo */ - fun login(request: HttpServletRequest, user: User): LoginVo + fun login(request: HttpServletRequest, loginParam: LoginParam): LoginVo /** * Logout diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt index 5dc403a..a208420 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt @@ -19,15 +19,15 @@ import top.fatweb.api.vo.permission.UserWithRoleInfoVo */ interface IUserService : IService { /** - * Get user with power by username + * Get user with power by username or email * - * @param username Username + * @param account Username or email * @return User object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see User */ - fun getUserWithPowerByUsername(username: String): User? + fun getUserWithPowerByAccount(account: String): User? /** * Get user information diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index 2e4f5cb..c57a22a 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -12,6 +12,7 @@ import top.fatweb.api.entity.permission.LoginUser import top.fatweb.api.entity.permission.User import top.fatweb.api.entity.system.EventLog import top.fatweb.api.exception.TokenHasExpiredException +import top.fatweb.api.param.permission.LoginParam import top.fatweb.api.properties.SecurityProperties import top.fatweb.api.service.permission.IAuthenticationService import top.fatweb.api.service.permission.IUserService @@ -42,8 +43,9 @@ class AuthenticationServiceImpl( private val logger: Logger = LoggerFactory.getLogger(this::class.java) @EventLogRecord(EventLog.Event.LOGIN) - override fun login(request: HttpServletRequest, user: User): LoginVo { - val usernamePasswordAuthenticationToken = UsernamePasswordAuthenticationToken(user.username, user.password) + override fun login(request: HttpServletRequest, loginParam: LoginParam): LoginVo { + val usernamePasswordAuthenticationToken = + UsernamePasswordAuthenticationToken(loginParam.account, loginParam.password) val authentication = authenticationManager.authenticate(usernamePasswordAuthenticationToken) authentication ?: let { throw RuntimeException("Login failed") @@ -52,13 +54,13 @@ class AuthenticationServiceImpl( val loginUser = authentication.principal as LoginUser loginUser.user.password = "" - logger.info("用户登录 [用户名: '{}', IP: '{}']", user.username, request.remoteAddr) + logger.info("用户登录 [用户名: '{}', IP: '{}']", loginUser.username, request.remoteAddr) userService.update(User().apply { currentLoginIp = request.remoteAddr currentLoginTime = LocalDateTime.now(ZoneOffset.UTC) lastLoginIp = loginUser.user.currentLoginIp lastLoginTime = loginUser.user.currentLoginTime - }, KtUpdateWrapper(User()).eq(User::username, user.username)) + }, KtUpdateWrapper(User()).eq(User::username, loginUser.username)) val userId = loginUser.user.id.toString() val jwt = JwtUtil.createJwt(userId) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt index a1bce50..f92d344 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt @@ -16,8 +16,8 @@ import top.fatweb.api.service.permission.IUserService */ @Service class UserDetailsServiceImpl(val userService: IUserService) : UserDetailsService { - override fun loadUserByUsername(username: String): UserDetails { - val user = userService.getUserWithPowerByUsername(username) + override fun loadUserByUsername(account: String): UserDetails { + val user = userService.getUserWithPowerByAccount(account) user ?: let { throw Exception("Username not found") } return LoginUser(user) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt index 3dfa092..f35f537 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt @@ -61,8 +61,8 @@ class UserServiceImpl( private val userRoleService: IUserRoleService, private val userGroupService: IUserGroupService ) : ServiceImpl(), IUserService { - override fun getUserWithPowerByUsername(username: String): User? { - val user = baseMapper.selectOneWithPowerInfoByUsername(username) + override fun getUserWithPowerByAccount(account: String): User? { + val user = baseMapper.selectOneWithPowerInfoByAccount(account) user ?: let { return null } if (user.id == 0L) { @@ -76,7 +76,7 @@ class UserServiceImpl( } override fun getInfo() = WebUtil.getLoginUsername() - ?.let { username -> getUserWithPowerByUsername(username)?.let { UserConverter.userToUserWithPowerInfoVo(it) } } + ?.let { username -> getUserWithPowerByAccount(username)?.let { UserConverter.userToUserWithPowerInfoVo(it) } } override fun getPage(userGetParam: UserGetParam?): PageVo { val userIdsPage = Page(userGetParam?.currentPage ?: 1, userGetParam?.pageSize ?: 20) diff --git a/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql b/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql index 0231a70..916e1fa 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql @@ -6,10 +6,11 @@ create table if not exists t_user_info user_id bigint not null comment '用户ID', nickname varchar(50) null comment '昵称', avatar text null comment '头像', - email varchar(100) null comment '邮箱', + email varchar(100) not null comment '邮箱', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', deleted bigint not null default 0, version int not null default 0, - constraint t_user_info_unique unique (user_id, deleted) + constraint t_user_info_unique_user_id unique (user_id, deleted), + constraint t_user_info_unique_email unique (email, deleted) ) comment '用户资料表'; \ No newline at end of file diff --git a/src/main/resources/mapper/permission/UserMapper.xml b/src/main/resources/mapper/permission/UserMapper.xml index cf2ff7c..52587ee 100644 --- a/src/main/resources/mapper/permission/UserMapper.xml +++ b/src/main/resources/mapper/permission/UserMapper.xml @@ -1,7 +1,7 @@ - select t_user.id as user_id, t_user.username as user_username, t_user.password as user_password, @@ -55,7 +55,7 @@ left join t_func as tf on tp.id = tf.id left join t_operation as t on tp.id = t.id where t_user.deleted = 0 - and t_user.username = #{username}; + and (tui.email = #{account} or t_user.username = #{account}); select t_user.id as user_id, t_user.username as user_username, - t_user.password as user_password, + t_user.verify as user_verify, t_user.locking as user_locking, t_user.expiration as user_expiration, t_user.credentials_expiration as user_credentials_expiration, @@ -177,7 +177,7 @@ select t_user.id as user_id, t_user.username as user_username, - t_user.password as user_password, + t_user.verify as user_verify, t_user.locking as user_locking, t_user.expiration as user_expiration, t_user.credentials_expiration as user_credentials_expiration, @@ -282,6 +282,7 @@ + diff --git a/src/main/resources/templates/email-verify-account-cn.vm b/src/main/resources/templates/email-verify-account-cn.vm new file mode 100644 index 0000000..ed1cc63 --- /dev/null +++ b/src/main/resources/templates/email-verify-account-cn.vm @@ -0,0 +1,85 @@ + + + + + + + 激活您的账号 + + + +

+
+
账 号 激 活
+
${username},您好:
+
感谢注册 ${appName}(${appUrl}),在继续使用之前,我们需要确定您的电子邮箱地址的有效性,请在 两小时内 点击下面的按钮帮助我们验证:
+ +
如果以上按钮无法点击,请复制此链接到浏览器地址栏中访问:${verifyUrl}
+
此邮件由系统自动发送,请勿回复!
+
+
+ + \ No newline at end of file From 47befa2a813e1e9b60ba32cab3a45e38e63798e8 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sat, 23 Dec 2023 16:28:18 +0800 Subject: [PATCH 156/258] Fix sql wrong file name. Fix can not save email settings bug. --- .../kotlin/top/fatweb/api/settings/SettingsOperator.kt | 7 ++----- ...sql => V1_0_0_231214__Add_table_'t_statistics_log'.sql} | 0 2 files changed, 2 insertions(+), 5 deletions(-) rename src/main/resources/db/migration/sqlite/{V1_0_0_231214__Add_table_'t_statistics'.sql => V1_0_0_231214__Add_table_'t_statistics_log'.sql} (100%) diff --git a/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt b/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt index 7b4f23e..9e023e7 100644 --- a/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt +++ b/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt @@ -91,11 +91,8 @@ object SettingsOperator { } } field.set(it, value) - } ?: { - MailSettings().also { - field.set(it, value) - systemSettings.mail = it - } + } ?: let { + systemSettings.mail = MailSettings().also { field.set(it, value) } } saveSettingsToFile() diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics_log'.sql similarity index 100% rename from src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics'.sql rename to src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics_log'.sql From 31358107c727b23ef498c5dbd22cc189c9a7ae3b Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 24 Dec 2023 23:46:24 +0800 Subject: [PATCH 157/258] Fix error user verify. Auto set nickname when register. --- .../api/service/permission/impl/AuthenticationServiceImpl.kt | 1 + src/main/resources/mapper/permission/UserMapper.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index 41f5331..122995b 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -76,6 +76,7 @@ class AuthenticationServiceImpl( userService.save(user) userInfoService.save(UserInfo().apply { userId = user.id + nickname = registerParam.username avatar = avatarService.randomBase64(null).base64 email = registerParam.email }) diff --git a/src/main/resources/mapper/permission/UserMapper.xml b/src/main/resources/mapper/permission/UserMapper.xml index 71e3c93..9242428 100644 --- a/src/main/resources/mapper/permission/UserMapper.xml +++ b/src/main/resources/mapper/permission/UserMapper.xml @@ -5,6 +5,7 @@ select t_user.id as user_id, t_user.username as user_username, t_user.password as user_password, + t_user.verify as user_verify, t_user.locking as user_locking, t_user.expiration as user_expiration, t_user.credentials_expiration as user_credentials_expiration, From 15f631971c9d420731139f9c9139e0fb4b99887c Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 25 Dec 2023 17:27:50 +0800 Subject: [PATCH 158/258] Optimize code. Add kdoc. --- .../top/fatweb/api/aop/EventLogAspect.kt | 21 +++++++--------- .../permission/AuthenticationController.kt | 9 +++---- .../top/fatweb/api/cron/StatisticsCron.kt | 12 ++++++++++ .../top/fatweb/api/entity/system/EventLog.kt | 2 +- .../api/exception/AccountNeedInitException.kt | 6 +++++ .../api/exception/NoEmailConfigException.kt | 6 +++++ .../NoVerificationRequiredException.kt | 6 +++++ ...VerificationCodeErrorOrExpiredException.kt | 6 +++++ .../api/mapper/system/EventLogMapper.kt | 6 +++++ .../api/mapper/system/StatisticsLogMapper.kt | 6 +++++ .../api/param/permission/user/UserAddParam.kt | 1 + .../api/param/system/ActiveInfoGetParam.kt | 6 +++++ .../api/param/system/OnlineInfoGetParam.kt | 6 +++++ .../permission/IAuthenticationService.kt | 3 ++- .../impl/AuthenticationServiceImpl.kt | 13 ++++++---- .../permission/impl/UserServiceImpl.kt | 23 +++++++++++++----- .../api/service/system/IEventLogService.kt | 11 ++++++++- .../service/system/IStatisticsLogService.kt | 6 +++++ .../system/impl/EventLogServiceImpl.kt | 21 +++++++++++++++- .../system/impl/StatisticsServiceImpl.kt | 2 +- .../fatweb/api/settings/MailSecurityType.kt | 6 +++++ .../kotlin/top/fatweb/api/util/MailUtil.kt | 6 +++++ .../fatweb/api/vo/permission/RegisterVo.kt | 24 +++++++++++++++++++ .../top/fatweb/api/vo/system/ActiveInfoVo.kt | 10 +++++++- .../V1_0_0_231019__Add_table_'t_user'.sql | 2 +- ...V1_0_0_231104__Add_table_'t_user_info'.sql | 2 +- .../templates/email-verify-account-cn.vm | 2 +- 27 files changed, 188 insertions(+), 36 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/api/vo/permission/RegisterVo.kt diff --git a/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt b/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt index 9d1fe2a..28c03c1 100644 --- a/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt +++ b/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt @@ -5,14 +5,12 @@ import org.aspectj.lang.annotation.AfterReturning import org.aspectj.lang.annotation.Aspect import org.aspectj.lang.annotation.Pointcut import org.aspectj.lang.reflect.MethodSignature -import org.slf4j.Logger -import org.slf4j.LoggerFactory import org.springframework.stereotype.Component import top.fatweb.api.annotation.EventLogRecord -import top.fatweb.api.entity.system.EventLog import top.fatweb.api.service.system.IEventLogService import top.fatweb.api.util.WebUtil import top.fatweb.api.vo.permission.LoginVo +import top.fatweb.api.vo.permission.RegisterVo /** * Event log record aspect @@ -25,24 +23,21 @@ import top.fatweb.api.vo.permission.LoginVo class EventLogAspect( private val eventLogService: IEventLogService ) { - private val logger: Logger = LoggerFactory.getLogger(this::class.java) @Pointcut("@annotation(top.fatweb.api.annotation.EventLogRecord)") fun eventLogPointcut() { } @AfterReturning(value = "eventLogPointcut()", returning = "retValue") - fun doAfter(joinPoint: JoinPoint, retValue: Any) { + fun doAfter(joinPoint: JoinPoint, retValue: Any?) { val annotation = (joinPoint.signature as MethodSignature).method.getAnnotation(EventLogRecord::class.java) - try { - eventLogService.save(EventLog().apply { - this.event = annotation.event - operateUserId = WebUtil.getLoginUserId() - ?: if (retValue is LoginVo) retValue.userId else -1 - }) - } catch (e: Exception) { - logger.error("Cannot record event!!!", e) + val userId = WebUtil.getLoginUserId() ?: when (retValue) { + is LoginVo -> retValue.userId!! + is RegisterVo -> retValue.userId!! + else -> -1 } + + eventLogService.saveEvent(annotation, userId) } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt index 6db34c2..fb77f50 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt @@ -15,6 +15,7 @@ import top.fatweb.api.param.permission.VerifyParam import top.fatweb.api.service.permission.IAuthenticationService import top.fatweb.api.util.WebUtil import top.fatweb.api.vo.permission.LoginVo +import top.fatweb.api.vo.permission.RegisterVo import top.fatweb.api.vo.permission.TokenVo /** @@ -36,11 +37,11 @@ class AuthenticationController( */ @Operation(summary = "注册") @PostMapping("/register") - fun register(@Valid @RequestBody registerParam: RegisterParam): ResponseResult { - authenticationService.register(registerParam) + fun register(@Valid @RequestBody registerParam: RegisterParam): ResponseResult = ResponseResult.success( + ResponseCode.PERMISSION_REGISTER_SUCCESS, + data = authenticationService.register(registerParam) + ) - return ResponseResult.success(ResponseCode.PERMISSION_REGISTER_SUCCESS) - } /** * Send verify email diff --git a/src/main/kotlin/top/fatweb/api/cron/StatisticsCron.kt b/src/main/kotlin/top/fatweb/api/cron/StatisticsCron.kt index 5408c4c..26677b1 100644 --- a/src/main/kotlin/top/fatweb/api/cron/StatisticsCron.kt +++ b/src/main/kotlin/top/fatweb/api/cron/StatisticsCron.kt @@ -7,11 +7,23 @@ import top.fatweb.api.properties.SecurityProperties import top.fatweb.api.service.system.IStatisticsLogService import top.fatweb.api.util.RedisUtil +/** + * Statistics scheduled tasks + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @Component class StatisticsCron( private val redisUtil: RedisUtil, private val statisticsLogService: IStatisticsLogService ) { + /** + * Auto record number of online users + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @Scheduled(cron = "0 * * * * *") fun onlineUserCount() { statisticsLogService.save(StatisticsLog().apply { diff --git a/src/main/kotlin/top/fatweb/api/entity/system/EventLog.kt b/src/main/kotlin/top/fatweb/api/entity/system/EventLog.kt index 5d28307..e09f86f 100644 --- a/src/main/kotlin/top/fatweb/api/entity/system/EventLog.kt +++ b/src/main/kotlin/top/fatweb/api/entity/system/EventLog.kt @@ -18,7 +18,7 @@ import java.time.LocalDateTime @TableName("t_event_log") class EventLog : Serializable { enum class Event(@field:EnumValue @field:JsonValue val code: String) { - LOGIN("LOGIN"), LOGOUT("LOGOUT"), REGISTER("REGISTER"), API("API") + LOGIN("LOGIN"), LOGOUT("LOGOUT"), REGISTER("REGISTER"), VERIFY("VERIFY"), API("API") } /** diff --git a/src/main/kotlin/top/fatweb/api/exception/AccountNeedInitException.kt b/src/main/kotlin/top/fatweb/api/exception/AccountNeedInitException.kt index e46093a..7f9056d 100644 --- a/src/main/kotlin/top/fatweb/api/exception/AccountNeedInitException.kt +++ b/src/main/kotlin/top/fatweb/api/exception/AccountNeedInitException.kt @@ -1,3 +1,9 @@ package top.fatweb.api.exception +/** + * Account need initialize exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ class AccountNeedInitException : RuntimeException("Account need initialize") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/exception/NoEmailConfigException.kt b/src/main/kotlin/top/fatweb/api/exception/NoEmailConfigException.kt index 07fdf50..a695abc 100644 --- a/src/main/kotlin/top/fatweb/api/exception/NoEmailConfigException.kt +++ b/src/main/kotlin/top/fatweb/api/exception/NoEmailConfigException.kt @@ -1,5 +1,11 @@ package top.fatweb.api.exception +/** + * Email settings not configured exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ class NoEmailConfigException( vararg configs: String ) : RuntimeException("Email settings not configured: ${configs.joinToString(", ")}") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/exception/NoVerificationRequiredException.kt b/src/main/kotlin/top/fatweb/api/exception/NoVerificationRequiredException.kt index 46a6233..5d26ae2 100644 --- a/src/main/kotlin/top/fatweb/api/exception/NoVerificationRequiredException.kt +++ b/src/main/kotlin/top/fatweb/api/exception/NoVerificationRequiredException.kt @@ -1,3 +1,9 @@ package top.fatweb.api.exception +/** + * No verification required exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ class NoVerificationRequiredException : RuntimeException("No verification required") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/exception/VerificationCodeErrorOrExpiredException.kt b/src/main/kotlin/top/fatweb/api/exception/VerificationCodeErrorOrExpiredException.kt index fcd3cd9..f3316ee 100644 --- a/src/main/kotlin/top/fatweb/api/exception/VerificationCodeErrorOrExpiredException.kt +++ b/src/main/kotlin/top/fatweb/api/exception/VerificationCodeErrorOrExpiredException.kt @@ -1,3 +1,9 @@ package top.fatweb.api.exception +/** + * Verification code error or expired exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ class VerificationCodeErrorOrExpiredException : RuntimeException("Verification code is error or has expired") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/mapper/system/EventLogMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/system/EventLogMapper.kt index 11177ba..8bf0da4 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/system/EventLogMapper.kt +++ b/src/main/kotlin/top/fatweb/api/mapper/system/EventLogMapper.kt @@ -4,5 +4,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper import top.fatweb.api.entity.system.EventLog +/** + * Event log mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @Mapper interface EventLogMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/mapper/system/StatisticsLogMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/system/StatisticsLogMapper.kt index 85bd9ce..1d60659 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/system/StatisticsLogMapper.kt +++ b/src/main/kotlin/top/fatweb/api/mapper/system/StatisticsLogMapper.kt @@ -4,5 +4,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper import top.fatweb.api.entity.system.StatisticsLog +/** + * Statistics log mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @Mapper interface StatisticsLogMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/param/permission/user/UserAddParam.kt b/src/main/kotlin/top/fatweb/api/param/permission/user/UserAddParam.kt index 9209c33..6176452 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/user/UserAddParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/permission/user/UserAddParam.kt @@ -86,6 +86,7 @@ data class UserAddParam( * @since 1.0.0 */ @Schema(description = "昵称") + @field:NotBlank(message = "Nickname can not be blank") val nickname: String?, /** diff --git a/src/main/kotlin/top/fatweb/api/param/system/ActiveInfoGetParam.kt b/src/main/kotlin/top/fatweb/api/param/system/ActiveInfoGetParam.kt index 7681e52..b7057fa 100644 --- a/src/main/kotlin/top/fatweb/api/param/system/ActiveInfoGetParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/system/ActiveInfoGetParam.kt @@ -3,6 +3,12 @@ package top.fatweb.api.param.system import com.baomidou.mybatisplus.annotation.EnumValue import com.fasterxml.jackson.annotation.JsonValue +/** + * Get active information parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ data class ActiveInfoGetParam( val scope: Scope = Scope.WEAK ) { diff --git a/src/main/kotlin/top/fatweb/api/param/system/OnlineInfoGetParam.kt b/src/main/kotlin/top/fatweb/api/param/system/OnlineInfoGetParam.kt index e3158d1..2b38ae6 100644 --- a/src/main/kotlin/top/fatweb/api/param/system/OnlineInfoGetParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/system/OnlineInfoGetParam.kt @@ -3,6 +3,12 @@ package top.fatweb.api.param.system import com.baomidou.mybatisplus.annotation.EnumValue import com.fasterxml.jackson.annotation.JsonValue +/** + * Get online information parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ data class OnlineInfoGetParam( val scope: Scope = Scope.WEAK ) { diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt index 11c0c25..7fe91fc 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt @@ -6,6 +6,7 @@ import top.fatweb.api.param.permission.LoginParam import top.fatweb.api.param.permission.RegisterParam import top.fatweb.api.param.permission.VerifyParam import top.fatweb.api.vo.permission.LoginVo +import top.fatweb.api.vo.permission.RegisterVo import top.fatweb.api.vo.permission.TokenVo /** @@ -21,7 +22,7 @@ interface IAuthenticationService { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - fun register(registerParam: RegisterParam) + fun register(registerParam: RegisterParam): RegisterVo /** * Send verify email diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index 122995b..35cce8f 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -34,6 +34,7 @@ import top.fatweb.api.util.MailUtil import top.fatweb.api.util.RedisUtil import top.fatweb.api.util.WebUtil import top.fatweb.api.vo.permission.LoginVo +import top.fatweb.api.vo.permission.RegisterVo import top.fatweb.api.vo.permission.TokenVo import java.io.StringWriter import java.time.Instant @@ -63,13 +64,14 @@ class AuthenticationServiceImpl( ) : IAuthenticationService { private val logger: Logger = LoggerFactory.getLogger(this::class.java) + @EventLogRecord(EventLog.Event.REGISTER) @Transactional - override fun register(registerParam: RegisterParam) { + override fun register(registerParam: RegisterParam): RegisterVo { val user = User().apply { username = registerParam.username password = passwordEncoder.encode(registerParam.password) verify = - "${LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli()}-${UUID.randomUUID()}" + "${LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli()}-${UUID.randomUUID()}-${UUID.randomUUID()}-${UUID.randomUUID()}" locking = 0 enable = 1 } @@ -82,6 +84,8 @@ class AuthenticationServiceImpl( }) sendVerifyMail(user.username!!, "http://localhost:5173/verify?code=${user.verify!!}", registerParam.email!!) + + return RegisterVo(userId = user.id) } @Transactional @@ -91,7 +95,7 @@ class AuthenticationServiceImpl( user.verify ?: throw NoVerificationRequiredException() user.verify = - "${LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli()}-${UUID.randomUUID()}" + "${LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli()}-${UUID.randomUUID()}-${UUID.randomUUID()}-${UUID.randomUUID()}" user.updateTime = LocalDateTime.now(ZoneOffset.UTC) userService.updateById(user) @@ -113,11 +117,12 @@ class AuthenticationServiceImpl( template.merge(velocityContext, stringWriter) MailUtil.sendSimpleMail( - "激活您的账号", stringWriter.toString(), true, + "验证您的账号", stringWriter.toString(), true, email ) } + @EventLogRecord(EventLog.Event.VERIFY) @Transactional override fun verify(verifyParam: VerifyParam) { val user = userService.getById(WebUtil.getLoginUserId()) ?: throw AccessDeniedException("Access Denied") diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt index 151ecc8..e8c57bd 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt @@ -28,6 +28,7 @@ import top.fatweb.api.vo.permission.UserWithPasswordRoleInfoVo import top.fatweb.api.vo.permission.UserWithRoleInfoVo import java.time.LocalDateTime import java.time.ZoneOffset +import java.util.* /** * User service implement @@ -111,9 +112,12 @@ class UserServiceImpl( user.apply { password = passwordEncoder.encode(rawPassword) + verify = if (userAddParam.verified) null else "${ + LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli() + }-${UUID.randomUUID()}-${UUID.randomUUID()}-${UUID.randomUUID()}" } - if (baseMapper.insert(user) == 1) { + if (this.save(user)) { user.userInfo?.let { userInfoService.save(it.apply { userId = user.id }) } if (!user.roles.isNullOrEmpty()) { @@ -175,9 +179,16 @@ class UserServiceImpl( removeGroupIds.removeAll(addGroupIds) oldGroupList.toSet().let { addGroupIds.removeAll(it) } - baseMapper.updateById(user) - baseMapper.update( - KtUpdateWrapper(User()).eq(User::id, user.id).set(User::expiration, user.expiration) + this.updateById(user) + this.update( + KtUpdateWrapper(User()).eq(User::id, user.id) + .set( + User::verify, + if (userUpdateParam.verified) null else "${ + LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli() + }-${UUID.randomUUID()}-${UUID.randomUUID()}-${UUID.randomUUID()}" + ) + .set(User::expiration, user.expiration) .set(User::credentialsExpiration, user.credentialsExpiration) ) @@ -230,7 +241,7 @@ class UserServiceImpl( throw AccessDeniedException("Access denied") } - val user = baseMapper.selectById(userUpdatePasswordParam.id) + val user = this.getById(userUpdatePasswordParam.id) user?.let { val wrapper = KtUpdateWrapper(User()) wrapper.eq(User::id, user.id) @@ -265,7 +276,7 @@ class UserServiceImpl( return } - baseMapper.deleteBatchIds(ids) + this.removeBatchByIds(ids) userInfoService.remove(KtQueryWrapper(UserInfo()).`in`(UserInfo::userId, ids)) userRoleService.remove(KtQueryWrapper(UserRole()).`in`(UserRole::userId, ids)) userGroupService.remove(KtQueryWrapper(UserGroup()).`in`(UserGroup::userId, ids)) diff --git a/src/main/kotlin/top/fatweb/api/service/system/IEventLogService.kt b/src/main/kotlin/top/fatweb/api/service/system/IEventLogService.kt index 481c946..ae45841 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/IEventLogService.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/IEventLogService.kt @@ -1,6 +1,15 @@ package top.fatweb.api.service.system import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.annotation.EventLogRecord import top.fatweb.api.entity.system.EventLog -interface IEventLogService : IService \ No newline at end of file +/** + * Event log service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +interface IEventLogService : IService { + fun saveEvent(annotation: EventLogRecord, userId: Long) +} \ 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 index 56136c8..e6cb5de 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/IStatisticsLogService.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/IStatisticsLogService.kt @@ -3,4 +3,10 @@ package top.fatweb.api.service.system import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.api.entity.system.StatisticsLog +/** + * Statistics log service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ interface IStatisticsLogService : IService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/EventLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/EventLogServiceImpl.kt index b1e20d0..0f7e7a2 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/EventLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/EventLogServiceImpl.kt @@ -2,11 +2,30 @@ package top.fatweb.api.service.system.impl import com.baomidou.dynamic.datasource.annotation.DS import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.slf4j.Logger +import org.slf4j.LoggerFactory import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Propagation +import org.springframework.transaction.annotation.Transactional +import top.fatweb.api.annotation.EventLogRecord import top.fatweb.api.entity.system.EventLog import top.fatweb.api.mapper.system.EventLogMapper import top.fatweb.api.service.system.IEventLogService @DS("sqlite") @Service -class EventLogServiceImpl : ServiceImpl(), IEventLogService \ No newline at end of file +class EventLogServiceImpl : ServiceImpl(), IEventLogService { + private val logger: Logger = LoggerFactory.getLogger(this::class.java) + + @Transactional(propagation = Propagation.REQUIRES_NEW) + override fun saveEvent(annotation: EventLogRecord, userId: Long) { + try { + this.save(EventLog().apply { + this.event = annotation.event + operateUserId = userId + }) + } catch (e: Exception) { + logger.error("Cannot record event!!!", e) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt index 49289a9..4100a69 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt @@ -223,6 +223,6 @@ class StatisticsServiceImpl( ) } - return ActiveInfoVo(getHistory("REGISTER"), getHistory("LOGIN")) + return ActiveInfoVo(getHistory("REGISTER"), getHistory("LOGIN"), getHistory("VERIFY")) } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/settings/MailSecurityType.kt b/src/main/kotlin/top/fatweb/api/settings/MailSecurityType.kt index b7b1f85..7b2666d 100644 --- a/src/main/kotlin/top/fatweb/api/settings/MailSecurityType.kt +++ b/src/main/kotlin/top/fatweb/api/settings/MailSecurityType.kt @@ -3,6 +3,12 @@ package top.fatweb.api.settings import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonValue +/** + * Type of mail security + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ enum class MailSecurityType(val code: String) { NONE("None"), SSL_TLS("SSL/TLS"), diff --git a/src/main/kotlin/top/fatweb/api/util/MailUtil.kt b/src/main/kotlin/top/fatweb/api/util/MailUtil.kt index 198e7a1..bf1ba4a 100644 --- a/src/main/kotlin/top/fatweb/api/util/MailUtil.kt +++ b/src/main/kotlin/top/fatweb/api/util/MailUtil.kt @@ -8,6 +8,12 @@ import top.fatweb.api.settings.MailSettings import top.fatweb.api.settings.SettingsOperator import java.util.* +/** + * Mail util + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ object MailUtil { private val mailSender: JavaMailSenderImpl = JavaMailSenderImpl() diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/RegisterVo.kt b/src/main/kotlin/top/fatweb/api/vo/permission/RegisterVo.kt new file mode 100644 index 0000000..7561b0e --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/permission/RegisterVo.kt @@ -0,0 +1,24 @@ +package top.fatweb.api.vo.permission + +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer +import io.swagger.v3.oas.annotations.media.Schema + +/** + * Register value object + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(description = "注册返回参数") +data class RegisterVo( + /** + * User ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "User ID", example = "1709986058679975938") + @JsonSerialize(using = ToStringSerializer::class) + val userId: Long? +) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt index 5aa59f7..0b6f7c7 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt @@ -25,7 +25,15 @@ data class ActiveInfoVo( * @since 1.0.0 * @see HistoryVo */ - val loginHistory: List + val loginHistory: List, + + /** + * Verify user number history + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + val verifyHistory: List ) { data class HistoryVo( /** diff --git a/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_user'.sql b/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_user'.sql index 1220681..cd04c92 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_user'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_user'.sql @@ -5,7 +5,7 @@ create table if not exists t_user id bigint not null primary key, username varchar(20) not null comment '用户名', password char(70) not null comment '密码', - verify varchar(50) null comment '验证信息', + verify varchar(144) null comment '验证信息', locking int not null comment '锁定', expiration datetime comment '过期时间', credentials_expiration datetime comment '认证过期时间', diff --git a/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql b/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql index 916e1fa..75c3232 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql @@ -4,7 +4,7 @@ create table if not exists t_user_info ( id bigint not null primary key, user_id bigint not null comment '用户ID', - nickname varchar(50) null comment '昵称', + nickname varchar(50) not null comment '昵称', avatar text null comment '头像', email varchar(100) not null comment '邮箱', create_time datetime not null default (utc_timestamp()) comment '创建时间', diff --git a/src/main/resources/templates/email-verify-account-cn.vm b/src/main/resources/templates/email-verify-account-cn.vm index ed1cc63..c8f44c3 100644 --- a/src/main/resources/templates/email-verify-account-cn.vm +++ b/src/main/resources/templates/email-verify-account-cn.vm @@ -5,7 +5,7 @@ - 激活您的账号 + 验证您的账号 + + +
+
+
密 码 已 更 改
+
${username},您好:
+
您在 ${appName}(${appUrl}) 的密码已更改,操作 + IP 地址为 [${ipAddress}]。如果不是您自己的操作,请尽快检查您的账号! +
+
此邮件由系统自动发送,请勿回复!
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/email-retrieve-password-cn.vm b/src/main/resources/templates/email-retrieve-password-cn.vm new file mode 100644 index 0000000..d520710 --- /dev/null +++ b/src/main/resources/templates/email-retrieve-password-cn.vm @@ -0,0 +1,90 @@ + + + + + + + 找回您的密码 + + + +
+
+
找 回 密 码
+
${username},您好:
+
您正在找回 ${appName}(${appUrl}) 的密码,操作 + IP 地址为 [${ipAddress}],如果是您自己的操作,请在 两小时内 点击下面的按钮找回您的密码: +
+ +
如果以上按钮无法点击,请复制此链接到浏览器地址栏中访问:${retrieveUrl}
+
如果并非本人操作,请忽略该邮件
+
此邮件由系统自动发送,请勿回复!
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/email-verify-account-cn.vm b/src/main/resources/templates/email-verify-account-cn.vm index c8f44c3..ead9e3a 100644 --- a/src/main/resources/templates/email-verify-account-cn.vm +++ b/src/main/resources/templates/email-verify-account-cn.vm @@ -54,6 +54,7 @@ justify-content: center; } + .verify-button a { padding: 20px 30px; color: white; @@ -75,9 +76,12 @@
账 号 激 活
${username},您好:
-
感谢注册 ${appName}(${appUrl}),在继续使用之前,我们需要确定您的电子邮箱地址的有效性,请在 两小时内 点击下面的按钮帮助我们验证:
+
感谢注册 ${appName}(${appUrl}),在继续使用之前,我们需要确定您的电子邮箱地址的有效性,请在 + 两小时内 点击下面的按钮帮助我们验证: +
-
如果以上按钮无法点击,请复制此链接到浏览器地址栏中访问:${verifyUrl}
+
如果以上按钮无法点击,请复制此链接到浏览器地址栏中访问:${verifyUrl} +
此邮件由系统自动发送,请勿回复!
From 8cc7adc215fee184852e7102e8cb0aedfd57ddda Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 27 Dec 2023 10:07:33 +0800 Subject: [PATCH 160/258] Auto offline user when chang password --- .../api/service/permission/impl/AuthenticationServiceImpl.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index 5cd2f76..e818b46 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -202,6 +202,8 @@ class AuthenticationServiceImpl( .set(User::password, passwordEncoder.encode(retrieveParam.password!!)) ) + WebUtil.offlineUser(redisUtil, user.id!!) + sendPasswordChangedMail(user.username!!, request.remoteAddr, userInfo!!.email!!) } From 605f3f4152b09892f035d0000034db24daef50c4 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 27 Dec 2023 17:15:22 +0800 Subject: [PATCH 161/258] Add base settings management api --- .../top/fatweb/api/aop/EventLogAspect.kt | 17 +++- .../fatweb/api/config/VelocityEngineConfig.kt | 6 ++ .../permission/AuthenticationController.kt | 23 ++++++ .../controller/system/SettingsController.kt | 27 +++++++ .../api/converter/system/SettingsConverter.kt | 48 ----------- .../api/exception/AccountNeedInitException.kt | 1 + .../AccountNeedResetPasswordException.kt | 1 + .../api/exception/NoEmailConfigException.kt | 2 + .../NoVerificationRequiredException.kt | 1 + .../RetrieveCodeErrorOrExpiredException.kt | 7 ++ .../api/exception/UserNotFoundException.kt | 7 ++ ...VerificationCodeErrorOrExpiredException.kt | 1 + .../api/param/system/BaseSettingsParam.kt | 48 +++++++++++ .../permission/IAuthenticationService.kt | 14 ++++ .../impl/AuthenticationServiceImpl.kt | 30 +++++-- .../api/service/system/ISettingsService.kt | 24 +++++- .../system/impl/SettingsServiceImpl.kt | 39 +++++++-- .../top/fatweb/api/settings/BaseSettings.kt | 44 +++++++++++ .../fatweb/api/settings/SettingsOperator.kt | 79 +++++++++++++------ .../top/fatweb/api/settings/SystemSettings.kt | 8 ++ .../top/fatweb/api/vo/system/ActiveInfoVo.kt | 7 ++ .../fatweb/api/vo/system/BaseSettingsVo.kt | 48 +++++++++++ .../top/fatweb/api/vo/system/CpuInfoVo.kt | 12 +++ .../fatweb/api/vo/system/FileStoreInfoVo.kt | 6 ++ .../fatweb/api/vo/system/HardwareInfoVo.kt | 12 +++ .../fatweb/api/vo/system/MailSettingsVo.kt | 9 +++ .../top/fatweb/api/vo/system/OnlineInfoVo.kt | 6 ++ .../top/fatweb/api/vo/system/SettingsVo.kt | 5 ++ .../fatweb/api/vo/system/SoftwareInfoVo.kt | 16 ++++ .../top/fatweb/api/vo/system/StorageInfoVo.kt | 12 +++ 30 files changed, 471 insertions(+), 89 deletions(-) delete mode 100644 src/main/kotlin/top/fatweb/api/converter/system/SettingsConverter.kt create mode 100644 src/main/kotlin/top/fatweb/api/param/system/BaseSettingsParam.kt create mode 100644 src/main/kotlin/top/fatweb/api/settings/BaseSettings.kt create mode 100644 src/main/kotlin/top/fatweb/api/vo/system/BaseSettingsVo.kt diff --git a/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt b/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt index 28c03c1..b5c26d9 100644 --- a/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt +++ b/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt @@ -17,17 +17,32 @@ import top.fatweb.api.vo.permission.RegisterVo * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see IEventLogService */ @Aspect @Component class EventLogAspect( private val eventLogService: IEventLogService ) { - + /** + * Event log record pointcut + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @Pointcut("@annotation(top.fatweb.api.annotation.EventLogRecord)") fun eventLogPointcut() { } + /** + * Do after event log record pointcut + * + * @param joinPoint Join point + * @param retValue Return value + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see JoinPoint + */ @AfterReturning(value = "eventLogPointcut()", returning = "retValue") fun doAfter(joinPoint: JoinPoint, retValue: Any?) { val annotation = (joinPoint.signature as MethodSignature).method.getAnnotation(EventLogRecord::class.java) diff --git a/src/main/kotlin/top/fatweb/api/config/VelocityEngineConfig.kt b/src/main/kotlin/top/fatweb/api/config/VelocityEngineConfig.kt index fd97e7d..2ae172d 100644 --- a/src/main/kotlin/top/fatweb/api/config/VelocityEngineConfig.kt +++ b/src/main/kotlin/top/fatweb/api/config/VelocityEngineConfig.kt @@ -6,6 +6,12 @@ import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +/** + * Velocity engine configuration + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @Configuration class VelocityEngineConfig { @Bean diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt index dee6214..99ce14a 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt @@ -30,8 +30,13 @@ class AuthenticationController( /** * Register * + * @param registerParam Register parameters + * @return Response object includes user ID * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see RegisterParam + * @see ResponseResult + * @see RegisterVo */ @Operation(summary = "注册") @PostMapping("/register") @@ -44,8 +49,10 @@ class AuthenticationController( /** * Send verify email * + * @return Response object includes resend result * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ResponseResult */ @Operation(summary = "发送验证邮件") @PostMapping("/resend") @@ -58,8 +65,12 @@ class AuthenticationController( /** * Verify email * + * @param verifyParam Verify parameters + * @return Response object includes verify result * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see VerifyParam + * @see ResponseResult */ @Operation(summary = "验证邮箱") @PostMapping("/verify") @@ -72,8 +83,14 @@ class AuthenticationController( /** * Forget password * + * @param request + * @param forgetParam Forget parameters + * @return Response object includes forget result * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see HttpServletRequest + * @see ForgetParam + * @see ResponseResult */ @Operation(summary = "忘记密码") @PostMapping("/forget") @@ -86,8 +103,14 @@ class AuthenticationController( /** * Retrieve password * + * @param request + * @param retrieveParam Retrieve parameters + * @return Response object include retrieve result * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see HttpServletRequest + * @see RetrieveParam + * @see ResponseResult */ @Operation(summary = "找回密码") @PostMapping("/retrieve") diff --git a/src/main/kotlin/top/fatweb/api/controller/system/SettingsController.kt b/src/main/kotlin/top/fatweb/api/controller/system/SettingsController.kt index 56dad25..39a4cd6 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/SettingsController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/system/SettingsController.kt @@ -9,9 +9,11 @@ import org.springframework.web.bind.annotation.PutMapping import org.springframework.web.bind.annotation.RequestBody import top.fatweb.api.annotation.BaseController import top.fatweb.api.entity.common.ResponseResult +import top.fatweb.api.param.system.BaseSettingsParam import top.fatweb.api.param.system.MailSendParam import top.fatweb.api.param.system.MailSettingsParam import top.fatweb.api.service.system.ISettingsService +import top.fatweb.api.vo.system.BaseSettingsVo import top.fatweb.api.vo.system.MailSettingsVo /** @@ -25,6 +27,31 @@ import top.fatweb.api.vo.system.MailSettingsVo class SettingsController( private val settingsService: ISettingsService ) { + /** + * Get base settings + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "获取基础设置") + @GetMapping("/base") + @PreAuthorize("hasAnyAuthority('system:settings:query:base')") + fun getApp(): ResponseResult = ResponseResult.success(data = settingsService.getBase()) + + /** + * Update base settings + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "更新基础设置") + @PutMapping("/base") + @PreAuthorize("hasAnyAuthority('system:settings:modify:base')") + fun updateApp(@RequestBody baseSettingsParam: BaseSettingsParam): ResponseResult { + settingsService.updateBase(baseSettingsParam) + return ResponseResult.success() + } + /** * Get mail settings * diff --git a/src/main/kotlin/top/fatweb/api/converter/system/SettingsConverter.kt b/src/main/kotlin/top/fatweb/api/converter/system/SettingsConverter.kt deleted file mode 100644 index c3370ff..0000000 --- a/src/main/kotlin/top/fatweb/api/converter/system/SettingsConverter.kt +++ /dev/null @@ -1,48 +0,0 @@ -package top.fatweb.api.converter.system - -import top.fatweb.api.settings.MailSettings -import top.fatweb.api.settings.SystemSettings -import top.fatweb.api.vo.system.MailSettingsVo -import top.fatweb.api.vo.system.SettingsVo - -/** - * Settings converter - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ -object SettingsConverter { - /** - * Convert MailSettings object into MailSettingsVo object - * - * @param mailSettings MailSettings object - * @return MailSettingsVo object - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see MailSettings - * @see MailSettingsVo - */ - fun mailSettingsToMailSettingsVo(mailSettings: MailSettings) = MailSettingsVo( - host = mailSettings.host, - port = mailSettings.port, - securityType = mailSettings.securityType, - username = mailSettings.username, - password = mailSettings.password, - from = mailSettings.from, - fromName = mailSettings.fromName - ) - - /** - * Convert SystemSettings object into SettingVo object - * - * @param systemSettings SystemSettings object - * @return SettingsVo object - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see SystemSettings - * @see SettingsVo - */ - fun systemSettingsToSettingsVo(systemSettings: SystemSettings) = SettingsVo( - mail = systemSettings.mail?.let { mailSettingsToMailSettingsVo(it) } - ) -} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/exception/AccountNeedInitException.kt b/src/main/kotlin/top/fatweb/api/exception/AccountNeedInitException.kt index 7f9056d..ec1bdb5 100644 --- a/src/main/kotlin/top/fatweb/api/exception/AccountNeedInitException.kt +++ b/src/main/kotlin/top/fatweb/api/exception/AccountNeedInitException.kt @@ -5,5 +5,6 @@ package top.fatweb.api.exception * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see RuntimeException */ class AccountNeedInitException : RuntimeException("Account need initialize") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/exception/AccountNeedResetPasswordException.kt b/src/main/kotlin/top/fatweb/api/exception/AccountNeedResetPasswordException.kt index 79fc9e1..10f6767 100644 --- a/src/main/kotlin/top/fatweb/api/exception/AccountNeedResetPasswordException.kt +++ b/src/main/kotlin/top/fatweb/api/exception/AccountNeedResetPasswordException.kt @@ -5,5 +5,6 @@ package top.fatweb.api.exception * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see RuntimeException */ class AccountNeedResetPasswordException : RuntimeException("Account need reset password") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/exception/NoEmailConfigException.kt b/src/main/kotlin/top/fatweb/api/exception/NoEmailConfigException.kt index a695abc..0377775 100644 --- a/src/main/kotlin/top/fatweb/api/exception/NoEmailConfigException.kt +++ b/src/main/kotlin/top/fatweb/api/exception/NoEmailConfigException.kt @@ -3,8 +3,10 @@ package top.fatweb.api.exception /** * Email settings not configured exception * + * @param configs Configs not config * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see RuntimeException */ class NoEmailConfigException( vararg configs: String diff --git a/src/main/kotlin/top/fatweb/api/exception/NoVerificationRequiredException.kt b/src/main/kotlin/top/fatweb/api/exception/NoVerificationRequiredException.kt index 5d26ae2..4ae2c74 100644 --- a/src/main/kotlin/top/fatweb/api/exception/NoVerificationRequiredException.kt +++ b/src/main/kotlin/top/fatweb/api/exception/NoVerificationRequiredException.kt @@ -5,5 +5,6 @@ package top.fatweb.api.exception * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see RuntimeException */ class NoVerificationRequiredException : RuntimeException("No verification required") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/exception/RetrieveCodeErrorOrExpiredException.kt b/src/main/kotlin/top/fatweb/api/exception/RetrieveCodeErrorOrExpiredException.kt index a91616b..d73239e 100644 --- a/src/main/kotlin/top/fatweb/api/exception/RetrieveCodeErrorOrExpiredException.kt +++ b/src/main/kotlin/top/fatweb/api/exception/RetrieveCodeErrorOrExpiredException.kt @@ -1,3 +1,10 @@ package top.fatweb.api.exception +/** + * Retrieve code error or expired exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class RetrieveCodeErrorOrExpiredException : RuntimeException("Retrieve code error or expired") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/exception/UserNotFoundException.kt b/src/main/kotlin/top/fatweb/api/exception/UserNotFoundException.kt index 0779276..64b032b 100644 --- a/src/main/kotlin/top/fatweb/api/exception/UserNotFoundException.kt +++ b/src/main/kotlin/top/fatweb/api/exception/UserNotFoundException.kt @@ -1,3 +1,10 @@ package top.fatweb.api.exception +/** + * User not found exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class UserNotFoundException : RuntimeException("User not found") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/exception/VerificationCodeErrorOrExpiredException.kt b/src/main/kotlin/top/fatweb/api/exception/VerificationCodeErrorOrExpiredException.kt index f3316ee..9c28388 100644 --- a/src/main/kotlin/top/fatweb/api/exception/VerificationCodeErrorOrExpiredException.kt +++ b/src/main/kotlin/top/fatweb/api/exception/VerificationCodeErrorOrExpiredException.kt @@ -5,5 +5,6 @@ package top.fatweb.api.exception * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see RuntimeException */ class VerificationCodeErrorOrExpiredException : RuntimeException("Verification code is error or has expired") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/param/system/BaseSettingsParam.kt b/src/main/kotlin/top/fatweb/api/param/system/BaseSettingsParam.kt new file mode 100644 index 0000000..6d8bb4c --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/param/system/BaseSettingsParam.kt @@ -0,0 +1,48 @@ +package top.fatweb.api.param.system + +import io.swagger.v3.oas.annotations.media.Schema + +/** + * Base settings parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(description = "基础设置请求参数") +data class BaseSettingsParam( + /** + * Application name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "应用名称") + val appName: String?, + + /** + * Application URL + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "应用 URL") + val appUrl: String?, + + /** + * Verify URL + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "验证邮箱 URL") + val verifyUrl: String?, + + /** + * Retrieve URL + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "找回密码 URL") + val retrieveUrl: String? +) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt index cbf2483..050d2f3 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt @@ -17,8 +17,12 @@ interface IAuthenticationService { /** * Register * + * @param registerParam Register parameters + * @return RegisterVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see RegisterParam + * @see RegisterVo */ fun register(registerParam: RegisterParam): RegisterVo @@ -33,24 +37,34 @@ interface IAuthenticationService { /** * Verify email * + * @param verifyParam Verify parameters * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see VerifyParam */ fun verify(verifyParam: VerifyParam) /** * Forget password * + * @param request + * @param forgetParam Forget parameters * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see HttpServletRequest + * @see ForgetParam */ fun forget(request: HttpServletRequest, forgetParam: ForgetParam) /** * Retrieve password * + * @param request + * @param retrieveParam Retrieve parameters * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see HttpServletRequest + * @see RetrieveParam */ fun retrieve(request: HttpServletRequest, retrieveParam: RetrieveParam) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt index e818b46..63a178d 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -25,6 +25,8 @@ import top.fatweb.api.service.api.v1.IAvatarService import top.fatweb.api.service.permission.IAuthenticationService import top.fatweb.api.service.permission.IUserInfoService import top.fatweb.api.service.permission.IUserService +import top.fatweb.api.settings.BaseSettings +import top.fatweb.api.settings.SettingsOperator import top.fatweb.api.util.JwtUtil import top.fatweb.api.util.MailUtil import top.fatweb.api.util.RedisUtil @@ -106,10 +108,16 @@ class AuthenticationServiceImpl( private fun sendVerifyMail(username: String, code: String, email: String) { val velocityContext = VelocityContext().apply { - put("appName", "氮工具") - put("appUrl", "http://localhost:5173/") + put("appName", SettingsOperator.getAppValue(BaseSettings::appName, "氧工具")) + put("appUrl", SettingsOperator.getAppValue(BaseSettings::appUrl, "http://localhost")) put("username", username) - put("verifyUrl", "http://localhost:5173/verify?code=${code}") + put( + "verifyUrl", + SettingsOperator.getAppValue(BaseSettings::verifyUrl, "http://localhost/verify?code=\${verifyCode}") + .replace( + Regex("(?<=([^\\\\]))\\$\\{verifyCode}"), code + ) + ) } val template = velocityEngine.getTemplate("templates/email-verify-account-cn.vm") @@ -160,11 +168,17 @@ class AuthenticationServiceImpl( private fun sendRetrieveMail(username: String, ip: String, code: String, email: String) { val velocityContext = VelocityContext().apply { - put("appName", "氮工具") - put("appUrl", "http://localhost:5173/") + put("appName", SettingsOperator.getAppValue(BaseSettings::appName, "氧工具")) + put("appUrl", SettingsOperator.getAppValue(BaseSettings::appUrl, "http://localhost")) put("username", username) put("ipAddress", ip) - put("retrieveUrl", "http://localhost:5173/forget?code=${code}") + put( + "retrieveUrl", + SettingsOperator.getAppValue(BaseSettings::retrieveUrl, "http://localhost/retrieve?code=\${retrieveCode}") + .replace( + Regex("(?<=([^\\\\]))\\$\\{retrieveCode}"), code + ) + ) } val template = velocityEngine.getTemplate("templates/email-retrieve-password-cn.vm") @@ -209,8 +223,8 @@ class AuthenticationServiceImpl( private fun sendPasswordChangedMail(username: String, ip: String, email: String) { val velocityContext = VelocityContext().apply { - put("appName", "氮工具") - put("appUrl", "http://localhost:5173/") + put("appName", SettingsOperator.getAppValue(BaseSettings::appName, "氧工具")) + put("appUrl", SettingsOperator.getAppValue(BaseSettings::appUrl, "http://localhost")) put("username", username) put("ipAddress", ip) } diff --git a/src/main/kotlin/top/fatweb/api/service/system/ISettingsService.kt b/src/main/kotlin/top/fatweb/api/service/system/ISettingsService.kt index 9327762..0e8d29d 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/ISettingsService.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/ISettingsService.kt @@ -1,7 +1,9 @@ package top.fatweb.api.service.system +import top.fatweb.api.param.system.BaseSettingsParam import top.fatweb.api.param.system.MailSendParam import top.fatweb.api.param.system.MailSettingsParam +import top.fatweb.api.vo.system.BaseSettingsVo import top.fatweb.api.vo.system.MailSettingsVo /** @@ -11,10 +13,30 @@ import top.fatweb.api.vo.system.MailSettingsVo * @since 1.0.0 */ interface ISettingsService { + /** + * Get base settings + * + * @return BaseSettingsVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseSettingsVo + */ + fun getBase(): BaseSettingsVo? + + /** + * Update base settings + * + * @param baseSettingsParam Base settings parameters + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseSettingsParam + */ + fun updateBase(baseSettingsParam: BaseSettingsParam) + /** * Get mail settings * - * @return MailSettingVo object + * @return MailSettingsVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see MailSettingsVo diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/SettingsServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/SettingsServiceImpl.kt index 635d110..6a1da9c 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/SettingsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/system/impl/SettingsServiceImpl.kt @@ -1,14 +1,17 @@ package top.fatweb.api.service.system.impl import org.springframework.stereotype.Service -import top.fatweb.api.converter.system.SettingsConverter +import top.fatweb.api.param.system.BaseSettingsParam import top.fatweb.api.param.system.MailSendParam import top.fatweb.api.param.system.MailSettingsParam import top.fatweb.api.properties.ServerProperties import top.fatweb.api.service.system.ISettingsService +import top.fatweb.api.settings.BaseSettings import top.fatweb.api.settings.MailSettings import top.fatweb.api.settings.SettingsOperator import top.fatweb.api.util.MailUtil +import top.fatweb.api.util.StrUtil +import top.fatweb.api.vo.system.BaseSettingsVo import top.fatweb.api.vo.system.MailSettingsVo /** @@ -20,14 +23,40 @@ import top.fatweb.api.vo.system.MailSettingsVo */ @Service class SettingsServiceImpl : ISettingsService { - override fun getMail(): MailSettingsVo? = SettingsOperator.settings().mail?.let { - SettingsConverter.mailSettingsToMailSettingsVo( - it + override fun getBase() = BaseSettingsVo( + appName = SettingsOperator.getAppValue(BaseSettings::appName, "氧工具"), + appUrl = SettingsOperator.getAppValue(BaseSettings::appUrl, "http://localhost"), + verifyUrl = SettingsOperator.getAppValue( + BaseSettings::verifyUrl, + "http://localhost/verify?code=\${verifyCode}" + ), + retrieveUrl = SettingsOperator.getAppValue( + BaseSettings::retrieveUrl, + "http://localhost/retrieve?code=\${retrieveCode}" ) + ) + + override fun updateBase(baseSettingsParam: BaseSettingsParam) { + baseSettingsParam.run { + SettingsOperator.setAppValue(BaseSettings::appName, appName) + SettingsOperator.setAppValue(BaseSettings::appUrl, appUrl) + SettingsOperator.setAppValue(BaseSettings::verifyUrl, verifyUrl) + SettingsOperator.setAppValue(BaseSettings::retrieveUrl, retrieveUrl) + } } + override fun getMail() = MailSettingsVo( + host = SettingsOperator.getMailValue(MailSettings::host), + port = SettingsOperator.getMailValue(MailSettings::port), + securityType = SettingsOperator.getMailValue(MailSettings::securityType), + username = SettingsOperator.getMailValue(MailSettings::username), + password = SettingsOperator.getMailValue(MailSettings::password)?.let { StrUtil.md5(it) }, + from = SettingsOperator.getMailValue(MailSettings::from), + fromName = SettingsOperator.getMailValue(MailSettings::fromName) + ) + override fun updateMail(mailSettingsParam: MailSettingsParam) { - mailSettingsParam.apply { + mailSettingsParam.run { SettingsOperator.setMailValue(MailSettings::host, host) SettingsOperator.setMailValue(MailSettings::port, port) SettingsOperator.setMailValue(MailSettings::securityType, securityType) diff --git a/src/main/kotlin/top/fatweb/api/settings/BaseSettings.kt b/src/main/kotlin/top/fatweb/api/settings/BaseSettings.kt new file mode 100644 index 0000000..b1479db --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/settings/BaseSettings.kt @@ -0,0 +1,44 @@ +package top.fatweb.api.settings + +import com.fasterxml.jackson.annotation.JsonInclude + +/** + * Base settings entity + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@JsonInclude(JsonInclude.Include.NON_EMPTY) +data class BaseSettings( + /** + * Application name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var appName: String? = null, + + /** + * Application URL + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var appUrl: String? = null, + + /** + * Verify URL + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var verifyUrl: String? = null, + + /** + * Retrieve URL + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var retrieveUrl: String? = null +) diff --git a/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt b/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt index 9e023e7..8f346a9 100644 --- a/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt +++ b/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt @@ -71,6 +71,51 @@ object SettingsOperator { yamlMapper.writeValue(settingFile, systemSettings) } + /** + * Set base settings value + * + * @param field Field to set value. e.g. BaseSettings::appName + * @param value Value to set + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see KMutableProperty1 + * @see BaseSettings + */ + fun setAppValue(field: KMutableProperty1, value: V?) { + systemSettings.base?.let { + field.set(it, value) + } ?: let { + systemSettings.base = BaseSettings().also { field.set(it, value) } + } + + saveSettingsToFile() + } + + /** + * Get base settings value + * + * @param field Field to get value from. e.g. BaseSettings::appName + * @return Value + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see KMutableProperty1 + * @see BaseSettings + */ + fun getAppValue(field: KMutableProperty1): V? = this.getAppValue(field, null) + + /** + * Get base settings value with default value + * + * @param field Field to get value from. e.g. BaseSettings::appName + * @param default Return default value when setting not found + * @return Value + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see KMutableProperty1 + * @see BaseSettings + */ + fun getAppValue(field: KMutableProperty1, default: V): V = systemSettings.base?.let(field) ?: default + /** * Set mail settings value * @@ -108,36 +153,18 @@ object SettingsOperator { * @see KMutableProperty1 * @see MailSettings */ - fun getMailValue(field: KMutableProperty1): V? = systemSettings.mail?.let(field) + fun getMailValue(field: KMutableProperty1): V? = this.getMailValue(field, null) /** - * Get system settings object + * Get value from mail settings with default value * - * @return System settings object (Copy) + * @param field Field to get value from. e.g. MailSettings::host + * @param default Return default value when setting not found + * @return Value * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 - * @see SystemSettings + * @see KMutableProperty1 + * @see MailSettings */ - fun settings(): SystemSettings = systemSettings.copy( - mail = systemSettings.mail?.copy() - ).apply { - mail?.apply { - password = password?.let { - StrUtil.md5(it) - } - } - } - - /** - * Overwrite all settings - * - * @param systemSettings SystemSettings object - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see SystemSettings - */ - fun overwrite(systemSettings: SystemSettings) { - this.systemSettings = systemSettings - saveSettingsToFile() - } + fun getMailValue(field: KMutableProperty1, default: V): V = systemSettings.mail?.let(field) ?: default } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/settings/SystemSettings.kt b/src/main/kotlin/top/fatweb/api/settings/SystemSettings.kt index 8d49508..d186a21 100644 --- a/src/main/kotlin/top/fatweb/api/settings/SystemSettings.kt +++ b/src/main/kotlin/top/fatweb/api/settings/SystemSettings.kt @@ -10,6 +10,14 @@ import com.fasterxml.jackson.annotation.JsonInclude */ @JsonInclude(JsonInclude.Include.NON_EMPTY) data class SystemSettings( + /** + * Base setting + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var base: BaseSettings? = null, + /** * Mail setting * diff --git a/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt index 0b6f7c7..65f4b60 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt @@ -1,5 +1,6 @@ package top.fatweb.api.vo.system +import io.swagger.v3.oas.annotations.media.Schema import top.fatweb.api.vo.system.ActiveInfoVo.HistoryVo import java.time.LocalDate @@ -9,6 +10,7 @@ import java.time.LocalDate * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "用户活跃信息返回参数") data class ActiveInfoVo( /** * Register user number history @@ -16,6 +18,7 @@ data class ActiveInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "注册用户数量历史") val registerHistory: List, /** @@ -25,6 +28,7 @@ data class ActiveInfoVo( * @since 1.0.0 * @see HistoryVo */ + @Schema(description = "登录用户数量历史") val loginHistory: List, /** @@ -33,6 +37,7 @@ data class ActiveInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "验证用户数量历史") val verifyHistory: List ) { data class HistoryVo( @@ -43,6 +48,7 @@ data class ActiveInfoVo( * @since 1.0.0 * @see LocalDate */ + @Schema(description = "记录时间", example = "1900-01-01") val time: LocalDate, /** @@ -51,6 +57,7 @@ data class ActiveInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "数量") val count: Int ) } diff --git a/src/main/kotlin/top/fatweb/api/vo/system/BaseSettingsVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/BaseSettingsVo.kt new file mode 100644 index 0000000..80193b6 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/vo/system/BaseSettingsVo.kt @@ -0,0 +1,48 @@ +package top.fatweb.api.vo.system + +import io.swagger.v3.oas.annotations.media.Schema + +/** + * Base settings value object + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(description = "基础设置返回参数") +data class BaseSettingsVo( + /** + * Application name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "应用名称") + val appName: String?, + + /** + * Application URL + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "应用 URL") + val appUrl: String?, + + /** + * Verify URL + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "验证邮箱 URL") + val verifyUrl: String?, + + /** + * Retrieve URL + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "找回密码 URL") + val retrieveUrl: String? +) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/system/CpuInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/CpuInfoVo.kt index 72d6cb3..de37e4c 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/CpuInfoVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/CpuInfoVo.kt @@ -1,6 +1,7 @@ package top.fatweb.api.vo.system import com.fasterxml.jackson.annotation.JsonInclude +import io.swagger.v3.oas.annotations.media.Schema /** * CPU information value object @@ -8,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonInclude * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "CPU 信息返回参数") @JsonInclude(JsonInclude.Include.NON_EMPTY) data class CpuInfoVo( /** @@ -18,6 +20,7 @@ data class CpuInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "user") val user: Long, /** @@ -28,6 +31,7 @@ data class CpuInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "nice") val nice: Long, /** @@ -40,6 +44,7 @@ data class CpuInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "system") val system: Long, /** @@ -50,6 +55,7 @@ data class CpuInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "idle") val idle: Long, /** @@ -61,6 +67,7 @@ data class CpuInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "iowait") val iowait: Long, /** @@ -71,6 +78,7 @@ data class CpuInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "irq") val irq: Long, /** @@ -81,6 +89,7 @@ data class CpuInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "softirq") val softirq: Long, /** @@ -92,6 +101,7 @@ data class CpuInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "steal") val steal: Long, /** @@ -100,6 +110,7 @@ data class CpuInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "total") val total: Long, /** @@ -108,5 +119,6 @@ data class CpuInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "处理器列表") val processors: List? = null ) diff --git a/src/main/kotlin/top/fatweb/api/vo/system/FileStoreInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/FileStoreInfoVo.kt index 43cbc0e..0fa6320 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/FileStoreInfoVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/FileStoreInfoVo.kt @@ -1,11 +1,14 @@ package top.fatweb.api.vo.system +import io.swagger.v3.oas.annotations.media.Schema + /** * File storage information value object * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "文件存储信息返回参数") data class FileStoreInfoVo( /** * Mount point of the File System. The @@ -15,6 +18,7 @@ data class FileStoreInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "挂载点") val mount: String, /** @@ -23,6 +27,7 @@ data class FileStoreInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "总容量") val total: Long, /** @@ -33,5 +38,6 @@ data class FileStoreInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "空闲容量") val free: Long ) diff --git a/src/main/kotlin/top/fatweb/api/vo/system/HardwareInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/HardwareInfoVo.kt index 12f5a09..8868595 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/HardwareInfoVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/HardwareInfoVo.kt @@ -1,11 +1,14 @@ package top.fatweb.api.vo.system +import io.swagger.v3.oas.annotations.media.Schema + /** * Hardware information value object * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "硬件信息返回参数") data class HardwareInfoVo( /** * Name of CPU @@ -13,6 +16,7 @@ data class HardwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "CPU") val cpu: String, /** @@ -21,6 +25,7 @@ data class HardwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "架构") val arch: String, /** @@ -29,6 +34,7 @@ data class HardwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "是否为64位") val is64Bit: Boolean, /** @@ -38,6 +44,7 @@ data class HardwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "物理 CPU") val cpuPhysicalPackageCount: Int, /** @@ -51,6 +58,7 @@ data class HardwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "物理核心") val cpuPhysicalProcessorCount: Int, /** @@ -64,6 +72,7 @@ data class HardwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "逻辑核心") val cpuLogicalProcessorCount: Int, /** @@ -72,6 +81,7 @@ data class HardwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "微架构") val microarchitecture: String, /** @@ -80,6 +90,7 @@ data class HardwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "内存") val memories: String, /** @@ -88,5 +99,6 @@ data class HardwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "存储") val disks: String ) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/system/MailSettingsVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/MailSettingsVo.kt index b909211..503d2c5 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/MailSettingsVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/MailSettingsVo.kt @@ -1,5 +1,6 @@ package top.fatweb.api.vo.system +import io.swagger.v3.oas.annotations.media.Schema import top.fatweb.api.settings.MailSecurityType /** @@ -8,6 +9,7 @@ import top.fatweb.api.settings.MailSecurityType * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "邮件设置返回参数") data class MailSettingsVo( /** * Host @@ -15,6 +17,7 @@ data class MailSettingsVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "SMTP 服务器") val host: String?, /** @@ -23,6 +26,7 @@ data class MailSettingsVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "端口") val port: Int?, /** @@ -31,6 +35,7 @@ data class MailSettingsVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "安全类型") val securityType: MailSecurityType?, /** @@ -39,6 +44,7 @@ data class MailSettingsVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "用户名") val username: String?, /** @@ -47,6 +53,7 @@ data class MailSettingsVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "密码") val password: String?, /** @@ -55,6 +62,7 @@ data class MailSettingsVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "发送者") val from: String?, /** @@ -63,5 +71,6 @@ data class MailSettingsVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "发送者名称") val fromName: String? ) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt index d98ddf7..8e043d5 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt @@ -1,5 +1,6 @@ package top.fatweb.api.vo.system +import io.swagger.v3.oas.annotations.media.Schema import top.fatweb.api.vo.system.OnlineInfoVo.HistoryVo import java.time.LocalDateTime @@ -9,6 +10,7 @@ import java.time.LocalDateTime * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "在线信息返回参数") data class OnlineInfoVo( /** * Number of user currently online @@ -16,6 +18,7 @@ data class OnlineInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "当前在线用户数量") val current: Long, /** @@ -25,6 +28,7 @@ data class OnlineInfoVo( * @since 1.0.0 * @see HistoryVo */ + @Schema(description = "历史记录") val history: List ) { data class HistoryVo( @@ -35,6 +39,7 @@ data class OnlineInfoVo( * @since 1.0.0 * @see LocalDateTime */ + @Schema(description = "记录时间") val time: LocalDateTime, /** @@ -43,6 +48,7 @@ data class OnlineInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "记录") val record: String ) } diff --git a/src/main/kotlin/top/fatweb/api/vo/system/SettingsVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/SettingsVo.kt index 4557402..03cd0e8 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/SettingsVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/SettingsVo.kt @@ -1,11 +1,15 @@ package top.fatweb.api.vo.system +import io.swagger.v3.oas.annotations.media.Schema + /** * System settings value object * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + +@Schema(description = "系统设置返回参数") data class SettingsVo( /** * MailSettingVo object @@ -14,5 +18,6 @@ data class SettingsVo( * @since 1.0.0 * @see MailSettingsVo */ + @Schema(description = "邮件设置") val mail: MailSettingsVo? ) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/vo/system/SoftwareInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/SoftwareInfoVo.kt index 7eb52ab..1caf962 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/SoftwareInfoVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/SoftwareInfoVo.kt @@ -1,5 +1,6 @@ package top.fatweb.api.vo.system +import io.swagger.v3.oas.annotations.media.Schema import java.time.LocalDateTime /** @@ -8,6 +9,7 @@ import java.time.LocalDateTime * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "软甲信息返回参数") data class SoftwareInfoVo( /** * Operating system @@ -15,6 +17,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "操作系统") val os: String, /** @@ -23,6 +26,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "位数") val bitness: Int, /** @@ -31,6 +35,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 版本") val javaVersion: String, /** @@ -39,6 +44,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 版本日期") val javaVersionDate: String, /** @@ -47,6 +53,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 供应商") val javaVendor: String, /** @@ -55,6 +62,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 运行时") val javaRuntime: String, /** @@ -63,6 +71,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 运行时版本") val javaRuntimeVersion: String, /** @@ -71,6 +80,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 虚拟机") val jvm: String, /** @@ -79,6 +89,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 虚拟机版本") val jvmVersion: String, /** @@ -87,6 +98,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 虚拟机信息") val jvmInfo: String, /** @@ -95,6 +107,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 虚拟机供应商") val jvmVendor: String, /** @@ -103,6 +116,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 字节文件版本") val javaClassVersion: String, /** @@ -111,6 +125,7 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "操作系统启动时间") val osBootTime: LocalDateTime, /** @@ -119,5 +134,6 @@ data class SoftwareInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "服务器启动时间") val serverStartupTime: LocalDateTime ) diff --git a/src/main/kotlin/top/fatweb/api/vo/system/StorageInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/system/StorageInfoVo.kt index 7362335..ca62096 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/StorageInfoVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/system/StorageInfoVo.kt @@ -1,11 +1,14 @@ package top.fatweb.api.vo.system +import io.swagger.v3.oas.annotations.media.Schema + /** * Storage information value object * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "存储信息返回参数") data class StorageInfoVo( /** * The amount of actual physical memory. @@ -13,6 +16,7 @@ data class StorageInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "总内存容量") val memoryTotal: Long, /** @@ -22,6 +26,7 @@ data class StorageInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "空闲内存容量") val memoryFree: Long, /** @@ -40,6 +45,7 @@ data class StorageInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "总虚拟内存容量") val virtualMemoryMax: Long, /** @@ -57,6 +63,7 @@ data class StorageInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "已用虚拟内存容量") val virtualMemoryInUse: Long, /** @@ -67,6 +74,7 @@ data class StorageInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "总交换区容量") val swapTotal: Long, /** @@ -76,6 +84,7 @@ data class StorageInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "可用交换区容量") val swapUsed: Long, /** @@ -84,6 +93,7 @@ data class StorageInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 虚拟机总内存容量") val jvmTotal: Long, /** @@ -92,6 +102,7 @@ data class StorageInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @Schema(description = "Java 虚拟机空闲内存容量") val jvmFree: Long, /** @@ -101,5 +112,6 @@ data class StorageInfoVo( * @since 1.0.0 * @see FileStoreInfoVo */ + @Schema(description = "文件存储信息列表") val fileStores: List ) From 47baa061257d860fd8311ff8cb883dc37f60b6d6 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 28 Dec 2023 13:39:42 +0800 Subject: [PATCH 162/258] Change namespace to top.fatweb.oxygen.api --- build-docker.sh | 16 +++--- pom.xml | 4 +- .../api/OxygenApiApplication.kt} | 8 +-- .../api/annotation/ApiController.kt | 2 +- .../api/annotation/BaseController.kt | 2 +- .../api/annotation/EventLogRecord.kt | 4 +- .../api/annotation/HiddenController.kt | 2 +- .../{ => oxygen}/api/aop/EventLogAspect.kt | 14 +++--- .../api/config/DataFormatConfig.kt | 2 +- .../{ => oxygen}/api/config/FilterConfig.kt | 4 +- .../{ => oxygen}/api/config/FlywayConfig.kt | 4 +- .../{ => oxygen}/api/config/InitConfig.kt | 15 +++--- .../api/config/MybatisPlusConfig.kt | 2 +- .../{ => oxygen}/api/config/RedisConfig.kt | 2 +- .../{ => oxygen}/api/config/SecurityConfig.kt | 8 +-- .../{ => oxygen}/api/config/SwaggerConfig.kt | 8 +-- .../{ => oxygen}/api/config/SysLogConfig.kt | 4 +- .../api/config/VelocityEngineConfig.kt | 2 +- .../api/config/WebMvcConfigurerConfig.kt | 6 +-- .../api/config/WebMvcRegistrationsConfig.kt | 4 +- .../api/controller/ExceptionController.kt | 4 +- .../api/controller/api/v1/AvatarController.kt | 16 +++--- .../permission/AuthenticationController.kt | 25 +++++----- .../controller/permission/GroupController.kt | 18 +++---- .../controller/permission/PowerController.kt | 10 ++-- .../controller/permission/RoleController.kt | 18 +++---- .../controller/permission/UserController.kt | 22 ++++----- .../controller/system/SettingsController.kt | 18 +++---- .../controller/system/StatisticsController.kt | 14 +++--- .../api/controller/system/SysLogController.kt | 16 +++--- .../api/converter/permission/FuncConverter.kt | 6 +-- .../converter/permission/GroupConverter.kt | 18 +++---- .../api/converter/permission/MenuConverter.kt | 6 +-- .../converter/permission/ModuleConverter.kt | 6 +-- .../permission/OperationConverter.kt | 6 +-- .../converter/permission/PowerConverter.kt | 6 +-- .../api/converter/permission/RoleConverter.kt | 18 +++---- .../api/converter/permission/UserConverter.kt | 24 ++++----- .../converter/permission/UserInfoConverter.kt | 6 +-- .../api/converter/system/SysLogConverter.kt | 8 +-- .../{ => oxygen}/api/cron/StatisticsCron.kt | 12 ++--- .../api/entity/common/BusinessCode.kt | 2 +- .../api/entity/common/ResponseCode.kt | 2 +- .../api/entity/common/ResponseResult.kt | 2 +- .../api/entity/permission/Func.kt | 2 +- .../api/entity/permission/Group.kt | 4 +- .../api/entity/permission/LoginUser.kt | 6 ++- .../api/entity/permission/Menu.kt | 2 +- .../api/entity/permission/Module.kt | 2 +- .../api/entity/permission/Operation.kt | 2 +- .../api/entity/permission/Power.kt | 2 +- .../api/entity/permission/PowerRole.kt | 2 +- .../api/entity/permission/PowerSet.kt | 6 ++- .../api/entity/permission/PowerType.kt | 2 +- .../api/entity/permission/Role.kt | 4 +- .../api/entity/permission/RoleGroup.kt | 2 +- .../api/entity/permission/User.kt | 2 +- .../api/entity/permission/UserGroup.kt | 2 +- .../api/entity/permission/UserInfo.kt | 2 +- .../api/entity/permission/UserRole.kt | 2 +- .../api/entity/system/EventLog.kt | 2 +- .../api/entity/system/StatisticsLog.kt | 4 +- .../{ => oxygen}/api/entity/system/SysLog.kt | 2 +- .../api/exception/AccountNeedInitException.kt | 2 +- .../AccountNeedResetPasswordException.kt | 2 +- .../api/exception/NoEmailConfigException.kt | 2 +- .../api/exception/NoRecordFoundException.kt | 2 +- .../NoVerificationRequiredException.kt | 2 +- .../RetrieveCodeErrorOrExpiredException.kt | 2 +- .../api/exception/TokenHasExpiredException.kt | 2 +- .../api/exception/UserNotFoundException.kt | 2 +- ...VerificationCodeErrorOrExpiredException.kt | 2 +- .../api/filter/ExceptionFilter.kt | 2 +- .../filter/JwtAuthenticationTokenFilter.kt | 14 +++--- .../api/handler/DataMetaObjectHandler.kt | 2 +- .../api/handler/ExceptionHandler.kt | 8 +-- .../api/handler/JwtAccessDeniedHandler.kt | 2 +- .../JwtAuthenticationEntryPointHandler.kt | 2 +- .../api/interceptor/SysLogInterceptor.kt | 14 +++--- .../api/mapper/permission/FuncMapper.kt | 4 +- .../api/mapper/permission/GroupMapper.kt | 4 +- .../api/mapper/permission/MenuMapper.kt | 4 +- .../api/mapper/permission/ModuleMapper.kt | 4 +- .../api/mapper/permission/OperationMapper.kt | 4 +- .../api/mapper/permission/PowerMapper.kt | 4 +- .../api/mapper/permission/PowerRoleMapper.kt | 4 +- .../api/mapper/permission/RoleGroupMapper.kt | 4 +- .../api/mapper/permission/RoleMapper.kt | 4 +- .../api/mapper/permission/UserGroupMapper.kt | 4 +- .../api/mapper/permission/UserInfoMapper.kt | 4 +- .../api/mapper/permission/UserMapper.kt | 4 +- .../api/mapper/permission/UserRoleMapper.kt | 4 +- .../api/mapper/system/EventLogMapper.kt | 4 +- .../api/mapper/system/StatisticsLogMapper.kt | 4 +- .../api/mapper/system/SysLogMapper.kt | 4 +- .../{ => oxygen}/api/param/PageSortParam.kt | 2 +- .../param/api/v1/avatar/AvatarBaseParam.kt | 2 +- .../param/api/v1/avatar/AvatarGitHubParam.kt | 2 +- .../api/param/permission/ForgetParam.kt | 2 +- .../api/param/permission/LoginParam.kt | 2 +- .../api/param/permission/RegisterParam.kt | 2 +- .../api/param/permission/RetrieveParam.kt | 2 +- .../api/param/permission/VerifyParam.kt | 2 +- .../param/permission/group/GroupAddParam.kt | 2 +- .../permission/group/GroupDeleteParam.kt | 2 +- .../param/permission/group/GroupGetParam.kt | 4 +- .../permission/group/GroupUpdateParam.kt | 2 +- .../group/GroupUpdateStatusParam.kt | 2 +- .../api/param/permission/role/RoleAddParam.kt | 2 +- .../param/permission/role/RoleDeleteParam.kt | 2 +- .../api/param/permission/role/RoleGetParam.kt | 4 +- .../param/permission/role/RoleUpdateParam.kt | 2 +- .../permission/role/RoleUpdateStatusParam.kt | 2 +- .../api/param/permission/user/UserAddParam.kt | 2 +- .../param/permission/user/UserDeleteParam.kt | 2 +- .../api/param/permission/user/UserGetParam.kt | 4 +- .../param/permission/user/UserUpdateParam.kt | 2 +- .../user/UserUpdatePasswordParam.kt | 2 +- .../api/param/system/ActiveInfoGetParam.kt | 2 +- .../api/param/system/BaseSettingsParam.kt | 2 +- .../api/param/system/MailSendParam.kt | 2 +- .../api/param/system/MailSettingsParam.kt | 4 +- .../api/param/system/OnlineInfoGetParam.kt | 2 +- .../api/param/system/SysLogGetParam.kt | 4 +- .../api/properties/AdminProperties.kt | 4 +- .../api/properties/FlywayProperties.kt | 2 +- .../api/properties/SecurityProperties.kt | 6 +-- .../api/properties/ServerProperties.kt | 4 +- .../api/service/api/v1/IAvatarService.kt | 8 +-- .../service/api/v1/impl/AvatarServiceImpl.kt | 12 ++--- .../permission/IAuthenticationService.kt | 12 ++--- .../api/service/permission/IFuncService.kt | 4 +- .../api/service/permission/IGroupService.kt | 12 ++--- .../api/service/permission/IMenuService.kt | 4 +- .../api/service/permission/IModuleService.kt | 4 +- .../service/permission/IOperationService.kt | 4 +- .../service/permission/IPowerRoleService.kt | 4 +- .../api/service/permission/IPowerService.kt | 6 +-- .../service/permission/IRoleGroupService.kt | 4 +- .../api/service/permission/IRoleService.kt | 12 ++--- .../service/permission/IUserGroupService.kt | 4 +- .../service/permission/IUserInfoService.kt | 4 +- .../service/permission/IUserRoleService.kt | 4 +- .../api/service/permission/IUserService.kt | 16 +++--- .../impl/AuthenticationServiceImpl.kt | 49 ++++++++++--------- .../permission/impl/FuncServiceImpl.kt | 8 +-- .../permission/impl/GroupServiceImpl.kt | 30 ++++++------ .../permission/impl/MenuServiceImpl.kt | 8 +-- .../permission/impl/ModuleServiceImpl.kt | 8 +-- .../permission/impl/OperationServiceImpl.kt | 8 +-- .../permission/impl/PowerRoleServiceImpl.kt | 8 +-- .../permission/impl/PowerServiceImpl.kt | 12 ++--- .../permission/impl/RoleGroupServiceImpl.kt | 8 +-- .../permission/impl/RoleServiceImpl.kt | 26 +++++----- .../permission/impl/UserDetailsServiceImpl.kt | 6 +-- .../permission/impl/UserGroupServiceImpl.kt | 8 +-- .../permission/impl/UserInfoServiceImpl.kt | 8 +-- .../permission/impl/UserRoleServiceImpl.kt | 8 +-- .../permission/impl/UserServiceImpl.kt | 34 ++++++------- .../api/service/system/IEventLogService.kt | 6 +-- .../api/service/system/ISettingsService.kt | 12 ++--- .../service/system/IStatisticsLogService.kt | 4 +- .../api/service/system/IStatisticsService.kt | 10 ++-- .../api/service/system/ISysLogService.kt | 10 ++-- .../system/impl/EventLogServiceImpl.kt | 10 ++-- .../system/impl/SettingsServiceImpl.kt | 26 +++++----- .../system/impl/StatisticsLogServiceImpl.kt | 8 +-- .../system/impl/StatisticsServiceImpl.kt | 28 +++++------ .../service/system/impl/SysLogServiceImpl.kt | 33 +++++++------ .../{ => oxygen}/api/settings/BaseSettings.kt | 2 +- .../api/settings/MailSecurityType.kt | 2 +- .../{ => oxygen}/api/settings/MailSettings.kt | 2 +- .../api/settings/SettingsOperator.kt | 10 ++-- .../api/settings/SystemSettings.kt | 2 +- .../util/ApiResponseMappingHandlerMapping.kt | 4 +- .../api/util/ApiVersionCondition.kt | 2 +- .../fatweb/{ => oxygen}/api/util/ByteUtil.kt | 2 +- .../fatweb/{ => oxygen}/api/util/JwtUtil.kt | 4 +- .../fatweb/{ => oxygen}/api/util/MailUtil.kt | 10 ++-- .../{ => oxygen}/api/util/NumberUtil.kt | 2 +- .../fatweb/{ => oxygen}/api/util/PageUtil.kt | 6 +-- .../fatweb/{ => oxygen}/api/util/RedisUtil.kt | 2 +- .../fatweb/{ => oxygen}/api/util/StrUtil.kt | 2 +- .../fatweb/{ => oxygen}/api/util/WebUtil.kt | 6 +-- .../top/fatweb/{ => oxygen}/api/vo/PageVo.kt | 2 +- .../api/vo/api/v1/avatar/AvatarBase64Vo.kt | 2 +- .../api/vo/permission/GroupWithRoleVo.kt | 4 +- .../{ => oxygen}/api/vo/permission/LoginVo.kt | 2 +- .../api/vo/permission/PowerSetVo.kt | 10 ++-- .../api/vo/permission/RegisterVo.kt | 2 +- .../api/vo/permission/RoleWithPowerVo.kt | 10 ++-- .../{ => oxygen}/api/vo/permission/TokenVo.kt | 2 +- .../api/vo/permission/UserWithInfoVo.kt | 4 +- .../permission/UserWithPasswordRoleInfoVo.kt | 8 +-- .../api/vo/permission/UserWithPowerInfoVo.kt | 4 +- .../api/vo/permission/UserWithRoleInfoVo.kt | 8 +-- .../api/vo/permission/base/FuncVo.kt | 2 +- .../api/vo/permission/base/GroupVo.kt | 2 +- .../api/vo/permission/base/MenuVo.kt | 2 +- .../api/vo/permission/base/ModuleVo.kt | 2 +- .../api/vo/permission/base/OperationVo.kt | 2 +- .../api/vo/permission/base/RoleVo.kt | 2 +- .../api/vo/permission/base/UserInfoVo.kt | 4 +- .../api/vo/system/ActiveInfoVo.kt | 4 +- .../api/vo/system/BaseSettingsVo.kt | 2 +- .../{ => oxygen}/api/vo/system/CpuInfoVo.kt | 2 +- .../api/vo/system/FileStoreInfoVo.kt | 2 +- .../api/vo/system/HardwareInfoVo.kt | 2 +- .../api/vo/system/MailSettingsVo.kt | 4 +- .../api/vo/system/OnlineInfoVo.kt | 4 +- .../{ => oxygen}/api/vo/system/SettingsVo.kt | 2 +- .../api/vo/system/SoftwareInfoVo.kt | 2 +- .../api/vo/system/StorageInfoVo.kt | 2 +- .../{ => oxygen}/api/vo/system/SysLogVo.kt | 4 +- .../resources/application-config-template.yml | 4 +- src/main/resources/application.yml | 2 +- .../mapper/permission/FuncMapper.xml | 2 +- .../mapper/permission/GroupMapper.xml | 4 +- .../mapper/permission/MenuMapper.xml | 2 +- .../mapper/permission/ModuleMapper.xml | 2 +- .../mapper/permission/OperationMapper.xml | 2 +- .../mapper/permission/PowerMapper.xml | 2 +- .../mapper/permission/PowerRoleMapper.xml | 2 +- .../mapper/permission/RoleGroupMapper.xml | 2 +- .../mapper/permission/RoleMapper.xml | 10 ++-- .../mapper/permission/UserGroupMapper.xml | 2 +- .../mapper/permission/UserInfoMapper.xml | 2 +- .../mapper/permission/UserMapper.xml | 16 +++--- .../mapper/permission/UserRoleMapper.xml | 2 +- .../resources/mapper/system/SysLogMapper.xml | 2 +- .../api/OxygenApiApplicationTests.kt} | 12 ++--- 231 files changed, 698 insertions(+), 682 deletions(-) rename src/main/kotlin/top/fatweb/{api/FatWebApiApplication.kt => oxygen/api/OxygenApiApplication.kt} (92%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/annotation/ApiController.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/annotation/BaseController.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/annotation/EventLogRecord.kt (72%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/annotation/HiddenController.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/aop/EventLogAspect.kt (78%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/DataFormatConfig.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/FilterConfig.kt (87%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/FlywayConfig.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/InitConfig.kt (85%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/MybatisPlusConfig.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/RedisConfig.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/SecurityConfig.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/SwaggerConfig.kt (71%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/SysLogConfig.kt (87%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/VelocityEngineConfig.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/WebMvcConfigurerConfig.kt (73%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/config/WebMvcRegistrationsConfig.kt (84%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/controller/ExceptionController.kt (81%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/controller/api/v1/AvatarController.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/controller/permission/AuthenticationController.kt (88%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/controller/permission/GroupController.kt (92%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/controller/permission/PowerController.kt (76%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/controller/permission/RoleController.kt (92%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/controller/permission/UserController.kt (89%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/controller/system/SettingsController.kt (85%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/controller/system/StatisticsController.kt (89%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/controller/system/SysLogController.kt (73%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/converter/permission/FuncConverter.kt (76%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/converter/permission/GroupConverter.kt (86%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/converter/permission/MenuConverter.kt (77%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/converter/permission/ModuleConverter.kt (74%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/converter/permission/OperationConverter.kt (77%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/converter/permission/PowerConverter.kt (83%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/converter/permission/RoleConverter.kt (87%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/converter/permission/UserConverter.kt (92%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/converter/permission/UserInfoConverter.kt (81%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/converter/system/SysLogConverter.kt (88%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/cron/StatisticsCron.kt (65%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/common/BusinessCode.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/common/ResponseCode.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/common/ResponseResult.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/Func.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/Group.kt (89%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/LoginUser.kt (91%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/Menu.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/Module.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/Operation.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/Power.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/PowerRole.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/PowerSet.kt (79%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/PowerType.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/Role.kt (90%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/RoleGroup.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/User.kt (99%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/UserGroup.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/UserInfo.kt (97%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/permission/UserRole.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/system/EventLog.kt (97%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/system/StatisticsLog.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/entity/system/SysLog.kt (99%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/exception/AccountNeedInitException.kt (84%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/exception/AccountNeedResetPasswordException.kt (85%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/exception/NoEmailConfigException.kt (88%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/exception/NoRecordFoundException.kt (82%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/exception/NoVerificationRequiredException.kt (84%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/exception/RetrieveCodeErrorOrExpiredException.kt (85%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/exception/TokenHasExpiredException.kt (83%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/exception/UserNotFoundException.kt (82%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/exception/VerificationCodeErrorOrExpiredException.kt (86%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/filter/ExceptionFilter.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/filter/JwtAuthenticationTokenFilter.kt (84%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/handler/DataMetaObjectHandler.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/handler/ExceptionHandler.kt (97%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/handler/JwtAccessDeniedHandler.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/handler/JwtAuthenticationEntryPointHandler.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/interceptor/SysLogInterceptor.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/FuncMapper.kt (73%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/GroupMapper.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/MenuMapper.kt (72%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/ModuleMapper.kt (72%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/OperationMapper.kt (73%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/PowerMapper.kt (72%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/PowerRoleMapper.kt (74%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/RoleGroupMapper.kt (74%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/RoleMapper.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/UserGroupMapper.kt (74%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/UserInfoMapper.kt (73%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/UserMapper.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/permission/UserRoleMapper.kt (74%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/system/EventLogMapper.kt (72%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/system/StatisticsLogMapper.kt (72%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/mapper/system/SysLogMapper.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/PageSortParam.kt (97%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/api/v1/avatar/AvatarBaseParam.kt (97%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/api/v1/avatar/AvatarGitHubParam.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/ForgetParam.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/LoginParam.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/RegisterParam.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/RetrieveParam.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/VerifyParam.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/group/GroupAddParam.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/group/GroupDeleteParam.kt (89%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/group/GroupGetParam.kt (88%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/group/GroupUpdateParam.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/group/GroupUpdateStatusParam.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/role/RoleAddParam.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/role/RoleDeleteParam.kt (89%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/role/RoleGetParam.kt (88%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/role/RoleUpdateParam.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/role/RoleUpdateStatusParam.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/user/UserAddParam.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/user/UserDeleteParam.kt (89%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/user/UserGetParam.kt (91%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/user/UserUpdateParam.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/permission/user/UserUpdatePasswordParam.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/system/ActiveInfoGetParam.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/system/BaseSettingsParam.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/system/MailSendParam.kt (92%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/system/MailSettingsParam.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/system/OnlineInfoGetParam.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/param/system/SysLogGetParam.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/properties/AdminProperties.kt (91%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/properties/FlywayProperties.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/properties/SecurityProperties.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/properties/ServerProperties.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/api/v1/IAvatarService.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/api/v1/impl/AvatarServiceImpl.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IAuthenticationService.kt (88%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IFuncService.kt (69%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IGroupService.kt (88%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IMenuService.kt (69%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IModuleService.kt (69%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IOperationService.kt (70%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IPowerRoleService.kt (71%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IPowerService.kt (73%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IRoleGroupService.kt (71%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IRoleService.kt (88%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IUserGroupService.kt (71%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IUserInfoService.kt (70%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IUserRoleService.kt (71%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/IUserService.kt (88%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/AuthenticationServiceImpl.kt (89%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/FuncServiceImpl.kt (62%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/GroupServiceImpl.kt (85%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/MenuServiceImpl.kt (61%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/ModuleServiceImpl.kt (62%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/OperationServiceImpl.kt (62%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/PowerRoleServiceImpl.kt (63%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/PowerServiceImpl.kt (73%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/RoleGroupServiceImpl.kt (63%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/RoleServiceImpl.kt (89%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/UserDetailsServiceImpl.kt (79%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/UserGroupServiceImpl.kt (63%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/UserInfoServiceImpl.kt (62%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/UserRoleServiceImpl.kt (62%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/permission/impl/UserServiceImpl.kt (91%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/system/IEventLogService.kt (64%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/system/ISettingsService.kt (80%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/system/IStatisticsLogService.kt (68%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/system/IStatisticsService.kt (87%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/system/ISysLogService.kt (71%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/system/impl/EventLogServiceImpl.kt (77%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/system/impl/SettingsServiceImpl.kt (80%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/system/impl/StatisticsLogServiceImpl.kt (55%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/system/impl/StatisticsServiceImpl.kt (92%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/service/system/impl/SysLogServiceImpl.kt (67%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/settings/BaseSettings.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/settings/MailSecurityType.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/settings/MailSettings.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/settings/SettingsOperator.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/settings/SystemSettings.kt (92%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/util/ApiResponseMappingHandlerMapping.kt (90%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/util/ApiVersionCondition.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/util/ByteUtil.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/util/JwtUtil.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/util/MailUtil.kt (88%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/util/NumberUtil.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/util/PageUtil.kt (85%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/util/RedisUtil.kt (99%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/util/StrUtil.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/util/WebUtil.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/PageVo.kt (97%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/api/v1/avatar/AvatarBase64Vo.kt (89%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/GroupWithRoleVo.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/LoginVo.kt (97%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/PowerSetVo.kt (80%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/RegisterVo.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/RoleWithPowerVo.kt (89%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/TokenVo.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/UserWithInfoVo.kt (97%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/UserWithPasswordRoleInfoVo.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/UserWithPowerInfoVo.kt (97%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/UserWithRoleInfoVo.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/base/FuncVo.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/base/GroupVo.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/base/MenuVo.kt (95%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/base/ModuleVo.kt (91%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/base/OperationVo.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/base/RoleVo.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/permission/base/UserInfoVo.kt (94%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/system/ActiveInfoVo.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/system/BaseSettingsVo.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/system/CpuInfoVo.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/system/FileStoreInfoVo.kt (96%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/system/HardwareInfoVo.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/system/MailSettingsVo.kt (93%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/system/OnlineInfoVo.kt (91%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/system/SettingsVo.kt (91%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/system/SoftwareInfoVo.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/system/StorageInfoVo.kt (98%) rename src/main/kotlin/top/fatweb/{ => oxygen}/api/vo/system/SysLogVo.kt (97%) rename src/test/kotlin/top/fatweb/{api/FatWebApiApplicationTests.kt => oxygen/api/OxygenApiApplicationTests.kt} (84%) diff --git a/build-docker.sh b/build-docker.sh index 3839b82..877f249 100644 --- a/build-docker.sh +++ b/build-docker.sh @@ -10,15 +10,15 @@ java -Djarmode=layertools -jar target/*.jar extract --destination target/extract if [[ "${JAR_VERSION}" =~ ^.*SNAPSHOT$ ]] then - docker build -t hub.fatweb.top/fatweb-api:snapshot-latest -t hub.fatweb.top/fatweb-api:$JAR_VERSION -t hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} . + docker build -t hub.fatweb.top/oxygen-api:snapshot-latest -t hub.fatweb.top/oxygen-api:$JAR_VERSION -t hub.fatweb.top/oxygen-api:$JAR_VERSION-${BUILD_TIME} . cat "${KEYS_PATH}/docker.password" | docker login hub.fatweb.top -u jenkins --password-stdin - docker push hub.fatweb.top/fatweb-api:snapshot-latest - docker push hub.fatweb.top/fatweb-api:$JAR_VERSION - docker push hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} + docker push hub.fatweb.top/oxygen-api:snapshot-latest + docker push hub.fatweb.top/oxygen-api:$JAR_VERSION + docker push hub.fatweb.top/oxygen-api:$JAR_VERSION-${BUILD_TIME} else - docker build -t hub.fatweb.top/fatweb-api:latest -t hub.fatweb.top/fatweb-api:$JAR_VERSION -t hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} . + docker build -t hub.fatweb.top/oxygen-api:latest -t hub.fatweb.top/oxygen-api:$JAR_VERSION -t hub.fatweb.top/oxygen-api:$JAR_VERSION-${BUILD_TIME} . cat "${KEYS_PATH}/docker.password" | docker login hub.fatweb.top -u jenkins --password-stdin - docker push hub.fatweb.top/fatweb-api:latest - docker push hub.fatweb.top/fatweb-api:$JAR_VERSION - docker push hub.fatweb.top/fatweb-api:$JAR_VERSION-${BUILD_TIME} + docker push hub.fatweb.top/oxygen-api:latest + docker push hub.fatweb.top/oxygen-api:$JAR_VERSION + docker push hub.fatweb.top/oxygen-api:$JAR_VERSION-${BUILD_TIME} fi \ No newline at end of file diff --git a/pom.xml b/pom.xml index 225ece4..eef0dab 100644 --- a/pom.xml +++ b/pom.xml @@ -11,8 +11,8 @@ top.fatweb api 0.0.1-SNAPSHOT - fatweb-api - fatweb-api + oxygen-api + oxygen-api diff --git a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt b/src/main/kotlin/top/fatweb/oxygen/api/OxygenApiApplication.kt similarity index 92% rename from src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt rename to src/main/kotlin/top/fatweb/oxygen/api/OxygenApiApplication.kt index 1bbf8aa..146c2fb 100644 --- a/src/main/kotlin/top/fatweb/api/FatWebApiApplication.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/OxygenApiApplication.kt @@ -1,4 +1,4 @@ -package top.fatweb.api +package top.fatweb.oxygen.api import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication @@ -17,7 +17,7 @@ import java.util.* @SpringBootApplication @EnableTransactionManagement @EnableScheduling -class FatWebApiApplication +class OxygenApiApplication /** * Main function @@ -53,10 +53,10 @@ fun main(args: Array) { } if (File("application-config.yml").exists() || File("data/application-config.yml").exists()) { - runApplication(*args) + runApplication(*args) } else { logger.warn("File 'application-config.yml' cannot be found in the running path or the data path. The configuration file template 'application-config.example.yml' has been created in directory 'data'. Please change the configuration file content, move it to the running path, rename it to 'application-config.yml', and then restart the server.") - FatWebApiApplication::class.java.getResource("/application-config-template.yml")?.readText()?.let { + OxygenApiApplication::class.java.getResource("/application-config-template.yml")?.readText()?.let { File("data/application-config.example.yml").writeText( it.replace( "\$uuid\$", UUID.randomUUID().toString().replace("-", "") diff --git a/src/main/kotlin/top/fatweb/api/annotation/ApiController.kt b/src/main/kotlin/top/fatweb/oxygen/api/annotation/ApiController.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/annotation/ApiController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/annotation/ApiController.kt index 0382a56..5805c4e 100644 --- a/src/main/kotlin/top/fatweb/api/annotation/ApiController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/annotation/ApiController.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.annotation +package top.fatweb.oxygen.api.annotation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.core.annotation.AliasFor diff --git a/src/main/kotlin/top/fatweb/api/annotation/BaseController.kt b/src/main/kotlin/top/fatweb/oxygen/api/annotation/BaseController.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/annotation/BaseController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/annotation/BaseController.kt index 029fa05..598555d 100644 --- a/src/main/kotlin/top/fatweb/api/annotation/BaseController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/annotation/BaseController.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.annotation +package top.fatweb.oxygen.api.annotation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.core.annotation.AliasFor diff --git a/src/main/kotlin/top/fatweb/api/annotation/EventLogRecord.kt b/src/main/kotlin/top/fatweb/oxygen/api/annotation/EventLogRecord.kt similarity index 72% rename from src/main/kotlin/top/fatweb/api/annotation/EventLogRecord.kt rename to src/main/kotlin/top/fatweb/oxygen/api/annotation/EventLogRecord.kt index 4eb87e0..f0e023b 100644 --- a/src/main/kotlin/top/fatweb/api/annotation/EventLogRecord.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/annotation/EventLogRecord.kt @@ -1,6 +1,6 @@ -package top.fatweb.api.annotation +package top.fatweb.oxygen.api.annotation -import top.fatweb.api.entity.system.EventLog +import top.fatweb.oxygen.api.entity.system.EventLog /** * Event log record annotation diff --git a/src/main/kotlin/top/fatweb/api/annotation/HiddenController.kt b/src/main/kotlin/top/fatweb/oxygen/api/annotation/HiddenController.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/annotation/HiddenController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/annotation/HiddenController.kt index 5e593e5..90287fb 100644 --- a/src/main/kotlin/top/fatweb/api/annotation/HiddenController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/annotation/HiddenController.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.annotation +package top.fatweb.oxygen.api.annotation import io.swagger.v3.oas.annotations.Hidden import org.springframework.core.annotation.AliasFor diff --git a/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt b/src/main/kotlin/top/fatweb/oxygen/api/aop/EventLogAspect.kt similarity index 78% rename from src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt rename to src/main/kotlin/top/fatweb/oxygen/api/aop/EventLogAspect.kt index b5c26d9..c9710e5 100644 --- a/src/main/kotlin/top/fatweb/api/aop/EventLogAspect.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/aop/EventLogAspect.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.aop +package top.fatweb.oxygen.api.aop import org.aspectj.lang.JoinPoint import org.aspectj.lang.annotation.AfterReturning @@ -6,11 +6,11 @@ import org.aspectj.lang.annotation.Aspect import org.aspectj.lang.annotation.Pointcut import org.aspectj.lang.reflect.MethodSignature import org.springframework.stereotype.Component -import top.fatweb.api.annotation.EventLogRecord -import top.fatweb.api.service.system.IEventLogService -import top.fatweb.api.util.WebUtil -import top.fatweb.api.vo.permission.LoginVo -import top.fatweb.api.vo.permission.RegisterVo +import top.fatweb.oxygen.api.annotation.EventLogRecord +import top.fatweb.oxygen.api.service.system.IEventLogService +import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.permission.LoginVo +import top.fatweb.oxygen.api.vo.permission.RegisterVo /** * Event log record aspect @@ -30,7 +30,7 @@ class EventLogAspect( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @Pointcut("@annotation(top.fatweb.api.annotation.EventLogRecord)") + @Pointcut("@annotation(top.fatweb.oxygen.api.annotation.EventLogRecord)") fun eventLogPointcut() { } diff --git a/src/main/kotlin/top/fatweb/api/config/DataFormatConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/DataFormatConfig.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/config/DataFormatConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/DataFormatConfig.kt index c974b86..328afaa 100644 --- a/src/main/kotlin/top/fatweb/api/config/DataFormatConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/DataFormatConfig.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer diff --git a/src/main/kotlin/top/fatweb/api/config/FilterConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/FilterConfig.kt similarity index 87% rename from src/main/kotlin/top/fatweb/api/config/FilterConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/FilterConfig.kt index 180bd67..7b1883b 100644 --- a/src/main/kotlin/top/fatweb/api/config/FilterConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/FilterConfig.kt @@ -1,9 +1,9 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import org.springframework.boot.web.servlet.FilterRegistrationBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration -import top.fatweb.api.filter.ExceptionFilter +import top.fatweb.oxygen.api.filter.ExceptionFilter /** * Filter configuration diff --git a/src/main/kotlin/top/fatweb/api/config/FlywayConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/FlywayConfig.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/config/FlywayConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/FlywayConfig.kt index 824b529..9e34385 100644 --- a/src/main/kotlin/top/fatweb/api/config/FlywayConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/FlywayConfig.kt @@ -1,11 +1,11 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import com.baomidou.dynamic.datasource.DynamicRoutingDataSource import jakarta.annotation.PostConstruct import org.flywaydb.core.Flyway import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.DependsOn -import top.fatweb.api.properties.FlywayProperties +import top.fatweb.oxygen.api.properties.FlywayProperties import javax.sql.DataSource /** diff --git a/src/main/kotlin/top/fatweb/api/config/InitConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/InitConfig.kt similarity index 85% rename from src/main/kotlin/top/fatweb/api/config/InitConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/InitConfig.kt index f20b707..7e4d123 100644 --- a/src/main/kotlin/top/fatweb/api/config/InitConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/InitConfig.kt @@ -1,20 +1,19 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import jakarta.annotation.PostConstruct -import org.apache.velocity.app.VelocityEngine import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.context.annotation.DependsOn import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Component -import top.fatweb.api.entity.permission.User -import top.fatweb.api.entity.permission.UserInfo -import top.fatweb.api.properties.AdminProperties -import top.fatweb.api.service.permission.IUserInfoService -import top.fatweb.api.service.permission.IUserService -import top.fatweb.api.util.StrUtil import top.fatweb.avatargenerator.GitHubAvatar +import top.fatweb.oxygen.api.entity.permission.User +import top.fatweb.oxygen.api.entity.permission.UserInfo +import top.fatweb.oxygen.api.properties.AdminProperties +import top.fatweb.oxygen.api.service.permission.IUserInfoService +import top.fatweb.oxygen.api.service.permission.IUserService +import top.fatweb.oxygen.api.util.StrUtil /** * Application initialization configuration diff --git a/src/main/kotlin/top/fatweb/api/config/MybatisPlusConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/MybatisPlusConfig.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/config/MybatisPlusConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/MybatisPlusConfig.kt index 83d7dec..9d36fe0 100644 --- a/src/main/kotlin/top/fatweb/api/config/MybatisPlusConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/MybatisPlusConfig.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor diff --git a/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/RedisConfig.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/config/RedisConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/RedisConfig.kt index 2ec60fe..b22b12f 100644 --- a/src/main/kotlin/top/fatweb/api/config/RedisConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/RedisConfig.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import com.fasterxml.jackson.annotation.JsonAutoDetect import com.fasterxml.jackson.annotation.JsonTypeInfo diff --git a/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt index 5e0dcb8..5d59bfe 100644 --- a/src/main/kotlin/top/fatweb/api/config/SecurityConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -13,9 +13,9 @@ import org.springframework.security.web.SecurityFilterChain import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter import org.springframework.web.cors.CorsConfiguration import org.springframework.web.cors.UrlBasedCorsConfigurationSource -import top.fatweb.api.filter.JwtAuthenticationTokenFilter -import top.fatweb.api.handler.JwtAccessDeniedHandler -import top.fatweb.api.handler.JwtAuthenticationEntryPointHandler +import top.fatweb.oxygen.api.filter.JwtAuthenticationTokenFilter +import top.fatweb.oxygen.api.handler.JwtAccessDeniedHandler +import top.fatweb.oxygen.api.handler.JwtAuthenticationEntryPointHandler /** * Spring Security configuration diff --git a/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/SwaggerConfig.kt similarity index 71% rename from src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/SwaggerConfig.kt index 78a59bf..af0ca61 100644 --- a/src/main/kotlin/top/fatweb/api/config/SwaggerConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/SwaggerConfig.kt @@ -1,11 +1,11 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import io.swagger.v3.oas.models.OpenAPI import io.swagger.v3.oas.models.info.Contact import io.swagger.v3.oas.models.info.Info import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration -import top.fatweb.api.properties.ServerProperties +import top.fatweb.oxygen.api.properties.ServerProperties /** * Swagger API doc configuration @@ -17,9 +17,9 @@ import top.fatweb.api.properties.ServerProperties class SwaggerConfig { @Bean fun customOpenAPI(): OpenAPI? { - val contact = Contact().name("FatttSnake").url("https://fatweb.top").email("fatttsnake@fatweb.top") + val contact = Contact().name("FatttSnake").url("https://fatweb.top").email("fatttsnake@gmail.com") return OpenAPI().info( - Info().title("FatWeb API 文档").description("FatWeb 后端 API 文档,包含各个 Controller 调用信息") + Info().title("Oxygen API 文档").description("Oxygen 后端 API 文档,包含各个 Controller 调用信息") .contact(contact).version( ServerProperties.version ) diff --git a/src/main/kotlin/top/fatweb/api/config/SysLogConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/SysLogConfig.kt similarity index 87% rename from src/main/kotlin/top/fatweb/api/config/SysLogConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/SysLogConfig.kt index f8a76e4..fbd40c3 100644 --- a/src/main/kotlin/top/fatweb/api/config/SysLogConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/SysLogConfig.kt @@ -1,9 +1,9 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import org.springframework.context.annotation.Configuration import org.springframework.web.servlet.config.annotation.InterceptorRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer -import top.fatweb.api.interceptor.SysLogInterceptor +import top.fatweb.oxygen.api.interceptor.SysLogInterceptor /** * System log configuration diff --git a/src/main/kotlin/top/fatweb/api/config/VelocityEngineConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/VelocityEngineConfig.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/config/VelocityEngineConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/VelocityEngineConfig.kt index 2ae172d..0995ada 100644 --- a/src/main/kotlin/top/fatweb/api/config/VelocityEngineConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/VelocityEngineConfig.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import org.apache.velocity.app.VelocityEngine import org.apache.velocity.runtime.RuntimeConstants diff --git a/src/main/kotlin/top/fatweb/api/config/WebMvcConfigurerConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/WebMvcConfigurerConfig.kt similarity index 73% rename from src/main/kotlin/top/fatweb/api/config/WebMvcConfigurerConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/WebMvcConfigurerConfig.kt index f2453a8..604a8ab 100644 --- a/src/main/kotlin/top/fatweb/api/config/WebMvcConfigurerConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/WebMvcConfigurerConfig.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations import org.springframework.context.annotation.Configuration import org.springframework.web.servlet.config.annotation.PathMatchConfigurer import org.springframework.web.servlet.config.annotation.WebMvcConfigurer -import top.fatweb.api.annotation.ApiController +import top.fatweb.oxygen.api.annotation.ApiController /** * Web MVC configurer configuration @@ -16,6 +16,6 @@ import top.fatweb.api.annotation.ApiController @Configuration class WebMvcConfigurerConfig : WebMvcConfigurer { override fun configurePathMatch(configurer: PathMatchConfigurer) { - configurer.addPathPrefix("/api/{API_VERSION}") {it.isAnnotationPresent(ApiController::class.java)} + configurer.addPathPrefix("/api/{API_VERSION}") { it.isAnnotationPresent(ApiController::class.java) } } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/config/WebMvcRegistrationsConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/WebMvcRegistrationsConfig.kt similarity index 84% rename from src/main/kotlin/top/fatweb/api/config/WebMvcRegistrationsConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/WebMvcRegistrationsConfig.kt index d5a1a26..f65a30c 100644 --- a/src/main/kotlin/top/fatweb/api/config/WebMvcRegistrationsConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/WebMvcRegistrationsConfig.kt @@ -1,9 +1,9 @@ -package top.fatweb.api.config +package top.fatweb.oxygen.api.config import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations import org.springframework.context.annotation.Configuration import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping -import top.fatweb.api.util.ApiResponseMappingHandlerMapping +import top.fatweb.oxygen.api.util.ApiResponseMappingHandlerMapping /** * Web MVC registrations configuration diff --git a/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/ExceptionController.kt similarity index 81% rename from src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/controller/ExceptionController.kt index 3c2f76f..c61cceb 100644 --- a/src/main/kotlin/top/fatweb/api/controller/ExceptionController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/ExceptionController.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.controller +package top.fatweb.oxygen.api.controller import jakarta.servlet.http.HttpServletRequest import org.springframework.web.bind.annotation.RequestMapping -import top.fatweb.api.annotation.HiddenController +import top.fatweb.oxygen.api.annotation.HiddenController /** * Exception controller diff --git a/src/main/kotlin/top/fatweb/api/controller/api/v1/AvatarController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/api/v1/AvatarController.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/controller/api/v1/AvatarController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/controller/api/v1/AvatarController.kt index b02bf7c..0747aff 100644 --- a/src/main/kotlin/top/fatweb/api/controller/api/v1/AvatarController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/api/v1/AvatarController.kt @@ -1,16 +1,16 @@ -package top.fatweb.api.controller.api.v1 +package top.fatweb.oxygen.api.controller.api.v1 import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid import org.springframework.http.MediaType import org.springframework.web.bind.annotation.GetMapping -import top.fatweb.api.annotation.ApiController -import top.fatweb.api.entity.common.ResponseCode -import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.param.api.v1.avatar.AvatarBaseParam -import top.fatweb.api.param.api.v1.avatar.AvatarGitHubParam -import top.fatweb.api.service.api.v1.IAvatarService -import top.fatweb.api.vo.api.v1.avatar.AvatarBase64Vo +import top.fatweb.oxygen.api.annotation.ApiController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.api.v1.avatar.AvatarBaseParam +import top.fatweb.oxygen.api.param.api.v1.avatar.AvatarGitHubParam +import top.fatweb.oxygen.api.service.api.v1.IAvatarService +import top.fatweb.oxygen.api.vo.api.v1.avatar.AvatarBase64Vo /** * Avatar controller diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/AuthenticationController.kt similarity index 88% rename from src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/controller/permission/AuthenticationController.kt index 99ce14a..4c47343 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/AuthenticationController.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.controller.permission +package top.fatweb.oxygen.api.controller.permission import io.swagger.v3.oas.annotations.Operation import jakarta.servlet.http.HttpServletRequest @@ -6,15 +6,15 @@ import jakarta.validation.Valid import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody -import top.fatweb.api.annotation.BaseController -import top.fatweb.api.entity.common.ResponseCode -import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.param.permission.* -import top.fatweb.api.service.permission.IAuthenticationService -import top.fatweb.api.util.WebUtil -import top.fatweb.api.vo.permission.LoginVo -import top.fatweb.api.vo.permission.RegisterVo -import top.fatweb.api.vo.permission.TokenVo +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.permission.* +import top.fatweb.oxygen.api.service.permission.IAuthenticationService +import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.permission.LoginVo +import top.fatweb.oxygen.api.vo.permission.RegisterVo +import top.fatweb.oxygen.api.vo.permission.TokenVo /** * Authentication controller @@ -114,7 +114,10 @@ class AuthenticationController( */ @Operation(summary = "找回密码") @PostMapping("/retrieve") - fun retrieve(request: HttpServletRequest, @Valid @RequestBody retrieveParam: RetrieveParam): ResponseResult { + fun retrieve( + request: HttpServletRequest, + @Valid @RequestBody retrieveParam: RetrieveParam + ): ResponseResult { authenticationService.retrieve(request, retrieveParam) return ResponseResult.success(ResponseCode.PERMISSION_RETRIEVE_SUCCESS) diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/GroupController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt similarity index 92% rename from src/main/kotlin/top/fatweb/api/controller/permission/GroupController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt index f52db31..5238386 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/GroupController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt @@ -1,17 +1,17 @@ -package top.fatweb.api.controller.permission +package top.fatweb.oxygen.api.controller.permission import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* -import top.fatweb.api.annotation.BaseController -import top.fatweb.api.entity.common.ResponseCode -import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.param.permission.group.* -import top.fatweb.api.service.permission.IGroupService -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.GroupWithRoleVo -import top.fatweb.api.vo.permission.base.GroupVo +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.permission.group.* +import top.fatweb.oxygen.api.service.permission.IGroupService +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.GroupWithRoleVo +import top.fatweb.oxygen.api.vo.permission.base.GroupVo /** * Group controller diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/PowerController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/PowerController.kt similarity index 76% rename from src/main/kotlin/top/fatweb/api/controller/permission/PowerController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/controller/permission/PowerController.kt index 3da4c87..4fcfa08 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/PowerController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/PowerController.kt @@ -1,12 +1,12 @@ -package top.fatweb.api.controller.permission +package top.fatweb.oxygen.api.controller.permission 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.service.permission.IPowerService -import top.fatweb.api.vo.permission.PowerSetVo +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.service.permission.IPowerService +import top.fatweb.oxygen.api.vo.permission.PowerSetVo /** * Power controller diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/RoleController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt similarity index 92% rename from src/main/kotlin/top/fatweb/api/controller/permission/RoleController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt index 63a7015..c92dee9 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/RoleController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt @@ -1,17 +1,17 @@ -package top.fatweb.api.controller.permission +package top.fatweb.oxygen.api.controller.permission import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* -import top.fatweb.api.annotation.BaseController -import top.fatweb.api.entity.common.ResponseCode -import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.param.permission.role.* -import top.fatweb.api.service.permission.IRoleService -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.RoleWithPowerVo -import top.fatweb.api.vo.permission.base.RoleVo +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.permission.role.* +import top.fatweb.oxygen.api.service.permission.IRoleService +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.RoleWithPowerVo +import top.fatweb.oxygen.api.vo.permission.base.RoleVo /** * Role controller diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt similarity index 89% rename from src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt index e2419e4..9cb4261 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt @@ -1,19 +1,19 @@ -package top.fatweb.api.controller.permission +package top.fatweb.oxygen.api.controller.permission import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* -import top.fatweb.api.annotation.BaseController -import top.fatweb.api.entity.common.ResponseCode -import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.exception.NoRecordFoundException -import top.fatweb.api.param.permission.user.* -import top.fatweb.api.service.permission.IUserService -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.UserWithPasswordRoleInfoVo -import top.fatweb.api.vo.permission.UserWithPowerInfoVo -import top.fatweb.api.vo.permission.UserWithRoleInfoVo +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.param.permission.user.* +import top.fatweb.oxygen.api.service.permission.IUserService +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.UserWithPasswordRoleInfoVo +import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo +import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo /** * User controller diff --git a/src/main/kotlin/top/fatweb/api/controller/system/SettingsController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt similarity index 85% rename from src/main/kotlin/top/fatweb/api/controller/system/SettingsController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt index 39a4cd6..9602e56 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/SettingsController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.controller.system +package top.fatweb.oxygen.api.controller.system import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid @@ -7,14 +7,14 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.PutMapping import org.springframework.web.bind.annotation.RequestBody -import top.fatweb.api.annotation.BaseController -import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.param.system.BaseSettingsParam -import top.fatweb.api.param.system.MailSendParam -import top.fatweb.api.param.system.MailSettingsParam -import top.fatweb.api.service.system.ISettingsService -import top.fatweb.api.vo.system.BaseSettingsVo -import top.fatweb.api.vo.system.MailSettingsVo +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.system.BaseSettingsParam +import top.fatweb.oxygen.api.param.system.MailSendParam +import top.fatweb.oxygen.api.param.system.MailSettingsParam +import top.fatweb.oxygen.api.service.system.ISettingsService +import top.fatweb.oxygen.api.vo.system.BaseSettingsVo +import top.fatweb.oxygen.api.vo.system.MailSettingsVo /** * System settings controller diff --git a/src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/StatisticsController.kt similarity index 89% rename from src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/controller/system/StatisticsController.kt index 107e6d4..f21802b 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/StatisticsController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/StatisticsController.kt @@ -1,14 +1,14 @@ -package top.fatweb.api.controller.system +package top.fatweb.oxygen.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.IStatisticsService -import top.fatweb.api.vo.system.* +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.system.ActiveInfoGetParam +import top.fatweb.oxygen.api.param.system.OnlineInfoGetParam +import top.fatweb.oxygen.api.service.system.IStatisticsService +import top.fatweb.oxygen.api.vo.system.* /** * Statistics controller diff --git a/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SysLogController.kt similarity index 73% rename from src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt rename to src/main/kotlin/top/fatweb/oxygen/api/controller/system/SysLogController.kt index 80298aa..01c37cd 100644 --- a/src/main/kotlin/top/fatweb/api/controller/system/SysLogController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SysLogController.kt @@ -1,16 +1,16 @@ -package top.fatweb.api.controller.system +package top.fatweb.oxygen.api.controller.system import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid 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.ResponseCode -import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.param.system.SysLogGetParam -import top.fatweb.api.service.system.ISysLogService -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.system.SysLogVo +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.system.SysLogGetParam +import top.fatweb.oxygen.api.service.system.ISysLogService +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.system.SysLogVo /** * System log controller diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/FuncConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/FuncConverter.kt similarity index 76% rename from src/main/kotlin/top/fatweb/api/converter/permission/FuncConverter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/converter/permission/FuncConverter.kt index 9079ee2..ed5c227 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/FuncConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/FuncConverter.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.converter.permission +package top.fatweb.oxygen.api.converter.permission -import top.fatweb.api.entity.permission.Func -import top.fatweb.api.vo.permission.base.FuncVo +import top.fatweb.oxygen.api.entity.permission.Func +import top.fatweb.oxygen.api.vo.permission.base.FuncVo /** * Function converter diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/GroupConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/GroupConverter.kt similarity index 86% rename from src/main/kotlin/top/fatweb/api/converter/permission/GroupConverter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/converter/permission/GroupConverter.kt index b218e48..8f3db91 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/GroupConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/GroupConverter.kt @@ -1,14 +1,14 @@ -package top.fatweb.api.converter.permission +package top.fatweb.oxygen.api.converter.permission import com.baomidou.mybatisplus.core.metadata.IPage -import top.fatweb.api.entity.permission.Group -import top.fatweb.api.entity.permission.Role -import top.fatweb.api.param.permission.group.GroupAddParam -import top.fatweb.api.param.permission.group.GroupUpdateStatusParam -import top.fatweb.api.param.permission.group.GroupUpdateParam -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.base.GroupVo -import top.fatweb.api.vo.permission.GroupWithRoleVo +import top.fatweb.oxygen.api.entity.permission.Group +import top.fatweb.oxygen.api.entity.permission.Role +import top.fatweb.oxygen.api.param.permission.group.GroupAddParam +import top.fatweb.oxygen.api.param.permission.group.GroupUpdateParam +import top.fatweb.oxygen.api.param.permission.group.GroupUpdateStatusParam +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.GroupWithRoleVo +import top.fatweb.oxygen.api.vo.permission.base.GroupVo /** * Group converter diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/MenuConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/MenuConverter.kt similarity index 77% rename from src/main/kotlin/top/fatweb/api/converter/permission/MenuConverter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/converter/permission/MenuConverter.kt index 8b9f205..ef573d1 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/MenuConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/MenuConverter.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.converter.permission +package top.fatweb.oxygen.api.converter.permission -import top.fatweb.api.entity.permission.Menu -import top.fatweb.api.vo.permission.base.MenuVo +import top.fatweb.oxygen.api.entity.permission.Menu +import top.fatweb.oxygen.api.vo.permission.base.MenuVo /** * Menu converter diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/ModuleConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/ModuleConverter.kt similarity index 74% rename from src/main/kotlin/top/fatweb/api/converter/permission/ModuleConverter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/converter/permission/ModuleConverter.kt index 4c32635..4760c51 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/ModuleConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/ModuleConverter.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.converter.permission +package top.fatweb.oxygen.api.converter.permission -import top.fatweb.api.entity.permission.Module -import top.fatweb.api.vo.permission.base.ModuleVo +import top.fatweb.oxygen.api.entity.permission.Module +import top.fatweb.oxygen.api.vo.permission.base.ModuleVo /** * Module converter diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/OperationConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/OperationConverter.kt similarity index 77% rename from src/main/kotlin/top/fatweb/api/converter/permission/OperationConverter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/converter/permission/OperationConverter.kt index 6328ad4..dd9f0b3 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/OperationConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/OperationConverter.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.converter.permission +package top.fatweb.oxygen.api.converter.permission -import top.fatweb.api.entity.permission.Operation -import top.fatweb.api.vo.permission.base.OperationVo +import top.fatweb.oxygen.api.entity.permission.Operation +import top.fatweb.oxygen.api.vo.permission.base.OperationVo /** * Operation converter diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/PowerConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/PowerConverter.kt similarity index 83% rename from src/main/kotlin/top/fatweb/api/converter/permission/PowerConverter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/converter/permission/PowerConverter.kt index 4c4dc05..80a21c0 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/PowerConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/PowerConverter.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.converter.permission +package top.fatweb.oxygen.api.converter.permission -import top.fatweb.api.entity.permission.PowerSet -import top.fatweb.api.vo.permission.PowerSetVo +import top.fatweb.oxygen.api.entity.permission.PowerSet +import top.fatweb.oxygen.api.vo.permission.PowerSetVo /** * Power converter diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/RoleConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/RoleConverter.kt similarity index 87% rename from src/main/kotlin/top/fatweb/api/converter/permission/RoleConverter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/converter/permission/RoleConverter.kt index 044227f..13a9005 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/RoleConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/RoleConverter.kt @@ -1,14 +1,14 @@ -package top.fatweb.api.converter.permission +package top.fatweb.oxygen.api.converter.permission import com.baomidou.mybatisplus.core.metadata.IPage -import top.fatweb.api.entity.permission.Power -import top.fatweb.api.entity.permission.Role -import top.fatweb.api.param.permission.role.RoleAddParam -import top.fatweb.api.param.permission.role.RoleUpdateStatusParam -import top.fatweb.api.param.permission.role.RoleUpdateParam -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.base.RoleVo -import top.fatweb.api.vo.permission.RoleWithPowerVo +import top.fatweb.oxygen.api.entity.permission.Power +import top.fatweb.oxygen.api.entity.permission.Role +import top.fatweb.oxygen.api.param.permission.role.RoleAddParam +import top.fatweb.oxygen.api.param.permission.role.RoleUpdateParam +import top.fatweb.oxygen.api.param.permission.role.RoleUpdateStatusParam +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.RoleWithPowerVo +import top.fatweb.oxygen.api.vo.permission.base.RoleVo /** * Role converter diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/UserConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/UserConverter.kt similarity index 92% rename from src/main/kotlin/top/fatweb/api/converter/permission/UserConverter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/converter/permission/UserConverter.kt index 13a2964..b75bc68 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/UserConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/UserConverter.kt @@ -1,18 +1,18 @@ -package top.fatweb.api.converter.permission +package top.fatweb.oxygen.api.converter.permission import com.baomidou.mybatisplus.core.metadata.IPage -import top.fatweb.api.entity.permission.Group -import top.fatweb.api.entity.permission.Role -import top.fatweb.api.entity.permission.User -import top.fatweb.api.entity.permission.UserInfo -import top.fatweb.api.param.permission.user.UserAddParam -import top.fatweb.api.param.permission.user.UserUpdateParam -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.UserWithInfoVo -import top.fatweb.api.vo.permission.UserWithPasswordRoleInfoVo -import top.fatweb.api.vo.permission.UserWithPowerInfoVo -import top.fatweb.api.vo.permission.UserWithRoleInfoVo import top.fatweb.avatargenerator.GitHubAvatar +import top.fatweb.oxygen.api.entity.permission.Group +import top.fatweb.oxygen.api.entity.permission.Role +import top.fatweb.oxygen.api.entity.permission.User +import top.fatweb.oxygen.api.entity.permission.UserInfo +import top.fatweb.oxygen.api.param.permission.user.UserAddParam +import top.fatweb.oxygen.api.param.permission.user.UserUpdateParam +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.UserWithInfoVo +import top.fatweb.oxygen.api.vo.permission.UserWithPasswordRoleInfoVo +import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo +import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo /** * User converter diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/UserInfoConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/UserInfoConverter.kt similarity index 81% rename from src/main/kotlin/top/fatweb/api/converter/permission/UserInfoConverter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/converter/permission/UserInfoConverter.kt index dd2c253..89bf651 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/UserInfoConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/UserInfoConverter.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.converter.permission +package top.fatweb.oxygen.api.converter.permission -import top.fatweb.api.entity.permission.UserInfo -import top.fatweb.api.vo.permission.base.UserInfoVo +import top.fatweb.oxygen.api.entity.permission.UserInfo +import top.fatweb.oxygen.api.vo.permission.base.UserInfoVo /** * User information converter diff --git a/src/main/kotlin/top/fatweb/api/converter/system/SysLogConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SysLogConverter.kt similarity index 88% rename from src/main/kotlin/top/fatweb/api/converter/system/SysLogConverter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/converter/system/SysLogConverter.kt index 80812df..d94bd90 100644 --- a/src/main/kotlin/top/fatweb/api/converter/system/SysLogConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SysLogConverter.kt @@ -1,9 +1,9 @@ -package top.fatweb.api.converter.system +package top.fatweb.oxygen.api.converter.system import com.baomidou.mybatisplus.core.metadata.IPage -import top.fatweb.api.entity.system.SysLog -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.system.SysLogVo +import top.fatweb.oxygen.api.entity.system.SysLog +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.system.SysLogVo /** * System log converter diff --git a/src/main/kotlin/top/fatweb/api/cron/StatisticsCron.kt b/src/main/kotlin/top/fatweb/oxygen/api/cron/StatisticsCron.kt similarity index 65% rename from src/main/kotlin/top/fatweb/api/cron/StatisticsCron.kt rename to src/main/kotlin/top/fatweb/oxygen/api/cron/StatisticsCron.kt index 26677b1..e4b014f 100644 --- a/src/main/kotlin/top/fatweb/api/cron/StatisticsCron.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/cron/StatisticsCron.kt @@ -1,11 +1,11 @@ -package top.fatweb.api.cron +package top.fatweb.oxygen.api.cron import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Component -import top.fatweb.api.entity.system.StatisticsLog -import top.fatweb.api.properties.SecurityProperties -import top.fatweb.api.service.system.IStatisticsLogService -import top.fatweb.api.util.RedisUtil +import top.fatweb.oxygen.api.entity.system.StatisticsLog +import top.fatweb.oxygen.api.properties.SecurityProperties +import top.fatweb.oxygen.api.service.system.IStatisticsLogService +import top.fatweb.oxygen.api.util.RedisUtil /** * Statistics scheduled tasks @@ -29,7 +29,7 @@ class StatisticsCron( 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() + .distinctBy { Regex("${SecurityProperties.jwtIssuer}_login_(.*):.*").matchEntire(it)?.groupValues?.getOrNull(1) }.size.toString() }) } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/common/BusinessCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/BusinessCode.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/entity/common/BusinessCode.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/common/BusinessCode.kt index faff351..5c3a4d2 100644 --- a/src/main/kotlin/top/fatweb/api/entity/common/BusinessCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/BusinessCode.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.common +package top.fatweb.oxygen.api.entity.common /** * Business code entity diff --git a/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index 23eb2d5..5b6b721 100644 --- a/src/main/kotlin/top/fatweb/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.common +package top.fatweb.oxygen.api.entity.common /** * Response code entity diff --git a/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseResult.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseResult.kt index c3e2a1a..7c866fe 100644 --- a/src/main/kotlin/top/fatweb/api/entity/common/ResponseResult.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseResult.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.common +package top.fatweb.oxygen.api.entity.common import io.swagger.v3.oas.annotations.media.Schema import java.io.Serializable diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Func.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Func.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/entity/permission/Func.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Func.kt index fd7163c..78014e0 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/Func.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Func.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.TableField import com.baomidou.mybatisplus.annotation.TableId diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Group.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Group.kt similarity index 89% rename from src/main/kotlin/top/fatweb/api/entity/permission/Group.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Group.kt index 2f6afb8..480f857 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/Group.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Group.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.* import java.io.Serializable @@ -90,6 +90,6 @@ class Group : Serializable { var roles: List? = null override fun toString(): String { - return "Group(id=$id, name=$name, enable=$enable, deleted=$deleted, version=$version, roles=$roles)" + return "Group(id=$id, name=$name, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, roles=$roles)" } } diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/LoginUser.kt similarity index 91% rename from src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/LoginUser.kt index 1d9ce30..29fafce 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/LoginUser.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/LoginUser.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonTypeInfo @@ -60,4 +60,8 @@ class LoginUser() : UserDetails { @JsonIgnore override fun isEnabled() = user.enable == 1 + + override fun toString(): String { + return "LoginUser(user=$user, authorities=$authorities)" + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Menu.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Menu.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/entity/permission/Menu.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Menu.kt index 37577ee..a3f982e 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/Menu.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Menu.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.TableField import com.baomidou.mybatisplus.annotation.TableId diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Module.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Module.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/entity/permission/Module.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Module.kt index 37f2488..eac5aa7 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/Module.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Module.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.TableField import com.baomidou.mybatisplus.annotation.TableId diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Operation.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Operation.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/entity/permission/Operation.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Operation.kt index 106876f..05740b4 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/Operation.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Operation.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.TableField import com.baomidou.mybatisplus.annotation.TableId diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Power.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Power.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/entity/permission/Power.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Power.kt index af610b4..3ebe80a 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/Power.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Power.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.TableField import com.baomidou.mybatisplus.annotation.TableId diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/PowerRole.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerRole.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/entity/permission/PowerRole.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerRole.kt index 5651c12..915eb5a 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/PowerRole.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerRole.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.* import java.io.Serializable diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/PowerSet.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerSet.kt similarity index 79% rename from src/main/kotlin/top/fatweb/api/entity/permission/PowerSet.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerSet.kt index 519c077..c99f5ae 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/PowerSet.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerSet.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import java.io.Serializable @@ -44,4 +44,8 @@ class PowerSet : Serializable { * @see Operation */ var operationList: List? = null + + override fun toString(): String { + return "PowerSet(moduleList=$moduleList, menuList=$menuList, funcList=$funcList, operationList=$operationList)" + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/PowerType.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerType.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/entity/permission/PowerType.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerType.kt index e250336..676588c 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/PowerType.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerType.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.TableField import com.baomidou.mybatisplus.annotation.TableId diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Role.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Role.kt similarity index 90% rename from src/main/kotlin/top/fatweb/api/entity/permission/Role.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Role.kt index 81efd8a..32ba4fe 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/Role.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Role.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.* import java.io.Serializable @@ -130,6 +130,6 @@ class Role : Serializable { var powers: List? = null override fun toString(): String { - return "Role(id=$id, name=$name, enable=$enable, deleted=$deleted, version=$version, modules=$modules, menus=$menus, funcs=$funcs, operations=$operations, powers=$powers)" + return "Role(id=$id, name=$name, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, modules=$modules, menus=$menus, funcs=$funcs, operations=$operations, powers=$powers)" } } diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/RoleGroup.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RoleGroup.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/entity/permission/RoleGroup.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RoleGroup.kt index cb9e557..149e31a 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/RoleGroup.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RoleGroup.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.* import java.io.Serializable diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/User.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/User.kt similarity index 99% rename from src/main/kotlin/top/fatweb/api/entity/permission/User.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/User.kt index 14d04d2..67b6592 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/User.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/User.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.* import java.io.Serializable diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/UserGroup.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserGroup.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/entity/permission/UserGroup.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserGroup.kt index 368253e..ae8c102 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/UserGroup.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserGroup.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.* import java.io.Serializable diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/UserInfo.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserInfo.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/entity/permission/UserInfo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserInfo.kt index 9635470..f1cb26e 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/UserInfo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserInfo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.* import java.io.Serializable diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/UserRole.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserRole.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/entity/permission/UserRole.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserRole.kt index 94cb0b6..de09ff6 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/UserRole.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserRole.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.permission +package top.fatweb.oxygen.api.entity.permission import com.baomidou.mybatisplus.annotation.* import java.io.Serializable diff --git a/src/main/kotlin/top/fatweb/api/entity/system/EventLog.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/EventLog.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/entity/system/EventLog.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/system/EventLog.kt index e09f86f..a719457 100644 --- a/src/main/kotlin/top/fatweb/api/entity/system/EventLog.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/EventLog.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.system +package top.fatweb.oxygen.api.entity.system import com.baomidou.mybatisplus.annotation.EnumValue import com.baomidou.mybatisplus.annotation.TableField diff --git a/src/main/kotlin/top/fatweb/api/entity/system/StatisticsLog.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/StatisticsLog.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/entity/system/StatisticsLog.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/system/StatisticsLog.kt index b8c1426..7ba87a6 100644 --- a/src/main/kotlin/top/fatweb/api/entity/system/StatisticsLog.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/StatisticsLog.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.system +package top.fatweb.oxygen.api.entity.system import com.baomidou.mybatisplus.annotation.EnumValue import com.baomidou.mybatisplus.annotation.TableField @@ -56,7 +56,7 @@ class StatisticsLog : Serializable { */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") @TableField("record_time") - var recordTime: LocalDateTime?= null + var recordTime: LocalDateTime? = null override fun toString(): String { return "StatisticsLog(id=$id, key=$key, value=$value, recordTime=$recordTime)" diff --git a/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SysLog.kt similarity index 99% rename from src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/system/SysLog.kt index 98fbdf4..b557357 100644 --- a/src/main/kotlin/top/fatweb/api/entity/system/SysLog.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SysLog.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.entity.system +package top.fatweb.oxygen.api.entity.system import com.baomidou.mybatisplus.annotation.EnumValue import com.baomidou.mybatisplus.annotation.TableField diff --git a/src/main/kotlin/top/fatweb/api/exception/AccountNeedInitException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/AccountNeedInitException.kt similarity index 84% rename from src/main/kotlin/top/fatweb/api/exception/AccountNeedInitException.kt rename to src/main/kotlin/top/fatweb/oxygen/api/exception/AccountNeedInitException.kt index ec1bdb5..311a9a6 100644 --- a/src/main/kotlin/top/fatweb/api/exception/AccountNeedInitException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/AccountNeedInitException.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.exception +package top.fatweb.oxygen.api.exception /** * Account need initialize exception diff --git a/src/main/kotlin/top/fatweb/api/exception/AccountNeedResetPasswordException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/AccountNeedResetPasswordException.kt similarity index 85% rename from src/main/kotlin/top/fatweb/api/exception/AccountNeedResetPasswordException.kt rename to src/main/kotlin/top/fatweb/oxygen/api/exception/AccountNeedResetPasswordException.kt index 10f6767..756682b 100644 --- a/src/main/kotlin/top/fatweb/api/exception/AccountNeedResetPasswordException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/AccountNeedResetPasswordException.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.exception +package top.fatweb.oxygen.api.exception /** * Account need reset password exception diff --git a/src/main/kotlin/top/fatweb/api/exception/NoEmailConfigException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/NoEmailConfigException.kt similarity index 88% rename from src/main/kotlin/top/fatweb/api/exception/NoEmailConfigException.kt rename to src/main/kotlin/top/fatweb/oxygen/api/exception/NoEmailConfigException.kt index 0377775..a7bd6f2 100644 --- a/src/main/kotlin/top/fatweb/api/exception/NoEmailConfigException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/NoEmailConfigException.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.exception +package top.fatweb.oxygen.api.exception /** * Email settings not configured exception diff --git a/src/main/kotlin/top/fatweb/api/exception/NoRecordFoundException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/NoRecordFoundException.kt similarity index 82% rename from src/main/kotlin/top/fatweb/api/exception/NoRecordFoundException.kt rename to src/main/kotlin/top/fatweb/oxygen/api/exception/NoRecordFoundException.kt index 574c7ab..65274fa 100644 --- a/src/main/kotlin/top/fatweb/api/exception/NoRecordFoundException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/NoRecordFoundException.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.exception +package top.fatweb.oxygen.api.exception /** * No record found exception diff --git a/src/main/kotlin/top/fatweb/api/exception/NoVerificationRequiredException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/NoVerificationRequiredException.kt similarity index 84% rename from src/main/kotlin/top/fatweb/api/exception/NoVerificationRequiredException.kt rename to src/main/kotlin/top/fatweb/oxygen/api/exception/NoVerificationRequiredException.kt index 4ae2c74..c0bcc3a 100644 --- a/src/main/kotlin/top/fatweb/api/exception/NoVerificationRequiredException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/NoVerificationRequiredException.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.exception +package top.fatweb.oxygen.api.exception /** * No verification required exception diff --git a/src/main/kotlin/top/fatweb/api/exception/RetrieveCodeErrorOrExpiredException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/RetrieveCodeErrorOrExpiredException.kt similarity index 85% rename from src/main/kotlin/top/fatweb/api/exception/RetrieveCodeErrorOrExpiredException.kt rename to src/main/kotlin/top/fatweb/oxygen/api/exception/RetrieveCodeErrorOrExpiredException.kt index d73239e..d8010c1 100644 --- a/src/main/kotlin/top/fatweb/api/exception/RetrieveCodeErrorOrExpiredException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/RetrieveCodeErrorOrExpiredException.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.exception +package top.fatweb.oxygen.api.exception /** * Retrieve code error or expired exception diff --git a/src/main/kotlin/top/fatweb/api/exception/TokenHasExpiredException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/TokenHasExpiredException.kt similarity index 83% rename from src/main/kotlin/top/fatweb/api/exception/TokenHasExpiredException.kt rename to src/main/kotlin/top/fatweb/oxygen/api/exception/TokenHasExpiredException.kt index e5fb85d..7250ef7 100644 --- a/src/main/kotlin/top/fatweb/api/exception/TokenHasExpiredException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/TokenHasExpiredException.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.exception +package top.fatweb.oxygen.api.exception /** * Token has expired exception diff --git a/src/main/kotlin/top/fatweb/api/exception/UserNotFoundException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/UserNotFoundException.kt similarity index 82% rename from src/main/kotlin/top/fatweb/api/exception/UserNotFoundException.kt rename to src/main/kotlin/top/fatweb/oxygen/api/exception/UserNotFoundException.kt index 64b032b..6b2dc60 100644 --- a/src/main/kotlin/top/fatweb/api/exception/UserNotFoundException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/UserNotFoundException.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.exception +package top.fatweb.oxygen.api.exception /** * User not found exception diff --git a/src/main/kotlin/top/fatweb/api/exception/VerificationCodeErrorOrExpiredException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/VerificationCodeErrorOrExpiredException.kt similarity index 86% rename from src/main/kotlin/top/fatweb/api/exception/VerificationCodeErrorOrExpiredException.kt rename to src/main/kotlin/top/fatweb/oxygen/api/exception/VerificationCodeErrorOrExpiredException.kt index 9c28388..bfbbee7 100644 --- a/src/main/kotlin/top/fatweb/api/exception/VerificationCodeErrorOrExpiredException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/VerificationCodeErrorOrExpiredException.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.exception +package top.fatweb.oxygen.api.exception /** * Verification code error or expired exception diff --git a/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt b/src/main/kotlin/top/fatweb/oxygen/api/filter/ExceptionFilter.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/filter/ExceptionFilter.kt index 193f33c..6117074 100644 --- a/src/main/kotlin/top/fatweb/api/filter/ExceptionFilter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/filter/ExceptionFilter.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.filter +package top.fatweb.oxygen.api.filter import jakarta.servlet.Filter import jakarta.servlet.FilterChain diff --git a/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt b/src/main/kotlin/top/fatweb/oxygen/api/filter/JwtAuthenticationTokenFilter.kt similarity index 84% rename from src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt rename to src/main/kotlin/top/fatweb/oxygen/api/filter/JwtAuthenticationTokenFilter.kt index 1af4dfb..0c61eb5 100644 --- a/src/main/kotlin/top/fatweb/api/filter/JwtAuthenticationTokenFilter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/filter/JwtAuthenticationTokenFilter.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.filter +package top.fatweb.oxygen.api.filter import jakarta.servlet.FilterChain import jakarta.servlet.http.HttpServletRequest @@ -8,12 +8,12 @@ import org.springframework.security.core.context.SecurityContextHolder import org.springframework.stereotype.Component import org.springframework.util.StringUtils import org.springframework.web.filter.OncePerRequestFilter -import top.fatweb.api.entity.permission.LoginUser -import top.fatweb.api.exception.TokenHasExpiredException -import top.fatweb.api.properties.SecurityProperties -import top.fatweb.api.util.JwtUtil -import top.fatweb.api.util.RedisUtil -import top.fatweb.api.util.WebUtil +import top.fatweb.oxygen.api.entity.permission.LoginUser +import top.fatweb.oxygen.api.exception.TokenHasExpiredException +import top.fatweb.oxygen.api.properties.SecurityProperties +import top.fatweb.oxygen.api.util.JwtUtil +import top.fatweb.oxygen.api.util.RedisUtil +import top.fatweb.oxygen.api.util.WebUtil /** * Jwt authentication token filter diff --git a/src/main/kotlin/top/fatweb/api/handler/DataMetaObjectHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/DataMetaObjectHandler.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/handler/DataMetaObjectHandler.kt rename to src/main/kotlin/top/fatweb/oxygen/api/handler/DataMetaObjectHandler.kt index b85cbe1..e667eec 100644 --- a/src/main/kotlin/top/fatweb/api/handler/DataMetaObjectHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/DataMetaObjectHandler.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.handler +package top.fatweb.oxygen.api.handler import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler import org.apache.ibatis.reflection.MetaObject diff --git a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt rename to src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index 3d818cb..47d2262 100644 --- a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.handler +package top.fatweb.oxygen.api.handler import com.auth0.jwt.exceptions.JWTDecodeException import com.auth0.jwt.exceptions.SignatureVerificationException @@ -14,10 +14,10 @@ import org.springframework.web.HttpRequestMethodNotSupportedException import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.RestControllerAdvice -import top.fatweb.api.entity.common.ResponseCode -import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.exception.* import top.fatweb.avatargenerator.AvatarException +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.exception.* /** * Exception handler diff --git a/src/main/kotlin/top/fatweb/api/handler/JwtAccessDeniedHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/JwtAccessDeniedHandler.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/handler/JwtAccessDeniedHandler.kt rename to src/main/kotlin/top/fatweb/oxygen/api/handler/JwtAccessDeniedHandler.kt index 7e8f1f8..2c89073 100644 --- a/src/main/kotlin/top/fatweb/api/handler/JwtAccessDeniedHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/JwtAccessDeniedHandler.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.handler +package top.fatweb.oxygen.api.handler import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse diff --git a/src/main/kotlin/top/fatweb/api/handler/JwtAuthenticationEntryPointHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/JwtAuthenticationEntryPointHandler.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/handler/JwtAuthenticationEntryPointHandler.kt rename to src/main/kotlin/top/fatweb/oxygen/api/handler/JwtAuthenticationEntryPointHandler.kt index fc477d4..b215232 100644 --- a/src/main/kotlin/top/fatweb/api/handler/JwtAuthenticationEntryPointHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/JwtAuthenticationEntryPointHandler.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.handler +package top.fatweb.oxygen.api.handler import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse diff --git a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt b/src/main/kotlin/top/fatweb/oxygen/api/interceptor/SysLogInterceptor.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt rename to src/main/kotlin/top/fatweb/oxygen/api/interceptor/SysLogInterceptor.kt index e91bc78..73ac78a 100644 --- a/src/main/kotlin/top/fatweb/api/interceptor/SysLogInterceptor.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/interceptor/SysLogInterceptor.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.interceptor +package top.fatweb.oxygen.api.interceptor import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse @@ -11,12 +11,12 @@ import org.springframework.http.server.ServerHttpResponse import org.springframework.web.bind.annotation.ControllerAdvice import org.springframework.web.servlet.HandlerInterceptor import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice -import top.fatweb.api.entity.common.ResponseCode -import top.fatweb.api.entity.common.ResponseResult -import top.fatweb.api.entity.system.SysLog -import top.fatweb.api.service.system.ISysLogService -import top.fatweb.api.util.WebUtil -import top.fatweb.api.vo.permission.LoginVo +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.entity.system.SysLog +import top.fatweb.oxygen.api.service.system.ISysLogService +import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.permission.LoginVo import java.net.URI import java.time.LocalDateTime import java.time.ZoneOffset diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/FuncMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/FuncMapper.kt similarity index 73% rename from src/main/kotlin/top/fatweb/api/mapper/permission/FuncMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/FuncMapper.kt index c20f3c6..167353d 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/FuncMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/FuncMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.permission.Func +import top.fatweb.oxygen.api.entity.permission.Func /** * Function mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/GroupMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/GroupMapper.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/mapper/permission/GroupMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/GroupMapper.kt index d2b001e..8413f65 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/GroupMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/GroupMapper.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import com.baomidou.mybatisplus.core.metadata.IPage import org.apache.ibatis.annotations.Mapper import org.apache.ibatis.annotations.Param -import top.fatweb.api.entity.permission.Group +import top.fatweb.oxygen.api.entity.permission.Group /** * Group mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/MenuMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/MenuMapper.kt similarity index 72% rename from src/main/kotlin/top/fatweb/api/mapper/permission/MenuMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/MenuMapper.kt index f3527af..1952dcd 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/MenuMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/MenuMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.permission.Menu +import top.fatweb.oxygen.api.entity.permission.Menu /** * Menu mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/ModuleMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/ModuleMapper.kt similarity index 72% rename from src/main/kotlin/top/fatweb/api/mapper/permission/ModuleMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/ModuleMapper.kt index 2c5041a..bc2e492 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/ModuleMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/ModuleMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.permission.Module +import top.fatweb.oxygen.api.entity.permission.Module /** * Module mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/OperationMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/OperationMapper.kt similarity index 73% rename from src/main/kotlin/top/fatweb/api/mapper/permission/OperationMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/OperationMapper.kt index c9e7dd1..848a5bf 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/OperationMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/OperationMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.permission.Operation +import top.fatweb.oxygen.api.entity.permission.Operation /** * Operation mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/PowerMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/PowerMapper.kt similarity index 72% rename from src/main/kotlin/top/fatweb/api/mapper/permission/PowerMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/PowerMapper.kt index 1dd1bb5..1100fdd 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/PowerMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/PowerMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.permission.Power +import top.fatweb.oxygen.api.entity.permission.Power /** * Power mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/PowerRoleMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/PowerRoleMapper.kt similarity index 74% rename from src/main/kotlin/top/fatweb/api/mapper/permission/PowerRoleMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/PowerRoleMapper.kt index 643f5a0..ec2af79 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/PowerRoleMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/PowerRoleMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.permission.PowerRole +import top.fatweb.oxygen.api.entity.permission.PowerRole /** * Power role intermediate mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/RoleGroupMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RoleGroupMapper.kt similarity index 74% rename from src/main/kotlin/top/fatweb/api/mapper/permission/RoleGroupMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RoleGroupMapper.kt index 39a3f04..8010ae4 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/RoleGroupMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RoleGroupMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.permission.RoleGroup +import top.fatweb.oxygen.api.entity.permission.RoleGroup /** * Role group intermediate mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/RoleMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RoleMapper.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/mapper/permission/RoleMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RoleMapper.kt index 94c99a5..b036bee 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/RoleMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RoleMapper.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import com.baomidou.mybatisplus.core.metadata.IPage import org.apache.ibatis.annotations.Mapper import org.apache.ibatis.annotations.Param -import top.fatweb.api.entity.permission.Role +import top.fatweb.oxygen.api.entity.permission.Role /** * Role mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/UserGroupMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserGroupMapper.kt similarity index 74% rename from src/main/kotlin/top/fatweb/api/mapper/permission/UserGroupMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserGroupMapper.kt index aea7444..4dbe85e 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/UserGroupMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserGroupMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.permission.UserGroup +import top.fatweb.oxygen.api.entity.permission.UserGroup /** * User group intermediate mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/UserInfoMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserInfoMapper.kt similarity index 73% rename from src/main/kotlin/top/fatweb/api/mapper/permission/UserInfoMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserInfoMapper.kt index 4313835..8e816d6 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/UserInfoMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserInfoMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.permission.UserInfo +import top.fatweb.oxygen.api.entity.permission.UserInfo /** * User information mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserMapper.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserMapper.kt index 0118e0d..1f91df6 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/UserMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserMapper.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import com.baomidou.mybatisplus.core.metadata.IPage import org.apache.ibatis.annotations.Mapper import org.apache.ibatis.annotations.Param -import top.fatweb.api.entity.permission.User +import top.fatweb.oxygen.api.entity.permission.User /** * User mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/UserRoleMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserRoleMapper.kt similarity index 74% rename from src/main/kotlin/top/fatweb/api/mapper/permission/UserRoleMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserRoleMapper.kt index 10d7892..ebc5eb6 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/permission/UserRoleMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserRoleMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.permission +package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.permission.UserRole +import top.fatweb.oxygen.api.entity.permission.UserRole /** * User role intermediate mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/system/EventLogMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/EventLogMapper.kt similarity index 72% rename from src/main/kotlin/top/fatweb/api/mapper/system/EventLogMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/system/EventLogMapper.kt index 8bf0da4..b9e5963 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/system/EventLogMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/EventLogMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.system +package top.fatweb.oxygen.api.mapper.system import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.system.EventLog +import top.fatweb.oxygen.api.entity.system.EventLog /** * Event log mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/system/StatisticsLogMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/StatisticsLogMapper.kt similarity index 72% rename from src/main/kotlin/top/fatweb/api/mapper/system/StatisticsLogMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/system/StatisticsLogMapper.kt index 1d60659..5c6266a 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/system/StatisticsLogMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/StatisticsLogMapper.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.mapper.system +package top.fatweb.oxygen.api.mapper.system import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.api.entity.system.StatisticsLog +import top.fatweb.oxygen.api.entity.system.StatisticsLog /** * Statistics log mapper diff --git a/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/SysLogMapper.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/system/SysLogMapper.kt index b8f0932..06088a2 100644 --- a/src/main/kotlin/top/fatweb/api/mapper/system/SysLogMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/SysLogMapper.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.mapper.system +package top.fatweb.oxygen.api.mapper.system import com.baomidou.mybatisplus.core.mapper.BaseMapper import com.baomidou.mybatisplus.core.metadata.IPage import org.apache.ibatis.annotations.Mapper import org.apache.ibatis.annotations.Param -import top.fatweb.api.entity.system.SysLog +import top.fatweb.oxygen.api.entity.system.SysLog import java.time.LocalDateTime /** diff --git a/src/main/kotlin/top/fatweb/api/param/PageSortParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/PageSortParam.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/param/PageSortParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/PageSortParam.kt index 6692b20..cab7e95 100644 --- a/src/main/kotlin/top/fatweb/api/param/PageSortParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/PageSortParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param +package top.fatweb.oxygen.api.param import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.Min diff --git a/src/main/kotlin/top/fatweb/api/param/api/v1/avatar/AvatarBaseParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarBaseParam.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/param/api/v1/avatar/AvatarBaseParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarBaseParam.kt index b333daa..390e4d1 100644 --- a/src/main/kotlin/top/fatweb/api/param/api/v1/avatar/AvatarBaseParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarBaseParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.api.v1.avatar +package top.fatweb.oxygen.api.param.api.v1.avatar import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.Max diff --git a/src/main/kotlin/top/fatweb/api/param/api/v1/avatar/AvatarGitHubParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarGitHubParam.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/param/api/v1/avatar/AvatarGitHubParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarGitHubParam.kt index 536c000..58e4908 100644 --- a/src/main/kotlin/top/fatweb/api/param/api/v1/avatar/AvatarGitHubParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarGitHubParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.api.v1.avatar +package top.fatweb.oxygen.api.param.api.v1.avatar import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.Max diff --git a/src/main/kotlin/top/fatweb/api/param/permission/ForgetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/ForgetParam.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/param/permission/ForgetParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/ForgetParam.kt index 97398b9..05091d2 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/ForgetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/ForgetParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission +package top.fatweb.oxygen.api.param.permission import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/permission/LoginParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/param/permission/LoginParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt index 163a849..2c0da76 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/LoginParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission +package top.fatweb.oxygen.api.param.permission import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/permission/RegisterParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/param/permission/RegisterParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt index 731cb6f..e32ee3a 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/RegisterParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission +package top.fatweb.oxygen.api.param.permission import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/permission/RetrieveParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/param/permission/RetrieveParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt index cbd41b9..f3571d5 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/RetrieveParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission +package top.fatweb.oxygen.api.param.permission import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/permission/VerifyParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/VerifyParam.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/param/permission/VerifyParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/VerifyParam.kt index a9670d1..c88e333 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/VerifyParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/VerifyParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission +package top.fatweb.oxygen.api.param.permission import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/permission/group/GroupAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupAddParam.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/param/permission/group/GroupAddParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupAddParam.kt index b3471a4..6f24d3d 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/group/GroupAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupAddParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.group +package top.fatweb.oxygen.api.param.permission.group import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/permission/group/GroupDeleteParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupDeleteParam.kt similarity index 89% rename from src/main/kotlin/top/fatweb/api/param/permission/group/GroupDeleteParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupDeleteParam.kt index 2e2dc54..f7ebe22 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/group/GroupDeleteParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupDeleteParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.group +package top.fatweb.oxygen.api.param.permission.group import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/param/permission/group/GroupGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupGetParam.kt similarity index 88% rename from src/main/kotlin/top/fatweb/api/param/permission/group/GroupGetParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupGetParam.kt index cbaf63e..f494191 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/group/GroupGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupGetParam.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.param.permission.group +package top.fatweb.oxygen.api.param.permission.group import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.param.PageSortParam +import top.fatweb.oxygen.api.param.PageSortParam /** * Get group parameters diff --git a/src/main/kotlin/top/fatweb/api/param/permission/group/GroupUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupUpdateParam.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/param/permission/group/GroupUpdateParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupUpdateParam.kt index d02d4e1..937679c 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/group/GroupUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupUpdateParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.group +package top.fatweb.oxygen.api.param.permission.group import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/permission/group/GroupUpdateStatusParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupUpdateStatusParam.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/param/permission/group/GroupUpdateStatusParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupUpdateStatusParam.kt index 9a7affb..2676a93 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/group/GroupUpdateStatusParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupUpdateStatusParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.group +package top.fatweb.oxygen.api.param.permission.group import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull diff --git a/src/main/kotlin/top/fatweb/api/param/permission/role/RoleAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleAddParam.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/param/permission/role/RoleAddParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleAddParam.kt index a44f703..ab093c5 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/role/RoleAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleAddParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.role +package top.fatweb.oxygen.api.param.permission.role import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/permission/role/RoleDeleteParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleDeleteParam.kt similarity index 89% rename from src/main/kotlin/top/fatweb/api/param/permission/role/RoleDeleteParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleDeleteParam.kt index 74a3b44..af400da 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/role/RoleDeleteParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleDeleteParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.role +package top.fatweb.oxygen.api.param.permission.role import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/param/permission/role/RoleGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleGetParam.kt similarity index 88% rename from src/main/kotlin/top/fatweb/api/param/permission/role/RoleGetParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleGetParam.kt index 469720b..929ba19 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/role/RoleGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleGetParam.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.param.permission.role +package top.fatweb.oxygen.api.param.permission.role import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.param.PageSortParam +import top.fatweb.oxygen.api.param.PageSortParam /** * Get role parameters diff --git a/src/main/kotlin/top/fatweb/api/param/permission/role/RoleUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleUpdateParam.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/param/permission/role/RoleUpdateParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleUpdateParam.kt index c123665..c24704f 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/role/RoleUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleUpdateParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.role +package top.fatweb.oxygen.api.param.permission.role import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/permission/role/RoleUpdateStatusParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleUpdateStatusParam.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/param/permission/role/RoleUpdateStatusParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleUpdateStatusParam.kt index fa0f135..5fda3c1 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/role/RoleUpdateStatusParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleUpdateStatusParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.role +package top.fatweb.oxygen.api.param.permission.role import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull diff --git a/src/main/kotlin/top/fatweb/api/param/permission/user/UserAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserAddParam.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/param/permission/user/UserAddParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserAddParam.kt index a2e227b..52b941a 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/user/UserAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserAddParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.user +package top.fatweb.oxygen.api.param.permission.user import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/permission/user/UserDeleteParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserDeleteParam.kt similarity index 89% rename from src/main/kotlin/top/fatweb/api/param/permission/user/UserDeleteParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserDeleteParam.kt index eba2828..486d39c 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/user/UserDeleteParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserDeleteParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.user +package top.fatweb.oxygen.api.param.permission.user import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/param/permission/user/UserGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserGetParam.kt similarity index 91% rename from src/main/kotlin/top/fatweb/api/param/permission/user/UserGetParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserGetParam.kt index f06548b..93c4fa0 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/user/UserGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserGetParam.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.param.permission.user +package top.fatweb.oxygen.api.param.permission.user import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.param.PageSortParam +import top.fatweb.oxygen.api.param.PageSortParam /** * Get user parameters diff --git a/src/main/kotlin/top/fatweb/api/param/permission/user/UserUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserUpdateParam.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/param/permission/user/UserUpdateParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserUpdateParam.kt index 96afb83..fb7298b 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/user/UserUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserUpdateParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.user +package top.fatweb.oxygen.api.param.permission.user import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/permission/user/UserUpdatePasswordParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserUpdatePasswordParam.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/param/permission/user/UserUpdatePasswordParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserUpdatePasswordParam.kt index 561ba34..76e8413 100644 --- a/src/main/kotlin/top/fatweb/api/param/permission/user/UserUpdatePasswordParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserUpdatePasswordParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.permission.user +package top.fatweb.oxygen.api.param.permission.user import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/system/ActiveInfoGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/ActiveInfoGetParam.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/param/system/ActiveInfoGetParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/system/ActiveInfoGetParam.kt index ce8b7ac..51e45b9 100644 --- a/src/main/kotlin/top/fatweb/api/param/system/ActiveInfoGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/ActiveInfoGetParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.system +package top.fatweb.oxygen.api.param.system import com.baomidou.mybatisplus.annotation.EnumValue import com.fasterxml.jackson.annotation.JsonValue diff --git a/src/main/kotlin/top/fatweb/api/param/system/BaseSettingsParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/BaseSettingsParam.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/param/system/BaseSettingsParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/system/BaseSettingsParam.kt index 6d8bb4c..eaf5226 100644 --- a/src/main/kotlin/top/fatweb/api/param/system/BaseSettingsParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/BaseSettingsParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.system +package top.fatweb.oxygen.api.param.system import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/param/system/MailSendParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSendParam.kt similarity index 92% rename from src/main/kotlin/top/fatweb/api/param/system/MailSendParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSendParam.kt index e408664..08ffd20 100644 --- a/src/main/kotlin/top/fatweb/api/param/system/MailSendParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSendParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.system +package top.fatweb.oxygen.api.param.system import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank diff --git a/src/main/kotlin/top/fatweb/api/param/system/MailSettingsParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSettingsParam.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/param/system/MailSettingsParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSettingsParam.kt index 0446b78..d56ca69 100644 --- a/src/main/kotlin/top/fatweb/api/param/system/MailSettingsParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSettingsParam.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.param.system +package top.fatweb.oxygen.api.param.system import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.settings.MailSecurityType +import top.fatweb.oxygen.api.settings.MailSecurityType /** * Mail settings parameters diff --git a/src/main/kotlin/top/fatweb/api/param/system/OnlineInfoGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/OnlineInfoGetParam.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/param/system/OnlineInfoGetParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/system/OnlineInfoGetParam.kt index 557be14..1e42833 100644 --- a/src/main/kotlin/top/fatweb/api/param/system/OnlineInfoGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/OnlineInfoGetParam.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.param.system +package top.fatweb.oxygen.api.param.system import com.baomidou.mybatisplus.annotation.EnumValue import com.fasterxml.jackson.annotation.JsonValue diff --git a/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/SysLogGetParam.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt rename to src/main/kotlin/top/fatweb/oxygen/api/param/system/SysLogGetParam.kt index 9d22674..f948f87 100644 --- a/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/SysLogGetParam.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.param.system +package top.fatweb.oxygen.api.param.system import io.swagger.v3.oas.annotations.media.Schema import org.springframework.format.annotation.DateTimeFormat -import top.fatweb.api.param.PageSortParam +import top.fatweb.oxygen.api.param.PageSortParam import java.time.LocalDateTime /** diff --git a/src/main/kotlin/top/fatweb/api/properties/AdminProperties.kt b/src/main/kotlin/top/fatweb/oxygen/api/properties/AdminProperties.kt similarity index 91% rename from src/main/kotlin/top/fatweb/api/properties/AdminProperties.kt rename to src/main/kotlin/top/fatweb/oxygen/api/properties/AdminProperties.kt index 0067b89..4638122 100644 --- a/src/main/kotlin/top/fatweb/api/properties/AdminProperties.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/properties/AdminProperties.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.properties +package top.fatweb.oxygen.api.properties import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.stereotype.Component @@ -42,5 +42,5 @@ object AdminProperties { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - var email = "admin@fatweb.top" + var email = "admin@mail.com" } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/properties/FlywayProperties.kt b/src/main/kotlin/top/fatweb/oxygen/api/properties/FlywayProperties.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/properties/FlywayProperties.kt rename to src/main/kotlin/top/fatweb/oxygen/api/properties/FlywayProperties.kt index 9a2a31e..c6f857e 100644 --- a/src/main/kotlin/top/fatweb/api/properties/FlywayProperties.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/properties/FlywayProperties.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.properties +package top.fatweb.oxygen.api.properties import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.stereotype.Component diff --git a/src/main/kotlin/top/fatweb/api/properties/SecurityProperties.kt b/src/main/kotlin/top/fatweb/oxygen/api/properties/SecurityProperties.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/properties/SecurityProperties.kt rename to src/main/kotlin/top/fatweb/oxygen/api/properties/SecurityProperties.kt index ed079bf..fe70e6d 100644 --- a/src/main/kotlin/top/fatweb/api/properties/SecurityProperties.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/properties/SecurityProperties.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.properties +package top.fatweb.oxygen.api.properties import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.stereotype.Component @@ -51,7 +51,7 @@ object SecurityProperties { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - var jwtKey = "FatWeb" + var jwtKey = "Oxygen" /** * Issuer of JWT @@ -59,7 +59,7 @@ object SecurityProperties { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - var jwtIssuer = "FatWeb" + var jwtIssuer = "Oxygen" /** * TTL of redis diff --git a/src/main/kotlin/top/fatweb/api/properties/ServerProperties.kt b/src/main/kotlin/top/fatweb/oxygen/api/properties/ServerProperties.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/properties/ServerProperties.kt rename to src/main/kotlin/top/fatweb/oxygen/api/properties/ServerProperties.kt index e9b3c1b..4912682 100644 --- a/src/main/kotlin/top/fatweb/api/properties/ServerProperties.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/properties/ServerProperties.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.properties +package top.fatweb.oxygen.api.properties import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.stereotype.Component @@ -39,7 +39,7 @@ object ServerProperties { * @since 1.0.0 */ lateinit var buildTime: String - + /** * Startup time * diff --git a/src/main/kotlin/top/fatweb/api/service/api/v1/IAvatarService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/IAvatarService.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/service/api/v1/IAvatarService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/IAvatarService.kt index c5659de..46520c9 100644 --- a/src/main/kotlin/top/fatweb/api/service/api/v1/IAvatarService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/IAvatarService.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.service.api.v1 +package top.fatweb.oxygen.api.service.api.v1 -import top.fatweb.api.param.api.v1.avatar.AvatarBaseParam -import top.fatweb.api.param.api.v1.avatar.AvatarGitHubParam -import top.fatweb.api.vo.api.v1.avatar.AvatarBase64Vo +import top.fatweb.oxygen.api.param.api.v1.avatar.AvatarBaseParam +import top.fatweb.oxygen.api.param.api.v1.avatar.AvatarGitHubParam +import top.fatweb.oxygen.api.vo.api.v1.avatar.AvatarBase64Vo /** * Avatar service interface diff --git a/src/main/kotlin/top/fatweb/api/service/api/v1/impl/AvatarServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/service/api/v1/impl/AvatarServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt index d209d3b..b117db4 100644 --- a/src/main/kotlin/top/fatweb/api/service/api/v1/impl/AvatarServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt @@ -1,16 +1,16 @@ -package top.fatweb.api.service.api.v1.impl +package top.fatweb.oxygen.api.service.api.v1.impl import org.springframework.stereotype.Service -import top.fatweb.api.param.api.v1.avatar.AvatarBaseParam -import top.fatweb.api.param.api.v1.avatar.AvatarGitHubParam -import top.fatweb.api.service.api.v1.IAvatarService -import top.fatweb.api.util.NumberUtil -import top.fatweb.api.vo.api.v1.avatar.AvatarBase64Vo import top.fatweb.avatargenerator.GitHubAvatar import top.fatweb.avatargenerator.IdenticonAvatar import top.fatweb.avatargenerator.SquareAvatar import top.fatweb.avatargenerator.TriangleAvatar import top.fatweb.avatargenerator.layer.background.ColorPaintBackgroundLayer +import top.fatweb.oxygen.api.param.api.v1.avatar.AvatarBaseParam +import top.fatweb.oxygen.api.param.api.v1.avatar.AvatarGitHubParam +import top.fatweb.oxygen.api.service.api.v1.IAvatarService +import top.fatweb.oxygen.api.util.NumberUtil +import top.fatweb.oxygen.api.vo.api.v1.avatar.AvatarBase64Vo import java.awt.Color import kotlin.io.encoding.Base64 import kotlin.io.encoding.ExperimentalEncodingApi diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IAuthenticationService.kt similarity index 88% rename from src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IAuthenticationService.kt index 050d2f3..557a8b8 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IAuthenticationService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IAuthenticationService.kt @@ -1,11 +1,11 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import jakarta.servlet.http.HttpServletRequest -import top.fatweb.api.entity.permission.User -import top.fatweb.api.param.permission.* -import top.fatweb.api.vo.permission.LoginVo -import top.fatweb.api.vo.permission.RegisterVo -import top.fatweb.api.vo.permission.TokenVo +import top.fatweb.oxygen.api.entity.permission.User +import top.fatweb.oxygen.api.param.permission.* +import top.fatweb.oxygen.api.vo.permission.LoginVo +import top.fatweb.oxygen.api.vo.permission.RegisterVo +import top.fatweb.oxygen.api.vo.permission.TokenVo /** * Authentication service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IFuncService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IFuncService.kt similarity index 69% rename from src/main/kotlin/top/fatweb/api/service/permission/IFuncService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IFuncService.kt index f482566..36af68a 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IFuncService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IFuncService.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.Func +import top.fatweb.oxygen.api.entity.permission.Func /** * Function service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IGroupService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IGroupService.kt similarity index 88% rename from src/main/kotlin/top/fatweb/api/service/permission/IGroupService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IGroupService.kt index 4660759..761ef8d 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IGroupService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IGroupService.kt @@ -1,11 +1,11 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.Group -import top.fatweb.api.param.permission.group.* -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.base.GroupVo -import top.fatweb.api.vo.permission.GroupWithRoleVo +import top.fatweb.oxygen.api.entity.permission.Group +import top.fatweb.oxygen.api.param.permission.group.* +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.GroupWithRoleVo +import top.fatweb.oxygen.api.vo.permission.base.GroupVo /** * Group service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IMenuService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IMenuService.kt similarity index 69% rename from src/main/kotlin/top/fatweb/api/service/permission/IMenuService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IMenuService.kt index ae2216b..967d56a 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IMenuService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IMenuService.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.Menu +import top.fatweb.oxygen.api.entity.permission.Menu /** * Menu service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IModuleService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IModuleService.kt similarity index 69% rename from src/main/kotlin/top/fatweb/api/service/permission/IModuleService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IModuleService.kt index f2a06bf..431a84d 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IModuleService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IModuleService.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.Module +import top.fatweb.oxygen.api.entity.permission.Module /** * Module service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IOperationService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IOperationService.kt similarity index 70% rename from src/main/kotlin/top/fatweb/api/service/permission/IOperationService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IOperationService.kt index fb36082..a468550 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IOperationService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IOperationService.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.Operation +import top.fatweb.oxygen.api.entity.permission.Operation /** * Operation service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IPowerRoleService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IPowerRoleService.kt similarity index 71% rename from src/main/kotlin/top/fatweb/api/service/permission/IPowerRoleService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IPowerRoleService.kt index 7cd4995..22787b0 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IPowerRoleService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IPowerRoleService.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.PowerRole +import top.fatweb.oxygen.api.entity.permission.PowerRole /** * Power role intermediate service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IPowerService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IPowerService.kt similarity index 73% rename from src/main/kotlin/top/fatweb/api/service/permission/IPowerService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IPowerService.kt index 8e8611a..b5a34cd 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IPowerService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IPowerService.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.Power -import top.fatweb.api.vo.permission.PowerSetVo +import top.fatweb.oxygen.api.entity.permission.Power +import top.fatweb.oxygen.api.vo.permission.PowerSetVo /** * Power service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IRoleGroupService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleGroupService.kt similarity index 71% rename from src/main/kotlin/top/fatweb/api/service/permission/IRoleGroupService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleGroupService.kt index 7ccddbc..0465468 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IRoleGroupService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleGroupService.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.RoleGroup +import top.fatweb.oxygen.api.entity.permission.RoleGroup /** * Role group intermediate service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleService.kt similarity index 88% rename from src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleService.kt index 8f944fa..c12c6d8 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleService.kt @@ -1,11 +1,11 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.Role -import top.fatweb.api.param.permission.role.* -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.base.RoleVo -import top.fatweb.api.vo.permission.RoleWithPowerVo +import top.fatweb.oxygen.api.entity.permission.Role +import top.fatweb.oxygen.api.param.permission.role.* +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.RoleWithPowerVo +import top.fatweb.oxygen.api.vo.permission.base.RoleVo /** * Role service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IUserGroupService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserGroupService.kt similarity index 71% rename from src/main/kotlin/top/fatweb/api/service/permission/IUserGroupService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserGroupService.kt index 8ff45d2..ec8765f 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IUserGroupService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserGroupService.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.UserGroup +import top.fatweb.oxygen.api.entity.permission.UserGroup /** * User group intermediate service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IUserInfoService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserInfoService.kt similarity index 70% rename from src/main/kotlin/top/fatweb/api/service/permission/IUserInfoService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserInfoService.kt index 4455d05..c2b29f3 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IUserInfoService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserInfoService.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.UserInfo +import top.fatweb.oxygen.api.entity.permission.UserInfo /** * User information service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IUserRoleService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserRoleService.kt similarity index 71% rename from src/main/kotlin/top/fatweb/api/service/permission/IUserRoleService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserRoleService.kt index 1b1ff58..debf680 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IUserRoleService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserRoleService.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.UserRole +import top.fatweb.oxygen.api.entity.permission.UserRole /** * User role intermediate service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt similarity index 88% rename from src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt index a208420..fe38623 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IUserService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt @@ -1,13 +1,13 @@ -package top.fatweb.api.service.permission +package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.permission.User -import top.fatweb.api.param.permission.user.* -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.UserWithInfoVo -import top.fatweb.api.vo.permission.UserWithPasswordRoleInfoVo -import top.fatweb.api.vo.permission.UserWithPowerInfoVo -import top.fatweb.api.vo.permission.UserWithRoleInfoVo +import top.fatweb.oxygen.api.entity.permission.User +import top.fatweb.oxygen.api.param.permission.user.* +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.UserWithInfoVo +import top.fatweb.oxygen.api.vo.permission.UserWithPasswordRoleInfoVo +import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo +import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo /** * User service interface diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt similarity index 89% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt index 63a178d..2bb8916 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper @@ -13,27 +13,27 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional -import top.fatweb.api.annotation.EventLogRecord -import top.fatweb.api.entity.permission.LoginUser -import top.fatweb.api.entity.permission.User -import top.fatweb.api.entity.permission.UserInfo -import top.fatweb.api.entity.system.EventLog -import top.fatweb.api.exception.* -import top.fatweb.api.param.permission.* -import top.fatweb.api.properties.SecurityProperties -import top.fatweb.api.service.api.v1.IAvatarService -import top.fatweb.api.service.permission.IAuthenticationService -import top.fatweb.api.service.permission.IUserInfoService -import top.fatweb.api.service.permission.IUserService -import top.fatweb.api.settings.BaseSettings -import top.fatweb.api.settings.SettingsOperator -import top.fatweb.api.util.JwtUtil -import top.fatweb.api.util.MailUtil -import top.fatweb.api.util.RedisUtil -import top.fatweb.api.util.WebUtil -import top.fatweb.api.vo.permission.LoginVo -import top.fatweb.api.vo.permission.RegisterVo -import top.fatweb.api.vo.permission.TokenVo +import top.fatweb.oxygen.api.annotation.EventLogRecord +import top.fatweb.oxygen.api.entity.permission.LoginUser +import top.fatweb.oxygen.api.entity.permission.User +import top.fatweb.oxygen.api.entity.permission.UserInfo +import top.fatweb.oxygen.api.entity.system.EventLog +import top.fatweb.oxygen.api.exception.* +import top.fatweb.oxygen.api.param.permission.* +import top.fatweb.oxygen.api.properties.SecurityProperties +import top.fatweb.oxygen.api.service.api.v1.IAvatarService +import top.fatweb.oxygen.api.service.permission.IAuthenticationService +import top.fatweb.oxygen.api.service.permission.IUserInfoService +import top.fatweb.oxygen.api.service.permission.IUserService +import top.fatweb.oxygen.api.settings.BaseSettings +import top.fatweb.oxygen.api.settings.SettingsOperator +import top.fatweb.oxygen.api.util.JwtUtil +import top.fatweb.oxygen.api.util.MailUtil +import top.fatweb.oxygen.api.util.RedisUtil +import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.permission.LoginVo +import top.fatweb.oxygen.api.vo.permission.RegisterVo +import top.fatweb.oxygen.api.vo.permission.TokenVo import java.io.StringWriter import java.time.Instant import java.time.LocalDateTime @@ -174,7 +174,10 @@ class AuthenticationServiceImpl( put("ipAddress", ip) put( "retrieveUrl", - SettingsOperator.getAppValue(BaseSettings::retrieveUrl, "http://localhost/retrieve?code=\${retrieveCode}") + SettingsOperator.getAppValue( + BaseSettings::retrieveUrl, + "http://localhost/retrieve?code=\${retrieveCode}" + ) .replace( Regex("(?<=([^\\\\]))\\$\\{retrieveCode}"), code ) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/FuncServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/FuncServiceImpl.kt similarity index 62% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/FuncServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/FuncServiceImpl.kt index e46d5eb..cbfbba6 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/FuncServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/FuncServiceImpl.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import top.fatweb.api.entity.permission.Func -import top.fatweb.api.mapper.permission.FuncMapper -import top.fatweb.api.service.permission.IFuncService +import top.fatweb.oxygen.api.entity.permission.Func +import top.fatweb.oxygen.api.mapper.permission.FuncMapper +import top.fatweb.oxygen.api.service.permission.IFuncService /** * Function service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/GroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt similarity index 85% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/GroupServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt index 63a9781..ae197c4 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/GroupServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt @@ -1,24 +1,24 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional -import top.fatweb.api.converter.permission.GroupConverter -import top.fatweb.api.entity.permission.Group -import top.fatweb.api.entity.permission.RoleGroup -import top.fatweb.api.mapper.permission.GroupMapper -import top.fatweb.api.param.permission.group.* -import top.fatweb.api.service.permission.IGroupService -import top.fatweb.api.service.permission.IRoleGroupService -import top.fatweb.api.service.permission.IUserService -import top.fatweb.api.util.PageUtil -import top.fatweb.api.util.RedisUtil -import top.fatweb.api.util.WebUtil -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.base.GroupVo -import top.fatweb.api.vo.permission.GroupWithRoleVo +import top.fatweb.oxygen.api.converter.permission.GroupConverter +import top.fatweb.oxygen.api.entity.permission.Group +import top.fatweb.oxygen.api.entity.permission.RoleGroup +import top.fatweb.oxygen.api.mapper.permission.GroupMapper +import top.fatweb.oxygen.api.param.permission.group.* +import top.fatweb.oxygen.api.service.permission.IGroupService +import top.fatweb.oxygen.api.service.permission.IRoleGroupService +import top.fatweb.oxygen.api.service.permission.IUserService +import top.fatweb.oxygen.api.util.PageUtil +import top.fatweb.oxygen.api.util.RedisUtil +import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.GroupWithRoleVo +import top.fatweb.oxygen.api.vo.permission.base.GroupVo /** * Group service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/MenuServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/MenuServiceImpl.kt similarity index 61% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/MenuServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/MenuServiceImpl.kt index d4de1e0..3c85e99 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/MenuServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/MenuServiceImpl.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import top.fatweb.api.entity.permission.Menu -import top.fatweb.api.mapper.permission.MenuMapper -import top.fatweb.api.service.permission.IMenuService +import top.fatweb.oxygen.api.entity.permission.Menu +import top.fatweb.oxygen.api.mapper.permission.MenuMapper +import top.fatweb.oxygen.api.service.permission.IMenuService /** * Menu service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/ModuleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/ModuleServiceImpl.kt similarity index 62% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/ModuleServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/ModuleServiceImpl.kt index ef2a479..23f0886 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/ModuleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/ModuleServiceImpl.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import top.fatweb.api.entity.permission.Module -import top.fatweb.api.mapper.permission.ModuleMapper -import top.fatweb.api.service.permission.IModuleService +import top.fatweb.oxygen.api.entity.permission.Module +import top.fatweb.oxygen.api.mapper.permission.ModuleMapper +import top.fatweb.oxygen.api.service.permission.IModuleService /** * Module service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/OperationServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/OperationServiceImpl.kt similarity index 62% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/OperationServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/OperationServiceImpl.kt index e331784..241efa9 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/OperationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/OperationServiceImpl.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import top.fatweb.api.entity.permission.Operation -import top.fatweb.api.mapper.permission.OperationMapper -import top.fatweb.api.service.permission.IOperationService +import top.fatweb.oxygen.api.entity.permission.Operation +import top.fatweb.oxygen.api.mapper.permission.OperationMapper +import top.fatweb.oxygen.api.service.permission.IOperationService /** * Operation service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerRoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/PowerRoleServiceImpl.kt similarity index 63% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/PowerRoleServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/PowerRoleServiceImpl.kt index 89e2f1f..5fa9d70 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerRoleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/PowerRoleServiceImpl.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import top.fatweb.api.entity.permission.PowerRole -import top.fatweb.api.mapper.permission.PowerRoleMapper -import top.fatweb.api.service.permission.IPowerRoleService +import top.fatweb.oxygen.api.entity.permission.PowerRole +import top.fatweb.oxygen.api.mapper.permission.PowerRoleMapper +import top.fatweb.oxygen.api.service.permission.IPowerRoleService /** * Power role intermediate service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/PowerServiceImpl.kt similarity index 73% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/PowerServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/PowerServiceImpl.kt index 4fca03a..d709f72 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/PowerServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/PowerServiceImpl.kt @@ -1,12 +1,12 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import top.fatweb.api.converter.permission.PowerConverter -import top.fatweb.api.entity.permission.Power -import top.fatweb.api.entity.permission.PowerSet -import top.fatweb.api.mapper.permission.PowerMapper -import top.fatweb.api.service.permission.* +import top.fatweb.oxygen.api.converter.permission.PowerConverter +import top.fatweb.oxygen.api.entity.permission.Power +import top.fatweb.oxygen.api.entity.permission.PowerSet +import top.fatweb.oxygen.api.mapper.permission.PowerMapper +import top.fatweb.oxygen.api.service.permission.* /** * Power service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleGroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleGroupServiceImpl.kt similarity index 63% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/RoleGroupServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleGroupServiceImpl.kt index 5d4e947..897614c 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleGroupServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleGroupServiceImpl.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import top.fatweb.api.entity.permission.RoleGroup -import top.fatweb.api.mapper.permission.RoleGroupMapper -import top.fatweb.api.service.permission.IRoleGroupService +import top.fatweb.oxygen.api.entity.permission.RoleGroup +import top.fatweb.oxygen.api.mapper.permission.RoleGroupMapper +import top.fatweb.oxygen.api.service.permission.IRoleGroupService /** * Role group intermediate service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt similarity index 89% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/RoleServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt index db077d6..ea8a5b6 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt @@ -1,22 +1,22 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional -import top.fatweb.api.converter.permission.RoleConverter -import top.fatweb.api.entity.permission.PowerRole -import top.fatweb.api.entity.permission.Role -import top.fatweb.api.mapper.permission.RoleMapper -import top.fatweb.api.param.permission.role.* -import top.fatweb.api.service.permission.* -import top.fatweb.api.util.PageUtil -import top.fatweb.api.util.RedisUtil -import top.fatweb.api.util.WebUtil -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.base.RoleVo -import top.fatweb.api.vo.permission.RoleWithPowerVo +import top.fatweb.oxygen.api.converter.permission.RoleConverter +import top.fatweb.oxygen.api.entity.permission.PowerRole +import top.fatweb.oxygen.api.entity.permission.Role +import top.fatweb.oxygen.api.mapper.permission.RoleMapper +import top.fatweb.oxygen.api.param.permission.role.* +import top.fatweb.oxygen.api.service.permission.* +import top.fatweb.oxygen.api.util.PageUtil +import top.fatweb.oxygen.api.util.RedisUtil +import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.RoleWithPowerVo +import top.fatweb.oxygen.api.vo.permission.base.RoleVo /** * Role service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserDetailsServiceImpl.kt similarity index 79% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserDetailsServiceImpl.kt index f92d344..9aa4351 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserDetailsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserDetailsServiceImpl.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import org.springframework.security.core.userdetails.UserDetails import org.springframework.security.core.userdetails.UserDetailsService import org.springframework.stereotype.Service -import top.fatweb.api.entity.permission.LoginUser -import top.fatweb.api.service.permission.IUserService +import top.fatweb.oxygen.api.entity.permission.LoginUser +import top.fatweb.oxygen.api.service.permission.IUserService /** * User details service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserGroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserGroupServiceImpl.kt similarity index 63% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/UserGroupServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserGroupServiceImpl.kt index 30432eb..5664ba4 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserGroupServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserGroupServiceImpl.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import top.fatweb.api.entity.permission.UserGroup -import top.fatweb.api.mapper.permission.UserGroupMapper -import top.fatweb.api.service.permission.IUserGroupService +import top.fatweb.oxygen.api.entity.permission.UserGroup +import top.fatweb.oxygen.api.mapper.permission.UserGroupMapper +import top.fatweb.oxygen.api.service.permission.IUserGroupService /** * User group intermediate service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserInfoServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserInfoServiceImpl.kt similarity index 62% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/UserInfoServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserInfoServiceImpl.kt index fce770a..c9ceb1e 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserInfoServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserInfoServiceImpl.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import top.fatweb.api.entity.permission.UserInfo -import top.fatweb.api.mapper.permission.UserInfoMapper -import top.fatweb.api.service.permission.IUserInfoService +import top.fatweb.oxygen.api.entity.permission.UserInfo +import top.fatweb.oxygen.api.mapper.permission.UserInfoMapper +import top.fatweb.oxygen.api.service.permission.IUserInfoService /** * User information service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserRoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserRoleServiceImpl.kt similarity index 62% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/UserRoleServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserRoleServiceImpl.kt index ebe3d9d..b42ba8b 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserRoleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserRoleServiceImpl.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import top.fatweb.api.entity.permission.UserRole -import top.fatweb.api.mapper.permission.UserRoleMapper -import top.fatweb.api.service.permission.IUserRoleService +import top.fatweb.oxygen.api.entity.permission.UserRole +import top.fatweb.oxygen.api.mapper.permission.UserRoleMapper +import top.fatweb.oxygen.api.service.permission.IUserRoleService /** * User role intermediate service implement diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt similarity index 91% rename from src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt index e8c57bd..6a8595e 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.service.permission.impl +package top.fatweb.oxygen.api.service.permission.impl import com.baomidou.dynamic.datasource.annotation.DS import com.baomidou.mybatisplus.core.metadata.OrderItem @@ -10,22 +10,22 @@ import org.springframework.security.access.AccessDeniedException import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional -import top.fatweb.api.converter.permission.UserConverter -import top.fatweb.api.entity.permission.User -import top.fatweb.api.entity.permission.UserGroup -import top.fatweb.api.entity.permission.UserInfo -import top.fatweb.api.entity.permission.UserRole -import top.fatweb.api.exception.NoRecordFoundException -import top.fatweb.api.mapper.permission.UserMapper -import top.fatweb.api.param.permission.user.* -import top.fatweb.api.service.permission.* -import top.fatweb.api.util.PageUtil -import top.fatweb.api.util.RedisUtil -import top.fatweb.api.util.StrUtil -import top.fatweb.api.util.WebUtil -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.permission.UserWithPasswordRoleInfoVo -import top.fatweb.api.vo.permission.UserWithRoleInfoVo +import top.fatweb.oxygen.api.converter.permission.UserConverter +import top.fatweb.oxygen.api.entity.permission.User +import top.fatweb.oxygen.api.entity.permission.UserGroup +import top.fatweb.oxygen.api.entity.permission.UserInfo +import top.fatweb.oxygen.api.entity.permission.UserRole +import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.mapper.permission.UserMapper +import top.fatweb.oxygen.api.param.permission.user.* +import top.fatweb.oxygen.api.service.permission.* +import top.fatweb.oxygen.api.util.PageUtil +import top.fatweb.oxygen.api.util.RedisUtil +import top.fatweb.oxygen.api.util.StrUtil +import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.permission.UserWithPasswordRoleInfoVo +import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo import java.time.LocalDateTime import java.time.ZoneOffset import java.util.* diff --git a/src/main/kotlin/top/fatweb/api/service/system/IEventLogService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/IEventLogService.kt similarity index 64% rename from src/main/kotlin/top/fatweb/api/service/system/IEventLogService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/system/IEventLogService.kt index ae45841..9925086 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/IEventLogService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/IEventLogService.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.service.system +package top.fatweb.oxygen.api.service.system import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.annotation.EventLogRecord -import top.fatweb.api.entity.system.EventLog +import top.fatweb.oxygen.api.annotation.EventLogRecord +import top.fatweb.oxygen.api.entity.system.EventLog /** * Event log service interface diff --git a/src/main/kotlin/top/fatweb/api/service/system/ISettingsService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/ISettingsService.kt similarity index 80% rename from src/main/kotlin/top/fatweb/api/service/system/ISettingsService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/system/ISettingsService.kt index 0e8d29d..0e7eee6 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/ISettingsService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/ISettingsService.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.system +package top.fatweb.oxygen.api.service.system -import top.fatweb.api.param.system.BaseSettingsParam -import top.fatweb.api.param.system.MailSendParam -import top.fatweb.api.param.system.MailSettingsParam -import top.fatweb.api.vo.system.BaseSettingsVo -import top.fatweb.api.vo.system.MailSettingsVo +import top.fatweb.oxygen.api.param.system.BaseSettingsParam +import top.fatweb.oxygen.api.param.system.MailSendParam +import top.fatweb.oxygen.api.param.system.MailSettingsParam +import top.fatweb.oxygen.api.vo.system.BaseSettingsVo +import top.fatweb.oxygen.api.vo.system.MailSettingsVo /** * Settings service interface diff --git a/src/main/kotlin/top/fatweb/api/service/system/IStatisticsLogService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/IStatisticsLogService.kt similarity index 68% rename from src/main/kotlin/top/fatweb/api/service/system/IStatisticsLogService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/system/IStatisticsLogService.kt index e6cb5de..571149a 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/IStatisticsLogService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/IStatisticsLogService.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.service.system +package top.fatweb.oxygen.api.service.system import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.system.StatisticsLog +import top.fatweb.oxygen.api.entity.system.StatisticsLog /** * Statistics log service interface diff --git a/src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/IStatisticsService.kt similarity index 87% rename from src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/system/IStatisticsService.kt index b28ee1d..c698c8d 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/IStatisticsService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/IStatisticsService.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.service.system +package top.fatweb.oxygen.api.service.system -import top.fatweb.api.param.system.ActiveInfoGetParam -import top.fatweb.api.param.system.OnlineInfoGetParam -import top.fatweb.api.vo.system.* +import top.fatweb.oxygen.api.param.system.ActiveInfoGetParam +import top.fatweb.oxygen.api.param.system.OnlineInfoGetParam +import top.fatweb.oxygen.api.vo.system.* /** * Statistics service interface @@ -50,7 +50,7 @@ interface IStatisticsService { * @see StorageInfoVo */ fun storage(): StorageInfoVo - + /** * Get the history of online users information * diff --git a/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/ISysLogService.kt similarity index 71% rename from src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/system/ISysLogService.kt index 034450d..16430ca 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/ISysLogService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/ISysLogService.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.service.system +package top.fatweb.oxygen.api.service.system import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.api.entity.system.SysLog -import top.fatweb.api.param.system.SysLogGetParam -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.system.SysLogVo +import top.fatweb.oxygen.api.entity.system.SysLog +import top.fatweb.oxygen.api.param.system.SysLogGetParam +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.system.SysLogVo /** * System log service interface diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/EventLogServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/EventLogServiceImpl.kt similarity index 77% rename from src/main/kotlin/top/fatweb/api/service/system/impl/EventLogServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/EventLogServiceImpl.kt index 0f7e7a2..845b1b6 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/EventLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/EventLogServiceImpl.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.service.system.impl +package top.fatweb.oxygen.api.service.system.impl import com.baomidou.dynamic.datasource.annotation.DS import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl @@ -7,10 +7,10 @@ import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Propagation import org.springframework.transaction.annotation.Transactional -import top.fatweb.api.annotation.EventLogRecord -import top.fatweb.api.entity.system.EventLog -import top.fatweb.api.mapper.system.EventLogMapper -import top.fatweb.api.service.system.IEventLogService +import top.fatweb.oxygen.api.annotation.EventLogRecord +import top.fatweb.oxygen.api.entity.system.EventLog +import top.fatweb.oxygen.api.mapper.system.EventLogMapper +import top.fatweb.oxygen.api.service.system.IEventLogService @DS("sqlite") @Service diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/SettingsServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt similarity index 80% rename from src/main/kotlin/top/fatweb/api/service/system/impl/SettingsServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt index 6a1da9c..c107aa4 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/SettingsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt @@ -1,18 +1,18 @@ -package top.fatweb.api.service.system.impl +package top.fatweb.oxygen.api.service.system.impl import org.springframework.stereotype.Service -import top.fatweb.api.param.system.BaseSettingsParam -import top.fatweb.api.param.system.MailSendParam -import top.fatweb.api.param.system.MailSettingsParam -import top.fatweb.api.properties.ServerProperties -import top.fatweb.api.service.system.ISettingsService -import top.fatweb.api.settings.BaseSettings -import top.fatweb.api.settings.MailSettings -import top.fatweb.api.settings.SettingsOperator -import top.fatweb.api.util.MailUtil -import top.fatweb.api.util.StrUtil -import top.fatweb.api.vo.system.BaseSettingsVo -import top.fatweb.api.vo.system.MailSettingsVo +import top.fatweb.oxygen.api.param.system.BaseSettingsParam +import top.fatweb.oxygen.api.param.system.MailSendParam +import top.fatweb.oxygen.api.param.system.MailSettingsParam +import top.fatweb.oxygen.api.properties.ServerProperties +import top.fatweb.oxygen.api.service.system.ISettingsService +import top.fatweb.oxygen.api.settings.BaseSettings +import top.fatweb.oxygen.api.settings.MailSettings +import top.fatweb.oxygen.api.settings.SettingsOperator +import top.fatweb.oxygen.api.util.MailUtil +import top.fatweb.oxygen.api.util.StrUtil +import top.fatweb.oxygen.api.vo.system.BaseSettingsVo +import top.fatweb.oxygen.api.vo.system.MailSettingsVo /** * Settings service implement diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsLogServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsLogServiceImpl.kt similarity index 55% rename from src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsLogServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsLogServiceImpl.kt index 212ceee..ada1265 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsLogServiceImpl.kt @@ -1,11 +1,11 @@ -package top.fatweb.api.service.system.impl +package top.fatweb.oxygen.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 +import top.fatweb.oxygen.api.entity.system.StatisticsLog +import top.fatweb.oxygen.api.mapper.system.StatisticsLogMapper +import top.fatweb.oxygen.api.service.system.IStatisticsLogService @DS("sqlite") @Service diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsServiceImpl.kt similarity index 92% rename from src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsServiceImpl.kt index 4100a69..e6394f8 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/StatisticsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsServiceImpl.kt @@ -1,22 +1,22 @@ -package top.fatweb.api.service.system.impl +package top.fatweb.oxygen.api.service.system.impl import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper 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.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.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.* +import top.fatweb.oxygen.api.entity.system.EventLog +import top.fatweb.oxygen.api.entity.system.StatisticsLog +import top.fatweb.oxygen.api.param.system.ActiveInfoGetParam +import top.fatweb.oxygen.api.param.system.OnlineInfoGetParam +import top.fatweb.oxygen.api.properties.SecurityProperties +import top.fatweb.oxygen.api.properties.ServerProperties +import top.fatweb.oxygen.api.service.system.IEventLogService +import top.fatweb.oxygen.api.service.system.IStatisticsLogService +import top.fatweb.oxygen.api.service.system.IStatisticsService +import top.fatweb.oxygen.api.util.ByteUtil +import top.fatweb.oxygen.api.util.RedisUtil +import top.fatweb.oxygen.api.vo.system.* import java.time.LocalDate import java.time.LocalDateTime import java.time.ZoneOffset @@ -190,7 +190,7 @@ class StatisticsServiceImpl( return OnlineInfoVo( current = redisUtil.keys("${SecurityProperties.jwtIssuer}_login_*") - .distinctBy { Regex("FatWeb_login_(.*):.*").matchEntire(it)?.groupValues?.getOrNull(1) }.size.toLong(), + .distinctBy { Regex("${SecurityProperties.jwtIssuer}_login_(.*):.*").matchEntire(it)?.groupValues?.getOrNull(1) }.size.toLong(), history = history ) } diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SysLogServiceImpl.kt similarity index 67% rename from src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SysLogServiceImpl.kt index 6f596a9..2ad005f 100644 --- a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SysLogServiceImpl.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.service.system.impl +package top.fatweb.oxygen.api.service.system.impl import com.baomidou.dynamic.datasource.annotation.DS import com.baomidou.mybatisplus.core.metadata.OrderItem @@ -6,16 +6,16 @@ import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import top.fatweb.api.converter.system.SysLogConverter -import top.fatweb.api.entity.permission.User -import top.fatweb.api.entity.system.SysLog -import top.fatweb.api.mapper.system.SysLogMapper -import top.fatweb.api.param.system.SysLogGetParam -import top.fatweb.api.service.permission.IUserService -import top.fatweb.api.service.system.ISysLogService -import top.fatweb.api.util.PageUtil -import top.fatweb.api.vo.PageVo -import top.fatweb.api.vo.system.SysLogVo +import top.fatweb.oxygen.api.converter.system.SysLogConverter +import top.fatweb.oxygen.api.entity.permission.User +import top.fatweb.oxygen.api.entity.system.SysLog +import top.fatweb.oxygen.api.mapper.system.SysLogMapper +import top.fatweb.oxygen.api.param.system.SysLogGetParam +import top.fatweb.oxygen.api.service.permission.IUserService +import top.fatweb.oxygen.api.service.system.ISysLogService +import top.fatweb.oxygen.api.util.PageUtil +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.system.SysLogVo /** * System log service implement @@ -52,13 +52,14 @@ class SysLogServiceImpl( if (sysLogIPage.records.isNotEmpty()) { val userIds = sysLogIPage.records.map { it.operateUserId } - userService.list(KtQueryWrapper(User()).select(User::id, User::username).`in`(User::id, userIds)).forEach { user -> - sysLogIPage.records.forEach { - if (it.operateUserId == user.id) { - it.operateUsername = user.username + userService.list(KtQueryWrapper(User()).select(User::id, User::username).`in`(User::id, userIds)) + .forEach { user -> + sysLogIPage.records.forEach { + if (it.operateUserId == user.id) { + it.operateUsername = user.username + } } } - } } return SysLogConverter.sysLogPageToSysLogPageVo(sysLogIPage) diff --git a/src/main/kotlin/top/fatweb/api/settings/BaseSettings.kt b/src/main/kotlin/top/fatweb/oxygen/api/settings/BaseSettings.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/settings/BaseSettings.kt rename to src/main/kotlin/top/fatweb/oxygen/api/settings/BaseSettings.kt index b1479db..4de70bf 100644 --- a/src/main/kotlin/top/fatweb/api/settings/BaseSettings.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/settings/BaseSettings.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.settings +package top.fatweb.oxygen.api.settings import com.fasterxml.jackson.annotation.JsonInclude diff --git a/src/main/kotlin/top/fatweb/api/settings/MailSecurityType.kt b/src/main/kotlin/top/fatweb/oxygen/api/settings/MailSecurityType.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/settings/MailSecurityType.kt rename to src/main/kotlin/top/fatweb/oxygen/api/settings/MailSecurityType.kt index 7b2666d..ede4118 100644 --- a/src/main/kotlin/top/fatweb/api/settings/MailSecurityType.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/settings/MailSecurityType.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.settings +package top.fatweb.oxygen.api.settings import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonValue diff --git a/src/main/kotlin/top/fatweb/api/settings/MailSettings.kt b/src/main/kotlin/top/fatweb/oxygen/api/settings/MailSettings.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/settings/MailSettings.kt rename to src/main/kotlin/top/fatweb/oxygen/api/settings/MailSettings.kt index 4c0c0f2..5c2fa27 100644 --- a/src/main/kotlin/top/fatweb/api/settings/MailSettings.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/settings/MailSettings.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.settings +package top.fatweb.oxygen.api.settings import com.fasterxml.jackson.annotation.JsonInclude diff --git a/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt b/src/main/kotlin/top/fatweb/oxygen/api/settings/SettingsOperator.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt rename to src/main/kotlin/top/fatweb/oxygen/api/settings/SettingsOperator.kt index 8f346a9..7388b72 100644 --- a/src/main/kotlin/top/fatweb/api/settings/SettingsOperator.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/settings/SettingsOperator.kt @@ -1,9 +1,9 @@ -package top.fatweb.api.settings +package top.fatweb.oxygen.api.settings import com.fasterxml.jackson.databind.exc.MismatchedInputException import com.fasterxml.jackson.dataformat.yaml.YAMLMapper import com.fasterxml.jackson.module.kotlin.readValue -import top.fatweb.api.util.StrUtil +import top.fatweb.oxygen.api.util.StrUtil import java.io.File import java.io.IOException import kotlin.reflect.KMutableProperty1 @@ -114,7 +114,8 @@ object SettingsOperator { * @see KMutableProperty1 * @see BaseSettings */ - fun getAppValue(field: KMutableProperty1, default: V): V = systemSettings.base?.let(field) ?: default + fun getAppValue(field: KMutableProperty1, default: V): V = + systemSettings.base?.let(field) ?: default /** * Set mail settings value @@ -166,5 +167,6 @@ object SettingsOperator { * @see KMutableProperty1 * @see MailSettings */ - fun getMailValue(field: KMutableProperty1, default: V): V = systemSettings.mail?.let(field) ?: default + fun getMailValue(field: KMutableProperty1, default: V): V = + systemSettings.mail?.let(field) ?: default } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/settings/SystemSettings.kt b/src/main/kotlin/top/fatweb/oxygen/api/settings/SystemSettings.kt similarity index 92% rename from src/main/kotlin/top/fatweb/api/settings/SystemSettings.kt rename to src/main/kotlin/top/fatweb/oxygen/api/settings/SystemSettings.kt index d186a21..b15a9f7 100644 --- a/src/main/kotlin/top/fatweb/api/settings/SystemSettings.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/settings/SystemSettings.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.settings +package top.fatweb.oxygen.api.settings import com.fasterxml.jackson.annotation.JsonInclude diff --git a/src/main/kotlin/top/fatweb/api/util/ApiResponseMappingHandlerMapping.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/ApiResponseMappingHandlerMapping.kt similarity index 90% rename from src/main/kotlin/top/fatweb/api/util/ApiResponseMappingHandlerMapping.kt rename to src/main/kotlin/top/fatweb/oxygen/api/util/ApiResponseMappingHandlerMapping.kt index df7c23c..03f2bda 100644 --- a/src/main/kotlin/top/fatweb/api/util/ApiResponseMappingHandlerMapping.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/ApiResponseMappingHandlerMapping.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.util +package top.fatweb.oxygen.api.util import org.springframework.web.servlet.mvc.condition.RequestCondition import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping -import top.fatweb.api.annotation.ApiController +import top.fatweb.oxygen.api.annotation.ApiController import java.lang.reflect.Method /** diff --git a/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/ApiVersionCondition.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt rename to src/main/kotlin/top/fatweb/oxygen/api/util/ApiVersionCondition.kt index b5a4a83..90411cf 100644 --- a/src/main/kotlin/top/fatweb/api/util/ApiVersionCondition.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/ApiVersionCondition.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.util +package top.fatweb.oxygen.api.util import jakarta.servlet.http.HttpServletRequest import org.springframework.web.servlet.mvc.condition.RequestCondition diff --git a/src/main/kotlin/top/fatweb/api/util/ByteUtil.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/ByteUtil.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/util/ByteUtil.kt rename to src/main/kotlin/top/fatweb/oxygen/api/util/ByteUtil.kt index 5e2747a..c18a46e 100644 --- a/src/main/kotlin/top/fatweb/api/util/ByteUtil.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/ByteUtil.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.util +package top.fatweb.oxygen.api.util import kotlin.math.floor diff --git a/src/main/kotlin/top/fatweb/api/util/JwtUtil.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/JwtUtil.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/util/JwtUtil.kt rename to src/main/kotlin/top/fatweb/oxygen/api/util/JwtUtil.kt index 5d78472..a831d5f 100644 --- a/src/main/kotlin/top/fatweb/api/util/JwtUtil.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/JwtUtil.kt @@ -1,9 +1,9 @@ -package top.fatweb.api.util +package top.fatweb.oxygen.api.util import com.auth0.jwt.JWT import com.auth0.jwt.algorithms.Algorithm import com.auth0.jwt.interfaces.DecodedJWT -import top.fatweb.api.properties.SecurityProperties +import top.fatweb.oxygen.api.properties.SecurityProperties import java.util.* import java.util.concurrent.TimeUnit import javax.crypto.spec.SecretKeySpec diff --git a/src/main/kotlin/top/fatweb/api/util/MailUtil.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/MailUtil.kt similarity index 88% rename from src/main/kotlin/top/fatweb/api/util/MailUtil.kt rename to src/main/kotlin/top/fatweb/oxygen/api/util/MailUtil.kt index bf1ba4a..d89d02c 100644 --- a/src/main/kotlin/top/fatweb/api/util/MailUtil.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/MailUtil.kt @@ -1,11 +1,11 @@ -package top.fatweb.api.util +package top.fatweb.oxygen.api.util import org.springframework.mail.javamail.JavaMailSenderImpl import org.springframework.mail.javamail.MimeMessageHelper -import top.fatweb.api.exception.NoEmailConfigException -import top.fatweb.api.settings.MailSecurityType -import top.fatweb.api.settings.MailSettings -import top.fatweb.api.settings.SettingsOperator +import top.fatweb.oxygen.api.exception.NoEmailConfigException +import top.fatweb.oxygen.api.settings.MailSecurityType +import top.fatweb.oxygen.api.settings.MailSettings +import top.fatweb.oxygen.api.settings.SettingsOperator import java.util.* /** diff --git a/src/main/kotlin/top/fatweb/api/util/NumberUtil.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/NumberUtil.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/util/NumberUtil.kt rename to src/main/kotlin/top/fatweb/oxygen/api/util/NumberUtil.kt index 41bb694..48db483 100644 --- a/src/main/kotlin/top/fatweb/api/util/NumberUtil.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/NumberUtil.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.util +package top.fatweb.oxygen.api.util /** * Number util diff --git a/src/main/kotlin/top/fatweb/api/util/PageUtil.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/PageUtil.kt similarity index 85% rename from src/main/kotlin/top/fatweb/api/util/PageUtil.kt rename to src/main/kotlin/top/fatweb/oxygen/api/util/PageUtil.kt index c785e09..4de5005 100644 --- a/src/main/kotlin/top/fatweb/api/util/PageUtil.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/PageUtil.kt @@ -1,8 +1,8 @@ -package top.fatweb.api.util +package top.fatweb.oxygen.api.util import com.baomidou.mybatisplus.core.metadata.OrderItem import com.baomidou.mybatisplus.extension.plugins.pagination.Page -import top.fatweb.api.param.PageSortParam +import top.fatweb.oxygen.api.param.PageSortParam /** * Page util @@ -23,7 +23,7 @@ object PageUtil { * @see PageSortParam * @see OrderItem */ - fun > setPageSort(pageSortParam: PageSortParam?, page: T, defaultOrder: OrderItem? = null) { + fun > setPageSort(pageSortParam: PageSortParam?, page: T, defaultOrder: OrderItem? = null) { if (pageSortParam?.sortField != null || pageSortParam?.sortOrder != null) { page.addOrder( if (pageSortParam.sortOrder?.startsWith( diff --git a/src/main/kotlin/top/fatweb/api/util/RedisUtil.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/RedisUtil.kt similarity index 99% rename from src/main/kotlin/top/fatweb/api/util/RedisUtil.kt rename to src/main/kotlin/top/fatweb/oxygen/api/util/RedisUtil.kt index 784fc1b..67dd99e 100644 --- a/src/main/kotlin/top/fatweb/api/util/RedisUtil.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/RedisUtil.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.util +package top.fatweb.oxygen.api.util import org.springframework.data.redis.core.BoundSetOperations import org.springframework.data.redis.core.RedisTemplate diff --git a/src/main/kotlin/top/fatweb/api/util/StrUtil.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/StrUtil.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/util/StrUtil.kt rename to src/main/kotlin/top/fatweb/oxygen/api/util/StrUtil.kt index e9787cd..bb356ad 100644 --- a/src/main/kotlin/top/fatweb/api/util/StrUtil.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/StrUtil.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.util +package top.fatweb.oxygen.api.util import java.security.MessageDigest diff --git a/src/main/kotlin/top/fatweb/api/util/WebUtil.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/WebUtil.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/util/WebUtil.kt rename to src/main/kotlin/top/fatweb/oxygen/api/util/WebUtil.kt index 9fb1432..4e0838c 100644 --- a/src/main/kotlin/top/fatweb/api/util/WebUtil.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/WebUtil.kt @@ -1,9 +1,9 @@ -package top.fatweb.api.util +package top.fatweb.oxygen.api.util import jakarta.servlet.http.HttpServletRequest import org.springframework.security.core.context.SecurityContextHolder -import top.fatweb.api.entity.permission.LoginUser -import top.fatweb.api.properties.SecurityProperties +import top.fatweb.oxygen.api.entity.permission.LoginUser +import top.fatweb.oxygen.api.properties.SecurityProperties /** * Web util diff --git a/src/main/kotlin/top/fatweb/api/vo/PageVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/PageVo.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/vo/PageVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/PageVo.kt index 2f20efd..3990b58 100644 --- a/src/main/kotlin/top/fatweb/api/vo/PageVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/PageVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo +package top.fatweb.oxygen.api.vo import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/api/v1/avatar/AvatarBase64Vo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/api/v1/avatar/AvatarBase64Vo.kt similarity index 89% rename from src/main/kotlin/top/fatweb/api/vo/api/v1/avatar/AvatarBase64Vo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/api/v1/avatar/AvatarBase64Vo.kt index 9266517..34bb7bd 100644 --- a/src/main/kotlin/top/fatweb/api/vo/api/v1/avatar/AvatarBase64Vo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/api/v1/avatar/AvatarBase64Vo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.api.v1.avatar +package top.fatweb.oxygen.api.vo.api.v1.avatar import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/GroupWithRoleVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/GroupWithRoleVo.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/vo/permission/GroupWithRoleVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/GroupWithRoleVo.kt index 7675cbf..7d5c28b 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/GroupWithRoleVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/GroupWithRoleVo.kt @@ -1,9 +1,9 @@ -package top.fatweb.api.vo.permission +package top.fatweb.oxygen.api.vo.permission import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.vo.permission.base.RoleVo +import top.fatweb.oxygen.api.vo.permission.base.RoleVo import java.time.LocalDateTime /** diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/LoginVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/LoginVo.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/vo/permission/LoginVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/LoginVo.kt index 8b130eb..b49a3fd 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/LoginVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/LoginVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.permission +package top.fatweb.oxygen.api.vo.permission import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/PowerSetVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/PowerSetVo.kt similarity index 80% rename from src/main/kotlin/top/fatweb/api/vo/permission/PowerSetVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/PowerSetVo.kt index 270c800..b3be209 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/PowerSetVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/PowerSetVo.kt @@ -1,10 +1,10 @@ -package top.fatweb.api.vo.permission +package top.fatweb.oxygen.api.vo.permission import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.vo.permission.base.FuncVo -import top.fatweb.api.vo.permission.base.MenuVo -import top.fatweb.api.vo.permission.base.ModuleVo -import top.fatweb.api.vo.permission.base.OperationVo +import top.fatweb.oxygen.api.vo.permission.base.FuncVo +import top.fatweb.oxygen.api.vo.permission.base.MenuVo +import top.fatweb.oxygen.api.vo.permission.base.ModuleVo +import top.fatweb.oxygen.api.vo.permission.base.OperationVo /** * Set of power value object diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/RegisterVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/RegisterVo.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/vo/permission/RegisterVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/RegisterVo.kt index 7561b0e..c33581b 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/RegisterVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/RegisterVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.permission +package top.fatweb.oxygen.api.vo.permission import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/RoleWithPowerVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/RoleWithPowerVo.kt similarity index 89% rename from src/main/kotlin/top/fatweb/api/vo/permission/RoleWithPowerVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/RoleWithPowerVo.kt index 3b072ce..d86b0cb 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/RoleWithPowerVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/RoleWithPowerVo.kt @@ -1,12 +1,12 @@ -package top.fatweb.api.vo.permission +package top.fatweb.oxygen.api.vo.permission import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.vo.permission.base.FuncVo -import top.fatweb.api.vo.permission.base.MenuVo -import top.fatweb.api.vo.permission.base.ModuleVo -import top.fatweb.api.vo.permission.base.OperationVo +import top.fatweb.oxygen.api.vo.permission.base.FuncVo +import top.fatweb.oxygen.api.vo.permission.base.MenuVo +import top.fatweb.oxygen.api.vo.permission.base.ModuleVo +import top.fatweb.oxygen.api.vo.permission.base.OperationVo import java.time.LocalDateTime /** diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/TokenVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/TokenVo.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/vo/permission/TokenVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/TokenVo.kt index 7e1b501..669ea6e 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/TokenVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/TokenVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.permission +package top.fatweb.oxygen.api.vo.permission import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/UserWithInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithInfoVo.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/vo/permission/UserWithInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithInfoVo.kt index fc55b20..f1f14f7 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/UserWithInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithInfoVo.kt @@ -1,9 +1,9 @@ -package top.fatweb.api.vo.permission +package top.fatweb.oxygen.api.vo.permission import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.vo.permission.base.UserInfoVo +import top.fatweb.oxygen.api.vo.permission.base.UserInfoVo import java.time.LocalDateTime /** diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/UserWithPasswordRoleInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithPasswordRoleInfoVo.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/vo/permission/UserWithPasswordRoleInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithPasswordRoleInfoVo.kt index 0fdc030..945bbdd 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/UserWithPasswordRoleInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithPasswordRoleInfoVo.kt @@ -1,11 +1,11 @@ -package top.fatweb.api.vo.permission +package top.fatweb.oxygen.api.vo.permission import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.vo.permission.base.GroupVo -import top.fatweb.api.vo.permission.base.RoleVo -import top.fatweb.api.vo.permission.base.UserInfoVo +import top.fatweb.oxygen.api.vo.permission.base.GroupVo +import top.fatweb.oxygen.api.vo.permission.base.RoleVo +import top.fatweb.oxygen.api.vo.permission.base.UserInfoVo import java.time.LocalDateTime /** diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/UserWithPowerInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithPowerInfoVo.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/vo/permission/UserWithPowerInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithPowerInfoVo.kt index c8409c8..7fd460c 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/UserWithPowerInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithPowerInfoVo.kt @@ -1,9 +1,9 @@ -package top.fatweb.api.vo.permission +package top.fatweb.oxygen.api.vo.permission import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.vo.permission.base.* +import top.fatweb.oxygen.api.vo.permission.base.* import java.time.LocalDateTime /** diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/UserWithRoleInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithRoleInfoVo.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/vo/permission/UserWithRoleInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithRoleInfoVo.kt index 9f6b115..edc69db 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/UserWithRoleInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithRoleInfoVo.kt @@ -1,11 +1,11 @@ -package top.fatweb.api.vo.permission +package top.fatweb.oxygen.api.vo.permission import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.vo.permission.base.GroupVo -import top.fatweb.api.vo.permission.base.RoleVo -import top.fatweb.api.vo.permission.base.UserInfoVo +import top.fatweb.oxygen.api.vo.permission.base.GroupVo +import top.fatweb.oxygen.api.vo.permission.base.RoleVo +import top.fatweb.oxygen.api.vo.permission.base.UserInfoVo import java.time.LocalDateTime /** diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/base/FuncVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/FuncVo.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/vo/permission/base/FuncVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/FuncVo.kt index 1e859ee..656723f 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/base/FuncVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/FuncVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.permission.base +package top.fatweb.oxygen.api.vo.permission.base import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/base/GroupVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/GroupVo.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/vo/permission/base/GroupVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/GroupVo.kt index 98baf46..2e3da98 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/base/GroupVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/GroupVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.permission.base +package top.fatweb.oxygen.api.vo.permission.base import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/base/MenuVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/MenuVo.kt similarity index 95% rename from src/main/kotlin/top/fatweb/api/vo/permission/base/MenuVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/MenuVo.kt index 7fb3b84..78b26bc 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/base/MenuVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/MenuVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.permission.base +package top.fatweb.oxygen.api.vo.permission.base import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/base/ModuleVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/ModuleVo.kt similarity index 91% rename from src/main/kotlin/top/fatweb/api/vo/permission/base/ModuleVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/ModuleVo.kt index a3d7fbe..2bb4af0 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/base/ModuleVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/ModuleVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.permission.base +package top.fatweb.oxygen.api.vo.permission.base import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/base/OperationVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/OperationVo.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/vo/permission/base/OperationVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/OperationVo.kt index 0221c52..cb28ebb 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/base/OperationVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/OperationVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.permission.base +package top.fatweb.oxygen.api.vo.permission.base import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/base/RoleVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/RoleVo.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/vo/permission/base/RoleVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/RoleVo.kt index ffe5e60..2bcd01d 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/base/RoleVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/RoleVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.permission.base +package top.fatweb.oxygen.api.vo.permission.base import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/base/UserInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/UserInfoVo.kt similarity index 94% rename from src/main/kotlin/top/fatweb/api/vo/permission/base/UserInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/UserInfoVo.kt index d3721b5..a6edbb8 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/base/UserInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/base/UserInfoVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.permission.base +package top.fatweb.oxygen.api.vo.permission.base import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer @@ -56,7 +56,7 @@ data class UserInfoVo( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @Schema(description = "邮箱", example = "user@fatweb.top") + @Schema(description = "邮箱", example = "user@mail.com") val email: String?, /** diff --git a/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/ActiveInfoVo.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/system/ActiveInfoVo.kt index 65f4b60..1394ced 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/ActiveInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/ActiveInfoVo.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.vo.system +package top.fatweb.oxygen.api.vo.system import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.vo.system.ActiveInfoVo.HistoryVo +import top.fatweb.oxygen.api.vo.system.ActiveInfoVo.HistoryVo import java.time.LocalDate /** diff --git a/src/main/kotlin/top/fatweb/api/vo/system/BaseSettingsVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/BaseSettingsVo.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/vo/system/BaseSettingsVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/system/BaseSettingsVo.kt index 80193b6..1d70fd0 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/BaseSettingsVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/BaseSettingsVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.system +package top.fatweb.oxygen.api.vo.system import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/system/CpuInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/CpuInfoVo.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/vo/system/CpuInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/system/CpuInfoVo.kt index de37e4c..17e843a 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/CpuInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/CpuInfoVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.system +package top.fatweb.oxygen.api.vo.system import com.fasterxml.jackson.annotation.JsonInclude import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/system/FileStoreInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/FileStoreInfoVo.kt similarity index 96% rename from src/main/kotlin/top/fatweb/api/vo/system/FileStoreInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/system/FileStoreInfoVo.kt index 0fa6320..e98b4c1 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/FileStoreInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/FileStoreInfoVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.system +package top.fatweb.oxygen.api.vo.system import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/system/HardwareInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/HardwareInfoVo.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/vo/system/HardwareInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/system/HardwareInfoVo.kt index 8868595..8f1e6a8 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/HardwareInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/HardwareInfoVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.system +package top.fatweb.oxygen.api.vo.system import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/system/MailSettingsVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/MailSettingsVo.kt similarity index 93% rename from src/main/kotlin/top/fatweb/api/vo/system/MailSettingsVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/system/MailSettingsVo.kt index 503d2c5..cf14853 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/MailSettingsVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/MailSettingsVo.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.vo.system +package top.fatweb.oxygen.api.vo.system import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.settings.MailSecurityType +import top.fatweb.oxygen.api.settings.MailSecurityType /** * Mail settings value object diff --git a/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/OnlineInfoVo.kt similarity index 91% rename from src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/system/OnlineInfoVo.kt index 8e043d5..4e76b70 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/OnlineInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/OnlineInfoVo.kt @@ -1,7 +1,7 @@ -package top.fatweb.api.vo.system +package top.fatweb.oxygen.api.vo.system import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.vo.system.OnlineInfoVo.HistoryVo +import top.fatweb.oxygen.api.vo.system.OnlineInfoVo.HistoryVo import java.time.LocalDateTime /** diff --git a/src/main/kotlin/top/fatweb/api/vo/system/SettingsVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SettingsVo.kt similarity index 91% rename from src/main/kotlin/top/fatweb/api/vo/system/SettingsVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/system/SettingsVo.kt index 03cd0e8..7555b6b 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/SettingsVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SettingsVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.system +package top.fatweb.oxygen.api.vo.system import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/system/SoftwareInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SoftwareInfoVo.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/vo/system/SoftwareInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/system/SoftwareInfoVo.kt index 1caf962..6a96097 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/SoftwareInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SoftwareInfoVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.system +package top.fatweb.oxygen.api.vo.system import io.swagger.v3.oas.annotations.media.Schema import java.time.LocalDateTime diff --git a/src/main/kotlin/top/fatweb/api/vo/system/StorageInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/StorageInfoVo.kt similarity index 98% rename from src/main/kotlin/top/fatweb/api/vo/system/StorageInfoVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/system/StorageInfoVo.kt index ca62096..2a467a0 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/StorageInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/StorageInfoVo.kt @@ -1,4 +1,4 @@ -package top.fatweb.api.vo.system +package top.fatweb.oxygen.api.vo.system import io.swagger.v3.oas.annotations.media.Schema diff --git a/src/main/kotlin/top/fatweb/api/vo/system/SysLogVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SysLogVo.kt similarity index 97% rename from src/main/kotlin/top/fatweb/api/vo/system/SysLogVo.kt rename to src/main/kotlin/top/fatweb/oxygen/api/vo/system/SysLogVo.kt index 28e5483..4c44028 100644 --- a/src/main/kotlin/top/fatweb/api/vo/system/SysLogVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SysLogVo.kt @@ -1,9 +1,9 @@ -package top.fatweb.api.vo.system +package top.fatweb.oxygen.api.vo.system import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.api.entity.system.SysLog +import top.fatweb.oxygen.api.entity.system.SysLog import java.time.LocalDateTime /** diff --git a/src/main/resources/application-config-template.yml b/src/main/resources/application-config-template.yml index 1b87aa3..2ca9240 100644 --- a/src/main/resources/application-config-template.yml +++ b/src/main/resources/application-config-template.yml @@ -3,14 +3,14 @@ app: # username: admin # Username of administrator # password: admin # Default password of administrator # nickname: Administrator # Nickname of administrator -# email: admin@fatweb.top # Email of administrator +# email: admin@mail.com # Email of administrator security: # header-string: "Authorization" # The key of head to get token # token-prefix: "Bearer " # Token prefix # jwt-ttl: 2 # The life of token # jwt-ttl-unit: hours # Unit of life of token [nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days] jwt-key: $uuid$ # Key to generate token (Only numbers and letters allow) -# jwt-issuer: FatWeb # Token issuer +# jwt-issuer: Oxygen # Token issuer # redis-ttl: 20 # The life of token in redis # redis-ttl-unit: minutes # Unit of life of token in redis [nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days] diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3117780..b8d5746 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -35,7 +35,7 @@ mybatis-plus: logic-not-delete-value: 0 logic-delete-value: id id-type: assign_id - type-aliases-package: top.fatweb.api.entity + type-aliases-package: top.fatweb.oxygen.api.entity logging: level: diff --git a/src/main/resources/mapper/permission/FuncMapper.xml b/src/main/resources/mapper/permission/FuncMapper.xml index f2211cb..ef0e20e 100644 --- a/src/main/resources/mapper/permission/FuncMapper.xml +++ b/src/main/resources/mapper/permission/FuncMapper.xml @@ -1,6 +1,6 @@ - + diff --git a/src/main/resources/mapper/permission/GroupMapper.xml b/src/main/resources/mapper/permission/GroupMapper.xml index e32fae4..24d6e8a 100644 --- a/src/main/resources/mapper/permission/GroupMapper.xml +++ b/src/main/resources/mapper/permission/GroupMapper.xml @@ -1,6 +1,6 @@ - + select id from t_role @@ -101,9 +101,9 @@ - - - - + + + + diff --git a/src/main/resources/mapper/permission/UserGroupMapper.xml b/src/main/resources/mapper/permission/UserGroupMapper.xml index 9eaaad8..ba22a76 100644 --- a/src/main/resources/mapper/permission/UserGroupMapper.xml +++ b/src/main/resources/mapper/permission/UserGroupMapper.xml @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/mapper/permission/UserInfoMapper.xml b/src/main/resources/mapper/permission/UserInfoMapper.xml index bdaf75a..de8ac7a 100644 --- a/src/main/resources/mapper/permission/UserInfoMapper.xml +++ b/src/main/resources/mapper/permission/UserInfoMapper.xml @@ -1,6 +1,6 @@ - + diff --git a/src/main/resources/mapper/permission/UserMapper.xml b/src/main/resources/mapper/permission/UserMapper.xml index 9242428..6e4642e 100644 --- a/src/main/resources/mapper/permission/UserMapper.xml +++ b/src/main/resources/mapper/permission/UserMapper.xml @@ -1,6 +1,6 @@ - + select t_sys_log.id as sys_log_id, t_sys_log.log_type as sys_log_log_type, diff --git a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt b/src/test/kotlin/top/fatweb/oxygen/api/OxygenApiApplicationTests.kt similarity index 84% rename from src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt rename to src/test/kotlin/top/fatweb/oxygen/api/OxygenApiApplicationTests.kt index 929c673..660eae7 100644 --- a/src/test/kotlin/top/fatweb/api/FatWebApiApplicationTests.kt +++ b/src/test/kotlin/top/fatweb/oxygen/api/OxygenApiApplicationTests.kt @@ -1,4 +1,4 @@ -package top.fatweb.api +package top.fatweb.oxygen.api import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -6,14 +6,14 @@ import org.junit.jupiter.api.extension.ExtendWith import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.test.context.junit.jupiter.SpringExtension -import top.fatweb.api.properties.SecurityProperties -import top.fatweb.api.util.ByteUtil -import top.fatweb.api.util.JwtUtil -import top.fatweb.api.util.StrUtil +import top.fatweb.oxygen.api.properties.SecurityProperties +import top.fatweb.oxygen.api.util.ByteUtil +import top.fatweb.oxygen.api.util.JwtUtil +import top.fatweb.oxygen.api.util.StrUtil @ExtendWith(SpringExtension::class) -class FatWebApiApplicationTests { +class OxygenApiApplicationTests { private val logger: Logger = LoggerFactory.getLogger(this::class.java) @Test From 94512ccd2bc00f78e94cf34879593d88bd883d7e Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 28 Dec 2023 14:57:14 +0800 Subject: [PATCH 163/258] Update dependencies --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index eef0dab..7bdce6c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.4 + 3.2.1 top.fatweb @@ -152,7 +152,7 @@ com.baomidou mybatis-plus-spring-boot3-starter - 3.5.4.1 + 3.5.5 org.xerial @@ -176,14 +176,14 @@ com.baomidou mybatis-plus-spring-boot3-starter-test - 3.5.4.1 + 3.5.5 test From 22055faca49ee49320c4a762c15071e4058b3031 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 29 Dec 2023 17:55:44 +0800 Subject: [PATCH 164/258] Optimize register api. Add verify Turnstile captcha to login api. --- pom.xml | 5 ++ .../fatweb/oxygen/api/config/JacksonConfig.kt | 28 +++++++++++ .../permission/AuthenticationController.kt | 7 ++- .../oxygen/api/entity/common/ResponseCode.kt | 1 + .../exception/InvalidCaptchaCodeException.kt | 10 ++++ .../oxygen/api/handler/ExceptionHandler.kt | 5 ++ .../fatweb/oxygen/api/http/TurnstileApi.kt | 33 +++++++++++++ .../entity/turnstile/SiteverifyResponse.kt | 48 +++++++++++++++++++ .../oxygen/api/param/permission/LoginParam.kt | 12 ++++- .../oxygen/api/properties/ServerProperties.kt | 8 ++++ .../permission/IAuthenticationService.kt | 2 +- .../impl/AuthenticationServiceImpl.kt | 23 +++++++-- .../oxygen/api/vo/permission/RegisterVo.kt | 11 +++++ .../resources/application-config-template.yml | 2 + src/main/resources/application.yml | 2 +- 15 files changed, 189 insertions(+), 8 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/config/JacksonConfig.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/InvalidCaptchaCodeException.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/http/TurnstileApi.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/http/entity/turnstile/SiteverifyResponse.kt diff --git a/pom.xml b/pom.xml index 7bdce6c..133a5d1 100644 --- a/pom.xml +++ b/pom.xml @@ -121,6 +121,11 @@ spring-security-test test + + com.github.lianjiatech + retrofit-spring-boot-starter + 3.0.3 + org.jetbrains.kotlin diff --git a/src/main/kotlin/top/fatweb/oxygen/api/config/JacksonConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/JacksonConfig.kt new file mode 100644 index 0000000..b3518e0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/JacksonConfig.kt @@ -0,0 +1,28 @@ +package top.fatweb.oxygen.api.config + +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.databind.DeserializationFeature +import com.fasterxml.jackson.databind.json.JsonMapper +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import retrofit2.converter.jackson.JacksonConverterFactory + +/** + * Jackson configuration + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Configuration +class JacksonConfig { + @Bean + fun jacksonConverterFactory(): JacksonConverterFactory { + val mapper = JsonMapper.builder() + .findAndAddModules() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .serializationInclusion(JsonInclude.Include.NON_NULL) + .build() + + return JacksonConverterFactory.create(mapper) + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/AuthenticationController.kt index 4c47343..d443136 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/AuthenticationController.kt @@ -40,9 +40,12 @@ class AuthenticationController( */ @Operation(summary = "注册") @PostMapping("/register") - fun register(@Valid @RequestBody registerParam: RegisterParam): ResponseResult = ResponseResult.success( + fun register( + request: HttpServletRequest, + @Valid @RequestBody registerParam: RegisterParam + ): ResponseResult = ResponseResult.success( ResponseCode.PERMISSION_REGISTER_SUCCESS, - data = authenticationService.register(registerParam) + data = authenticationService.register(request, registerParam) ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index 5b6b721..d2b1dd3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -13,6 +13,7 @@ enum class ResponseCode(val code: Int) { SYSTEM_TIMEOUT(BusinessCode.SYSTEM, 51), SYSTEM_REQUEST_ILLEGAL(BusinessCode.SYSTEM, 52), SYSTEM_ARGUMENT_NOT_VALID(BusinessCode.SYSTEM, 53), + SYSTEM_INVALID_CAPTCHA_CODE(BusinessCode.SYSTEM, 54), PERMISSION_LOGIN_SUCCESS(BusinessCode.PERMISSION, 0), PERMISSION_PASSWORD_CHANGE_SUCCESS(BusinessCode.PERMISSION, 1), diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/InvalidCaptchaCodeException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/InvalidCaptchaCodeException.kt new file mode 100644 index 0000000..6e2b6a5 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/InvalidCaptchaCodeException.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Invalid captcha code exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class InvalidCaptchaCodeException : RuntimeException("Invalid captcha code") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index 47d2262..333724e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -151,6 +151,11 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.PERMISSION_ACCOUNT_NEED_RESET_PASSWORD, e.localizedMessage, null) } + is InvalidCaptchaCodeException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_INVALID_CAPTCHA_CODE, e.localizedMessage, null) + } + is BadSqlGrammarException -> { logger.debug(e.localizedMessage, e) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/http/TurnstileApi.kt b/src/main/kotlin/top/fatweb/oxygen/api/http/TurnstileApi.kt new file mode 100644 index 0000000..7f28258 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/http/TurnstileApi.kt @@ -0,0 +1,33 @@ +package top.fatweb.oxygen.api.http + +import com.github.lianjiatech.retrofit.spring.boot.core.RetrofitClient +import org.springframework.stereotype.Service +import retrofit2.http.Field +import retrofit2.http.FormUrlEncoded +import retrofit2.http.POST +import top.fatweb.oxygen.api.http.entity.turnstile.SiteverifyResponse +import top.fatweb.oxygen.api.properties.ServerProperties + +/** + * Turnstile http request api + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Service +@RetrofitClient(baseUrl = "https://challenges.cloudflare.com/turnstile/v0/") +interface TurnstileApi { + /** + * Turnstile post verify captcha code + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see SiteverifyResponse + */ + @FormUrlEncoded + @POST("siteverify") + fun siteverify( + @Field("response") captchaCode: String, + @Field("secret") secret: String = ServerProperties.turnstileSecretKey + ): SiteverifyResponse +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/http/entity/turnstile/SiteverifyResponse.kt b/src/main/kotlin/top/fatweb/oxygen/api/http/entity/turnstile/SiteverifyResponse.kt new file mode 100644 index 0000000..e6e6b94 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/http/entity/turnstile/SiteverifyResponse.kt @@ -0,0 +1,48 @@ +package top.fatweb.oxygen.api.http.entity.turnstile + +import com.fasterxml.jackson.annotation.JsonProperty +import java.time.LocalDateTime + +/** + * Turnstile verify captcha code response + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class SiteverifyResponse( + /** + * Is success + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @JsonProperty("success") + val success: Boolean, + + /** + * Challenge time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @JsonProperty("challenge_ts") + val challengeTs: LocalDateTime?, + + /** + * Hostname + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @JsonProperty("hostname") + val hostname: String?, + + /** + * Error codes list + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @JsonProperty("error-codes") + val errorCodes: List? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt index 2c0da76..4f8b391 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt @@ -29,5 +29,15 @@ data class LoginParam( */ @Schema(description = "密码", required = true) @field:NotBlank(message = "Password can not be blank") - val password: String? + val password: String?, + + /** + * Captcha code + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "验证码", required = true) + @field:NotBlank(message = "Captcha code can not be blank") + val captchaCode: String? ) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/properties/ServerProperties.kt b/src/main/kotlin/top/fatweb/oxygen/api/properties/ServerProperties.kt index 4912682..83b2835 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/properties/ServerProperties.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/properties/ServerProperties.kt @@ -48,6 +48,14 @@ object ServerProperties { */ val startupTime: LocalDateTime = LocalDateTime.now(ZoneOffset.UTC) + /** + * Turnstile secret key + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + lateinit var turnstileSecretKey: String + fun buildZoneDateTime(zoneId: ZoneId = ZoneId.systemDefault()): ZonedDateTime = LocalDateTime.parse(buildTime).atZone(ZoneId.of("UTC")).withZoneSameInstant(zoneId) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IAuthenticationService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IAuthenticationService.kt index 557a8b8..a242964 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IAuthenticationService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IAuthenticationService.kt @@ -24,7 +24,7 @@ interface IAuthenticationService { * @see RegisterParam * @see RegisterVo */ - fun register(registerParam: RegisterParam): RegisterVo + fun register(request: HttpServletRequest, registerParam: RegisterParam): RegisterVo /** * Send verify email diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt index 2bb8916..95949d9 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -19,6 +19,7 @@ import top.fatweb.oxygen.api.entity.permission.User import top.fatweb.oxygen.api.entity.permission.UserInfo import top.fatweb.oxygen.api.entity.system.EventLog import top.fatweb.oxygen.api.exception.* +import top.fatweb.oxygen.api.http.TurnstileApi import top.fatweb.oxygen.api.param.permission.* import top.fatweb.oxygen.api.properties.SecurityProperties import top.fatweb.oxygen.api.service.api.v1.IAvatarService @@ -56,6 +57,7 @@ class AuthenticationServiceImpl( private val authenticationManager: AuthenticationManager, private val passwordEncoder: PasswordEncoder, private val redisUtil: RedisUtil, + private val turnstileApi: TurnstileApi, private val userService: IUserService, private val userInfoService: IUserInfoService, private val avatarService: IAvatarService @@ -64,7 +66,7 @@ class AuthenticationServiceImpl( @EventLogRecord(EventLog.Event.REGISTER) @Transactional - override fun register(registerParam: RegisterParam): RegisterVo { + override fun register(request: HttpServletRequest, registerParam: RegisterParam): RegisterVo { val user = User().apply { username = registerParam.username password = passwordEncoder.encode(registerParam.password) @@ -85,7 +87,9 @@ class AuthenticationServiceImpl( sendVerifyMail(user.username!!, user.verify!!, registerParam.email!!) - return RegisterVo(userId = user.id) + val loginVo = this.login(request, registerParam.username!!, registerParam.password!!) + + return RegisterVo(token = loginVo.token, userId = loginVo.userId) } @Transactional @@ -244,8 +248,21 @@ class AuthenticationServiceImpl( @EventLogRecord(EventLog.Event.LOGIN) override fun login(request: HttpServletRequest, loginParam: LoginParam): LoginVo { + try { + val siteverifyResponse = turnstileApi.siteverify(loginParam.captchaCode!!) + if (!siteverifyResponse.success) { + throw InvalidCaptchaCodeException() + } + } catch (e: Exception) { + throw InvalidCaptchaCodeException() + } + + return this.login(request, loginParam.account!!, loginParam.password!!) + } + + private fun login(request: HttpServletRequest, account: String, password: String): LoginVo { val usernamePasswordAuthenticationToken = - UsernamePasswordAuthenticationToken(loginParam.account, loginParam.password) + UsernamePasswordAuthenticationToken(account, password) val authentication = authenticationManager.authenticate(usernamePasswordAuthenticationToken) authentication ?: let { throw RuntimeException("Login failed") diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/RegisterVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/RegisterVo.kt index c33581b..b15ca14 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/RegisterVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/RegisterVo.kt @@ -12,6 +12,17 @@ import io.swagger.v3.oas.annotations.media.Schema */ @Schema(description = "注册返回参数") data class RegisterVo( + /** + * Token + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema( + description = "Token", + example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYTllYjFkYmVmZDQ0OWRkOThlOGNjNzZlNzZkMDgyNSIsInN1YiI6IjE3MDk5ODYwNTg2Nzk5NzU5MzgiLCJpc3MiOiJGYXRXZWIiLCJpYXQiOjE2OTY1MjgxMTcsImV4cCI6MTY5NjUzNTMxN30.U2ZsyrGk7NbsP-DJfdz9xgWSfect5r2iKQnlEsscAA8" + ) val token: String, + /** * User ID * diff --git a/src/main/resources/application-config-template.yml b/src/main/resources/application-config-template.yml index 2ca9240..dbe25d5 100644 --- a/src/main/resources/application-config-template.yml +++ b/src/main/resources/application-config-template.yml @@ -1,4 +1,6 @@ app: + app-name: Oxygen Toolbox # Application name + turnstile-secret-key: 1x0000000000000000000000000000000AA # Turnstile secret key admin: # username: admin # Username of administrator # password: admin # Default password of administrator diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b8d5746..46ec570 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ app: - app-name: FatWeb + app-name: Oxygen Toolbox version: @project.version@ build-time: @build.timestamp@ From 21e9bd98c962aa690c46aedfa761a9b8f1a0c410 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 2 Jan 2024 16:46:36 +0800 Subject: [PATCH 165/258] Optimize authentication api --- .../oxygen/api/entity/common/ResponseCode.kt | 1 + .../api/exception/RequestTooFrequent.kt | 9 + .../oxygen/api/handler/ExceptionHandler.kt | 5 + .../oxygen/api/param/CaptchaCodeParam.kt | 22 ++ .../api/param/permission/ForgetParam.kt | 3 +- .../oxygen/api/param/permission/LoginParam.kt | 15 +- .../api/param/permission/RegisterParam.kt | 3 +- .../api/param/permission/RetrieveParam.kt | 3 +- .../impl/AuthenticationServiceImpl.kt | 207 ++++++++++-------- .../mapper/permission/UserMapper.xml | 11 +- 10 files changed, 171 insertions(+), 108 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequent.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/CaptchaCodeParam.kt diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index d2b1dd3..ef3ad98 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -14,6 +14,7 @@ enum class ResponseCode(val code: Int) { SYSTEM_REQUEST_ILLEGAL(BusinessCode.SYSTEM, 52), SYSTEM_ARGUMENT_NOT_VALID(BusinessCode.SYSTEM, 53), SYSTEM_INVALID_CAPTCHA_CODE(BusinessCode.SYSTEM, 54), + SYSTEM_REQUEST_TOO_FREQUENT(BusinessCode.SYSTEM, 55), PERMISSION_LOGIN_SUCCESS(BusinessCode.PERMISSION, 0), PERMISSION_PASSWORD_CHANGE_SUCCESS(BusinessCode.PERMISSION, 1), diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequent.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequent.kt new file mode 100644 index 0000000..be1f1e2 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequent.kt @@ -0,0 +1,9 @@ +package top.fatweb.oxygen.api.exception + +/** + * Request too frequent exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +class RequestTooFrequent: RuntimeException("Request too frequent") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index 333724e..477bc62 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -58,6 +58,11 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.SYSTEM_ARGUMENT_NOT_VALID, errorMessage, null) } + is RequestTooFrequent -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_TOO_FREQUENT, e.localizedMessage, null) + } + is InsufficientAuthenticationException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.PERMISSION_UNAUTHORIZED, e.localizedMessage, null) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/CaptchaCodeParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/CaptchaCodeParam.kt new file mode 100644 index 0000000..fa686ce --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/CaptchaCodeParam.kt @@ -0,0 +1,22 @@ +package top.fatweb.oxygen.api.param + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank + +/** + * Captcha code parameter + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +open class CaptchaCodeParam { + /** + * Captcha code + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "验证码", required = true) + @field:NotBlank(message = "Captcha code can not be blank") + var captchaCode: String? = null +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/ForgetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/ForgetParam.kt index 05091d2..e6ff4ce 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/ForgetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/ForgetParam.kt @@ -3,6 +3,7 @@ package top.fatweb.oxygen.api.param.permission import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.Pattern +import top.fatweb.oxygen.api.param.CaptchaCodeParam /** * Forget password parameters @@ -22,4 +23,4 @@ data class ForgetParam( @field:NotBlank(message = "Email can not be blank") @field:Pattern(regexp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\$", message = "Illegal email address") val email: String? -) +) : CaptchaCodeParam() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt index 4f8b391..8112d73 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.param.permission import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank +import top.fatweb.oxygen.api.param.CaptchaCodeParam /** * Login parameters @@ -29,15 +30,5 @@ data class LoginParam( */ @Schema(description = "密码", required = true) @field:NotBlank(message = "Password can not be blank") - val password: String?, - - /** - * Captcha code - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "验证码", required = true) - @field:NotBlank(message = "Captcha code can not be blank") - val captchaCode: String? -) \ No newline at end of file + val password: String? +) : CaptchaCodeParam() \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt index e32ee3a..47af7de 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.Pattern import jakarta.validation.constraints.Size +import top.fatweb.oxygen.api.param.CaptchaCodeParam /** * Register parameters @@ -45,4 +46,4 @@ data class RegisterParam( @field:NotBlank(message = "Password can not be blank") @field:Size(min = 10, max = 30) val password: String? -) \ No newline at end of file +) : CaptchaCodeParam() \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt index f3571d5..b94a786 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt @@ -3,6 +3,7 @@ package top.fatweb.oxygen.api.param.permission import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.Size +import top.fatweb.oxygen.api.param.CaptchaCodeParam /** * Retrieve password parameters @@ -32,4 +33,4 @@ data class RetrieveParam( @field:NotBlank(message = "New password can not be blank") @field:Size(min = 10, max = 30) val password: String? -) +) : CaptchaCodeParam() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt index 95949d9..5bb7f3f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -67,6 +67,8 @@ class AuthenticationServiceImpl( @EventLogRecord(EventLog.Event.REGISTER) @Transactional override fun register(request: HttpServletRequest, registerParam: RegisterParam): RegisterVo { + verifyCaptcha(registerParam.captchaCode!!) + val user = User().apply { username = registerParam.username password = passwordEncoder.encode(registerParam.password) @@ -98,6 +100,12 @@ class AuthenticationServiceImpl( user.verify ?: throw NoVerificationRequiredException() + if (LocalDateTime.ofInstant(Instant.ofEpochMilli(user.verify!!.split("-").first().toLong()), ZoneOffset.UTC) + .isAfter(LocalDateTime.now(ZoneOffset.UTC).minusMinutes(5)) + ) { + throw RequestTooFrequent() + } + user.verify = "${ LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli() @@ -110,30 +118,6 @@ class AuthenticationServiceImpl( } ?: throw AccessDeniedException("Access Denied") } - private fun sendVerifyMail(username: String, code: String, email: String) { - val velocityContext = VelocityContext().apply { - put("appName", SettingsOperator.getAppValue(BaseSettings::appName, "氧工具")) - put("appUrl", SettingsOperator.getAppValue(BaseSettings::appUrl, "http://localhost")) - put("username", username) - put( - "verifyUrl", - SettingsOperator.getAppValue(BaseSettings::verifyUrl, "http://localhost/verify?code=\${verifyCode}") - .replace( - Regex("(?<=([^\\\\]))\\$\\{verifyCode}"), code - ) - ) - } - val template = velocityEngine.getTemplate("templates/email-verify-account-cn.vm") - - val stringWriter = StringWriter() - template.merge(velocityContext, stringWriter) - - MailUtil.sendSimpleMail( - "验证您的账号", stringWriter.toString(), true, - email - ) - } - @EventLogRecord(EventLog.Event.VERIFY) @Transactional override fun verify(verifyParam: VerifyParam) { @@ -161,8 +145,19 @@ class AuthenticationServiceImpl( @Transactional override fun forget(request: HttpServletRequest, forgetParam: ForgetParam) { + verifyCaptcha(forgetParam.captchaCode!!) + val user = userService.getUserWithPowerByAccount(forgetParam.email!!) user ?: let { throw UserNotFoundException() } + + user.forget?.let { + if (LocalDateTime.ofInstant(Instant.ofEpochMilli(it.split("-").first().toLong()), ZoneOffset.UTC) + .isAfter(LocalDateTime.now(ZoneOffset.UTC).minusMinutes(5)) + ) { + throw RequestTooFrequent() + } + } + val code = "${ LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli() }-${UUID.randomUUID()}-${UUID.randomUUID()}-${UUID.randomUUID()}" @@ -170,6 +165,95 @@ class AuthenticationServiceImpl( sendRetrieveMail(user.username!!, request.remoteAddr, code, forgetParam.email) } + @Transactional + override fun retrieve(request: HttpServletRequest, retrieveParam: RetrieveParam) { + verifyCaptcha(retrieveParam.captchaCode!!) + + val codeStrings = retrieveParam.code!!.split("-") + if (codeStrings.size != 16) { + throw RetrieveCodeErrorOrExpiredException() + } + try { + if (LocalDateTime.ofInstant(Instant.ofEpochMilli(codeStrings.first().toLong()), ZoneOffset.UTC) + .isBefore(LocalDateTime.now(ZoneOffset.UTC).minusHours(2)) + ) { + throw RetrieveCodeErrorOrExpiredException() + } + } catch (e: Exception) { + throw RetrieveCodeErrorOrExpiredException() + } + + val user = userService.getOne(KtQueryWrapper(User()).eq(User::forget, retrieveParam.code)) + ?: throw RetrieveCodeErrorOrExpiredException() + val userInfo = userInfoService.getOne(KtQueryWrapper(UserInfo()).eq(UserInfo::userId, user.id)) + + userService.update( + KtUpdateWrapper(User()).eq(User::id, user.id).set(User::forget, null) + .set(User::password, passwordEncoder.encode(retrieveParam.password!!)) + ) + + WebUtil.offlineUser(redisUtil, user.id!!) + + sendPasswordChangedMail(user.username!!, request.remoteAddr, userInfo!!.email!!) + } + + @EventLogRecord(EventLog.Event.LOGIN) + override fun login(request: HttpServletRequest, loginParam: LoginParam): LoginVo { + verifyCaptcha(loginParam.captchaCode!!) + + return this.login(request, loginParam.account!!, loginParam.password!!) + } + + @EventLogRecord(EventLog.Event.LOGOUT) + override fun logout(token: String): Boolean { + val loginUser = WebUtil.getLoginUser() ?: let { throw TokenHasExpiredException() } + + return redisUtil.delObject("${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:" + token) + } + + override fun renewToken(token: String): TokenVo { + val loginUser = WebUtil.getLoginUser() ?: let { throw TokenHasExpiredException() } + + val oldRedisKey = "${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:" + token + redisUtil.delObject(oldRedisKey) + val jwt = JwtUtil.createJwt(WebUtil.getLoginUserId().toString()) + + jwt ?: let { + throw RuntimeException("Login failed") + } + + val redisKey = "${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:" + jwt + redisUtil.setObject( + redisKey, loginUser, SecurityProperties.redisTtl, SecurityProperties.redisTtlUnit + ) + + return TokenVo(jwt) + } + + private fun sendVerifyMail(username: String, code: String, email: String) { + val velocityContext = VelocityContext().apply { + put("appName", SettingsOperator.getAppValue(BaseSettings::appName, "氧工具")) + put("appUrl", SettingsOperator.getAppValue(BaseSettings::appUrl, "http://localhost")) + put("username", username) + put( + "verifyUrl", + SettingsOperator.getAppValue(BaseSettings::verifyUrl, "http://localhost/verify?code=\${verifyCode}") + .replace( + Regex("(?<=([^\\\\]))\\$\\{verifyCode}"), code + ) + ) + } + val template = velocityEngine.getTemplate("templates/email-verify-account-cn.vm") + + val stringWriter = StringWriter() + template.merge(velocityContext, stringWriter) + + MailUtil.sendSimpleMail( + "验证您的账号", stringWriter.toString(), true, + email + ) + } + private fun sendRetrieveMail(username: String, ip: String, code: String, email: String) { val velocityContext = VelocityContext().apply { put("appName", SettingsOperator.getAppValue(BaseSettings::appName, "氧工具")) @@ -198,36 +282,6 @@ class AuthenticationServiceImpl( ) } - @Transactional - override fun retrieve(request: HttpServletRequest, retrieveParam: RetrieveParam) { - val codeStrings = retrieveParam.code!!.split("-") - if (codeStrings.size != 16) { - throw RetrieveCodeErrorOrExpiredException() - } - try { - if (LocalDateTime.ofInstant(Instant.ofEpochMilli(codeStrings.first().toLong()), ZoneOffset.UTC) - .isBefore(LocalDateTime.now(ZoneOffset.UTC).minusHours(2)) - ) { - throw RetrieveCodeErrorOrExpiredException() - } - } catch (e: Exception) { - throw RetrieveCodeErrorOrExpiredException() - } - - val user = userService.getOne(KtQueryWrapper(User()).eq(User::forget, retrieveParam.code)) - ?: throw RetrieveCodeErrorOrExpiredException() - val userInfo = userInfoService.getOne(KtQueryWrapper(UserInfo()).eq(UserInfo::userId, user.id)) - - userService.update( - KtUpdateWrapper(User()).eq(User::id, user.id).set(User::forget, null) - .set(User::password, passwordEncoder.encode(retrieveParam.password!!)) - ) - - WebUtil.offlineUser(redisUtil, user.id!!) - - sendPasswordChangedMail(user.username!!, request.remoteAddr, userInfo!!.email!!) - } - private fun sendPasswordChangedMail(username: String, ip: String, email: String) { val velocityContext = VelocityContext().apply { put("appName", SettingsOperator.getAppValue(BaseSettings::appName, "氧工具")) @@ -246,20 +300,6 @@ class AuthenticationServiceImpl( ) } - @EventLogRecord(EventLog.Event.LOGIN) - override fun login(request: HttpServletRequest, loginParam: LoginParam): LoginVo { - try { - val siteverifyResponse = turnstileApi.siteverify(loginParam.captchaCode!!) - if (!siteverifyResponse.success) { - throw InvalidCaptchaCodeException() - } - } catch (e: Exception) { - throw InvalidCaptchaCodeException() - } - - return this.login(request, loginParam.account!!, loginParam.password!!) - } - private fun login(request: HttpServletRequest, account: String, password: String): LoginVo { val usernamePasswordAuthenticationToken = UsernamePasswordAuthenticationToken(account, password) @@ -292,29 +332,14 @@ class AuthenticationServiceImpl( return LoginVo(jwt, loginUser.user.id, loginUser.user.currentLoginTime, loginUser.user.currentLoginIp) } - @EventLogRecord(EventLog.Event.LOGOUT) - override fun logout(token: String): Boolean { - val loginUser = WebUtil.getLoginUser() ?: let { throw TokenHasExpiredException() } - - return redisUtil.delObject("${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:" + token) - } - - override fun renewToken(token: String): TokenVo { - val loginUser = WebUtil.getLoginUser() ?: let { throw TokenHasExpiredException() } - - val oldRedisKey = "${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:" + token - redisUtil.delObject(oldRedisKey) - val jwt = JwtUtil.createJwt(WebUtil.getLoginUserId().toString()) - - jwt ?: let { - throw RuntimeException("Login failed") + private fun verifyCaptcha(captchaCode: String) { + try { + val siteverifyResponse = turnstileApi.siteverify(captchaCode) + if (!siteverifyResponse.success) { + throw InvalidCaptchaCodeException() + } + } catch (e: Exception) { + throw InvalidCaptchaCodeException() } - - val redisKey = "${SecurityProperties.jwtIssuer}_login_${loginUser.user.id}:" + jwt - redisUtil.setObject( - redisKey, loginUser, SecurityProperties.redisTtl, SecurityProperties.redisTtlUnit - ) - - return TokenVo(jwt) } } \ No newline at end of file diff --git a/src/main/resources/mapper/permission/UserMapper.xml b/src/main/resources/mapper/permission/UserMapper.xml index 6e4642e..5488731 100644 --- a/src/main/resources/mapper/permission/UserMapper.xml +++ b/src/main/resources/mapper/permission/UserMapper.xml @@ -6,6 +6,7 @@ t_user.username as user_username, t_user.password as user_password, t_user.verify as user_verify, + t_user.forget as user_forget, t_user.locking as user_locking, t_user.expiration as user_expiration, t_user.credentials_expiration as user_credentials_expiration, @@ -128,6 +129,7 @@ select t_user.id as user_id, t_user.username as user_username, t_user.verify as user_verify, + t_user.forget as user_forget, t_user.locking as user_locking, t_user.expiration as user_expiration, t_user.credentials_expiration as user_credentials_expiration, @@ -179,6 +181,7 @@ select t_user.id as user_id, t_user.username as user_username, t_user.verify as user_verify, + t_user.forget as user_forget, t_user.locking as user_locking, t_user.expiration as user_expiration, t_user.credentials_expiration as user_credentials_expiration, @@ -227,6 +230,7 @@ t_user.username as user_username, t_user.verify as user_verify, t_user.locking as user_locking, + t_user.forget as user_forget, t_user.expiration as user_expiration, t_user.credentials_expiration as user_credentials_expiration, t_user.enable as user_enable, @@ -284,6 +288,7 @@ + @@ -299,7 +304,8 @@ - + @@ -307,7 +313,8 @@ - + From 41a9cecdf550d81cc529432cf7eb7230bbe5964f Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 2 Jan 2024 17:20:49 +0800 Subject: [PATCH 166/258] Fix system log can not search bug --- .../oxygen/api/service/system/impl/SysLogServiceImpl.kt | 5 +---- src/main/resources/mapper/system/SysLogMapper.xml | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SysLogServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SysLogServiceImpl.kt index 2ad005f..709c560 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SysLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SysLogServiceImpl.kt @@ -45,10 +45,7 @@ class SysLogServiceImpl( sysLogGetParam?.searchStartTime, sysLogGetParam?.searchEndTime ) - sysLogIPage.records.forEach { - it.operateUsername = - it.operateUserId?.let { it1 -> userService.getOne(it1)?.username } - } + if (sysLogIPage.records.isNotEmpty()) { val userIds = sysLogIPage.records.map { it.operateUserId } diff --git a/src/main/resources/mapper/system/SysLogMapper.xml b/src/main/resources/mapper/system/SysLogMapper.xml index 1b37cf6..99c568f 100644 --- a/src/main/resources/mapper/system/SysLogMapper.xml +++ b/src/main/resources/mapper/system/SysLogMapper.xml @@ -30,7 +30,7 @@ and t_sys_log.request_server_address || t_sys_log.request_uri || case when length(t_sys_log.request_params) != 0 then '?' || t_sys_log.request_params else '' end like - '%'||'mail'||'%' + '%'||#{searchRequestUrl}||'%' and t_sys_log.start_time between #{searchStartTime} and #{searchEndTime} From af134f04e029c83e100e531589402b60e295c458 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 2 Jan 2024 18:23:39 +0800 Subject: [PATCH 167/258] Fix system log can not sort by start_time when search by url bug --- src/main/resources/mapper/system/SysLogMapper.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/mapper/system/SysLogMapper.xml b/src/main/resources/mapper/system/SysLogMapper.xml index 99c568f..7f82da5 100644 --- a/src/main/resources/mapper/system/SysLogMapper.xml +++ b/src/main/resources/mapper/system/SysLogMapper.xml @@ -28,9 +28,9 @@ #{item} - and t_sys_log.request_server_address || t_sys_log.request_uri || - case when length(t_sys_log.request_params) != 0 then '?' || t_sys_log.request_params else '' end like - '%'||#{searchRequestUrl}||'%' + and ((t_sys_log.request_server_address || t_sys_log.request_uri || + (case when length(t_sys_log.request_params) != 0 then '?' || t_sys_log.request_params else '' end)) + like #{searchRequestUrl}) and t_sys_log.start_time between #{searchStartTime} and #{searchEndTime} From f3b63ce17dc5086c5de329e8098c78a732feecdb Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 3 Jan 2024 18:48:33 +0800 Subject: [PATCH 168/258] Optimize code --- ...ataFormatConfig.kt => DateFormatConfig.kt} | 10 +++---- .../oxygen/api/handler/ExceptionHandler.kt | 3 +- .../V1_0_0_231212__Add_table_'t_sys_log'.sql | 30 +++++++++---------- ...V1_0_0_231213__Add_table_'t_event_log'.sql | 8 ++--- ...0_231214__Add_table_'t_statistics_log'.sql | 8 ++--- 5 files changed, 30 insertions(+), 29 deletions(-) rename src/main/kotlin/top/fatweb/oxygen/api/config/{DataFormatConfig.kt => DateFormatConfig.kt} (90%) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/config/DataFormatConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/DateFormatConfig.kt similarity index 90% rename from src/main/kotlin/top/fatweb/oxygen/api/config/DataFormatConfig.kt rename to src/main/kotlin/top/fatweb/oxygen/api/config/DateFormatConfig.kt index 328afaa..9eb49c8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/config/DataFormatConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/DateFormatConfig.kt @@ -14,13 +14,13 @@ import java.time.format.DateTimeFormatter import java.util.* /** - * Data format configuration + * Date format configuration * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ @JsonComponent -class DataFormatConfig { +class DateFormatConfig { /** * The format of the time in response when request APIs * @@ -28,7 +28,7 @@ class DataFormatConfig { * @since 1.0.0 */ @set:Value("\${spring.jackson.date-format}") - lateinit var dataFormat: String + lateinit var dateFormat: String /** * The timezone of the time in response when request APIs @@ -43,7 +43,7 @@ class DataFormatConfig { @Bean fun jackson2ObjectMapperBuilder() = Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder -> val tz = timeZone - val df: DateFormat = SimpleDateFormat(dataFormat) + val df: DateFormat = SimpleDateFormat(dateFormat) df.timeZone = tz builder.failOnEmptyBeans(false).failOnUnknownProperties(false) .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).dateFormat(df) @@ -53,7 +53,7 @@ class DataFormatConfig { fun jackson2ObjectMapperBuilderCustomizer() = Jackson2ObjectMapperBuilderCustomizer { builder: Jackson2ObjectMapperBuilder -> builder.serializerByType( - LocalDateTime::class.java, LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dataFormat)) + LocalDateTime::class.java, LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateFormat)) ) } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index 477bc62..7b39df0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -14,6 +14,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.RestControllerAdvice +import org.springframework.web.servlet.resource.NoResourceFoundException import top.fatweb.avatargenerator.AvatarException import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult @@ -42,7 +43,7 @@ class ExceptionHandler { @ExceptionHandler(value = [Exception::class]) fun exceptionHandler(e: Exception): ResponseResult<*> { return when (e) { - is HttpRequestMethodNotSupportedException -> { + is HttpRequestMethodNotSupportedException, is NoResourceFoundException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage, null) } diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_sys_log'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_sys_log'.sql index 93c1301..87bd930 100644 --- a/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_sys_log'.sql +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_sys_log'.sql @@ -2,19 +2,19 @@ drop table if exists t_sys_log; create table t_sys_log -- 系统日志表 ( - id bigint not null, - log_type varchar(50) not null, -- 日志类型 - operate_user_id bigint not null, -- 操作用户 - operate_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f','now')), -- 操作时间 - request_uri varchar(500) default null, -- 请求 URI - request_method varchar(10) default null, -- 请求方式 - request_params text, -- 请求参数 - request_ip varchar(20) not null, -- 请求 IP - request_server_address varchar(50) not null, -- 请求服务器地址 - exception int not null default 0, -- 是否异常 - exception_info text, -- 异常信息 - start_time datetime not null, -- 开始时间 - end_time datetime not null, -- 结束时间 - execute_time bigint default null, -- 执行时间 - user_agent varchar(500) default null -- 用户代理 + id integer not null, + log_type text not null, -- 日志类型 + operate_user_id integer not null, -- 操作用户 + operate_time text not null default (strftime('%Y-%m-%d %H:%M:%f', 'now')), -- 操作时间 + request_uri text default null, -- 请求 URI + request_method text default null, -- 请求方式 + request_params text, -- 请求参数 + request_ip text not null, -- 请求 IP + request_server_address text not null, -- 请求服务器地址 + exception integer not null default 0, -- 是否异常 + exception_info text, -- 异常信息 + start_time text not null, -- 开始时间 + end_time text not null, -- 结束时间 + execute_time integer default null, -- 执行时间 + user_agent text default null -- 用户代理 ); \ No newline at end of file diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_event_log'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_event_log'.sql index a2b97a6..e921a6c 100644 --- a/src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_event_log'.sql +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_event_log'.sql @@ -2,8 +2,8 @@ drop table if exists t_event_log; create table if not exists t_event_log -- 事件日志表 ( - id bigint not null primary key, - event varchar(50) not null, -- 事件, - operate_user_id bigint not null, -- 操作用户 - operate_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f','now')) -- 操作时间 + id integer not null primary key, + event text not null, -- 事件, + operate_user_id integer not null, -- 操作用户 + operate_time text not null default (strftime('%Y-%m-%d %H:%M:%f', 'now')) -- 操作时间 ); \ No newline at end of file diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics_log'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics_log'.sql index 22a14de..5228202 100644 --- a/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics_log'.sql +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics_log'.sql @@ -2,8 +2,8 @@ drop table if exists t_statistics_log; create table if not exists t_statistics_log -- 统计日志表 ( - id bigint not null primary key, - key varchar(50) not null, -- 记录键 - value varchar(100) not null, -- 记录值 - record_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f', 'now')) -- 记录时间 + id integer not null primary key, + key text not null, -- 记录键 + value text not null, -- 记录值 + record_time text not null default (strftime('%Y-%m-%d %H:%M:%f', 'now')) -- 记录时间 ) \ No newline at end of file From 3b9111392eef3b98bf76be9108fe84248c2d4e93 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 4 Jan 2024 17:55:41 +0800 Subject: [PATCH 169/258] Add sensitive word filter --- .../controller/system/SettingsController.kt | 66 +++++++++++++++++-- .../api/converter/system/SettingsConverter.kt | 26 ++++++++ .../oxygen/api/entity/common/ResponseCode.kt | 1 + .../oxygen/api/entity/system/SensitiveWord.kt | 63 ++++++++++++++++++ .../exception/MatchSensitiveWordException.kt | 3 + .../oxygen/api/handler/ExceptionHandler.kt | 22 ++++++- .../api/mapper/system/SensitiveWordMapper.kt | 14 ++++ .../param/api/v1/avatar/AvatarBaseParam.kt | 4 +- .../api/param/system/ActiveInfoGetParam.kt | 1 + .../api/param/system/OnlineInfoGetParam.kt | 1 + .../api/param/system/SensitiveWordAddParam.kt | 43 ++++++++++++ .../param/system/SensitiveWordUpdateParam.kt | 15 +++++ .../impl/AuthenticationServiceImpl.kt | 4 ++ .../api/service/system/IEventLogService.kt | 7 ++ .../service/system/ISensitiveWordService.kt | 58 ++++++++++++++++ .../system/impl/EventLogServiceImpl.kt | 6 ++ .../system/impl/SensitiveWordServiceImpl.kt | 66 +++++++++++++++++++ .../system/impl/StatisticsLogServiceImpl.kt | 6 ++ .../oxygen/api/vo/system/SensitiveWordVo.kt | 52 +++++++++++++++ .../db/migration/master/R__Basic_data.sql | 8 ++- ...0_240103__Add_table_‘t_sensitive_word'.sql | 9 +++ 21 files changed, 466 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/entity/system/SensitiveWord.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/system/SensitiveWordMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/system/SensitiveWordAddParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/system/SensitiveWordUpdateParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/system/ISensitiveWordService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/vo/system/SensitiveWordVo.kt create mode 100644 src/main/resources/db/migration/sqlite/V1_0_0_240103__Add_table_‘t_sensitive_word'.sql diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt index 9602e56..8da32a9 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt @@ -3,18 +3,21 @@ package top.fatweb.oxygen.api.controller.system import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid import org.springframework.security.access.prepost.PreAuthorize +import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.PutMapping import org.springframework.web.bind.annotation.RequestBody import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult -import top.fatweb.oxygen.api.param.system.BaseSettingsParam -import top.fatweb.oxygen.api.param.system.MailSendParam -import top.fatweb.oxygen.api.param.system.MailSettingsParam +import top.fatweb.oxygen.api.param.system.* +import top.fatweb.oxygen.api.service.system.ISensitiveWordService import top.fatweb.oxygen.api.service.system.ISettingsService import top.fatweb.oxygen.api.vo.system.BaseSettingsVo import top.fatweb.oxygen.api.vo.system.MailSettingsVo +import top.fatweb.oxygen.api.vo.system.SensitiveWordVo /** * System settings controller @@ -25,7 +28,8 @@ import top.fatweb.oxygen.api.vo.system.MailSettingsVo */ @BaseController(path = ["/system/settings"], name = "系统设置", description = "系统设置相关接口") class SettingsController( - private val settingsService: ISettingsService + private val settingsService: ISettingsService, + private val sensitiveWordService: ISensitiveWordService ) { /** * Get base settings @@ -97,4 +101,58 @@ class SettingsController( settingsService.sendMail(mailSendParam) return ResponseResult.success() } + + /** + * Get sensitive word settings + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "获取敏感词配置") + @GetMapping("/sensitive") + @PreAuthorize("hasAnyAuthority('system:settings:query:sensitive')") + fun getSensitive(): ResponseResult> = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_SELECT_SUCCESS, data = sensitiveWordService.get()) + + /** + * Add sensitive word + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "添加敏感词") + @PostMapping("/sensitive") + @PreAuthorize("hasAnyAuthority('system:settings:modify:sensitive')") + fun addSensitive(@RequestBody @Valid sensitiveWordAddParam: SensitiveWordAddParam): ResponseResult { + sensitiveWordService.add(sensitiveWordAddParam) + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_INSERT_SUCCESS) + } + + /** + * Update sensitive word + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "修改敏感词") + @PutMapping("/sensitive") + @PreAuthorize("hasAnyAuthority('system:settings:modify:sensitive')") + fun updateSensitive(@RequestBody sensitiveWordUpdateParam: SensitiveWordUpdateParam): ResponseResult { + sensitiveWordService.update(sensitiveWordUpdateParam) + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) + } + + /** + * Delete sensitive word + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "删除敏感词") + @DeleteMapping("/sensitive/{id}") + @PreAuthorize("hasAnyAuthority('system:settings:modify:sensitive')") + fun deleteSensitive(@PathVariable id: Long): ResponseResult { + sensitiveWordService.delete(id) + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt new file mode 100644 index 0000000..a9f29bb --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt @@ -0,0 +1,26 @@ +package top.fatweb.oxygen.api.converter.system + +import top.fatweb.oxygen.api.entity.system.SensitiveWord +import top.fatweb.oxygen.api.param.system.SensitiveWordAddParam +import top.fatweb.oxygen.api.vo.system.SensitiveWordVo + +/** + * Settings converter + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +object SettingsConverter { + fun sensitiveWordToSensitiveWordVo(sensitiveWord: SensitiveWord) = SensitiveWordVo( + id = sensitiveWord.id, + word = sensitiveWord.word, + useFor = sensitiveWord.useFor?.map(SensitiveWord.Use::valueOf)?.toSet(), + enable = sensitiveWord.enable == 1 + ) + + fun sensitiveWordAddParamToSensitiveWord(sensitiveWordAddParam: SensitiveWordAddParam) = SensitiveWord().apply { + word = sensitiveWordAddParam.word + useFor = sensitiveWordAddParam.useFor.map(SensitiveWord.Use::code).toSet() + enable = if (sensitiveWordAddParam.enable) 1 else 0 + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index ef3ad98..4e3032c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -15,6 +15,7 @@ enum class ResponseCode(val code: Int) { SYSTEM_ARGUMENT_NOT_VALID(BusinessCode.SYSTEM, 53), SYSTEM_INVALID_CAPTCHA_CODE(BusinessCode.SYSTEM, 54), SYSTEM_REQUEST_TOO_FREQUENT(BusinessCode.SYSTEM, 55), + SYSTEM_MATCH_SENSITIVE_WORD(BusinessCode.SYSTEM, 56), PERMISSION_LOGIN_SUCCESS(BusinessCode.PERMISSION, 0), PERMISSION_PASSWORD_CHANGE_SUCCESS(BusinessCode.PERMISSION, 1), diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SensitiveWord.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SensitiveWord.kt new file mode 100644 index 0000000..a38413a --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SensitiveWord.kt @@ -0,0 +1,63 @@ +package top.fatweb.oxygen.api.entity.system + +import com.baomidou.mybatisplus.annotation.EnumValue +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableName +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler +import com.fasterxml.jackson.annotation.JsonValue +import java.io.Serializable + +/** + * Sensitive word entity + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@TableName("t_sensitive_word", autoResultMap = true) +class SensitiveWord : Serializable { + enum class Use(@field:EnumValue @field:JsonValue val code: String) { + USERNAME("USERNAME"), TITLE("TITLE"); + } + + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableId("id") + var id: Long? = null + + /** + * Word + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("word") + var word: String? = null + + /** + * Use for + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(value = "use_for", typeHandler = JacksonTypeHandler::class) + @JvmField + var useFor: Set? = null + + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("enable") + var enable: Int? = null + + override fun toString(): String { + return "SensitiveWord(id=$id, word=$word, useFor=$useFor, enable=$enable)" + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt new file mode 100644 index 0000000..d428efb --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt @@ -0,0 +1,3 @@ +package top.fatweb.oxygen.api.exception + +class MatchSensitiveWordException: RuntimeException("Match sensitive word") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index 7b39df0..a47a3c3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory import org.springframework.dao.DuplicateKeyException import org.springframework.http.converter.HttpMessageNotReadableException import org.springframework.jdbc.BadSqlGrammarException +import org.springframework.jdbc.UncategorizedSQLException import org.springframework.security.access.AccessDeniedException import org.springframework.security.authentication.* import org.springframework.web.HttpRequestMethodNotSupportedException @@ -43,6 +44,7 @@ class ExceptionHandler { @ExceptionHandler(value = [Exception::class]) fun exceptionHandler(e: Exception): ResponseResult<*> { return when (e) { + /* Request */ is HttpRequestMethodNotSupportedException, is NoResourceFoundException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage, null) @@ -64,6 +66,7 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_TOO_FREQUENT, e.localizedMessage, null) } + /* Authentication */ is InsufficientAuthenticationException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.PERMISSION_UNAUTHORIZED, e.localizedMessage, null) @@ -162,7 +165,7 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.SYSTEM_INVALID_CAPTCHA_CODE, e.localizedMessage, null) } - + /* SQL */ is BadSqlGrammarException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.DATABASE_EXECUTE_ERROR, "Incorrect SQL syntax", null) @@ -178,6 +181,23 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.DATABASE_NO_RECORD_FOUND, e.localizedMessage, null) } + is UncategorizedSQLException -> { + if (e.localizedMessage.contains("SQLITE_CONSTRAINT_UNIQUE")) { + logger.debug(e.localizedMessage, e) + return ResponseResult.fail(ResponseCode.DATABASE_DUPLICATE_KEY, "Duplicate key", null) + } + + logger.error(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.DATABASE_EXECUTE_ERROR, e.localizedMessage, null) + } + + /* Other */ + is MatchSensitiveWordException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_MATCH_SENSITIVE_WORD, e.localizedMessage, null) + } + + /* API */ is AvatarException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.API_AVATAR_ERROR, e.localizedMessage, null) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/SensitiveWordMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/SensitiveWordMapper.kt new file mode 100644 index 0000000..c9dfd82 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/SensitiveWordMapper.kt @@ -0,0 +1,14 @@ +package top.fatweb.oxygen.api.mapper.system + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.oxygen.api.entity.system.SensitiveWord + +/** + * Sensitive word mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Mapper +interface SensitiveWordMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarBaseParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarBaseParam.kt index 390e4d1..c949017 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarBaseParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarBaseParam.kt @@ -54,7 +54,7 @@ open class AvatarBaseParam { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @Schema(defaultValue = "颜色列表", example = "#FFFFFFAA") + @Schema(description = "颜色列表", example = "#FFFFFFAA") var colors: List? = null /** @@ -63,7 +63,7 @@ open class AvatarBaseParam { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @Schema(defaultValue = "背景颜色", example = "#FFFFFFAA") + @Schema(description = "背景颜色", example = "#FFFFFFAA") @field:Pattern(regexp = "^#[0-9a-fA-F]{6}|#[0-9a-fA-F]{8}$", message = "Background color must be a hex color code") var background: String? = null } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/system/ActiveInfoGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/ActiveInfoGetParam.kt index 51e45b9..c085c80 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/system/ActiveInfoGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/ActiveInfoGetParam.kt @@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.media.Schema * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "用户活跃信息请求参数") data class ActiveInfoGetParam( /** * Scope diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/system/OnlineInfoGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/OnlineInfoGetParam.kt index 1e42833..932f10e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/system/OnlineInfoGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/OnlineInfoGetParam.kt @@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.media.Schema * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "在线信息请求参数") data class OnlineInfoGetParam( /** * Scope diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/system/SensitiveWordAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/SensitiveWordAddParam.kt new file mode 100644 index 0000000..6071bf2 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/SensitiveWordAddParam.kt @@ -0,0 +1,43 @@ +package top.fatweb.oxygen.api.param.system + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank +import top.fatweb.oxygen.api.entity.system.SensitiveWord + +/** + * Add sensitive word settings parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(defaultValue = "敏感词添加请求参数") +data class SensitiveWordAddParam( + /** + * Word + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "词", required = true) + @field:NotBlank(message = "Word can not be blank") + val word: String?, + + /** + * Use for + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see SensitiveWord.Use + */ + @Schema(description = "用于", allowableValues = ["USERNAME"]) + val useFor: Set = emptySet(), + + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "启用", allowableValues = ["true", "false"], defaultValue = "true") + val enable: Boolean = true +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/system/SensitiveWordUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/SensitiveWordUpdateParam.kt new file mode 100644 index 0000000..1faf759 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/SensitiveWordUpdateParam.kt @@ -0,0 +1,15 @@ +package top.fatweb.oxygen.api.param.system + +import io.swagger.v3.oas.annotations.media.Schema + +/** + * Update sensitive word settings parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(defaultValue = "敏感词修改请求参数") +data class SensitiveWordUpdateParam( + @Schema(description = "ID 列表") + val ids: Set = emptySet() +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt index 5bb7f3f..dc6fd10 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -26,6 +26,7 @@ import top.fatweb.oxygen.api.service.api.v1.IAvatarService import top.fatweb.oxygen.api.service.permission.IAuthenticationService import top.fatweb.oxygen.api.service.permission.IUserInfoService import top.fatweb.oxygen.api.service.permission.IUserService +import top.fatweb.oxygen.api.service.system.ISensitiveWordService import top.fatweb.oxygen.api.settings.BaseSettings import top.fatweb.oxygen.api.settings.SettingsOperator import top.fatweb.oxygen.api.util.JwtUtil @@ -60,6 +61,7 @@ class AuthenticationServiceImpl( private val turnstileApi: TurnstileApi, private val userService: IUserService, private val userInfoService: IUserInfoService, + private val sensitiveWordService: ISensitiveWordService, private val avatarService: IAvatarService ) : IAuthenticationService { private val logger: Logger = LoggerFactory.getLogger(this::class.java) @@ -68,6 +70,7 @@ class AuthenticationServiceImpl( @Transactional override fun register(request: HttpServletRequest, registerParam: RegisterParam): RegisterVo { verifyCaptcha(registerParam.captchaCode!!) + sensitiveWordService.checkSensitiveWord(registerParam.username!!) val user = User().apply { username = registerParam.username @@ -132,6 +135,7 @@ class AuthenticationServiceImpl( if (verifyParam.nickname.isNullOrBlank() || verifyParam.avatar.isNullOrBlank()) { throw AccountNeedInitException() } + sensitiveWordService.checkSensitiveWord(verifyParam.nickname) userService.update( KtUpdateWrapper(User()).eq(User::id, user.id).set(User::verify, null) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/IEventLogService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/IEventLogService.kt index 9925086..ca2693c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/IEventLogService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/IEventLogService.kt @@ -11,5 +11,12 @@ import top.fatweb.oxygen.api.entity.system.EventLog * @since 1.0.0 */ interface IEventLogService : IService { + /** + * Save event + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see EventLogRecord + */ fun saveEvent(annotation: EventLogRecord, userId: Long) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/ISensitiveWordService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/ISensitiveWordService.kt new file mode 100644 index 0000000..c51606e --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/ISensitiveWordService.kt @@ -0,0 +1,58 @@ +package top.fatweb.oxygen.api.service.system + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.system.SensitiveWord +import top.fatweb.oxygen.api.param.system.SensitiveWordAddParam +import top.fatweb.oxygen.api.param.system.SensitiveWordUpdateParam +import top.fatweb.oxygen.api.vo.system.SensitiveWordVo + +/** + * Sensitive word service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +interface ISensitiveWordService : IService { + /** + * Get sensitive word settings + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see SensitiveWordVo + */ + fun get(): List + + /** + * Add sensitive word settings item + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see SensitiveWordAddParam + */ + fun add(sensitiveWordAddParam: SensitiveWordAddParam) + + /** + * Update sensitive word settings + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see SensitiveWordUpdateParam + */ + fun update(sensitiveWordUpdateParam: SensitiveWordUpdateParam) + + /** + * Delete sensitive word settings item + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun delete(id: Long) + + /** + * Check sensitive word + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun checkSensitiveWord(str: String) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/EventLogServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/EventLogServiceImpl.kt index 845b1b6..b2d51d6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/EventLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/EventLogServiceImpl.kt @@ -12,6 +12,12 @@ import top.fatweb.oxygen.api.entity.system.EventLog import top.fatweb.oxygen.api.mapper.system.EventLogMapper import top.fatweb.oxygen.api.service.system.IEventLogService +/** + * Event log service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @DS("sqlite") @Service class EventLogServiceImpl : ServiceImpl(), IEventLogService { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt new file mode 100644 index 0000000..f95a233 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt @@ -0,0 +1,66 @@ +package top.fatweb.oxygen.api.service.system.impl + +import com.baomidou.dynamic.datasource.annotation.DS +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper +import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Propagation +import org.springframework.transaction.annotation.Transactional +import top.fatweb.oxygen.api.converter.system.SettingsConverter +import top.fatweb.oxygen.api.entity.system.SensitiveWord +import top.fatweb.oxygen.api.exception.MatchSensitiveWordException +import top.fatweb.oxygen.api.mapper.system.SensitiveWordMapper +import top.fatweb.oxygen.api.param.system.SensitiveWordAddParam +import top.fatweb.oxygen.api.param.system.SensitiveWordUpdateParam +import top.fatweb.oxygen.api.service.system.ISensitiveWordService +import top.fatweb.oxygen.api.vo.system.SensitiveWordVo + +/** + * Sensitive word service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@DS("sqlite") +@Service +class SensitiveWordServiceImpl : ServiceImpl(), ISensitiveWordService { + @Transactional(propagation = Propagation.REQUIRES_NEW) + override fun get(): List = this.list().map(SettingsConverter::sensitiveWordToSensitiveWordVo) + + @Transactional(propagation = Propagation.REQUIRES_NEW) + override fun add(sensitiveWordAddParam: SensitiveWordAddParam) { + checkSensitiveWord(sensitiveWordAddParam.word!!) + this.save(SettingsConverter.sensitiveWordAddParamToSensitiveWord(sensitiveWordAddParam)) + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + override fun update(sensitiveWordUpdateParam: SensitiveWordUpdateParam) { + this.update(KtUpdateWrapper(SensitiveWord()).set(SensitiveWord::enable, false)) + this.update( + KtUpdateWrapper(SensitiveWord()).`in`(SensitiveWord::id, sensitiveWordUpdateParam.ids) + .set(SensitiveWord::enable, true) + ) + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + override fun delete(id: Long) { + this.removeById(id) + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + override fun checkSensitiveWord(str: String) { + this.list(KtQueryWrapper(SensitiveWord()).eq(SensitiveWord::enable, 1)).map(SensitiveWord::word).forEach { + it ?: let { return@forEach } + + try { + if (Regex(it, RegexOption.IGNORE_CASE).matches(str)) { + throw MatchSensitiveWordException() + } + } catch (e: MatchSensitiveWordException) { + throw e + } catch (_: Exception) { + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsLogServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsLogServiceImpl.kt index ada1265..b7faec6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsLogServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsLogServiceImpl.kt @@ -7,6 +7,12 @@ import top.fatweb.oxygen.api.entity.system.StatisticsLog import top.fatweb.oxygen.api.mapper.system.StatisticsLogMapper import top.fatweb.oxygen.api.service.system.IStatisticsLogService +/** + * Statistics log service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @DS("sqlite") @Service class StatisticsLogServiceImpl : ServiceImpl(), IStatisticsLogService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SensitiveWordVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SensitiveWordVo.kt new file mode 100644 index 0000000..926e4e1 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SensitiveWordVo.kt @@ -0,0 +1,52 @@ +package top.fatweb.oxygen.api.vo.system + +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer +import io.swagger.v3.oas.annotations.media.Schema +import top.fatweb.oxygen.api.entity.system.SensitiveWord + +/** + * Sensitive word settings value object + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(defaultValue = "敏感词设置返回参数") +data class SensitiveWordVo( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @JsonSerialize(using = ToStringSerializer::class) + val id: Long?, + + /** + * Word + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "词") + val word: String?, + + /** + * Use for + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see SensitiveWord.Use + */ + @Schema(description = "用于") + val useFor: Set?, + + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "启用") + val enable: Boolean +) 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 0199971..ce4e4a4 100644 --- a/src/main/resources/db/migration/master/R__Basic_data.sql +++ b/src/main/resources/db/migration/master/R__Basic_data.sql @@ -63,8 +63,10 @@ insert into t_power (id, type_id) (1520101, 4), (1530101, 4), (1530102, 4), + (1530103, 4), (1530301, 4), - (1530302, 4) + (1530302, 4), + (1530303, 4) as new_value on duplicate key update type_id = new_value.type_id; @@ -139,8 +141,10 @@ insert into t_operation(id, name, code, func_id) (1520101, '全部', 'system:log:query:all', 1520100), (1530101, '基础', 'system:settings:query:base', 1530100), (1530102, '邮件', 'system:settings:query:mail', 1530100), + (1530103, '敏感词', 'system:settings:query:sensitive', 1530100), (1530301, '基础', 'system:settings:modify:base', 1530300), - (1530302, '邮件', 'system:settings:modify:mail', 1530300) as new_value + (1530302, '邮件', 'system:settings:modify:mail', 1530300), + (1530303, '敏感词', 'system:settings:modify:sensitive', 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_240103__Add_table_‘t_sensitive_word'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_240103__Add_table_‘t_sensitive_word'.sql new file mode 100644 index 0000000..d078b41 --- /dev/null +++ b/src/main/resources/db/migration/sqlite/V1_0_0_240103__Add_table_‘t_sensitive_word'.sql @@ -0,0 +1,9 @@ +drop table if exists t_sensitive_word; + +create table if not exists t_sensitive_word -- 敏感词表 +( + id integer not null primary key, + word text not null unique, -- 词 + use_for text null, -- 用于 + enable integer not null default 1 -- 启用 +); From 6cc16adc1d7c6d59bd8a49d80489714f259bb818 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 14 Jan 2024 18:59:07 +0800 Subject: [PATCH 170/258] Add ER map --- db/schema.sql | 28 - doc/database.drawio | 982 ++++++++++++++++++ ...1_0_0_231031__Add_table_'t_role_group'.sql | 2 +- 3 files changed, 983 insertions(+), 29 deletions(-) delete mode 100644 db/schema.sql create mode 100644 doc/database.drawio diff --git a/db/schema.sql b/db/schema.sql deleted file mode 100644 index fc482b8..0000000 --- a/db/schema.sql +++ /dev/null @@ -1,28 +0,0 @@ -drop table if exists t_sys_log; -create table t_sys_log -- 系统日志表 -( - id bigint not null, - log_type varchar(50) not null, -- 日志类型 - operate_user_id bigint not null, -- 操作用户 - operate_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f','now')), -- 操作时间 - request_uri varchar(500) default null, -- 请求 URI - request_method varchar(10) default null, -- 请求方式 - request_params text, -- 请求参数 - request_ip varchar(20) not null, -- 请求 IP - request_server_address varchar(50) not null, -- 请求服务器地址 - exception int not null default 0, -- 是否异常 - exception_info text, -- 异常信息 - start_time datetime not null, -- 开始时间 - end_time datetime not null, -- 结束时间 - execute_time bigint default null, -- 执行时间 - user_agent varchar(500) default null -- 用户代理 -); - -drop table if exists t_active; -create table t_active_log -- 用户活跃日志表 -( - id bigint not null, - event varchar(50) not null, -- 事件, - operate_user_id bigint not null, -- 操作用户 - operate_time datetime not null default (strftime('%Y-%m-%d %H:%M:%f','now')) -- 操作时间 -); \ No newline at end of file diff --git a/doc/database.drawio b/doc/database.drawio new file mode 100644 index 0000000..7b56815 --- /dev/null +++ b/doc/database.drawio @@ -0,0 +1,982 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_role_group'.sql b/src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_role_group'.sql index 9492e35..89f1b93 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_role_group'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_role_group'.sql @@ -4,7 +4,7 @@ create table if not exists t_role_group ( id bigint not null primary key, role_id bigint not null comment '角色', - group_id bigint not null comment '群组', + group_id bigint not null comment '用户组', deleted bigint not null default 0, version int not null default 0 ) comment '中间表-角色-用户组'; \ No newline at end of file From 1848ba3abe61f904fe3a38f2bdfc734579ec4b32 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 15 Jan 2024 18:31:11 +0800 Subject: [PATCH 171/258] Add t_tools table (still not complete) --- .../master/V1_0_0_240115__Add_table_'t_tools'.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_tools'.sql diff --git a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_tools'.sql b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_tools'.sql new file mode 100644 index 0000000..b6c4905 --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_tools'.sql @@ -0,0 +1,12 @@ +drop table if exists t_tools; + +create table if not exists t_tools ( + id bigint not null primary key , + name varchar(50) not null comment '工具名', + tool_id varchar(50) not null comment '工具 ID', + description varchar(500) null comment '简介', + version varchar(20) not null comment '版本', + private int not null default 0 comment '私有', + keyword varchar(500) not null comment '关键字', + category varchar(500) not null comment '类别' +) \ No newline at end of file From 251e1278f1155dd4067110a084213281e0416060 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 16 Jan 2024 10:58:42 +0800 Subject: [PATCH 172/258] Rename tables --- doc/database.drawio | 1202 ++++++++--------- .../oxygen/api/entity/permission/Func.kt | 2 +- .../oxygen/api/entity/permission/Group.kt | 2 +- .../oxygen/api/entity/permission/Menu.kt | 2 +- .../oxygen/api/entity/permission/Module.kt | 2 +- .../oxygen/api/entity/permission/Operation.kt | 2 +- .../oxygen/api/entity/permission/Power.kt | 2 +- .../oxygen/api/entity/permission/PowerRole.kt | 2 +- .../oxygen/api/entity/permission/PowerType.kt | 2 +- .../oxygen/api/entity/permission/Role.kt | 2 +- .../oxygen/api/entity/permission/RoleGroup.kt | 2 +- .../oxygen/api/entity/permission/User.kt | 2 +- .../oxygen/api/entity/permission/UserGroup.kt | 2 +- .../oxygen/api/entity/permission/UserInfo.kt | 2 +- .../oxygen/api/entity/permission/UserRole.kt | 2 +- .../oxygen/api/entity/system/EventLog.kt | 2 +- .../oxygen/api/entity/system/SensitiveWord.kt | 2 +- .../oxygen/api/entity/system/StatisticsLog.kt | 2 +- .../fatweb/oxygen/api/entity/system/SysLog.kt | 2 +- .../system/impl/SensitiveWordServiceImpl.kt | 2 - .../db/migration/master/R__Basic_data.sql | 14 +- .../V1_0_0_231019__Add_table_'t_s_user'.sql | 25 + .../V1_0_0_231019__Add_table_'t_user'.sql | 25 - ...1_0_0_231023__Add_table_'t_power_type'.sql | 7 - ...0_0_231023__Add_table_'t_s_power_type'.sql | 7 + .../V1_0_0_231024__Add_table_'t_power'.sql | 7 - .../V1_0_0_231024__Add_table_'t_s_power'.sql | 7 + ...> V1_0_0_231025__Add_table_'t_s_menu'.sql} | 6 +- ...> V1_0_0_231026__Add_table_'t_s_func'.sql} | 6 +- ...V1_0_0_231027__Add_table_'t_operation'.sql | 9 - ..._0_0_231027__Add_table_'t_s_operation'.sql | 9 + .../V1_0_0_231028__Add_table_'t_group'.sql | 13 - .../V1_0_0_231028__Add_table_'t_s_group'.sql | 13 + ..._0_231029__Add_table_'t_r_user_group'.sql} | 6 +- .../V1_0_0_231030__Add_table_'t_role'.sql | 13 - .../V1_0_0_231030__Add_table_'t_s_role'.sql | 13 + ..._0_231031__Add_table_'t_r_role_group'.sql} | 6 +- ...0_0_231101__Add_table_'t_r_user_role'.sql} | 6 +- ..._0_231102__Add_table_'t_r_power_role'.sql} | 6 +- .../V1_0_0_231103__Add_table_'t_module'.sql | 7 - .../V1_0_0_231103__Add_table_'t_s_module'.sql | 7 + ...0_0_231104__Add_table_'t_s_user_info'.sql} | 10 +- ...240103__Add_table_‘t_s_sensitive_word'.sql | 12 + ...1_0_0_231212__Add_table_'t_l_sys_log'.sql} | 4 +- ...0_0_231213__Add_table_'t_l_event_log'.sql} | 4 +- ...31214__Add_table_'t_l_statistics_log'.sql} | 4 +- ...0_240103__Add_table_‘t_sensitive_word'.sql | 9 - .../mapper/permission/GroupMapper.xml | 78 +- .../mapper/permission/RoleMapper.xml | 129 +- .../mapper/permission/UserMapper.xml | 402 +++--- .../resources/mapper/system/SysLogMapper.xml | 42 +- 51 files changed, 1074 insertions(+), 1072 deletions(-) create mode 100644 src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_s_user'.sql delete mode 100644 src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_user'.sql delete mode 100644 src/main/resources/db/migration/master/V1_0_0_231023__Add_table_'t_power_type'.sql create mode 100644 src/main/resources/db/migration/master/V1_0_0_231023__Add_table_'t_s_power_type'.sql delete mode 100644 src/main/resources/db/migration/master/V1_0_0_231024__Add_table_'t_power'.sql create mode 100644 src/main/resources/db/migration/master/V1_0_0_231024__Add_table_'t_s_power'.sql rename src/main/resources/db/migration/master/{V1_0_0_231025__Add_table_'t_menu'.sql => V1_0_0_231025__Add_table_'t_s_menu'.sql} (73%) rename src/main/resources/db/migration/master/{V1_0_0_231026__Add_table_'t_func'.sql => V1_0_0_231026__Add_table_'t_s_func'.sql} (68%) delete mode 100644 src/main/resources/db/migration/master/V1_0_0_231027__Add_table_'t_operation'.sql create mode 100644 src/main/resources/db/migration/master/V1_0_0_231027__Add_table_'t_s_operation'.sql delete mode 100644 src/main/resources/db/migration/master/V1_0_0_231028__Add_table_'t_group'.sql create mode 100644 src/main/resources/db/migration/master/V1_0_0_231028__Add_table_'t_s_group'.sql rename src/main/resources/db/migration/master/{V1_0_0_231029__Add_table_'t_user_group'.sql => V1_0_0_231029__Add_table_'t_r_user_group'.sql} (63%) delete mode 100644 src/main/resources/db/migration/master/V1_0_0_231030__Add_table_'t_role'.sql create mode 100644 src/main/resources/db/migration/master/V1_0_0_231030__Add_table_'t_s_role'.sql rename src/main/resources/db/migration/master/{V1_0_0_231031__Add_table_'t_role_group'.sql => V1_0_0_231031__Add_table_'t_r_role_group'.sql} (63%) rename src/main/resources/db/migration/master/{V1_0_0_231101__Add_table_'t_user_role'.sql => V1_0_0_231101__Add_table_'t_r_user_role'.sql} (63%) rename src/main/resources/db/migration/master/{V1_0_0_231102__Add_table_'t_power_role'.sql => V1_0_0_231102__Add_table_'t_r_power_role'.sql} (64%) delete mode 100644 src/main/resources/db/migration/master/V1_0_0_231103__Add_table_'t_module'.sql create mode 100644 src/main/resources/db/migration/master/V1_0_0_231103__Add_table_'t_s_module'.sql rename src/main/resources/db/migration/master/{V1_0_0_231104__Add_table_'t_user_info'.sql => V1_0_0_231104__Add_table_'t_s_user_info'.sql} (68%) create mode 100644 src/main/resources/db/migration/master/V1_0_0_240103__Add_table_‘t_s_sensitive_word'.sql rename src/main/resources/db/migration/sqlite/{V1_0_0_231212__Add_table_'t_sys_log'.sql => V1_0_0_231212__Add_table_'t_l_sys_log'.sql} (94%) rename src/main/resources/db/migration/sqlite/{V1_0_0_231213__Add_table_'t_event_log'.sql => V1_0_0_231213__Add_table_'t_l_event_log'.sql} (77%) rename src/main/resources/db/migration/sqlite/{V1_0_0_231214__Add_table_'t_statistics_log'.sql => V1_0_0_231214__Add_table_'t_l_statistics_log'.sql} (74%) delete mode 100644 src/main/resources/db/migration/sqlite/V1_0_0_240103__Add_table_‘t_sensitive_word'.sql diff --git a/doc/database.drawio b/doc/database.drawio index 7b56815..007b0d0 100644 --- a/doc/database.drawio +++ b/doc/database.drawio @@ -1,871 +1,871 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - - + + - + + + + - - - + + + - - + + - - - - + - - - + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - + + + - - - + + + - + - - - + + + - - - + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - + + - - - - + - - - + + + - - + + - + - - - + + + - - + + - + - - - + + + - - + + - - - - + - - - + + + - - + + - + + + + - - - + + + - - + + - + - - - + + + - - + + - + - - - + + + - - + + - + + + + - - - + + + - - + + - + - - - + + + - - + + - + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -874,7 +874,7 @@ - + @@ -883,7 +883,7 @@ - + @@ -892,49 +892,49 @@ - + - + - + - + - + - + - + - + - + @@ -943,7 +943,7 @@ - + @@ -952,7 +952,7 @@ - + @@ -961,13 +961,13 @@ - + - + diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Func.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Func.kt index 78014e0..61fa701 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Func.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Func.kt @@ -11,7 +11,7 @@ import java.io.Serializable * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_func") +@TableName("t_s_func") class Func : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Group.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Group.kt index 480f857..5d779ad 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Group.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Group.kt @@ -10,7 +10,7 @@ import java.time.LocalDateTime * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_group") +@TableName("t_s_group") class Group : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Menu.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Menu.kt index a3f982e..d81e235 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Menu.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Menu.kt @@ -11,7 +11,7 @@ import java.io.Serializable * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_menu") +@TableName("t_s_menu") class Menu : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Module.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Module.kt index eac5aa7..fa26a28 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Module.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Module.kt @@ -11,7 +11,7 @@ import java.io.Serializable * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_module") +@TableName("t_s_module") class Module : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Operation.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Operation.kt index 05740b4..c111ce6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Operation.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Operation.kt @@ -11,7 +11,7 @@ import java.io.Serializable * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_operation") +@TableName("t_s_operation") class Operation : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Power.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Power.kt index 3ebe80a..4f1a7a0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Power.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Power.kt @@ -11,7 +11,7 @@ import java.io.Serializable * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_power") +@TableName("t_s_power") class Power : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerRole.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerRole.kt index 915eb5a..d99b9a1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerRole.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerRole.kt @@ -9,7 +9,7 @@ import java.io.Serializable * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_power_role") +@TableName("t_r_power_role") class PowerRole : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerType.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerType.kt index 676588c..c2be1e4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerType.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerType.kt @@ -11,7 +11,7 @@ import java.io.Serializable * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_power_type") +@TableName("t_s_power_type") class PowerType : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Role.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Role.kt index 32ba4fe..e5175fc 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Role.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/Role.kt @@ -10,7 +10,7 @@ import java.time.LocalDateTime * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_role") +@TableName("t_s_role") class Role : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RoleGroup.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RoleGroup.kt index 149e31a..a6363f2 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RoleGroup.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RoleGroup.kt @@ -9,7 +9,7 @@ import java.io.Serializable * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_role_group") +@TableName("t_r_role_group") class RoleGroup : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/User.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/User.kt index 67b6592..905178f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/User.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/User.kt @@ -10,7 +10,7 @@ import java.time.LocalDateTime * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_user") +@TableName("t_s_user") class User() : Serializable { constructor(id: Long?, username: String, password: String, enable: Boolean = true) : this() { this.id = id diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserGroup.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserGroup.kt index ae8c102..408a75c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserGroup.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserGroup.kt @@ -9,7 +9,7 @@ import java.io.Serializable * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_user_group") +@TableName("t_r_user_group") class UserGroup : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserInfo.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserInfo.kt index f1cb26e..8aa8e24 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserInfo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserInfo.kt @@ -10,7 +10,7 @@ import java.time.LocalDateTime * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_user_info") +@TableName("t_s_user_info") class UserInfo : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserRole.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserRole.kt index de09ff6..cc4b99b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserRole.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserRole.kt @@ -9,7 +9,7 @@ import java.io.Serializable * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_user_role") +@TableName("t_r_user_role") class UserRole : Serializable { /** * ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/system/EventLog.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/EventLog.kt index a719457..c689547 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/system/EventLog.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/EventLog.kt @@ -15,7 +15,7 @@ import java.time.LocalDateTime * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_event_log") +@TableName("t_l_event_log") class EventLog : Serializable { enum class Event(@field:EnumValue @field:JsonValue val code: String) { LOGIN("LOGIN"), LOGOUT("LOGOUT"), REGISTER("REGISTER"), VERIFY("VERIFY"), API("API") diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SensitiveWord.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SensitiveWord.kt index a38413a..a024d6e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SensitiveWord.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SensitiveWord.kt @@ -14,7 +14,7 @@ import java.io.Serializable * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_sensitive_word", autoResultMap = true) +@TableName("t_s_sensitive_word", autoResultMap = true) class SensitiveWord : Serializable { enum class Use(@field:EnumValue @field:JsonValue val code: String) { USERNAME("USERNAME"), TITLE("TITLE"); diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/system/StatisticsLog.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/StatisticsLog.kt index 7ba87a6..165a2c4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/system/StatisticsLog.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/StatisticsLog.kt @@ -15,7 +15,7 @@ import java.time.LocalDateTime * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_statistics_log") +@TableName("t_l_statistics_log") class StatisticsLog : Serializable { enum class KeyItem(@field:EnumValue @field:JsonValue val code: String) { ONLINE_USERS_COUNT("ONLINE_USER_COUNT") diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SysLog.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SysLog.kt index b557357..b17e2fa 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SysLog.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/system/SysLog.kt @@ -15,7 +15,7 @@ import java.time.LocalDateTime * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@TableName("t_sys_log") +@TableName("t_l_sys_log") class SysLog : Serializable { /** * Log type enum diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt index f95a233..e279160 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt @@ -1,6 +1,5 @@ package top.fatweb.oxygen.api.service.system.impl -import com.baomidou.dynamic.datasource.annotation.DS import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl @@ -22,7 +21,6 @@ import top.fatweb.oxygen.api.vo.system.SensitiveWordVo * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@DS("sqlite") @Service class SensitiveWordServiceImpl : ServiceImpl(), ISensitiveWordService { @Transactional(propagation = Propagation.REQUIRES_NEW) 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 ce4e4a4..71f9147 100644 --- a/src/main/resources/db/migration/master/R__Basic_data.sql +++ b/src/main/resources/db/migration/master/R__Basic_data.sql @@ -1,11 +1,11 @@ -insert into t_power_type (id, name) +insert into t_s_power_type (id, name) values (1, 'module'), (2, 'menu'), (3, 'func'), (4, 'operation') as new_value on duplicate key update name = new_value.name; -insert into t_power (id, type_id) +insert into t_s_power (id, type_id) values (1000000, 1), (1990000, 2), (1010000, 2), @@ -70,11 +70,11 @@ insert into t_power (id, type_id) as new_value on duplicate key update type_id = new_value.type_id; -insert into t_module (id, name) +insert into t_s_module (id, name) values (1000000, '系统') as new_value -on duplicate key update name = new_value.name; +on duplicate key update name = new_value.name; -insert into t_menu (id, name, url, parent_id, module_id) +insert into t_s_menu (id, name, url, parent_id, module_id) values (1990000, '系统管理', '/system', null, 1000000), (1010000, '用户管理', '/system/user', 1990000, 1000000), (1020000, '角色管理', '/system/role', 1990000, 1000000), @@ -87,7 +87,7 @@ on duplicate key update name =new_value.name, url =new_value.url, parent_id =new_value.parent_id; -insert into t_func(id, name, menu_id, parent_id) +insert into t_s_func(id, name, menu_id, parent_id) values (1010100, '查询', 1010000, null), (1010200, '增加', 1010000, null), (1010300, '修改', 1010000, null), @@ -109,7 +109,7 @@ on duplicate key update name = new_value.name, menu_id = new_value.menu_id, parent_id = new_value.parent_id; -insert into t_operation(id, name, code, func_id) +insert into t_s_operation(id, name, code, func_id) values (1010101, '单个', 'system:user:query:one', 1010100), (1010102, '全部', 'system:user:query:all', 1010100), (1010103, '列表', 'system:user:query:list', 1010100), diff --git a/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_s_user'.sql b/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_s_user'.sql new file mode 100644 index 0000000..9e2287d --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_s_user'.sql @@ -0,0 +1,25 @@ +drop table if exists t_s_user; + +create table if not exists t_s_user +( + id bigint not null primary key, + username varchar(20) not null comment '用户名', + password char(70) not null comment '密码', + verify varchar(144) null comment '验证邮箱', + forget varchar(144) null comment '忘记密码', + locking int not null comment '锁定', + expiration datetime comment '过期时间', + credentials_expiration datetime comment '认证过期时间', + enable int not null comment '启用', + current_login_time datetime comment '当前登录时间', + current_login_ip varchar(128) comment '当前登录 IP', + last_login_time datetime comment '上次登录时间', + last_login_ip varchar(128) comment '上次登录 IP', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, + constraint t_s_user_unique_username unique (username, deleted), + constraint t_s_user_unique_verify unique (verify, deleted), + constraint t_s_user_unique_forget unique (forget, deleted) +) comment '系统-用户表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_user'.sql b/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_user'.sql deleted file mode 100644 index f00170d..0000000 --- a/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_user'.sql +++ /dev/null @@ -1,25 +0,0 @@ -drop table if exists t_user; - -create table if not exists t_user -( - id bigint not null primary key, - username varchar(20) not null comment '用户名', - password char(70) not null comment '密码', - verify varchar(144) null comment '验证邮箱', - forget varchar(144) null comment '忘记密码', - locking int not null comment '锁定', - expiration datetime comment '过期时间', - credentials_expiration datetime comment '认证过期时间', - enable int not null comment '启用', - current_login_time datetime comment '当前登录时间', - current_login_ip varchar(128) comment '当前登录 IP', - last_login_time datetime comment '上次登录时间', - last_login_ip varchar(128) comment '上次登录 IP', - create_time datetime not null default (utc_timestamp()) comment '创建时间', - update_time datetime not null default (utc_timestamp()) comment '修改时间', - deleted bigint not null default 0, - version int not null default 0, - constraint t_user_unique_username unique (username, deleted), - constraint t_user_unique_verify unique (verify, deleted), - constraint t_user_unique_forget unique (forget, deleted) -) comment '用户表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231023__Add_table_'t_power_type'.sql b/src/main/resources/db/migration/master/V1_0_0_231023__Add_table_'t_power_type'.sql deleted file mode 100644 index 0ac9660..0000000 --- a/src/main/resources/db/migration/master/V1_0_0_231023__Add_table_'t_power_type'.sql +++ /dev/null @@ -1,7 +0,0 @@ -drop table if exists t_power_type; - -create table if not exists t_power_type -( - id bigint not null primary key, - name varchar(50) not null comment '权限类型名' -) comment '权限类型表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231023__Add_table_'t_s_power_type'.sql b/src/main/resources/db/migration/master/V1_0_0_231023__Add_table_'t_s_power_type'.sql new file mode 100644 index 0000000..8544453 --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_231023__Add_table_'t_s_power_type'.sql @@ -0,0 +1,7 @@ +drop table if exists t_s_power_type; + +create table if not exists t_s_power_type +( + id bigint not null primary key, + name varchar(50) not null comment '权限类型名' +) comment '系统-权限类型表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231024__Add_table_'t_power'.sql b/src/main/resources/db/migration/master/V1_0_0_231024__Add_table_'t_power'.sql deleted file mode 100644 index c6f1135..0000000 --- a/src/main/resources/db/migration/master/V1_0_0_231024__Add_table_'t_power'.sql +++ /dev/null @@ -1,7 +0,0 @@ -drop table if exists t_power; - -create table if not exists t_power -( - id bigint not null primary key, - type_id int not null comment '权限类型' -) comment '权限表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231024__Add_table_'t_s_power'.sql b/src/main/resources/db/migration/master/V1_0_0_231024__Add_table_'t_s_power'.sql new file mode 100644 index 0000000..1407a9b --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_231024__Add_table_'t_s_power'.sql @@ -0,0 +1,7 @@ +drop table if exists t_s_power; + +create table if not exists t_s_power +( + id bigint not null primary key, + type_id int not null comment '权限类型' +) comment '系统-权限表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231025__Add_table_'t_menu'.sql b/src/main/resources/db/migration/master/V1_0_0_231025__Add_table_'t_s_menu'.sql similarity index 73% rename from src/main/resources/db/migration/master/V1_0_0_231025__Add_table_'t_menu'.sql rename to src/main/resources/db/migration/master/V1_0_0_231025__Add_table_'t_s_menu'.sql index 42135de..6b8de95 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231025__Add_table_'t_menu'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231025__Add_table_'t_s_menu'.sql @@ -1,10 +1,10 @@ -drop table if exists t_menu; +drop table if exists t_s_menu; -create table if not exists t_menu +create table if not exists t_s_menu ( id bigint not null primary key, name varchar(30) not null comment ' 菜单名', url varchar(100) null comment 'URL', parent_id bigint null comment '父ID', module_id bigint not null comment '模块ID' -) comment '菜单表'; \ No newline at end of file +) comment '系统-菜单表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231026__Add_table_'t_func'.sql b/src/main/resources/db/migration/master/V1_0_0_231026__Add_table_'t_s_func'.sql similarity index 68% rename from src/main/resources/db/migration/master/V1_0_0_231026__Add_table_'t_func'.sql rename to src/main/resources/db/migration/master/V1_0_0_231026__Add_table_'t_s_func'.sql index 4951d9f..0f5f33f 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231026__Add_table_'t_func'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231026__Add_table_'t_s_func'.sql @@ -1,9 +1,9 @@ -drop table if exists t_func; +drop table if exists t_s_func; -create table if not exists t_func +create table if not exists t_s_func ( id bigint not null primary key, name varchar(100) not null comment '功能名', parent_id bigint null comment '父ID', menu_id bigint not null comment '菜单ID' -) comment '功能表'; \ No newline at end of file +) comment '系统-功能表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231027__Add_table_'t_operation'.sql b/src/main/resources/db/migration/master/V1_0_0_231027__Add_table_'t_operation'.sql deleted file mode 100644 index 4ffe588..0000000 --- a/src/main/resources/db/migration/master/V1_0_0_231027__Add_table_'t_operation'.sql +++ /dev/null @@ -1,9 +0,0 @@ -drop table if exists t_operation; - -create table if not exists t_operation -( - id bigint not null primary key, - name varchar(50) not null comment '操作名', - code varchar(50) null comment '操作编码', - func_id bigint not null comment '功能ID' -) comment '操作表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231027__Add_table_'t_s_operation'.sql b/src/main/resources/db/migration/master/V1_0_0_231027__Add_table_'t_s_operation'.sql new file mode 100644 index 0000000..a527025 --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_231027__Add_table_'t_s_operation'.sql @@ -0,0 +1,9 @@ +drop table if exists t_s_operation; + +create table if not exists t_s_operation +( + id bigint not null primary key, + name varchar(50) not null comment '操作名', + code varchar(50) null comment '操作编码', + func_id bigint not null comment '功能ID' +) comment '系统-操作表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231028__Add_table_'t_group'.sql b/src/main/resources/db/migration/master/V1_0_0_231028__Add_table_'t_group'.sql deleted file mode 100644 index 9d0c6fb..0000000 --- a/src/main/resources/db/migration/master/V1_0_0_231028__Add_table_'t_group'.sql +++ /dev/null @@ -1,13 +0,0 @@ -drop table if exists t_group; - -create table if not exists t_group -( - id bigint not null primary key, - name varchar(30) not null comment '用户组名', - enable int not null comment '启用', - create_time datetime not null default (utc_timestamp()) comment '创建时间', - update_time datetime not null default (utc_timestamp()) comment '修改时间', - deleted bigint not null default 0, - version int not null default 0, - constraint t_group_unique unique (name, deleted) -) comment '用户组表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231028__Add_table_'t_s_group'.sql b/src/main/resources/db/migration/master/V1_0_0_231028__Add_table_'t_s_group'.sql new file mode 100644 index 0000000..6168a2b --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_231028__Add_table_'t_s_group'.sql @@ -0,0 +1,13 @@ +drop table if exists t_s_group; + +create table if not exists t_s_group +( + id bigint not null primary key, + name varchar(30) not null comment '用户组名', + enable int not null comment '启用', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, + constraint t_s_group_unique unique (name, deleted) +) comment '系统-用户组表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231029__Add_table_'t_user_group'.sql b/src/main/resources/db/migration/master/V1_0_0_231029__Add_table_'t_r_user_group'.sql similarity index 63% rename from src/main/resources/db/migration/master/V1_0_0_231029__Add_table_'t_user_group'.sql rename to src/main/resources/db/migration/master/V1_0_0_231029__Add_table_'t_r_user_group'.sql index 27ede64..969c3a7 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231029__Add_table_'t_user_group'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231029__Add_table_'t_r_user_group'.sql @@ -1,10 +1,10 @@ -drop table if exists t_user_group; +drop table if exists t_r_user_group; -create table if not exists t_user_group +create table if not exists t_r_user_group ( id bigint not null primary key, user_id bigint not null comment '用户', group_id bigint not null comment '用户组', deleted bigint not null default 0, version int not null default 0 -) comment '中间表-用户-用户组'; \ No newline at end of file +) comment '中间表-系统-用户-用户组'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231030__Add_table_'t_role'.sql b/src/main/resources/db/migration/master/V1_0_0_231030__Add_table_'t_role'.sql deleted file mode 100644 index 98d96de..0000000 --- a/src/main/resources/db/migration/master/V1_0_0_231030__Add_table_'t_role'.sql +++ /dev/null @@ -1,13 +0,0 @@ -drop table if exists t_role; - -create table if not exists t_role -( - id bigint not null primary key, - name varchar(20) not null comment '角色名', - enable int not null comment '启用', - create_time datetime not null default (utc_timestamp()) comment '创建时间', - update_time datetime not null default (utc_timestamp()) comment '修改时间', - deleted bigint not null default 0, - version int not null default 0, - constraint t_role_unique unique (name, deleted) -) comment '角色表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231030__Add_table_'t_s_role'.sql b/src/main/resources/db/migration/master/V1_0_0_231030__Add_table_'t_s_role'.sql new file mode 100644 index 0000000..d553aea --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_231030__Add_table_'t_s_role'.sql @@ -0,0 +1,13 @@ +drop table if exists t_s_role; + +create table if not exists t_s_role +( + id bigint not null primary key, + name varchar(20) not null comment '角色名', + enable int not null comment '启用', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, + constraint t_s_role_unique unique (name, deleted) +) comment '系统-角色表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_role_group'.sql b/src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_r_role_group'.sql similarity index 63% rename from src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_role_group'.sql rename to src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_r_role_group'.sql index 89f1b93..ba976d0 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_role_group'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231031__Add_table_'t_r_role_group'.sql @@ -1,10 +1,10 @@ -drop table if exists t_role_group; +drop table if exists t_r_role_group; -create table if not exists t_role_group +create table if not exists t_r_role_group ( id bigint not null primary key, role_id bigint not null comment '角色', group_id bigint not null comment '用户组', deleted bigint not null default 0, version int not null default 0 -) comment '中间表-角色-用户组'; \ No newline at end of file +) comment '中间表-系统-角色-用户组'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231101__Add_table_'t_user_role'.sql b/src/main/resources/db/migration/master/V1_0_0_231101__Add_table_'t_r_user_role'.sql similarity index 63% rename from src/main/resources/db/migration/master/V1_0_0_231101__Add_table_'t_user_role'.sql rename to src/main/resources/db/migration/master/V1_0_0_231101__Add_table_'t_r_user_role'.sql index 27d674d..8703912 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231101__Add_table_'t_user_role'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231101__Add_table_'t_r_user_role'.sql @@ -1,10 +1,10 @@ -drop table if exists t_user_role; +drop table if exists t_r_user_role; -create table if not exists t_user_role +create table if not exists t_r_user_role ( id bigint not null primary key, user_id bigint not null comment '用户', role_id bigint not null comment '角色', deleted bigint not null default 0, version int not null default 0 -) comment '中间表-用户-角色'; \ No newline at end of file +) comment '中间表-系统-用户-角色'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231102__Add_table_'t_power_role'.sql b/src/main/resources/db/migration/master/V1_0_0_231102__Add_table_'t_r_power_role'.sql similarity index 64% rename from src/main/resources/db/migration/master/V1_0_0_231102__Add_table_'t_power_role'.sql rename to src/main/resources/db/migration/master/V1_0_0_231102__Add_table_'t_r_power_role'.sql index 854e78b..81bc1cc 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231102__Add_table_'t_power_role'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231102__Add_table_'t_r_power_role'.sql @@ -1,10 +1,10 @@ -drop table if exists t_power_role; +drop table if exists t_r_power_role; -create table if not exists t_power_role +create table if not exists t_r_power_role ( id bigint not null primary key, power_id bigint not null comment '权限', role_id bigint not null comment '角色', deleted bigint not null default 0, version int not null default 0 -) comment '中间表-权限-角色'; \ No newline at end of file +) comment '中间表-系统-权限-角色'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231103__Add_table_'t_module'.sql b/src/main/resources/db/migration/master/V1_0_0_231103__Add_table_'t_module'.sql deleted file mode 100644 index a2e36b9..0000000 --- a/src/main/resources/db/migration/master/V1_0_0_231103__Add_table_'t_module'.sql +++ /dev/null @@ -1,7 +0,0 @@ -drop table if exists t_module; - -create table if not exists t_module -( - id bigint not null primary key, - name varchar(100) not null comment '模块名' -) comment '模块表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231103__Add_table_'t_s_module'.sql b/src/main/resources/db/migration/master/V1_0_0_231103__Add_table_'t_s_module'.sql new file mode 100644 index 0000000..b859553 --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_231103__Add_table_'t_s_module'.sql @@ -0,0 +1,7 @@ +drop table if exists t_s_module; + +create table if not exists t_s_module +( + id bigint not null primary key, + name varchar(100) not null comment '模块名' +) comment '系统-模块表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql b/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_s_user_info'.sql similarity index 68% rename from src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql rename to src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_s_user_info'.sql index 75c3232..b2599f3 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_user_info'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231104__Add_table_'t_s_user_info'.sql @@ -1,6 +1,6 @@ -drop table if exists t_user_info; +drop table if exists t_s_user_info; -create table if not exists t_user_info +create table if not exists t_s_user_info ( id bigint not null primary key, user_id bigint not null comment '用户ID', @@ -11,6 +11,6 @@ create table if not exists t_user_info update_time datetime not null default (utc_timestamp()) comment '修改时间', deleted bigint not null default 0, version int not null default 0, - constraint t_user_info_unique_user_id unique (user_id, deleted), - constraint t_user_info_unique_email unique (email, deleted) -) comment '用户资料表'; \ No newline at end of file + constraint t_s_user_info_unique_user_id unique (user_id, deleted), + constraint t_s_user_info_unique_email unique (email, deleted) +) comment '系统-用户资料表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240103__Add_table_‘t_s_sensitive_word'.sql b/src/main/resources/db/migration/master/V1_0_0_240103__Add_table_‘t_s_sensitive_word'.sql new file mode 100644 index 0000000..5177ab7 --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_240103__Add_table_‘t_s_sensitive_word'.sql @@ -0,0 +1,12 @@ +drop table if exists t_s_sensitive_word; + +create table if not exists t_s_sensitive_word +( + id bigint not null primary key, + word varchar(400) not null comment '词', + use_for varchar(50) null comment '用于', + enable int not null default 1 comment '启用', + deleted bigint not null default 0, + version int not null default 0, + constraint t_s_sensitive_word_unique_word unique (word, deleted) +) comment '系统-敏感词表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_sys_log'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_l_sys_log'.sql similarity index 94% rename from src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_sys_log'.sql rename to src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_l_sys_log'.sql index 87bd930..a49c66c 100644 --- a/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_sys_log'.sql +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_l_sys_log'.sql @@ -1,6 +1,6 @@ -drop table if exists t_sys_log; +drop table if exists t_l_sys_log; -create table t_sys_log -- 系统日志表 +create table t_l_sys_log -- 本地-系统日志表 ( id integer not null, log_type text not null, -- 日志类型 diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_event_log'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_l_event_log'.sql similarity index 77% rename from src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_event_log'.sql rename to src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_l_event_log'.sql index e921a6c..d729c85 100644 --- a/src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_event_log'.sql +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231213__Add_table_'t_l_event_log'.sql @@ -1,6 +1,6 @@ -drop table if exists t_event_log; +drop table if exists t_l_event_log; -create table if not exists t_event_log -- 事件日志表 +create table if not exists t_l_event_log -- 本地-事件日志表 ( id integer not null primary key, event text not null, -- 事件, diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics_log'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_l_statistics_log'.sql similarity index 74% rename from src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics_log'.sql rename to src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_l_statistics_log'.sql index 5228202..2fb9390 100644 --- a/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_statistics_log'.sql +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_l_statistics_log'.sql @@ -1,6 +1,6 @@ -drop table if exists t_statistics_log; +drop table if exists t_l_statistics_log; -create table if not exists t_statistics_log -- 统计日志表 +create table if not exists t_l_statistics_log -- 本地-统计日志表 ( id integer not null primary key, key text not null, -- 记录键 diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_240103__Add_table_‘t_sensitive_word'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_240103__Add_table_‘t_sensitive_word'.sql deleted file mode 100644 index d078b41..0000000 --- a/src/main/resources/db/migration/sqlite/V1_0_0_240103__Add_table_‘t_sensitive_word'.sql +++ /dev/null @@ -1,9 +0,0 @@ -drop table if exists t_sensitive_word; - -create table if not exists t_sensitive_word -- 敏感词表 -( - id integer not null primary key, - word text not null unique, -- 词 - use_for text null, -- 用于 - enable integer not null default 1 -- 启用 -); diff --git a/src/main/resources/mapper/permission/GroupMapper.xml b/src/main/resources/mapper/permission/GroupMapper.xml index 24d6e8a..0523c54 100644 --- a/src/main/resources/mapper/permission/GroupMapper.xml +++ b/src/main/resources/mapper/permission/GroupMapper.xml @@ -3,16 +3,16 @@ diff --git a/src/main/resources/mapper/permission/RoleMapper.xml b/src/main/resources/mapper/permission/RoleMapper.xml index eaa0e6a..c19bb24 100644 --- a/src/main/resources/mapper/permission/RoleMapper.xml +++ b/src/main/resources/mapper/permission/RoleMapper.xml @@ -3,16 +3,16 @@ @@ -104,6 +104,7 @@ - + diff --git a/src/main/resources/mapper/permission/UserMapper.xml b/src/main/resources/mapper/permission/UserMapper.xml index 5488731..4e3770b 100644 --- a/src/main/resources/mapper/permission/UserMapper.xml +++ b/src/main/resources/mapper/permission/UserMapper.xml @@ -2,121 +2,121 @@ - select t_sys_log.id as sys_log_id, - t_sys_log.log_type as sys_log_log_type, - t_sys_log.operate_user_id as sys_log_operate_user_id, - t_sys_log.operate_time as sys_log_operate_time, - t_sys_log.request_uri as sys_log_request_uri, - t_sys_log.request_method as sys_log_request_method, - t_sys_log.request_params as sys_log_request_params, - t_sys_log.request_ip as sys_log_request_ip, - t_sys_log.request_server_address as sys_log_request_server_address, - t_sys_log.exception as sys_log_exception, - t_sys_log.exception_info as sys_log_exception_info, - t_sys_log.start_time as sys_log_start_time, - t_sys_log.end_time as sys_log_end_time, - t_sys_log.execute_time as sys_log_execute_time, - t_sys_log.user_agent as sys_log_user_agent - from t_sys_log + select t_l_sys_log.id as sys_log_id, + t_l_sys_log.log_type as sys_log_log_type, + t_l_sys_log.operate_user_id as sys_log_operate_user_id, + t_l_sys_log.operate_time as sys_log_operate_time, + t_l_sys_log.request_uri as sys_log_request_uri, + t_l_sys_log.request_method as sys_log_request_method, + t_l_sys_log.request_params as sys_log_request_params, + t_l_sys_log.request_ip as sys_log_request_ip, + t_l_sys_log.request_server_address as sys_log_request_server_address, + t_l_sys_log.exception as sys_log_exception, + t_l_sys_log.exception_info as sys_log_exception_info, + t_l_sys_log.start_time as sys_log_start_time, + t_l_sys_log.end_time as sys_log_end_time, + t_l_sys_log.execute_time as sys_log_execute_time, + t_l_sys_log.user_agent as sys_log_user_agent + from t_l_sys_log - #{item} - #{item} - and ((t_sys_log.request_server_address || t_sys_log.request_uri || - (case when length(t_sys_log.request_params) != 0 then '?' || t_sys_log.request_params else '' end)) + and ((t_l_sys_log.request_server_address || t_l_sys_log.request_uri || + (case when length(t_l_sys_log.request_params) != 0 then '?' || t_l_sys_log.request_params else '' end)) like #{searchRequestUrl}) - and t_sys_log.start_time between #{searchStartTime} and #{searchEndTime} + and t_l_sys_log.start_time between #{searchStartTime} and #{searchEndTime} From 705449c5b1b1dfd808ba2de3ca52e099d9d78055 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 16 Jan 2024 16:12:47 +0800 Subject: [PATCH 173/258] Rename classes --- .../{PowerRole.kt => RPowerRole.kt} | 4 +- .../{RoleGroup.kt => RRoleGroup.kt} | 4 +- .../{UserGroup.kt => RUserGroup.kt} | 4 +- .../permission/{UserRole.kt => RUserRole.kt} | 4 +- ...PowerRoleMapper.kt => RPowerRoleMapper.kt} | 6 +-- ...RoleGroupMapper.kt => RRoleGroupMapper.kt} | 6 +-- ...UserGroupMapper.kt => RUserGroupMapper.kt} | 6 +-- .../{UserRoleMapper.kt => RUserRoleMapper.kt} | 6 +-- ...erRoleService.kt => IRPowerRoleService.kt} | 6 +-- ...eGroupService.kt => IRRoleGroupService.kt} | 6 +-- ...rGroupService.kt => IRUserGroupService.kt} | 6 +-- ...serRoleService.kt => IRUserRoleService.kt} | 6 +-- .../permission/impl/GroupServiceImpl.kt | 28 +++++----- .../permission/impl/PowerRoleServiceImpl.kt | 20 ------- .../permission/impl/RPowerRoleServiceImpl.kt | 20 +++++++ .../permission/impl/RRoleGroupServiceImpl.kt | 20 +++++++ .../permission/impl/RUserGroupServiceImpl.kt | 20 +++++++ .../permission/impl/RUserRoleServiceImpl.kt | 19 +++++++ .../permission/impl/RoleGroupServiceImpl.kt | 20 ------- .../permission/impl/RoleServiceImpl.kt | 26 +++++----- .../permission/impl/UserGroupServiceImpl.kt | 20 ------- .../permission/impl/UserRoleServiceImpl.kt | 19 ------- .../permission/impl/UserServiceImpl.kt | 52 +++++++++---------- .../mapper/permission/PowerRoleMapper.xml | 2 +- .../mapper/permission/RoleGroupMapper.xml | 2 +- .../mapper/permission/UserGroupMapper.xml | 2 +- .../mapper/permission/UserRoleMapper.xml | 2 +- 27 files changed, 168 insertions(+), 168 deletions(-) rename src/main/kotlin/top/fatweb/oxygen/api/entity/permission/{PowerRole.kt => RPowerRole.kt} (89%) rename src/main/kotlin/top/fatweb/oxygen/api/entity/permission/{RoleGroup.kt => RRoleGroup.kt} (89%) rename src/main/kotlin/top/fatweb/oxygen/api/entity/permission/{UserGroup.kt => RUserGroup.kt} (89%) rename src/main/kotlin/top/fatweb/oxygen/api/entity/permission/{UserRole.kt => RUserRole.kt} (89%) rename src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/{PowerRoleMapper.kt => RPowerRoleMapper.kt} (68%) rename src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/{RoleGroupMapper.kt => RRoleGroupMapper.kt} (68%) rename src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/{UserGroupMapper.kt => RUserGroupMapper.kt} (68%) rename src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/{UserRoleMapper.kt => RUserRoleMapper.kt} (69%) rename src/main/kotlin/top/fatweb/oxygen/api/service/permission/{IPowerRoleService.kt => IRPowerRoleService.kt} (65%) rename src/main/kotlin/top/fatweb/oxygen/api/service/permission/{IRoleGroupService.kt => IRRoleGroupService.kt} (65%) rename src/main/kotlin/top/fatweb/oxygen/api/service/permission/{IUserGroupService.kt => IRUserGroupService.kt} (65%) rename src/main/kotlin/top/fatweb/oxygen/api/service/permission/{IUserRoleService.kt => IRUserRoleService.kt} (65%) delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/PowerRoleServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RPowerRoleServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RRoleGroupServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserGroupServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserRoleServiceImpl.kt delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleGroupServiceImpl.kt delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserGroupServiceImpl.kt delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserRoleServiceImpl.kt diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerRole.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RPowerRole.kt similarity index 89% rename from src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerRole.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RPowerRole.kt index d99b9a1..fc0da02 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/PowerRole.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RPowerRole.kt @@ -10,7 +10,7 @@ import java.io.Serializable * @since 1.0.0 */ @TableName("t_r_power_role") -class PowerRole : Serializable { +class RPowerRole : Serializable { /** * ID * @@ -59,6 +59,6 @@ class PowerRole : Serializable { var version: Int? = null override fun toString(): String { - return "PowerRole(id=$id, powerId=$powerId, roleId=$roleId, deleted=$deleted, version=$version)" + return "RPowerRole(id=$id, powerId=$powerId, roleId=$roleId, deleted=$deleted, version=$version)" } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RoleGroup.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RRoleGroup.kt similarity index 89% rename from src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RoleGroup.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RRoleGroup.kt index a6363f2..a3af844 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RoleGroup.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RRoleGroup.kt @@ -10,7 +10,7 @@ import java.io.Serializable * @since 1.0.0 */ @TableName("t_r_role_group") -class RoleGroup : Serializable { +class RRoleGroup : Serializable { /** * ID * @@ -59,6 +59,6 @@ class RoleGroup : Serializable { var version: Int? = null override fun toString(): String { - return "RoleGroup(id=$id, roleId=$roleId, groupId=$groupId, deleted=$deleted, version=$version)" + return "RRoleGroup(id=$id, roleId=$roleId, groupId=$groupId, deleted=$deleted, version=$version)" } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserGroup.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RUserGroup.kt similarity index 89% rename from src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserGroup.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RUserGroup.kt index 408a75c..60986f3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserGroup.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RUserGroup.kt @@ -10,7 +10,7 @@ import java.io.Serializable * @since 1.0.0 */ @TableName("t_r_user_group") -class UserGroup : Serializable { +class RUserGroup : Serializable { /** * ID * @@ -59,6 +59,6 @@ class UserGroup : Serializable { var version: Int? = null override fun toString(): String { - return "UserGroup(id=$id, userId=$userId, groupId=$groupId, deleted=$deleted, version=$version)" + return "RUserGroup(id=$id, userId=$userId, groupId=$groupId, deleted=$deleted, version=$version)" } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserRole.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RUserRole.kt similarity index 89% rename from src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserRole.kt rename to src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RUserRole.kt index cc4b99b..a3f7d77 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/UserRole.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/RUserRole.kt @@ -10,7 +10,7 @@ import java.io.Serializable * @since 1.0.0 */ @TableName("t_r_user_role") -class UserRole : Serializable { +class RUserRole : Serializable { /** * ID * @@ -59,6 +59,6 @@ class UserRole : Serializable { var version: Int? = null override fun toString(): String { - return "UserRole(id=$id, userId=$userId, roleId=$roleId, deleted=$deleted, version=$version)" + return "RUserRole(id=$id, userId=$userId, roleId=$roleId, deleted=$deleted, version=$version)" } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/PowerRoleMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RPowerRoleMapper.kt similarity index 68% rename from src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/PowerRoleMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RPowerRoleMapper.kt index ec2af79..be569f3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/PowerRoleMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RPowerRoleMapper.kt @@ -2,7 +2,7 @@ package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.oxygen.api.entity.permission.PowerRole +import top.fatweb.oxygen.api.entity.permission.RPowerRole /** * Power role intermediate mapper @@ -10,7 +10,7 @@ import top.fatweb.oxygen.api.entity.permission.PowerRole * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see BaseMapper - * @see PowerRole + * @see RPowerRole */ @Mapper -interface PowerRoleMapper : BaseMapper +interface RPowerRoleMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RoleGroupMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RRoleGroupMapper.kt similarity index 68% rename from src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RoleGroupMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RRoleGroupMapper.kt index 8010ae4..48f10da 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RoleGroupMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RRoleGroupMapper.kt @@ -2,7 +2,7 @@ package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.oxygen.api.entity.permission.RoleGroup +import top.fatweb.oxygen.api.entity.permission.RRoleGroup /** * Role group intermediate mapper @@ -10,7 +10,7 @@ import top.fatweb.oxygen.api.entity.permission.RoleGroup * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see BaseMapper - * @see RoleGroup + * @see RRoleGroup */ @Mapper -interface RoleGroupMapper : BaseMapper +interface RRoleGroupMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserGroupMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RUserGroupMapper.kt similarity index 68% rename from src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserGroupMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RUserGroupMapper.kt index 4dbe85e..fa0b8bb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserGroupMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RUserGroupMapper.kt @@ -2,7 +2,7 @@ package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.oxygen.api.entity.permission.UserGroup +import top.fatweb.oxygen.api.entity.permission.RUserGroup /** * User group intermediate mapper @@ -10,7 +10,7 @@ import top.fatweb.oxygen.api.entity.permission.UserGroup * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see BaseMapper - * @see UserGroup + * @see RUserGroup */ @Mapper -interface UserGroupMapper : BaseMapper +interface RUserGroupMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserRoleMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RUserRoleMapper.kt similarity index 69% rename from src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserRoleMapper.kt rename to src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RUserRoleMapper.kt index ebc5eb6..b6a18f4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserRoleMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/RUserRoleMapper.kt @@ -2,7 +2,7 @@ package top.fatweb.oxygen.api.mapper.permission import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import top.fatweb.oxygen.api.entity.permission.UserRole +import top.fatweb.oxygen.api.entity.permission.RUserRole /** * User role intermediate mapper @@ -10,7 +10,7 @@ import top.fatweb.oxygen.api.entity.permission.UserRole * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see BaseMapper - * @see UserRole + * @see RUserRole */ @Mapper -interface UserRoleMapper : BaseMapper +interface RUserRoleMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IPowerRoleService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRPowerRoleService.kt similarity index 65% rename from src/main/kotlin/top/fatweb/oxygen/api/service/permission/IPowerRoleService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRPowerRoleService.kt index 22787b0..9984d69 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IPowerRoleService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRPowerRoleService.kt @@ -1,7 +1,7 @@ package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.oxygen.api.entity.permission.PowerRole +import top.fatweb.oxygen.api.entity.permission.RPowerRole /** * Power role intermediate service interface @@ -9,6 +9,6 @@ import top.fatweb.oxygen.api.entity.permission.PowerRole * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see IService - * @see PowerRole + * @see RPowerRole */ -interface IPowerRoleService : IService +interface IRPowerRoleService : IService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleGroupService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRRoleGroupService.kt similarity index 65% rename from src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleGroupService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRRoleGroupService.kt index 0465468..f536395 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleGroupService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRRoleGroupService.kt @@ -1,7 +1,7 @@ package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.oxygen.api.entity.permission.RoleGroup +import top.fatweb.oxygen.api.entity.permission.RRoleGroup /** * Role group intermediate service interface @@ -9,6 +9,6 @@ import top.fatweb.oxygen.api.entity.permission.RoleGroup * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see IService - * @see RoleGroup + * @see RRoleGroup */ -interface IRoleGroupService : IService +interface IRRoleGroupService : IService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserGroupService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRUserGroupService.kt similarity index 65% rename from src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserGroupService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRUserGroupService.kt index ec8765f..008aa4c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserGroupService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRUserGroupService.kt @@ -1,7 +1,7 @@ package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.oxygen.api.entity.permission.UserGroup +import top.fatweb.oxygen.api.entity.permission.RUserGroup /** * User group intermediate service interface @@ -9,6 +9,6 @@ import top.fatweb.oxygen.api.entity.permission.UserGroup * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see IService - * @see UserGroup + * @see RUserGroup */ -interface IUserGroupService : IService +interface IRUserGroupService : IService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserRoleService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRUserRoleService.kt similarity index 65% rename from src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserRoleService.kt rename to src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRUserRoleService.kt index debf680..969f3ee 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserRoleService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRUserRoleService.kt @@ -1,7 +1,7 @@ package top.fatweb.oxygen.api.service.permission import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.oxygen.api.entity.permission.UserRole +import top.fatweb.oxygen.api.entity.permission.RUserRole /** * User role intermediate service interface @@ -9,6 +9,6 @@ import top.fatweb.oxygen.api.entity.permission.UserRole * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see IService - * @see UserRole + * @see RUserRole */ -interface IUserRoleService : IService +interface IRUserRoleService : IService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt index ae197c4..246137c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt @@ -7,11 +7,11 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.permission.GroupConverter import top.fatweb.oxygen.api.entity.permission.Group -import top.fatweb.oxygen.api.entity.permission.RoleGroup +import top.fatweb.oxygen.api.entity.permission.RRoleGroup import top.fatweb.oxygen.api.mapper.permission.GroupMapper import top.fatweb.oxygen.api.param.permission.group.* import top.fatweb.oxygen.api.service.permission.IGroupService -import top.fatweb.oxygen.api.service.permission.IRoleGroupService +import top.fatweb.oxygen.api.service.permission.IRRoleGroupService import top.fatweb.oxygen.api.service.permission.IUserService import top.fatweb.oxygen.api.util.PageUtil import top.fatweb.oxygen.api.util.RedisUtil @@ -26,7 +26,7 @@ import top.fatweb.oxygen.api.vo.permission.base.GroupVo * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see RedisUtil - * @see IRoleGroupService + * @see IRRoleGroupService * @see IUserService * @see ServiceImpl * @see GroupMapper @@ -36,7 +36,7 @@ import top.fatweb.oxygen.api.vo.permission.base.GroupVo @Service class GroupServiceImpl( private val redisUtil: RedisUtil, - private val roleGroupService: IRoleGroupService, + private val rRoleGroupService: IRRoleGroupService, private val userService: IUserService ) : ServiceImpl(), IGroupService { override fun getPage(groupGetParam: GroupGetParam?): PageVo { @@ -72,8 +72,8 @@ class GroupServiceImpl( return GroupConverter.groupToGroupVo(group) } - if (roleGroupService.saveBatch(group.roles!!.map { - RoleGroup().apply { + if (rRoleGroupService.saveBatch(group.roles!!.map { + RRoleGroup().apply { groupId = group.id roleId = it.id } @@ -88,8 +88,8 @@ class GroupServiceImpl( @Transactional override fun update(groupUpdateParam: GroupUpdateParam): GroupVo? { val group = GroupConverter.groupUpdateParamToGroup(groupUpdateParam) - val oldRoleList = roleGroupService.list( - KtQueryWrapper(RoleGroup()).select(RoleGroup::roleId).eq(RoleGroup::groupId, groupUpdateParam.id) + val oldRoleList = rRoleGroupService.list( + KtQueryWrapper(RRoleGroup()).select(RRoleGroup::roleId).eq(RRoleGroup::groupId, groupUpdateParam.id) ).map { it.roleId } val addRoleIds = HashSet() val removeRoleIds = HashSet() @@ -105,15 +105,15 @@ class GroupServiceImpl( baseMapper.updateById(group) removeRoleIds.forEach { - roleGroupService.remove( - KtQueryWrapper(RoleGroup()).eq( - RoleGroup::groupId, groupUpdateParam.id - ).eq(RoleGroup::roleId, it) + rRoleGroupService.remove( + KtQueryWrapper(RRoleGroup()).eq( + RRoleGroup::groupId, groupUpdateParam.id + ).eq(RRoleGroup::roleId, it) ) } addRoleIds.forEach { - roleGroupService.save(RoleGroup().apply { + rRoleGroupService.save(RRoleGroup().apply { groupId = groupUpdateParam.id roleId = it }) @@ -142,7 +142,7 @@ class GroupServiceImpl( @Transactional override fun delete(groupDeleteParam: GroupDeleteParam) { baseMapper.deleteBatchIds(groupDeleteParam.ids) - roleGroupService.remove(KtQueryWrapper(RoleGroup()).`in`(RoleGroup::groupId, groupDeleteParam.ids)) + rRoleGroupService.remove(KtQueryWrapper(RRoleGroup()).`in`(RRoleGroup::groupId, groupDeleteParam.ids)) offlineUser(*groupDeleteParam.ids.toLongArray()) } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/PowerRoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/PowerRoleServiceImpl.kt deleted file mode 100644 index 5fa9d70..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/PowerRoleServiceImpl.kt +++ /dev/null @@ -1,20 +0,0 @@ -package top.fatweb.oxygen.api.service.permission.impl - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl -import org.springframework.stereotype.Service -import top.fatweb.oxygen.api.entity.permission.PowerRole -import top.fatweb.oxygen.api.mapper.permission.PowerRoleMapper -import top.fatweb.oxygen.api.service.permission.IPowerRoleService - -/** - * Power role intermediate service implement - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see ServiceImpl - * @see PowerRoleMapper - * @see PowerRole - * @see IPowerRoleService - */ -@Service -class PowerRoleServiceImpl : ServiceImpl(), IPowerRoleService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RPowerRoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RPowerRoleServiceImpl.kt new file mode 100644 index 0000000..9522f91 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RPowerRoleServiceImpl.kt @@ -0,0 +1,20 @@ +package top.fatweb.oxygen.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.oxygen.api.entity.permission.RPowerRole +import top.fatweb.oxygen.api.mapper.permission.RPowerRoleMapper +import top.fatweb.oxygen.api.service.permission.IRPowerRoleService + +/** + * Power role intermediate service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see RPowerRoleMapper + * @see RPowerRole + * @see IRPowerRoleService + */ +@Service +class RPowerRoleServiceImpl : ServiceImpl(), IRPowerRoleService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RRoleGroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RRoleGroupServiceImpl.kt new file mode 100644 index 0000000..e83e8b1 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RRoleGroupServiceImpl.kt @@ -0,0 +1,20 @@ +package top.fatweb.oxygen.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.oxygen.api.entity.permission.RRoleGroup +import top.fatweb.oxygen.api.mapper.permission.RRoleGroupMapper +import top.fatweb.oxygen.api.service.permission.IRRoleGroupService + +/** + * Role group intermediate service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see RRoleGroupMapper + * @see RRoleGroup + * @see IRRoleGroupService + */ +@Service +class RRoleGroupServiceImpl : ServiceImpl(), IRRoleGroupService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserGroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserGroupServiceImpl.kt new file mode 100644 index 0000000..12b5100 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserGroupServiceImpl.kt @@ -0,0 +1,20 @@ +package top.fatweb.oxygen.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.oxygen.api.entity.permission.RUserGroup +import top.fatweb.oxygen.api.mapper.permission.RUserGroupMapper +import top.fatweb.oxygen.api.service.permission.IRUserGroupService + +/** + * User group intermediate service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see RUserGroupMapper + * @see RUserGroup + * @see IRUserGroupService + */ +@Service +class RUserGroupServiceImpl : ServiceImpl(), IRUserGroupService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserRoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserRoleServiceImpl.kt new file mode 100644 index 0000000..86f705c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RUserRoleServiceImpl.kt @@ -0,0 +1,19 @@ +package top.fatweb.oxygen.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.oxygen.api.entity.permission.RUserRole +import top.fatweb.oxygen.api.mapper.permission.RUserRoleMapper +import top.fatweb.oxygen.api.service.permission.IRUserRoleService + +/** + * User role intermediate service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see RUserRoleMapper + * @see IRUserRoleService + */ +@Service +class RUserRoleServiceImpl : ServiceImpl(), IRUserRoleService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleGroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleGroupServiceImpl.kt deleted file mode 100644 index 897614c..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleGroupServiceImpl.kt +++ /dev/null @@ -1,20 +0,0 @@ -package top.fatweb.oxygen.api.service.permission.impl - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl -import org.springframework.stereotype.Service -import top.fatweb.oxygen.api.entity.permission.RoleGroup -import top.fatweb.oxygen.api.mapper.permission.RoleGroupMapper -import top.fatweb.oxygen.api.service.permission.IRoleGroupService - -/** - * Role group intermediate service implement - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see ServiceImpl - * @see RoleGroupMapper - * @see RoleGroup - * @see IRoleGroupService - */ -@Service -class RoleGroupServiceImpl : ServiceImpl(), IRoleGroupService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt index ea8a5b6..fdb70e6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt @@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.permission.RoleConverter -import top.fatweb.oxygen.api.entity.permission.PowerRole +import top.fatweb.oxygen.api.entity.permission.RPowerRole import top.fatweb.oxygen.api.entity.permission.Role import top.fatweb.oxygen.api.mapper.permission.RoleMapper import top.fatweb.oxygen.api.param.permission.role.* @@ -24,7 +24,7 @@ import top.fatweb.oxygen.api.vo.permission.base.RoleVo * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see RedisUtil - * @see IPowerRoleService + * @see IRPowerRoleService * @see IFuncService * @see IMenuService * @see IUserService @@ -36,7 +36,7 @@ import top.fatweb.oxygen.api.vo.permission.base.RoleVo @Service class RoleServiceImpl( private val redisUtil: RedisUtil, - private val powerRoleService: IPowerRoleService, + private val rPowerRoleService: IRPowerRoleService, private val funcService: IFuncService, private val menuService: IMenuService, private val userService: IUserService @@ -79,8 +79,8 @@ class RoleServiceImpl( return RoleConverter.roleToRoleVo(role) } - if (powerRoleService.saveBatch(fullPowerIds.map { - PowerRole().apply { + if (rPowerRoleService.saveBatch(fullPowerIds.map { + RPowerRole().apply { roleId = role.id powerId = it } @@ -97,8 +97,8 @@ class RoleServiceImpl( val fullPowerIds = roleUpdateParam.powerIds?.let { getFullPowerIds(it) } val role = RoleConverter.roleUpdateParamToRole(roleUpdateParam) - val oldPowerList = powerRoleService.list( - KtQueryWrapper(PowerRole()).select(PowerRole::powerId).eq(PowerRole::roleId, roleUpdateParam.id) + val oldPowerList = rPowerRoleService.list( + KtQueryWrapper(RPowerRole()).select(RPowerRole::powerId).eq(RPowerRole::roleId, roleUpdateParam.id) ).map { it.powerId } val addPowerIds = HashSet() val removePowerIds = HashSet() @@ -114,15 +114,15 @@ class RoleServiceImpl( baseMapper.updateById(role) removePowerIds.forEach { - powerRoleService.remove( - KtQueryWrapper(PowerRole()).eq( - PowerRole::roleId, roleUpdateParam.id - ).eq(PowerRole::powerId, it) + rPowerRoleService.remove( + KtQueryWrapper(RPowerRole()).eq( + RPowerRole::roleId, roleUpdateParam.id + ).eq(RPowerRole::powerId, it) ) } addPowerIds.forEach { - powerRoleService.save(PowerRole().apply { + rPowerRoleService.save(RPowerRole().apply { roleId = roleUpdateParam.id powerId = it }) @@ -151,7 +151,7 @@ class RoleServiceImpl( @Transactional override fun delete(roleDeleteParam: RoleDeleteParam) { baseMapper.deleteBatchIds(roleDeleteParam.ids) - powerRoleService.remove(KtQueryWrapper(PowerRole()).`in`(PowerRole::roleId, roleDeleteParam.ids)) + rPowerRoleService.remove(KtQueryWrapper(RPowerRole()).`in`(RPowerRole::roleId, roleDeleteParam.ids)) offlineUser(*roleDeleteParam.ids.toLongArray()) } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserGroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserGroupServiceImpl.kt deleted file mode 100644 index 5664ba4..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserGroupServiceImpl.kt +++ /dev/null @@ -1,20 +0,0 @@ -package top.fatweb.oxygen.api.service.permission.impl - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl -import org.springframework.stereotype.Service -import top.fatweb.oxygen.api.entity.permission.UserGroup -import top.fatweb.oxygen.api.mapper.permission.UserGroupMapper -import top.fatweb.oxygen.api.service.permission.IUserGroupService - -/** - * User group intermediate service implement - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see ServiceImpl - * @see UserGroupMapper - * @see UserGroup - * @see IUserGroupService - */ -@Service -class UserGroupServiceImpl : ServiceImpl(), IUserGroupService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserRoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserRoleServiceImpl.kt deleted file mode 100644 index b42ba8b..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserRoleServiceImpl.kt +++ /dev/null @@ -1,19 +0,0 @@ -package top.fatweb.oxygen.api.service.permission.impl - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl -import org.springframework.stereotype.Service -import top.fatweb.oxygen.api.entity.permission.UserRole -import top.fatweb.oxygen.api.mapper.permission.UserRoleMapper -import top.fatweb.oxygen.api.service.permission.IUserRoleService - -/** - * User role intermediate service implement - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see ServiceImpl - * @see UserRoleMapper - * @see IUserRoleService - */ -@Service -class UserRoleServiceImpl : ServiceImpl(), IUserRoleService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt index 6a8595e..1758246 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt @@ -12,9 +12,9 @@ import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.permission.UserConverter import top.fatweb.oxygen.api.entity.permission.User -import top.fatweb.oxygen.api.entity.permission.UserGroup +import top.fatweb.oxygen.api.entity.permission.RUserGroup import top.fatweb.oxygen.api.entity.permission.UserInfo -import top.fatweb.oxygen.api.entity.permission.UserRole +import top.fatweb.oxygen.api.entity.permission.RUserRole import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.mapper.permission.UserMapper import top.fatweb.oxygen.api.param.permission.user.* @@ -42,8 +42,8 @@ import java.util.* * @see IMenuService * @see IFuncService * @see IOperationService - * @see IUserRoleService - * @see IUserGroupService + * @see IRUserRoleService + * @see IRUserGroupService * @see ServiceImpl * @see UserMapper * @see User @@ -59,8 +59,8 @@ class UserServiceImpl( private val menuService: IMenuService, private val funcService: IFuncService, private val operationService: IOperationService, - private val userRoleService: IUserRoleService, - private val userGroupService: IUserGroupService + private val rUserRoleService: IRUserRoleService, + private val rUserGroupService: IRUserGroupService ) : ServiceImpl(), IUserService { override fun getUserWithPowerByAccount(account: String): User? { val user = baseMapper.selectOneWithPowerInfoByAccount(account) @@ -121,8 +121,8 @@ class UserServiceImpl( user.userInfo?.let { userInfoService.save(it.apply { userId = user.id }) } if (!user.roles.isNullOrEmpty()) { - userRoleService.saveBatch(user.roles!!.map { - UserRole().apply { + rUserRoleService.saveBatch(user.roles!!.map { + RUserRole().apply { userId = user.id roleId = it.id } @@ -130,8 +130,8 @@ class UserServiceImpl( } if (!user.groups.isNullOrEmpty()) { - userGroupService.saveBatch(user.groups!!.map { - UserGroup().apply { + rUserGroupService.saveBatch(user.groups!!.map { + RUserGroup().apply { userId = user.id groupId = it.id } @@ -151,8 +151,8 @@ class UserServiceImpl( val user = UserConverter.userUpdateParamToUser(userUpdateParam) user.updateTime = LocalDateTime.now(ZoneOffset.UTC) - val oldRoleList = userRoleService.list( - KtQueryWrapper(UserRole()).select(UserRole::roleId).eq(UserRole::userId, userUpdateParam.id) + val oldRoleList = rUserRoleService.list( + KtQueryWrapper(RUserRole()).select(RUserRole::roleId).eq(RUserRole::userId, userUpdateParam.id) ).map { it.roleId } val addRoleIds = HashSet() val removeRoleIds = HashSet() @@ -165,8 +165,8 @@ class UserServiceImpl( removeRoleIds.removeAll(addRoleIds) oldRoleList.toSet().let { addRoleIds.removeAll(it) } - val oldGroupList = userGroupService.list( - KtQueryWrapper(UserGroup()).select(UserGroup::groupId).eq(UserGroup::userId, userUpdateParam.id) + val oldGroupList = rUserGroupService.list( + KtQueryWrapper(RUserGroup()).select(RUserGroup::groupId).eq(RUserGroup::userId, userUpdateParam.id) ).map { it.groupId } val addGroupIds = HashSet() val removeGroupIds = HashSet() @@ -202,30 +202,30 @@ class UserServiceImpl( } removeRoleIds.forEach { - userRoleService.remove( - KtQueryWrapper(UserRole()).eq( - UserRole::userId, userUpdateParam.id - ).eq(UserRole::roleId, it) + rUserRoleService.remove( + KtQueryWrapper(RUserRole()).eq( + RUserRole::userId, userUpdateParam.id + ).eq(RUserRole::roleId, it) ) } addRoleIds.forEach { - userRoleService.save(UserRole().apply { + rUserRoleService.save(RUserRole().apply { userId = userUpdateParam.id roleId = it }) } removeGroupIds.forEach { - userGroupService.remove( - KtQueryWrapper(UserGroup()).eq( - UserGroup::userId, userUpdateParam.id - ).eq(UserGroup::groupId, it) + rUserGroupService.remove( + KtQueryWrapper(RUserGroup()).eq( + RUserGroup::userId, userUpdateParam.id + ).eq(RUserGroup::groupId, it) ) } addGroupIds.forEach { - userGroupService.save(UserGroup().apply { + rUserGroupService.save(RUserGroup().apply { userId = userUpdateParam.id groupId = it }) @@ -278,8 +278,8 @@ class UserServiceImpl( this.removeBatchByIds(ids) userInfoService.remove(KtQueryWrapper(UserInfo()).`in`(UserInfo::userId, ids)) - userRoleService.remove(KtQueryWrapper(UserRole()).`in`(UserRole::userId, ids)) - userGroupService.remove(KtQueryWrapper(UserGroup()).`in`(UserGroup::userId, ids)) + rUserRoleService.remove(KtQueryWrapper(RUserRole()).`in`(RUserRole::userId, ids)) + rUserGroupService.remove(KtQueryWrapper(RUserGroup()).`in`(RUserGroup::userId, ids)) WebUtil.offlineUser(redisUtil, *ids.toLongArray()) } diff --git a/src/main/resources/mapper/permission/PowerRoleMapper.xml b/src/main/resources/mapper/permission/PowerRoleMapper.xml index 368771a..7cc22a5 100644 --- a/src/main/resources/mapper/permission/PowerRoleMapper.xml +++ b/src/main/resources/mapper/permission/PowerRoleMapper.xml @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/mapper/permission/RoleGroupMapper.xml b/src/main/resources/mapper/permission/RoleGroupMapper.xml index f265c74..4125e6e 100644 --- a/src/main/resources/mapper/permission/RoleGroupMapper.xml +++ b/src/main/resources/mapper/permission/RoleGroupMapper.xml @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/mapper/permission/UserGroupMapper.xml b/src/main/resources/mapper/permission/UserGroupMapper.xml index ba22a76..49b30ef 100644 --- a/src/main/resources/mapper/permission/UserGroupMapper.xml +++ b/src/main/resources/mapper/permission/UserGroupMapper.xml @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/mapper/permission/UserRoleMapper.xml b/src/main/resources/mapper/permission/UserRoleMapper.xml index 0db5478..5906666 100644 --- a/src/main/resources/mapper/permission/UserRoleMapper.xml +++ b/src/main/resources/mapper/permission/UserRoleMapper.xml @@ -1,5 +1,5 @@ - + From e6688ccc5630325616b0c1f5faeb5f9e702da691 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 16 Jan 2024 18:09:46 +0800 Subject: [PATCH 174/258] Add tool tables --- .../api/controller/common/ToolController.kt | 5 + .../oxygen/api/entity/tool/RToolCategory.kt | 64 ++++++++ .../top/fatweb/oxygen/api/entity/tool/Tool.kt | 142 ++++++++++++++++++ .../oxygen/api/entity/tool/ToolCategory.kt | 63 ++++++++ .../fatweb/oxygen/api/entity/tool/ToolData.kt | 36 +++++ .../api/mapper/system/EventLogMapper.kt | 2 + .../api/mapper/system/SensitiveWordMapper.kt | 2 + .../api/mapper/system/StatisticsLogMapper.kt | 2 + .../api/mapper/tool/RToolCategoryMapper.kt | 16 ++ .../api/mapper/tool/ToolCategoryMapper.kt | 16 ++ .../oxygen/api/mapper/tool/ToolDataMapper.kt | 16 ++ .../oxygen/api/mapper/tool/ToolMapper.kt | 16 ++ .../api/service/tool/IRToolCategoryService.kt | 14 ++ .../api/service/tool/IToolCategoryService.kt | 14 ++ .../api/service/tool/IToolDataService.kt | 14 ++ .../oxygen/api/service/tool/IToolService.kt | 14 ++ .../tool/impl/RToolCategoryServiceImpl.kt | 18 +++ .../tool/impl/ToolCategoryServiceImpl.kt | 18 +++ .../service/tool/impl/ToolDataServiceImpl.kt | 18 +++ .../api/service/tool/impl/ToolServiceImpl.kt | 18 +++ ..._0_0_240115__Add_table_'t_b_tool_main'.sql | 23 +++ .../V1_0_0_240115__Add_table_'t_tools'.sql | 12 -- ..._240116__Add_table_'t_b_tool_category'.sql | 13 ++ ...17__Add_table_'t_r_tool_main_category'.sql | 12 ++ ..._0_0_240118__Add_table_'t_b_tool_data'.sql | 11 ++ ..._240119__Add_table_'t_b_tool_template'.sql | 16 ++ ..._0_0_240120__Add_table_'t_b_tool_base'.sql | 14 ++ 27 files changed, 597 insertions(+), 12 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/controller/common/ToolController.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/entity/tool/RToolCategory.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/RToolCategoryMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolCategoryMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolDataMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IRToolCategoryService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolDataService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/RToolCategoryServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolDataServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt create mode 100644 src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql delete mode 100644 src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_tools'.sql create mode 100644 src/main/resources/db/migration/master/V1_0_0_240116__Add_table_'t_b_tool_category'.sql create mode 100644 src/main/resources/db/migration/master/V1_0_0_240117__Add_table_'t_r_tool_main_category'.sql create mode 100644 src/main/resources/db/migration/master/V1_0_0_240118__Add_table_'t_b_tool_data'.sql create mode 100644 src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql create mode 100644 src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/common/ToolController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/common/ToolController.kt new file mode 100644 index 0000000..e759d7e --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/common/ToolController.kt @@ -0,0 +1,5 @@ +package top.fatweb.oxygen.api.controller.common + + +class ToolController { +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/RToolCategory.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/RToolCategory.kt new file mode 100644 index 0000000..cce2436 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/RToolCategory.kt @@ -0,0 +1,64 @@ +package top.fatweb.oxygen.api.entity.tool + +import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable + +/** + * Tool category intermediate entity + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@TableName("t_r_tool_main_category") +class RToolCategory : Serializable { + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableId("id") + var id: Long? = null + + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("tool_id") + var toolId: Long? = null + + /** + * Category ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("category_id") + var categoryId: Long? = null + + /** + * Deleted + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("version") + @Version + var version: Int? = null + + override fun toString(): String { + return "RToolCategory(id=$id, toolId=$toolId, categoryId=$categoryId, deleted=$deleted, version=$version)" + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt new file mode 100644 index 0000000..c9178fd --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt @@ -0,0 +1,142 @@ +package top.fatweb.oxygen.api.entity.tool + +import com.baomidou.mybatisplus.annotation.* +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler + +/** + * Tool entity + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@TableName("t_b_tool_main", autoResultMap = true) +class Tool { + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableId("id") + var id: Long? = null + + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("name") + var name: String? = null + + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("tool_id") + var toolId: String? = null + + /** + * Description + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("description") + var description: String? = null + + /** + * Author + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("author") + var author: Long? = null + + /** + * Version of tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("ver") + var ver: String? = null + + /** + * Privately + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("privately") + var privately: Int? = null + + /** + * Keyword + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("keyword", typeHandler = JacksonTypeHandler::class) + var keyword: List? = null + + /** + * Source code + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("source") + var source: Long? = null + + /** + * Compile product + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var dist: Long? = null + + /** + * Publish + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var publish: Int? = null + + /** + * Review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + var review: Int? = null + + /** + * Deleted + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("version") + @Version + var version: Int? = null + + override fun toString(): String { + return "Tool(id=$id, name=$name, toolId=$toolId, description=$description, author=$author, ver=$ver, privately=$privately, keyword=$keyword, source=$source, dist=$dist, publish=$publish, review=$review, deleted=$deleted, version=$version)" + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt new file mode 100644 index 0000000..e441685 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt @@ -0,0 +1,63 @@ +package top.fatweb.oxygen.api.entity.tool + +import com.baomidou.mybatisplus.annotation.* + +/** + * Tool category entity + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@TableName("t_b_tool_category") +class ToolCategory { + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableId("id") + var id: Long? = null + + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("name") + var name: String? = null + + /** + * Enabel + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("enable") + var enable: Int? = null + + /** + * Deleted + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("version") + @Version + var version: Int? = null + + override fun toString(): String { + return "ToolCategory(id=$id, name=$name, enable=$enable, deleted=$deleted, version=$version)" + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt new file mode 100644 index 0000000..84430c8 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt @@ -0,0 +1,36 @@ +package top.fatweb.oxygen.api.entity.tool + +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableName + +/** + * Tool data entity + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@TableName("t_b_tool_data") +class ToolData { + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableId("id") + var id: Long? = null + + /** + * Data + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("data") + var data: String? = null + + override fun toString(): String { + return "ToolData(id=$id, data=$data)" + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/EventLogMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/EventLogMapper.kt index b9e5963..aaf96e0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/EventLogMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/EventLogMapper.kt @@ -9,6 +9,8 @@ import top.fatweb.oxygen.api.entity.system.EventLog * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see BaseMapper + * @see EventLog */ @Mapper interface EventLogMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/SensitiveWordMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/SensitiveWordMapper.kt index c9dfd82..be01e0c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/SensitiveWordMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/SensitiveWordMapper.kt @@ -9,6 +9,8 @@ import top.fatweb.oxygen.api.entity.system.SensitiveWord * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see BaseMapper + * @see SensitiveWord */ @Mapper interface SensitiveWordMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/StatisticsLogMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/StatisticsLogMapper.kt index 5c6266a..59b1523 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/StatisticsLogMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/system/StatisticsLogMapper.kt @@ -9,6 +9,8 @@ import top.fatweb.oxygen.api.entity.system.StatisticsLog * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see BaseMapper + * @see StatisticsLog */ @Mapper interface StatisticsLogMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/RToolCategoryMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/RToolCategoryMapper.kt new file mode 100644 index 0000000..1bc8be4 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/RToolCategoryMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.oxygen.api.entity.tool.RToolCategory + +/** + * Tool category intermediate mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see RToolCategory + */ +@Mapper +interface RToolCategoryMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolCategoryMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolCategoryMapper.kt new file mode 100644 index 0000000..414eb72 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolCategoryMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.oxygen.api.entity.tool.ToolCategory + +/** + * Tool category mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see ToolCategory + */ +@Mapper +interface ToolCategoryMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolDataMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolDataMapper.kt new file mode 100644 index 0000000..088f219 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolDataMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.oxygen.api.entity.tool.ToolData + +/** + * Tool data mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see ToolData + */ +@Mapper +interface ToolDataMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt new file mode 100644 index 0000000..77dd30a --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.oxygen.api.entity.tool.Tool + +/** + * Tool mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see Tool + */ +@Mapper +interface ToolMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IRToolCategoryService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IRToolCategoryService.kt new file mode 100644 index 0000000..4fc46c5 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IRToolCategoryService.kt @@ -0,0 +1,14 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.RToolCategory + +/** + * Tool category intermediate service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see RToolCategory + */ +interface IRToolCategoryService : IService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt new file mode 100644 index 0000000..aac755e --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt @@ -0,0 +1,14 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.ToolCategory + +/** + * Tool category service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see ToolCategory + */ +interface IToolCategoryService : IService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolDataService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolDataService.kt new file mode 100644 index 0000000..b8e9adc --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolDataService.kt @@ -0,0 +1,14 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.ToolData + +/** + * Tool data service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see ToolData + */ +interface IToolDataService : IService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt new file mode 100644 index 0000000..c0df740 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt @@ -0,0 +1,14 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.Tool + +/** + * Tool service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see Tool + */ +interface IToolService : IService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/RToolCategoryServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/RToolCategoryServiceImpl.kt new file mode 100644 index 0000000..d7a6904 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/RToolCategoryServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import top.fatweb.oxygen.api.entity.tool.RToolCategory +import top.fatweb.oxygen.api.mapper.tool.RToolCategoryMapper +import top.fatweb.oxygen.api.service.tool.IRToolCategoryService + +/** + * Tool category service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see RToolCategoryMapper + * @see RToolCategory + * @see IRToolCategoryService + */ +class RToolCategoryServiceImpl : ServiceImpl(), IRToolCategoryService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt new file mode 100644 index 0000000..4edbdb0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import top.fatweb.oxygen.api.entity.tool.ToolCategory +import top.fatweb.oxygen.api.mapper.tool.ToolCategoryMapper +import top.fatweb.oxygen.api.service.tool.IToolCategoryService + +/** + * Tool category service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see ToolCategoryMapper + * @see ToolCategory + * @see IToolCategoryService + */ +class ToolCategoryServiceImpl : ServiceImpl(), IToolCategoryService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolDataServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolDataServiceImpl.kt new file mode 100644 index 0000000..545a48a --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolDataServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import top.fatweb.oxygen.api.entity.tool.ToolData +import top.fatweb.oxygen.api.mapper.tool.ToolDataMapper +import top.fatweb.oxygen.api.service.tool.IToolDataService + +/** + * Tool data service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see ToolDataMapper + * @see ToolData + * @see IToolDataService + */ +class ToolDataServiceImpl : ServiceImpl(), IToolDataService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt new file mode 100644 index 0000000..2fe45a2 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.mapper.tool.ToolMapper +import top.fatweb.oxygen.api.service.tool.IToolService + +/** + * Tool service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see ToolMapper + * @see Tool + * @see IToolService + */ +class ToolServiceImpl : ServiceImpl(), IToolService \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql new file mode 100644 index 0000000..4bed7ef --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql @@ -0,0 +1,23 @@ +drop table if exists t_b_tool_main; + +create table if not exists t_b_tool_main +( + id bigint not null primary key, + name varchar(50) not null comment '工具名', + tool_id varchar(50) not null comment '工具 ID', + description varchar(500) null comment '简介', + base bigint not null comment '基于', + author bigint not null comment '作者', + ver varchar(20) not null comment '版本', + privately int not null default 0 comment '私有', + keyword varchar(500) not null comment '关键字', + source bigint null comment '源码', + dist bigint null comment '产物', + publish int not null default 0 comment '发布', + review varchar(10) not null default 'NONE' comment '审核', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, + constraint t_b_tool_main_unique_tool_id unique (tool_id, author, deleted) +) comment '工具-主表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_tools'.sql b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_tools'.sql deleted file mode 100644 index b6c4905..0000000 --- a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_tools'.sql +++ /dev/null @@ -1,12 +0,0 @@ -drop table if exists t_tools; - -create table if not exists t_tools ( - id bigint not null primary key , - name varchar(50) not null comment '工具名', - tool_id varchar(50) not null comment '工具 ID', - description varchar(500) null comment '简介', - version varchar(20) not null comment '版本', - private int not null default 0 comment '私有', - keyword varchar(500) not null comment '关键字', - category varchar(500) not null comment '类别' -) \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240116__Add_table_'t_b_tool_category'.sql b/src/main/resources/db/migration/master/V1_0_0_240116__Add_table_'t_b_tool_category'.sql new file mode 100644 index 0000000..21a15d5 --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_240116__Add_table_'t_b_tool_category'.sql @@ -0,0 +1,13 @@ +drop table if exists t_b_tool_category; + +create table if not exists t_b_tool_category +( + id bigint not null primary key, + name varchar(50) not null comment '工具类别名', + enable int not null default 1 comment '启用', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, + constraint t_tool_category_name unique (name, deleted) +) comment '工具-类别表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240117__Add_table_'t_r_tool_main_category'.sql b/src/main/resources/db/migration/master/V1_0_0_240117__Add_table_'t_r_tool_main_category'.sql new file mode 100644 index 0000000..ceb3afc --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_240117__Add_table_'t_r_tool_main_category'.sql @@ -0,0 +1,12 @@ +drop table if exists t_r_tool_main_category; + +create table if not exists t_r_tool_main_category +( + id bigint not null primary key, + tool_id bigint not null comment '工具', + category_id bigint not null comment '类别', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0 +) comment '中间表-工具-主表-类别'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240118__Add_table_'t_b_tool_data'.sql b/src/main/resources/db/migration/master/V1_0_0_240118__Add_table_'t_b_tool_data'.sql new file mode 100644 index 0000000..fc61740 --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_240118__Add_table_'t_b_tool_data'.sql @@ -0,0 +1,11 @@ +drop table if exists t_b_tool_data; + +create table if not exists t_b_tool_data +( + id bigint not null primary key, + data text not null comment '数据', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0 +) comment '工具-数据表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql new file mode 100644 index 0000000..d9c8b71 --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql @@ -0,0 +1,16 @@ +drop table if exists t_b_tool_template; + +create table if not exists t_b_tool_template +( + id bigint not null primary key, + name varchar(40) not null comment '模板名', + ver varchar(20) not null comment '版本', + base varchar(20) not null comment '基于', + source bigint not null comment '源码', + dist bigint not null comment '产物', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, + constraint t_b_tool_template_unique_name unique (name, deleted) +) comment '工具-模板表' \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql new file mode 100644 index 0000000..84f0df4 --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql @@ -0,0 +1,14 @@ +drop table if exists t_b_tool_base; + +create table if not exists t_b_tool_base +( + id bigint not null primary key, + name varchar(20) not null comment '基板名', + source bigint not null comment '源码', + dist bigint not null comment '产物', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, + constraint t_b_tool_base_unique_name unique (name, deleted) +) \ No newline at end of file From 0512bab3cafed9f090471d2742917f3d217c2f29 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 16 Jan 2024 23:36:10 +0800 Subject: [PATCH 175/258] Add power --- .../db/migration/master/R__Basic_data.sql | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) 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 71f9147..0b5d2a8 100644 --- a/src/main/resources/db/migration/master/R__Basic_data.sql +++ b/src/main/resources/db/migration/master/R__Basic_data.sql @@ -15,6 +15,7 @@ insert into t_s_power (id, type_id) (1510000, 2), (1520000, 2), (1530000, 2), + (1540000, 2), (1010100, 3), (1010200, 3), (1010300, 3), @@ -32,6 +33,10 @@ insert into t_s_power (id, type_id) (1520100, 3), (1530100, 3), (1530300, 3), + (1540100, 3), + (1540200, 3), + (1540300, 3), + (1540400, 3), (1010101, 4), (1010102, 4), (1010103, 4), @@ -66,8 +71,15 @@ insert into t_s_power (id, type_id) (1530103, 4), (1530301, 4), (1530302, 4), - (1530303, 4) - as new_value + (1530303, 4), + (1540101, 4), + (1540102, 4), + (1540201, 4), + (1540202, 4), + (1540301, 4), + (1540302, 4), + (1540401, 4), + (1540402, 4) as new_value on duplicate key update type_id = new_value.type_id; insert into t_s_module (id, name) @@ -82,7 +94,8 @@ insert into t_s_menu (id, name, url, parent_id, module_id) (1040000, '权限管理', '/system/power', 1990000, 1000000), (1510000, '系统概况', '/system/statistics', 1990000, 1000000), (1520000, '日志管理', '/system/log', 1990000, 1000000), - (1530000, '系统设置', '/system/settings', 1990000, 1000000) as new_value + (1530000, '系统设置', '/system/settings', 1990000, 1000000), + (1540000, '工具配置', '/system/tools', 1990000, 1000000) as new_value on duplicate key update name =new_value.name, url =new_value.url, parent_id =new_value.parent_id; @@ -104,7 +117,11 @@ insert into t_s_func(id, name, menu_id, parent_id) (1510100, '查询', 1510000, null), (1520100, '查询', 1520000, null), (1530100, '查询', 1530000, null), - (1530300, '修改', 1530000, null) as new_value + (1530300, '修改', 1530000, null), + (1540100, '查询', 1540000, null), + (1540200, '增加', 1540000, null), + (1540300, '修改', 1540000, null), + (1540400, '删除', 1540000, null) as new_value on duplicate key update name = new_value.name, menu_id = new_value.menu_id, parent_id = new_value.parent_id; @@ -144,7 +161,15 @@ insert into t_s_operation(id, name, code, func_id) (1530103, '敏感词', 'system:settings:query:sensitive', 1530100), (1530301, '基础', 'system:settings:modify:base', 1530300), (1530302, '邮件', 'system:settings:modify:mail', 1530300), - (1530303, '敏感词', 'system:settings:modify:sensitive', 1530300) as new_value + (1530303, '敏感词', 'system:settings:modify:sensitive', 1530300), + (1540101, '基板', 'system:tools:query:base', 1540100), + (1540102, '模板', 'system:tools:query:template', 1540100), + (1540201, '基板', 'system:tools:add:base', 1540200), + (1540202, '模板', 'system:tools:add:template', 1540200), + (1540301, '基板', 'system:tools:modify:base', 1540300), + (1540302, '模板', 'system:tools:modify:template', 1540300), + (1540401, '基板', 'system:tools:delete:base', 1540400), + (1540402, '模板', 'system:tools:delete:template', 1540400) 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 From d559fc53dd7daa4fb2ce7bdb654a79edd11033d0 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 18 Jan 2024 14:14:36 +0800 Subject: [PATCH 176/258] Add tool api --- .../api/controller/common/ToolController.kt | 5 - .../controller/system/SettingsController.kt | 1 + .../api/controller/tool/BaseController.kt | 50 +++++++ .../api/controller/tool/CategoryController.kt | 57 ++++++++ .../api/controller/tool/EditController.kt | 56 ++++++++ .../controller/tool/ManagementController.kt | 50 +++++++ .../api/controller/tool/TemplateController.kt | 50 +++++++ .../api/converter/tool/ToolBaseConverter.kt | 16 +++ .../converter/tool/ToolCategoryConverter.kt | 27 ++++ .../api/converter/tool/ToolConverter.kt | 26 ++++ .../api/converter/tool/ToolDataConverter.kt | 13 ++ .../converter/tool/ToolTemplateConverter.kt | 17 +++ .../top/fatweb/oxygen/api/entity/tool/Tool.kt | 94 +++++++++++-- .../fatweb/oxygen/api/entity/tool/ToolBase.kt | 111 +++++++++++++++ .../oxygen/api/entity/tool/ToolCategory.kt | 23 +++- .../fatweb/oxygen/api/entity/tool/ToolData.kt | 47 ++++++- .../oxygen/api/entity/tool/ToolTemplate.kt | 129 ++++++++++++++++++ .../oxygen/api/exception/ToolHasPublish.kt | 3 + .../oxygen/api/mapper/tool/ToolBaseMapper.kt | 21 +++ .../oxygen/api/mapper/tool/ToolMapper.kt | 7 +- .../api/mapper/tool/ToolTemplateMapper.kt | 21 +++ .../oxygen/api/param/tool/ToolAddParam.kt | 44 ++++++ .../oxygen/api/param/tool/ToolBaseAddParam.kt | 15 ++ .../api/param/tool/ToolBaseUpdateParam.kt | 14 ++ .../api/param/tool/ToolCategoryAddParam.kt | 10 ++ .../api/param/tool/ToolCategoryUpdateParam.kt | 14 ++ .../api/param/tool/ToolTemplateAddParam.kt | 23 ++++ .../api/param/tool/ToolTemplateUpdateParam.kt | 20 +++ .../oxygen/api/param/tool/ToolUpdateParam.kt | 34 +++++ .../api/service/tool/IToolBaseService.kt | 29 ++++ .../api/service/tool/IToolCategoryService.kt | 15 +- .../oxygen/api/service/tool/IToolService.kt | 15 +- .../api/service/tool/IToolTemplateService.kt | 27 ++++ .../tool/impl/RToolCategoryServiceImpl.kt | 2 + .../service/tool/impl/ToolBaseServiceImpl.kt | 85 ++++++++++++ .../tool/impl/ToolCategoryServiceImpl.kt | 33 ++++- .../service/tool/impl/ToolDataServiceImpl.kt | 2 + .../api/service/tool/impl/ToolServiceImpl.kt | 108 ++++++++++++++- .../tool/impl/ToolTemplateServiceImpl.kt | 96 +++++++++++++ .../fatweb/oxygen/api/vo/tool/ToolBaseVo.kt | 20 +++ .../oxygen/api/vo/tool/ToolCategoryVo.kt | 18 +++ .../fatweb/oxygen/api/vo/tool/ToolDataVo.kt | 16 +++ .../oxygen/api/vo/tool/ToolTemplateVo.kt | 25 ++++ .../top/fatweb/oxygen/api/vo/tool/ToolVo.kt | 42 ++++++ .../db/migration/master/R__Basic_data.sql | 52 ++++--- ..._0_0_240115__Add_table_'t_b_tool_main'.sql | 12 +- ...17__Add_table_'t_r_tool_main_category'.sql | 12 +- ..._240119__Add_table_'t_b_tool_template'.sql | 6 +- ..._0_0_240120__Add_table_'t_b_tool_base'.sql | 4 +- .../resources/mapper/tool/ToolBaseMapper.xml | 82 +++++++++++ .../resources/mapper/tool/ToolDataMapper.xml | 12 ++ .../mapper/tool/ToolTemplateMapper.xml | 91 ++++++++++++ 52 files changed, 1738 insertions(+), 64 deletions(-) delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/controller/common/ToolController.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolDataConverter.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolTemplateMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryAddParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolCategoryVo.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolDataVo.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt create mode 100644 src/main/resources/mapper/tool/ToolBaseMapper.xml create mode 100644 src/main/resources/mapper/tool/ToolDataMapper.xml create mode 100644 src/main/resources/mapper/tool/ToolTemplateMapper.xml diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/common/ToolController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/common/ToolController.kt deleted file mode 100644 index e759d7e..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/common/ToolController.kt +++ /dev/null @@ -1,5 +0,0 @@ -package top.fatweb.oxygen.api.controller.common - - -class ToolController { -} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt index 8da32a9..451a7d5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt @@ -25,6 +25,7 @@ import top.fatweb.oxygen.api.vo.system.SensitiveWordVo * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see ISettingsService + * @see ISensitiveWordService */ @BaseController(path = ["/system/settings"], name = "系统设置", description = "系统设置相关接口") class SettingsController( diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt new file mode 100644 index 0000000..d7d95b7 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt @@ -0,0 +1,50 @@ +package top.fatweb.oxygen.api.controller.tool + +import io.swagger.v3.oas.annotations.Operation +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.* +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam +import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam +import top.fatweb.oxygen.api.service.tool.IToolBaseService +import top.fatweb.oxygen.api.vo.tool.ToolBaseVo + +@BaseController(path = ["/system/tool/base"], name = "工具基板管理", description = "工具基板管理相关接口") +class BaseController( + private val toolBaseService: IToolBaseService +) { + @Operation(summary = "获取单个基板") + @GetMapping("/{id}") + fun getOne(@PathVariable id: Long): ResponseResult = + toolBaseService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } + ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + + @Operation(summary = "获取基板") + @GetMapping + fun get(): ResponseResult> = + ResponseResult.databaseSuccess(data = toolBaseService.get()) + + @Operation(summary = "新增基板") + @PostMapping + fun add(@RequestBody @Valid toolBaseAddParam: ToolBaseAddParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_INSERT_SUCCESS, + data = toolBaseService.add(toolBaseAddParam) + ) + + @Operation(summary = "更新基板") + @PutMapping + fun update(@RequestBody @Valid toolBaseUpdateParam: ToolBaseUpdateParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, + data = toolBaseService.update(toolBaseUpdateParam) + ) + + @Operation(summary = "删除基板") + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseResult = + if (toolBaseService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt new file mode 100644 index 0000000..09ef95f --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt @@ -0,0 +1,57 @@ +package top.fatweb.oxygen.api.controller.tool + +import io.swagger.v3.oas.annotations.Operation +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.* +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam +import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam +import top.fatweb.oxygen.api.service.tool.IToolCategoryService +import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo + + +/** + * Tool category management controller + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@BaseController(path = ["/system/tool/category"], name = "工具类别管理", description = "工具列别管理相关接口") +class CategoryController( + private val toolCategoryService: IToolCategoryService +) { + @Operation(summary = "获取单个类别") + @GetMapping("/{id}") + fun getOne(@PathVariable id: Long): ResponseResult = + toolCategoryService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } + ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + + @Operation(summary = "获取类别") + @GetMapping + fun get(): ResponseResult> = + ResponseResult.databaseSuccess(data = toolCategoryService.get()) + + @Operation(summary = "新增类别") + @PostMapping + fun add(@RequestBody @Valid toolCategoryAddParam: ToolCategoryAddParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_INSERT_SUCCESS, + data = toolCategoryService.add(toolCategoryAddParam) + ) + + @Operation(summary = "更新类别") + @PutMapping + fun update(@RequestBody @Valid toolCategoryUpdateParam: ToolCategoryUpdateParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, + data = toolCategoryService.update(toolCategoryUpdateParam) + ) + + @Operation(summary = "删除类别") + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseResult = + if (toolCategoryService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt new file mode 100644 index 0000000..8027b4b --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -0,0 +1,56 @@ +package top.fatweb.oxygen.api.controller.tool + +import io.swagger.v3.oas.annotations.Operation +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.* +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.tool.ToolAddParam +import top.fatweb.oxygen.api.param.tool.ToolUpdateParam +import top.fatweb.oxygen.api.service.tool.IToolService +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool management controller + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@BaseController(path = ["/tool"], name = "工具管理", description = "工具管理相关接口") +class EditController( + private val toolService: IToolService +) { + @Operation(summary = "获取单个工具") + @GetMapping("/{id}") + fun getOne(@PathVariable id: Long): ResponseResult = + toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } + ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + + @Operation(summary = "获取工具") + @GetMapping + fun get(): ResponseResult> = + ResponseResult.databaseSuccess(data = toolService.get()) + + @Operation(summary = "新增工具") + @PostMapping + fun add(@RequestBody @Valid toolAddParam: ToolAddParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_INSERT_SUCCESS, + data = toolService.add(toolAddParam) + ) + + @Operation(summary = "更新工具") + @PutMapping + fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, + data = toolService.update(toolUpdateParam) + ) + + @Operation(summary = "删除工具") + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseResult = + if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt new file mode 100644 index 0000000..1db647c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt @@ -0,0 +1,50 @@ +package top.fatweb.oxygen.api.controller.tool + +import io.swagger.v3.oas.annotations.Operation +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.* +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.tool.ToolAddParam +import top.fatweb.oxygen.api.param.tool.ToolUpdateParam +import top.fatweb.oxygen.api.service.tool.IToolService +import top.fatweb.oxygen.api.vo.tool.ToolVo + +@BaseController(path = ["/system/tool"], name = "工具管理", description = "工具管理相关接口") +class ManagementController( + private val toolService: IToolService +) { + @Operation(summary = "获取单个工具") + @GetMapping("/{id}") + fun getOne(@PathVariable id: Long): ResponseResult = + toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } + ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + + @Operation(summary = "获取工具") + @GetMapping + fun get(): ResponseResult> = + ResponseResult.databaseSuccess(data = toolService.get()) + + @Operation(summary = "新增工具") + @PostMapping + fun add(@RequestBody @Valid toolAddParam: ToolAddParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_INSERT_SUCCESS, + data = toolService.add(toolAddParam) + ) + + @Operation(summary = "更新工具") + @PutMapping + fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, + data = toolService.update(toolUpdateParam) + ) + + @Operation(summary = "删除工具") + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseResult = + if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt new file mode 100644 index 0000000..e9eb154 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt @@ -0,0 +1,50 @@ +package top.fatweb.oxygen.api.controller.tool + +import io.swagger.v3.oas.annotations.Operation +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.* +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.tool.ToolTemplateAddParam +import top.fatweb.oxygen.api.param.tool.ToolTemplateUpdateParam +import top.fatweb.oxygen.api.service.tool.IToolTemplateService +import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo + +@BaseController(path = ["/system/tool/template"], name = "工具模板管理", description = "工具模板管理相关接口") +class TemplateController( + private val toolTemplateService: IToolTemplateService +) { + @Operation(summary = "获取单个模板") + @GetMapping("/{id}") + fun getOne(@PathVariable id: Long): ResponseResult = + toolTemplateService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } + ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + + @Operation(summary = "获取模板") + @GetMapping + fun get(): ResponseResult> = + ResponseResult.databaseSuccess(data = toolTemplateService.get()) + + @Operation(summary = "添加模板") + @PostMapping + fun add(@RequestBody @Valid toolTemplateAddParam: ToolTemplateAddParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_INSERT_SUCCESS, + data = toolTemplateService.add(toolTemplateAddParam) + ) + + @Operation(summary = "更新模板") + @PutMapping + fun update(@RequestBody @Valid toolTemplateUpdateParam: ToolTemplateUpdateParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, + data = toolTemplateService.update(toolTemplateUpdateParam) + ) + + @Operation(summary = "删除模板") + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseResult = + if (toolTemplateService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt new file mode 100644 index 0000000..d9b3333 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt @@ -0,0 +1,16 @@ +package top.fatweb.oxygen.api.converter.tool + +import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam +import top.fatweb.oxygen.api.vo.tool.ToolBaseVo + +object ToolBaseConverter { + fun toolBaseToToolBaseVo(toolBase: ToolBase) = ToolBaseVo( + id = toolBase.id, + name = toolBase.name, + source = toolBase.source?.let(ToolDataConverter::toolDataToToolDataVo), + dist = toolBase.dist?.let(ToolDataConverter::toolDataToToolDataVo), + createTime = toolBase.createTime, + updateTime = toolBase.updateTime + ) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt new file mode 100644 index 0000000..aa8a41c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt @@ -0,0 +1,27 @@ +package top.fatweb.oxygen.api.converter.tool + +import top.fatweb.oxygen.api.entity.tool.ToolCategory +import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam +import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam +import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo + +object ToolCategoryConverter { + fun toolCategoryToToolCategoryVo(toolCategory: ToolCategory) = ToolCategoryVo( + id = toolCategory.id, + name = toolCategory.name, + enable = toolCategory.enable == 1, + createTime = toolCategory.createTime, + updateTime = toolCategory.updateTime + ) + + fun toolCategoryAddParamToToolCategory(toolCategoryAddParam: ToolCategoryAddParam) = ToolCategory().apply { + name = toolCategoryAddParam.name + enable = if (toolCategoryAddParam.enable) 1 else 0 + } + + fun toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam: ToolCategoryUpdateParam) = ToolCategory().apply { + id = toolCategoryUpdateParam.id + name = toolCategoryUpdateParam.name + enable = toolCategoryUpdateParam.enable?. let { if (it) 1 else 0 } + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt new file mode 100644 index 0000000..92cc185 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt @@ -0,0 +1,26 @@ +package top.fatweb.oxygen.api.converter.tool + +import top.fatweb.oxygen.api.converter.permission.UserInfoConverter +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.vo.tool.ToolVo + +object ToolConverter { + fun toolToToolVo(tool: Tool) = ToolVo( + id = tool.id, + name = tool.name, + toolId = tool.toolId, + description = tool.description, + baseId = tool.baseId, + author = tool.author?.let(UserInfoConverter::userInfoToUserInfoVo), + ver = tool.ver, + privately = tool.privately == 1, + keywords = tool.keywords, + categories = tool.categories?.map(ToolCategoryConverter::toolCategoryToToolCategoryVo), + source = tool.source?.let(ToolDataConverter::toolDataToToolDataVo), + dist = tool.dist?.let(ToolDataConverter::toolDataToToolDataVo), + publish = tool.publish == 1, + review = tool.review, + createTime = tool.createTime, + updateTime = tool.updateTime + ) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolDataConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolDataConverter.kt new file mode 100644 index 0000000..bd978b0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolDataConverter.kt @@ -0,0 +1,13 @@ +package top.fatweb.oxygen.api.converter.tool + +import top.fatweb.oxygen.api.entity.tool.ToolData +import top.fatweb.oxygen.api.vo.tool.ToolDataVo + +object ToolDataConverter { + fun toolDataToToolDataVo(toolData: ToolData) = ToolDataVo( + id = toolData.id, + data = toolData.data, + createTime = toolData.createTime, + updateTime = toolData.updateTime + ) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt new file mode 100644 index 0000000..3a665e9 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt @@ -0,0 +1,17 @@ +package top.fatweb.oxygen.api.converter.tool + +import top.fatweb.oxygen.api.entity.tool.ToolTemplate +import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo + +object ToolTemplateConverter { + fun toolTemplateToToolTemplateVo(toolTemplate: ToolTemplate) = ToolTemplateVo( + id = toolTemplate.id, + name = toolTemplate.name, + ver = toolTemplate.ver, + baseId = toolTemplate.baseId, + source = toolTemplate.source?.let(ToolDataConverter::toolDataToToolDataVo), + dist = toolTemplate.dist?.let(ToolDataConverter::toolDataToToolDataVo), + createTime = toolTemplate.createTime, + updateTime = toolTemplate.updateTime + ) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt index c9178fd..36aa2a6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt @@ -2,6 +2,8 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler +import top.fatweb.oxygen.api.entity.permission.UserInfo +import java.time.LocalDateTime /** * Tool entity @@ -48,13 +50,22 @@ class Tool { var description: String? = null /** - * Author + * Base ID * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @TableField("author") - var author: Long? = null + @TableField("base_id") + var baseId: Long? = null + + /** + * Author ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("author_id") + var authorId: Long? = null /** * Version of tool @@ -75,30 +86,31 @@ class Tool { var privately: Int? = null /** - * Keyword + * Keywords * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @TableField("keyword", typeHandler = JacksonTypeHandler::class) - var keyword: List? = null + @TableField("keywords", typeHandler = JacksonTypeHandler::class) + var keywords: List? = null /** - * Source code + * Source code ID * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @TableField("source") - var source: Long? = null + @TableField("source_id") + var sourceId: Long? = null /** - * Compile product + * Compile product ID * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - var dist: Long? = null + @TableField("dist_id") + var distId: Long? = null /** * Publish @@ -106,6 +118,7 @@ class Tool { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @TableField("publish") var publish: Int? = null /** @@ -114,8 +127,29 @@ class Tool { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ + @TableField("review") var review: Int? = null + /** + * Create time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @TableField("create_time", fill = FieldFill.INSERT) + var createTime: LocalDateTime? = null + + /** + * Update time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @TableField("update_time", fill = FieldFill.INSERT_UPDATE) + var updateTime: LocalDateTime? = null + /** * Deleted * @@ -136,7 +170,43 @@ class Tool { @Version var version: Int? = null + /** + * Author + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var author: UserInfo? = null + + /** + * Categories + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var categories: List? = null + + /** + * Source + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var source: ToolData? = null + + /** + * Dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var dist: ToolData? = null + override fun toString(): String { - return "Tool(id=$id, name=$name, toolId=$toolId, description=$description, author=$author, ver=$ver, privately=$privately, keyword=$keyword, source=$source, dist=$dist, publish=$publish, review=$review, deleted=$deleted, version=$version)" + return "Tool(id=$id, name=$name, toolId=$toolId, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, privately=$privately, keywords=$keywords, sourceId=$sourceId, distId=$distId, publish=$publish, review=$review, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, author=$author, categories=$categories, source=$source, dist=$dist)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt new file mode 100644 index 0000000..ba9b5b5 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt @@ -0,0 +1,111 @@ +package top.fatweb.oxygen.api.entity.tool + +import com.baomidou.mybatisplus.annotation.* +import java.time.LocalDateTime + +/** + * Tool base entity + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@TableName("t_b_tool_base") +class ToolBase { + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableId("id") + var id: Long? = null + + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("name") + var name: String? = null + + /** + * Source ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("source_id") + var sourceId: Long? = null + + /** + * Dist ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("dist_id") + var distId: Long? = null + + /** + * Create time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @TableField("create_time", fill = FieldFill.INSERT) + var createTime: LocalDateTime? = null + + /** + * Update time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @TableField("update_time", fill = FieldFill.INSERT_UPDATE) + var updateTime: LocalDateTime? = null + + /** + * Deleted + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("version") + @Version + var version: Int? = null + + /** + * Source + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var source: ToolData? = null + + /** + * Dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var dist: ToolData? = null + + override fun toString(): String { + return "ToolBase(id=$id, name=$name, sourceId=$sourceId, distId=$distId, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, dist=$dist)" + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt index e441685..f111e1d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* +import java.time.LocalDateTime /** * Tool category entity @@ -37,6 +38,26 @@ class ToolCategory { @TableField("enable") var enable: Int? = null + /** + * Create time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @TableField("create_time", fill = FieldFill.INSERT) + var createTime: LocalDateTime? = null + + /** + * Update time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @TableField("update_time", fill = FieldFill.INSERT_UPDATE) + var updateTime: LocalDateTime? = null + /** * Deleted * @@ -58,6 +79,6 @@ class ToolCategory { var version: Int? = null override fun toString(): String { - return "ToolCategory(id=$id, name=$name, enable=$enable, deleted=$deleted, version=$version)" + return "ToolCategory(id=$id, name=$name, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt index 84430c8..d576b23 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt @@ -1,8 +1,7 @@ package top.fatweb.oxygen.api.entity.tool -import com.baomidou.mybatisplus.annotation.TableField -import com.baomidou.mybatisplus.annotation.TableId -import com.baomidou.mybatisplus.annotation.TableName +import com.baomidou.mybatisplus.annotation.* +import java.time.LocalDateTime /** * Tool data entity @@ -30,7 +29,47 @@ class ToolData { @TableField("data") var data: String? = null + /** + * Create time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @TableField("create_time", fill = FieldFill.INSERT) + var createTime: LocalDateTime? = null + + /** + * Update time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @TableField("update_time", fill = FieldFill.INSERT_UPDATE) + var updateTime: LocalDateTime? = null + + /** + * Deleted + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("version") + @Version + var version: Int? = null + override fun toString(): String { - return "ToolData(id=$id, data=$data)" + return "ToolData(id=$id, data=$data, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt new file mode 100644 index 0000000..7d47149 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt @@ -0,0 +1,129 @@ +package top.fatweb.oxygen.api.entity.tool + +import com.baomidou.mybatisplus.annotation.* +import java.time.LocalDateTime + +/** + * Tool template entity + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@TableName("t_b_tool_template") +class ToolTemplate { + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableId("id") + var id: Long? = null + + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("name") + var name: String? = null + + /** + * ver + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("ver") + var ver: String? = null + + /** + * Base ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("base_id") + var baseId: Long? = null + + /** + * Source ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("source_id") + var sourceId: Long? = null + + /** + * Dist ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("dist_id") + var distId: Long? = null + + /** + * Create time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @TableField("create_time", fill = FieldFill.INSERT) + var createTime: LocalDateTime? = null + + /** + * Update time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @TableField("update_time", fill = FieldFill.INSERT_UPDATE) + var updateTime: LocalDateTime? = null + + /** + * Deleted + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("version") + @Version + var version: Int? = null + + /** + * Source + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var source: ToolData? = null + + /** + * Dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var dist: ToolData? = null + + override fun toString(): String { + return "ToolTemplate(id=$id, name=$name, ver=$ver, baseId=$baseId, sourceId=$sourceId, distId=$distId, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)" + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt new file mode 100644 index 0000000..72998c2 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt @@ -0,0 +1,3 @@ +package top.fatweb.oxygen.api.exception + +class ToolHasPublish : RuntimeException("The tool has been published and cannot be modified") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt new file mode 100644 index 0000000..d79f84d --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt @@ -0,0 +1,21 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import org.apache.ibatis.annotations.Param +import top.fatweb.oxygen.api.entity.tool.ToolBase + +/** + * Tool base mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see ToolBase + */ +@Mapper +interface ToolBaseMapper : BaseMapper { + fun selectOne(@Param("id") id: Long): ToolBase? + + fun selectList(): List +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt index 77dd30a..ac7caed 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.mapper.tool import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper +import org.apache.ibatis.annotations.Param import top.fatweb.oxygen.api.entity.tool.Tool /** @@ -13,4 +14,8 @@ import top.fatweb.oxygen.api.entity.tool.Tool * @see Tool */ @Mapper -interface ToolMapper : BaseMapper \ No newline at end of file +interface ToolMapper : BaseMapper { + fun selectOne(@Param("id") id: Long): Tool? + + fun selectList(): List +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolTemplateMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolTemplateMapper.kt new file mode 100644 index 0000000..a11ce86 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolTemplateMapper.kt @@ -0,0 +1,21 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import org.apache.ibatis.annotations.Param +import top.fatweb.oxygen.api.entity.tool.ToolTemplate + +/** + * Tool template mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see ToolTemplate + */ +@Mapper +interface ToolTemplateMapper : BaseMapper { + fun selectOne(@Param("id") id: Long): ToolTemplate? + + fun selectList(): List +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt new file mode 100644 index 0000000..0cbfcb8 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt @@ -0,0 +1,44 @@ +package top.fatweb.oxygen.api.param.tool + +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotEmpty +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern + +data class ToolAddParam( + @field: NotBlank(message = "Name can not be blank") + val name: String?, + + @field: NotBlank(message = "ToolId can not be blank") + @field: Pattern( + regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", + message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" + ) + val toolId: String?, + + val description: String?, + + @field: NotNull(message = "BaseId can not be null") + val baseId: Long?, + + @field: NotNull(message = "AuthorId can not be null") + val authorId: Long?, + + @field: NotBlank(message = "Ver can not be blank") + @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") + val ver: String?, + + val privately: Boolean = false, + + @field: NotEmpty(message = "Keywords can not be empty") + val keywords: List, + + @field: NotEmpty(message = "Categories can not be empty") + val categories: List, + + @field: NotNull(message = "Source can not be null") + val source: String?, + + @field:NotNull(message = "Dist can not be null") + val dist: String? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt new file mode 100644 index 0000000..77f4bfa --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt @@ -0,0 +1,15 @@ +package top.fatweb.oxygen.api.param.tool + +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotNull + +data class ToolBaseAddParam( + @field: NotBlank(message = "Name can not be blank") + val name: String?, + + @field: NotNull(message = "Source can not be null") + val source: String?, + + @field:NotNull(message = "Dist can not be null") + val dist: String? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt new file mode 100644 index 0000000..6287b11 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt @@ -0,0 +1,14 @@ +package top.fatweb.oxygen.api.param.tool + +import jakarta.validation.constraints.NotNull + +data class ToolBaseUpdateParam( + @field: NotNull(message = "ID can not be null") + val id: Long?, + + val name: String?, + + val source: String?, + + val dist: String? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryAddParam.kt new file mode 100644 index 0000000..7e8bc39 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryAddParam.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.param.tool + +import jakarta.validation.constraints.NotBlank + +data class ToolCategoryAddParam( + @field: NotBlank(message = "Name can not be blank") + val name: String?, + + val enable: Boolean = true +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt new file mode 100644 index 0000000..4fca7ec --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt @@ -0,0 +1,14 @@ +package top.fatweb.oxygen.api.param.tool + +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotNull + +data class ToolCategoryUpdateParam( + @field: NotNull(message = "ID can not be null") + val id: Long?, + + @field: NotBlank(message = "Name can not be blank") + val name: String?, + + val enable: Boolean? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt new file mode 100644 index 0000000..49839d0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt @@ -0,0 +1,23 @@ +package top.fatweb.oxygen.api.param.tool + +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern + +data class ToolTemplateAddParam( + @field: NotBlank(message = "Name can not be blank") + val name: String?, + + @field: NotBlank(message = "Ver can not be blank") + @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") + val ver: String?, + + @field: NotNull(message = "BaseId can not be null") + val baseId: Long? = null, + + @field: NotNull(message = "Source can not be null") + val source: String?, + + @field:NotNull(message = "Dist can not be null") + val dist: String? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt new file mode 100644 index 0000000..d170e3e --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt @@ -0,0 +1,20 @@ +package top.fatweb.oxygen.api.param.tool + +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern + +data class ToolTemplateUpdateParam( + @field: NotNull(message = "ID can not be null") + val id: Long?, + + val name: String?, + + @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") + val ver: String?, + + val baseId: Long?, + + val source: String?, + + val dist: String? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt new file mode 100644 index 0000000..94d1d0d --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt @@ -0,0 +1,34 @@ +package top.fatweb.oxygen.api.param.tool + +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern + +data class ToolUpdateParam( + @field: NotNull(message = "ID can not be null") + val id: Long?, + + val name: String?, + + @field: Pattern( + regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", + message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" + ) + val toolId: String?, + + val description: String?, + + val authorId: Long?, + + @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") + val ver: String?, + + val privately: Boolean?, + + val keywords: List, + + val categories: List, + + val source: String?, + + val dist: String? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt new file mode 100644 index 0000000..0ccfff9 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt @@ -0,0 +1,29 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.entity.tool.ToolCategory +import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam +import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam +import top.fatweb.oxygen.api.vo.tool.ToolBaseVo +import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo + +/** + * Tool base service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see ToolBase + */ +interface IToolBaseService : IService { + fun getOne(id: Long): ToolBaseVo? + + fun get(): List + + fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo + + fun update(toolBaseUpdateParam: ToolBaseUpdateParam): ToolBaseVo + + fun delete(id: Long): Boolean +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt index aac755e..c661773 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt @@ -2,6 +2,9 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.ToolCategory +import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam +import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam +import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo /** * Tool category service interface @@ -11,4 +14,14 @@ import top.fatweb.oxygen.api.entity.tool.ToolCategory * @see IService * @see ToolCategory */ -interface IToolCategoryService : IService \ No newline at end of file +interface IToolCategoryService : IService { + fun getOne(id: Long): ToolCategoryVo? + + fun get(): List + + fun add(toolCategoryAddParam: ToolCategoryAddParam): ToolCategoryVo + + fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo + + fun delete(id: Long): Boolean +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt index c0df740..d32a1a5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt @@ -2,6 +2,9 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.param.tool.ToolAddParam +import top.fatweb.oxygen.api.param.tool.ToolUpdateParam +import top.fatweb.oxygen.api.vo.tool.ToolVo /** * Tool service interface @@ -11,4 +14,14 @@ import top.fatweb.oxygen.api.entity.tool.Tool * @see IService * @see Tool */ -interface IToolService : IService \ No newline at end of file +interface IToolService : IService { + fun getOne(id: Long): ToolVo? + + fun get(): List + + fun add(toolAddParam: ToolAddParam): ToolVo + + fun update(toolUpdateParam: ToolUpdateParam): ToolVo + + fun delete(id: Long): Boolean +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt new file mode 100644 index 0000000..3fcdf81 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt @@ -0,0 +1,27 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.ToolTemplate +import top.fatweb.oxygen.api.param.tool.ToolTemplateAddParam +import top.fatweb.oxygen.api.param.tool.ToolTemplateUpdateParam +import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo + +/** + * Tool template service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see ToolTemplate + */ +interface IToolTemplateService : IService { + fun getOne(id: Long): ToolTemplateVo? + + fun get(): List + + fun add(toolTemplateAddParam: ToolTemplateAddParam): ToolTemplateVo + + fun update(toolTemplateUpdateParam: ToolTemplateUpdateParam): ToolTemplateVo + + fun delete(id: Long): Boolean +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/RToolCategoryServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/RToolCategoryServiceImpl.kt index d7a6904..87844df 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/RToolCategoryServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/RToolCategoryServiceImpl.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service import top.fatweb.oxygen.api.entity.tool.RToolCategory import top.fatweb.oxygen.api.mapper.tool.RToolCategoryMapper import top.fatweb.oxygen.api.service.tool.IRToolCategoryService @@ -15,4 +16,5 @@ import top.fatweb.oxygen.api.service.tool.IRToolCategoryService * @see RToolCategory * @see IRToolCategoryService */ +@Service class RToolCategoryServiceImpl : ServiceImpl(), IRToolCategoryService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt new file mode 100644 index 0000000..4b338da --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -0,0 +1,85 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import top.fatweb.oxygen.api.converter.tool.ToolBaseConverter +import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.entity.tool.ToolData +import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.mapper.tool.ToolBaseMapper +import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam +import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam +import top.fatweb.oxygen.api.service.tool.IToolBaseService +import top.fatweb.oxygen.api.service.tool.IToolDataService +import top.fatweb.oxygen.api.vo.tool.ToolBaseVo + +/** + * Tool base service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see ToolBaseMapper + * @see ToolBase + * @see IToolBaseService + */ +@Service +class ToolBaseServiceImpl( + private val toolDataService: IToolDataService +) : ServiceImpl(), IToolBaseService { + override fun getOne(id: Long): ToolBaseVo? = baseMapper.selectOne(id)?.let(ToolBaseConverter::toolBaseToToolBaseVo) + + override fun get(): List = baseMapper.selectList().map(ToolBaseConverter::toolBaseToToolBaseVo) + + @Transactional + override fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo { + val newSource = ToolData().apply { data = toolBaseAddParam.source } + val newDist = ToolData().apply { data = toolBaseAddParam.dist } + + toolDataService.save(newSource) + toolDataService.save(newDist) + + val toolBase = ToolBase().apply { + name = toolBaseAddParam.name + sourceId = newSource.id + distId = newDist.id + source = newSource + dist = newDist + } + + this.save(toolBase) + + return ToolBaseConverter.toolBaseToToolBaseVo(toolBase) + } + + @Transactional + override fun update(toolBaseUpdateParam: ToolBaseUpdateParam): ToolBaseVo { + val toolBase = baseMapper.selectOne(toolBaseUpdateParam.id!!) ?: throw NoRecordFoundException() + + toolDataService.updateById(ToolData().apply { + id = toolBase.sourceId + data = toolBaseUpdateParam.source + }) + + toolDataService.updateById(ToolData().apply { + id = toolBase.distId + data = toolBaseUpdateParam.dist + }) + + this.updateById(ToolBase().apply { + id = toolBaseUpdateParam.id + name = toolBaseUpdateParam.name + }) + + return this.getOne(toolBase.id!!)!! + } + + @Transactional + override fun delete(id: Long): Boolean { + val toolBase = this.getById(id) + + return toolDataService.removeBatchByIds(listOf(toolBase.sourceId, toolBase.distId)) + && this.removeById(id) + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt index 4edbdb0..a9c408b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt @@ -1,9 +1,15 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import top.fatweb.oxygen.api.converter.tool.ToolCategoryConverter import top.fatweb.oxygen.api.entity.tool.ToolCategory import top.fatweb.oxygen.api.mapper.tool.ToolCategoryMapper +import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam +import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam import top.fatweb.oxygen.api.service.tool.IToolCategoryService +import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo /** * Tool category service implement @@ -15,4 +21,29 @@ import top.fatweb.oxygen.api.service.tool.IToolCategoryService * @see ToolCategory * @see IToolCategoryService */ -class ToolCategoryServiceImpl : ServiceImpl(), IToolCategoryService \ No newline at end of file +@Service +class ToolCategoryServiceImpl : ServiceImpl(), IToolCategoryService { + override fun getOne(id: Long): ToolCategoryVo? = + this.getById(id)?.let(ToolCategoryConverter::toolCategoryToToolCategoryVo) + + override fun get(): List = + this.list().map(ToolCategoryConverter::toolCategoryToToolCategoryVo) + + override fun add(toolCategoryAddParam: ToolCategoryAddParam): ToolCategoryVo { + val toolCategory = ToolCategoryConverter.toolCategoryAddParamToToolCategory(toolCategoryAddParam) + + this.save(toolCategory) + + return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory) + } + + override fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo { + val toolCategory = ToolCategoryConverter.toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam) + + this.updateById(toolCategory) + + return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory) + } + + override fun delete(id: Long): Boolean = this.removeById(id) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolDataServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolDataServiceImpl.kt index 545a48a..74cc3ca 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolDataServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolDataServiceImpl.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service import top.fatweb.oxygen.api.entity.tool.ToolData import top.fatweb.oxygen.api.mapper.tool.ToolDataMapper import top.fatweb.oxygen.api.service.tool.IToolDataService @@ -15,4 +16,5 @@ import top.fatweb.oxygen.api.service.tool.IToolDataService * @see ToolData * @see IToolDataService */ +@Service class ToolDataServiceImpl : ServiceImpl(), IToolDataService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt index 2fe45a2..f48ca96 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt @@ -1,9 +1,22 @@ package top.fatweb.oxygen.api.service.tool.impl +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import top.fatweb.oxygen.api.converter.tool.ToolConverter +import top.fatweb.oxygen.api.entity.tool.RToolCategory import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.entity.tool.ToolData +import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.exception.ToolHasPublish +import top.fatweb.oxygen.api.exception.UserNotFoundException import top.fatweb.oxygen.api.mapper.tool.ToolMapper -import top.fatweb.oxygen.api.service.tool.IToolService +import top.fatweb.oxygen.api.param.tool.ToolAddParam +import top.fatweb.oxygen.api.param.tool.ToolUpdateParam +import top.fatweb.oxygen.api.service.permission.IUserService +import top.fatweb.oxygen.api.service.tool.* +import top.fatweb.oxygen.api.vo.tool.ToolVo /** * Tool service implement @@ -15,4 +28,95 @@ import top.fatweb.oxygen.api.service.tool.IToolService * @see Tool * @see IToolService */ -class ToolServiceImpl : ServiceImpl(), IToolService \ No newline at end of file +@Service +class ToolServiceImpl( + private val toolDataService: IToolDataService, + private val toolBaseService: IToolBaseService, + private val toolCategoryService: IToolCategoryService, + private val rToolCategoryService: IRToolCategoryService, + private val userService: IUserService +) : ServiceImpl(), IToolService { + override fun getOne(id: Long): ToolVo? = baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) + + override fun get(): List = baseMapper.selectList().map(ToolConverter::toolToToolVo) + + @Transactional + override fun add(toolAddParam: ToolAddParam): ToolVo { + toolBaseService.getOne(toolAddParam.baseId!!) ?: throw NoRecordFoundException() + userService.getOne(toolAddParam.authorId!!) ?: throw UserNotFoundException() + + val newSource = ToolData().apply { data = toolAddParam.source } + val newDist = ToolData().apply { data = toolAddParam.dist } + + toolDataService.save(newSource) + toolDataService.save(newDist) + + val tool = Tool().apply { + name = toolAddParam.name + toolId = toolAddParam.toolId + description = toolAddParam.description + baseId = toolAddParam.baseId + authorId = toolAddParam.authorId + ver = toolAddParam.ver + privately = if (toolAddParam.privately) 1 else 0 + keywords = toolAddParam.keywords + sourceId = newSource.id + distId = newDist.id + } + + this.save(tool) + + toolAddParam.categories.forEach { + toolCategoryService.getById(it) ?: throw NoRecordFoundException() + rToolCategoryService.save(RToolCategory().apply { + toolId = tool.id + categoryId = it + }) + } + + return this.getOne(tool.id!!)!! + } + + @Transactional + override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { + val tool = baseMapper.selectOne(toolUpdateParam.id!!) ?: throw NoRecordFoundException() + if (tool.publish == 1) { + throw ToolHasPublish() + } + userService.getOne(toolUpdateParam.authorId!!) ?: throw UserNotFoundException() + + toolDataService.updateById(ToolData().apply { + id = tool.sourceId + data = toolUpdateParam.source + }) + + toolDataService.updateById(ToolData().apply { + id = tool.distId + data = toolUpdateParam.dist + }) + + this.updateById(Tool().apply { + id = toolUpdateParam.id + name = toolUpdateParam.name + toolId = toolUpdateParam.toolId + description = toolUpdateParam.description + authorId = toolUpdateParam.authorId + ver = toolUpdateParam.ver + privately = toolUpdateParam.privately?.let { if (it) 1 else 0 } + keywords = toolUpdateParam.keywords + }) + + // TODO + + return this.getOne(tool.id!!)!! + } + + @Transactional + override fun delete(id: Long): Boolean { + val tool = this.getById(id) + + return toolDataService.removeBatchByIds(listOf(tool.sourceId, tool.distId)) + && rToolCategoryService.remove(KtQueryWrapper(RToolCategory()).eq(RToolCategory::toolId, tool.id)) + && this.removeById(tool.id) + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt new file mode 100644 index 0000000..f78b226 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt @@ -0,0 +1,96 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import top.fatweb.oxygen.api.converter.tool.ToolTemplateConverter +import top.fatweb.oxygen.api.entity.tool.ToolData +import top.fatweb.oxygen.api.entity.tool.ToolTemplate +import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.mapper.tool.ToolTemplateMapper +import top.fatweb.oxygen.api.param.tool.ToolTemplateAddParam +import top.fatweb.oxygen.api.param.tool.ToolTemplateUpdateParam +import top.fatweb.oxygen.api.service.tool.IToolBaseService +import top.fatweb.oxygen.api.service.tool.IToolDataService +import top.fatweb.oxygen.api.service.tool.IToolTemplateService +import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo + +/** + * Tool template service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see ToolTemplateMapper + * @see ToolTemplate + * @see IToolTemplateService + */ +@Service +class ToolTemplateServiceImpl( + private val toolDataService: IToolDataService, + private val toolBaseService: IToolBaseService +) : ServiceImpl(), IToolTemplateService { + override fun getOne(id: Long): ToolTemplateVo? = + baseMapper.selectOne(id)?.let(ToolTemplateConverter::toolTemplateToToolTemplateVo) + + override fun get(): List = + baseMapper.selectList().map(ToolTemplateConverter::toolTemplateToToolTemplateVo) + + @Transactional + override fun add(toolTemplateAddParam: ToolTemplateAddParam): ToolTemplateVo { + toolBaseService.getOne(toolTemplateAddParam.baseId!!) ?: throw NoRecordFoundException() + + val newSource = ToolData().apply { data = toolTemplateAddParam.source } + val newDist = ToolData().apply { data = toolTemplateAddParam.dist } + + toolDataService.save(newSource) + toolDataService.save(newDist) + + val toolTemplate = ToolTemplate().apply { + name = toolTemplateAddParam.name + ver = toolTemplateAddParam.ver + baseId = toolTemplateAddParam.baseId + sourceId = newSource.id + distId = newDist.id + source = newSource + dist = newDist + } + + this.save(toolTemplate) + + return ToolTemplateConverter.toolTemplateToToolTemplateVo(toolTemplate) + } + + @Transactional + override fun update(toolTemplateUpdateParam: ToolTemplateUpdateParam): ToolTemplateVo { + val toolTemplate = baseMapper.selectOne(toolTemplateUpdateParam.id!!) ?: throw NoRecordFoundException() + toolTemplateUpdateParam.baseId?.let { toolBaseService.getOne(it) ?: throw NoRecordFoundException() } + + toolDataService.updateById(ToolData().apply { + id = toolTemplate.sourceId + data = toolTemplateUpdateParam.source + }) + + toolDataService.updateById(ToolData().apply { + id = toolTemplate.distId + data = toolTemplateUpdateParam.dist + }) + + this.updateById(ToolTemplate().apply { + id = toolTemplateUpdateParam.id + name = toolTemplateUpdateParam.name + ver = toolTemplateUpdateParam.ver + baseId = toolTemplateUpdateParam.baseId + }) + + return this.getOne(toolTemplate.id!!)!! + } + + @Transactional + override fun delete(id: Long): Boolean { + val toolTemplate = this.getById(id) + + return toolDataService.removeBatchByIds(listOf(toolTemplate.sourceId, toolTemplate.distId)) + && this.removeById(id) + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt new file mode 100644 index 0000000..cc92560 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt @@ -0,0 +1,20 @@ +package top.fatweb.oxygen.api.vo.tool + +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer +import java.time.LocalDateTime + +data class ToolBaseVo( + @JsonSerialize(using = ToStringSerializer::class) + val id: Long?, + + val name: String?, + + val source: ToolDataVo?, + + val dist: ToolDataVo?, + + val createTime: LocalDateTime?, + + val updateTime: LocalDateTime? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolCategoryVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolCategoryVo.kt new file mode 100644 index 0000000..2c1d3a1 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolCategoryVo.kt @@ -0,0 +1,18 @@ +package top.fatweb.oxygen.api.vo.tool + +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer +import java.time.LocalDateTime + +data class ToolCategoryVo( + @JsonSerialize(using = ToStringSerializer::class) + val id: Long?, + + val name: String?, + + val enable: Boolean?, + + val createTime: LocalDateTime?, + + val updateTime: LocalDateTime? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolDataVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolDataVo.kt new file mode 100644 index 0000000..dde38e5 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolDataVo.kt @@ -0,0 +1,16 @@ +package top.fatweb.oxygen.api.vo.tool + +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer +import java.time.LocalDateTime + +data class ToolDataVo( + @JsonSerialize(using = ToStringSerializer::class) + val id: Long?, + + val data: String?, + + val createTime: LocalDateTime?, + + val updateTime: LocalDateTime? +) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt new file mode 100644 index 0000000..cce4be4 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt @@ -0,0 +1,25 @@ +package top.fatweb.oxygen.api.vo.tool + +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer +import java.time.LocalDateTime + +data class ToolTemplateVo( + @JsonSerialize(using = ToStringSerializer::class) + val id: Long?, + + val name: String?, + + val ver: String?, + + @JsonSerialize(using = ToStringSerializer::class) + val baseId: Long?, + + val source: ToolDataVo?, + + val dist: ToolDataVo?, + + val createTime: LocalDateTime?, + + val updateTime: LocalDateTime? +) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt new file mode 100644 index 0000000..3b7fe20 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt @@ -0,0 +1,42 @@ +package top.fatweb.oxygen.api.vo.tool + +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer +import top.fatweb.oxygen.api.vo.permission.base.UserInfoVo +import java.time.LocalDateTime + +data class ToolVo ( + @JsonSerialize(using = ToStringSerializer::class) + val id: Long?, + + val name: String?, + + val toolId: String?, + + val description: String?, + + @JsonSerialize(using = ToStringSerializer::class) + val baseId: Long?, + + val author: UserInfoVo?, + + val ver: String?, + + val privately: Boolean?, + + val keywords: List?, + + val categories: List?, + + val source: ToolDataVo?, + + val dist: ToolDataVo?, + + val publish: Boolean?, + + val review: Int?, + + val createTime: LocalDateTime?, + + val updateTime: LocalDateTime? +) \ No newline at end of file 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 0b5d2a8..e8bb177 100644 --- a/src/main/resources/db/migration/master/R__Basic_data.sql +++ b/src/main/resources/db/migration/master/R__Basic_data.sql @@ -74,12 +74,20 @@ insert into t_s_power (id, type_id) (1530303, 4), (1540101, 4), (1540102, 4), + (1540103, 4), + (1540104, 4), (1540201, 4), (1540202, 4), + (1540203, 4), + (1540204, 4), (1540301, 4), (1540302, 4), + (1540303, 4), + (1540304, 4), (1540401, 4), - (1540402, 4) as new_value + (1540402, 4), + (1540403, 4), + (1540404, 4) as new_value on duplicate key update type_id = new_value.type_id; insert into t_s_module (id, name) @@ -87,15 +95,15 @@ insert into t_s_module (id, name) on duplicate key update name = new_value.name; insert into t_s_menu (id, name, url, parent_id, module_id) - values (1990000, '系统管理', '/system', null, 1000000), - (1010000, '用户管理', '/system/user', 1990000, 1000000), - (1020000, '角色管理', '/system/role', 1990000, 1000000), - (1030000, '用户组管理', '/system/group', 1990000, 1000000), - (1040000, '权限管理', '/system/power', 1990000, 1000000), - (1510000, '系统概况', '/system/statistics', 1990000, 1000000), - (1520000, '日志管理', '/system/log', 1990000, 1000000), - (1530000, '系统设置', '/system/settings', 1990000, 1000000), - (1540000, '工具配置', '/system/tools', 1990000, 1000000) as new_value + values (1990000, '系统管理', '^/system$', null, 1000000), + (1010000, '用户管理', '^/system/user$', 1990000, 1000000), + (1020000, '角色管理', '^/system/role$', 1990000, 1000000), + (1030000, '用户组管理', '^/system/group$', 1990000, 1000000), + (1040000, '权限管理', '^/system/power$', 1990000, 1000000), + (1510000, '系统概况', '^/system/statistics$', 1990000, 1000000), + (1520000, '日志管理', '^/system/log$', 1990000, 1000000), + (1530000, '系统设置', '^/system/settings$', 1990000, 1000000), + (1540000, '工具配置', '^/system/tools(/.*)?$', 1990000, 1000000) as new_value on duplicate key update name =new_value.name, url =new_value.url, parent_id =new_value.parent_id; @@ -162,14 +170,22 @@ insert into t_s_operation(id, name, code, func_id) (1530301, '基础', 'system:settings:modify:base', 1530300), (1530302, '邮件', 'system:settings:modify:mail', 1530300), (1530303, '敏感词', 'system:settings:modify:sensitive', 1530300), - (1540101, '基板', 'system:tools:query:base', 1540100), - (1540102, '模板', 'system:tools:query:template', 1540100), - (1540201, '基板', 'system:tools:add:base', 1540200), - (1540202, '模板', 'system:tools:add:template', 1540200), - (1540301, '基板', 'system:tools:modify:base', 1540300), - (1540302, '模板', 'system:tools:modify:template', 1540300), - (1540401, '基板', 'system:tools:delete:base', 1540400), - (1540402, '模板', 'system:tools:delete:template', 1540400) as new_value + (1540101, '类别', 'system:tool:query:category', 1540100), + (1540102, '基板', 'system:tool:query:base', 1540100), + (1540103, '模板', 'system:tool:query:template', 1540100), + (1540104, '工具', 'system:tool:query:tool', 1540100), + (1540201, '类别', 'system:tool:add:category', 1540200), + (1540202, '基板', 'system:tool:add:base', 1540200), + (1540203, '模板', 'system:tool:add:template', 1540200), + (1540204, '工具', 'system:tool:add:tool', 1540200), + (1540301, '类别', 'system:tool:modify:category', 1540300), + (1540302, '基板', 'system:tool:modify:base', 1540300), + (1540303, '模板', 'system:tool:modify:template', 1540300), + (1540304, '工具', 'system:tool:modify:tool', 1540300), + (1540401, '类别', 'system:tool:delete:category', 1540400), + (1540402, '基板', 'system:tool:delete:base', 1540400), + (1540403, '模板', 'system:tool:delete:template', 1540400), + (1540404, '工具', 'system:tool:delete:tool', 1540400) 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/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql index 4bed7ef..9e31827 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql @@ -6,18 +6,18 @@ create table if not exists t_b_tool_main name varchar(50) not null comment '工具名', tool_id varchar(50) not null comment '工具 ID', description varchar(500) null comment '简介', - base bigint not null comment '基于', - author bigint not null comment '作者', + base_id bigint not null comment '基板 ID', + author_id bigint not null comment '作者 ID', ver varchar(20) not null comment '版本', privately int not null default 0 comment '私有', - keyword varchar(500) not null comment '关键字', - source bigint null comment '源码', - dist bigint null comment '产物', + keywords varchar(500) not null comment '关键字', + source_id bigint not null comment '源码 ID', + dist_id bigint not null comment '产物 ID', publish int not null default 0 comment '发布', review varchar(10) not null default 'NONE' comment '审核', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', deleted bigint not null default 0, version int not null default 0, - constraint t_b_tool_main_unique_tool_id unique (tool_id, author, deleted) + constraint t_b_tool_main_unique_tool_id unique (tool_id, author_id, deleted) ) comment '工具-主表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240117__Add_table_'t_r_tool_main_category'.sql b/src/main/resources/db/migration/master/V1_0_0_240117__Add_table_'t_r_tool_main_category'.sql index ceb3afc..c711b56 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240117__Add_table_'t_r_tool_main_category'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240117__Add_table_'t_r_tool_main_category'.sql @@ -2,11 +2,9 @@ drop table if exists t_r_tool_main_category; create table if not exists t_r_tool_main_category ( - id bigint not null primary key, - tool_id bigint not null comment '工具', - category_id bigint not null comment '类别', - create_time datetime not null default (utc_timestamp()) comment '创建时间', - update_time datetime not null default (utc_timestamp()) comment '修改时间', - deleted bigint not null default 0, - version int not null default 0 + id bigint not null primary key, + tool_id bigint not null comment '工具', + category_id bigint not null comment '类别', + deleted bigint not null default 0, + version int not null default 0 ) comment '中间表-工具-主表-类别'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql index d9c8b71..d5317b0 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql @@ -5,9 +5,9 @@ create table if not exists t_b_tool_template id bigint not null primary key, name varchar(40) not null comment '模板名', ver varchar(20) not null comment '版本', - base varchar(20) not null comment '基于', - source bigint not null comment '源码', - dist bigint not null comment '产物', + base_id bigint not null comment '基板 ID', + source_id bigint not null comment '源码 ID', + dist_id bigint not null comment '产物 ID', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', deleted bigint not null default 0, diff --git a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql index 84f0df4..d6e1c17 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql @@ -4,8 +4,8 @@ create table if not exists t_b_tool_base ( id bigint not null primary key, name varchar(20) not null comment '基板名', - source bigint not null comment '源码', - dist bigint not null comment '产物', + source_id bigint not null comment '源码 ID', + dist_id bigint not null comment '产物 ID', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', deleted bigint not null default 0, diff --git a/src/main/resources/mapper/tool/ToolBaseMapper.xml b/src/main/resources/mapper/tool/ToolBaseMapper.xml new file mode 100644 index 0000000..d940e45 --- /dev/null +++ b/src/main/resources/mapper/tool/ToolBaseMapper.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mapper/tool/ToolDataMapper.xml b/src/main/resources/mapper/tool/ToolDataMapper.xml new file mode 100644 index 0000000..cb72ea3 --- /dev/null +++ b/src/main/resources/mapper/tool/ToolDataMapper.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/main/resources/mapper/tool/ToolTemplateMapper.xml b/src/main/resources/mapper/tool/ToolTemplateMapper.xml new file mode 100644 index 0000000..cd73755 --- /dev/null +++ b/src/main/resources/mapper/tool/ToolTemplateMapper.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From cec9a9e07b206a21fd2c8cdf3f5963b3363c83d9 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 18 Jan 2024 16:54:23 +0800 Subject: [PATCH 177/258] Optimize code --- .../controller/permission/GroupController.kt | 32 +++--- .../controller/permission/RoleController.kt | 43 +++----- .../controller/permission/UserController.kt | 27 ++---- .../api/controller/tool/BaseController.kt | 5 +- .../api/controller/tool/CategoryController.kt | 5 +- .../api/controller/tool/EditController.kt | 5 +- .../controller/tool/ManagementController.kt | 5 +- .../api/controller/tool/TemplateController.kt | 5 +- .../api/converter/tool/ToolBaseConverter.kt | 1 - .../oxygen/api/entity/common/ResponseCode.kt | 4 +- .../api/exception/DatabaseDeleteException.kt | 3 + .../api/exception/DatabaseInsertException.kt | 3 + .../api/exception/DatabaseSelectException.kt | 3 + .../api/exception/DatabaseUpdateException.kt | 3 + .../oxygen/api/handler/ExceptionHandler.kt | 20 ++++ .../service/api/v1/impl/AvatarServiceImpl.kt | 28 +++--- .../api/service/permission/IGroupService.kt | 30 +++--- .../api/service/permission/IRoleService.kt | 30 +++--- .../api/service/permission/IUserService.kt | 30 +++--- .../impl/AuthenticationServiceImpl.kt | 2 +- .../permission/impl/GroupServiceImpl.kt | 71 +++++++------- .../permission/impl/RoleServiceImpl.kt | 75 +++++++------- .../permission/impl/UserServiceImpl.kt | 97 ++++++++++--------- .../system/impl/SettingsServiceImpl.kt | 2 +- .../api/service/tool/IToolBaseService.kt | 4 +- .../api/service/tool/IToolCategoryService.kt | 2 +- .../oxygen/api/service/tool/IToolService.kt | 2 +- .../api/service/tool/IToolTemplateService.kt | 2 +- .../service/tool/impl/ToolBaseServiceImpl.kt | 5 +- .../tool/impl/ToolCategoryServiceImpl.kt | 16 ++- .../api/service/tool/impl/ToolServiceImpl.kt | 16 +-- .../tool/impl/ToolTemplateServiceImpl.kt | 9 +- 32 files changed, 295 insertions(+), 290 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt index 5238386..563345d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt @@ -38,9 +38,7 @@ class GroupController( @GetMapping("/{id}") @PreAuthorize("hasAnyAuthority('system:group:query:one')") fun getOne(@PathVariable id: Long): ResponseResult = - ResponseResult.databaseSuccess( - data = groupService.getOne(id) - ) + ResponseResult.databaseSuccess(data = groupService.getOne(id)) /** * Get group paging information @@ -76,7 +74,7 @@ class GroupController( @PreAuthorize("hasAnyAuthority('system:group:query:list', 'system:user:add:one', 'system:user:modify:one')") fun list(): ResponseResult> = ResponseResult.databaseSuccess( - data = groupService.listAll() + data = groupService.getList() ) /** @@ -94,11 +92,9 @@ class GroupController( @PostMapping @PreAuthorize("hasAnyAuthority('system:group:add:one')") fun add(@Valid @RequestBody groupAddParam: GroupAddParam): ResponseResult = - groupService.add(groupAddParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_INSERT_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) } + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_INSERT_SUCCESS, data = groupService.add(groupAddParam) + ) /** * Update group @@ -115,11 +111,9 @@ class GroupController( @PutMapping @PreAuthorize("hasAnyAuthority('system:group:modify:one')") fun update(@Valid @RequestBody groupUpdateParam: GroupUpdateParam): ResponseResult = - groupService.update(groupUpdateParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_UPDATE_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) } + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, data = groupService.update(groupUpdateParam) + ) /** * Update status of group @@ -134,12 +128,10 @@ class GroupController( @Operation(summary = "修改用户组状态") @PatchMapping @PreAuthorize("hasAnyAuthority('system:group:modify:status')") - fun updateStatus(@Valid @RequestBody groupUpdateStatusParam: GroupUpdateStatusParam): ResponseResult = - if (groupService.status(groupUpdateStatusParam)) { - ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) - } else { - ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) - } + fun updateStatus(@Valid @RequestBody groupUpdateStatusParam: GroupUpdateStatusParam): ResponseResult { + groupService.status(groupUpdateStatusParam) + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) + } /** * Delete group by ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt index c92dee9..0a45bb8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt @@ -37,11 +37,8 @@ class RoleController( @Operation(summary = "获取单个角色") @GetMapping("/{id}") @PreAuthorize("hasAnyAuthority('system:role:query:one')") - fun getOne(@PathVariable id: Long): ResponseResult { - return ResponseResult.databaseSuccess( - data = roleService.getOne(id) - ) - } + fun getOne(@PathVariable id: Long): ResponseResult = + ResponseResult.databaseSuccess(data = roleService.getOne(id)) /** * Get role paging information @@ -57,11 +54,10 @@ class RoleController( @Operation(summary = "获取角色") @GetMapping @PreAuthorize("hasAnyAuthority('system:role:query:all')") - fun get(roleGetParam: RoleGetParam?): ResponseResult> { - return ResponseResult.databaseSuccess( + fun get(roleGetParam: RoleGetParam?): ResponseResult> = + ResponseResult.databaseSuccess( data = roleService.getPage(roleGetParam) ) - } /** * Get role list @@ -77,7 +73,7 @@ class RoleController( @PreAuthorize("hasAnyAuthority('system:role:query:list', 'system:group:add:one', 'system:group:modify:one', 'system:user:add:one', 'system:user:modify:one')") fun list(): ResponseResult> { return ResponseResult.databaseSuccess( - data = roleService.listAll() + data = roleService.getList() ) } @@ -95,13 +91,10 @@ class RoleController( @Operation(summary = "添加角色") @PostMapping @PreAuthorize("hasAnyAuthority('system:role:add:one')") - fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult { - return roleService.add(roleAddParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_INSERT_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) } - } + fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_INSERT_SUCCESS, data = roleService.add(roleAddParam) + ) /** * Update role @@ -117,13 +110,10 @@ class RoleController( @Operation(summary = "修改角色") @PutMapping @PreAuthorize("hasAnyAuthority('system:role:modify:one')") - fun update(@Valid @RequestBody roleUpdateParam: RoleUpdateParam): ResponseResult { - return roleService.update(roleUpdateParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_UPDATE_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) } - } + fun update(@Valid @RequestBody roleUpdateParam: RoleUpdateParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, data = roleService.update(roleUpdateParam) + ) /** * Update status of role @@ -139,11 +129,8 @@ class RoleController( @PatchMapping @PreAuthorize("hasAnyAuthority('system:role:modify:status')") fun status(@Valid @RequestBody roleUpdateStatusParam: RoleUpdateStatusParam): ResponseResult { - return if (roleService.status(roleUpdateStatusParam)) { - ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) - } else { - ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) - } + roleService.status(roleUpdateStatusParam) + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS) } /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt index 9cb4261..6c23fa7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt @@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult -import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.param.permission.user.* import top.fatweb.oxygen.api.service.permission.IUserService import top.fatweb.oxygen.api.vo.PageVo @@ -38,9 +37,7 @@ class UserController( @Operation(summary = "获取当前用户信息") @GetMapping("info") fun getInfo(): ResponseResult = - userService.getInfo()?.let { - ResponseResult.databaseSuccess(data = it) - } ?: let { ResponseResult.databaseFail() } + ResponseResult.databaseSuccess(data = userService.getInfo()) /** * Get user by ID @@ -56,11 +53,7 @@ class UserController( @GetMapping("/{id}") @PreAuthorize("hasAnyAuthority('system:user:query:one')") fun getOne(@PathVariable id: Long): ResponseResult = - userService.getOne(id)?.let { - ResponseResult.databaseSuccess(data = it) - } ?: let { - throw NoRecordFoundException() - } + ResponseResult.databaseSuccess(data = userService.getOne(id)) /** * Get user paging information @@ -96,11 +89,9 @@ class UserController( @PostMapping @PreAuthorize("hasAnyAuthority('system:user:add:one')") fun add(@Valid @RequestBody userAddParam: UserAddParam): ResponseResult = - userService.add(userAddParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_INSERT_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) } + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_INSERT_SUCCESS, data = userService.add(userAddParam) + ) /** * Update user @@ -117,11 +108,9 @@ class UserController( @PutMapping @PreAuthorize("hasAnyAuthority('system:user:modify:one')") fun update(@Valid @RequestBody userUpdateParam: UserUpdateParam): ResponseResult = - userService.update(userUpdateParam)?.let { - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_UPDATE_SUCCESS, data = it - ) - } ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) } + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, data = userService.update(userUpdateParam) + ) /** * Update user password diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt index d7d95b7..5d14167 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt @@ -18,8 +18,7 @@ class BaseController( @Operation(summary = "获取单个基板") @GetMapping("/{id}") fun getOne(@PathVariable id: Long): ResponseResult = - toolBaseService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } - ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + ResponseResult.databaseSuccess(data = toolBaseService.getOne(id)) @Operation(summary = "获取基板") @GetMapping @@ -46,5 +45,5 @@ class BaseController( @DeleteMapping("/{id}") fun delete(@PathVariable id: Long): ResponseResult = if (toolBaseService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt index 09ef95f..504e3d1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt @@ -25,8 +25,7 @@ class CategoryController( @Operation(summary = "获取单个类别") @GetMapping("/{id}") fun getOne(@PathVariable id: Long): ResponseResult = - toolCategoryService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } - ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + ResponseResult.databaseSuccess(data = toolCategoryService.getOne(id)) @Operation(summary = "获取类别") @GetMapping @@ -53,5 +52,5 @@ class CategoryController( @DeleteMapping("/{id}") fun delete(@PathVariable id: Long): ResponseResult = if (toolCategoryService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index 8027b4b..e69c0c0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -24,8 +24,7 @@ class EditController( @Operation(summary = "获取单个工具") @GetMapping("/{id}") fun getOne(@PathVariable id: Long): ResponseResult = - toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } - ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + ResponseResult.databaseSuccess(data = toolService.getOne(id)) @Operation(summary = "获取工具") @GetMapping @@ -52,5 +51,5 @@ class EditController( @DeleteMapping("/{id}") fun delete(@PathVariable id: Long): ResponseResult = if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt index 1db647c..9e09628 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt @@ -18,8 +18,7 @@ class ManagementController( @Operation(summary = "获取单个工具") @GetMapping("/{id}") fun getOne(@PathVariable id: Long): ResponseResult = - toolService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } - ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + ResponseResult.databaseSuccess(data = toolService.getOne(id)) @Operation(summary = "获取工具") @GetMapping @@ -46,5 +45,5 @@ class ManagementController( @DeleteMapping("/{id}") fun delete(@PathVariable id: Long): ResponseResult = if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt index e9eb154..2067c58 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt @@ -18,8 +18,7 @@ class TemplateController( @Operation(summary = "获取单个模板") @GetMapping("/{id}") fun getOne(@PathVariable id: Long): ResponseResult = - toolTemplateService.getOne(id)?.let { ResponseResult.databaseSuccess(data = it) } - ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_NO_RECORD_FOUND) } + ResponseResult.databaseSuccess(data = toolTemplateService.getOne(id)) @Operation(summary = "获取模板") @GetMapping @@ -46,5 +45,5 @@ class TemplateController( @DeleteMapping("/{id}") fun delete(@PathVariable id: Long): ResponseResult = if (toolTemplateService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FILED) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt index d9b3333..ba16e30 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt @@ -1,7 +1,6 @@ package top.fatweb.oxygen.api.converter.tool import top.fatweb.oxygen.api.entity.tool.ToolBase -import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam import top.fatweb.oxygen.api.vo.tool.ToolBaseVo object ToolBaseConverter { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index 4e3032c..047c15f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -51,9 +51,9 @@ enum class ResponseCode(val code: Int) { DATABASE_INSERT_SUCCESS(BusinessCode.DATABASE, 10), DATABASE_INSERT_FAILED(BusinessCode.DATABASE, 15), DATABASE_UPDATE_SUCCESS(BusinessCode.DATABASE, 20), - DATABASE_UPDATE_FILED(BusinessCode.DATABASE, 25), + DATABASE_UPDATE_FAILED(BusinessCode.DATABASE, 25), DATABASE_DELETE_SUCCESS(BusinessCode.DATABASE, 30), - DATABASE_DELETE_FILED(BusinessCode.DATABASE, 35), + DATABASE_DELETE_FAILED(BusinessCode.DATABASE, 35), DATABASE_EXECUTE_ERROR(BusinessCode.DATABASE, 50), DATABASE_DUPLICATE_KEY(BusinessCode.DATABASE, 51), DATABASE_NO_RECORD_FOUND(BusinessCode.DATABASE, 52), diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt new file mode 100644 index 0000000..f6926b2 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt @@ -0,0 +1,3 @@ +package top.fatweb.oxygen.api.exception + +class DatabaseDeleteException(message: String = "Database delete failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt new file mode 100644 index 0000000..1744ea7 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt @@ -0,0 +1,3 @@ +package top.fatweb.oxygen.api.exception + +class DatabaseInsertException(message: String = "Database insert failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt new file mode 100644 index 0000000..e8e1d2b --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt @@ -0,0 +1,3 @@ +package top.fatweb.oxygen.api.exception + +class DatabaseSelectException(message: String = "Database select failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt new file mode 100644 index 0000000..c2fa87c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt @@ -0,0 +1,3 @@ +package top.fatweb.oxygen.api.exception + +class DatabaseUpdateException(message: String = "Database update failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index a47a3c3..879627a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -166,6 +166,26 @@ class ExceptionHandler { } /* SQL */ + is DatabaseSelectException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.databaseFail(ResponseCode.DATABASE_SELECT_FAILED, e.localizedMessage, null) + } + + is DatabaseInsertException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED, e.localizedMessage, null) + } + + is DatabaseUpdateException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FAILED, e.localizedMessage, null) + } + + is DatabaseDeleteException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED, e.localizedMessage, null) + } + is BadSqlGrammarException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.DATABASE_EXECUTE_ERROR, "Incorrect SQL syntax", null) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt index b117db4..9fc383d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt @@ -59,12 +59,12 @@ class AvatarServiceImpl : IAvatarService { if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty()) TriangleAvatar.newAvatarBuilder() else TriangleAvatar.newAvatarBuilder( - *avatarBaseParam.colors!!.map { decodeColor(it) }.toTypedArray() + *avatarBaseParam.colors!!.map(this::decodeColor).toTypedArray() ) ).apply { - avatarBaseParam?.size?.let { size(it, it) } - avatarBaseParam?.margin?.let { margin(it) } - avatarBaseParam?.padding?.let { padding(it) } + avatarBaseParam?.size?.let(this::size) + avatarBaseParam?.margin?.let(this::margin) + avatarBaseParam?.padding?.let(this::padding) avatarBaseParam?.background?.let { layers(ColorPaintBackgroundLayer(decodeColor(it))) } }.build() @@ -79,12 +79,12 @@ class AvatarServiceImpl : IAvatarService { if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty()) SquareAvatar.newAvatarBuilder() else SquareAvatar.newAvatarBuilder( - *avatarBaseParam.colors!!.map { decodeColor(it) }.toTypedArray() + *avatarBaseParam.colors!!.map(this::decodeColor).toTypedArray() ) ).apply { - avatarBaseParam?.size?.let { size(it, it) } - avatarBaseParam?.margin?.let { margin(it) } - avatarBaseParam?.padding?.let { padding(it) } + avatarBaseParam?.size?.let(this::size) + avatarBaseParam?.margin?.let(this::margin) + avatarBaseParam?.padding?.let(this::padding) avatarBaseParam?.background?.let { layers(ColorPaintBackgroundLayer(decodeColor(it))) } }.build() @@ -96,9 +96,9 @@ class AvatarServiceImpl : IAvatarService { override fun identicon(avatarBaseParam: AvatarBaseParam?): ByteArray { val avatar = IdenticonAvatar.newAvatarBuilder().apply { - avatarBaseParam?.size?.let { size(it, it) } - avatarBaseParam?.margin?.let { margin(it) } - avatarBaseParam?.padding?.let { padding(it) } + avatarBaseParam?.size?.let(this::size) + avatarBaseParam?.margin?.let(this::margin) + avatarBaseParam?.padding?.let(this::padding) if (avatarBaseParam != null && !avatarBaseParam.colors.isNullOrEmpty()) { color(decodeColor(avatarBaseParam.colors!!.random())) } @@ -114,9 +114,9 @@ class AvatarServiceImpl : IAvatarService { override fun github(avatarGitHubParam: AvatarGitHubParam?): ByteArray { val avatar = (avatarGitHubParam?.let { GitHubAvatar.newAvatarBuilder(it.elementSize, it.precision) } ?: let { GitHubAvatar.newAvatarBuilder(400, 5) }).apply { - avatarGitHubParam?.size?.let { size(it, it) } - avatarGitHubParam?.margin?.let { margin(it) } - avatarGitHubParam?.padding?.let { padding(it) } + avatarGitHubParam?.size?.let(this::size) + avatarGitHubParam?.margin?.let(this::margin) + avatarGitHubParam?.padding?.let(this::padding) if (avatarGitHubParam != null && !avatarGitHubParam.colors.isNullOrEmpty()) { color(decodeColor(avatarGitHubParam.colors!!.random())) } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IGroupService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IGroupService.kt index 761ef8d..9db4c4f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IGroupService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IGroupService.kt @@ -16,6 +16,17 @@ import top.fatweb.oxygen.api.vo.permission.base.GroupVo * @see Group */ interface IGroupService : IService { + /** + * Get one group by ID + * + * @param id ID + * @return GroupWithRoleVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see GroupWithRoleVo + */ + fun getOne(id: Long): GroupWithRoleVo + /** * Get group in page * @@ -29,17 +40,6 @@ interface IGroupService : IService { */ fun getPage(groupGetParam: GroupGetParam?): PageVo - /** - * Get one group by ID - * - * @param id ID - * @return GroupWithRoleVo object - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see GroupWithRoleVo - */ - fun getOne(id: Long): GroupWithRoleVo? - /** * Get all group in list * @@ -48,7 +48,7 @@ interface IGroupService : IService { * @since 1.0.0 * @see GroupVo */ - fun listAll(): List + fun getList(): List /** * Add group @@ -60,7 +60,7 @@ interface IGroupService : IService { * @see GroupAddParam * @see GroupVo */ - fun add(groupAddParam: GroupAddParam): GroupVo? + fun add(groupAddParam: GroupAddParam): GroupVo /** * Update group @@ -72,7 +72,7 @@ interface IGroupService : IService { * @see GroupUpdateParam * @see GroupVo */ - fun update(groupUpdateParam: GroupUpdateParam): GroupVo? + fun update(groupUpdateParam: GroupUpdateParam): GroupVo /** * Update status of group @@ -83,7 +83,7 @@ interface IGroupService : IService { * @since 1.0.0 * @see GroupUpdateStatusParam */ - fun status(groupUpdateStatusParam: GroupUpdateStatusParam): Boolean + fun status(groupUpdateStatusParam: GroupUpdateStatusParam) /** * Delete group by ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleService.kt index c12c6d8..37d6da7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IRoleService.kt @@ -16,6 +16,17 @@ import top.fatweb.oxygen.api.vo.permission.base.RoleVo * @see Role */ interface IRoleService : IService { + /** + * Get user by ID + * + * @param id ID + * @return RoleWithPowerVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RoleWithPowerVo + */ + fun getOne(id: Long): RoleWithPowerVo + /** * Get role in page * @@ -29,17 +40,6 @@ interface IRoleService : IService { */ fun getPage(roleGetParam: RoleGetParam?): PageVo - /** - * Get user by ID - * - * @param id ID - * @return RoleWithPowerVo object - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see RoleWithPowerVo - */ - fun getOne(id: Long): RoleWithPowerVo? - /** * Get all role in list * @@ -48,7 +48,7 @@ interface IRoleService : IService { * @since 1.0.0 * @see RoleVo */ - fun listAll(): List + fun getList(): List /** * Add role @@ -60,7 +60,7 @@ interface IRoleService : IService { * @see RoleAddParam * @see RoleVo */ - fun add(roleAddParam: RoleAddParam): RoleVo? + fun add(roleAddParam: RoleAddParam): RoleVo /** * Update role @@ -72,7 +72,7 @@ interface IRoleService : IService { * @see RoleUpdateParam * @see RoleVo */ - fun update(roleUpdateParam: RoleUpdateParam): RoleVo? + fun update(roleUpdateParam: RoleUpdateParam): RoleVo /** * Update status of role @@ -83,7 +83,7 @@ interface IRoleService : IService { * @since 1.0.0 * @see RoleUpdateStatusParam */ - fun status(roleUpdateStatusParam: RoleUpdateStatusParam): Boolean + fun status(roleUpdateStatusParam: RoleUpdateStatusParam) /** * Delete role by ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt index fe38623..3406bf8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt @@ -37,7 +37,18 @@ interface IUserService : IService { * @since 1.0.0 * @see UserWithPowerInfoVo */ - fun getInfo(): UserWithPowerInfoVo? + fun getInfo(): UserWithPowerInfoVo + + /** + * Get one user by ID + * + * @param id ID + * @return UserWithRoleInfoVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see UserWithRoleInfoVo + */ + fun getOne(id: Long): UserWithRoleInfoVo /** * Get user in page @@ -52,17 +63,6 @@ interface IUserService : IService { */ fun getPage(userGetParam: UserGetParam?): PageVo - /** - * Get one user by ID - * - * @param id ID - * @return UserWithRoleInfoVo object - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see UserWithRoleInfoVo - */ - fun getOne(id: Long): UserWithRoleInfoVo? - /** * Get all user as list * @@ -71,7 +71,7 @@ interface IUserService : IService { * @since 1.0.0 * @see UserWithInfoVo */ - fun listAll(): List + fun getList(): List /** * Add user @@ -83,7 +83,7 @@ interface IUserService : IService { * @see UserAddParam * @see UserWithPasswordRoleInfoVo */ - fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo? + fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo /** * Update user @@ -95,7 +95,7 @@ interface IUserService : IService { * @see UserUpdateParam * @see UserWithRoleInfoVo */ - fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo? + fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo /** * Update user password diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt index dc6fd10..45c7a58 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -92,7 +92,7 @@ class AuthenticationServiceImpl( sendVerifyMail(user.username!!, user.verify!!, registerParam.email!!) - val loginVo = this.login(request, registerParam.username!!, registerParam.password!!) + val loginVo = this.login(request, registerParam.username, registerParam.password!!) return RegisterVo(token = loginVo.token, userId = loginVo.userId) } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt index 246137c..d81da51 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt @@ -8,6 +8,9 @@ import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.permission.GroupConverter import top.fatweb.oxygen.api.entity.permission.Group import top.fatweb.oxygen.api.entity.permission.RRoleGroup +import top.fatweb.oxygen.api.exception.DatabaseInsertException +import top.fatweb.oxygen.api.exception.DatabaseUpdateException +import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.mapper.permission.GroupMapper import top.fatweb.oxygen.api.param.permission.group.* import top.fatweb.oxygen.api.service.permission.IGroupService @@ -54,55 +57,51 @@ class GroupServiceImpl( return GroupConverter.groupPageToGroupWithRolePageVo(groupPage) } - override fun getOne(id: Long): GroupWithRoleVo? { - return baseMapper.selectOneById(id)?.let { GroupConverter.groupToGroupWithRoleVo(it) } ?: let { null } - } + override fun getOne(id: Long): GroupWithRoleVo = + baseMapper.selectOneById(id)?.let(GroupConverter::groupToGroupWithRoleVo) ?: throw NoRecordFoundException() - override fun listAll(): List { - val groups = this.list() - - return groups.map { GroupConverter.groupToGroupVo(it) } - } + override fun getList(): List = this.list().map(GroupConverter::groupToGroupVo) @Transactional - override fun add(groupAddParam: GroupAddParam): GroupVo? { + override fun add(groupAddParam: GroupAddParam): GroupVo { val group = GroupConverter.groupAddParamToGroup(groupAddParam) - if (baseMapper.insert(group) == 1) { - if (group.roles.isNullOrEmpty()) { - return GroupConverter.groupToGroupVo(group) - } - - if (rRoleGroupService.saveBatch(group.roles!!.map { - RRoleGroup().apply { - groupId = group.id - roleId = it.id - } - })) { - return GroupConverter.groupToGroupVo(group) - } + if (baseMapper.insert(group) != 1) { + throw DatabaseInsertException() } - return null + if (group.roles.isNullOrEmpty()) { + return GroupConverter.groupToGroupVo(group) + } + + rRoleGroupService.saveBatch(group.roles!!.map { + RRoleGroup().apply { + groupId = group.id + roleId = it.id + } + }) + + return GroupConverter.groupToGroupVo(group) } @Transactional - override fun update(groupUpdateParam: GroupUpdateParam): GroupVo? { + override fun update(groupUpdateParam: GroupUpdateParam): GroupVo { val group = GroupConverter.groupUpdateParamToGroup(groupUpdateParam) + + if (baseMapper.updateById(group) != 1) { + throw DatabaseUpdateException() + } + val oldRoleList = rRoleGroupService.list( KtQueryWrapper(RRoleGroup()).select(RRoleGroup::roleId).eq(RRoleGroup::groupId, groupUpdateParam.id) ).map { it.roleId } val addRoleIds = HashSet() val removeRoleIds = HashSet() - groupUpdateParam.roleIds?.forEach { addRoleIds.add(it) } + groupUpdateParam.roleIds?.forEach(addRoleIds::add) oldRoleList.forEach { - if (it != null) { - removeRoleIds.add(it) - } + it?.let(removeRoleIds::add) } removeRoleIds.removeAll(addRoleIds) - oldRoleList.toSet().let { addRoleIds.removeAll(it) } - - baseMapper.updateById(group) + oldRoleList.toSet().let(addRoleIds::removeAll) removeRoleIds.forEach { rRoleGroupService.remove( @@ -124,13 +123,15 @@ class GroupServiceImpl( return GroupConverter.groupToGroupVo(group) } - override fun status(groupUpdateStatusParam: GroupUpdateStatusParam): Boolean { + override fun status(groupUpdateStatusParam: GroupUpdateStatusParam) { updateById(GroupConverter.groupUpdateStatusParamToGroup(groupUpdateStatusParam)).let { - if (it && !groupUpdateStatusParam.enable) { - groupUpdateStatusParam.id?.let { id -> offlineUser(id) } + if (!it) { + throw DatabaseUpdateException() } - return it + if (!groupUpdateStatusParam.enable) { + groupUpdateStatusParam.id?.let { id -> offlineUser(id) } + } } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt index fdb70e6..8ea381c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt @@ -8,6 +8,9 @@ import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.permission.RoleConverter import top.fatweb.oxygen.api.entity.permission.RPowerRole import top.fatweb.oxygen.api.entity.permission.Role +import top.fatweb.oxygen.api.exception.DatabaseInsertException +import top.fatweb.oxygen.api.exception.DatabaseUpdateException +import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.mapper.permission.RoleMapper import top.fatweb.oxygen.api.param.permission.role.* import top.fatweb.oxygen.api.service.permission.* @@ -58,60 +61,54 @@ class RoleServiceImpl( return RoleConverter.rolePageToRoleWithPowerPageVo(rolePage) } - override fun getOne(id: Long): RoleWithPowerVo? { - return baseMapper.selectOneById(id)?.let { RoleConverter.roleToRoleWithPowerVo(it) } ?: let { null } - } - - override fun listAll(): List { - val roles = this.list() - - return roles.map { RoleConverter.roleToRoleVo(it) } - } + override fun getOne(id: Long): RoleWithPowerVo = + baseMapper.selectOneById(id)?.let(RoleConverter::roleToRoleWithPowerVo) ?: throw NoRecordFoundException() + override fun getList(): List = this.list().map(RoleConverter::roleToRoleVo) @Transactional - override fun add(roleAddParam: RoleAddParam): RoleVo? { - val fullPowerIds = roleAddParam.powerIds?.let { getFullPowerIds(it) } + override fun add(roleAddParam: RoleAddParam): RoleVo { + val fullPowerIds = roleAddParam.powerIds?.let(this::getFullPowerIds) val role = RoleConverter.roleAddParamToRole(roleAddParam) - if (baseMapper.insert(role) == 1) { - if (fullPowerIds.isNullOrEmpty()) { - return RoleConverter.roleToRoleVo(role) - } - - if (rPowerRoleService.saveBatch(fullPowerIds.map { - RPowerRole().apply { - roleId = role.id - powerId = it - } - })) { - return RoleConverter.roleToRoleVo(role) - } + if (baseMapper.insert(role) != 1) { + throw DatabaseInsertException() } - return null + if (fullPowerIds.isNullOrEmpty()) { + return RoleConverter.roleToRoleVo(role) + } + + rPowerRoleService.saveBatch(fullPowerIds.map { + RPowerRole().apply { + roleId = role.id + powerId = it + } + }) + return RoleConverter.roleToRoleVo(role) } @Transactional - override fun update(roleUpdateParam: RoleUpdateParam): RoleVo? { - val fullPowerIds = roleUpdateParam.powerIds?.let { getFullPowerIds(it) } + override fun update(roleUpdateParam: RoleUpdateParam): RoleVo { + val fullPowerIds = roleUpdateParam.powerIds?.let(this::getFullPowerIds) val role = RoleConverter.roleUpdateParamToRole(roleUpdateParam) + + if (baseMapper.updateById(role) != 1) { + throw DatabaseUpdateException() + } + val oldPowerList = rPowerRoleService.list( KtQueryWrapper(RPowerRole()).select(RPowerRole::powerId).eq(RPowerRole::roleId, roleUpdateParam.id) ).map { it.powerId } val addPowerIds = HashSet() val removePowerIds = HashSet() - fullPowerIds?.forEach { addPowerIds.add(it) } + fullPowerIds?.forEach(addPowerIds::add) oldPowerList.forEach { - if (it != null) { - removePowerIds.add(it) - } + it?.let(removePowerIds::add) } removePowerIds.removeAll(addPowerIds) - oldPowerList.toSet().let { addPowerIds.removeAll(it) } - - baseMapper.updateById(role) + oldPowerList.toSet().let(addPowerIds::removeAll) removePowerIds.forEach { rPowerRoleService.remove( @@ -133,13 +130,15 @@ class RoleServiceImpl( return RoleConverter.roleToRoleVo(role) } - override fun status(roleUpdateStatusParam: RoleUpdateStatusParam): Boolean { + override fun status(roleUpdateStatusParam: RoleUpdateStatusParam) { updateById(RoleConverter.roleUpdateStatusParamToRole(roleUpdateStatusParam)).let { - if (it && !roleUpdateStatusParam.enable) { - roleUpdateStatusParam.id?.let { id -> offlineUser(id) } + if (!it) { + throw DatabaseUpdateException() } - return it + if (!roleUpdateStatusParam.enable) { + roleUpdateStatusParam.id?.let { id -> offlineUser(id) } + } } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt index 1758246..b698886 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt @@ -11,11 +11,14 @@ import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.permission.UserConverter -import top.fatweb.oxygen.api.entity.permission.User import top.fatweb.oxygen.api.entity.permission.RUserGroup -import top.fatweb.oxygen.api.entity.permission.UserInfo import top.fatweb.oxygen.api.entity.permission.RUserRole +import top.fatweb.oxygen.api.entity.permission.User +import top.fatweb.oxygen.api.entity.permission.UserInfo +import top.fatweb.oxygen.api.exception.DatabaseInsertException +import top.fatweb.oxygen.api.exception.DatabaseUpdateException import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.exception.UserNotFoundException import top.fatweb.oxygen.api.mapper.permission.UserMapper import top.fatweb.oxygen.api.param.permission.user.* import top.fatweb.oxygen.api.service.permission.* @@ -25,6 +28,7 @@ import top.fatweb.oxygen.api.util.StrUtil import top.fatweb.oxygen.api.util.WebUtil import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.permission.UserWithPasswordRoleInfoVo +import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo import java.time.LocalDateTime import java.time.ZoneOffset @@ -76,8 +80,13 @@ class UserServiceImpl( return user } - override fun getInfo() = WebUtil.getLoginUsername() - ?.let { username -> getUserWithPowerByAccount(username)?.let { UserConverter.userToUserWithPowerInfoVo(it) } } + override fun getInfo(): UserWithPowerInfoVo = + WebUtil.getLoginUsername()?.let(this::getUserWithPowerByAccount)?.let(UserConverter::userToUserWithPowerInfoVo) + ?: throw UserNotFoundException() + + override fun getOne(id: Long): UserWithRoleInfoVo = + baseMapper.selectOneWithRoleInfoById(id)?.let(UserConverter::userToUserWithRoleInfoVo) + ?: throw UserNotFoundException() override fun getPage(userGetParam: UserGetParam?): PageVo { val userIdsPage = Page(userGetParam?.currentPage ?: 1, userGetParam?.pageSize ?: 20) @@ -99,13 +108,10 @@ class UserServiceImpl( return UserConverter.userPageToUserWithRoleInfoPageVo(userPage) } - override fun getOne(id: Long) = - baseMapper.selectOneWithRoleInfoById(id)?.let { UserConverter.userToUserWithRoleInfoVo(it) } - - override fun listAll() = baseMapper.selectListWithInfo().map { UserConverter.userToUserWithInfoVo(it) } + override fun getList() = baseMapper.selectListWithInfo().map(UserConverter::userToUserWithInfoVo) @Transactional - override fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo? { + override fun add(userAddParam: UserAddParam): UserWithPasswordRoleInfoVo { val rawPassword = if (userAddParam.password.isNullOrBlank()) StrUtil.getRandomPassword(10) else userAddParam.password val user = UserConverter.userAddParamToUser(userAddParam) @@ -117,37 +123,38 @@ class UserServiceImpl( }-${UUID.randomUUID()}-${UUID.randomUUID()}-${UUID.randomUUID()}" } - if (this.save(user)) { - user.userInfo?.let { userInfoService.save(it.apply { userId = user.id }) } - - if (!user.roles.isNullOrEmpty()) { - rUserRoleService.saveBatch(user.roles!!.map { - RUserRole().apply { - userId = user.id - roleId = it.id - } - }) - } - - if (!user.groups.isNullOrEmpty()) { - rUserGroupService.saveBatch(user.groups!!.map { - RUserGroup().apply { - userId = user.id - groupId = it.id - } - }) - } - - user.password = rawPassword - - return UserConverter.userToUserWithPasswordRoleInfoVo(user) + if (!this.save(user)) { + throw DatabaseInsertException() } - return null + + user.userInfo?.apply { userId = user.id }?.let(userInfoService::save) + + if (!user.roles.isNullOrEmpty()) { + rUserRoleService.saveBatch(user.roles!!.map { + RUserRole().apply { + userId = user.id + roleId = it.id + } + }) + } + + if (!user.groups.isNullOrEmpty()) { + rUserGroupService.saveBatch(user.groups!!.map { + RUserGroup().apply { + userId = user.id + groupId = it.id + } + }) + } + + user.password = rawPassword + + return UserConverter.userToUserWithPasswordRoleInfoVo(user) } @Transactional - override fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo? { + override fun update(userUpdateParam: UserUpdateParam): UserWithRoleInfoVo { val user = UserConverter.userUpdateParamToUser(userUpdateParam) user.updateTime = LocalDateTime.now(ZoneOffset.UTC) @@ -156,28 +163,24 @@ class UserServiceImpl( ).map { it.roleId } val addRoleIds = HashSet() val removeRoleIds = HashSet() - userUpdateParam.roleIds?.forEach { addRoleIds.add(it) } + userUpdateParam.roleIds?.forEach(addRoleIds::add) oldRoleList.forEach { - if (it != null) { - removeRoleIds.add(it) - } + it?.let(removeRoleIds::add) } removeRoleIds.removeAll(addRoleIds) - oldRoleList.toSet().let { addRoleIds.removeAll(it) } + oldRoleList.toSet().let(addRoleIds::removeAll) val oldGroupList = rUserGroupService.list( KtQueryWrapper(RUserGroup()).select(RUserGroup::groupId).eq(RUserGroup::userId, userUpdateParam.id) ).map { it.groupId } val addGroupIds = HashSet() val removeGroupIds = HashSet() - userUpdateParam.groupIds?.forEach { addGroupIds.add(it) } + userUpdateParam.groupIds?.forEach(addGroupIds::add) oldGroupList.forEach { - if (it != null) { - removeGroupIds.add(it) - } + it?.let(removeGroupIds::add) } removeGroupIds.removeAll(addGroupIds) - oldGroupList.toSet().let { addGroupIds.removeAll(it) } + oldGroupList.toSet().let(addGroupIds::removeAll) this.updateById(user) this.update( @@ -252,7 +255,9 @@ class UserServiceImpl( ) .set(User::updateTime, LocalDateTime.now(ZoneOffset.UTC)) - this.update(wrapper) + if (!this.update(wrapper)) { + throw DatabaseUpdateException() + } userUpdatePasswordParam.id?.let { WebUtil.offlineUser(redisUtil, it) } } ?: let { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt index c107aa4..aa3a7e5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt @@ -50,7 +50,7 @@ class SettingsServiceImpl : ISettingsService { port = SettingsOperator.getMailValue(MailSettings::port), securityType = SettingsOperator.getMailValue(MailSettings::securityType), username = SettingsOperator.getMailValue(MailSettings::username), - password = SettingsOperator.getMailValue(MailSettings::password)?.let { StrUtil.md5(it) }, + password = SettingsOperator.getMailValue(MailSettings::password)?.let(StrUtil::md5), from = SettingsOperator.getMailValue(MailSettings::from), fromName = SettingsOperator.getMailValue(MailSettings::fromName) ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt index 0ccfff9..f4e9fbb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt @@ -2,11 +2,9 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.ToolBase -import top.fatweb.oxygen.api.entity.tool.ToolCategory import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam import top.fatweb.oxygen.api.vo.tool.ToolBaseVo -import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo /** * Tool base service interface @@ -17,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo * @see ToolBase */ interface IToolBaseService : IService { - fun getOne(id: Long): ToolBaseVo? + fun getOne(id: Long): ToolBaseVo fun get(): List diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt index c661773..4f70553 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt @@ -15,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo * @see ToolCategory */ interface IToolCategoryService : IService { - fun getOne(id: Long): ToolCategoryVo? + fun getOne(id: Long): ToolCategoryVo fun get(): List diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt index d32a1a5..69ef68c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt @@ -15,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo * @see Tool */ interface IToolService : IService { - fun getOne(id: Long): ToolVo? + fun getOne(id: Long): ToolVo fun get(): List diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt index 3fcdf81..7d29168 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt @@ -15,7 +15,7 @@ import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo * @see ToolTemplate */ interface IToolTemplateService : IService { - fun getOne(id: Long): ToolTemplateVo? + fun getOne(id: Long): ToolTemplateVo fun get(): List diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt index 4b338da..445c830 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -28,7 +28,8 @@ import top.fatweb.oxygen.api.vo.tool.ToolBaseVo class ToolBaseServiceImpl( private val toolDataService: IToolDataService ) : ServiceImpl(), IToolBaseService { - override fun getOne(id: Long): ToolBaseVo? = baseMapper.selectOne(id)?.let(ToolBaseConverter::toolBaseToToolBaseVo) + override fun getOne(id: Long): ToolBaseVo = + baseMapper.selectOne(id)?.let(ToolBaseConverter::toolBaseToToolBaseVo) ?: throw NoRecordFoundException() override fun get(): List = baseMapper.selectList().map(ToolBaseConverter::toolBaseToToolBaseVo) @@ -72,7 +73,7 @@ class ToolBaseServiceImpl( name = toolBaseUpdateParam.name }) - return this.getOne(toolBase.id!!)!! + return this.getOne(toolBase.id!!) } @Transactional diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt index a9c408b..d200bb4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt @@ -2,9 +2,11 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.tool.ToolCategoryConverter import top.fatweb.oxygen.api.entity.tool.ToolCategory +import top.fatweb.oxygen.api.exception.DatabaseInsertException +import top.fatweb.oxygen.api.exception.DatabaseUpdateException +import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.mapper.tool.ToolCategoryMapper import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam @@ -23,8 +25,8 @@ import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo */ @Service class ToolCategoryServiceImpl : ServiceImpl(), IToolCategoryService { - override fun getOne(id: Long): ToolCategoryVo? = - this.getById(id)?.let(ToolCategoryConverter::toolCategoryToToolCategoryVo) + override fun getOne(id: Long): ToolCategoryVo = + this.getById(id)?.let(ToolCategoryConverter::toolCategoryToToolCategoryVo) ?: throw NoRecordFoundException() override fun get(): List = this.list().map(ToolCategoryConverter::toolCategoryToToolCategoryVo) @@ -32,7 +34,9 @@ class ToolCategoryServiceImpl : ServiceImpl(), override fun add(toolCategoryAddParam: ToolCategoryAddParam): ToolCategoryVo { val toolCategory = ToolCategoryConverter.toolCategoryAddParamToToolCategory(toolCategoryAddParam) - this.save(toolCategory) + if (!this.save(toolCategory)) { + throw DatabaseInsertException() + } return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory) } @@ -40,7 +44,9 @@ class ToolCategoryServiceImpl : ServiceImpl(), override fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo { val toolCategory = ToolCategoryConverter.toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam) - this.updateById(toolCategory) + if (this.updateById(toolCategory)) { + throw DatabaseUpdateException() + } return ToolCategoryConverter.toolCategoryToToolCategoryVo(toolCategory) } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt index f48ca96..ca982af 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt @@ -10,7 +10,6 @@ import top.fatweb.oxygen.api.entity.tool.Tool import top.fatweb.oxygen.api.entity.tool.ToolData import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.exception.ToolHasPublish -import top.fatweb.oxygen.api.exception.UserNotFoundException import top.fatweb.oxygen.api.mapper.tool.ToolMapper import top.fatweb.oxygen.api.param.tool.ToolAddParam import top.fatweb.oxygen.api.param.tool.ToolUpdateParam @@ -36,14 +35,15 @@ class ToolServiceImpl( private val rToolCategoryService: IRToolCategoryService, private val userService: IUserService ) : ServiceImpl(), IToolService { - override fun getOne(id: Long): ToolVo? = baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) + override fun getOne(id: Long): ToolVo = + baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() override fun get(): List = baseMapper.selectList().map(ToolConverter::toolToToolVo) @Transactional override fun add(toolAddParam: ToolAddParam): ToolVo { - toolBaseService.getOne(toolAddParam.baseId!!) ?: throw NoRecordFoundException() - userService.getOne(toolAddParam.authorId!!) ?: throw UserNotFoundException() + toolBaseService.getOne(toolAddParam.baseId!!) + userService.getOne(toolAddParam.authorId!!) val newSource = ToolData().apply { data = toolAddParam.source } val newDist = ToolData().apply { data = toolAddParam.dist } @@ -74,7 +74,7 @@ class ToolServiceImpl( }) } - return this.getOne(tool.id!!)!! + return this.getOne(tool.id!!) } @Transactional @@ -83,7 +83,7 @@ class ToolServiceImpl( if (tool.publish == 1) { throw ToolHasPublish() } - userService.getOne(toolUpdateParam.authorId!!) ?: throw UserNotFoundException() + userService.getOne(toolUpdateParam.authorId!!) toolDataService.updateById(ToolData().apply { id = tool.sourceId @@ -106,9 +106,9 @@ class ToolServiceImpl( keywords = toolUpdateParam.keywords }) - // TODO + // TODO Category process - return this.getOne(tool.id!!)!! + return this.getOne(tool.id!!) } @Transactional diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt index f78b226..872b24a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt @@ -30,15 +30,16 @@ class ToolTemplateServiceImpl( private val toolDataService: IToolDataService, private val toolBaseService: IToolBaseService ) : ServiceImpl(), IToolTemplateService { - override fun getOne(id: Long): ToolTemplateVo? = + override fun getOne(id: Long): ToolTemplateVo = baseMapper.selectOne(id)?.let(ToolTemplateConverter::toolTemplateToToolTemplateVo) + ?: throw NoRecordFoundException() override fun get(): List = baseMapper.selectList().map(ToolTemplateConverter::toolTemplateToToolTemplateVo) @Transactional override fun add(toolTemplateAddParam: ToolTemplateAddParam): ToolTemplateVo { - toolBaseService.getOne(toolTemplateAddParam.baseId!!) ?: throw NoRecordFoundException() + toolBaseService.getOne(toolTemplateAddParam.baseId!!) val newSource = ToolData().apply { data = toolTemplateAddParam.source } val newDist = ToolData().apply { data = toolTemplateAddParam.dist } @@ -64,7 +65,7 @@ class ToolTemplateServiceImpl( @Transactional override fun update(toolTemplateUpdateParam: ToolTemplateUpdateParam): ToolTemplateVo { val toolTemplate = baseMapper.selectOne(toolTemplateUpdateParam.id!!) ?: throw NoRecordFoundException() - toolTemplateUpdateParam.baseId?.let { toolBaseService.getOne(it) ?: throw NoRecordFoundException() } + toolTemplateUpdateParam.baseId?.let(toolBaseService::getOne) toolDataService.updateById(ToolData().apply { id = toolTemplate.sourceId @@ -83,7 +84,7 @@ class ToolTemplateServiceImpl( baseId = toolTemplateUpdateParam.baseId }) - return this.getOne(toolTemplate.id!!)!! + return this.getOne(toolTemplate.id!!) } @Transactional From 3da5260ddd136314879b16c3156ed591ca274dcb Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 19 Jan 2024 18:27:34 +0800 Subject: [PATCH 178/258] Add enable field to ToolBase and ToolTemplate --- .../api/controller/tool/BaseController.kt | 5 +++ .../api/converter/tool/ToolBaseConverter.kt | 14 ++++++- .../converter/tool/ToolTemplateConverter.kt | 3 +- .../fatweb/oxygen/api/entity/tool/ToolBase.kt | 9 ++++ .../oxygen/api/entity/tool/ToolTemplate.kt | 9 ++++ .../oxygen/api/param/tool/ToolBaseAddParam.kt | 9 ++-- .../api/param/tool/ToolBaseUpdateParam.kt | 4 +- .../api/param/tool/ToolTemplateAddParam.kt | 4 +- .../api/param/tool/ToolTemplateUpdateParam.kt | 4 +- .../api/service/tool/IToolBaseService.kt | 2 + .../service/tool/impl/ToolBaseServiceImpl.kt | 3 ++ .../tool/impl/ToolTemplateServiceImpl.kt | 2 + .../fatweb/oxygen/api/vo/tool/ToolBaseVo.kt | 2 + .../oxygen/api/vo/tool/ToolTemplateVo.kt | 2 + ..._240119__Add_table_'t_b_tool_template'.sql | 1 + ..._0_0_240120__Add_table_'t_b_tool_base'.sql | 1 + .../resources/mapper/tool/ToolBaseMapper.xml | 42 ++++++++++--------- .../mapper/tool/ToolTemplateMapper.xml | 3 ++ 18 files changed, 90 insertions(+), 29 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt index 5d14167..48d5cb4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt @@ -25,6 +25,11 @@ class BaseController( fun get(): ResponseResult> = ResponseResult.databaseSuccess(data = toolBaseService.get()) + @Operation(summary = "获取基板列表") + @GetMapping("/list") + fun getList(): ResponseResult> = + ResponseResult.databaseSuccess(data = toolBaseService.getList()) + @Operation(summary = "新增基板") @PostMapping fun add(@RequestBody @Valid toolBaseAddParam: ToolBaseAddParam): ResponseResult = diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt index ba16e30..923a315 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.converter.tool import top.fatweb.oxygen.api.entity.tool.ToolBase import top.fatweb.oxygen.api.vo.tool.ToolBaseVo +import top.fatweb.oxygen.api.vo.tool.ToolDataVo object ToolBaseConverter { fun toolBaseToToolBaseVo(toolBase: ToolBase) = ToolBaseVo( @@ -10,6 +11,17 @@ object ToolBaseConverter { source = toolBase.source?.let(ToolDataConverter::toolDataToToolDataVo), dist = toolBase.dist?.let(ToolDataConverter::toolDataToToolDataVo), createTime = toolBase.createTime, - updateTime = toolBase.updateTime + updateTime = toolBase.updateTime, + enable = toolBase.enable == 1 + ) + + fun toolBaseToToolBaseVoByGetList(toolBase: ToolBase) = ToolBaseVo( + id = toolBase.id, + name = toolBase.name, + source = ToolDataVo(id = toolBase.sourceId, data = null, createTime = null, updateTime = null), + dist = ToolDataVo(id = toolBase.distId, data = null, createTime = null, updateTime = null), + createTime = toolBase.createTime, + updateTime = toolBase.updateTime, + enable = toolBase.enable == 1 ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt index 3a665e9..391a857 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt @@ -12,6 +12,7 @@ object ToolTemplateConverter { source = toolTemplate.source?.let(ToolDataConverter::toolDataToToolDataVo), dist = toolTemplate.dist?.let(ToolDataConverter::toolDataToToolDataVo), createTime = toolTemplate.createTime, - updateTime = toolTemplate.updateTime + updateTime = toolTemplate.updateTime, + enable = toolTemplate.enable == 1 ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt index ba9b5b5..c74bc40 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt @@ -47,6 +47,15 @@ class ToolBase { @TableField("dist_id") var distId: Long? = null + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("enable") + var enable: Int? = null + /** * Create time * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt index 7d47149..ad1a41e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt @@ -65,6 +65,15 @@ class ToolTemplate { @TableField("dist_id") var distId: Long? = null + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("enable") + var enable: Int? = null + /** * Create time * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt index 77f4bfa..b0962b9 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt @@ -1,15 +1,14 @@ package top.fatweb.oxygen.api.param.tool import jakarta.validation.constraints.NotBlank -import jakarta.validation.constraints.NotNull data class ToolBaseAddParam( @field: NotBlank(message = "Name can not be blank") val name: String?, - @field: NotNull(message = "Source can not be null") - val source: String?, + val source: String = "", - @field:NotNull(message = "Dist can not be null") - val dist: String? + val dist: String = "", + + val enable: Boolean = true ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt index 6287b11..cbd1918 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt @@ -10,5 +10,7 @@ data class ToolBaseUpdateParam( val source: String?, - val dist: String? + val dist: String?, + + val enable: Boolean? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt index 49839d0..ad96aec 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt @@ -19,5 +19,7 @@ data class ToolTemplateAddParam( val source: String?, @field:NotNull(message = "Dist can not be null") - val dist: String? + val dist: String?, + + val enable: Boolean = true ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt index d170e3e..1d90f3f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt @@ -16,5 +16,7 @@ data class ToolTemplateUpdateParam( val source: String?, - val dist: String? + val dist: String?, + + val enable: Boolean? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt index f4e9fbb..894ad43 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt @@ -19,6 +19,8 @@ interface IToolBaseService : IService { fun get(): List + fun getList(): List + fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo fun update(toolBaseUpdateParam: ToolBaseUpdateParam): ToolBaseVo diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt index 445c830..ea68d32 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -32,6 +32,7 @@ class ToolBaseServiceImpl( baseMapper.selectOne(id)?.let(ToolBaseConverter::toolBaseToToolBaseVo) ?: throw NoRecordFoundException() override fun get(): List = baseMapper.selectList().map(ToolBaseConverter::toolBaseToToolBaseVo) + override fun getList(): List = this.list().map(ToolBaseConverter::toolBaseToToolBaseVoByGetList) @Transactional override fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo { @@ -47,6 +48,7 @@ class ToolBaseServiceImpl( distId = newDist.id source = newSource dist = newDist + enable = if (toolBaseAddParam.enable) 1 else 0 } this.save(toolBase) @@ -71,6 +73,7 @@ class ToolBaseServiceImpl( this.updateById(ToolBase().apply { id = toolBaseUpdateParam.id name = toolBaseUpdateParam.name + enable = toolBaseUpdateParam.enable?.let { if (it) 1 else 0 } }) return this.getOne(toolBase.id!!) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt index 872b24a..229a46a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt @@ -55,6 +55,7 @@ class ToolTemplateServiceImpl( distId = newDist.id source = newSource dist = newDist + enable = if (toolTemplateAddParam.enable) 1 else 0 } this.save(toolTemplate) @@ -82,6 +83,7 @@ class ToolTemplateServiceImpl( name = toolTemplateUpdateParam.name ver = toolTemplateUpdateParam.ver baseId = toolTemplateUpdateParam.baseId + enable = toolTemplateUpdateParam.enable?.let { if (it) 1 else 0 } }) return this.getOne(toolTemplate.id!!) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt index cc92560..4cc2f65 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt @@ -14,6 +14,8 @@ data class ToolBaseVo( val dist: ToolDataVo?, + val enable: Boolean?, + val createTime: LocalDateTime?, val updateTime: LocalDateTime? diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt index cce4be4..235d5ae 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt @@ -19,6 +19,8 @@ data class ToolTemplateVo( val dist: ToolDataVo?, + val enable: Boolean?, + val createTime: LocalDateTime?, val updateTime: LocalDateTime? diff --git a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql index d5317b0..b5b6451 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql @@ -8,6 +8,7 @@ create table if not exists t_b_tool_template base_id bigint not null comment '基板 ID', source_id bigint not null comment '源码 ID', dist_id bigint not null comment '产物 ID', + enable int not null default 1 comment '启用', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', deleted bigint not null default 0, diff --git a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql index d6e1c17..4d02b98 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql @@ -6,6 +6,7 @@ create table if not exists t_b_tool_base name varchar(20) not null comment '基板名', source_id bigint not null comment '源码 ID', dist_id bigint not null comment '产物 ID', + enable int not null default 1 comment '启用', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', deleted bigint not null default 0, diff --git a/src/main/resources/mapper/tool/ToolBaseMapper.xml b/src/main/resources/mapper/tool/ToolBaseMapper.xml index d940e45..d6a4a5f 100644 --- a/src/main/resources/mapper/tool/ToolBaseMapper.xml +++ b/src/main/resources/mapper/tool/ToolBaseMapper.xml @@ -6,6 +6,7 @@ t_b_tool_base.name as tool_base_name, t_b_tool_base.source_id as tool_base_source_id, t_b_tool_base.dist_id as tool_base_dist_id, + t_b_tool_base.enable as tool_base_enable, t_b_tool_base.create_time as tool_base_create_time, t_b_tool_base.update_time as tool_base_update_time, t_b_tool_base.deleted as tool_base_deleted, @@ -29,27 +30,29 @@ @@ -58,6 +61,7 @@ + diff --git a/src/main/resources/mapper/tool/ToolTemplateMapper.xml b/src/main/resources/mapper/tool/ToolTemplateMapper.xml index cd73755..3b7ca5c 100644 --- a/src/main/resources/mapper/tool/ToolTemplateMapper.xml +++ b/src/main/resources/mapper/tool/ToolTemplateMapper.xml @@ -8,6 +8,7 @@ t_b_tool_template.base_id as tool_template_base_id, t_b_tool_template.source_id as tool_template_source_id, t_b_tool_template.dist_id as tool_template_dist_id, + t_b_tool_template.enable as tool_template_enable, t_b_tool_template.create_time as tool_template_create_time, t_b_tool_template.update_time as tool_template_update_time, t_b_tool_template.deleted as tool_template_deleted, @@ -38,6 +39,7 @@ t_b_tool_template.base_id as tool_template_base_id, t_b_tool_template.source_id as tool_template_source_id, t_b_tool_template.dist_id as tool_template_dist_id, + t_b_tool_template.enable as tool_template_enable, t_b_tool_template.create_time as tool_template_create_time, t_b_tool_template.update_time as tool_template_update_time, t_b_tool_template.deleted as tool_template_deleted, @@ -67,6 +69,7 @@ + From 98e2f637d293788f87f783992d09dc21f9d9954c Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 22 Jan 2024 18:18:47 +0800 Subject: [PATCH 179/258] Optimize ToolBase and ToolTemplate api --- .../api/controller/tool/BaseController.kt | 5 -- .../converter/tool/ToolTemplateConverter.kt | 4 +- .../oxygen/api/entity/tool/ToolTemplate.kt | 24 ++------- .../oxygen/api/mapper/tool/ToolBaseMapper.kt | 2 - .../api/param/tool/ToolTemplateAddParam.kt | 11 +--- .../api/param/tool/ToolTemplateUpdateParam.kt | 6 --- .../api/service/tool/IToolBaseService.kt | 2 - .../service/tool/impl/ToolBaseServiceImpl.kt | 3 +- .../tool/impl/ToolTemplateServiceImpl.kt | 13 +---- .../oxygen/api/vo/tool/ToolTemplateVo.kt | 7 +-- ..._240119__Add_table_'t_b_tool_template'.sql | 2 - .../resources/mapper/tool/ToolBaseMapper.xml | 32 ++--------- .../mapper/tool/ToolTemplateMapper.xml | 53 ++++++------------- 13 files changed, 29 insertions(+), 135 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt index 48d5cb4..5d14167 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt @@ -25,11 +25,6 @@ class BaseController( fun get(): ResponseResult> = ResponseResult.databaseSuccess(data = toolBaseService.get()) - @Operation(summary = "获取基板列表") - @GetMapping("/list") - fun getList(): ResponseResult> = - ResponseResult.databaseSuccess(data = toolBaseService.getList()) - @Operation(summary = "新增基板") @PostMapping fun add(@RequestBody @Valid toolBaseAddParam: ToolBaseAddParam): ResponseResult = diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt index 391a857..3244ed7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt @@ -7,10 +7,8 @@ object ToolTemplateConverter { fun toolTemplateToToolTemplateVo(toolTemplate: ToolTemplate) = ToolTemplateVo( id = toolTemplate.id, name = toolTemplate.name, - ver = toolTemplate.ver, - baseId = toolTemplate.baseId, + base = toolTemplate.base?.let(ToolBaseConverter::toolBaseToToolBaseVo), source = toolTemplate.source?.let(ToolDataConverter::toolDataToToolDataVo), - dist = toolTemplate.dist?.let(ToolDataConverter::toolDataToToolDataVo), createTime = toolTemplate.createTime, updateTime = toolTemplate.updateTime, enable = toolTemplate.enable == 1 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt index ad1a41e..1fcbdd4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt @@ -29,15 +29,6 @@ class ToolTemplate { @TableField("name") var name: String? = null - /** - * ver - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @TableField("ver") - var ver: String? = null - /** * Base ID * @@ -56,15 +47,6 @@ class ToolTemplate { @TableField("source_id") var sourceId: Long? = null - /** - * Dist ID - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @TableField("dist_id") - var distId: Long? = null - /** * Enable * @@ -124,15 +106,15 @@ class ToolTemplate { var source: ToolData? = null /** - * Dist + * Base * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ @TableField(exist = false) - var dist: ToolData? = null + var base: ToolBase? = null override fun toString(): String { - return "ToolTemplate(id=$id, name=$name, ver=$ver, baseId=$baseId, sourceId=$sourceId, distId=$distId, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)" + return "ToolTemplate(id=$id, name=$name, baseId=$baseId, sourceId=$sourceId, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, base=$base)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt index d79f84d..51f9d82 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt @@ -16,6 +16,4 @@ import top.fatweb.oxygen.api.entity.tool.ToolBase @Mapper interface ToolBaseMapper : BaseMapper { fun selectOne(@Param("id") id: Long): ToolBase? - - fun selectList(): List } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt index ad96aec..f1d8a66 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt @@ -2,24 +2,15 @@ package top.fatweb.oxygen.api.param.tool import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.NotNull -import jakarta.validation.constraints.Pattern data class ToolTemplateAddParam( @field: NotBlank(message = "Name can not be blank") val name: String?, - @field: NotBlank(message = "Ver can not be blank") - @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") - val ver: String?, - @field: NotNull(message = "BaseId can not be null") val baseId: Long? = null, - @field: NotNull(message = "Source can not be null") - val source: String?, - - @field:NotNull(message = "Dist can not be null") - val dist: String?, + val source: String = "", val enable: Boolean = true ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt index 1d90f3f..a158999 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt @@ -1,7 +1,6 @@ package top.fatweb.oxygen.api.param.tool import jakarta.validation.constraints.NotNull -import jakarta.validation.constraints.Pattern data class ToolTemplateUpdateParam( @field: NotNull(message = "ID can not be null") @@ -9,14 +8,9 @@ data class ToolTemplateUpdateParam( val name: String?, - @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") - val ver: String?, - val baseId: Long?, val source: String?, - val dist: String?, - val enable: Boolean? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt index 894ad43..f4e9fbb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt @@ -19,8 +19,6 @@ interface IToolBaseService : IService { fun get(): List - fun getList(): List - fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo fun update(toolBaseUpdateParam: ToolBaseUpdateParam): ToolBaseVo diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt index ea68d32..904dba7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -31,8 +31,7 @@ class ToolBaseServiceImpl( override fun getOne(id: Long): ToolBaseVo = baseMapper.selectOne(id)?.let(ToolBaseConverter::toolBaseToToolBaseVo) ?: throw NoRecordFoundException() - override fun get(): List = baseMapper.selectList().map(ToolBaseConverter::toolBaseToToolBaseVo) - override fun getList(): List = this.list().map(ToolBaseConverter::toolBaseToToolBaseVoByGetList) + override fun get(): List = this.list().map(ToolBaseConverter::toolBaseToToolBaseVoByGetList) @Transactional override fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt index 229a46a..116f9fd 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt @@ -42,19 +42,14 @@ class ToolTemplateServiceImpl( toolBaseService.getOne(toolTemplateAddParam.baseId!!) val newSource = ToolData().apply { data = toolTemplateAddParam.source } - val newDist = ToolData().apply { data = toolTemplateAddParam.dist } toolDataService.save(newSource) - toolDataService.save(newDist) val toolTemplate = ToolTemplate().apply { name = toolTemplateAddParam.name - ver = toolTemplateAddParam.ver baseId = toolTemplateAddParam.baseId sourceId = newSource.id - distId = newDist.id source = newSource - dist = newDist enable = if (toolTemplateAddParam.enable) 1 else 0 } @@ -73,15 +68,9 @@ class ToolTemplateServiceImpl( data = toolTemplateUpdateParam.source }) - toolDataService.updateById(ToolData().apply { - id = toolTemplate.distId - data = toolTemplateUpdateParam.dist - }) - this.updateById(ToolTemplate().apply { id = toolTemplateUpdateParam.id name = toolTemplateUpdateParam.name - ver = toolTemplateUpdateParam.ver baseId = toolTemplateUpdateParam.baseId enable = toolTemplateUpdateParam.enable?.let { if (it) 1 else 0 } }) @@ -93,7 +82,7 @@ class ToolTemplateServiceImpl( override fun delete(id: Long): Boolean { val toolTemplate = this.getById(id) - return toolDataService.removeBatchByIds(listOf(toolTemplate.sourceId, toolTemplate.distId)) + return toolDataService.removeById(toolTemplate.sourceId) && this.removeById(id) } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt index 235d5ae..ae9c5f9 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt @@ -10,15 +10,10 @@ data class ToolTemplateVo( val name: String?, - val ver: String?, - - @JsonSerialize(using = ToStringSerializer::class) - val baseId: Long?, + val base: ToolBaseVo?, val source: ToolDataVo?, - val dist: ToolDataVo?, - val enable: Boolean?, val createTime: LocalDateTime?, diff --git a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql index b5b6451..8a91504 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql @@ -4,10 +4,8 @@ create table if not exists t_b_tool_template ( id bigint not null primary key, name varchar(40) not null comment '模板名', - ver varchar(20) not null comment '版本', base_id bigint not null comment '基板 ID', source_id bigint not null comment '源码 ID', - dist_id bigint not null comment '产物 ID', enable int not null default 1 comment '启用', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', diff --git a/src/main/resources/mapper/tool/ToolBaseMapper.xml b/src/main/resources/mapper/tool/ToolBaseMapper.xml index d6a4a5f..68112da 100644 --- a/src/main/resources/mapper/tool/ToolBaseMapper.xml +++ b/src/main/resources/mapper/tool/ToolBaseMapper.xml @@ -1,7 +1,7 @@ - select t_b_tool_base.id as tool_base_id, t_b_tool_base.name as tool_base_name, t_b_tool_base.source_id as tool_base_source_id, @@ -29,33 +29,6 @@ and t_b_tool_base.id = #{id} - - @@ -66,6 +39,9 @@ + + + diff --git a/src/main/resources/mapper/tool/ToolTemplateMapper.xml b/src/main/resources/mapper/tool/ToolTemplateMapper.xml index 3b7ca5c..be3e29a 100644 --- a/src/main/resources/mapper/tool/ToolTemplateMapper.xml +++ b/src/main/resources/mapper/tool/ToolTemplateMapper.xml @@ -1,13 +1,11 @@ - select t_b_tool_template.id as tool_template_id, t_b_tool_template.name as tool_template_name, - t_b_tool_template.ver as tool_template_ver, t_b_tool_template.base_id as tool_template_base_id, t_b_tool_template.source_id as tool_template_source_id, - t_b_tool_template.dist_id as tool_template_dist_id, t_b_tool_template.enable as tool_template_enable, t_b_tool_template.create_time as tool_template_create_time, t_b_tool_template.update_time as tool_template_update_time, @@ -18,16 +16,13 @@ tbtds.update_time as tool_template_source_update_time, tbtds.deleted as tool_template_source_delete, tbtds.version as tool_template_source_version, - tbtdd.data as tool_template_dist_data, - tbtdd.create_time as tool_template_dist_create_time, - tbtdd.update_time as tool_template_dist_update_time, - tbtdd.deleted as tool_template_dist_delete, - tbtdd.version as tool_template_dist_version + tbtb.name as tool_template_base_name, + tbtb.enable as tool_template_base_enable from t_b_tool_template left join (select * from t_b_tool_data where deleted = 0) as tbtds on tbtds.id = t_b_tool_template.source_id - left join (select * from t_b_tool_data where deleted = 0) as tbtdd - on tbtdd.id = t_b_tool_template.dist_id + left join (select * from t_b_tool_base where deleted = 0) as tbtb + on tbtb.id = t_b_tool_template.base_id where t_b_tool_template.deleted = 0 and t_b_tool_template.id = #{id} @@ -35,45 +30,39 @@ - - + + + + + + + + @@ -82,13 +71,5 @@ - - - - - - - - From cecf4ab2bfc885b59c1af78cd2728397f691680c Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 23 Jan 2024 15:43:22 +0800 Subject: [PATCH 180/258] Optimize ToolBase api --- .../api/converter/tool/ToolBaseConverter.kt | 2 ++ .../fatweb/oxygen/api/entity/tool/ToolBase.kt | 11 +++++++- .../service/tool/impl/ToolBaseServiceImpl.kt | 25 +++++++++++++------ .../fatweb/oxygen/api/vo/tool/ToolBaseVo.kt | 2 ++ ..._0_0_240118__Add_table_'t_b_tool_data'.sql | 12 ++++----- ..._0_0_240120__Add_table_'t_b_tool_base'.sql | 1 + .../resources/mapper/tool/ToolBaseMapper.xml | 2 ++ 7 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt index 923a315..b91e267 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt @@ -10,6 +10,7 @@ object ToolBaseConverter { name = toolBase.name, source = toolBase.source?.let(ToolDataConverter::toolDataToToolDataVo), dist = toolBase.dist?.let(ToolDataConverter::toolDataToToolDataVo), + compiled = toolBase.compiled == 1, createTime = toolBase.createTime, updateTime = toolBase.updateTime, enable = toolBase.enable == 1 @@ -20,6 +21,7 @@ object ToolBaseConverter { name = toolBase.name, source = ToolDataVo(id = toolBase.sourceId, data = null, createTime = null, updateTime = null), dist = ToolDataVo(id = toolBase.distId, data = null, createTime = null, updateTime = null), + compiled = toolBase.compiled == 1, createTime = toolBase.createTime, updateTime = toolBase.updateTime, enable = toolBase.enable == 1 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt index c74bc40..10a591b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt @@ -47,6 +47,15 @@ class ToolBase { @TableField("dist_id") var distId: Long? = null + /** + * Has compiled + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("compiled") + var compiled: Int? = null + /** * Enable * @@ -115,6 +124,6 @@ class ToolBase { var dist: ToolData? = null override fun toString(): String { - return "ToolBase(id=$id, name=$name, sourceId=$sourceId, distId=$distId, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, dist=$dist)" + return "ToolBase(id=$id, name=$name, sourceId=$sourceId, distId=$distId, compiled=$compiled, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, dist=$dist)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt index 904dba7..ce921c7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -59,19 +59,28 @@ class ToolBaseServiceImpl( override fun update(toolBaseUpdateParam: ToolBaseUpdateParam): ToolBaseVo { val toolBase = baseMapper.selectOne(toolBaseUpdateParam.id!!) ?: throw NoRecordFoundException() - toolDataService.updateById(ToolData().apply { - id = toolBase.sourceId - data = toolBaseUpdateParam.source - }) + var hasCompiled: Int? = null - toolDataService.updateById(ToolData().apply { - id = toolBase.distId - data = toolBaseUpdateParam.dist - }) + if (!toolBaseUpdateParam.source.isNullOrBlank()) { + toolDataService.updateById(ToolData().apply { + id = toolBase.sourceId + data = toolBaseUpdateParam.source + }) + hasCompiled = 0 + } + + if (!toolBaseUpdateParam.dist.isNullOrBlank()) { + toolDataService.updateById(ToolData().apply { + id = toolBase.distId + data = toolBaseUpdateParam.dist + }) + hasCompiled = 1 + } this.updateById(ToolBase().apply { id = toolBaseUpdateParam.id name = toolBaseUpdateParam.name + compiled = hasCompiled enable = toolBaseUpdateParam.enable?.let { if (it) 1 else 0 } }) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt index 4cc2f65..5c0681a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt @@ -14,6 +14,8 @@ data class ToolBaseVo( val dist: ToolDataVo?, + val compiled: Boolean?, + val enable: Boolean?, val createTime: LocalDateTime?, diff --git a/src/main/resources/db/migration/master/V1_0_0_240118__Add_table_'t_b_tool_data'.sql b/src/main/resources/db/migration/master/V1_0_0_240118__Add_table_'t_b_tool_data'.sql index fc61740..f05e75a 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240118__Add_table_'t_b_tool_data'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240118__Add_table_'t_b_tool_data'.sql @@ -2,10 +2,10 @@ drop table if exists t_b_tool_data; create table if not exists t_b_tool_data ( - id bigint not null primary key, - data text not null comment '数据', - create_time datetime not null default (utc_timestamp()) comment '创建时间', - update_time datetime not null default (utc_timestamp()) comment '修改时间', - deleted bigint not null default 0, - version int not null default 0 + id bigint not null primary key, + data mediumtext not null comment '数据', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0 ) comment '工具-数据表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql index 4d02b98..deee8b0 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql @@ -6,6 +6,7 @@ create table if not exists t_b_tool_base name varchar(20) not null comment '基板名', source_id bigint not null comment '源码 ID', dist_id bigint not null comment '产物 ID', + compiled int not null default 0 comment '已编译', enable int not null default 1 comment '启用', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', diff --git a/src/main/resources/mapper/tool/ToolBaseMapper.xml b/src/main/resources/mapper/tool/ToolBaseMapper.xml index 68112da..26fe0c3 100644 --- a/src/main/resources/mapper/tool/ToolBaseMapper.xml +++ b/src/main/resources/mapper/tool/ToolBaseMapper.xml @@ -6,6 +6,7 @@ t_b_tool_base.name as tool_base_name, t_b_tool_base.source_id as tool_base_source_id, t_b_tool_base.dist_id as tool_base_dist_id, + t_b_tool_base.compiled as tool_base_compiled, t_b_tool_base.enable as tool_base_enable, t_b_tool_base.create_time as tool_base_create_time, t_b_tool_base.update_time as tool_base_update_time, @@ -34,6 +35,7 @@ + From ea2868e87ad5af62cef55bb36053d3f74e45ad2b Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 24 Jan 2024 16:16:18 +0800 Subject: [PATCH 181/258] Optimize kdoc --- .../permission/AuthenticationController.kt | 2 +- .../controller/permission/GroupController.kt | 4 ++-- .../controller/permission/PowerController.kt | 2 +- .../controller/permission/RoleController.kt | 2 +- .../controller/permission/UserController.kt | 2 +- .../controller/system/SettingsController.kt | 2 +- .../controller/system/StatisticsController.kt | 2 +- .../api/controller/system/SysLogController.kt | 2 +- .../api/converter/system/SettingsConverter.kt | 20 +++++++++++++++++++ .../oxygen/api/entity/permission/User.kt | 2 +- .../api/vo/permission/UserWithPowerInfoVo.kt | 2 +- 11 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/AuthenticationController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/AuthenticationController.kt index d443136..1d21a2c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/AuthenticationController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/AuthenticationController.kt @@ -108,7 +108,7 @@ class AuthenticationController( * * @param request * @param retrieveParam Retrieve parameters - * @return Response object include retrieve result + * @return Response object includes retrieve result * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see HttpServletRequest diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt index 563345d..664a928 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/GroupController.kt @@ -14,7 +14,7 @@ import top.fatweb.oxygen.api.vo.permission.GroupWithRoleVo import top.fatweb.oxygen.api.vo.permission.base.GroupVo /** - * Group controller + * Group management controller * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 @@ -28,7 +28,7 @@ class GroupController( * Get group by ID * * @param id Group ID - * @return Response object includes group info + * @return Response object includes group information * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see ResponseResult diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/PowerController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/PowerController.kt index 4fcfa08..310f809 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/PowerController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/PowerController.kt @@ -9,7 +9,7 @@ import top.fatweb.oxygen.api.service.permission.IPowerService import top.fatweb.oxygen.api.vo.permission.PowerSetVo /** - * Power controller + * Power management controller * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt index 0a45bb8..77144e2 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/RoleController.kt @@ -14,7 +14,7 @@ import top.fatweb.oxygen.api.vo.permission.RoleWithPowerVo import top.fatweb.oxygen.api.vo.permission.base.RoleVo /** - * Role controller + * Role management controller * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt index 6c23fa7..af08ef3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/permission/UserController.kt @@ -15,7 +15,7 @@ import top.fatweb.oxygen.api.vo.permission.UserWithPowerInfoVo import top.fatweb.oxygen.api.vo.permission.UserWithRoleInfoVo /** - * User controller + * User management controller * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt index 451a7d5..68adf8e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SettingsController.kt @@ -20,7 +20,7 @@ import top.fatweb.oxygen.api.vo.system.MailSettingsVo import top.fatweb.oxygen.api.vo.system.SensitiveWordVo /** - * System settings controller + * System settings management controller * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/system/StatisticsController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/StatisticsController.kt index f21802b..4826755 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/system/StatisticsController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/StatisticsController.kt @@ -11,7 +11,7 @@ import top.fatweb.oxygen.api.service.system.IStatisticsService import top.fatweb.oxygen.api.vo.system.* /** - * Statistics controller + * Statistics management controller * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SysLogController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SysLogController.kt index 01c37cd..894fe05 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SysLogController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/system/SysLogController.kt @@ -13,7 +13,7 @@ import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.system.SysLogVo /** - * System log controller + * System log viewer controller * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt index a9f29bb..2d7f717 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt @@ -11,6 +11,16 @@ import top.fatweb.oxygen.api.vo.system.SensitiveWordVo * @since 1.0.0 */ object SettingsConverter { + /** + * Convert SensitiveWord object into SensitiveWordVo object + * + * @param sensitiveWord SensitiveWord object + * @return SensitiveWordVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see SensitiveWord + * @see SensitiveWordVo + */ fun sensitiveWordToSensitiveWordVo(sensitiveWord: SensitiveWord) = SensitiveWordVo( id = sensitiveWord.id, word = sensitiveWord.word, @@ -18,6 +28,16 @@ object SettingsConverter { enable = sensitiveWord.enable == 1 ) + /** + * Convert SensitiveWordAddParam object into SensitiveWord object + * + * @param sensitiveWordAddParam SensitiveWordAddParam object + * @return SensitiveWord object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see SensitiveWordAddParam + * @see SensitiveWord + */ fun sensitiveWordAddParamToSensitiveWord(sensitiveWordAddParam: SensitiveWordAddParam) = SensitiveWord().apply { word = sensitiveWordAddParam.word useFor = sensitiveWordAddParam.useFor.map(SensitiveWord.Use::code).toSet() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/User.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/User.kt index 905178f..11324c6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/User.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/permission/User.kt @@ -181,7 +181,7 @@ class User() : Serializable { var version: Int? = null /** - * User info + * User information * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithPowerInfoVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithPowerInfoVo.kt index 7fd460c..4616b50 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithPowerInfoVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/permission/UserWithPowerInfoVo.kt @@ -119,7 +119,7 @@ data class UserWithPowerInfoVo( val lastLoginIp: String?, /** - * Update time + * Create time * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 From 6e73f8212bef4f0660562e37ce1dd32a42677bc0 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 24 Jan 2024 16:17:17 +0800 Subject: [PATCH 182/258] Add kdoc and permission --- .../api/controller/tool/BaseController.kt | 63 ++++++++++++++++++ .../api/controller/tool/CategoryController.kt | 57 +++++++++++++++- .../api/controller/tool/TemplateController.kt | 63 ++++++++++++++++++ .../api/converter/tool/ToolBaseConverter.kt | 26 ++++++++ .../converter/tool/ToolCategoryConverter.kt | 36 ++++++++++ .../api/converter/tool/ToolConverter.kt | 16 +++++ .../api/converter/tool/ToolDataConverter.kt | 16 +++++ .../converter/tool/ToolTemplateConverter.kt | 16 +++++ .../oxygen/api/param/tool/ToolBaseAddParam.kt | 25 +++++-- .../api/param/tool/ToolBaseUpdateParam.kt | 42 ++++++++++++ .../api/param/tool/ToolCategoryAddParam.kt | 21 ++++++ .../api/param/tool/ToolCategoryUpdateParam.kt | 30 ++++++++- .../api/param/tool/ToolTemplateAddParam.kt | 30 ++++++++- .../api/param/tool/ToolTemplateUpdateParam.kt | 42 ++++++++++++ .../api/service/tool/IToolBaseService.kt | 45 +++++++++++++ .../api/service/tool/IToolCategoryService.kt | 45 +++++++++++++ .../api/service/tool/IToolTemplateService.kt | 45 +++++++++++++ .../service/tool/impl/ToolBaseServiceImpl.kt | 4 +- .../tool/impl/ToolTemplateServiceImpl.kt | 2 +- .../fatweb/oxygen/api/vo/tool/ToolBaseVo.kt | 65 +++++++++++++++++++ .../oxygen/api/vo/tool/ToolCategoryVo.kt | 44 +++++++++++++ .../fatweb/oxygen/api/vo/tool/ToolDataVo.kt | 37 +++++++++++ .../oxygen/api/vo/tool/ToolTemplateVo.kt | 58 +++++++++++++++++ ..._0_0_240115__Add_table_'t_b_tool_main'.sql | 4 +- 24 files changed, 818 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt index 5d14167..f682fd3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.controller.tool import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid +import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.entity.common.ResponseCode @@ -11,38 +12,100 @@ import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam import top.fatweb.oxygen.api.service.tool.IToolBaseService import top.fatweb.oxygen.api.vo.tool.ToolBaseVo +/** + * Tool base management controller + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IToolBaseService + */ @BaseController(path = ["/system/tool/base"], name = "工具基板管理", description = "工具基板管理相关接口") class BaseController( private val toolBaseService: IToolBaseService ) { + /** + * Get tool base by ID + * + * @param id Tool base ID + * @return Response object includes tool base information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolBaseVo + */ @Operation(summary = "获取单个基板") @GetMapping("/{id}") + @PreAuthorize("hasAnyAuthority('system:tool:query:base')") fun getOne(@PathVariable id: Long): ResponseResult = ResponseResult.databaseSuccess(data = toolBaseService.getOne(id)) + /** + * Get tool base list + * + * @return Response object includes tool base list + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolBaseVo + */ @Operation(summary = "获取基板") @GetMapping + @PreAuthorize("hasAnyAuthority('system:tool:query:base', 'system:tool:add:template', 'system:tool:modify:template')") fun get(): ResponseResult> = ResponseResult.databaseSuccess(data = toolBaseService.get()) + /** + * Add tool base + * + * @param toolBaseAddParam Add tool base parameters + * @return Response object includes tool base information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBaseAddParam + * @see ResponseResult + * @see ToolBaseVo + */ @Operation(summary = "新增基板") @PostMapping + @PreAuthorize("hasAnyAuthority('system:tool:add:base')") fun add(@RequestBody @Valid toolBaseAddParam: ToolBaseAddParam): ResponseResult = ResponseResult.databaseSuccess( ResponseCode.DATABASE_INSERT_SUCCESS, data = toolBaseService.add(toolBaseAddParam) ) + /** + * Update tool base + * + * @param toolBaseUpdateParam Update tool base parameters + * @return Response object includes tool base information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBaseUpdateParam + * @see ResponseResult + * @see ToolBaseVo + */ @Operation(summary = "更新基板") @PutMapping + @PreAuthorize("hasAnyAuthority('system:tool:modify:base')") fun update(@RequestBody @Valid toolBaseUpdateParam: ToolBaseUpdateParam): ResponseResult = ResponseResult.databaseSuccess( ResponseCode.DATABASE_UPDATE_SUCCESS, data = toolBaseService.update(toolBaseUpdateParam) ) + /** + * Delete tool base by ID + * + * @param id Tool base ID + * @return Response object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + */ @Operation(summary = "删除基板") @DeleteMapping("/{id}") + @PreAuthorize("hasAnyAuthority('system:tool:delete:base')") fun delete(@PathVariable id: Long): ResponseResult = if (toolBaseService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt index 504e3d1..2a79f65 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/CategoryController.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.controller.tool import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid +import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.entity.common.ResponseCode @@ -11,7 +12,6 @@ import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam import top.fatweb.oxygen.api.service.tool.IToolCategoryService import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo - /** * Tool category management controller * @@ -22,34 +22,89 @@ import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo class CategoryController( private val toolCategoryService: IToolCategoryService ) { + /** + * Get tool category by ID + * + * @param id Tool category ID + * @return Response object includes tool template information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolCategoryVo + */ @Operation(summary = "获取单个类别") @GetMapping("/{id}") + @PreAuthorize("hasAnyAuthority('system:tool:query:category')") fun getOne(@PathVariable id: Long): ResponseResult = ResponseResult.databaseSuccess(data = toolCategoryService.getOne(id)) + /** + * Get tool category list + * + * @return Response object includes tool template list + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolCategoryVo + */ @Operation(summary = "获取类别") @GetMapping + @PreAuthorize("hasAnyAuthority('system:tool:query:category')") fun get(): ResponseResult> = ResponseResult.databaseSuccess(data = toolCategoryService.get()) + /** + * Add tool category + * + * @param toolCategoryAddParam Add tool category parameters + * @return Response object includes tool category information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryAddParam + * @see ResponseResult + * @see ToolCategoryVo + */ @Operation(summary = "新增类别") @PostMapping + @PreAuthorize("hasAnyAuthority('system:tool:add:category')") fun add(@RequestBody @Valid toolCategoryAddParam: ToolCategoryAddParam): ResponseResult = ResponseResult.databaseSuccess( ResponseCode.DATABASE_INSERT_SUCCESS, data = toolCategoryService.add(toolCategoryAddParam) ) + /** + * Update tool category + * + * @param toolCategoryUpdateParam Update tool category parameters + * @return Response object includes tool category information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryUpdateParam + * @see ResponseResult + * @see ToolCategoryVo + */ @Operation(summary = "更新类别") @PutMapping + @PreAuthorize("hasAnyAuthority('system:tool:modify:category')") fun update(@RequestBody @Valid toolCategoryUpdateParam: ToolCategoryUpdateParam): ResponseResult = ResponseResult.databaseSuccess( ResponseCode.DATABASE_UPDATE_SUCCESS, data = toolCategoryService.update(toolCategoryUpdateParam) ) + /** + * Delete tool category + * + * @param id Tool category ID + * @return Response object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + */ @Operation(summary = "删除类别") @DeleteMapping("/{id}") + @PreAuthorize("hasAnyAuthority('system:tool:delete:category')") fun delete(@PathVariable id: Long): ResponseResult = if (toolCategoryService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt index 2067c58..ab7fe7e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/TemplateController.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.controller.tool import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid +import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.entity.common.ResponseCode @@ -11,38 +12,100 @@ import top.fatweb.oxygen.api.param.tool.ToolTemplateUpdateParam import top.fatweb.oxygen.api.service.tool.IToolTemplateService import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo +/** + * Tool template management controller + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IToolTemplateService + */ @BaseController(path = ["/system/tool/template"], name = "工具模板管理", description = "工具模板管理相关接口") class TemplateController( private val toolTemplateService: IToolTemplateService ) { + /** + * Get tool template by ID + * + * @param id Tool template ID + * @return Response object includes tool template information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolTemplateVo + */ @Operation(summary = "获取单个模板") @GetMapping("/{id}") + @PreAuthorize("hasAnyAuthority('system:tool:query:template')") fun getOne(@PathVariable id: Long): ResponseResult = ResponseResult.databaseSuccess(data = toolTemplateService.getOne(id)) + /** + * Get tool template list + * + * @return Response object includes tool template list + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolTemplateVo + */ @Operation(summary = "获取模板") @GetMapping + @PreAuthorize("hasAnyAuthority('system:tool:query:template')") fun get(): ResponseResult> = ResponseResult.databaseSuccess(data = toolTemplateService.get()) + /** + * Add tool template + * + * @param toolTemplateAddParam Add tool template parameters + * @return Response object includes tool template information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplateAddParam + * @see ResponseResult + * @see ToolTemplateVo + */ @Operation(summary = "添加模板") @PostMapping + @PreAuthorize("hasAnyAuthority('system:tool:add:template')") fun add(@RequestBody @Valid toolTemplateAddParam: ToolTemplateAddParam): ResponseResult = ResponseResult.databaseSuccess( ResponseCode.DATABASE_INSERT_SUCCESS, data = toolTemplateService.add(toolTemplateAddParam) ) + /** + * Update tool template + * + * @param toolTemplateUpdateParam Update tool template parameters + * @return Response object includes tool template information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplateUpdateParam + * @see ResponseResult + * @see ToolTemplateVo + */ @Operation(summary = "更新模板") @PutMapping + @PreAuthorize("hasAnyAuthority('system:tool:modify:template')") fun update(@RequestBody @Valid toolTemplateUpdateParam: ToolTemplateUpdateParam): ResponseResult = ResponseResult.databaseSuccess( ResponseCode.DATABASE_UPDATE_SUCCESS, data = toolTemplateService.update(toolTemplateUpdateParam) ) + /** + * Delete tool template + * + * @param id Tool template ID + * @return Response object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + */ @Operation(summary = "删除模板") @DeleteMapping("/{id}") + @PreAuthorize("hasAnyAuthority('system:tool:delete:template')") fun delete(@PathVariable id: Long): ResponseResult = if (toolTemplateService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt index b91e267..03cada4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt @@ -4,7 +4,23 @@ import top.fatweb.oxygen.api.entity.tool.ToolBase import top.fatweb.oxygen.api.vo.tool.ToolBaseVo import top.fatweb.oxygen.api.vo.tool.ToolDataVo +/** + * Tool base converter + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ object ToolBaseConverter { + /** + * Convert ToolBase object into ToolBaseVo object + * + * @param toolBase ToolBase object + * @return ToolBaseVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBase + * @see ToolBaseVo + */ fun toolBaseToToolBaseVo(toolBase: ToolBase) = ToolBaseVo( id = toolBase.id, name = toolBase.name, @@ -16,6 +32,16 @@ object ToolBaseConverter { enable = toolBase.enable == 1 ) + /** + * Convert ToolBase object into ToolBaseVo object by get list + * + * @param toolBase ToolBase object + * @return ToolBaseVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBase + * @see ToolBaseVo + */ fun toolBaseToToolBaseVoByGetList(toolBase: ToolBase) = ToolBaseVo( id = toolBase.id, name = toolBase.name, diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt index aa8a41c..f01feb8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt @@ -5,7 +5,23 @@ import top.fatweb.oxygen.api.param.tool.ToolCategoryAddParam import top.fatweb.oxygen.api.param.tool.ToolCategoryUpdateParam import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo +/** + * Tool category converter + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ object ToolCategoryConverter { + /** + * Convert ToolCategory object into ToolCategoryVo object + * + * @param toolCategory ToolCategory object + * @return ToolCategoryVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategory + * @see ToolCategoryVo + */ fun toolCategoryToToolCategoryVo(toolCategory: ToolCategory) = ToolCategoryVo( id = toolCategory.id, name = toolCategory.name, @@ -14,11 +30,31 @@ object ToolCategoryConverter { updateTime = toolCategory.updateTime ) + /** + * Convert ToolCategoryAddParam object into ToolCategory object + * + * @param toolCategoryAddParam ToolCategoryAddParam object + * @return ToolCateGory object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryAddParam + * @see ToolCategory + */ fun toolCategoryAddParamToToolCategory(toolCategoryAddParam: ToolCategoryAddParam) = ToolCategory().apply { name = toolCategoryAddParam.name enable = if (toolCategoryAddParam.enable) 1 else 0 } + /** + * Convert ToolCategoryUpdateParam object into ToolCategory object + * + * @param toolCategoryUpdateParam ToolCategoryUpdateParam object + * @return ToolCategory object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryUpdateParam + * @see ToolCategory + */ fun toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam: ToolCategoryUpdateParam) = ToolCategory().apply { id = toolCategoryUpdateParam.id name = toolCategoryUpdateParam.name diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt index 92cc185..d490e11 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt @@ -4,7 +4,23 @@ import top.fatweb.oxygen.api.converter.permission.UserInfoConverter import top.fatweb.oxygen.api.entity.tool.Tool import top.fatweb.oxygen.api.vo.tool.ToolVo +/** + * Tool converter + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ object ToolConverter { + /** + * Convert Tool object into ToolVo object + * + * @param tool Tool object + * @return ToolVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tool + * @see ToolVo + */ fun toolToToolVo(tool: Tool) = ToolVo( id = tool.id, name = tool.name, diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolDataConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolDataConverter.kt index bd978b0..117752d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolDataConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolDataConverter.kt @@ -3,7 +3,23 @@ package top.fatweb.oxygen.api.converter.tool import top.fatweb.oxygen.api.entity.tool.ToolData import top.fatweb.oxygen.api.vo.tool.ToolDataVo +/** + * Tool data converter + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ object ToolDataConverter { + /** + * Convert ToolData object into ToolDataVo object + * + * @param toolData ToolData object + * @return ToolDataVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolData + * @see ToolDataVo + */ fun toolDataToToolDataVo(toolData: ToolData) = ToolDataVo( id = toolData.id, data = toolData.data, diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt index 3244ed7..37c93fa 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt @@ -3,7 +3,23 @@ package top.fatweb.oxygen.api.converter.tool import top.fatweb.oxygen.api.entity.tool.ToolTemplate import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo +/** + * Tool template converter + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ object ToolTemplateConverter { + /** + * Convert ToolTemplate object into ToolTemplateVo object + * + * @param toolTemplate ToolTemplate object + * @return ToolTemplateVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplate + * @see ToolTemplateVo + */ fun toolTemplateToToolTemplateVo(toolTemplate: ToolTemplate) = ToolTemplateVo( id = toolTemplate.id, name = toolTemplate.name, diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt index b0962b9..773aa51 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt @@ -1,14 +1,31 @@ package top.fatweb.oxygen.api.param.tool +import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank +/** + * Add tool base parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ data class ToolBaseAddParam( + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称", required = true) @field: NotBlank(message = "Name can not be blank") val name: String?, - val source: String = "", - - val dist: String = "", - + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "启用", allowableValues = ["true", "false"], defaultValue = "true") val enable: Boolean = true ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt index cbd1918..83f4cc3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt @@ -1,16 +1,58 @@ package top.fatweb.oxygen.api.param.tool +import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull +/** + * Update tool base parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ data class ToolBaseUpdateParam( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "ID", required = true) @field: NotNull(message = "ID can not be null") val id: Long?, + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称") val name: String?, + /** + * Source + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "源码") val source: String?, + /** + * Dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "产物") val dist: String?, + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "启用", allowableValues = ["true", "false"]) val enable: Boolean? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryAddParam.kt index 7e8bc39..657bb98 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryAddParam.kt @@ -1,10 +1,31 @@ package top.fatweb.oxygen.api.param.tool +import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank +/** + * Add tool category parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ data class ToolCategoryAddParam( + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称", required = true) @field: NotBlank(message = "Name can not be blank") val name: String?, + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "启用", allowableValues = ["true", "false"], defaultValue = "true") val enable: Boolean = true ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt index 4fca7ec..84496b3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt @@ -1,14 +1,40 @@ package top.fatweb.oxygen.api.param.tool -import jakarta.validation.constraints.NotBlank +import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull +/** + * Update tool category parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ data class ToolCategoryUpdateParam( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "ID", required = true) @field: NotNull(message = "ID can not be null") val id: Long?, - @field: NotBlank(message = "Name can not be blank") + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称") val name: String?, + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "启用", allowableValues = ["true", "false"]) val enable: Boolean? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt index f1d8a66..44fa42d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt @@ -1,16 +1,42 @@ package top.fatweb.oxygen.api.param.tool +import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.NotNull +/** + * Add tool template parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ data class ToolTemplateAddParam( + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称", required = true) @field: NotBlank(message = "Name can not be blank") val name: String?, + /** + * Base ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "Base ID", required = true) @field: NotNull(message = "BaseId can not be null") val baseId: Long? = null, - val source: String = "", - + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "启用", allowableValues = ["true", "false"], defaultValue = "true") val enable: Boolean = true ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt index a158999..a06672b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt @@ -1,16 +1,58 @@ package top.fatweb.oxygen.api.param.tool +import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull +/** + * Update tool template parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ data class ToolTemplateUpdateParam( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "ID", required = true) @field: NotNull(message = "ID can not be null") val id: Long?, + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称") val name: String?, + /** + * Base ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "Base ID") val baseId: Long?, + /** + * Source + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "源码") val source: String?, + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "启用", allowableValues = ["true", "false"]) val enable: Boolean? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt index f4e9fbb..5bd0966 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolBaseService.kt @@ -15,13 +15,58 @@ import top.fatweb.oxygen.api.vo.tool.ToolBaseVo * @see ToolBase */ interface IToolBaseService : IService { + /** + * Get tool base by ID + * + * @param id ID + * @return ToolBaseVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBaseVo + */ fun getOne(id: Long): ToolBaseVo + /** + * Get tool base in list + * + * @return List of ToolBaseVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBaseVo + */ fun get(): List + /** + * Add tool base + * + * @param toolBaseAddParam Add tool base parameters + * @return ToolBaseVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBaseAddParam + * @see ToolBaseVo + */ fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo + /** + * Update tool base + * + * @param toolBaseUpdateParam Update tool base parameters + * @return ToolBaseVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBaseUpdateParam + * @see ToolBaseVo + */ fun update(toolBaseUpdateParam: ToolBaseUpdateParam): ToolBaseVo + /** + * Delete tool base + * + * @param id ID + * @return Result + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ fun delete(id: Long): Boolean } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt index 4f70553..7b2e3a5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolCategoryService.kt @@ -15,13 +15,58 @@ import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo * @see ToolCategory */ interface IToolCategoryService : IService { + /** + * Get tool category by ID + * + * @param id ID + * @return ToolCategoryVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryVo + */ fun getOne(id: Long): ToolCategoryVo + /** + * Get tool category in list + * + * @return List of ToolCategoryVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryVo + */ fun get(): List + /** + * Add tool category + * + * @param toolCategoryAddParam Add tool category parameters + * @return ToolCategoryVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryAddParam + * @see ToolCategoryVo + */ fun add(toolCategoryAddParam: ToolCategoryAddParam): ToolCategoryVo + /** + * Update tool category + * + * @param toolCategoryUpdateParam Update tool category parameters + * @return ToolCategoryVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryUpdateParam + * @see ToolCategoryVo + */ fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo + /** + * Delete tool category + * + * @param id ID + * @return Result + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ fun delete(id: Long): Boolean } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt index 7d29168..1cb3d54 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolTemplateService.kt @@ -15,13 +15,58 @@ import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo * @see ToolTemplate */ interface IToolTemplateService : IService { + /** + * Get tool template by ID + * + * @param id ID + * @return ToolTemplateVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplateVo + */ fun getOne(id: Long): ToolTemplateVo + /** + * Get tool template in list + * + * @return List of ToolTemplateVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplateVo + */ fun get(): List + /** + * Add tool template + * + * @param toolTemplateAddParam Add tool template parameters + * @return ToolTemplateVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplateAddParam + * @see ToolTemplateVo + */ fun add(toolTemplateAddParam: ToolTemplateAddParam): ToolTemplateVo + /** + * Update tool template + * + * @param toolTemplateUpdateParam Update tool template parameters + * @return ToolTemplateVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplateUpdateParam + * @see ToolTemplateVo + */ fun update(toolTemplateUpdateParam: ToolTemplateUpdateParam): ToolTemplateVo + /** + * Delete tool template + * + * @param id ID + * @return Result + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ fun delete(id: Long): Boolean } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt index ce921c7..278dda4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -35,8 +35,8 @@ class ToolBaseServiceImpl( @Transactional override fun add(toolBaseAddParam: ToolBaseAddParam): ToolBaseVo { - val newSource = ToolData().apply { data = toolBaseAddParam.source } - val newDist = ToolData().apply { data = toolBaseAddParam.dist } + val newSource = ToolData().apply { data = "" } + val newDist = ToolData().apply { data = "" } toolDataService.save(newSource) toolDataService.save(newDist) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt index 116f9fd..47706bf 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt @@ -41,7 +41,7 @@ class ToolTemplateServiceImpl( override fun add(toolTemplateAddParam: ToolTemplateAddParam): ToolTemplateVo { toolBaseService.getOne(toolTemplateAddParam.baseId!!) - val newSource = ToolData().apply { data = toolTemplateAddParam.source } + val newSource = ToolData().apply { data = "" } toolDataService.save(newSource) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt index 5c0681a..954dcb0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt @@ -2,23 +2,88 @@ package top.fatweb.oxygen.api.vo.tool import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer +import io.swagger.v3.oas.annotations.media.Schema import java.time.LocalDateTime +/** + * Tool base value object + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(description = "工具基板返回参数") data class ToolBaseVo( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @JsonSerialize(using = ToStringSerializer::class) val id: Long?, + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称") val name: String?, + /** + * Source + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "源码") val source: ToolDataVo?, + /** + * Dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "产物") val dist: ToolDataVo?, + /** + * Compiled + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "已编译") val compiled: Boolean?, + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "启用") val enable: Boolean?, + /** + * Create time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "创建时间", example = "1900-01-01T00:00:00.000Z") val createTime: LocalDateTime?, + /** + * Update time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z") val updateTime: LocalDateTime? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolCategoryVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolCategoryVo.kt index 2c1d3a1..3be4db8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolCategoryVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolCategoryVo.kt @@ -2,17 +2,61 @@ package top.fatweb.oxygen.api.vo.tool import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer +import io.swagger.v3.oas.annotations.media.Schema import java.time.LocalDateTime +/** + * Tool base value object + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(description = "工具类别返回参数") data class ToolCategoryVo( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @JsonSerialize(using = ToStringSerializer::class) val id: Long?, + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称") val name: String?, + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "启用") val enable: Boolean?, + /** + * Create time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "创建时间", example = "1900-01-01T00:00:00.000Z") val createTime: LocalDateTime?, + /** + * Update time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z") val updateTime: LocalDateTime? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolDataVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolDataVo.kt index dde38e5..309dbf4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolDataVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolDataVo.kt @@ -2,15 +2,52 @@ package top.fatweb.oxygen.api.vo.tool import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer +import io.swagger.v3.oas.annotations.media.Schema import java.time.LocalDateTime +/** + * Tool data value object + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(description = "工具数据返回参数") data class ToolDataVo( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @JsonSerialize(using = ToStringSerializer::class) val id: Long?, + /** + * Data + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "数据") val data: String?, + /** + * Create time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "创建时间", example = "1900-01-01T00:00:00.000Z") val createTime: LocalDateTime?, + /** + * Update time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z") val updateTime: LocalDateTime? ) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt index ae9c5f9..90b71d5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt @@ -2,21 +2,79 @@ package top.fatweb.oxygen.api.vo.tool import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer +import io.swagger.v3.oas.annotations.media.Schema import java.time.LocalDateTime +/** + * Tool template value object + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(description = "工具模板返回参数") data class ToolTemplateVo( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @JsonSerialize(using = ToStringSerializer::class) val id: Long?, + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称") val name: String?, + /** + * Base + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "基板") val base: ToolBaseVo?, + /** + * Source + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "源码") val source: ToolDataVo?, + /** + * Enable + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "启用") val enable: Boolean?, + /** + * Create time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "创建时间", example = "1900-01-01T00:00:00.000Z") val createTime: LocalDateTime?, + /** + * Update time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z") val updateTime: LocalDateTime? ) \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql index 9e31827..45b96e6 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql @@ -10,7 +10,7 @@ create table if not exists t_b_tool_main author_id bigint not null comment '作者 ID', ver varchar(20) not null comment '版本', privately int not null default 0 comment '私有', - keywords varchar(500) not null comment '关键字', + keywords varchar(500) not null comment '关键字', source_id bigint not null comment '源码 ID', dist_id bigint not null comment '产物 ID', publish int not null default 0 comment '发布', @@ -19,5 +19,5 @@ create table if not exists t_b_tool_main update_time datetime not null default (utc_timestamp()) comment '修改时间', deleted bigint not null default 0, version int not null default 0, - constraint t_b_tool_main_unique_tool_id unique (tool_id, author_id, deleted) + constraint t_b_tool_main_unique_tool_id unique (tool_id, author_id, ver, deleted) ) comment '工具-主表'; \ No newline at end of file From a66c5caa600b40bf357402779997483c8c0e3ab5 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Jan 2024 14:54:40 +0800 Subject: [PATCH 183/258] Add create tool api --- .../api/controller/tool/EditController.kt | 96 +++++++----- .../controller/tool/ManagementController.kt | 61 +++----- .../api/converter/tool/ToolBaseConverter.kt | 6 +- .../api/converter/tool/ToolConverter.kt | 5 +- .../converter/tool/ToolTemplateConverter.kt | 57 ++++++- .../top/fatweb/oxygen/api/entity/tool/Tool.kt | 37 ++++- .../fatweb/oxygen/api/entity/tool/ToolBase.kt | 20 +-- .../oxygen/api/entity/tool/ToolTemplate.kt | 11 +- .../oxygen/api/mapper/tool/EditMapper.kt | 22 +++ .../oxygen/api/mapper/tool/ToolMapper.kt | 7 +- .../oxygen/api/param/tool/ToolAddParam.kt | 44 ------ .../oxygen/api/param/tool/ToolBaseAddParam.kt | 11 +- .../api/param/tool/ToolBaseUpdateParam.kt | 11 +- .../oxygen/api/param/tool/ToolCreateParam.kt | 99 ++++++++++++ .../api/param/tool/ToolTemplateAddParam.kt | 10 ++ .../api/param/tool/ToolTemplateUpdateParam.kt | 9 ++ .../oxygen/api/param/tool/ToolUpdateParam.kt | 84 ++++++++++ .../oxygen/api/service/tool/IEditService.kt | 74 +++++++++ .../oxygen/api/service/tool/IToolService.kt | 15 +- .../api/service/tool/impl/EditServiceImpl.kt | 92 +++++++++++ .../service/tool/impl/ToolBaseServiceImpl.kt | 5 +- .../api/service/tool/impl/ToolServiceImpl.kt | 138 ++++++----------- .../tool/impl/ToolTemplateServiceImpl.kt | 2 + .../fatweb/oxygen/api/vo/tool/ToolBaseVo.kt | 9 -- .../oxygen/api/vo/tool/ToolTemplateVo.kt | 9 ++ .../top/fatweb/oxygen/api/vo/tool/ToolVo.kt | 143 +++++++++++++++++- ..._0_0_240115__Add_table_'t_b_tool_main'.sql | 1 + ..._240119__Add_table_'t_b_tool_template'.sql | 1 + ..._0_0_240120__Add_table_'t_b_tool_base'.sql | 1 - src/main/resources/mapper/tool/EditMapper.xml | 142 +++++++++++++++++ .../resources/mapper/tool/ToolBaseMapper.xml | 2 - .../mapper/tool/ToolCategoryMapper.xml | 13 ++ .../mapper/tool/ToolTemplateMapper.xml | 10 +- 33 files changed, 945 insertions(+), 302 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt create mode 100644 src/main/resources/mapper/tool/EditMapper.xml create mode 100644 src/main/resources/mapper/tool/ToolCategoryMapper.xml diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index e69c0c0..1e735e6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -2,54 +2,80 @@ package top.fatweb.oxygen.api.controller.tool import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult -import top.fatweb.oxygen.api.param.tool.ToolAddParam -import top.fatweb.oxygen.api.param.tool.ToolUpdateParam -import top.fatweb.oxygen.api.service.tool.IToolService +import top.fatweb.oxygen.api.param.tool.ToolCreateParam +import top.fatweb.oxygen.api.service.tool.IEditService +import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo +import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo /** - * Tool management controller + * Tool edit controller * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@BaseController(path = ["/tool"], name = "工具管理", description = "工具管理相关接口") +@BaseController(path = ["/tool"], name = "工具编辑", description = "工具编辑相关接口") class EditController( - private val toolService: IToolService + private val editService: IEditService ) { - @Operation(summary = "获取单个工具") - @GetMapping("/{id}") - fun getOne(@PathVariable id: Long): ResponseResult = - ResponseResult.databaseSuccess(data = toolService.getOne(id)) + /** + * Get tool template list + * + * @return Response object includes tool template list + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolTemplateVo + */ + @Operation(summary = "获取模板") + @GetMapping("/template") + fun getTemplate(): ResponseResult> = + ResponseResult.databaseSuccess(data = editService.getTemplate()) - @Operation(summary = "获取工具") - @GetMapping - fun get(): ResponseResult> = - ResponseResult.databaseSuccess(data = toolService.get()) + /** + * Get tool template by ID + * + * @param id ID + * @return Response object includes tool template information + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolTemplateVo + */ + @Operation(summary = "获取单个模板") + @GetMapping("/template/{id}") + fun getTemplate(@PathVariable id: Long): ResponseResult = + ResponseResult.databaseSuccess(data = editService.getTemplate(id)) - @Operation(summary = "新增工具") + /** + * Get tool category list + * + * @return Response object includes tool category list + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ResponseResult + * @see ToolCategoryVo + */ + @Operation(summary = "获取类别") + @GetMapping("/category") + fun getCategory(): ResponseResult> = + ResponseResult.databaseSuccess(data = editService.getCategory()) + + /** + * Create tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "创建工具") @PostMapping - fun add(@RequestBody @Valid toolAddParam: ToolAddParam): ResponseResult = - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_INSERT_SUCCESS, - data = toolService.add(toolAddParam) - ) - - @Operation(summary = "更新工具") - @PutMapping - fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult = - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_UPDATE_SUCCESS, - data = toolService.update(toolUpdateParam) - ) - - @Operation(summary = "删除工具") - @DeleteMapping("/{id}") - fun delete(@PathVariable id: Long): ResponseResult = - if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) + fun create(@RequestBody @Valid toolCreateParam: ToolCreateParam): ResponseResult = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_INSERT_SUCCESS, data = editService.create(toolCreateParam)) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt index 9e09628..e062586 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt @@ -1,49 +1,30 @@ package top.fatweb.oxygen.api.controller.tool -import io.swagger.v3.oas.annotations.Operation -import jakarta.validation.Valid -import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController -import top.fatweb.oxygen.api.entity.common.ResponseCode -import top.fatweb.oxygen.api.entity.common.ResponseResult -import top.fatweb.oxygen.api.param.tool.ToolAddParam -import top.fatweb.oxygen.api.param.tool.ToolUpdateParam -import top.fatweb.oxygen.api.service.tool.IToolService -import top.fatweb.oxygen.api.vo.tool.ToolVo @BaseController(path = ["/system/tool"], name = "工具管理", description = "工具管理相关接口") -class ManagementController( - private val toolService: IToolService -) { - @Operation(summary = "获取单个工具") - @GetMapping("/{id}") - fun getOne(@PathVariable id: Long): ResponseResult = - ResponseResult.databaseSuccess(data = toolService.getOne(id)) +class ManagementController { + /* @Operation(summary = "获取单个工具") + @GetMapping("/{id}") + fun getOne(@PathVariable id: Long): ResponseResult = + ResponseResult.databaseSuccess(data = toolService.getOne(id)) - @Operation(summary = "获取工具") - @GetMapping - fun get(): ResponseResult> = - ResponseResult.databaseSuccess(data = toolService.get()) + @Operation(summary = "获取工具") + @GetMapping + fun get(): ResponseResult> = + ResponseResult.databaseSuccess(data = toolService.get()) - @Operation(summary = "新增工具") - @PostMapping - fun add(@RequestBody @Valid toolAddParam: ToolAddParam): ResponseResult = - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_INSERT_SUCCESS, - data = toolService.add(toolAddParam) - ) + @Operation(summary = "更新工具") + @PutMapping + fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, + data = toolService.update(toolUpdateParam) + ) - @Operation(summary = "更新工具") - @PutMapping - fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult = - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_UPDATE_SUCCESS, - data = toolService.update(toolUpdateParam) - ) - - @Operation(summary = "删除工具") - @DeleteMapping("/{id}") - fun delete(@PathVariable id: Long): ResponseResult = - if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) + @Operation(summary = "删除工具") + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseResult = + if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)*/ } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt index 03cada4..1877c39 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt @@ -28,8 +28,7 @@ object ToolBaseConverter { dist = toolBase.dist?.let(ToolDataConverter::toolDataToToolDataVo), compiled = toolBase.compiled == 1, createTime = toolBase.createTime, - updateTime = toolBase.updateTime, - enable = toolBase.enable == 1 + updateTime = toolBase.updateTime ) /** @@ -49,7 +48,6 @@ object ToolBaseConverter { dist = ToolDataVo(id = toolBase.distId, data = null, createTime = null, updateTime = null), compiled = toolBase.compiled == 1, createTime = toolBase.createTime, - updateTime = toolBase.updateTime, - enable = toolBase.enable == 1 + updateTime = toolBase.updateTime ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt index d490e11..83f2069 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt @@ -1,6 +1,6 @@ package top.fatweb.oxygen.api.converter.tool -import top.fatweb.oxygen.api.converter.permission.UserInfoConverter +import top.fatweb.oxygen.api.converter.permission.UserConverter import top.fatweb.oxygen.api.entity.tool.Tool import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -27,13 +27,14 @@ object ToolConverter { toolId = tool.toolId, description = tool.description, baseId = tool.baseId, - author = tool.author?.let(UserInfoConverter::userInfoToUserInfoVo), + author = tool.author?.let(UserConverter::userToUserWithInfoVo), ver = tool.ver, privately = tool.privately == 1, keywords = tool.keywords, categories = tool.categories?.map(ToolCategoryConverter::toolCategoryToToolCategoryVo), source = tool.source?.let(ToolDataConverter::toolDataToToolDataVo), dist = tool.dist?.let(ToolDataConverter::toolDataToToolDataVo), + entryPoint = tool.entryPoint, publish = tool.publish == 1, review = tool.review, createTime = tool.createTime, diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt index 37c93fa..e3243ce 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt @@ -1,6 +1,8 @@ package top.fatweb.oxygen.api.converter.tool import top.fatweb.oxygen.api.entity.tool.ToolTemplate +import top.fatweb.oxygen.api.vo.tool.ToolBaseVo +import top.fatweb.oxygen.api.vo.tool.ToolDataVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo /** @@ -25,8 +27,59 @@ object ToolTemplateConverter { name = toolTemplate.name, base = toolTemplate.base?.let(ToolBaseConverter::toolBaseToToolBaseVo), source = toolTemplate.source?.let(ToolDataConverter::toolDataToToolDataVo), + entryPoint = toolTemplate.entryPoint, + enable = toolTemplate.enable == 1, createTime = toolTemplate.createTime, - updateTime = toolTemplate.updateTime, - enable = toolTemplate.enable == 1 + updateTime = toolTemplate.updateTime + ) + + /** + * Convert ToolTemplate object into ToolTemplateVo object by list + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun toolTemplateToToolTemplateVoByList(toolTemplate: ToolTemplate) = ToolTemplateVo( + id = toolTemplate.id, + name = toolTemplate.name, + base = ToolBaseVo( + id = toolTemplate.baseId, + name = null, + source = null, + dist = null, + compiled = null, + createTime = null, + updateTime = null + ), + source = ToolDataVo(id = toolTemplate.sourceId, data = null, createTime = null, updateTime = null), + entryPoint = toolTemplate.entryPoint, + enable = toolTemplate.enable == 1, + createTime = toolTemplate.createTime, + updateTime = toolTemplate.updateTime + ) + + /** + * Convert ToolTemplate object into ToolTemplateVo object with base dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun toolTemplateToToolTemplateVoWithBaseDist(toolTemplate: ToolTemplate) = ToolTemplateVo( + id = toolTemplate.id, + name = toolTemplate.name, + base = ToolBaseVo( + id = toolTemplate.baseId, + name = toolTemplate.base?.name, + source = null, + dist = ToolDataVo(id = null, data = toolTemplate.base?.distData, createTime = null, updateTime = null), + compiled = null, + createTime = null, + updateTime = null + ), + source = toolTemplate.source?.let(ToolDataConverter::toolDataToToolDataVo), + entryPoint = toolTemplate.entryPoint, + enable = toolTemplate.enable == 1, + createTime = toolTemplate.createTime, + updateTime = toolTemplate.updateTime ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt index 36aa2a6..9c04a29 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt @@ -2,7 +2,8 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler -import top.fatweb.oxygen.api.entity.permission.UserInfo +import com.fasterxml.jackson.annotation.JsonValue +import top.fatweb.oxygen.api.entity.permission.User import java.time.LocalDateTime /** @@ -13,6 +14,16 @@ import java.time.LocalDateTime */ @TableName("t_b_tool_main", autoResultMap = true) class Tool { + /** + * Tool review type enum + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + enum class ReviewType(@field:EnumValue @field:JsonValue val code: String) { + NONE("NONE"), PASS("PASS"), REJECT("REJECT") + } + /** * ID * @@ -112,6 +123,15 @@ class Tool { @TableField("dist_id") var distId: Long? = null + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("entry_point") + var entryPoint: String? = null + /** * Publish * @@ -128,7 +148,7 @@ class Tool { * @since 1.0.0 */ @TableField("review") - var review: Int? = null + var review: ReviewType? = null /** * Create time @@ -177,7 +197,16 @@ class Tool { * @since 1.0.0 */ @TableField(exist = false) - var author: UserInfo? = null + var author: User? = null + + /** + * Base + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var base: ToolBase? = null /** * Categories @@ -207,6 +236,6 @@ class Tool { var dist: ToolData? = null override fun toString(): String { - return "Tool(id=$id, name=$name, toolId=$toolId, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, privately=$privately, keywords=$keywords, sourceId=$sourceId, distId=$distId, publish=$publish, review=$review, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, author=$author, categories=$categories, source=$source, dist=$dist)" + return "Tool(id=$id, name=$name, toolId=$toolId, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, privately=$privately, keywords=$keywords, sourceId=$sourceId, distId=$distId, entryPoint=$entryPoint, publish=$publish, review=$review, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, author=$author, categories=$categories, source=$source, dist=$dist)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt index 10a591b..9878b57 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt @@ -56,15 +56,6 @@ class ToolBase { @TableField("compiled") var compiled: Int? = null - /** - * Enable - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @TableField("enable") - var enable: Int? = null - /** * Create time * @@ -123,7 +114,16 @@ class ToolBase { @TableField(exist = false) var dist: ToolData? = null + /** + * Dist data + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var distData: String? = null + override fun toString(): String { - return "ToolBase(id=$id, name=$name, sourceId=$sourceId, distId=$distId, compiled=$compiled, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, dist=$dist)" + return "ToolBase(id=$id, name=$name, sourceId=$sourceId, distId=$distId, compiled=$compiled, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, dist=$dist, distData=$distData)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt index 1fcbdd4..124995b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt @@ -47,6 +47,15 @@ class ToolTemplate { @TableField("source_id") var sourceId: Long? = null + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("entry_point") + var entryPoint: String? = null + /** * Enable * @@ -115,6 +124,6 @@ class ToolTemplate { var base: ToolBase? = null override fun toString(): String { - return "ToolTemplate(id=$id, name=$name, baseId=$baseId, sourceId=$sourceId, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, base=$base)" + return "ToolTemplate(id=$id, name=$name, baseId=$baseId, sourceId=$sourceId, entryPoint=$entryPoint, enable=$enable, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, source=$source, base=$base)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt new file mode 100644 index 0000000..56f0802 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt @@ -0,0 +1,22 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import org.apache.ibatis.annotations.Param +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.entity.tool.ToolTemplate + +/** + * Tool edit mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see Tool + */ +@Mapper +interface EditMapper : BaseMapper { + fun getTemplate(@Param("id") id: Long): ToolTemplate? + + fun selectOne(@Param("id") id: Long, @Param("userId") userId: Long): Tool? +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt index ac7caed..77dd30a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt @@ -2,7 +2,6 @@ package top.fatweb.oxygen.api.mapper.tool import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper -import org.apache.ibatis.annotations.Param import top.fatweb.oxygen.api.entity.tool.Tool /** @@ -14,8 +13,4 @@ import top.fatweb.oxygen.api.entity.tool.Tool * @see Tool */ @Mapper -interface ToolMapper : BaseMapper { - fun selectOne(@Param("id") id: Long): Tool? - - fun selectList(): List -} \ No newline at end of file +interface ToolMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt deleted file mode 100644 index 0cbfcb8..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolAddParam.kt +++ /dev/null @@ -1,44 +0,0 @@ -package top.fatweb.oxygen.api.param.tool - -import jakarta.validation.constraints.NotBlank -import jakarta.validation.constraints.NotEmpty -import jakarta.validation.constraints.NotNull -import jakarta.validation.constraints.Pattern - -data class ToolAddParam( - @field: NotBlank(message = "Name can not be blank") - val name: String?, - - @field: NotBlank(message = "ToolId can not be blank") - @field: Pattern( - regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", - message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" - ) - val toolId: String?, - - val description: String?, - - @field: NotNull(message = "BaseId can not be null") - val baseId: Long?, - - @field: NotNull(message = "AuthorId can not be null") - val authorId: Long?, - - @field: NotBlank(message = "Ver can not be blank") - @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") - val ver: String?, - - val privately: Boolean = false, - - @field: NotEmpty(message = "Keywords can not be empty") - val keywords: List, - - @field: NotEmpty(message = "Categories can not be empty") - val categories: List, - - @field: NotNull(message = "Source can not be null") - val source: String?, - - @field:NotNull(message = "Dist can not be null") - val dist: String? -) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt index 773aa51..582925b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt @@ -18,14 +18,5 @@ data class ToolBaseAddParam( */ @Schema(description = "名称", required = true) @field: NotBlank(message = "Name can not be blank") - val name: String?, - - /** - * Enable - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "启用", allowableValues = ["true", "false"], defaultValue = "true") - val enable: Boolean = true + val name: String? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt index 83f4cc3..d4da30e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt @@ -45,14 +45,5 @@ data class ToolBaseUpdateParam( * @since 1.0.0 */ @Schema(description = "产物") - val dist: String?, - - /** - * Enable - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "启用", allowableValues = ["true", "false"]) - val enable: Boolean? + val dist: String? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt new file mode 100644 index 0000000..01d1159 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt @@ -0,0 +1,99 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotEmpty +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern + +/** + * Create tool parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(description = "创建工具请求参数") +data class ToolCreateParam( + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称", required = true) + @field: NotBlank(message = "Name can not be blank") + val name: String?, + + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "工具唯一 ID", required = true, example = "tool_a") + @field: NotBlank(message = "ToolId can not be blank") + @field: Pattern( + regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", + message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" + ) + val toolId: String?, + + /** + * Description + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "简介") + val description: String?, + + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "版本", required = true, example = "1.0.3") + @field: NotBlank(message = "Ver can not be blank") + @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") + val ver: String?, + + /** + * Template ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "模板 ID", required = true) + @field: NotNull(message = "TemplateId can not be null") + val templateId: Long?, + + /** + * Privately + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "私有", allowableValues = ["true", "false"], defaultValue = "false") + val privately: Boolean = false, + + /** + * Keywords + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "关键词", required = true) + @field: NotEmpty(message = "Keywords can not be empty") + val keywords: List, + + /** + * Categories + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "类别", required = true) + @field: NotEmpty(message = "Categories can not be empty") + val categories: List +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt index 44fa42d..137c554 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateAddParam.kt @@ -31,6 +31,16 @@ data class ToolTemplateAddParam( @field: NotNull(message = "BaseId can not be null") val baseId: Long? = null, + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "入口文件", required = true) + @field:NotBlank(message = "EntryPoint can not be null") + val entryPoint: String? = null, + /** * Enable * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt index a06672b..523f74d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt @@ -47,6 +47,15 @@ data class ToolTemplateUpdateParam( @Schema(description = "源码") val source: String?, + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "入口文件") + val entryPoint: String?, + /** * Enable * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt index 94d1d0d..f341be8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt @@ -1,34 +1,118 @@ package top.fatweb.oxygen.api.param.tool +import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull import jakarta.validation.constraints.Pattern +/** + * Update tool parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ data class ToolUpdateParam( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "ID", required = true) @field: NotNull(message = "ID can not be null") val id: Long?, + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称") val name: String?, + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "工具唯一 ID", example = "tool_a") @field: Pattern( regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" ) val toolId: String?, + /** + * Description + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "简介") val description: String?, + /** + * Author ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "作者 ID") val authorId: Long?, + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "版本", example = "1.0.3") @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") val ver: String?, + /** + * Privately + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "私有", allowableValues = ["true", "false"]) val privately: Boolean?, + /** + * Keywords + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "关键词") val keywords: List, + /** + * Categories + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "类别") val categories: List, + /** + * Source + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "源码") val source: String?, + /** + * Dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "产物") val dist: String? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt new file mode 100644 index 0000000..819fc66 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt @@ -0,0 +1,74 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.param.tool.ToolCreateParam +import top.fatweb.oxygen.api.param.tool.ToolUpdateParam +import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo +import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool edit service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see Tool + */ +interface IEditService : IService { + /** + * Get tool template as list + * + * @return List of ToolTemplateVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplateVo + */ + fun getTemplate(): List + + /** + * Get tool template by ID + * + * @param id ID + * @return ToolTemplateVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplateVo + */ + fun getTemplate(id: Long): ToolTemplateVo + + /** + * Get tool category as list + * + * @return List of ToolCategoryVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryVo + */ + fun getCategory(): List + + /** + * Get tool by ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun getOne(id: Long): ToolVo + + /** + * Create tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun create(toolCreateParam: ToolCreateParam): ToolVo + + /** + * Update tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun update(toolUpdateParam: ToolUpdateParam): ToolVo +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt index 69ef68c..c0df740 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt @@ -2,9 +2,6 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.Tool -import top.fatweb.oxygen.api.param.tool.ToolAddParam -import top.fatweb.oxygen.api.param.tool.ToolUpdateParam -import top.fatweb.oxygen.api.vo.tool.ToolVo /** * Tool service interface @@ -14,14 +11,4 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo * @see IService * @see Tool */ -interface IToolService : IService { - fun getOne(id: Long): ToolVo - - fun get(): List - - fun add(toolAddParam: ToolAddParam): ToolVo - - fun update(toolUpdateParam: ToolUpdateParam): ToolVo - - fun delete(id: Long): Boolean -} \ No newline at end of file +interface IToolService : IService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt new file mode 100644 index 0000000..6bfc39a --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -0,0 +1,92 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import top.fatweb.oxygen.api.converter.tool.ToolCategoryConverter +import top.fatweb.oxygen.api.converter.tool.ToolConverter +import top.fatweb.oxygen.api.converter.tool.ToolTemplateConverter +import top.fatweb.oxygen.api.entity.tool.* +import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.exception.UserNotFoundException +import top.fatweb.oxygen.api.mapper.tool.EditMapper +import top.fatweb.oxygen.api.param.tool.ToolCreateParam +import top.fatweb.oxygen.api.param.tool.ToolUpdateParam +import top.fatweb.oxygen.api.service.tool.* +import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo +import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool edit service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see EditMapper + * @see Tool + * @see IEditService + */ +@Service +class EditServiceImpl( + private val toolTemplateService: IToolTemplateService, + private val toolCategoryService: IToolCategoryService, + private val toolDataService: IToolDataService, + private val rToolCategoryService: IRToolCategoryService +) : ServiceImpl(), IEditService { + override fun getTemplate(): List = + toolTemplateService.list(KtQueryWrapper(ToolTemplate()).eq(ToolTemplate::enable, 1)) + .map(ToolTemplateConverter::toolTemplateToToolTemplateVoByList) + + override fun getTemplate(id: Long): ToolTemplateVo = + baseMapper.getTemplate(id)?.let(ToolTemplateConverter::toolTemplateToToolTemplateVoWithBaseDist) + ?: throw NoRecordFoundException() + + override fun getCategory(): List = + toolCategoryService.list(KtQueryWrapper(ToolCategory()).eq(ToolCategory::enable, 1)) + .map(ToolCategoryConverter::toolCategoryToToolCategoryVo) + + override fun getOne(id: Long): ToolVo = + baseMapper.selectOne(id, WebUtil.getLoginUserId() ?: throw UserNotFoundException()) + ?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() + + @Transactional + override fun create(toolCreateParam: ToolCreateParam): ToolVo { + val template = this.getTemplate(toolCreateParam.templateId!!) + val newSource = ToolData().apply { data = template.source!!.data } + val newDist = ToolData().apply { data = "" } + toolDataService.saveBatch(listOf(newSource, newDist)) + + val tool = Tool().apply { + name = toolCreateParam.name!!.trim() + toolId = toolCreateParam.toolId + description = toolCreateParam.description + baseId = template.base!!.id + authorId = WebUtil.getLoginUserId() ?: throw UserNotFoundException() + ver = toolCreateParam.ver!!.split(".").map(String::toLong).joinToString(".") + privately = if (toolCreateParam.privately) 1 else 0 + keywords = toolCreateParam.keywords + sourceId = newSource.id + distId = newDist.id + } + + this.save(tool) + + toolCreateParam.categories.forEach { + toolCategoryService.getById(it) ?: throw NoRecordFoundException() + rToolCategoryService.save(RToolCategory().apply { + toolId = tool.id + categoryId = it + }) + } + + return this.getOne(tool.id!!) + } + + @Transactional + override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt index 278dda4..e1070f9 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -38,8 +38,7 @@ class ToolBaseServiceImpl( val newSource = ToolData().apply { data = "" } val newDist = ToolData().apply { data = "" } - toolDataService.save(newSource) - toolDataService.save(newDist) + toolDataService.saveBatch(listOf(newSource, newDist)) val toolBase = ToolBase().apply { name = toolBaseAddParam.name @@ -47,7 +46,6 @@ class ToolBaseServiceImpl( distId = newDist.id source = newSource dist = newDist - enable = if (toolBaseAddParam.enable) 1 else 0 } this.save(toolBase) @@ -81,7 +79,6 @@ class ToolBaseServiceImpl( id = toolBaseUpdateParam.id name = toolBaseUpdateParam.name compiled = hasCompiled - enable = toolBaseUpdateParam.enable?.let { if (it) 1 else 0 } }) return this.getOne(toolBase.id!!) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt index ca982af..1f77089 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt @@ -1,21 +1,10 @@ package top.fatweb.oxygen.api.service.tool.impl -import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional -import top.fatweb.oxygen.api.converter.tool.ToolConverter -import top.fatweb.oxygen.api.entity.tool.RToolCategory import top.fatweb.oxygen.api.entity.tool.Tool -import top.fatweb.oxygen.api.entity.tool.ToolData -import top.fatweb.oxygen.api.exception.NoRecordFoundException -import top.fatweb.oxygen.api.exception.ToolHasPublish import top.fatweb.oxygen.api.mapper.tool.ToolMapper -import top.fatweb.oxygen.api.param.tool.ToolAddParam -import top.fatweb.oxygen.api.param.tool.ToolUpdateParam -import top.fatweb.oxygen.api.service.permission.IUserService -import top.fatweb.oxygen.api.service.tool.* -import top.fatweb.oxygen.api.vo.tool.ToolVo +import top.fatweb.oxygen.api.service.tool.IToolService /** * Tool service implement @@ -28,95 +17,54 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo * @see IToolService */ @Service -class ToolServiceImpl( - private val toolDataService: IToolDataService, - private val toolBaseService: IToolBaseService, - private val toolCategoryService: IToolCategoryService, - private val rToolCategoryService: IRToolCategoryService, - private val userService: IUserService -) : ServiceImpl(), IToolService { - override fun getOne(id: Long): ToolVo = - baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() +class ToolServiceImpl : ServiceImpl(), IToolService { + /* + override fun getOne(id: Long): ToolVo = + baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() - override fun get(): List = baseMapper.selectList().map(ToolConverter::toolToToolVo) + override fun get(): List = baseMapper.selectList().map(ToolConverter::toolToToolVo) - @Transactional - override fun add(toolAddParam: ToolAddParam): ToolVo { - toolBaseService.getOne(toolAddParam.baseId!!) - userService.getOne(toolAddParam.authorId!!) + @Transactional + override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { + val tool = baseMapper.selectOne(toolUpdateParam.id!!) ?: throw NoRecordFoundException() + if (tool.publish == 1) { + throw ToolHasPublish() + } + userService.getOne(toolUpdateParam.authorId!!) - val newSource = ToolData().apply { data = toolAddParam.source } - val newDist = ToolData().apply { data = toolAddParam.dist } - - toolDataService.save(newSource) - toolDataService.save(newDist) - - val tool = Tool().apply { - name = toolAddParam.name - toolId = toolAddParam.toolId - description = toolAddParam.description - baseId = toolAddParam.baseId - authorId = toolAddParam.authorId - ver = toolAddParam.ver - privately = if (toolAddParam.privately) 1 else 0 - keywords = toolAddParam.keywords - sourceId = newSource.id - distId = newDist.id - } - - this.save(tool) - - toolAddParam.categories.forEach { - toolCategoryService.getById(it) ?: throw NoRecordFoundException() - rToolCategoryService.save(RToolCategory().apply { - toolId = tool.id - categoryId = it + toolDataService.updateById(ToolData().apply { + id = tool.sourceId + data = toolUpdateParam.source }) + + toolDataService.updateById(ToolData().apply { + id = tool.distId + data = toolUpdateParam.dist + }) + + this.updateById(Tool().apply { + id = toolUpdateParam.id + name = toolUpdateParam.name + toolId = toolUpdateParam.toolId + description = toolUpdateParam.description + authorId = toolUpdateParam.authorId + ver = toolUpdateParam.ver + privately = toolUpdateParam.privately?.let { if (it) 1 else 0 } + keywords = toolUpdateParam.keywords + }) + + // TODO Category process + + return this.getOne(tool.id!!) } - return this.getOne(tool.id!!) - } + @Transactional + override fun delete(id: Long): Boolean { + val tool = this.getById(id) - @Transactional - override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { - val tool = baseMapper.selectOne(toolUpdateParam.id!!) ?: throw NoRecordFoundException() - if (tool.publish == 1) { - throw ToolHasPublish() + return toolDataService.removeBatchByIds(listOf(tool.sourceId, tool.distId)) + && rToolCategoryService.remove(KtQueryWrapper(RToolCategory()).eq(RToolCategory::toolId, tool.id)) + && this.removeById(tool.id) } - userService.getOne(toolUpdateParam.authorId!!) - - toolDataService.updateById(ToolData().apply { - id = tool.sourceId - data = toolUpdateParam.source - }) - - toolDataService.updateById(ToolData().apply { - id = tool.distId - data = toolUpdateParam.dist - }) - - this.updateById(Tool().apply { - id = toolUpdateParam.id - name = toolUpdateParam.name - toolId = toolUpdateParam.toolId - description = toolUpdateParam.description - authorId = toolUpdateParam.authorId - ver = toolUpdateParam.ver - privately = toolUpdateParam.privately?.let { if (it) 1 else 0 } - keywords = toolUpdateParam.keywords - }) - - // TODO Category process - - return this.getOne(tool.id!!) - } - - @Transactional - override fun delete(id: Long): Boolean { - val tool = this.getById(id) - - return toolDataService.removeBatchByIds(listOf(tool.sourceId, tool.distId)) - && rToolCategoryService.remove(KtQueryWrapper(RToolCategory()).eq(RToolCategory::toolId, tool.id)) - && this.removeById(tool.id) - } + */ } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt index 47706bf..ab9e16a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolTemplateServiceImpl.kt @@ -50,6 +50,7 @@ class ToolTemplateServiceImpl( baseId = toolTemplateAddParam.baseId sourceId = newSource.id source = newSource + entryPoint = toolTemplateAddParam.entryPoint enable = if (toolTemplateAddParam.enable) 1 else 0 } @@ -72,6 +73,7 @@ class ToolTemplateServiceImpl( id = toolTemplateUpdateParam.id name = toolTemplateUpdateParam.name baseId = toolTemplateUpdateParam.baseId + entryPoint = toolTemplateUpdateParam.entryPoint enable = toolTemplateUpdateParam.enable?.let { if (it) 1 else 0 } }) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt index 954dcb0..0704766 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt @@ -58,15 +58,6 @@ data class ToolBaseVo( @Schema(description = "已编译") val compiled: Boolean?, - /** - * Enable - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "启用") - val enable: Boolean?, - /** * Create time * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt index 90b71d5..fea3b1f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt @@ -49,6 +49,15 @@ data class ToolTemplateVo( @Schema(description = "源码") val source: ToolDataVo?, + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "入口文件") + val entryPoint: String?, + /** * Enable * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt index 3b7fe20..fe30113 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt @@ -2,41 +2,176 @@ package top.fatweb.oxygen.api.vo.tool import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer -import top.fatweb.oxygen.api.vo.permission.base.UserInfoVo +import io.swagger.v3.oas.annotations.media.Schema +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.vo.permission.UserWithInfoVo import java.time.LocalDateTime -data class ToolVo ( +/** + * Tool value object + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class ToolVo( + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @JsonSerialize(using = ToStringSerializer::class) val id: Long?, + /** + * Name + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "名称") val name: String?, + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "工具 ID") val toolId: String?, + /** + * Description + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "简介") val description: String?, + /** + * Base ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @JsonSerialize(using = ToStringSerializer::class) + @Schema(description = "基板 ID") val baseId: Long?, - val author: UserInfoVo?, + /** + * Author + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see UserWithInfoVo + */ + @Schema(description = "作者") + val author: UserWithInfoVo?, + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "版本") val ver: String?, + /** + * Privately + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "私有") val privately: Boolean?, + /** + * Keywords + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "关键字") val keywords: List?, + /** + * Categories + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolCategoryVo + */ + @Schema(description = "类别") val categories: List?, + /** + * Source + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolDataVo + */ + @Schema(description = "源码") val source: ToolDataVo?, + /** + * Dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolDataVo + */ + @Schema(description = "产物") val dist: ToolDataVo?, + /** + * Entry point + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "入口文件") + val entryPoint: String?, + + /** + * Publish + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "发布") val publish: Boolean?, - val review: Int?, + /** + * Review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tool.ReviewType + */ + @Schema(description = "审核") + val review: Tool.ReviewType?, + /** + * Create time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "创建时间", example = "1900-01-01T00:00:00.000Z") val createTime: LocalDateTime?, + /** + * Update time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z") val updateTime: LocalDateTime? ) \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql index 45b96e6..9b24ce1 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql @@ -13,6 +13,7 @@ create table if not exists t_b_tool_main keywords varchar(500) not null comment '关键字', source_id bigint not null comment '源码 ID', dist_id bigint not null comment '产物 ID', + entry_point varchar(64) not null default 'main.tsx' comment '入口文件', publish int not null default 0 comment '发布', review varchar(10) not null default 'NONE' comment '审核', create_time datetime not null default (utc_timestamp()) comment '创建时间', diff --git a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql index 8a91504..0d442a9 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql @@ -6,6 +6,7 @@ create table if not exists t_b_tool_template name varchar(40) not null comment '模板名', base_id bigint not null comment '基板 ID', source_id bigint not null comment '源码 ID', + entry_point varchar(64) not null default 'main.tsx' comment '入口文件', enable int not null default 1 comment '启用', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', diff --git a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql index deee8b0..9225778 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql @@ -7,7 +7,6 @@ create table if not exists t_b_tool_base source_id bigint not null comment '源码 ID', dist_id bigint not null comment '产物 ID', compiled int not null default 0 comment '已编译', - enable int not null default 1 comment '启用', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', deleted bigint not null default 0, diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml new file mode 100644 index 0000000..f3dd370 --- /dev/null +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/tool/ToolBaseMapper.xml b/src/main/resources/mapper/tool/ToolBaseMapper.xml index 26fe0c3..2994493 100644 --- a/src/main/resources/mapper/tool/ToolBaseMapper.xml +++ b/src/main/resources/mapper/tool/ToolBaseMapper.xml @@ -7,7 +7,6 @@ t_b_tool_base.source_id as tool_base_source_id, t_b_tool_base.dist_id as tool_base_dist_id, t_b_tool_base.compiled as tool_base_compiled, - t_b_tool_base.enable as tool_base_enable, t_b_tool_base.create_time as tool_base_create_time, t_b_tool_base.update_time as tool_base_update_time, t_b_tool_base.deleted as tool_base_deleted, @@ -36,7 +35,6 @@ - diff --git a/src/main/resources/mapper/tool/ToolCategoryMapper.xml b/src/main/resources/mapper/tool/ToolCategoryMapper.xml new file mode 100644 index 0000000..5be8646 --- /dev/null +++ b/src/main/resources/mapper/tool/ToolCategoryMapper.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/tool/ToolTemplateMapper.xml b/src/main/resources/mapper/tool/ToolTemplateMapper.xml index be3e29a..b25a8eb 100644 --- a/src/main/resources/mapper/tool/ToolTemplateMapper.xml +++ b/src/main/resources/mapper/tool/ToolTemplateMapper.xml @@ -6,6 +6,7 @@ t_b_tool_template.name as tool_template_name, t_b_tool_template.base_id as tool_template_base_id, t_b_tool_template.source_id as tool_template_source_id, + t_b_tool_template.entry_point as tool_template_entry_point, t_b_tool_template.enable as tool_template_enable, t_b_tool_template.create_time as tool_template_create_time, t_b_tool_template.update_time as tool_template_update_time, @@ -16,8 +17,7 @@ tbtds.update_time as tool_template_source_update_time, tbtds.deleted as tool_template_source_delete, tbtds.version as tool_template_source_version, - tbtb.name as tool_template_base_name, - tbtb.enable as tool_template_base_enable + tbtb.name as tool_template_base_name from t_b_tool_template left join (select * from t_b_tool_data where deleted = 0) as tbtds on tbtds.id = t_b_tool_template.source_id @@ -32,13 +32,13 @@ t_b_tool_template.name as tool_template_name, t_b_tool_template.base_id as tool_template_base_id, t_b_tool_template.source_id as tool_template_source_id, + t_b_tool_template.entry_point as tool_template_entry_point, t_b_tool_template.enable as tool_template_enable, t_b_tool_template.create_time as tool_template_create_time, t_b_tool_template.update_time as tool_template_update_time, t_b_tool_template.deleted as tool_template_deleted, t_b_tool_template.version as tool_template_version, - tbtb.name as tool_template_base_name, - tbtb.enable as tool_template_base_enable + tbtb.name as tool_template_base_name from t_b_tool_template left join (select * from t_b_tool_base where deleted = 0) as tbtb on tbtb.id = t_b_tool_template.base_id @@ -50,6 +50,7 @@ + @@ -58,7 +59,6 @@ - From 3dc935a98a2eaadb78827aadffa518a1d3ec00ca Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Jan 2024 17:31:26 +0800 Subject: [PATCH 184/258] Add icon and publish time to tool --- .../api/converter/tool/ToolConverter.kt | 2 + .../top/fatweb/oxygen/api/entity/tool/Tool.kt | 22 ++++- .../oxygen/api/param/tool/ToolCreateParam.kt | 10 ++ .../api/service/tool/impl/EditServiceImpl.kt | 1 + .../top/fatweb/oxygen/api/vo/tool/ToolVo.kt | 19 ++++ ..._0_0_240115__Add_table_'t_b_tool_main'.sql | 38 ++++---- src/main/resources/mapper/tool/EditMapper.xml | 92 ++++++++++--------- 7 files changed, 121 insertions(+), 63 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt index 83f2069..bed4354 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt @@ -25,6 +25,7 @@ object ToolConverter { id = tool.id, name = tool.name, toolId = tool.toolId, + icon = tool.icon, description = tool.description, baseId = tool.baseId, author = tool.author?.let(UserConverter::userToUserWithInfoVo), @@ -37,6 +38,7 @@ object ToolConverter { entryPoint = tool.entryPoint, publish = tool.publish == 1, review = tool.review, + publishTime = tool.publishTime, createTime = tool.createTime, updateTime = tool.updateTime ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt index 9c04a29..7c61490 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt @@ -51,6 +51,15 @@ class Tool { @TableField("tool_id") var toolId: String? = null + /** + * Icon + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("icon") + var icon: String? = null + /** * Description * @@ -146,10 +155,21 @@ class Tool { * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ReviewType */ @TableField("review") var review: ReviewType? = null + /** + * Publish time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @TableField("publish_time") + var publishTime: LocalDateTime? = null + /** * Create time * @@ -236,6 +256,6 @@ class Tool { var dist: ToolData? = null override fun toString(): String { - return "Tool(id=$id, name=$name, toolId=$toolId, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, privately=$privately, keywords=$keywords, sourceId=$sourceId, distId=$distId, entryPoint=$entryPoint, publish=$publish, review=$review, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, author=$author, categories=$categories, source=$source, dist=$dist)" + return "Tool(id=$id, name=$name, toolId=$toolId, icon=$icon, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, privately=$privately, keywords=$keywords, sourceId=$sourceId, distId=$distId, entryPoint=$entryPoint, publish=$publish, review=$review, publishTime=$publishTime, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, author=$author, base=$base, categories=$categories, source=$source, dist=$dist)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt index 01d1159..1955b93 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt @@ -38,6 +38,16 @@ data class ToolCreateParam( ) val toolId: String?, + /** + * Icon + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "图标", required = true) + @field: NotBlank(message = "Icon can not be blank") + val icon: String?, + /** * Description * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index 6bfc39a..434abf8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -62,6 +62,7 @@ class EditServiceImpl( val tool = Tool().apply { name = toolCreateParam.name!!.trim() toolId = toolCreateParam.toolId + icon = toolCreateParam.icon description = toolCreateParam.description baseId = template.base!!.id authorId = WebUtil.getLoginUserId() ?: throw UserNotFoundException() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt index fe30113..8569307 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt @@ -41,6 +41,15 @@ data class ToolVo( @Schema(description = "工具 ID") val toolId: String?, + /** + * Icon + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "图标") + val icon: String?, + /** * Description * @@ -155,6 +164,16 @@ data class ToolVo( @Schema(description = "审核") val review: Tool.ReviewType?, + /** + * Publish time + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see LocalDateTime + */ + @Schema(description = "发布时间", example = "1900-01-01T00:00:00.000Z") + val publishTime: LocalDateTime?, + /** * Create time * diff --git a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql index 9b24ce1..39ba7c4 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240115__Add_table_'t_b_tool_main'.sql @@ -2,23 +2,25 @@ drop table if exists t_b_tool_main; create table if not exists t_b_tool_main ( - id bigint not null primary key, - name varchar(50) not null comment '工具名', - tool_id varchar(50) not null comment '工具 ID', - description varchar(500) null comment '简介', - base_id bigint not null comment '基板 ID', - author_id bigint not null comment '作者 ID', - ver varchar(20) not null comment '版本', - privately int not null default 0 comment '私有', - keywords varchar(500) not null comment '关键字', - source_id bigint not null comment '源码 ID', - dist_id bigint not null comment '产物 ID', - entry_point varchar(64) not null default 'main.tsx' comment '入口文件', - publish int not null default 0 comment '发布', - review varchar(10) not null default 'NONE' comment '审核', - create_time datetime not null default (utc_timestamp()) comment '创建时间', - update_time datetime not null default (utc_timestamp()) comment '修改时间', - deleted bigint not null default 0, - version int not null default 0, + id bigint not null primary key, + name varchar(50) not null comment '工具名', + tool_id varchar(50) not null comment '工具 ID', + icon text not null comment '图标', + description varchar(500) null comment '简介', + base_id bigint not null comment '基板 ID', + author_id bigint not null comment '作者 ID', + ver varchar(20) not null comment '版本', + privately int not null default 0 comment '私有', + keywords varchar(500) not null comment '关键字', + source_id bigint not null comment '源码 ID', + dist_id bigint not null comment '产物 ID', + entry_point varchar(64) not null default 'main.tsx' comment '入口文件', + publish int not null default 0 comment '发布', + review varchar(10) not null default 'NONE' comment '审核', + publish_time datetime null comment '发布时间', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0, constraint t_b_tool_main_unique_tool_id unique (tool_id, author_id, ver, deleted) ) comment '工具-主表'; \ No newline at end of file diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml index f3dd370..f3f1c9f 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -31,50 +31,52 @@ - select t_b_tool_main.id as tool_id, t_b_tool_main.name as tool_name, t_b_tool_main.tool_id as tool_tool_id, @@ -39,14 +39,12 @@ t_b_tool_main.base_id as tool_base_id, t_b_tool_main.author_id as tool_author_id, t_b_tool_main.ver as tool_ver, - t_b_tool_main.privately as tool_privately, t_b_tool_main.keywords as tool_keywords, t_b_tool_main.source_id as tool_source_id, t_b_tool_main.dist_id as tool_dist_id, t_b_tool_main.entry_point as tool_entry_point, t_b_tool_main.publish as tool_publish, t_b_tool_main.review as tool_review, - t_b_tool_main.publish_time as tool_publish_time, t_b_tool_main.create_time as tool_create_time, t_b_tool_main.update_time as tool_update_time, t_b_tool_main.deleted as tool_deleted, @@ -94,6 +92,124 @@ and t_b_tool_main.id = #{id} + + + + @@ -111,18 +227,24 @@ - - + + + + + + + + @@ -140,7 +262,5 @@ - - \ No newline at end of file From 7aca58f1de385f1ab6924e09431b73bd49de6c67 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 30 Jan 2024 19:24:44 +0800 Subject: [PATCH 187/258] Add tool upgrade api --- .../api/controller/tool/EditController.kt | 29 +++++- .../oxygen/api/entity/common/BusinessCode.kt | 8 ++ .../oxygen/api/entity/common/ResponseCode.kt | 2 + .../api/exception/IllegalVersionException.kt | 3 + .../oxygen/api/handler/ExceptionHandler.kt | 6 ++ .../oxygen/api/param/tool/ToolUpgradeParam.kt | 39 ++++++++ .../impl/AuthenticationServiceImpl.kt | 4 +- .../oxygen/api/service/tool/IEditService.kt | 20 ++++ .../api/service/tool/impl/EditServiceImpl.kt | 74 +++++++++++++- src/main/resources/mapper/tool/EditMapper.xml | 99 ++++++++++--------- 10 files changed, 226 insertions(+), 58 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index af6335f..318fadd 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -2,14 +2,12 @@ package top.fatweb.oxygen.api.controller.tool import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult import top.fatweb.oxygen.api.param.tool.ToolCreateParam +import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam import top.fatweb.oxygen.api.service.tool.IEditService import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo @@ -79,6 +77,17 @@ class EditController( fun create(@RequestBody @Valid toolCreateParam: ToolCreateParam): ResponseResult = ResponseResult.databaseSuccess(ResponseCode.DATABASE_INSERT_SUCCESS, data = editService.create(toolCreateParam)) + /** + * Upgrade tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "更新工具") + @PatchMapping + fun upgrade(@RequestBody @Valid toolUpgradeParam: ToolUpgradeParam): ResponseResult = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = editService.upgrade(toolUpgradeParam)) + /** * Get personal tool * @@ -103,4 +112,16 @@ class EditController( ResponseCode.DATABASE_SELECT_SUCCESS, data = editService.detail(username, toolId, ver) ) + + /** + * Delete tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "删除工具") + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseResult = + if (editService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/BusinessCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/BusinessCode.kt index 5c3a4d2..5b1f363 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/BusinessCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/BusinessCode.kt @@ -31,6 +31,14 @@ enum class BusinessCode(val code: Int) { */ DATABASE(300), + /** + * Tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + TOOL(400), + /** * Avatar API * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index 047c15f..738f9ae 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -58,6 +58,8 @@ enum class ResponseCode(val code: Int) { DATABASE_DUPLICATE_KEY(BusinessCode.DATABASE, 51), DATABASE_NO_RECORD_FOUND(BusinessCode.DATABASE, 52), + TOOL_ILLEGAL_VERSION(BusinessCode.TOOL, 50), + API_AVATAR_SUCCESS(BusinessCode.API_AVATAR, 0), API_AVATAR_ERROR(BusinessCode.API_AVATAR, 50); diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt new file mode 100644 index 0000000..3ee96ae --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt @@ -0,0 +1,3 @@ +package top.fatweb.oxygen.api.exception + +class IllegalVersionException : RuntimeException("Illegal Version") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index 879627a..e558606 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -211,6 +211,12 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.DATABASE_EXECUTE_ERROR, e.localizedMessage, null) } + /* Tool */ + is IllegalVersionException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.TOOL_ILLEGAL_VERSION, e.localizedMessage, null) + } + /* Other */ is MatchSensitiveWordException -> { logger.debug(e.localizedMessage, e) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt new file mode 100644 index 0000000..eb140f2 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt @@ -0,0 +1,39 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.Pattern + +/** + * Upgrade tool parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@Schema(description = "更新工具请求参数") +data class ToolUpgradeParam( + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "工具唯一 ID", required = true, example = "tool_a") + @field: NotBlank(message = "ToolId can not be blank") + @field: Pattern( + regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", + message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" + ) + val toolId: String?, + + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "版本", required = true, example = "1.0.3") + @field: NotBlank(message = "Ver can not be blank") + @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") + val ver: String? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt index 45c7a58..f9e4982 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -99,7 +99,7 @@ class AuthenticationServiceImpl( @Transactional override fun resend() { - val user = userService.getById(WebUtil.getLoginUserId()) ?: throw AccessDeniedException("Access Denied") + val user = userService.getById(WebUtil.getLoginUserId()) user.verify ?: throw NoVerificationRequiredException() @@ -124,7 +124,7 @@ class AuthenticationServiceImpl( @EventLogRecord(EventLog.Event.VERIFY) @Transactional override fun verify(verifyParam: VerifyParam) { - val user = userService.getById(WebUtil.getLoginUserId()) ?: throw AccessDeniedException("Access Denied") + val user = userService.getById(WebUtil.getLoginUserId()) user.verify ?: throw NoVerificationRequiredException() if (LocalDateTime.ofInstant(Instant.ofEpochMilli(user.verify!!.split("-").first().toLong()), ZoneOffset.UTC) .isBefore(LocalDateTime.now(ZoneOffset.UTC).minusHours(2)) || user.verify != verifyParam.code diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt index b8717ea..7f8e197 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.Tool import top.fatweb.oxygen.api.param.tool.ToolCreateParam import top.fatweb.oxygen.api.param.tool.ToolUpdateParam +import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -51,6 +52,7 @@ interface IEditService : IService { /** * Get tool by ID * + * @param * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ @@ -64,6 +66,16 @@ interface IEditService : IService { */ fun create(toolCreateParam: ToolCreateParam): ToolVo + /** + * Upgrade tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolUpgradeParam + * @see ToolVo + */ + fun upgrade(toolUpgradeParam: ToolUpgradeParam): ToolVo + /** * Update tool * @@ -87,4 +99,12 @@ interface IEditService : IService { * @since 1.0.0 */ fun detail(username: String, toolId: String, ver: String): ToolVo + + /** + * Delete tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun delete(id: Long): Boolean } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index 58c0a4b..f0ee779 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -2,17 +2,19 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.dao.DuplicateKeyException import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.tool.ToolCategoryConverter import top.fatweb.oxygen.api.converter.tool.ToolConverter import top.fatweb.oxygen.api.converter.tool.ToolTemplateConverter import top.fatweb.oxygen.api.entity.tool.* +import top.fatweb.oxygen.api.exception.IllegalVersionException import top.fatweb.oxygen.api.exception.NoRecordFoundException -import top.fatweb.oxygen.api.exception.UserNotFoundException import top.fatweb.oxygen.api.mapper.tool.EditMapper import top.fatweb.oxygen.api.param.tool.ToolCreateParam import top.fatweb.oxygen.api.param.tool.ToolUpdateParam +import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam import top.fatweb.oxygen.api.service.tool.* import top.fatweb.oxygen.api.util.WebUtil import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo @@ -49,11 +51,15 @@ class EditServiceImpl( .map(ToolCategoryConverter::toolCategoryToToolCategoryVo) override fun getOne(id: Long): ToolVo = - baseMapper.selectOne(id, WebUtil.getLoginUserId() ?: throw UserNotFoundException()) + baseMapper.selectOne(id, WebUtil.getLoginUserId()!!) ?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() @Transactional override fun create(toolCreateParam: ToolCreateParam): ToolVo { + baseMapper.selectOne( + KtQueryWrapper(Tool()).eq(Tool::toolId, toolCreateParam.toolId!!) + .eq(Tool::authorId, WebUtil.getLoginUserId()!!) + )?.let { throw DuplicateKeyException("Duplicate Key") } val template = this.getTemplate(toolCreateParam.templateId!!) val newSource = ToolData().apply { data = template.source!!.data } val newDist = ToolData().apply { data = "" } @@ -65,11 +71,12 @@ class EditServiceImpl( icon = toolCreateParam.icon description = toolCreateParam.description baseId = template.base!!.id - authorId = WebUtil.getLoginUserId() ?: throw UserNotFoundException() + authorId = WebUtil.getLoginUserId()!! ver = toolCreateParam.ver!!.split(".").map(String::toLong).joinToString(".") keywords = toolCreateParam.keywords sourceId = newSource.id distId = newDist.id + entryPoint = template.entryPoint } this.save(tool) @@ -85,13 +92,60 @@ class EditServiceImpl( return this.getOne(tool.id!!) } + @Transactional + override fun upgrade(toolUpgradeParam: ToolUpgradeParam): ToolVo { + val originalTool = this.detail("!", toolUpgradeParam.toolId!!, "latest") + + val originalVersion = originalTool.ver!! + if (originalVersion.split(".").map(String::toLong).joinToString(".") == toolUpgradeParam.ver!!.split(".") + .map(String::toLong).joinToString(".") + ) { + throw IllegalVersionException() + } + originalVersion.split(".").forEachIndexed { index, s -> + if ((toolUpgradeParam.ver.split(".")[index].toLong() < s.toLong())) { + throw IllegalVersionException() + } + } + + val newSource = ToolData().apply { data = originalTool.source!!.data } + val newDist = ToolData().apply { data = "" } + toolDataService.saveBatch(listOf(newSource, newDist)) + + val tool = Tool().apply { + name = originalTool.name!! + toolId = originalTool.toolId + icon = originalTool.icon + description = originalTool.description + baseId = originalTool.base!!.id + authorId = WebUtil.getLoginUserId()!! + ver = toolUpgradeParam.ver.split(".").map(String::toLong).joinToString(".") + keywords = originalTool.keywords + sourceId = newSource.id + distId = newDist.id + entryPoint = originalTool.entryPoint + } + + this.save(tool) + + originalTool.categories!!.forEach { + toolCategoryService.getById(it.id) ?: throw NoRecordFoundException() + rToolCategoryService.save(RToolCategory().apply { + toolId = tool.id + categoryId = it.id + }) + } + + return this.getOne(tool.id!!) + } + @Transactional override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { TODO("Not yet implemented") } override fun get(): List = - baseMapper.selectPersonal(WebUtil.getLoginUserId() ?: throw UserNotFoundException()) + baseMapper.selectPersonal(WebUtil.getLoginUserId()!!) .map(ToolConverter::toolToToolVo) override fun detail(username: String, toolId: String, ver: String): ToolVo { @@ -102,4 +156,16 @@ class EditServiceImpl( return baseMapper.detail(username, toolId, ver, WebUtil.getLoginUsername())?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() } + + @Transactional + override fun delete(id: Long): Boolean { + val tool = baseMapper.selectOne( + KtQueryWrapper(Tool()).eq(Tool::id, id) + .eq(Tool::authorId, WebUtil.getLoginUserId()!!) + ) ?: throw NoRecordFoundException() + + toolDataService.removeBatchByIds(listOf(tool.sourceId, tool.distId)) + rToolCategoryService.remove(KtQueryWrapper(RToolCategory()).eq(RToolCategory::toolId, tool.id)) + return this.removeById(id) + } } \ No newline at end of file diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml index b8ab555..9250171 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -31,50 +31,50 @@ - + @@ -236,8 +238,9 @@ - - + + From 1ce60d1bfb5d30af102265bf1204234836c05475 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 31 Jan 2024 18:07:01 +0800 Subject: [PATCH 188/258] Add PROCESSING to Tool.ReviewType --- src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt index ae485ff..a06d660 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt @@ -21,7 +21,7 @@ class Tool { * @since 1.0.0 */ enum class ReviewType(@field:EnumValue @field:JsonValue val code: String) { - NONE("NONE"), PASS("PASS"), REJECT("REJECT") + NONE("NONE"), PROCESSING("PROCESSING"), PASS("PASS"), REJECT("REJECT") } /** From 04587fbb7a8363b18961ee7b4fc0fc9d5811df2e Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 1 Feb 2024 16:51:20 +0800 Subject: [PATCH 189/258] Implement update tool --- .../api/controller/tool/EditController.kt | 19 ++++- .../oxygen/api/entity/common/ResponseCode.kt | 3 + .../api/exception/DatabaseDeleteException.kt | 8 +++ .../api/exception/DatabaseInsertException.kt | 8 +++ .../api/exception/DatabaseSelectException.kt | 8 +++ .../api/exception/DatabaseUpdateException.kt | 8 +++ .../api/exception/IllegalVersionException.kt | 7 ++ .../exception/MatchSensitiveWordException.kt | 9 ++- ...uent.kt => RequestTooFrequentException.kt} | 3 +- .../ToolHasBeenPublishedException.kt | 10 +++ .../oxygen/api/exception/ToolHasPublish.kt | 3 - .../ToolHasUnpublishedVersionException.kt | 10 +++ .../api/exception/ToolUnderReviewException.kt | 10 +++ .../oxygen/api/handler/ExceptionHandler.kt | 17 ++++- .../oxygen/api/mapper/tool/EditMapper.kt | 2 +- .../permission/group/GroupDeleteParam.kt | 4 +- .../param/permission/role/RoleDeleteParam.kt | 4 +- .../param/permission/user/UserDeleteParam.kt | 4 +- .../oxygen/api/param/tool/ToolCreateParam.kt | 4 +- .../oxygen/api/param/tool/ToolUpdateParam.kt | 55 ++------------- .../oxygen/api/param/tool/ToolUpgradeParam.kt | 2 +- .../impl/AuthenticationServiceImpl.kt | 4 +- .../permission/impl/GroupServiceImpl.kt | 2 +- .../permission/impl/RoleServiceImpl.kt | 2 +- .../permission/impl/UserServiceImpl.kt | 2 +- .../api/service/tool/impl/EditServiceImpl.kt | 70 +++++++++++++++++-- src/main/resources/mapper/tool/EditMapper.xml | 1 - 27 files changed, 204 insertions(+), 75 deletions(-) rename src/main/kotlin/top/fatweb/oxygen/api/exception/{RequestTooFrequent.kt => RequestTooFrequentException.kt} (59%) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasBeenPublishedException.kt delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasUnpublishedVersionException.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/ToolUnderReviewException.kt diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index 318fadd..6451998 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -7,6 +7,7 @@ import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult import top.fatweb.oxygen.api.param.tool.ToolCreateParam +import top.fatweb.oxygen.api.param.tool.ToolUpdateParam import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam import top.fatweb.oxygen.api.service.tool.IEditService import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo @@ -83,10 +84,13 @@ class EditController( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @Operation(summary = "更新工具") + @Operation(summary = "升级工具") @PatchMapping fun upgrade(@RequestBody @Valid toolUpgradeParam: ToolUpgradeParam): ResponseResult = - ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = editService.upgrade(toolUpgradeParam)) + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, + data = editService.upgrade(toolUpgradeParam) + ) /** * Get personal tool @@ -113,6 +117,17 @@ class EditController( data = editService.detail(username, toolId, ver) ) + /** + * Update tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "更新工具") + @PutMapping + fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam) = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = editService.update(toolUpdateParam)) + /** * Delete tool * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index 738f9ae..be1dae1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -59,6 +59,9 @@ enum class ResponseCode(val code: Int) { DATABASE_NO_RECORD_FOUND(BusinessCode.DATABASE, 52), TOOL_ILLEGAL_VERSION(BusinessCode.TOOL, 50), + TOOL_UNDER_REVIEW(BusinessCode.TOOL, 51), + TOOL_HAS_UNPUBLISHED_VERSION(BusinessCode.TOOL, 52), + TOOL_HAS_BEEN_PUBLISHED(BusinessCode.TOOL, 53), API_AVATAR_SUCCESS(BusinessCode.API_AVATAR, 0), API_AVATAR_ERROR(BusinessCode.API_AVATAR, 50); diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt index f6926b2..cd1ea34 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseDeleteException.kt @@ -1,3 +1,11 @@ package top.fatweb.oxygen.api.exception +/** + * Database delete exception + * + * @param message Exception message + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class DatabaseDeleteException(message: String = "Database delete failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt index 1744ea7..b3e301d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseInsertException.kt @@ -1,3 +1,11 @@ package top.fatweb.oxygen.api.exception +/** + * Database insert exception + * + * @param message Exception message + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class DatabaseInsertException(message: String = "Database insert failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt index e8e1d2b..1b5623b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseSelectException.kt @@ -1,3 +1,11 @@ package top.fatweb.oxygen.api.exception +/** + * Database select exception + * + * @param message Exception message + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class DatabaseSelectException(message: String = "Database select failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt index c2fa87c..43f6c09 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/DatabaseUpdateException.kt @@ -1,3 +1,11 @@ package top.fatweb.oxygen.api.exception +/** + * Database update exception + * + * @param message Exception message + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class DatabaseUpdateException(message: String = "Database update failed"): RuntimeException(message) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt index 3ee96ae..b53fc99 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/IllegalVersionException.kt @@ -1,3 +1,10 @@ package top.fatweb.oxygen.api.exception +/** + * Illegal version exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ class IllegalVersionException : RuntimeException("Illegal Version") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt index d428efb..dbf5cf6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/MatchSensitiveWordException.kt @@ -1,3 +1,10 @@ package top.fatweb.oxygen.api.exception -class MatchSensitiveWordException: RuntimeException("Match sensitive word") \ No newline at end of file +/** + * Match sensitive word exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class MatchSensitiveWordException : RuntimeException("Match sensitive word") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequent.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequentException.kt similarity index 59% rename from src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequent.kt rename to src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequentException.kt index be1f1e2..59a5b16 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequent.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/RequestTooFrequentException.kt @@ -5,5 +5,6 @@ package top.fatweb.oxygen.api.exception * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see RuntimeException */ -class RequestTooFrequent: RuntimeException("Request too frequent") \ No newline at end of file +class RequestTooFrequentException: RuntimeException("Request too frequent") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasBeenPublishedException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasBeenPublishedException.kt new file mode 100644 index 0000000..f80dfca --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasBeenPublishedException.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Tool has been published exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class ToolHasBeenPublishedException : RuntimeException("Tool has been published") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt deleted file mode 100644 index 72998c2..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasPublish.kt +++ /dev/null @@ -1,3 +0,0 @@ -package top.fatweb.oxygen.api.exception - -class ToolHasPublish : RuntimeException("The tool has been published and cannot be modified") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasUnpublishedVersionException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasUnpublishedVersionException.kt new file mode 100644 index 0000000..0b4d41e --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasUnpublishedVersionException.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Tool has unpublished version exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class ToolHasUnpublishedVersionException : RuntimeException("Has unpublished version") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolUnderReviewException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolUnderReviewException.kt new file mode 100644 index 0000000..83083f0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolUnderReviewException.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Tool under review exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class ToolUnderReviewException : RuntimeException("Tool under review") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index e558606..a3c85ef 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -61,7 +61,7 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.SYSTEM_ARGUMENT_NOT_VALID, errorMessage, null) } - is RequestTooFrequent -> { + is RequestTooFrequentException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_TOO_FREQUENT, e.localizedMessage, null) } @@ -217,6 +217,21 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.TOOL_ILLEGAL_VERSION, e.localizedMessage, null) } + is ToolUnderReviewException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.TOOL_UNDER_REVIEW, e.localizedMessage, null) + } + + is ToolHasUnpublishedVersionException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.TOOL_HAS_UNPUBLISHED_VERSION, e.localizedMessage, null) + } + + is ToolHasBeenPublishedException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.TOOL_HAS_BEEN_PUBLISHED, e.localizedMessage, null) + } + /* Other */ is MatchSensitiveWordException -> { logger.debug(e.localizedMessage, e) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt index 567f741..d31a8eb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt @@ -27,5 +27,5 @@ interface EditMapper : BaseMapper { @Param("toolId") toolId: String, @Param("ver") ver: String, @Param("operator") operator: String? - ): Tool? + ): List? } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupDeleteParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupDeleteParam.kt index f7ebe22..ff08c35 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupDeleteParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/group/GroupDeleteParam.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.param.permission.group import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotEmpty /** * Delete group parameters @@ -17,5 +18,6 @@ data class GroupDeleteParam( * @since 1.0.0 */ @Schema(description = "用户组 ID 列表", required = true) - val ids: List + @field: NotEmpty(message = "Ids can not be empty") + val ids: List? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleDeleteParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleDeleteParam.kt index af400da..0704b2a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleDeleteParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/role/RoleDeleteParam.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.param.permission.role import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotEmpty /** * Delete role parameters @@ -17,5 +18,6 @@ data class RoleDeleteParam( * @since 1.0.0 */ @Schema(description = "角色 ID 列表", required = true) - val ids: List + @field: NotEmpty(message = "Ids can not be empty") + val ids: List? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserDeleteParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserDeleteParam.kt index 486d39c..0a61709 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserDeleteParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserDeleteParam.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.param.permission.user import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotEmpty /** * Delete user parameters @@ -17,5 +18,6 @@ data class UserDeleteParam( * @since 1.0.0 */ @Schema(description = "用户 ID 列表", required = true) - val ids: List + @field: NotEmpty(message = "Ids can not be empty") + val ids: List? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt index 8cd4e83..3cb0361 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt @@ -86,7 +86,7 @@ data class ToolCreateParam( */ @Schema(description = "关键词", required = true) @field: NotEmpty(message = "Keywords can not be empty") - val keywords: List, + val keywords: List?, /** * Categories @@ -96,5 +96,5 @@ data class ToolCreateParam( */ @Schema(description = "类别", required = true) @field: NotEmpty(message = "Categories can not be empty") - val categories: List + val categories: List? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt index f341be8..935ceef 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt @@ -2,7 +2,6 @@ package top.fatweb.oxygen.api.param.tool import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull -import jakarta.validation.constraints.Pattern /** * Update tool parameters @@ -10,6 +9,7 @@ import jakarta.validation.constraints.Pattern * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ +@Schema(description = "更新工具请求参数") data class ToolUpdateParam( /** * ID @@ -31,17 +31,13 @@ data class ToolUpdateParam( val name: String?, /** - * Tool ID + * Icon * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @Schema(description = "工具唯一 ID", example = "tool_a") - @field: Pattern( - regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", - message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" - ) - val toolId: String?, + @Schema(description = "图标") + val icon: String?, /** * Description @@ -52,34 +48,6 @@ data class ToolUpdateParam( @Schema(description = "简介") val description: String?, - /** - * Author ID - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "作者 ID") - val authorId: Long?, - - /** - * Version - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "版本", example = "1.0.3") - @field: Pattern(regexp = "^\\d+\\.\\d+\\.\\d+\$", message = "Ver can only match '..'") - val ver: String?, - - /** - * Privately - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "私有", allowableValues = ["true", "false"]) - val privately: Boolean?, - /** * Keywords * @@ -87,7 +55,7 @@ data class ToolUpdateParam( * @since 1.0.0 */ @Schema(description = "关键词") - val keywords: List, + val keywords: List?, /** * Categories @@ -96,7 +64,7 @@ data class ToolUpdateParam( * @since 1.0.0 */ @Schema(description = "类别") - val categories: List, + val categories: List?, /** * Source @@ -105,14 +73,5 @@ data class ToolUpdateParam( * @since 1.0.0 */ @Schema(description = "源码") - val source: String?, - - /** - * Dist - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - @Schema(description = "产物") - val dist: String? + val source: String? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt index eb140f2..e3cca51 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt @@ -10,7 +10,7 @@ import jakarta.validation.constraints.Pattern * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -@Schema(description = "更新工具请求参数") +@Schema(description = "升级工具请求参数") data class ToolUpgradeParam( /** * Tool ID diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt index f9e4982..b83dbe5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -106,7 +106,7 @@ class AuthenticationServiceImpl( if (LocalDateTime.ofInstant(Instant.ofEpochMilli(user.verify!!.split("-").first().toLong()), ZoneOffset.UTC) .isAfter(LocalDateTime.now(ZoneOffset.UTC).minusMinutes(5)) ) { - throw RequestTooFrequent() + throw RequestTooFrequentException() } user.verify = @@ -158,7 +158,7 @@ class AuthenticationServiceImpl( if (LocalDateTime.ofInstant(Instant.ofEpochMilli(it.split("-").first().toLong()), ZoneOffset.UTC) .isAfter(LocalDateTime.now(ZoneOffset.UTC).minusMinutes(5)) ) { - throw RequestTooFrequent() + throw RequestTooFrequentException() } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt index d81da51..416bc65 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt @@ -144,7 +144,7 @@ class GroupServiceImpl( override fun delete(groupDeleteParam: GroupDeleteParam) { baseMapper.deleteBatchIds(groupDeleteParam.ids) rRoleGroupService.remove(KtQueryWrapper(RRoleGroup()).`in`(RRoleGroup::groupId, groupDeleteParam.ids)) - offlineUser(*groupDeleteParam.ids.toLongArray()) + offlineUser(*groupDeleteParam.ids!!.toLongArray()) } private fun offlineUser(vararg groupIds: Long) { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt index 8ea381c..49859c3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt @@ -151,7 +151,7 @@ class RoleServiceImpl( override fun delete(roleDeleteParam: RoleDeleteParam) { baseMapper.deleteBatchIds(roleDeleteParam.ids) rPowerRoleService.remove(KtQueryWrapper(RPowerRole()).`in`(RPowerRole::roleId, roleDeleteParam.ids)) - offlineUser(*roleDeleteParam.ids.toLongArray()) + offlineUser(*roleDeleteParam.ids!!.toLongArray()) } private fun getFullPowerIds(powerIds: List): Set { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt index b698886..912413a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt @@ -276,7 +276,7 @@ class UserServiceImpl( @Transactional override fun delete(userDeleteParam: UserDeleteParam) { - val ids = userDeleteParam.ids.filter { it != 0L } + val ids = userDeleteParam.ids!!.filter { it != 0L } if (ids.isEmpty()) { return } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index f0ee779..e7326c1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -9,8 +9,7 @@ import top.fatweb.oxygen.api.converter.tool.ToolCategoryConverter import top.fatweb.oxygen.api.converter.tool.ToolConverter import top.fatweb.oxygen.api.converter.tool.ToolTemplateConverter import top.fatweb.oxygen.api.entity.tool.* -import top.fatweb.oxygen.api.exception.IllegalVersionException -import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.exception.* import top.fatweb.oxygen.api.mapper.tool.EditMapper import top.fatweb.oxygen.api.param.tool.ToolCreateParam import top.fatweb.oxygen.api.param.tool.ToolUpdateParam @@ -81,7 +80,7 @@ class EditServiceImpl( this.save(tool) - toolCreateParam.categories.forEach { + toolCreateParam.categories!!.forEach { toolCategoryService.getById(it) ?: throw NoRecordFoundException() rToolCategoryService.save(RToolCategory().apply { toolId = tool.id @@ -95,6 +94,12 @@ class EditServiceImpl( @Transactional override fun upgrade(toolUpgradeParam: ToolUpgradeParam): ToolVo { val originalTool = this.detail("!", toolUpgradeParam.toolId!!, "latest") + if (originalTool.review == Tool.ReviewType.PROCESSING) { + throw ToolUnderReviewException() + } + if (originalTool.review != Tool.ReviewType.PASS || originalTool.publish == 0L) { + throw ToolHasUnpublishedVersionException() + } val originalVersion = originalTool.ver!! if (originalVersion.split(".").map(String::toLong).joinToString(".") == toolUpgradeParam.ver!!.split(".") @@ -141,7 +146,57 @@ class EditServiceImpl( @Transactional override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { - TODO("Not yet implemented") + val tool = getById(toolUpdateParam.id) + if (tool.review == Tool.ReviewType.PROCESSING) { + throw ToolUnderReviewException() + } + if (tool.review == Tool.ReviewType.PASS || tool.publish != 0L) { + throw ToolHasBeenPublishedException() + } + + this.updateById(Tool().apply { + id = toolUpdateParam.id + name = toolUpdateParam.name + icon = toolUpdateParam.icon + description = toolUpdateParam.description + keywords = toolUpdateParam.keywords + }) + + if (!toolUpdateParam.categories.isNullOrEmpty()) { + val oldCategories = rToolCategoryService.list( + KtQueryWrapper(RToolCategory()).select(RToolCategory::categoryId).eq(RToolCategory::toolId, tool.id) + ).map(RToolCategory::categoryId) + val addCategories = HashSet() + val removeCategories = HashSet() + toolUpdateParam.categories.forEach(addCategories::add) + oldCategories.forEach { + it?.let(removeCategories::add) + } + removeCategories.removeAll(addCategories) + oldCategories.toSet().let(addCategories::removeAll) + + removeCategories.forEach { + rToolCategoryService.remove( + KtQueryWrapper(RToolCategory()).eq( + RToolCategory::toolId, tool.id + ).eq(RToolCategory::categoryId, it) + ) + } + + addCategories.forEach { + rToolCategoryService.save(RToolCategory().apply { + toolId = tool.id + categoryId = it + }) + } + + toolDataService.updateById(ToolData().apply { + id = tool.sourceId + data = toolUpdateParam.source + }) + } + + return this.getOne(tool.id!!) } override fun get(): List = @@ -152,9 +207,12 @@ class EditServiceImpl( if (username == "!" && WebUtil.getLoginUserId() == null) { throw NoRecordFoundException() } + val toolList = baseMapper.detail(username, toolId, ver, WebUtil.getLoginUsername()) + if (toolList.isNullOrEmpty()) { + throw NoRecordFoundException() + } - return baseMapper.detail(username, toolId, ver, WebUtil.getLoginUsername())?.let(ToolConverter::toolToToolVo) - ?: throw NoRecordFoundException() + return toolList.first().let(ToolConverter::toolToToolVo) } @Transactional diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml index 9250171..1303e22 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -208,7 +208,6 @@ order by t_b_tool_main.id desc - limit 1 Date: Thu, 1 Feb 2024 19:07:12 +0800 Subject: [PATCH 190/258] Add tool submit and cancel api --- .../api/controller/tool/EditController.kt | 24 ++++++++++++++++++ .../oxygen/api/entity/common/ResponseCode.kt | 9 +++++-- .../exception/ToolNotUnderReviewException.kt | 10 ++++++++ .../oxygen/api/handler/ExceptionHandler.kt | 5 ++++ .../oxygen/api/service/tool/IEditService.kt | 16 ++++++++++++ .../api/service/tool/impl/EditServiceImpl.kt | 25 +++++++++++++++++++ 6 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/ToolNotUnderReviewException.kt diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index 6451998..e6d0501 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -128,6 +128,30 @@ class EditController( fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam) = ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = editService.update(toolUpdateParam)) + /** + * Submit tool review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "提交工具审核") + @PostMapping("/{id}") + fun submit(@PathVariable id: Long): ResponseResult = + if (editService.submit(id)) ResponseResult.success(ResponseCode.TOOL_SUBMIT_SUCCESS) + else ResponseResult.fail(ResponseCode.TOOL_SUBMIT_ERROR) + + /** + * Cancel tool review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "取消工具审核") + @PutMapping("/{id}") + fun cancel(@PathVariable id: Long): ResponseResult = + if (editService.cancel(id)) ResponseResult.success(ResponseCode.TOOL_CANCEL_SUCCESS) + else ResponseResult.fail(ResponseCode.TOOL_CANCEL_ERROR) + /** * Delete tool * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index be1dae1..01d14af 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -58,10 +58,15 @@ enum class ResponseCode(val code: Int) { DATABASE_DUPLICATE_KEY(BusinessCode.DATABASE, 51), DATABASE_NO_RECORD_FOUND(BusinessCode.DATABASE, 52), + TOOL_SUBMIT_SUCCESS(BusinessCode.TOOL, 10), + TOOL_CANCEL_SUCCESS(BusinessCode.TOOL, 11), TOOL_ILLEGAL_VERSION(BusinessCode.TOOL, 50), TOOL_UNDER_REVIEW(BusinessCode.TOOL, 51), - TOOL_HAS_UNPUBLISHED_VERSION(BusinessCode.TOOL, 52), - TOOL_HAS_BEEN_PUBLISHED(BusinessCode.TOOL, 53), + TOOL_NOT_UNDER_REVIEW(BusinessCode.TOOL, 52), + TOOL_HAS_UNPUBLISHED_VERSION(BusinessCode.TOOL, 53), + TOOL_HAS_BEEN_PUBLISHED(BusinessCode.TOOL, 54), + TOOL_SUBMIT_ERROR(BusinessCode.TOOL, 60), + TOOL_CANCEL_ERROR(BusinessCode.TOOL, 61), API_AVATAR_SUCCESS(BusinessCode.API_AVATAR, 0), API_AVATAR_ERROR(BusinessCode.API_AVATAR, 50); diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolNotUnderReviewException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolNotUnderReviewException.kt new file mode 100644 index 0000000..586d71f --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolNotUnderReviewException.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Tool not under review exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class ToolNotUnderReviewException : RuntimeException("Tool not under review") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index a3c85ef..2f4d155 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -222,6 +222,11 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.TOOL_UNDER_REVIEW, e.localizedMessage, null) } + is ToolNotUnderReviewException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.TOOL_NOT_UNDER_REVIEW, e.localizedMessage, null) + } + is ToolHasUnpublishedVersionException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.TOOL_HAS_UNPUBLISHED_VERSION, e.localizedMessage, null) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt index 7f8e197..31da2ef 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt @@ -100,6 +100,22 @@ interface IEditService : IService { */ fun detail(username: String, toolId: String, ver: String): ToolVo + /** + * Submit tool review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun submit(id: Long): Boolean + + /** + * Cancel tool review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun cancel(id: Long): Boolean + /** * Delete tool * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index e7326c1..6d79f0e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper +import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.dao.DuplicateKeyException import org.springframework.stereotype.Service @@ -215,6 +216,30 @@ class EditServiceImpl( return toolList.first().let(ToolConverter::toolToToolVo) } + override fun submit(id: Long): Boolean { + val tool = getById(id) + if (tool.review == Tool.ReviewType.PROCESSING) { + throw ToolUnderReviewException() + } + if (tool.review == Tool.ReviewType.PASS || tool.publish != 0L) { + throw ToolHasBeenPublishedException() + } + + return update(KtUpdateWrapper(Tool()).eq(Tool::id, id).set(Tool::review, Tool.ReviewType.PROCESSING)) + } + + override fun cancel(id: Long): Boolean { + val tool = getById(id) + if (tool.review == Tool.ReviewType.PASS || tool.publish != 0L) { + throw ToolHasBeenPublishedException() + } + if (tool.review != Tool.ReviewType.PROCESSING) { + throw ToolNotUnderReviewException() + } + + return update(KtUpdateWrapper(Tool()).eq(Tool::id, id).set(Tool::review, Tool.ReviewType.NONE)) + } + @Transactional override fun delete(id: Long): Boolean { val tool = baseMapper.selectOne( From 9692550198b219a010c82a3b9fc12d72c9f85d6d Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 2 Feb 2024 17:43:09 +0800 Subject: [PATCH 191/258] Add tool management api --- .../controller/tool/ManagementController.kt | 100 ++++++++-- .../api/converter/tool/ToolConverter.kt | 10 + .../oxygen/api/entity/common/ResponseCode.kt | 3 +- .../ToolHasNotBeenPublishedException.kt | 10 + .../oxygen/api/handler/ExceptionHandler.kt | 5 + .../api/mapper/tool/ManagementMapper.kt | 30 +++ .../oxygen/api/mapper/tool/ToolMapper.kt | 16 -- .../oxygen/api/param/system/SysLogGetParam.kt | 14 +- .../api/param/tool/ToolManagementGetParam.kt | 54 +++++ .../api/service/tool/IManagementService.kt | 29 +++ .../oxygen/api/service/tool/IToolService.kt | 14 -- .../api/service/tool/impl/EditServiceImpl.kt | 2 + .../tool/impl/ManagementServiceImpl.kt | 125 ++++++++++++ .../api/service/tool/impl/ToolServiceImpl.kt | 70 ------- .../mapper/permission/GroupMapper.xml | 7 +- .../mapper/permission/RoleMapper.xml | 4 + .../mapper/permission/UserMapper.xml | 4 + src/main/resources/mapper/tool/EditMapper.xml | 64 +----- .../mapper/tool/ManagementMapper.xml | 184 ++++++++++++++++++ 19 files changed, 557 insertions(+), 188 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasNotBeenPublishedException.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt delete mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt create mode 100644 src/main/resources/mapper/tool/ManagementMapper.xml diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt index e062586..82b2bfc 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt @@ -1,30 +1,88 @@ package top.fatweb.oxygen.api.controller.tool +import io.swagger.v3.oas.annotations.Operation +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PatchMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.PutMapping import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseCode +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.tool.ToolManagementGetParam +import top.fatweb.oxygen.api.service.tool.IManagementService +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.tool.ToolVo @BaseController(path = ["/system/tool"], name = "工具管理", description = "工具管理相关接口") -class ManagementController { - /* @Operation(summary = "获取单个工具") - @GetMapping("/{id}") - fun getOne(@PathVariable id: Long): ResponseResult = - ResponseResult.databaseSuccess(data = toolService.getOne(id)) +class ManagementController( + private val managementService: IManagementService +) { + /** + * Get tool by ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "获取单个工具") + @GetMapping("/{id}") + fun getOne(@PathVariable id: Long): ResponseResult = + ResponseResult.databaseSuccess(data = managementService.getOne(id)) - @Operation(summary = "获取工具") - @GetMapping - fun get(): ResponseResult> = - ResponseResult.databaseSuccess(data = toolService.get()) + /** + * Get tool paging information + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "获取工具") + @GetMapping + fun get(toolManagementGetParam: ToolManagementGetParam): ResponseResult> = + ResponseResult.databaseSuccess(data = managementService.getPage(toolManagementGetParam)) + + /** + * Pass tool review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "通过审核") + @PostMapping("/{id}") + fun pass(@PathVariable id: Long): ResponseResult = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = managementService.pass(id)) - @Operation(summary = "更新工具") - @PutMapping - fun update(@RequestBody @Valid toolUpdateParam: ToolUpdateParam): ResponseResult = - ResponseResult.databaseSuccess( - ResponseCode.DATABASE_UPDATE_SUCCESS, - data = toolService.update(toolUpdateParam) - ) + /** + * Reject tool review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "驳回审核") + @PutMapping("/{id}") + fun reject(@PathVariable id: Long): ResponseResult = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = managementService.reject(id)) - @Operation(summary = "删除工具") - @DeleteMapping("/{id}") - fun delete(@PathVariable id: Long): ResponseResult = - if (toolService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) - else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED)*/ + /** + * Put off shelve + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "下架") + @PatchMapping("/{id}") + fun offShelve(@PathVariable id: Long):ResponseResult = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = managementService.offShelve(id)) + + /** + * Delete tool + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Operation(summary = "删除工具") + @DeleteMapping("/{id}") + fun delete(@PathVariable id: Long): ResponseResult = + if (managementService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt index 9c9c39d..9d273b6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt @@ -1,7 +1,9 @@ package top.fatweb.oxygen.api.converter.tool +import com.baomidou.mybatisplus.extension.plugins.pagination.Page import top.fatweb.oxygen.api.converter.permission.UserConverter import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo /** @@ -40,4 +42,12 @@ object ToolConverter { createTime = tool.createTime, updateTime = tool.updateTime ) + + fun toolPageToToolPageVo(toolPage: Page): PageVo = PageVo( + total = toolPage.total, + pages = toolPage.pages, + size = toolPage.size, + current = toolPage.current, + records = toolPage.records.map(this::toolToToolVo) + ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index 01d14af..83a3dfd 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -64,7 +64,8 @@ enum class ResponseCode(val code: Int) { TOOL_UNDER_REVIEW(BusinessCode.TOOL, 51), TOOL_NOT_UNDER_REVIEW(BusinessCode.TOOL, 52), TOOL_HAS_UNPUBLISHED_VERSION(BusinessCode.TOOL, 53), - TOOL_HAS_BEEN_PUBLISHED(BusinessCode.TOOL, 54), + TOOL_HAS_NOT_BEEN_PUBLISHED(BusinessCode.TOOL, 54), + TOOL_HAS_BEEN_PUBLISHED(BusinessCode.TOOL, 55), TOOL_SUBMIT_ERROR(BusinessCode.TOOL, 60), TOOL_CANCEL_ERROR(BusinessCode.TOOL, 61), diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasNotBeenPublishedException.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasNotBeenPublishedException.kt new file mode 100644 index 0000000..af82607 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/ToolHasNotBeenPublishedException.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Tool has not been published exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class ToolHasNotBeenPublishedException : RuntimeException("Tool has not been published") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index 2f4d155..8624e10 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -232,6 +232,11 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.TOOL_HAS_UNPUBLISHED_VERSION, e.localizedMessage, null) } + is ToolHasNotBeenPublishedException -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.TOOL_HAS_NOT_BEEN_PUBLISHED, e.localizedMessage, null) + } + is ToolHasBeenPublishedException -> { logger.debug(e.localizedMessage, e) ResponseResult.fail(ResponseCode.TOOL_HAS_BEEN_PUBLISHED, e.localizedMessage, null) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt new file mode 100644 index 0000000..185bc30 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt @@ -0,0 +1,30 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import com.baomidou.mybatisplus.core.metadata.IPage +import org.apache.ibatis.annotations.Mapper +import org.apache.ibatis.annotations.Param +import top.fatweb.oxygen.api.entity.tool.Tool + +/** + * Tool mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see Tool + */ +@Mapper +interface ManagementMapper : BaseMapper { + fun selectOne(@Param("id") id: Long): Tool? + + fun selectPage( + page: IPage, + @Param("review") review: List?, + @Param("searchType") searchType: String, + @Param("searchValue") searchValue: String?, + @Param("searchRegex") searchRegex: Boolean + ): IPage + + fun selectListByIds(@Param("ids") ids: List): List +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt deleted file mode 100644 index 77dd30a..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolMapper.kt +++ /dev/null @@ -1,16 +0,0 @@ -package top.fatweb.oxygen.api.mapper.tool - -import com.baomidou.mybatisplus.core.mapper.BaseMapper -import org.apache.ibatis.annotations.Mapper -import top.fatweb.oxygen.api.entity.tool.Tool - -/** - * Tool mapper - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see BaseMapper - * @see Tool - */ -@Mapper -interface ToolMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/system/SysLogGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/SysLogGetParam.kt index f948f87..ef5263b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/system/SysLogGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/SysLogGetParam.kt @@ -20,7 +20,11 @@ data class SysLogGetParam( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @Schema(description = "类型过滤(多个使用逗号分隔)", allowableValues = ["INFO", "ERROR"], example = "INFO") + @Schema( + description = "类型过滤(多个使用逗号分隔)", + allowableValues = ["INFO", "LOGIN", "LOGOUT", "REGISTER", "STATISTICS", "API", "ERROR"], + example = "INFO" + ) val logType: String?, /** @@ -51,10 +55,10 @@ data class SysLogGetParam( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ -/* - @Schema(description = "查询使用正则表达式", allowableValues = ["true", "false"], defaultValue = "false") - val searchRegex: Boolean = false, -*/ + /* + @Schema(description = "查询使用正则表达式", allowableValues = ["true", "false"], defaultValue = "false") + val searchRegex: Boolean = false, + */ /** * Start time to search for diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt new file mode 100644 index 0000000..f6941bd --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt @@ -0,0 +1,54 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import top.fatweb.oxygen.api.param.PageSortParam + +data class ToolManagementGetParam( + /** + * Type of search + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema( + description = "搜索类型", + allowableValues = ["ALL", "ID", "USERNAME", "NICKNAME", "EMAIL"], + defaultValue = "ALL", + example = "ALL" + ) + val searchType: String = "ALL", + + /** + * Value to search for + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "查询内容", example = "ToolName") + val searchValue: String?, + + /** + * Use regex + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema( + description = "查询使用正则表达式", + allowableValues = ["true", "false"], + defaultValue = "false", + example = "false" + ) + val searchRegex: Boolean = false, + + /** + * Review + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "审核状态过滤(多个使用逗号分隔)", + allowableValues = ["NONE", "PROCESSING", "REJECT", "PASS"], + example = "NONE,PASS") + val review: String? +) : PageSortParam() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt new file mode 100644 index 0000000..e7373ac --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt @@ -0,0 +1,29 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.param.tool.ToolManagementGetParam +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool management service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see Tool + */ +interface IManagementService : IService { + fun getOne(id: Long): ToolVo + + fun getPage(toolManagementGetParam: ToolManagementGetParam?): PageVo + + fun pass(id: Long): ToolVo + + fun reject(id: Long): ToolVo + + fun offShelve(id: Long): ToolVo + + fun delete(id: Long): Boolean +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt deleted file mode 100644 index c0df740..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolService.kt +++ /dev/null @@ -1,14 +0,0 @@ -package top.fatweb.oxygen.api.service.tool - -import com.baomidou.mybatisplus.extension.service.IService -import top.fatweb.oxygen.api.entity.tool.Tool - -/** - * Tool service interface - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see IService - * @see Tool - */ -interface IToolService : IService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index 6d79f0e..af4caa3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -190,7 +190,9 @@ class EditServiceImpl( categoryId = it }) } + } + if (!toolUpdateParam.source.isNullOrBlank()) { toolDataService.updateById(ToolData().apply { id = tool.sourceId data = toolUpdateParam.source diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt new file mode 100644 index 0000000..45cb9fe --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt @@ -0,0 +1,125 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.core.metadata.OrderItem +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper +import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper +import com.baomidou.mybatisplus.extension.plugins.pagination.Page +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import top.fatweb.oxygen.api.converter.tool.ToolConverter +import top.fatweb.oxygen.api.entity.tool.RToolCategory +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.exception.NoRecordFoundException +import top.fatweb.oxygen.api.exception.ToolHasNotBeenPublishedException +import top.fatweb.oxygen.api.exception.ToolNotUnderReviewException +import top.fatweb.oxygen.api.mapper.tool.ManagementMapper +import top.fatweb.oxygen.api.param.tool.ToolManagementGetParam +import top.fatweb.oxygen.api.service.tool.IEditService +import top.fatweb.oxygen.api.service.tool.IManagementService +import top.fatweb.oxygen.api.service.tool.IRToolCategoryService +import top.fatweb.oxygen.api.service.tool.IToolDataService +import top.fatweb.oxygen.api.util.PageUtil +import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.tool.ToolVo +import java.time.LocalDateTime +import java.time.ZoneOffset + +/** + * Tool management service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see ManagementMapper + * @see Tool + * @see IManagementService + */ +@Service +class ManagementServiceImpl( + private val toolDataService: IToolDataService, + private val rToolCategoryService: IRToolCategoryService +) : ServiceImpl(), IManagementService { + override fun getOne(id: Long): ToolVo = + baseMapper.selectOne(id) + ?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() + override fun getPage(toolManagementGetParam: ToolManagementGetParam?): PageVo { + val toolIdsPage = Page(toolManagementGetParam?.currentPage ?: 1, toolManagementGetParam?.pageSize ?: 20) + + PageUtil.setPageSort(toolManagementGetParam, toolIdsPage, OrderItem.desc("id")) + + val toolIdsIPage = + baseMapper.selectPage( + toolIdsPage, + toolManagementGetParam?.review?.split(","), + toolManagementGetParam?.searchType ?: "ALL", + toolManagementGetParam?.searchValue, + toolManagementGetParam?.searchRegex ?: false + ) + val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) + if (toolIdsIPage.total > 0) { + toolPage.setRecords(baseMapper.selectListByIds(toolIdsIPage.records)) + } + + return ToolConverter.toolPageToToolPageVo(toolPage) + } + + override fun pass(id: Long): ToolVo { + val tool = this.getById(id) ?: throw NoRecordFoundException() + if (tool.review !== Tool.ReviewType.PROCESSING) { + throw ToolNotUnderReviewException() + } + + this.update( + KtUpdateWrapper(Tool()) + .eq(Tool::id, id) + .set(Tool::review, Tool.ReviewType.PASS) + .set(Tool::publish, LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli()) + ) + + return this.getOne(id) + } + + override fun reject(id: Long): ToolVo { + val tool = this.getById(id) ?: throw NoRecordFoundException() + if (tool.review !== Tool.ReviewType.PROCESSING) { + throw ToolNotUnderReviewException() + } + + this.update( + KtUpdateWrapper(Tool()) + .eq(Tool::id, id) + .set(Tool::review, Tool.ReviewType.REJECT) + ) + + return this.getOne(id) + } + + override fun offShelve(id: Long): ToolVo { + val tool = this.getById(id) ?: throw NoRecordFoundException() + if (tool.review !== Tool.ReviewType.PASS && tool.publish == 0L) { + throw ToolHasNotBeenPublishedException() + } + + this.update( + KtUpdateWrapper(Tool()) + .eq(Tool::id, id) + .set(Tool::review, Tool.ReviewType.REJECT) + .set(Tool::publish, 0) + ) + + return this.getOne(id) + } + + @Transactional + override fun delete(id: Long): Boolean { + val tool = this.getById(id) ?: throw NoRecordFoundException() + + toolDataService.removeBatchByIds(listOf(tool.sourceId, tool.distId)) + rToolCategoryService.remove(KtQueryWrapper(RToolCategory()).eq(RToolCategory::toolId, id)) + + return this.removeById(id) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt deleted file mode 100644 index 1f77089..0000000 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolServiceImpl.kt +++ /dev/null @@ -1,70 +0,0 @@ -package top.fatweb.oxygen.api.service.tool.impl - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl -import org.springframework.stereotype.Service -import top.fatweb.oxygen.api.entity.tool.Tool -import top.fatweb.oxygen.api.mapper.tool.ToolMapper -import top.fatweb.oxygen.api.service.tool.IToolService - -/** - * Tool service implement - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - * @see ServiceImpl - * @see ToolMapper - * @see Tool - * @see IToolService - */ -@Service -class ToolServiceImpl : ServiceImpl(), IToolService { - /* - override fun getOne(id: Long): ToolVo = - baseMapper.selectOne(id)?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() - - override fun get(): List = baseMapper.selectList().map(ToolConverter::toolToToolVo) - - @Transactional - override fun update(toolUpdateParam: ToolUpdateParam): ToolVo { - val tool = baseMapper.selectOne(toolUpdateParam.id!!) ?: throw NoRecordFoundException() - if (tool.publish == 1) { - throw ToolHasPublish() - } - userService.getOne(toolUpdateParam.authorId!!) - - toolDataService.updateById(ToolData().apply { - id = tool.sourceId - data = toolUpdateParam.source - }) - - toolDataService.updateById(ToolData().apply { - id = tool.distId - data = toolUpdateParam.dist - }) - - this.updateById(Tool().apply { - id = toolUpdateParam.id - name = toolUpdateParam.name - toolId = toolUpdateParam.toolId - description = toolUpdateParam.description - authorId = toolUpdateParam.authorId - ver = toolUpdateParam.ver - privately = toolUpdateParam.privately?.let { if (it) 1 else 0 } - keywords = toolUpdateParam.keywords - }) - - // TODO Category process - - return this.getOne(tool.id!!) - } - - @Transactional - override fun delete(id: Long): Boolean { - val tool = this.getById(id) - - return toolDataService.removeBatchByIds(listOf(tool.sourceId, tool.distId)) - && rToolCategoryService.remove(KtQueryWrapper(RToolCategory()).eq(RToolCategory::toolId, tool.id)) - && this.removeById(tool.id) - } - */ -} \ No newline at end of file diff --git a/src/main/resources/mapper/permission/GroupMapper.xml b/src/main/resources/mapper/permission/GroupMapper.xml index 0523c54..74d97b9 100644 --- a/src/main/resources/mapper/permission/GroupMapper.xml +++ b/src/main/resources/mapper/permission/GroupMapper.xml @@ -38,11 +38,16 @@ left join (select * from t_r_role_group where deleted = 0) as trrg on t_s_group.id = trrg.group_id left join (select * from t_s_role where deleted = 0) as tsr on tsr.id = trrg.role_id - #{item} + + #{item} + + - select t_b_tool_main.id as tool_id, t_b_tool_main.name as tool_name, t_b_tool_main.tool_id as tool_tool_id, @@ -92,7 +92,7 @@ and t_b_tool_main.id = #{id} - select t_b_tool_main.id as tool_id, t_b_tool_main.name as tool_name, t_b_tool_main.tool_id as tool_tool_id, @@ -128,7 +128,7 @@ order by t_b_tool_main.id desc - select t_b_tool_main.id as tool_id, t_b_tool_main.name as tool_name, t_b_tool_main.tool_id as tool_tool_id, @@ -209,60 +209,4 @@ order by t_b_tool_main.id desc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/mapper/tool/ManagementMapper.xml b/src/main/resources/mapper/tool/ManagementMapper.xml new file mode 100644 index 0000000..186a5a8 --- /dev/null +++ b/src/main/resources/mapper/tool/ManagementMapper.xml @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From c751b0984c2931f4396aeccf8b0d5b7c3436ed1e Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 4 Feb 2024 01:58:55 +0800 Subject: [PATCH 192/258] Add auto publish to tool management api --- .../controller/tool/ManagementController.kt | 23 +++++++++++-------- .../api/param/tool/ToolManagementPassParam.kt | 22 ++++++++++++++++++ .../api/service/tool/IManagementService.kt | 3 ++- .../tool/impl/ManagementServiceImpl.kt | 11 ++++++--- .../tool/impl/ToolCategoryServiceImpl.kt | 2 +- 5 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt index 82b2bfc..24e2715 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt @@ -1,16 +1,13 @@ package top.fatweb.oxygen.api.controller.tool import io.swagger.v3.oas.annotations.Operation -import org.springframework.web.bind.annotation.DeleteMapping -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PatchMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.PutMapping +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult import top.fatweb.oxygen.api.param.tool.ToolManagementGetParam +import top.fatweb.oxygen.api.param.tool.ToolManagementPassParam import top.fatweb.oxygen.api.service.tool.IManagementService import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -40,7 +37,7 @@ class ManagementController( @GetMapping fun get(toolManagementGetParam: ToolManagementGetParam): ResponseResult> = ResponseResult.databaseSuccess(data = managementService.getPage(toolManagementGetParam)) - + /** * Pass tool review * @@ -49,8 +46,14 @@ class ManagementController( */ @Operation(summary = "通过审核") @PostMapping("/{id}") - fun pass(@PathVariable id: Long): ResponseResult = - ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = managementService.pass(id)) + fun pass( + @PathVariable id: Long, + @RequestBody @Valid toolManagementPassParam: ToolManagementPassParam + ): ResponseResult = + ResponseResult.databaseSuccess( + ResponseCode.DATABASE_UPDATE_SUCCESS, + data = managementService.pass(id, toolManagementPassParam) + ) /** * Reject tool review @@ -71,7 +74,7 @@ class ManagementController( */ @Operation(summary = "下架") @PatchMapping("/{id}") - fun offShelve(@PathVariable id: Long):ResponseResult = + fun offShelve(@PathVariable id: Long): ResponseResult = ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS, data = managementService.offShelve(id)) /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt new file mode 100644 index 0000000..33460d4 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt @@ -0,0 +1,22 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank + +/** + * Pass tool in management parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class ToolManagementPassParam( + /** + * Dist + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "产物") + @field:NotBlank(message = "Dist can not be blank") + val dist: String? +) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt index e7373ac..8be97b4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt @@ -3,6 +3,7 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.Tool import top.fatweb.oxygen.api.param.tool.ToolManagementGetParam +import top.fatweb.oxygen.api.param.tool.ToolManagementPassParam import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -19,7 +20,7 @@ interface IManagementService : IService { fun getPage(toolManagementGetParam: ToolManagementGetParam?): PageVo - fun pass(id: Long): ToolVo + fun pass(id: Long, toolManagementPassParam: ToolManagementPassParam): ToolVo fun reject(id: Long): ToolVo diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt index 45cb9fe..9e6ed3e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt @@ -10,17 +10,17 @@ import org.springframework.transaction.annotation.Transactional import top.fatweb.oxygen.api.converter.tool.ToolConverter import top.fatweb.oxygen.api.entity.tool.RToolCategory import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.entity.tool.ToolData import top.fatweb.oxygen.api.exception.NoRecordFoundException import top.fatweb.oxygen.api.exception.ToolHasNotBeenPublishedException import top.fatweb.oxygen.api.exception.ToolNotUnderReviewException import top.fatweb.oxygen.api.mapper.tool.ManagementMapper import top.fatweb.oxygen.api.param.tool.ToolManagementGetParam -import top.fatweb.oxygen.api.service.tool.IEditService +import top.fatweb.oxygen.api.param.tool.ToolManagementPassParam import top.fatweb.oxygen.api.service.tool.IManagementService import top.fatweb.oxygen.api.service.tool.IRToolCategoryService import top.fatweb.oxygen.api.service.tool.IToolDataService import top.fatweb.oxygen.api.util.PageUtil -import top.fatweb.oxygen.api.util.WebUtil import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo import java.time.LocalDateTime @@ -44,6 +44,7 @@ class ManagementServiceImpl( override fun getOne(id: Long): ToolVo = baseMapper.selectOne(id) ?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() + override fun getPage(toolManagementGetParam: ToolManagementGetParam?): PageVo { val toolIdsPage = Page(toolManagementGetParam?.currentPage ?: 1, toolManagementGetParam?.pageSize ?: 20) @@ -65,12 +66,16 @@ class ManagementServiceImpl( return ToolConverter.toolPageToToolPageVo(toolPage) } - override fun pass(id: Long): ToolVo { + override fun pass(id: Long, toolManagementPassParam: ToolManagementPassParam): ToolVo { val tool = this.getById(id) ?: throw NoRecordFoundException() if (tool.review !== Tool.ReviewType.PROCESSING) { throw ToolNotUnderReviewException() } + toolDataService.update( + KtUpdateWrapper(ToolData()).eq(ToolData::id, tool.distId).set(ToolData::data, toolManagementPassParam.dist) + ) + this.update( KtUpdateWrapper(Tool()) .eq(Tool::id, id) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt index d200bb4..ed11c75 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolCategoryServiceImpl.kt @@ -44,7 +44,7 @@ class ToolCategoryServiceImpl : ServiceImpl(), override fun update(toolCategoryUpdateParam: ToolCategoryUpdateParam): ToolCategoryVo { val toolCategory = ToolCategoryConverter.toolCategoryUpdateParamToToolCategory(toolCategoryUpdateParam) - if (this.updateById(toolCategory)) { + if (!this.updateById(toolCategory)) { throw DatabaseUpdateException() } From 6c618607d8a83e00f4834bda9c0dc215943be590 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 11 Feb 2024 14:40:20 +0800 Subject: [PATCH 193/258] Optimize search in ToolManagement --- .../api/param/tool/ToolManagementGetParam.kt | 8 +- .../mapper/tool/ManagementMapper.xml | 78 ++++++++++++++++++- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt index f6941bd..8948910 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt @@ -12,7 +12,7 @@ data class ToolManagementGetParam( */ @Schema( description = "搜索类型", - allowableValues = ["ALL", "ID", "USERNAME", "NICKNAME", "EMAIL"], + allowableValues = ["ALL", "NAME", "TOOL_ID", "NICKNAME", "USERNAME", "KEYWORD"], defaultValue = "ALL", example = "ALL" ) @@ -47,8 +47,10 @@ data class ToolManagementGetParam( * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - @Schema(description = "审核状态过滤(多个使用逗号分隔)", + @Schema( + description = "审核状态过滤(多个使用逗号分隔)", allowableValues = ["NONE", "PROCESSING", "REJECT", "PASS"], - example = "NONE,PASS") + example = "NONE,PASS" + ) val review: String? ) : PageSortParam() diff --git a/src/main/resources/mapper/tool/ManagementMapper.xml b/src/main/resources/mapper/tool/ManagementMapper.xml index 186a5a8..a53ea79 100644 --- a/src/main/resources/mapper/tool/ManagementMapper.xml +++ b/src/main/resources/mapper/tool/ManagementMapper.xml @@ -65,12 +65,87 @@ @@ -153,7 +228,8 @@ - + From b32f062594cf587b6473a51825d434bd00fa397a Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 15 Feb 2024 23:59:21 +0800 Subject: [PATCH 194/258] Add kdoc --- .../controller/tool/ManagementController.kt | 6 ++ .../api/converter/tool/ToolConverter.kt | 12 ++++ .../api/mapper/permission/UserMapper.kt | 2 +- .../oxygen/api/mapper/tool/EditMapper.kt | 44 +++++++++++++- .../api/mapper/tool/ManagementMapper.kt | 30 ++++++++++ .../oxygen/api/mapper/tool/ToolBaseMapper.kt | 9 +++ .../api/mapper/tool/ToolTemplateMapper.kt | 17 ++++++ .../param/api/v1/avatar/AvatarGitHubParam.kt | 1 + .../api/param/permission/ForgetParam.kt | 1 + .../oxygen/api/param/permission/LoginParam.kt | 1 + .../api/param/permission/RegisterParam.kt | 1 + .../api/param/permission/RetrieveParam.kt | 1 + .../api/param/tool/ToolManagementGetParam.kt | 7 +++ .../oxygen/api/service/tool/IEditService.kt | 26 ++++++++- .../api/service/tool/IManagementService.kt | 57 +++++++++++++++++++ .../api/service/tool/impl/EditServiceImpl.kt | 4 +- src/main/resources/mapper/tool/EditMapper.xml | 4 +- 17 files changed, 215 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt index 24e2715..c518250 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/ManagementController.kt @@ -12,6 +12,12 @@ import top.fatweb.oxygen.api.service.tool.IManagementService import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo +/** + * Tool management controller + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ @BaseController(path = ["/system/tool"], name = "工具管理", description = "工具管理相关接口") class ManagementController( private val managementService: IManagementService diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt index 9d273b6..b5b378d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt @@ -43,6 +43,18 @@ object ToolConverter { updateTime = tool.updateTime ) + /** + * Convert Page object into PageVo object + * + * @param toolPage Page object + * @return PageVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Page + * @see Tool + * @see PageVo + * @see ToolVo + */ fun toolPageToToolPageVo(toolPage: Page): PageVo = PageVo( total = toolPage.total, pages = toolPage.pages, diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserMapper.kt index 1f91df6..836b217 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/permission/UserMapper.kt @@ -28,7 +28,7 @@ interface UserMapper : BaseMapper { fun selectOneWithPowerInfoByAccount(@Param("account") account: String): User? /** - * Select user in page + * Select user ID in page * * @param page Pagination * @param searchType Type of search diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt index d31a8eb..3cfca8b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt @@ -16,13 +16,53 @@ import top.fatweb.oxygen.api.entity.tool.ToolTemplate */ @Mapper interface EditMapper : BaseMapper { - fun getTemplate(@Param("id") id: Long): ToolTemplate? + /** + * Select tool template by ID + * + * @param id Template ID + * @return ToolTemplate object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplate + */ + fun selectTemplate(@Param("id") id: Long): ToolTemplate? + /** + * Select tool by ID and user ID + * + * @param id Tool ID + * @param userId User ID + * @return Tool object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tool + */ fun selectOne(@Param("id") id: Long, @Param("userId") userId: Long): Tool? + /** + * Select tool in list by User ID + * + * @param userId User ID + * @return List of tool object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tool + */ fun selectPersonal(@Param("userId") userId: Long): List - fun detail( + /** + * Select tool detail + * + * @param username Username + * @param toolId Tool ID + * @param ver Tool version + * @param operator Operator username + * @return List of tool object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tool + */ + fun selectDetail( @Param("username") username: String, @Param("toolId") toolId: String, @Param("ver") ver: String, diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt index 185bc30..f29865b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt @@ -16,8 +16,30 @@ import top.fatweb.oxygen.api.entity.tool.Tool */ @Mapper interface ManagementMapper : BaseMapper { + /** + * Select tool by ID + * + * @param id Tool ID + * @return Tool object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tool + */ fun selectOne(@Param("id") id: Long): Tool? + /** + * Select tool ID in page + * + * @param page Pagination + * @param review Review + * @param searchType Type of search + * @param searchValue Value to search for + * @param searchRegex Use regex + * @return Tool object in page + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IPage + */ fun selectPage( page: IPage, @Param("review") review: List?, @@ -26,5 +48,13 @@ interface ManagementMapper : BaseMapper { @Param("searchRegex") searchRegex: Boolean ): IPage + /** + * Select tool in list by tool IDs + * + * @param ids List of tool IDs + * @return List of tool object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ fun selectListByIds(@Param("ids") ids: List): List } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt index 51f9d82..26f470f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolBaseMapper.kt @@ -15,5 +15,14 @@ import top.fatweb.oxygen.api.entity.tool.ToolBase */ @Mapper interface ToolBaseMapper : BaseMapper { + /** + * Select tool base by ID + * + * @param id Tool base ID + * @return ToolBase object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBase + */ fun selectOne(@Param("id") id: Long): ToolBase? } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolTemplateMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolTemplateMapper.kt index a11ce86..e50c009 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolTemplateMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolTemplateMapper.kt @@ -15,7 +15,24 @@ import top.fatweb.oxygen.api.entity.tool.ToolTemplate */ @Mapper interface ToolTemplateMapper : BaseMapper { + /** + * Select tool template by ID + * + * @param id Tool template ID + * @return ToolTemplate object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplate + */ fun selectOne(@Param("id") id: Long): ToolTemplate? + /** + * Select tool template in list + * + * @return List of ToolTemplate object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolTemplate + */ fun selectList(): List } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarGitHubParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarGitHubParam.kt index 58e4908..6ea06a5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarGitHubParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/api/v1/avatar/AvatarGitHubParam.kt @@ -8,6 +8,7 @@ import jakarta.validation.constraints.Max * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see AvatarBaseParam */ data class AvatarGitHubParam( /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/ForgetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/ForgetParam.kt index e6ff4ce..de70365 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/ForgetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/ForgetParam.kt @@ -10,6 +10,7 @@ import top.fatweb.oxygen.api.param.CaptchaCodeParam * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see CaptchaCodeParam */ @Schema(description = "忘记密码请求参数") data class ForgetParam( diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt index 8112d73..df53af9 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/LoginParam.kt @@ -9,6 +9,7 @@ import top.fatweb.oxygen.api.param.CaptchaCodeParam * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see CaptchaCodeParam */ @Schema(description = "登录请求参数") data class LoginParam( diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt index 47af7de..88f017a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt @@ -11,6 +11,7 @@ import top.fatweb.oxygen.api.param.CaptchaCodeParam * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see CaptchaCodeParam */ @Schema(description = "注册请求参数") data class RegisterParam( diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt index b94a786..1b8f685 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt @@ -10,6 +10,7 @@ import top.fatweb.oxygen.api.param.CaptchaCodeParam * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see CaptchaCodeParam */ @Schema(description = "找回密码请求参数") data class RetrieveParam( diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt index 8948910..0c8fc83 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt @@ -3,6 +3,13 @@ package top.fatweb.oxygen.api.param.tool import io.swagger.v3.oas.annotations.media.Schema import top.fatweb.oxygen.api.param.PageSortParam +/** + * Get tool in management parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see PageSortParam + */ data class ToolManagementGetParam( /** * Type of search diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt index 31da2ef..3a92b4a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt @@ -52,7 +52,8 @@ interface IEditService : IService { /** * Get tool by ID * - * @param + * @param id Tool ID + * @return ToolVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ @@ -61,14 +62,20 @@ interface IEditService : IService { /** * Create tool * + * @param toolCreateParam Create tool parameters + * @return ToolVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ToolCreateParam + * @see ToolVo */ fun create(toolCreateParam: ToolCreateParam): ToolVo /** * Upgrade tool * + * @param toolUpgradeParam Upgrade tool parameters + * @return ToolVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see ToolUpgradeParam @@ -79,30 +86,43 @@ interface IEditService : IService { /** * Update tool * + * @param toolUpdateParam Update tool parameters + * @return ToolVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ToolUpdateParam + * @see ToolVo */ fun update(toolUpdateParam: ToolUpdateParam): ToolVo /** * Get personal tools * + * @return List of ToolVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ToolVo */ fun get(): List /** * Get tool detail * + * @param username Username + * @param toolId Tool ID + * @param ver Version + * @return ToolVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ToolVo */ fun detail(username: String, toolId: String, ver: String): ToolVo /** * Submit tool review * + * @param id Tool ID + * @return Result * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ @@ -111,6 +131,8 @@ interface IEditService : IService { /** * Cancel tool review * + * @param id Tool ID + * @return Result * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ @@ -119,6 +141,8 @@ interface IEditService : IService { /** * Delete tool * + * @param id Tool ID + * @return Result * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt index 8be97b4..039ad51 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt @@ -16,15 +16,72 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo * @see Tool */ interface IManagementService : IService { + /** + * Get tool by ID + * + * @param id Tool ID + * @return ToolVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolVo + */ fun getOne(id: Long): ToolVo + /** + * Get tool as page + * + * @param toolManagementGetParam Get tool parameters in tool management + * @return PageVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolManagementGetParam + * @see PageVo + * @see ToolVo + */ fun getPage(toolManagementGetParam: ToolManagementGetParam?): PageVo + /** + * Pass tool review + * + * @param id Tool ID + * @param toolManagementPassParam Pass tool review parameters in tool management + * @return ToolVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolManagementPassParam + * @see ToolVo + */ fun pass(id: Long, toolManagementPassParam: ToolManagementPassParam): ToolVo + /** + * Reject tool review + * + * @param id Tool ID + * @return ToolVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolVo + */ fun reject(id: Long): ToolVo + /** + * Off shelve tool + * + * @param id Tool ID + * @return ToolVo object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolVo + */ fun offShelve(id: Long): ToolVo + /** + * Delete tool + * + * @param id Tool ID + * @return Result + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ fun delete(id: Long): Boolean } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index af4caa3..7b2eecd 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -43,7 +43,7 @@ class EditServiceImpl( .map(ToolTemplateConverter::toolTemplateToToolTemplateVoByList) override fun getTemplate(id: Long): ToolTemplateVo = - baseMapper.getTemplate(id)?.let(ToolTemplateConverter::toolTemplateToToolTemplateVoWithBaseDist) + baseMapper.selectTemplate(id)?.let(ToolTemplateConverter::toolTemplateToToolTemplateVoWithBaseDist) ?: throw NoRecordFoundException() override fun getCategory(): List = @@ -210,7 +210,7 @@ class EditServiceImpl( if (username == "!" && WebUtil.getLoginUserId() == null) { throw NoRecordFoundException() } - val toolList = baseMapper.detail(username, toolId, ver, WebUtil.getLoginUsername()) + val toolList = baseMapper.selectDetail(username, toolId, ver, WebUtil.getLoginUsername()) if (toolList.isNullOrEmpty()) { throw NoRecordFoundException() } diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml index 910c7ea..591d72f 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -1,7 +1,7 @@ - select t_b_tool_template.id as tool_template_id, t_b_tool_template.name as tool_template_name, t_b_tool_template.base_id as tool_template_base_id, @@ -128,7 +128,7 @@ order by t_b_tool_main.id desc - select t_b_tool_main.id as tool_id, t_b_tool_main.name as tool_name, t_b_tool_main.tool_id as tool_tool_id, From c5dcb432ef391abeb0b692cbaa42e8054437bd6c Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sat, 17 Feb 2024 14:24:42 +0800 Subject: [PATCH 195/258] Add store get tool api --- .../api/controller/tool/StoreController.kt | 31 +++++++ .../api/mapper/tool/ManagementMapper.kt | 5 +- .../oxygen/api/mapper/tool/StoreMapper.kt | 41 +++++++++ .../api/param/tool/ToolManagementGetParam.kt | 2 +- .../api/param/tool/ToolManagementPassParam.kt | 2 +- .../api/param/tool/ToolStoreGetParam.kt | 16 ++++ .../api/service/tool/IManagementService.kt | 2 +- .../oxygen/api/service/tool/IStoreService.kt | 25 ++++++ .../api/service/tool/impl/StoreServiceImpl.kt | 37 +++++++++ .../resources/mapper/tool/StoreMapper.xml | 83 +++++++++++++++++++ 10 files changed, 239 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt create mode 100644 src/main/resources/mapper/tool/StoreMapper.xml diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt new file mode 100644 index 0000000..52d1daa --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/StoreController.kt @@ -0,0 +1,31 @@ +package top.fatweb.oxygen.api.controller.tool + +import jakarta.validation.Valid +import org.springframework.web.bind.annotation.GetMapping +import top.fatweb.oxygen.api.annotation.BaseController +import top.fatweb.oxygen.api.entity.common.ResponseResult +import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam +import top.fatweb.oxygen.api.service.tool.IStoreService +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool store controller + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +@BaseController(path = ["/tool/store"], name = "工具商店", description = "工具商店相关接口") +class StoreController( + private val storeService: IStoreService +) { + /** + * Get store tool in page + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @GetMapping + fun get(@Valid toolStoreGetParam: ToolStoreGetParam): ResponseResult> = + ResponseResult.databaseSuccess(data = storeService.getPage(toolStoreGetParam)) +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt index f29865b..8ef9eb7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ManagementMapper.kt @@ -7,7 +7,7 @@ import org.apache.ibatis.annotations.Param import top.fatweb.oxygen.api.entity.tool.Tool /** - * Tool mapper + * Tool management mapper * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 @@ -35,7 +35,7 @@ interface ManagementMapper : BaseMapper { * @param searchType Type of search * @param searchValue Value to search for * @param searchRegex Use regex - * @return Tool object in page + * @return Tool ID in page * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see IPage @@ -55,6 +55,7 @@ interface ManagementMapper : BaseMapper { * @return List of tool object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see Tool */ fun selectListByIds(@Param("ids") ids: List): List } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt new file mode 100644 index 0000000..ec3c0f6 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt @@ -0,0 +1,41 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import com.baomidou.mybatisplus.core.metadata.IPage +import org.apache.ibatis.annotations.Mapper +import org.apache.ibatis.annotations.Param +import top.fatweb.oxygen.api.entity.tool.Tool + +/** + * Tool store mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see Tool + */ +@Mapper +interface StoreMapper : BaseMapper { + /** + * Select tool ID in page + * + * @param page Pagination + * @param searchValue Value to search for + * @return Tool ID in page + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IPage + */ + fun selectPage(page: IPage, @Param("searchValue") searchValue: String?): IPage + + /** + * Select tool in list by tool IDs + * + * @param ids List of tool IDs + * @return List of tool object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tool + */ + fun selectListByIds(@Param("ids") ids: List): List +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt index 0c8fc83..dd58600 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementGetParam.kt @@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema import top.fatweb.oxygen.api.param.PageSortParam /** - * Get tool in management parameters + * Get tool parameters in tool management * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt index 33460d4..bf993c1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolManagementPassParam.kt @@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank /** - * Pass tool in management parameters + * Pass tool parameters in tool management * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt new file mode 100644 index 0000000..a83ae41 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt @@ -0,0 +1,16 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import top.fatweb.oxygen.api.param.PageSortParam + +/** + * Get tool parameters in tool store + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see PageSortParam + */ +data class ToolStoreGetParam( + @Schema(description = "查询内容", example = "ToolName") + val searchValue: String? +) : PageSortParam() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt index 039ad51..2ec08a7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IManagementService.kt @@ -28,7 +28,7 @@ interface IManagementService : IService { fun getOne(id: Long): ToolVo /** - * Get tool as page + * Get tool in page * * @param toolManagementGetParam Get tool parameters in tool management * @return PageVo object diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt new file mode 100644 index 0000000..4ef68cd --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt @@ -0,0 +1,25 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool store service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see Tool + */ +interface IStoreService : IService { + /** + * Get tool in page + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt new file mode 100644 index 0000000..e1ba2f0 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt @@ -0,0 +1,37 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.oxygen.api.converter.tool.ToolConverter +import top.fatweb.oxygen.api.entity.tool.Tool +import top.fatweb.oxygen.api.mapper.tool.StoreMapper +import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam +import top.fatweb.oxygen.api.service.tool.IStoreService +import top.fatweb.oxygen.api.vo.PageVo +import top.fatweb.oxygen.api.vo.tool.ToolVo + +/** + * Tool store service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see StoreMapper + * @see Tool + * @see IStoreService + */ +@Service +class StoreServiceImpl : ServiceImpl(), IStoreService { + override fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo { + val toolIdsPage = Page(toolStoreGetParam?.currentPage ?: 1, 20) + + val toolIdsIPage = baseMapper.selectPage(toolIdsPage, toolStoreGetParam?.searchValue) + val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) + if (toolIdsIPage.total > 0) { + toolPage.setRecords(baseMapper.selectListByIds(toolIdsIPage.records)) + } + + return ToolConverter.toolPageToToolPageVo(toolPage) + } +} \ No newline at end of file diff --git a/src/main/resources/mapper/tool/StoreMapper.xml b/src/main/resources/mapper/tool/StoreMapper.xml new file mode 100644 index 0000000..6f5f2c9 --- /dev/null +++ b/src/main/resources/mapper/tool/StoreMapper.xml @@ -0,0 +1,83 @@ + + + + + + + \ No newline at end of file From 0baccbd0e5e5da3ce47dd4e204ff355c8b69ae94 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 18 Feb 2024 17:39:12 +0800 Subject: [PATCH 196/258] Optimize tools api --- .../oxygen/api/config/SecurityConfig.kt | 2 +- .../api/service/tool/impl/EditServiceImpl.kt | 4 +-- .../tool/impl/ManagementServiceImpl.kt | 1 - .../resources/mapper/tool/StoreMapper.xml | 27 ++++++++++++------- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt index 3c0059b..c4b8679 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/SecurityConfig.kt @@ -79,7 +79,7 @@ class SecurityConfig( "/forget", "/retrieve" ).anonymous() - .requestMatchers("/tool/detail/**").permitAll() + .requestMatchers("/tool/detail/**", "/tool/store").permitAll() // Authentication required .anyRequest().authenticated() } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index 7b2eecd..ab8268c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -223,7 +223,7 @@ class EditServiceImpl( if (tool.review == Tool.ReviewType.PROCESSING) { throw ToolUnderReviewException() } - if (tool.review == Tool.ReviewType.PASS || tool.publish != 0L) { + if (tool.review == Tool.ReviewType.PASS && tool.publish != 0L) { throw ToolHasBeenPublishedException() } @@ -232,7 +232,7 @@ class EditServiceImpl( override fun cancel(id: Long): Boolean { val tool = getById(id) - if (tool.review == Tool.ReviewType.PASS || tool.publish != 0L) { + if (tool.review == Tool.ReviewType.PASS && tool.publish != 0L) { throw ToolHasBeenPublishedException() } if (tool.review != Tool.ReviewType.PROCESSING) { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt index 9e6ed3e..e5180b1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt @@ -111,7 +111,6 @@ class ManagementServiceImpl( KtUpdateWrapper(Tool()) .eq(Tool::id, id) .set(Tool::review, Tool.ReviewType.REJECT) - .set(Tool::publish, 0) ) return this.getOne(id) diff --git a/src/main/resources/mapper/tool/StoreMapper.xml b/src/main/resources/mapper/tool/StoreMapper.xml index 6f5f2c9..93192fa 100644 --- a/src/main/resources/mapper/tool/StoreMapper.xml +++ b/src/main/resources/mapper/tool/StoreMapper.xml @@ -2,31 +2,40 @@ + + + + select t_s_user.id as user_id, t_s_user.username as user_username, + t_s_user.two_factor as user_two_factor, t_s_user.verify as user_verify, t_s_user.forget as user_forget, t_s_user.locking as user_locking, @@ -196,6 +198,7 @@ - + select t_b_tool_template.id as tool_template_id, + t_b_tool_template.name as tool_template_name, + t_b_tool_template.base_id as tool_template_base_id, + t_b_tool_template.source_id as tool_template_source_id, + t_b_tool_template.platform as tool_template_platform, + t_b_tool_template.entry_point as tool_template_entry_point, + t_b_tool_template.enable as tool_template_enable, + t_b_tool_template.create_time as tool_template_create_time, + t_b_tool_template.update_time as tool_template_update_time, + t_b_tool_template.deleted as tool_template_deleted, + t_b_tool_template.version as tool_template_version, + tbtb.name as tool_template_base_name from t_b_tool_template - left join (select * from t_b_tool_base where deleted = 0) as tbtb - on tbtb.id = t_b_tool_template.base_id - where t_b_tool_template.deleted = 0 + left join (select * from t_b_tool_base where deleted = 0) as tbtb + on tbtb.id = t_b_tool_template.base_id + + and t_b_tool_template.deleted = 0 + + #{item} + + @@ -50,6 +58,7 @@ + From 17bf4146e11ce76865623b3c206386b7aa91d9fc Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 19 Mar 2024 18:38:19 +0800 Subject: [PATCH 217/258] Feat: store - support multiple platforms --- .../oxygen/api/mapper/tool/StoreMapper.kt | 19 ++- .../api/service/tool/impl/StoreServiceImpl.kt | 8 +- .../resources/mapper/tool/StoreMapper.xml | 160 ++++++++++++------ 3 files changed, 129 insertions(+), 58 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt index 96da5e0..78e6449 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt @@ -17,16 +17,16 @@ import top.fatweb.oxygen.api.entity.tool.Tool @Mapper interface StoreMapper : BaseMapper { /** - * Select tool ID in page + * Select author and tool ID in page * * @param page Pagination * @param searchValue Value to search for - * @return Tool ID in page + * @return Author:Tool_ID in page * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see IPage */ - fun selectPage(page: IPage, @Param("searchValue") searchValue: String?): IPage + fun selectAuthorToolIdPage(page: IPage, @Param("searchValue") searchValue: String?): IPage /** * Select tool ID by username in page @@ -38,7 +38,7 @@ interface StoreMapper : BaseMapper { * @since 1.0.0 * @see IPage */ - fun selectPageByUsername(page: IPage, @Param("username") username: String): IPage + fun selectAuthorToolIdPageByUsername(page: IPage, @Param("username") username: String): IPage /** * Select tool in list by tool IDs @@ -50,4 +50,15 @@ interface StoreMapper : BaseMapper { * @see Tool */ fun selectListByIds(@Param("ids") ids: List): List + + /** + * Select tool in list by Author:Tool_ID + * + * @param ids List of Author:Tool_ID + * @return List of tool object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Tool + */ + fun selectListByAuthorToolIds(@Param("ids") ids: List): List } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt index a59d487..7139e56 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt @@ -28,10 +28,10 @@ class StoreServiceImpl : ServiceImpl(), IStoreService { val toolIdsPage = Page(toolStoreGetParam?.currentPage ?: 1, 20) toolIdsPage.setOptimizeCountSql(false) - val toolIdsIPage = baseMapper.selectPage(toolIdsPage, toolStoreGetParam?.searchValue) + val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam?.searchValue) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { - toolPage.setRecords(baseMapper.selectListByIds(toolIdsIPage.records)) + toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records)) } return ToolConverter.toolPageToToolPageVo(toolPage) @@ -41,10 +41,10 @@ class StoreServiceImpl : ServiceImpl(), IStoreService { val toolIdsPage = Page(pageSortParam.currentPage, 20) toolIdsPage.setOptimizeCountSql(false) - val toolIdsIPage = baseMapper.selectPageByUsername(toolIdsPage, username) + val toolIdsIPage = baseMapper.selectAuthorToolIdPageByUsername(toolIdsPage, username) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { - toolPage.setRecords(baseMapper.selectListByIds(toolIdsIPage.records)) + toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records)) } return ToolConverter.toolPageToToolPageVo(toolPage) diff --git a/src/main/resources/mapper/tool/StoreMapper.xml b/src/main/resources/mapper/tool/StoreMapper.xml index ef002f7..f4b4e02 100644 --- a/src/main/resources/mapper/tool/StoreMapper.xml +++ b/src/main/resources/mapper/tool/StoreMapper.xml @@ -1,58 +1,60 @@ - + select concat(temp2.author_id, ':', temp2.tool_id) + from (select temp1.tool_id, temp1.author_id, row_number() over (partition by temp1.tool_id, temp1.author_id) as rn2 + from (select temp0.* + from (select *, row_number() over (partition by t_b_tool_main.tool_id, t_b_tool_main.author_id order by t_b_tool_main.id desc) as rn1 + from t_b_tool_main + where t_b_tool_main.deleted = 0 + ) as temp0 + where temp0.rn1 = 1 + ) as temp1 + left join json_table(json_extract(temp1.keywords, '$[*]'), '$[*]' columns (keyword varchar(50) path '$')) as tk on true + + and temp1.publish != 0 and temp1.review = 'PASS' + + and ( + temp1.name like concat('%', #{searchValue}, '%') + or tk.keyword like concat('%', #{searchValue}, '%') + ) + + + + + order by instr(temp1.name, #{searchValue}) = 0, + char_length(temp1.name), + instr(temp1.name, #{searchValue}), + instr(tk.keyword, #{searchValue}) = 0, + char_length(tk.keyword), + instr(tk.keyword, #{searchValue}) + + + order by temp1.publish desc + + + ) as temp2 + where temp2.rn2 = 1 - + select concat(temp2.author_id, ':', temp2.tool_id) + from (select temp1.tool_id, temp1.author_id, row_number() over (partition by temp1.tool_id, temp1.author_id) as rn2 + from (select temp0.* + from (select *, row_number() over (partition by t_b_tool_main.tool_id, t_b_tool_main.author_id order by t_b_tool_main.id desc) as rn1 + from t_b_tool_main + where t_b_tool_main.deleted = 0 + ) as temp0 + where temp0.rn1 = 1 + ) as temp1 + left join (select * from t_s_user where deleted = 0) as tsu on tsu.id = temp1.author_id + where temp1.publish != 0 + and temp1.review = 'PASS' + and tsu.username = #{username} + order by temp1.publish desc + ) as temp2 + where temp2.rn2 = 1 + + \ No newline at end of file From 0e41d8c31091498155d76c9a7cf16b9d2ef93d21 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 21 Mar 2024 16:01:40 +0800 Subject: [PATCH 218/258] Fix: create - can not upgrade tool bug --- .../top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index 3956347..344a198 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -130,6 +130,7 @@ class EditServiceImpl( name = originalTool.name!! toolId = originalTool.toolId icon = originalTool.icon + platform = originalTool.platform description = originalTool.description baseId = originalTool.base!!.id authorId = WebUtil.getLoginUserId()!! From 2d2a6641fb516a141e8698f21eef3202e0d44749 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 26 Mar 2024 11:18:33 +0800 Subject: [PATCH 219/258] Optimize: parameters - optimize verification --- .../top/fatweb/oxygen/api/controller/tool/BaseController.kt | 1 - .../top/fatweb/oxygen/api/controller/tool/EditController.kt | 1 - .../top/fatweb/oxygen/api/param/permission/RegisterParam.kt | 2 +- .../top/fatweb/oxygen/api/param/permission/RetrieveParam.kt | 2 +- .../top/fatweb/oxygen/api/param/permission/VerifyParam.kt | 4 ++-- .../api/param/permission/user/UserChangePasswordParam.kt | 2 +- .../oxygen/api/param/permission/user/UserInfoUpdateParam.kt | 2 +- .../top/fatweb/oxygen/api/param/system/MailSendParam.kt | 2 +- src/main/resources/application-config-template.yml | 3 --- 9 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt index 5f607bf..8741981 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/BaseController.kt @@ -8,7 +8,6 @@ import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.annotation.Trim import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult -import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.ToolBaseAddParam import top.fatweb.oxygen.api.param.tool.ToolBaseGetParam import top.fatweb.oxygen.api.param.tool.ToolBaseUpdateParam diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index 41aaed9..c805d84 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -2,7 +2,6 @@ package top.fatweb.oxygen.api.controller.tool import io.swagger.v3.oas.annotations.Operation import jakarta.validation.Valid -import jakarta.validation.constraints.NotNull import org.springframework.web.bind.annotation.* import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.annotation.Trim diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt index 3280d1f..59bf97d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RegisterParam.kt @@ -49,6 +49,6 @@ data class RegisterParam( */ @Schema(description = "密码", required = true) @field:NotBlank(message = "Password can not be blank") - @field:Size(min = 10, max = 30, message = "Password must be 10-20 characters") + @field:Size(min = 10, max = 30, message = "Password must be 10-30 characters") val password: String? ) : CaptchaCodeParam() \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt index 1b8f685..5163e5f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/RetrieveParam.kt @@ -32,6 +32,6 @@ data class RetrieveParam( */ @Schema(description = "新密码") @field:NotBlank(message = "New password can not be blank") - @field:Size(min = 10, max = 30) + @field:Size(min = 10, max = 30, message = "New password must be 10-30 characters") val password: String? ) : CaptchaCodeParam() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/VerifyParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/VerifyParam.kt index a9be0c0..ebe1cd3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/VerifyParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/VerifyParam.kt @@ -2,7 +2,7 @@ package top.fatweb.oxygen.api.param.permission import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank -import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size import top.fatweb.oxygen.api.annotation.Trim /** @@ -32,7 +32,7 @@ data class VerifyParam( */ @Trim @Schema(description = "昵称", example = "QwQ") - @field:Pattern(regexp = "^.{3,20}$", message = "Nickname must be 3-20 characters") + @field:Size(min = 3, max = 20, message = "Nickname must be 3-20 characters") var nickname: String?, /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserChangePasswordParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserChangePasswordParam.kt index 7e704e6..094c3b5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserChangePasswordParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserChangePasswordParam.kt @@ -30,6 +30,6 @@ data class UserChangePasswordParam( */ @Schema(description = "原密码", required = true) @field:NotBlank(message = "New password can not be blank") - @field:Size(min = 10, max = 30, message = "New password must be 10-20 characters") + @field:Size(min = 10, max = 30, message = "New password must be 10-30 characters") val newPassword: String? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserInfoUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserInfoUpdateParam.kt index 4aae0a9..7928cf6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserInfoUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/permission/user/UserInfoUpdateParam.kt @@ -32,6 +32,6 @@ data class UserInfoUpdateParam( @Trim @Schema(description = "昵称", example = "QwQ") @field:NotBlank(message = "Nickname can not be blank") - @field:Size(min = 3, max = 30, message = "Nickname must be 3-20 characters") + @field:Size(min = 3, max = 20, message = "Nickname must be 3-20 characters") var nickname: String? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSendParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSendParam.kt index 842c49a..bdbdde1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSendParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSendParam.kt @@ -21,6 +21,6 @@ data class MailSendParam( */ @Trim @Schema(description = "接收者", required = true, example = "user@email.com") - @field:NotBlank + @field:NotBlank(message = "Receiver cannot be blank") var to: String? ) diff --git a/src/main/resources/application-config-template.yml b/src/main/resources/application-config-template.yml index d42e842..6747dbc 100644 --- a/src/main/resources/application-config-template.yml +++ b/src/main/resources/application-config-template.yml @@ -62,8 +62,5 @@ logging: # max-file-size: 10MB # Maximum log file size # max-history: 7 # Maximum number of archive log files to keep -mybatis-plus: - type-aliases-package: top.fatweb.oxygen.api.entity - knife4j: production: true # Production environment mode will block doc \ No newline at end of file From 555877770d4720c4c3f6436e603732e7d22a374a Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 26 Mar 2024 14:19:01 +0800 Subject: [PATCH 220/258] Fix: IP - real IP address cannot be obtained when using reverse proxy bug --- .../oxygen/api/aop/SysLogInterceptor.kt | 2 +- .../impl/AuthenticationServiceImpl.kt | 8 +++--- .../top/fatweb/oxygen/api/util/WebUtil.kt | 27 +++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/aop/SysLogInterceptor.kt b/src/main/kotlin/top/fatweb/oxygen/api/aop/SysLogInterceptor.kt index c6f41e9..5c8a27c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/aop/SysLogInterceptor.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/aop/SysLogInterceptor.kt @@ -49,7 +49,7 @@ class SysLogInterceptor( requestUri = URI(request.requestURI).path requestParams = formatParams(request.parameterMap) requestMethod = request.method - requestIp = request.remoteAddr + requestIp = WebUtil.getRequestIp(request) requestServerAddress = "${request.scheme}://${request.serverName}:${request.serverPort}" userAgent = request.getHeader("User-Agent") } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt index 1143cc1..afdbb73 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/AuthenticationServiceImpl.kt @@ -165,7 +165,7 @@ class AuthenticationServiceImpl( LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli() }-${UUID.randomUUID()}-${UUID.randomUUID()}-${UUID.randomUUID()}" userService.update(KtUpdateWrapper(User()).eq(User::id, user.id).set(User::forget, code)) - sendRetrieveMail(user.username!!, request.remoteAddr, code, forgetParam.email!!) + sendRetrieveMail(user.username!!, WebUtil.getRequestIp(request), code, forgetParam.email!!) } @Transactional @@ -197,7 +197,7 @@ class AuthenticationServiceImpl( WebUtil.offlineUser(redisUtil, user.id!!) - sendPasswordChangedMail(user.username!!, request.remoteAddr, userInfo!!.email!!) + sendPasswordChangedMail(user.username!!, WebUtil.getRequestIp(request), userInfo!!.email!!) } @EventLogRecord(EventLog.Event.LOGIN) @@ -377,9 +377,9 @@ class AuthenticationServiceImpl( } } - logger.info("用户登录 [用户名: '{}', IP: '{}']", loginUser.username, request.remoteAddr) + logger.info("用户登录 [用户名: '{}', IP: '{}']", loginUser.username, WebUtil.getRequestIp(request)) userService.update(User().apply { - currentLoginIp = request.remoteAddr + currentLoginIp = WebUtil.getRequestIp(request) currentLoginTime = LocalDateTime.now(ZoneOffset.UTC) lastLoginIp = loginUser.user.currentLoginIp lastLoginTime = loginUser.user.currentLoginTime diff --git a/src/main/kotlin/top/fatweb/oxygen/api/util/WebUtil.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/WebUtil.kt index 4e0838c..6e3ad46 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/util/WebUtil.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/WebUtil.kt @@ -76,4 +76,31 @@ object WebUtil { redisUtil.delObject(keys) } + + /** + * Get real request IP + * + * @param request HttpServletRequest object + * @return IP address + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see HttpServletRequest + */ + fun getRequestIp(request: HttpServletRequest): String { + var ip = request.getHeader("X-Real-IP") + if (!ip.isNullOrBlank() && !"unknown".equals(ip, true)) { + return ip + } + ip = request.getHeader("X-Forwarded-For") + return if (!ip.isNullOrBlank() && !"unknown".equals(ip, true)) { + val index = ip.indexOf(",") + if (index != -1) { + ip.substring(0, index) + } else { + ip + } + } else { + request.remoteAddr + } + } } \ No newline at end of file From fcfd76d60cb4f9e6629465bfca07d529a5c8896d Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 22 Apr 2024 00:14:34 +0800 Subject: [PATCH 221/258] Fix(Tool): Fix bug in tool update version number verification Fix bug in tool update version number verification --- .../api/service/tool/impl/EditServiceImpl.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index 344a198..44165cb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -111,16 +111,16 @@ class EditServiceImpl( } val originalVersion = originalTool.ver!! - if (originalVersion.split(".").map(String::toLong).joinToString(".") == toolUpgradeParam.ver!!.split(".") - .map(String::toLong).joinToString(".") - ) { + val originalVersionNumberList = originalVersion.split(".").map(String::toLong) + val newVersionNumberList = toolUpgradeParam.ver!!.split(".").map(String::toLong) + if (!newVersionNumberList.foldIndexed(false) { index: Int, acc: Boolean, version: Long -> + if (!acc && originalVersionNumberList[index] > version) { + throw IllegalVersionException() + } + if (originalVersionNumberList[index] < version) true else acc + }) { throw IllegalVersionException() } - originalVersion.split(".").forEachIndexed { index, s -> - if ((toolUpgradeParam.ver.split(".")[index].toLong() < s.toLong())) { - throw IllegalVersionException() - } - } val newSource = ToolData().apply { data = originalTool.source!!.data } val newDist = ToolData().apply { data = "" } @@ -134,7 +134,7 @@ class EditServiceImpl( description = originalTool.description baseId = originalTool.base!!.id authorId = WebUtil.getLoginUserId()!! - ver = toolUpgradeParam.ver.split(".").map(String::toLong).joinToString(".") + ver = newVersionNumberList.joinToString(".") keywords = originalTool.keywords sourceId = newSource.id distId = newDist.id From a0812b4f11a8b63a0992a9ec6c5c40c968759c56 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 22 Apr 2024 00:17:48 +0800 Subject: [PATCH 222/258] Refactor(UserService): Change wrong method name Change method getIdsWithRoleIds to getIdsByRoleIds, and change method getIdsWithGroupIds to getIdsByGroupIds --- .../top/fatweb/oxygen/api/service/permission/IUserService.kt | 4 ++-- .../oxygen/api/service/permission/impl/GroupServiceImpl.kt | 2 +- .../oxygen/api/service/permission/impl/RoleServiceImpl.kt | 2 +- .../oxygen/api/service/permission/impl/UserServiceImpl.kt | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt index 06351d7..f7b2475 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/IUserService.kt @@ -161,7 +161,7 @@ interface IUserService : IService { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - fun getIdsWithRoleIds(roleIds: List): List + fun getIdsByRoleIds(roleIds: List): List /** * Get user IDs list by list of group IDs @@ -171,5 +171,5 @@ interface IUserService : IService { * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 */ - fun getIdsWithGroupIds(groupIds: List): List + fun getIdsByGroupIds(groupIds: List): List } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt index 416bc65..5a61ce4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/GroupServiceImpl.kt @@ -148,7 +148,7 @@ class GroupServiceImpl( } private fun offlineUser(vararg groupIds: Long) { - val userIds = userService.getIdsWithGroupIds(groupIds.toList()) + val userIds = userService.getIdsByGroupIds(groupIds.toList()) WebUtil.offlineUser(redisUtil, *userIds.toLongArray()) } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt index 4fb6636..dc40da1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/RoleServiceImpl.kt @@ -181,7 +181,7 @@ class RoleServiceImpl( } private fun offlineUser(vararg roleIds: Long) { - val userIds = userService.getIdsWithRoleIds(roleIds.toList()) + val userIds = userService.getIdsByRoleIds(roleIds.toList()) WebUtil.offlineUser(redisUtil, *userIds.toLongArray()) } } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt index 64375b3..059b22c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt @@ -323,7 +323,7 @@ class UserServiceImpl( WebUtil.offlineUser(redisUtil, *ids.toLongArray()) } - override fun getIdsWithRoleIds(roleIds: List) = baseMapper.selectIdsWithRoleIds(roleIds) + override fun getIdsByRoleIds(roleIds: List) = baseMapper.selectIdsWithRoleIds(roleIds) - override fun getIdsWithGroupIds(groupIds: List) = baseMapper.selectIdsWithGroupIds(groupIds) + override fun getIdsByGroupIds(groupIds: List) = baseMapper.selectIdsWithGroupIds(groupIds) } From cebe809504adad3cbfa43a5037e8606415cc0b49 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 22 Apr 2024 00:18:35 +0800 Subject: [PATCH 223/258] Style(Code): Format code --- .../oxygen/api/config/DateFormatConfig.kt | 9 +++---- .../fatweb/oxygen/api/config/FilterConfig.kt | 12 ++++------ .../fatweb/oxygen/api/config/JacksonConfig.kt | 17 +++++++------ .../oxygen/api/config/MybatisPlusConfig.kt | 12 ++++------ .../fatweb/oxygen/api/config/RedisConfig.kt | 4 ++-- .../service/api/v1/impl/AvatarServiceImpl.kt | 24 +++++++++---------- .../system/impl/SettingsServiceImpl.kt | 2 +- .../util/ApiResponseMappingHandlerMapping.kt | 8 ++----- .../top/fatweb/oxygen/api/util/WebUtil.kt | 5 ++-- 9 files changed, 41 insertions(+), 52 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/config/DateFormatConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/DateFormatConfig.kt index 2e908a8..a2ff193 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/config/DateFormatConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/DateFormatConfig.kt @@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Value import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer import org.springframework.boot.jackson.JsonComponent import org.springframework.context.annotation.Bean -import java.text.DateFormat import java.text.SimpleDateFormat import java.time.LocalDateTime import java.time.format.DateTimeFormatter @@ -41,11 +40,10 @@ class DateFormatConfig { @Bean fun jackson2ObjectMapperBuilder() = Jackson2ObjectMapperBuilderCustomizer { - val tz = timeZone - val df: DateFormat = SimpleDateFormat(dateFormat) - df.timeZone = tz + val dateFormat = SimpleDateFormat(dateFormat) + dateFormat.timeZone = timeZone it.failOnEmptyBeans(false).failOnUnknownProperties(false) - .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).dateFormat(df) + .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).dateFormat(dateFormat) } @Bean @@ -55,5 +53,4 @@ class DateFormatConfig { LocalDateTime::class.java, LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateFormat)) ) } - } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/config/FilterConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/FilterConfig.kt index 7b1883b..54d659e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/config/FilterConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/FilterConfig.kt @@ -14,11 +14,9 @@ import top.fatweb.oxygen.api.filter.ExceptionFilter @Configuration class FilterConfig { @Bean - fun exceptionFilterRegistrationBean(exceptionFilter: ExceptionFilter): FilterRegistrationBean { - val registrationBean = FilterRegistrationBean(exceptionFilter) - registrationBean.setBeanName("exceptionFilter") - registrationBean.order = -100 - - return registrationBean - } + fun exceptionFilterRegistrationBean(exceptionFilter: ExceptionFilter): FilterRegistrationBean = + FilterRegistrationBean(exceptionFilter).apply { + setBeanName("exceptionFilter") + order = -100 + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/config/JacksonConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/JacksonConfig.kt index b3518e0..795435d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/config/JacksonConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/JacksonConfig.kt @@ -16,13 +16,12 @@ import retrofit2.converter.jackson.JacksonConverterFactory @Configuration class JacksonConfig { @Bean - fun jacksonConverterFactory(): JacksonConverterFactory { - val mapper = JsonMapper.builder() - .findAndAddModules() - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .serializationInclusion(JsonInclude.Include.NON_NULL) - .build() - - return JacksonConverterFactory.create(mapper) - } + fun jacksonConverterFactory(): JacksonConverterFactory = + JacksonConverterFactory.create( + JsonMapper.builder() + .findAndAddModules() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .serializationInclusion(JsonInclude.Include.NON_NULL) + .build() + ) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/config/MybatisPlusConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/MybatisPlusConfig.kt index 9d36fe0..0d163bd 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/config/MybatisPlusConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/MybatisPlusConfig.kt @@ -15,11 +15,9 @@ import org.springframework.context.annotation.Configuration @Configuration class MybatisPlusConfig { @Bean - fun mybatisPlusInterceptor(): MybatisPlusInterceptor { - val mybatisPlusInterceptor = MybatisPlusInterceptor() - mybatisPlusInterceptor.addInnerInterceptor(OptimisticLockerInnerInterceptor()) - mybatisPlusInterceptor.addInnerInterceptor(PaginationInnerInterceptor()) - - return mybatisPlusInterceptor - } + fun mybatisPlusInterceptor(): MybatisPlusInterceptor = + MybatisPlusInterceptor().apply { + addInnerInterceptor(OptimisticLockerInnerInterceptor()) + addInnerInterceptor(PaginationInnerInterceptor()) + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/config/RedisConfig.kt b/src/main/kotlin/top/fatweb/oxygen/api/config/RedisConfig.kt index b22b12f..a28eacb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/config/RedisConfig.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/config/RedisConfig.kt @@ -33,11 +33,11 @@ class RedisConfig { } val anyJackson2JsonRedisSerializer = Jackson2JsonRedisSerializer(objectMapper, Any::class.java) - // 使用StringRedisSerializer来序列化和反序列化redis的key值 + // Use String Redis Serializer to serialize and deserialize redis key values redisTemplate.keySerializer = stringRedisSerializer redisTemplate.valueSerializer = anyJackson2JsonRedisSerializer - // Hash的key也采用StringRedisSerializer的序列化方式 + // The Hash key also uses the String Redis Serializer serialization method. redisTemplate.hashKeySerializer = stringRedisSerializer redisTemplate.hashValueSerializer = anyJackson2JsonRedisSerializer diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt index 630d46b..ddb2de5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/api/v1/impl/AvatarServiceImpl.kt @@ -56,12 +56,12 @@ class AvatarServiceImpl : IAvatarService { override fun triangle(avatarBaseParam: AvatarBaseParam?): ByteArray { val avatar = ( - if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty()) - TriangleAvatar.newAvatarBuilder() - else TriangleAvatar.newAvatarBuilder( - *avatarBaseParam.colors!!.map(::decodeColor).toTypedArray() - ) - ).apply { + if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty()) + TriangleAvatar.newAvatarBuilder() + else TriangleAvatar.newAvatarBuilder( + *avatarBaseParam.colors!!.map(::decodeColor).toTypedArray() + ) + ).apply { avatarBaseParam?.size?.let(::size) avatarBaseParam?.margin?.let(::margin) avatarBaseParam?.padding?.let(::padding) @@ -76,12 +76,12 @@ class AvatarServiceImpl : IAvatarService { override fun square(avatarBaseParam: AvatarBaseParam?): ByteArray { val avatar = ( - if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty()) - SquareAvatar.newAvatarBuilder() - else SquareAvatar.newAvatarBuilder( - *avatarBaseParam.colors!!.map(::decodeColor).toTypedArray() - ) - ).apply { + if (avatarBaseParam == null || avatarBaseParam.colors.isNullOrEmpty()) + SquareAvatar.newAvatarBuilder() + else SquareAvatar.newAvatarBuilder( + *avatarBaseParam.colors!!.map(::decodeColor).toTypedArray() + ) + ).apply { avatarBaseParam?.size?.let(::size) avatarBaseParam?.margin?.let(::margin) avatarBaseParam?.padding?.let(::padding) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt index 556cc2a..46b02d0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SettingsServiceImpl.kt @@ -35,7 +35,7 @@ class SettingsServiceImpl : ISettingsService { ), retrieveUrl = SettingsOperator.getAppValue( BaseSettings::retrieveUrl, - "http://localhost/retrieve?code=\${retrieveCode}" + "http://localhost/forget?code=\${retrieveCode}" ) ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/util/ApiResponseMappingHandlerMapping.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/ApiResponseMappingHandlerMapping.kt index 7d10d7e..62afabf 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/util/ApiResponseMappingHandlerMapping.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/ApiResponseMappingHandlerMapping.kt @@ -13,12 +13,8 @@ import java.lang.reflect.Method */ class ApiResponseMappingHandlerMapping : RequestMappingHandlerMapping() { - private fun createCondition(clazz: Class<*>): RequestCondition? { - val apiController = clazz.getAnnotation(ApiController::class.java) - apiController ?: return null - - return ApiVersionCondition(apiController.version) - } + private fun createCondition(clazz: Class<*>): RequestCondition? = + clazz.getAnnotation(ApiController::class.java)?.version?.let { ApiVersionCondition(it) } override fun getCustomMethodCondition(method: Method): RequestCondition<*>? = createCondition(method.javaClass) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/util/WebUtil.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/WebUtil.kt index 6e3ad46..103e536 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/util/WebUtil.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/WebUtil.kt @@ -20,8 +20,9 @@ object WebUtil { * @since 1.0.0 * @see LoginUser */ - fun getLoginUser(): LoginUser? = if (SecurityContextHolder.getContext().authentication.principal is String) null - else SecurityContextHolder.getContext().authentication.principal as LoginUser + fun getLoginUser(): LoginUser? = + if (SecurityContextHolder.getContext().authentication.principal is String) null + else SecurityContextHolder.getContext().authentication.principal as LoginUser /** * Get ID of the user currently calling api From ff0c31d26381af1632a1ee974b2d11e2dcab8906 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 22 Apr 2024 11:54:35 +0800 Subject: [PATCH 224/258] Docs(Graph): Update Update database and permission --- doc/database.drawio | 1225 ++++++++++++++++++++++++++++++++++++++--- doc/permission.drawio | 483 +++++++++++----- 2 files changed, 1488 insertions(+), 220 deletions(-) diff --git a/doc/database.drawio b/doc/database.drawio index 007b0d0..1106267 100644 --- a/doc/database.drawio +++ b/doc/database.drawio @@ -1,11 +1,11 @@ - + - + - + @@ -46,9 +46,22 @@ - + + + + + + + + + + + + + + @@ -60,7 +73,7 @@ - + @@ -73,7 +86,7 @@ - + @@ -86,7 +99,7 @@ - + @@ -99,7 +112,7 @@ - + @@ -112,7 +125,7 @@ - + @@ -125,7 +138,7 @@ - + @@ -138,7 +151,7 @@ - + @@ -151,7 +164,7 @@ - + @@ -164,7 +177,7 @@ - + @@ -177,7 +190,7 @@ - + @@ -190,7 +203,7 @@ - + @@ -203,7 +216,7 @@ - + @@ -232,7 +245,7 @@ - + @@ -261,7 +274,7 @@ - + @@ -329,7 +342,7 @@ - + @@ -384,7 +397,7 @@ - + @@ -413,7 +426,7 @@ - + @@ -468,7 +481,7 @@ - + @@ -578,7 +591,7 @@ - + @@ -646,7 +659,7 @@ - + @@ -730,7 +743,7 @@ - + @@ -745,21 +758,8 @@ - - - - - - - - - - - - - - + @@ -771,6 +771,19 @@ + + + + + + + + + + + + + @@ -867,71 +880,71 @@ - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - + - - + + + + + - + - + - - - - - - + + + @@ -939,7 +952,7 @@ - + @@ -948,7 +961,7 @@ - + @@ -976,6 +989,1084 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/permission.drawio b/doc/permission.drawio index f2f17a0..2ca4a6e 100644 --- a/doc/permission.drawio +++ b/doc/permission.drawio @@ -1,341 +1,518 @@ - + - + - + - + - + - + - + - + - + - - + + - + - - - - + - + + + + - + - + - + - + - + + + + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - - - - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 1083b8aa946757a4bdcd8ace04538bd5f9e932ff Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 22 Apr 2024 13:30:03 +0800 Subject: [PATCH 225/258] Refactor(Database): Update database Update database unique key and format SQL --- .../master/V1_0_0_231019__Add_table_'t_s_user'.sql | 13 ++++++------- ...1_0_0_240103__Add_table_‘t_s_sensitive_word'.sql | 10 +++++----- ...V1_0_0_240116__Add_table_'t_b_tool_category'.sql | 2 +- ...V1_0_0_240119__Add_table_'t_b_tool_template'.sql | 2 +- .../V1_0_0_240120__Add_table_'t_b_tool_base'.sql | 4 ++-- .../V1_0_0_231212__Add_table_'t_l_sys_log'.sql | 12 ++++++------ ...1_0_0_231214__Add_table_'t_l_statistics_log'.sql | 2 +- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_s_user'.sql b/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_s_user'.sql index 4526913..490aa4a 100644 --- a/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_s_user'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_231019__Add_table_'t_s_user'.sql @@ -9,19 +9,18 @@ create table if not exists t_s_user verify varchar(144) null comment '验证邮箱', forget varchar(144) null comment '忘记密码', locking int not null comment '锁定', - expiration datetime comment '过期时间', - credentials_expiration datetime comment '认证过期时间', + expiration datetime null comment '过期时间', + credentials_expiration datetime null comment '认证过期时间', enable int not null comment '启用', - current_login_time datetime comment '当前登录时间', - current_login_ip varchar(128) comment '当前登录 IP', - last_login_time datetime comment '上次登录时间', - last_login_ip varchar(128) comment '上次登录 IP', + current_login_time datetime null comment '当前登录时间', + current_login_ip varchar(128) null comment '当前登录 IP', + last_login_time datetime null comment '上次登录时间', + last_login_ip varchar(128) null comment '上次登录 IP', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', deleted bigint not null default 0, version int not null default 0, constraint t_s_user_unique_username unique (username, deleted), - constraint t_s_user_unique_two_factor unique (two_factor, deleted), constraint t_s_user_unique_verify unique (verify, deleted), constraint t_s_user_unique_forget unique (forget, deleted) ) comment '系统-用户表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240103__Add_table_‘t_s_sensitive_word'.sql b/src/main/resources/db/migration/master/V1_0_0_240103__Add_table_‘t_s_sensitive_word'.sql index 5177ab7..d6c2830 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240103__Add_table_‘t_s_sensitive_word'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240103__Add_table_‘t_s_sensitive_word'.sql @@ -2,11 +2,11 @@ drop table if exists t_s_sensitive_word; create table if not exists t_s_sensitive_word ( - id bigint not null primary key, - word varchar(400) not null comment '词', + id bigint not null primary key, + word varchar(400) not null comment '词', use_for varchar(50) null comment '用于', - enable int not null default 1 comment '启用', - deleted bigint not null default 0, - version int not null default 0, + enable int not null default 1 comment '启用', + deleted bigint not null default 0, + version int not null default 0, constraint t_s_sensitive_word_unique_word unique (word, deleted) ) comment '系统-敏感词表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240116__Add_table_'t_b_tool_category'.sql b/src/main/resources/db/migration/master/V1_0_0_240116__Add_table_'t_b_tool_category'.sql index 21a15d5..1b5ef6e 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240116__Add_table_'t_b_tool_category'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240116__Add_table_'t_b_tool_category'.sql @@ -3,7 +3,7 @@ drop table if exists t_b_tool_category; create table if not exists t_b_tool_category ( id bigint not null primary key, - name varchar(50) not null comment '工具类别名', + name varchar(50) not null comment '类别名', enable int not null default 1 comment '启用', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', diff --git a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql index 899b171..3b4bd89 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240119__Add_table_'t_b_tool_template'.sql @@ -14,4 +14,4 @@ create table if not exists t_b_tool_template deleted bigint not null default 0, version int not null default 0, constraint t_b_tool_template_unique_name_platform unique (name, platform, deleted) -) comment '工具-模板表' \ No newline at end of file +) comment '工具-模板表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql index 8531682..0956bf6 100644 --- a/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql +++ b/src/main/resources/db/migration/master/V1_0_0_240120__Add_table_'t_b_tool_base'.sql @@ -6,11 +6,11 @@ create table if not exists t_b_tool_base name varchar(20) not null comment '基板名', source_id bigint not null comment '源码 ID', dist_id bigint not null comment '产物 ID', - platform varchar(20) not null comment '平台', + platform varchar(20) not null comment '平台', compiled int not null default 0 comment '已编译', create_time datetime not null default (utc_timestamp()) comment '创建时间', update_time datetime not null default (utc_timestamp()) comment '修改时间', deleted bigint not null default 0, version int not null default 0, constraint t_b_tool_base_unique_name_platform unique (name, platform, deleted) -) \ No newline at end of file +) comment '工具-基板表'; \ No newline at end of file diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_l_sys_log'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_l_sys_log'.sql index a49c66c..ba3c20a 100644 --- a/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_l_sys_log'.sql +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231212__Add_table_'t_l_sys_log'.sql @@ -6,15 +6,15 @@ create table t_l_sys_log -- 本地-系统日志表 log_type text not null, -- 日志类型 operate_user_id integer not null, -- 操作用户 operate_time text not null default (strftime('%Y-%m-%d %H:%M:%f', 'now')), -- 操作时间 - request_uri text default null, -- 请求 URI - request_method text default null, -- 请求方式 - request_params text, -- 请求参数 + request_uri text null default null, -- 请求 URI + request_method text null default null, -- 请求方式 + request_params text null, -- 请求参数 request_ip text not null, -- 请求 IP request_server_address text not null, -- 请求服务器地址 exception integer not null default 0, -- 是否异常 - exception_info text, -- 异常信息 + exception_info text null, -- 异常信息 start_time text not null, -- 开始时间 end_time text not null, -- 结束时间 - execute_time integer default null, -- 执行时间 - user_agent text default null -- 用户代理 + execute_time integer null default null, -- 执行时间 + user_agent text null default null -- 用户代理 ); \ No newline at end of file diff --git a/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_l_statistics_log'.sql b/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_l_statistics_log'.sql index 2fb9390..8f8331a 100644 --- a/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_l_statistics_log'.sql +++ b/src/main/resources/db/migration/sqlite/V1_0_0_231214__Add_table_'t_l_statistics_log'.sql @@ -6,4 +6,4 @@ create table if not exists t_l_statistics_log -- 本地-统计日志表 key text not null, -- 记录键 value text not null, -- 记录值 record_time text not null default (strftime('%Y-%m-%d %H:%M:%f', 'now')) -- 记录时间 -) \ No newline at end of file +); \ No newline at end of file From 27ed533530d65424e5f3d0b222af2c4ae220b9ef Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 22 Apr 2024 15:12:12 +0800 Subject: [PATCH 226/258] Refactor(Statistics): Correct incorrect spelling Correct WEAK to WEEK --- .../oxygen/api/param/system/ActiveInfoGetParam.kt | 10 +++++----- .../oxygen/api/param/system/OnlineInfoGetParam.kt | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/system/ActiveInfoGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/ActiveInfoGetParam.kt index c085c80..de4c1ba 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/system/ActiveInfoGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/ActiveInfoGetParam.kt @@ -20,14 +20,14 @@ data class ActiveInfoGetParam( */ @Schema( description = "范围", - allowableValues = ["WEAK", "MONTH", "QUARTER", "YEAR", "TWO_YEARS", "THREE_YEARS", "FIVE_YEARS", "ALL"], - defaultValue = "WEAK", - example = "WEAK" + allowableValues = ["WEEK", "MONTH", "QUARTER", "YEAR", "TWO_YEARS", "THREE_YEARS", "FIVE_YEARS", "ALL"], + defaultValue = "WEEK", + example = "WEEK" ) - val scope: Scope = Scope.WEAK + val scope: Scope = Scope.WEEK ) { enum class Scope(@field:EnumValue @field:JsonValue val code: String) { - WEAK("WEAK"), + WEEK("WEEK"), MONTH("MONTH"), diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/system/OnlineInfoGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/OnlineInfoGetParam.kt index 932f10e..d00d9eb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/system/OnlineInfoGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/OnlineInfoGetParam.kt @@ -20,16 +20,16 @@ data class OnlineInfoGetParam( */ @Schema( description = "范围", - allowableValues = ["WEAK", "MONTH", "QUARTER", "YEAR", "TWO_YEARS", "THREE_YEARS", "FIVE_YEARS", "ALL"], - defaultValue = "WEAK", - example = "WEAK" + allowableValues = ["WEEK", "MONTH", "QUARTER", "YEAR", "TWO_YEARS", "THREE_YEARS", "FIVE_YEARS", "ALL"], + defaultValue = "WEEK", + example = "WEEK" ) - val scope: Scope = Scope.WEAK + val scope: Scope = Scope.WEEK ) { enum class Scope(@field:EnumValue @field:JsonValue val code: String) { DAY("DAY"), - WEAK("WEAK"), + WEEK("WEEK"), MONTH("MONTH"), From eb031fefb3ed97aeecc6cecc9a2e9e4e3fd81741 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 22 Apr 2024 15:13:45 +0800 Subject: [PATCH 227/258] Refactor(Statistics): Optimize memory and hard disk capacity display Unknown is displayed when detailed capacity cannot be obtained --- .../api/service/system/impl/StatisticsServiceImpl.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsServiceImpl.kt index e6394f8..ae264a7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/StatisticsServiceImpl.kt @@ -66,15 +66,17 @@ class StatisticsServiceImpl( cpuLogicalProcessorCount = systemInfo.hardware.processor.logicalProcessorCount, microarchitecture = systemInfo.hardware.processor.processorIdentifier.microarchitecture, memories = "${ByteUtil.formatByteSize(systemInfo.hardware.memory.total)} (${ - systemInfo.hardware.memory.physicalMemory.joinToString( + if (systemInfo.hardware.memory.physicalMemory.size > 0) systemInfo.hardware.memory.physicalMemory.joinToString( " + " ) { ByteUtil.formatByteSize(it.capacity) } + else "Unknown" })", - disks = "${ByteUtil.formatByteSize(systemInfo.hardware.diskStores.sumOf { it.size })} (${ + disks = if (systemInfo.hardware.diskStores.size > 0) "${ByteUtil.formatByteSize(systemInfo.hardware.diskStores.sumOf { it.size })} (${ systemInfo.hardware.diskStores.joinToString( " + " ) { ByteUtil.formatByteSize(it.size) } })" + else "Unknown" ) override fun cpu(): CpuInfoVo { @@ -190,7 +192,11 @@ class StatisticsServiceImpl( return OnlineInfoVo( current = redisUtil.keys("${SecurityProperties.jwtIssuer}_login_*") - .distinctBy { Regex("${SecurityProperties.jwtIssuer}_login_(.*):.*").matchEntire(it)?.groupValues?.getOrNull(1) }.size.toLong(), + .distinctBy { + Regex("${SecurityProperties.jwtIssuer}_login_(.*):.*").matchEntire(it)?.groupValues?.getOrNull( + 1 + ) + }.size.toLong(), history = history ) } From 015e2ac09c16da76093be28eea2adab01698f4ba Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 22 Apr 2024 16:14:06 +0800 Subject: [PATCH 228/258] Refactor(Parameter): Optimize parameter verification Optimize parameter verification for update operations --- .../fatweb/oxygen/api/param/system/MailSettingsParam.kt | 2 +- .../fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt | 4 ++++ .../oxygen/api/param/tool/ToolCategoryUpdateParam.kt | 2 ++ .../oxygen/api/param/tool/ToolTemplateUpdateParam.kt | 4 ++++ .../top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt | 7 +++++++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSettingsParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSettingsParam.kt index 8e5cec5..61284fd 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSettingsParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/system/MailSettingsParam.kt @@ -40,7 +40,7 @@ data class MailSettingsParam( * @since 1.0.0 */ @Schema(description = "安全类型", allowableValues = ["None", "SSL/TLS", "StartTls"], defaultValue = "None") - val securityType: MailSecurityType? = MailSecurityType.NONE, + val securityType: MailSecurityType = MailSecurityType.NONE, /** * Username diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt index fd5ef0b..b798fc2 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseUpdateParam.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.param.tool import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern import top.fatweb.oxygen.api.annotation.Trim /** @@ -30,6 +31,7 @@ data class ToolBaseUpdateParam( */ @Trim @Schema(description = "名称") + @field: Pattern(regexp = "^.*\\S.*$", message = "Name can not be blank") var name: String?, /** @@ -39,6 +41,7 @@ data class ToolBaseUpdateParam( * @since 1.0.0 */ @Schema(description = "源码") + @field: Pattern(regexp = "^.*\\S.*$", message = "Source can not be blank") val source: String?, /** @@ -48,5 +51,6 @@ data class ToolBaseUpdateParam( * @since 1.0.0 */ @Schema(description = "产物") + @field: Pattern(regexp = "^.*\\S.*$", message = "Dist can not be blank") val dist: String? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt index 00fc869..72c63b2 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCategoryUpdateParam.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.param.tool import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern import top.fatweb.oxygen.api.annotation.Trim /** @@ -30,6 +31,7 @@ data class ToolCategoryUpdateParam( */ @Trim @Schema(description = "名称") + @field: Pattern(regexp = "^.*\\S.*$", message = "Name can not be blank") var name: String?, /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt index 14ea57a..1f7c232 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolTemplateUpdateParam.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.param.tool import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern import top.fatweb.oxygen.api.annotation.Trim /** @@ -30,6 +31,7 @@ data class ToolTemplateUpdateParam( */ @Trim @Schema(description = "名称") + @field: Pattern(regexp = "^.*\\S.*$", message = "Name can not be blank") var name: String?, /** @@ -39,6 +41,7 @@ data class ToolTemplateUpdateParam( * @since 1.0.0 */ @Schema(description = "源码") + @field: Pattern(regexp = "^.*\\S.*$", message = "Source can not be blank") val source: String?, /** @@ -49,6 +52,7 @@ data class ToolTemplateUpdateParam( */ @Trim @Schema(description = "入口文件") + @field: Pattern(regexp = "^.*\\S.*$", message = "Entry point can not be blank") var entryPoint: String?, /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt index 90b4610..8e59883 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpdateParam.kt @@ -2,6 +2,8 @@ package top.fatweb.oxygen.api.param.tool import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Size import top.fatweb.oxygen.api.annotation.Trim /** @@ -31,6 +33,7 @@ data class ToolUpdateParam( */ @Trim @Schema(description = "名称") + @field: Pattern(regexp = "^.*\\S.*$", message = "Name can not be blank") var name: String?, /** @@ -40,6 +43,7 @@ data class ToolUpdateParam( * @since 1.0.0 */ @Schema(description = "图标") + @field: Pattern(regexp = "^.*\\S.*$", message = "Icon can not be blank") val icon: String?, /** @@ -58,6 +62,7 @@ data class ToolUpdateParam( * @since 1.0.0 */ @Schema(description = "关键词") + @field:Size(min = 1, message = "Keywords can not be empty") val keywords: List?, /** @@ -67,6 +72,7 @@ data class ToolUpdateParam( * @since 1.0.0 */ @Schema(description = "类别") + @field:Size(min = 1, message = "Categories can not be empty") val categories: List?, /** @@ -76,5 +82,6 @@ data class ToolUpdateParam( * @since 1.0.0 */ @Schema(description = "源码") + @field: Pattern(regexp = "^.*\\S.*$", message = "Source can not be blank") val source: String? ) From bdd0197d78d998bbc05cc5e19187b16582b518a2 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Apr 2024 16:31:44 +0800 Subject: [PATCH 229/258] Fix(EditService): Fix get wrong tool detail Fix get wrong tool detail in source page --- .../kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt | 2 +- .../fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt | 7 ++----- src/main/resources/mapper/tool/EditMapper.xml | 3 +++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt index f874483..2fb8321 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt @@ -69,5 +69,5 @@ interface EditMapper : BaseMapper { @Param("ver") ver: String, @Param("platform") platform: ToolBase.Platform, @Param("operator") operator: String? - ): List? + ): Tool? } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index 44165cb..c5ef9d3 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -219,12 +219,9 @@ class EditServiceImpl( if (username == "!" && WebUtil.getLoginUserId() == null) { throw NoRecordFoundException() } - val toolList = baseMapper.selectDetail(username, toolId, ver, platform, WebUtil.getLoginUsername()) - if (toolList.isNullOrEmpty()) { - throw NoRecordFoundException() - } - return toolList.first().let(ToolConverter::toolToToolVo) + return baseMapper.selectDetail(username, toolId, ver, platform, WebUtil.getLoginUsername()) + ?.let(ToolConverter::toolToToolVo) ?: throw NoRecordFoundException() } override fun submit(id: Long): Boolean { diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml index ca46957..c48c967 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -195,6 +195,7 @@ and tsu.username = #{username} + and t_b_tool_main.publish != 0 @@ -206,11 +207,13 @@ and tsu.username = #{username} + and t_b_tool_main.publish != 0 order by t_b_tool_main.id desc + limit 1 \ No newline at end of file From 4527944a219cfe9dd8d3c6be95c7510b820bb1be Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Apr 2024 16:35:22 +0800 Subject: [PATCH 230/258] Fix(ToolParam): Fix wrong validate message Fix wrong validate message in ToolCreateParam and ToolUpgradeParam --- .../kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt | 2 +- .../kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt index 0f8b666..379b51e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolCreateParam.kt @@ -38,7 +38,7 @@ data class ToolCreateParam( @field: NotBlank(message = "ToolId can not be blank") @field: Pattern( regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", - message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" + message = "ToolId can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" ) var toolId: String?, diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt index 321c1ff..1863b31 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt @@ -27,7 +27,7 @@ data class ToolUpgradeParam( @field: NotBlank(message = "ToolId can not be blank") @field: Pattern( regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", - message = "Ver can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" + message = "ToolId can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" ) var toolId: String?, From bc8b0b8f9f043ddb2f082904cda95b14b1f00ed0 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Apr 2024 16:45:16 +0800 Subject: [PATCH 231/258] Refactor(Entity): Add implement Serializable Add implement Serializable to entity --- src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt | 3 ++- src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt | 3 ++- .../kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt | 3 ++- src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt | 3 ++- .../kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt index 6788c81..848c2be 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.* import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler import com.fasterxml.jackson.annotation.JsonValue import top.fatweb.oxygen.api.entity.permission.User +import java.io.Serializable import java.time.LocalDateTime /** @@ -13,7 +14,7 @@ import java.time.LocalDateTime * @since 1.0.0 */ @TableName("t_b_tool_main", autoResultMap = true) -class Tool { +class Tool : Serializable { /** * Tool review type enum * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt index 9de0aa0..94765cf 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* import com.fasterxml.jackson.annotation.JsonValue +import java.io.Serializable import java.time.LocalDateTime /** @@ -11,7 +12,7 @@ import java.time.LocalDateTime * @since 1.0.0 */ @TableName("t_b_tool_base") -class ToolBase { +class ToolBase : Serializable { /** * Platform enum * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt index f111e1d..37246b1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolCategory.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable import java.time.LocalDateTime /** @@ -10,7 +11,7 @@ import java.time.LocalDateTime * @since 1.0.0 */ @TableName("t_b_tool_category") -class ToolCategory { +class ToolCategory : Serializable { /** * ID * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt index d576b23..dd1f0dd 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolData.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable import java.time.LocalDateTime /** @@ -10,7 +11,7 @@ import java.time.LocalDateTime * @since 1.0.0 */ @TableName("t_b_tool_data") -class ToolData { +class ToolData : Serializable { /** * ID * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt index 09e8bde..d82358b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable import java.time.LocalDateTime /** @@ -10,7 +11,7 @@ import java.time.LocalDateTime * @since 1.0.0 */ @TableName("t_b_tool_template") -class ToolTemplate { +class ToolTemplate : Serializable { /** * ID * From 96afb185e7f6105ad9b32266ce6c40efdaf2c772 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Apr 2024 16:55:35 +0800 Subject: [PATCH 232/258] Fix(StoreMapper): Fix get wrong tools Fix unable to get tools after creating a new version bug --- src/main/resources/mapper/tool/StoreMapper.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/mapper/tool/StoreMapper.xml b/src/main/resources/mapper/tool/StoreMapper.xml index f4b4e02..d309167 100644 --- a/src/main/resources/mapper/tool/StoreMapper.xml +++ b/src/main/resources/mapper/tool/StoreMapper.xml @@ -8,12 +8,12 @@ from (select *, row_number() over (partition by t_b_tool_main.tool_id, t_b_tool_main.author_id order by t_b_tool_main.id desc) as rn1 from t_b_tool_main where t_b_tool_main.deleted = 0 + and t_b_tool_main.publish != 0 and t_b_tool_main.review = 'PASS' ) as temp0 where temp0.rn1 = 1 ) as temp1 left join json_table(json_extract(temp1.keywords, '$[*]'), '$[*]' columns (keyword varchar(50) path '$')) as tk on true - and temp1.publish != 0 and temp1.review = 'PASS' and ( temp1.name like concat('%', #{searchValue}, '%') @@ -45,13 +45,13 @@ from (select *, row_number() over (partition by t_b_tool_main.tool_id, t_b_tool_main.author_id order by t_b_tool_main.id desc) as rn1 from t_b_tool_main where t_b_tool_main.deleted = 0 + and t_b_tool_main.publish != 0 + and t_b_tool_main.review = 'PASS' ) as temp0 where temp0.rn1 = 1 ) as temp1 left join (select * from t_s_user where deleted = 0) as tsu on tsu.id = temp1.author_id - where temp1.publish != 0 - and temp1.review = 'PASS' - and tsu.username = #{username} + where tsu.username = #{username} order by temp1.publish desc ) as temp2 where temp2.rn2 = 1 From 5c3484a22ddf637338fec9ec3f8583f539461ae3 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 26 Apr 2024 18:07:49 +0800 Subject: [PATCH 233/258] Feat(ToolStore): Add tool favorite controller Add controller to add and remove favorite tool --- .../api/controller/tool/EditController.kt | 40 ++++++++- .../api/converter/tool/ToolConverter.kt | 3 +- .../oxygen/api/entity/common/ResponseCode.kt | 1 + .../top/fatweb/oxygen/api/entity/tool/Tool.kt | 11 ++- .../oxygen/api/entity/tool/ToolFavorite.kt | 81 +++++++++++++++++++ .../api/exception/RecordAlreadyExists.kt | 10 +++ .../oxygen/api/handler/ExceptionHandler.kt | 11 ++- .../oxygen/api/mapper/tool/StoreMapper.kt | 2 +- .../api/mapper/tool/ToolFavoriteMapper.kt | 8 ++ .../api/param/tool/ToolFavoriteAddParam.kt | 53 ++++++++++++ .../api/param/tool/ToolFavoriteRemoveParam.kt | 53 ++++++++++++ .../oxygen/api/service/tool/IEditService.kt | 24 +++++- .../api/service/tool/IToolFavoriteService.kt | 6 ++ .../api/service/tool/impl/EditServiceImpl.kt | 46 ++++++++++- .../api/service/tool/impl/StoreServiceImpl.kt | 5 +- .../tool/impl/ToolFavoriteServiceImpl.kt | 10 +++ .../top/fatweb/oxygen/api/vo/tool/ToolVo.kt | 11 ++- ..._240426__Add_table_'t_b_tool_favorite'.sql | 13 +++ .../mapper/tool/ManagementMapper.xml | 1 + .../resources/mapper/tool/StoreMapper.xml | 11 ++- .../mapper/tool/ToolFavoriteMapper.xml | 10 +++ 21 files changed, 389 insertions(+), 21 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolFavorite.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/exception/RecordAlreadyExists.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteAddParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteRemoveParam.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt create mode 100644 src/main/resources/db/migration/master/V1_0_0_240426__Add_table_'t_b_tool_favorite'.sql create mode 100644 src/main/resources/mapper/tool/ToolFavoriteMapper.xml diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index c805d84..73720dd 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -8,9 +8,7 @@ import top.fatweb.oxygen.api.annotation.Trim import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult import top.fatweb.oxygen.api.entity.tool.ToolBase -import top.fatweb.oxygen.api.param.tool.ToolCreateParam -import top.fatweb.oxygen.api.param.tool.ToolUpdateParam -import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam +import top.fatweb.oxygen.api.param.tool.* import top.fatweb.oxygen.api.service.tool.IEditService import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo @@ -207,4 +205,40 @@ class EditController( fun delete(@PathVariable id: Long): ResponseResult = if (editService.delete(id)) ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) else ResponseResult.databaseFail(ResponseCode.DATABASE_DELETE_FAILED) + + /** + * Add favorite tool + * + * @param toolFavoriteAddParam Add favorite tool parameters + * @return Response object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolFavoriteAddParam + * @see ResponseResult + */ + @Operation(summary = "收藏工具") + @PostMapping("/favorite") + fun addFavorite(@RequestBody toolFavoriteAddParam: ToolFavoriteAddParam): ResponseResult { + editService.addFavorite(toolFavoriteAddParam) + + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_INSERT_SUCCESS) + } + + /** + * Remove favorite tool + * + * @param toolFavoriteRemoveParam Remove favorite tool parameters + * @return Response object + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolFavoriteRemoveParam + * @see ResponseResult + */ + @Operation(summary = "收藏工具") + @DeleteMapping("/favorite") + fun addFavorite(@RequestBody toolFavoriteRemoveParam: ToolFavoriteRemoveParam): ResponseResult { + editService.removeFavorite(toolFavoriteRemoveParam) + + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt index 1402af2..19f54ba 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt @@ -41,7 +41,8 @@ object ToolConverter { publish = tool.publish, review = tool.review, createTime = tool.createTime, - updateTime = tool.updateTime + updateTime = tool.updateTime, + favorite = tool.favorite == 1 ) /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt index e61be09..c95a4a5 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/common/ResponseCode.kt @@ -61,6 +61,7 @@ enum class ResponseCode(val code: Int) { DATABASE_EXECUTE_ERROR(BusinessCode.DATABASE, 50), DATABASE_DUPLICATE_KEY(BusinessCode.DATABASE, 51), DATABASE_NO_RECORD_FOUND(BusinessCode.DATABASE, 52), + DATABASE_RECORD_ALREADY_EXISTS(BusinessCode.DATABASE, 53), TOOL_SUBMIT_SUCCESS(BusinessCode.TOOL, 10), TOOL_CANCEL_SUCCESS(BusinessCode.TOOL, 11), diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt index 848c2be..947f2d0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt @@ -247,7 +247,16 @@ class Tool : Serializable { @TableField(exist = false) var dist: ToolData? = null + /** + * Favorite + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField(exist = false) + var favorite: Int? = null + override fun toString(): String { - return "Tool(id=$id, name=$name, toolId=$toolId, icon=$icon, platform=$platform, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, keywords=$keywords, sourceId=$sourceId, distId=$distId, entryPoint=$entryPoint, publish=$publish, review=$review, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, author=$author, base=$base, categories=$categories, source=$source, dist=$dist)" + return "Tool(id=$id, name=$name, toolId=$toolId, icon=$icon, platform=$platform, description=$description, baseId=$baseId, authorId=$authorId, ver=$ver, keywords=$keywords, sourceId=$sourceId, distId=$distId, entryPoint=$entryPoint, publish=$publish, review=$review, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version, author=$author, base=$base, categories=$categories, source=$source, dist=$dist, favorite=$favorite)" } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolFavorite.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolFavorite.kt new file mode 100644 index 0000000..56c7f18 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolFavorite.kt @@ -0,0 +1,81 @@ +package top.fatweb.oxygen.api.entity.tool + +import com.baomidou.mybatisplus.annotation.TableField +import com.baomidou.mybatisplus.annotation.TableId +import com.baomidou.mybatisplus.annotation.TableLogic +import com.baomidou.mybatisplus.annotation.TableName +import com.baomidou.mybatisplus.annotation.Version +import java.io.Serializable + +@TableName("t_b_tool_favorite") +class ToolFavorite : Serializable { + /** + * ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableId("id") + var id: Long? = null + + /** + * User ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("user_id") + var userId: Long? = null + + /** + * Username + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("username") + var username: String? = null + + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("tool_id") + var toolId: String? = null + + /** + * Platform + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBase.Platform + */ + @TableField("platform") + var platform: ToolBase.Platform? = null + + /** + * Deleted + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + /** + * Version + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @TableField("version") + @Version + var version: Int? = null + + override fun toString(): String { + return "ToolFavorite(id=$id, userId=$userId, username=$username, toolId=$toolId, platform=$platform, deleted=$deleted, version=$version)" + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/exception/RecordAlreadyExists.kt b/src/main/kotlin/top/fatweb/oxygen/api/exception/RecordAlreadyExists.kt new file mode 100644 index 0000000..20aaf88 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/exception/RecordAlreadyExists.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.exception + +/** + * Record already exists exception + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see RuntimeException + */ +class RecordAlreadyExists : RuntimeException("Record already exists") \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt index d9969c0..587f5a1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/handler/ExceptionHandler.kt @@ -177,7 +177,11 @@ class ExceptionHandler { is TwoFactorVerificationCodeErrorException -> { logger.debug(e.localizedMessage, e) - ResponseResult.fail(ResponseCode.PERMISSION_TWO_FACTOR_VERIFICATION_CODE_ERROR, e.localizedMessage, null) + ResponseResult.fail( + ResponseCode.PERMISSION_TWO_FACTOR_VERIFICATION_CODE_ERROR, + e.localizedMessage, + null + ) } /* SQL */ @@ -226,6 +230,11 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.DATABASE_EXECUTE_ERROR, e.localizedMessage, null) } + is RecordAlreadyExists -> { + logger.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.DATABASE_RECORD_ALREADY_EXISTS, e.localizedMessage, null) + } + /* Tool */ is IllegalVersionException -> { logger.debug(e.localizedMessage, e) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt index 78e6449..786f58e 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt @@ -60,5 +60,5 @@ interface StoreMapper : BaseMapper { * @since 1.0.0 * @see Tool */ - fun selectListByAuthorToolIds(@Param("ids") ids: List): List + fun selectListByAuthorToolIds(@Param("ids") ids: List, @Param("operator") operator: Long?): List } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt new file mode 100644 index 0000000..69d2d9c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt @@ -0,0 +1,8 @@ +package top.fatweb.oxygen.api.mapper.tool + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.oxygen.api.entity.tool.ToolFavorite + +@Mapper +interface ToolFavoriteMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteAddParam.kt new file mode 100644 index 0000000..3a7537c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteAddParam.kt @@ -0,0 +1,53 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import top.fatweb.oxygen.api.annotation.Trim +import top.fatweb.oxygen.api.entity.tool.ToolBase + +/** + * Add favorite tool parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class ToolFavoriteAddParam( + /** + * Username + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Trim + @Schema(description = "用户名", required = true) + @field: NotBlank(message = "Username cannot be blank") + var username: String?, + + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Trim + @Schema(description = "工具唯一 ID", required = true) + @field: NotBlank(message = "ToolId cannot be blank") + @field: Pattern( + regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", + message = "ToolId can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" + ) + var toolId: String?, + + /** + * Platform + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBase.Platform + */ + @Schema(description = "平台") + @field:NotNull(message = "Platform can not be null") + val platform: ToolBase.Platform? +) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteRemoveParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteRemoveParam.kt new file mode 100644 index 0000000..3ae65c9 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolFavoriteRemoveParam.kt @@ -0,0 +1,53 @@ +package top.fatweb.oxygen.api.param.tool + +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotNull +import jakarta.validation.constraints.Pattern +import top.fatweb.oxygen.api.annotation.Trim +import top.fatweb.oxygen.api.entity.tool.ToolBase + +/** + * Remove favorite tool parameters + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +data class ToolFavoriteRemoveParam( + /** + * Username + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Trim + @Schema(description = "用户名", required = true) + @field: NotBlank(message = "Username cannot be blank") + var username: String?, + + /** + * Tool ID + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Trim + @Schema(description = "工具唯一 ID", required = true) + @field: NotBlank(message = "ToolId cannot be blank") + @field: Pattern( + regexp = "^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$", + message = "ToolId can only match '^[a-zA-Z-_][0-9a-zA-Z-_]{2,19}\$'" + ) + var toolId: String?, + + /** + * Platform + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolBase.Platform + */ + @Schema(description = "平台") + @field:NotNull(message = "Platform can not be null") + val platform: ToolBase.Platform? +) \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt index 0c41807..774031c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt @@ -3,9 +3,7 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.Tool import top.fatweb.oxygen.api.entity.tool.ToolBase -import top.fatweb.oxygen.api.param.tool.ToolCreateParam -import top.fatweb.oxygen.api.param.tool.ToolUpdateParam -import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam +import top.fatweb.oxygen.api.param.tool.* import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -151,4 +149,24 @@ interface IEditService : IService { * @since 1.0.0 */ fun delete(id: Long): Boolean + + /*** + * Add favorite + * + * @param toolFavoriteAddParam Add favorite tool parameters + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolFavoriteAddParam + */ + fun addFavorite(toolFavoriteAddParam: ToolFavoriteAddParam) + + /*** + * Remove favorite tool + * + * @param toolFavoriteRemoveParam Remove favorite tool parameters + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ToolFavoriteRemoveParam + */ + fun removeFavorite(toolFavoriteRemoveParam: ToolFavoriteRemoveParam) } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt new file mode 100644 index 0000000..59cf54c --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt @@ -0,0 +1,6 @@ +package top.fatweb.oxygen.api.service.tool + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.ToolFavorite + +interface IToolFavoriteService : IService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index c5ef9d3..d7958f9 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -12,9 +12,7 @@ import top.fatweb.oxygen.api.converter.tool.ToolTemplateConverter import top.fatweb.oxygen.api.entity.tool.* import top.fatweb.oxygen.api.exception.* import top.fatweb.oxygen.api.mapper.tool.EditMapper -import top.fatweb.oxygen.api.param.tool.ToolCreateParam -import top.fatweb.oxygen.api.param.tool.ToolUpdateParam -import top.fatweb.oxygen.api.param.tool.ToolUpgradeParam +import top.fatweb.oxygen.api.param.tool.* import top.fatweb.oxygen.api.service.tool.* import top.fatweb.oxygen.api.util.WebUtil import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo @@ -36,7 +34,8 @@ class EditServiceImpl( private val toolTemplateService: IToolTemplateService, private val toolCategoryService: IToolCategoryService, private val toolDataService: IToolDataService, - private val rToolCategoryService: IRToolCategoryService + private val rToolCategoryService: IRToolCategoryService, + private val toolFavoriteService: IToolFavoriteService ) : ServiceImpl(), IEditService { override fun getTemplate(platform: ToolBase.Platform): List = toolTemplateService.list( @@ -259,4 +258,43 @@ class EditServiceImpl( rToolCategoryService.remove(KtQueryWrapper(RToolCategory()).eq(RToolCategory::toolId, tool.id)) return this.removeById(id) } + + @Transactional + override fun addFavorite(toolFavoriteAddParam: ToolFavoriteAddParam) { + if (toolFavoriteService.exists( + KtQueryWrapper(ToolFavorite()) + .eq(ToolFavorite::userId, WebUtil.getLoginUserId()) + .eq(ToolFavorite::username, toolFavoriteAddParam.username) + .eq(ToolFavorite::toolId, toolFavoriteAddParam.toolId) + .eq(ToolFavorite::platform, toolFavoriteAddParam.platform) + ) + ) { + throw RecordAlreadyExists() + } + + this.detail(toolFavoriteAddParam.username!!, toolFavoriteAddParam.toolId!!, "latest", toolFavoriteAddParam.platform!!) + + toolFavoriteService.save( + ToolFavorite().apply { + userId = WebUtil.getLoginUserId() + username = toolFavoriteAddParam.username + toolId = toolFavoriteAddParam.toolId + platform = toolFavoriteAddParam.platform + } + ) + } + + @Transactional + override fun removeFavorite(toolFavoriteRemoveParam: ToolFavoriteRemoveParam) { + if (!toolFavoriteService.remove( + KtQueryWrapper(ToolFavorite()) + .eq(ToolFavorite::userId, WebUtil.getLoginUserId()) + .eq(ToolFavorite::username, toolFavoriteRemoveParam.username) + .eq(ToolFavorite::toolId, toolFavoriteRemoveParam.toolId) + .eq(ToolFavorite::platform, toolFavoriteRemoveParam.platform) + ) + ) { + throw NoRecordFoundException() + } + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt index 7139e56..747526f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt @@ -9,6 +9,7 @@ import top.fatweb.oxygen.api.mapper.tool.StoreMapper import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.ToolStoreGetParam import top.fatweb.oxygen.api.service.tool.IStoreService +import top.fatweb.oxygen.api.util.WebUtil import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -31,7 +32,7 @@ class StoreServiceImpl : ServiceImpl(), IStoreService { val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam?.searchValue) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { - toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records)) + toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId())) } return ToolConverter.toolPageToToolPageVo(toolPage) @@ -44,7 +45,7 @@ class StoreServiceImpl : ServiceImpl(), IStoreService { val toolIdsIPage = baseMapper.selectAuthorToolIdPageByUsername(toolIdsPage, username) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { - toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records)) + toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId())) } return ToolConverter.toolPageToToolPageVo(toolPage) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt new file mode 100644 index 0000000..7ac062a --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt @@ -0,0 +1,10 @@ +package top.fatweb.oxygen.api.service.tool.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.oxygen.api.entity.tool.ToolFavorite +import top.fatweb.oxygen.api.mapper.tool.ToolFavoriteMapper +import top.fatweb.oxygen.api.service.tool.IToolFavoriteService + +@Service +class ToolFavoriteServiceImpl : ServiceImpl(), IToolFavoriteService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt index 6cce238..3be8f47 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt @@ -184,5 +184,14 @@ data class ToolVo( * @see LocalDateTime */ @Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z") - val updateTime: LocalDateTime? + val updateTime: LocalDateTime?, + + /** + * Favorite + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ + @Schema(description = "收藏") + val favorite: Boolean? ) \ No newline at end of file diff --git a/src/main/resources/db/migration/master/V1_0_0_240426__Add_table_'t_b_tool_favorite'.sql b/src/main/resources/db/migration/master/V1_0_0_240426__Add_table_'t_b_tool_favorite'.sql new file mode 100644 index 0000000..20c051e --- /dev/null +++ b/src/main/resources/db/migration/master/V1_0_0_240426__Add_table_'t_b_tool_favorite'.sql @@ -0,0 +1,13 @@ +drop table if exists t_b_tool_favorite; + +create table if not exists t_b_tool_favorite +( + id bigint not null primary key, + user_id bigint not null comment '用户 ID', + username varchar(20) not null comment '用户名', + tool_id varchar(50) not null comment '工具 ID', + platform varchar(20) not null comment '平台', + deleted bigint not null default 0, + version int not null default 0, + constraint t_b_tool_favorite_unique_user_id_username_tool_id_platform unique (user_id, username, tool_id, platform, deleted) +) comment '工具-收藏表'; \ No newline at end of file diff --git a/src/main/resources/mapper/tool/ManagementMapper.xml b/src/main/resources/mapper/tool/ManagementMapper.xml index b2e6e71..a5f7b2f 100644 --- a/src/main/resources/mapper/tool/ManagementMapper.xml +++ b/src/main/resources/mapper/tool/ManagementMapper.xml @@ -237,6 +237,7 @@ + and tbtm.rn = 1 + + + + + + + + + From f5b6687d97ee763b4bf033880eaeaad3c44832b4 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sat, 27 Apr 2024 16:32:13 +0800 Subject: [PATCH 234/258] Feat(PersonalTool): Add pagination Add pagination to personal tool management --- .../api/controller/tool/EditController.kt | 9 +++++-- .../oxygen/api/mapper/tool/EditMapper.kt | 20 ++++++++++++--- .../oxygen/api/mapper/tool/StoreMapper.kt | 6 ++--- .../api/mapper/tool/ToolFavoriteMapper.kt | 8 ++++++ .../oxygen/api/service/tool/IEditService.kt | 9 +++++-- .../oxygen/api/service/tool/IStoreService.kt | 13 +++++++++- .../api/service/tool/IToolFavoriteService.kt | 8 ++++++ .../api/service/tool/impl/EditServiceImpl.kt | 25 ++++++++++++++++--- .../api/service/tool/impl/StoreServiceImpl.kt | 6 ++--- .../tool/impl/ToolFavoriteServiceImpl.kt | 10 ++++++++ src/main/resources/mapper/tool/EditMapper.xml | 25 ++++++++++++++++--- 11 files changed, 117 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index 73720dd..ef150b4 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -8,8 +8,10 @@ import top.fatweb.oxygen.api.annotation.Trim import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.* import top.fatweb.oxygen.api.service.tool.IEditService +import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -111,13 +113,16 @@ class EditController( * @return Response object includes tool list * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see PageSortParam * @see ResponseResult + * @see PageVo * @see ToolVo */ + @Trim @Operation(summary = "获取个人工具") @GetMapping - fun get(): ResponseResult> = - ResponseResult.databaseSuccess(ResponseCode.DATABASE_SELECT_SUCCESS, data = editService.get()) + fun get(@Valid pageSortParam: PageSortParam): ResponseResult> = + ResponseResult.databaseSuccess(ResponseCode.DATABASE_SELECT_SUCCESS, data = editService.getPage(pageSortParam)) /** * Get tool detail diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt index 2fb8321..7cc0da1 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.mapper.tool import com.baomidou.mybatisplus.core.mapper.BaseMapper +import com.baomidou.mybatisplus.core.metadata.IPage import org.apache.ibatis.annotations.Mapper import org.apache.ibatis.annotations.Param import top.fatweb.oxygen.api.entity.tool.Tool @@ -41,15 +42,28 @@ interface EditMapper : BaseMapper { fun selectOne(@Param("id") id: Long, @Param("userId") userId: Long): Tool? /** - * Select tool in list by User ID + * Select tool ID by user ID in page * + * @param page Pagination * @param userId User ID - * @return List of tool object + * @return Tool ID in page + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IPage + */ + fun selectPersonalToolIdPage(page: IPage, @Param("userId") userId: Long): IPage + + /** + * Select tool in list by tool IDs and user ID + * + * @param toolIds List of tool Ids + * @param userId User ID + * @return List of Tool object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see Tool */ - fun selectPersonal(@Param("userId") userId: Long): List + fun selectListByToolIds(@Param("toolIds") toolIds: List, @Param("userId") userId: Long): List /** * Select tool detail diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt index 786f58e..e464b45 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt @@ -29,11 +29,11 @@ interface StoreMapper : BaseMapper { fun selectAuthorToolIdPage(page: IPage, @Param("searchValue") searchValue: String?): IPage /** - * Select tool ID by username in page + * Select author and tool ID by username in page * * @param page Pagination * @param username Username - * @return Tool ID in page + * @return Author:Tool_ID in page * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see IPage @@ -44,7 +44,7 @@ interface StoreMapper : BaseMapper { * Select tool in list by tool IDs * * @param ids List of tool IDs - * @return List of tool object + * @return List of Tool object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 * @see Tool diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt index 69d2d9c..213975b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/ToolFavoriteMapper.kt @@ -4,5 +4,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper import org.apache.ibatis.annotations.Mapper import top.fatweb.oxygen.api.entity.tool.ToolFavorite +/** + * Tool favorite mapper + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see BaseMapper + * @see ToolFavorite + */ @Mapper interface ToolFavoriteMapper : BaseMapper \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt index 774031c..8d9ba15 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt @@ -3,7 +3,9 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.Tool import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.* +import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -98,12 +100,15 @@ interface IEditService : IService { /** * Get personal tools * - * @return List of ToolVo object + * @param pageSortParam Page sort parameters + * @return PageVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see PageSortParam + * @see PageVo * @see ToolVo */ - fun get(): List + fun getPage(pageSortParam: PageSortParam): PageVo /** * Get tool detail diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt index 956d114..d5efaa8 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IStoreService.kt @@ -19,16 +19,27 @@ interface IStoreService : IService { /** * Get tool in page * + * @param toolStoreGetParam Get tool parameters in tool store + * @return PageVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see ToolStoreGetParam + * @see PageVo + * @see ToolVo */ - fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo + fun getPage(toolStoreGetParam: ToolStoreGetParam): PageVo /** * Get tool by username in page * + * @param pageSortParam Page sort parameters + * @param username Username + * @return PageVo } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt index 59cf54c..108b50c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IToolFavoriteService.kt @@ -3,4 +3,12 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService import top.fatweb.oxygen.api.entity.tool.ToolFavorite +/** + * Tool favorite service interface + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see IService + * @see ToolFavorite + */ interface IToolFavoriteService : IService \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index d7958f9..d879dbe 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper +import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.dao.DuplicateKeyException import org.springframework.stereotype.Service @@ -12,9 +13,11 @@ import top.fatweb.oxygen.api.converter.tool.ToolTemplateConverter import top.fatweb.oxygen.api.entity.tool.* import top.fatweb.oxygen.api.exception.* import top.fatweb.oxygen.api.mapper.tool.EditMapper +import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.* import top.fatweb.oxygen.api.service.tool.* import top.fatweb.oxygen.api.util.WebUtil +import top.fatweb.oxygen.api.vo.PageVo import top.fatweb.oxygen.api.vo.tool.ToolCategoryVo import top.fatweb.oxygen.api.vo.tool.ToolTemplateVo import top.fatweb.oxygen.api.vo.tool.ToolVo @@ -210,9 +213,18 @@ class EditServiceImpl( return this.getOne(tool.id!!) } - override fun get(): List = - baseMapper.selectPersonal(WebUtil.getLoginUserId()!!) - .map(ToolConverter::toolToToolVo) + override fun getPage(pageSortParam: PageSortParam): PageVo { + val toolIdsPage = Page(pageSortParam.currentPage, 20) + toolIdsPage.setOptimizeCountSql(false) + + val toolIdsIPage = baseMapper.selectPersonalToolIdPage(toolIdsPage, WebUtil.getLoginUserId()!!) + val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) + if (toolIdsIPage.total > 0) { + toolPage.setRecords(baseMapper.selectListByToolIds(toolIdsIPage.records, WebUtil.getLoginUserId()!!)) + } + + return ToolConverter.toolPageToToolPageVo(toolPage) + } override fun detail(username: String, toolId: String, ver: String, platform: ToolBase.Platform): ToolVo { if (username == "!" && WebUtil.getLoginUserId() == null) { @@ -272,7 +284,12 @@ class EditServiceImpl( throw RecordAlreadyExists() } - this.detail(toolFavoriteAddParam.username!!, toolFavoriteAddParam.toolId!!, "latest", toolFavoriteAddParam.platform!!) + this.detail( + toolFavoriteAddParam.username!!, + toolFavoriteAddParam.toolId!!, + "latest", + toolFavoriteAddParam.platform!! + ) toolFavoriteService.save( ToolFavorite().apply { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt index 747526f..21e5413 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt @@ -25,11 +25,11 @@ import top.fatweb.oxygen.api.vo.tool.ToolVo */ @Service class StoreServiceImpl : ServiceImpl(), IStoreService { - override fun getPage(toolStoreGetParam: ToolStoreGetParam?): PageVo { - val toolIdsPage = Page(toolStoreGetParam?.currentPage ?: 1, 20) + override fun getPage(toolStoreGetParam: ToolStoreGetParam): PageVo { + val toolIdsPage = Page(toolStoreGetParam.currentPage, 20) toolIdsPage.setOptimizeCountSql(false) - val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam?.searchValue) + val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam.searchValue) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId())) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt index 7ac062a..8bb5b55 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolFavoriteServiceImpl.kt @@ -6,5 +6,15 @@ import top.fatweb.oxygen.api.entity.tool.ToolFavorite import top.fatweb.oxygen.api.mapper.tool.ToolFavoriteMapper import top.fatweb.oxygen.api.service.tool.IToolFavoriteService +/** + * Tool favorite service implement + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see ServiceImpl + * @see ToolFavoriteMapper + * @see ToolFavorite + * @see IToolFavoriteService + */ @Service class ToolFavoriteServiceImpl : ServiceImpl(), IToolFavoriteService \ No newline at end of file diff --git a/src/main/resources/mapper/tool/EditMapper.xml b/src/main/resources/mapper/tool/EditMapper.xml index c48c967..818ca35 100644 --- a/src/main/resources/mapper/tool/EditMapper.xml +++ b/src/main/resources/mapper/tool/EditMapper.xml @@ -94,7 +94,15 @@ and t_b_tool_main.id = #{id} - + select distinct t_b_tool_main.tool_id + from t_b_tool_main + where t_b_tool_main.deleted = 0 + and t_b_tool_main.author_id = #{userId} + order by t_b_tool_main.id desc + + + - - + + \ No newline at end of file From ab20c45f1f4ae9a45af6996ee2c39e75cb84a43f Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 6 May 2024 13:37:29 +0800 Subject: [PATCH 238/258] Refactor(KtWrapper): Simplify KtWrapper Change KtUpdateWrapper to ktUpdate. Change KtQueryWrapper to ktQuery --- .../api/service/permission/impl/UserServiceImpl.kt | 6 +++--- .../api/service/system/impl/SensitiveWordServiceImpl.kt | 8 +++----- .../oxygen/api/service/tool/impl/EditServiceImpl.kt | 9 ++++----- .../api/service/tool/impl/ManagementServiceImpl.kt | 6 +++--- .../oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt | 3 +-- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt index 059b22c..c82ddbf 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt @@ -106,7 +106,7 @@ class UserServiceImpl( if (!passwordEncoder.matches(userChangePasswordParam.originalPassword, user.password)) { throw BadCredentialsException("Passwords do not match") } - val wrapper = KtUpdateWrapper(User()) + val wrapper = ktUpdate() .eq(User::id, user.id) .set(User::password, passwordEncoder.encode(userChangePasswordParam.newPassword)) .set(User::credentialsExpiration, null) @@ -220,7 +220,7 @@ class UserServiceImpl( this.updateById(user) this.update( - KtUpdateWrapper(User()).eq(User::id, user.id) + ktUpdate().eq(User::id, user.id) .set( User::verify, if (userUpdateParam.verified || userUpdateParam.id == 0L) null else "${ @@ -282,7 +282,7 @@ class UserServiceImpl( val user = this.getById(userUpdatePasswordParam.id) user?.let { - val wrapper = KtUpdateWrapper(User()) + val wrapper = ktUpdate() .eq(User::id, user.id) .set(User::password, passwordEncoder.encode(userUpdatePasswordParam.password)) .set( diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt index f60c2f0..a591550 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt @@ -1,7 +1,5 @@ package top.fatweb.oxygen.api.service.system.impl -import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper -import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Propagation @@ -38,9 +36,9 @@ class SensitiveWordServiceImpl : ServiceImpl @Transactional(propagation = Propagation.REQUIRES_NEW) override fun update(sensitiveWordUpdateParam: SensitiveWordUpdateParam) { - this.update(KtUpdateWrapper(SensitiveWord()).set(SensitiveWord::enable, false)) + this.update(ktUpdate().set(SensitiveWord::enable, false)) this.update( - KtUpdateWrapper(SensitiveWord()).`in`(SensitiveWord::id, sensitiveWordUpdateParam.ids) + ktUpdate().`in`(SensitiveWord::id, sensitiveWordUpdateParam.ids) .set(SensitiveWord::enable, true) ) } @@ -52,7 +50,7 @@ class SensitiveWordServiceImpl : ServiceImpl @Transactional(propagation = Propagation.REQUIRES_NEW) override fun checkSensitiveWord(str: String) { - this.list(KtQueryWrapper(SensitiveWord()).eq(SensitiveWord::enable, 1)).map(SensitiveWord::word).forEach { + this.list(ktQuery().eq(SensitiveWord::enable, 1)).map(SensitiveWord::word).forEach { it ?: return@forEach try { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index 74e2208..6007746 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -1,7 +1,6 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper -import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.dao.DuplicateKeyException @@ -64,7 +63,7 @@ class EditServiceImpl( override fun create(toolCreateParam: ToolCreateParam): ToolVo { val template = this.getTemplate(toolCreateParam.templateId!!) baseMapper.selectOne( - KtQueryWrapper(Tool()) + ktQuery() .eq(Tool::toolId, toolCreateParam.toolId!!) .eq(Tool::authorId, WebUtil.getLoginUserId()!!) .eq(Tool::platform, template.platform) @@ -245,7 +244,7 @@ class EditServiceImpl( throw ToolHasBeenPublishedException() } - return update(KtUpdateWrapper(Tool()).eq(Tool::id, id).set(Tool::review, Tool.ReviewType.PROCESSING)) + return update(ktUpdate().eq(Tool::id, id).set(Tool::review, Tool.ReviewType.PROCESSING)) } override fun cancel(id: Long): Boolean { @@ -257,13 +256,13 @@ class EditServiceImpl( throw ToolNotUnderReviewException() } - return update(KtUpdateWrapper(Tool()).eq(Tool::id, id).set(Tool::review, Tool.ReviewType.NONE)) + return update(ktUpdate().eq(Tool::id, id).set(Tool::review, Tool.ReviewType.NONE)) } @Transactional override fun delete(id: Long): Boolean { val tool = baseMapper.selectOne( - KtQueryWrapper(Tool()).eq(Tool::id, id) + ktQuery().eq(Tool::id, id) .eq(Tool::authorId, WebUtil.getLoginUserId()!!) ) ?: throw NoRecordFoundException() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt index 4810eae..ae18c7c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt @@ -77,7 +77,7 @@ class ManagementServiceImpl( ) this.update( - KtUpdateWrapper(Tool()) + ktUpdate() .eq(Tool::id, id) .set(Tool::review, Tool.ReviewType.PASS) .set(Tool::publish, LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli()) @@ -93,7 +93,7 @@ class ManagementServiceImpl( } this.update( - KtUpdateWrapper(Tool()) + ktUpdate() .eq(Tool::id, id) .set(Tool::review, Tool.ReviewType.REJECT) ) @@ -108,7 +108,7 @@ class ManagementServiceImpl( } this.update( - KtUpdateWrapper(Tool()) + ktUpdate() .eq(Tool::id, id) .set(Tool::review, Tool.ReviewType.REJECT) ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt index 237ba10..c077601 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -1,6 +1,5 @@ package top.fatweb.oxygen.api.service.tool.impl -import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service @@ -45,7 +44,7 @@ class ToolBaseServiceImpl( return ToolBaseConverter.toolBasePageToToolBasePageVo( this.page( basePage, - KtQueryWrapper(ToolBase()).`in`( + ktQuery().`in`( !toolBaseGetParam?.platform.isNullOrBlank(), ToolBase::platform, toolBaseGetParam?.platform?.split(",") From 0f2d29831d93c880c4fe2f2ef917796b6c02ed15 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 7 May 2024 11:29:10 +0800 Subject: [PATCH 239/258] Refactor(Converter): Optimize Boolean type attribute conversion --- .../converter/permission/GroupConverter.kt | 4 +-- .../api/converter/permission/RoleConverter.kt | 4 +-- .../api/converter/system/SettingsConverter.kt | 2 +- .../api/converter/system/SysLogConverter.kt | 34 +++++++++---------- .../api/converter/tool/ToolBaseConverter.kt | 4 +-- .../converter/tool/ToolCategoryConverter.kt | 2 +- .../api/converter/tool/ToolConverter.kt | 2 +- .../converter/tool/ToolTemplateConverter.kt | 6 ++-- .../oxygen/api/vo/system/SensitiveWordVo.kt | 2 +- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/GroupConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/GroupConverter.kt index 28cbbd6..0f544e9 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/GroupConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/GroupConverter.kt @@ -30,7 +30,7 @@ object GroupConverter { fun groupToGroupVo(group: Group) = GroupVo( id = group.id, name = group.name, - enable = group.enable == 1, + enable = group.enable?.let { it == 1}, createTime = group.createTime, updateTime = group.updateTime ) @@ -48,7 +48,7 @@ object GroupConverter { fun groupToGroupWithRoleVo(group: Group) = GroupWithRoleVo( id = group.id, name = group.name, - enable = group.enable == 1, + enable = group.enable?.let { it == 1}, createTime = group.createTime, updateTime = group.updateTime, roles = group.roles?.map(RoleConverter::roleToRoleVo) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/RoleConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/RoleConverter.kt index 98f7375..f6bd0b7 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/RoleConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/permission/RoleConverter.kt @@ -30,7 +30,7 @@ object RoleConverter { fun roleToRoleVo(role: Role) = RoleVo( id = role.id, name = role.name, - enable = role.enable == 1, + enable = role.enable?.let { it == 1}, createTime = role.createTime, updateTime = role.updateTime ) @@ -48,7 +48,7 @@ object RoleConverter { fun roleToRoleWithPowerVo(role: Role) = RoleWithPowerVo( id = role.id, name = role.name, - enable = role.enable == 1, + enable = role.enable?.let { it == 1}, createTime = role.createTime, updateTime = role.updateTime, modules = role.modules?.map(ModuleConverter::moduleToModuleVo), diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt index 2d7f717..8f2d554 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SettingsConverter.kt @@ -25,7 +25,7 @@ object SettingsConverter { id = sensitiveWord.id, word = sensitiveWord.word, useFor = sensitiveWord.useFor?.map(SensitiveWord.Use::valueOf)?.toSet(), - enable = sensitiveWord.enable == 1 + enable = sensitiveWord.enable?.let { it == 1} ) /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SysLogConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SysLogConverter.kt index d94bd90..ce7f05c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SysLogConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/system/SysLogConverter.kt @@ -29,24 +29,24 @@ object SysLogConverter { syslogPage.pages, syslogPage.size, syslogPage.current, - syslogPage.records.map { + syslogPage.records.map { sysLog -> SysLogVo( - id = it.id, - logType = it.logType, - operateUserId = it.operateUserId, - operateTime = it.operateTime, - requestUri = it.requestUri, - requestMethod = it.requestMethod, - requestParams = it.requestParams, - requestIp = it.requestIp, - requestServerAddress = it.requestServerAddress, - exception = it.exception == 1, - exceptionInfo = it.exceptionInfo, - startTime = it.startTime, - endTime = it.endTime, - executeTime = it.executeTime, - userAgent = it.userAgent, - operateUsername = it.operateUsername + id = sysLog.id, + logType = sysLog.logType, + operateUserId = sysLog.operateUserId, + operateTime = sysLog.operateTime, + requestUri = sysLog.requestUri, + requestMethod = sysLog.requestMethod, + requestParams = sysLog.requestParams, + requestIp = sysLog.requestIp, + requestServerAddress = sysLog.requestServerAddress, + exception = sysLog.exception?.let { it == 1}, + exceptionInfo = sysLog.exceptionInfo, + startTime = sysLog.startTime, + endTime = sysLog.endTime, + executeTime = sysLog.executeTime, + userAgent = sysLog.userAgent, + operateUsername = sysLog.operateUsername ) }) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt index d37c56f..fb76be6 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolBaseConverter.kt @@ -29,7 +29,7 @@ object ToolBaseConverter { source = toolBase.source?.let(ToolDataConverter::toolDataToToolDataVo), dist = toolBase.dist?.let(ToolDataConverter::toolDataToToolDataVo), platform = toolBase.platform, - compiled = toolBase.compiled == 1, + compiled = toolBase.compiled?.let { it == 1}, createTime = toolBase.createTime, updateTime = toolBase.updateTime ) @@ -50,7 +50,7 @@ object ToolBaseConverter { source = ToolDataVo(id = toolBase.sourceId, data = null, createTime = null, updateTime = null), dist = ToolDataVo(id = toolBase.distId, data = null, createTime = null, updateTime = null), platform = toolBase.platform, - compiled = toolBase.compiled == 1, + compiled = toolBase.compiled?.let { it == 1}, createTime = toolBase.createTime, updateTime = toolBase.updateTime ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt index f01feb8..9efcb6f 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolCategoryConverter.kt @@ -25,7 +25,7 @@ object ToolCategoryConverter { fun toolCategoryToToolCategoryVo(toolCategory: ToolCategory) = ToolCategoryVo( id = toolCategory.id, name = toolCategory.name, - enable = toolCategory.enable == 1, + enable = toolCategory.enable?.let { it == 1}, createTime = toolCategory.createTime, updateTime = toolCategory.updateTime ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt index 19f54ba..249b69d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolConverter.kt @@ -42,7 +42,7 @@ object ToolConverter { review = tool.review, createTime = tool.createTime, updateTime = tool.updateTime, - favorite = tool.favorite == 1 + favorite = tool.favorite?.let { it == 1} ) /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt index ccb8233..7fb5663 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/converter/tool/ToolTemplateConverter.kt @@ -31,7 +31,7 @@ object ToolTemplateConverter { source = toolTemplate.source?.let(ToolDataConverter::toolDataToToolDataVo), platform = toolTemplate.platform, entryPoint = toolTemplate.entryPoint, - enable = toolTemplate.enable == 1, + enable = toolTemplate.enable?.let { it == 1}, createTime = toolTemplate.createTime, updateTime = toolTemplate.updateTime ) @@ -72,7 +72,7 @@ object ToolTemplateConverter { source = ToolDataVo(id = toolTemplate.sourceId, data = null, createTime = null, updateTime = null), platform = toolTemplate.platform, entryPoint = toolTemplate.entryPoint, - enable = toolTemplate.enable == 1, + enable = toolTemplate.enable?.let { it == 1}, createTime = toolTemplate.createTime, updateTime = toolTemplate.updateTime ) @@ -99,7 +99,7 @@ object ToolTemplateConverter { source = toolTemplate.source?.let(ToolDataConverter::toolDataToToolDataVo), platform = toolTemplate.platform, entryPoint = toolTemplate.entryPoint, - enable = toolTemplate.enable == 1, + enable = toolTemplate.enable?.let { it == 1}, createTime = toolTemplate.createTime, updateTime = toolTemplate.updateTime ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SensitiveWordVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SensitiveWordVo.kt index 926e4e1..5b547fc 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SensitiveWordVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/system/SensitiveWordVo.kt @@ -48,5 +48,5 @@ data class SensitiveWordVo( * @since 1.0.0 */ @Schema(description = "启用") - val enable: Boolean + val enable: Boolean? ) From 8f29faa0f2f8b7c0e1822ee1198c20b740c4e675 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 7 May 2024 17:26:02 +0800 Subject: [PATCH 240/258] Revert "Refactor(KtWrapper): Simplify KtWrapper" This reverts commit ab20c45f1f4ae9a45af6996ee2c39e75cb84a43f. --- .../api/service/permission/impl/UserServiceImpl.kt | 6 +++--- .../api/service/system/impl/SensitiveWordServiceImpl.kt | 8 +++++--- .../oxygen/api/service/tool/impl/EditServiceImpl.kt | 9 +++++---- .../api/service/tool/impl/ManagementServiceImpl.kt | 6 +++--- .../oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt | 3 ++- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt index c82ddbf..059b22c 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/permission/impl/UserServiceImpl.kt @@ -106,7 +106,7 @@ class UserServiceImpl( if (!passwordEncoder.matches(userChangePasswordParam.originalPassword, user.password)) { throw BadCredentialsException("Passwords do not match") } - val wrapper = ktUpdate() + val wrapper = KtUpdateWrapper(User()) .eq(User::id, user.id) .set(User::password, passwordEncoder.encode(userChangePasswordParam.newPassword)) .set(User::credentialsExpiration, null) @@ -220,7 +220,7 @@ class UserServiceImpl( this.updateById(user) this.update( - ktUpdate().eq(User::id, user.id) + KtUpdateWrapper(User()).eq(User::id, user.id) .set( User::verify, if (userUpdateParam.verified || userUpdateParam.id == 0L) null else "${ @@ -282,7 +282,7 @@ class UserServiceImpl( val user = this.getById(userUpdatePasswordParam.id) user?.let { - val wrapper = ktUpdate() + val wrapper = KtUpdateWrapper(User()) .eq(User::id, user.id) .set(User::password, passwordEncoder.encode(userUpdatePasswordParam.password)) .set( diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt index a591550..f60c2f0 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/system/impl/SensitiveWordServiceImpl.kt @@ -1,5 +1,7 @@ package top.fatweb.oxygen.api.service.system.impl +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper +import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Propagation @@ -36,9 +38,9 @@ class SensitiveWordServiceImpl : ServiceImpl @Transactional(propagation = Propagation.REQUIRES_NEW) override fun update(sensitiveWordUpdateParam: SensitiveWordUpdateParam) { - this.update(ktUpdate().set(SensitiveWord::enable, false)) + this.update(KtUpdateWrapper(SensitiveWord()).set(SensitiveWord::enable, false)) this.update( - ktUpdate().`in`(SensitiveWord::id, sensitiveWordUpdateParam.ids) + KtUpdateWrapper(SensitiveWord()).`in`(SensitiveWord::id, sensitiveWordUpdateParam.ids) .set(SensitiveWord::enable, true) ) } @@ -50,7 +52,7 @@ class SensitiveWordServiceImpl : ServiceImpl @Transactional(propagation = Propagation.REQUIRES_NEW) override fun checkSensitiveWord(str: String) { - this.list(ktQuery().eq(SensitiveWord::enable, 1)).map(SensitiveWord::word).forEach { + this.list(KtQueryWrapper(SensitiveWord()).eq(SensitiveWord::enable, 1)).map(SensitiveWord::word).forEach { it ?: return@forEach try { diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index 6007746..74e2208 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -1,6 +1,7 @@ package top.fatweb.oxygen.api.service.tool.impl import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper +import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.dao.DuplicateKeyException @@ -63,7 +64,7 @@ class EditServiceImpl( override fun create(toolCreateParam: ToolCreateParam): ToolVo { val template = this.getTemplate(toolCreateParam.templateId!!) baseMapper.selectOne( - ktQuery() + KtQueryWrapper(Tool()) .eq(Tool::toolId, toolCreateParam.toolId!!) .eq(Tool::authorId, WebUtil.getLoginUserId()!!) .eq(Tool::platform, template.platform) @@ -244,7 +245,7 @@ class EditServiceImpl( throw ToolHasBeenPublishedException() } - return update(ktUpdate().eq(Tool::id, id).set(Tool::review, Tool.ReviewType.PROCESSING)) + return update(KtUpdateWrapper(Tool()).eq(Tool::id, id).set(Tool::review, Tool.ReviewType.PROCESSING)) } override fun cancel(id: Long): Boolean { @@ -256,13 +257,13 @@ class EditServiceImpl( throw ToolNotUnderReviewException() } - return update(ktUpdate().eq(Tool::id, id).set(Tool::review, Tool.ReviewType.NONE)) + return update(KtUpdateWrapper(Tool()).eq(Tool::id, id).set(Tool::review, Tool.ReviewType.NONE)) } @Transactional override fun delete(id: Long): Boolean { val tool = baseMapper.selectOne( - ktQuery().eq(Tool::id, id) + KtQueryWrapper(Tool()).eq(Tool::id, id) .eq(Tool::authorId, WebUtil.getLoginUserId()!!) ) ?: throw NoRecordFoundException() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt index ae18c7c..4810eae 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ManagementServiceImpl.kt @@ -77,7 +77,7 @@ class ManagementServiceImpl( ) this.update( - ktUpdate() + KtUpdateWrapper(Tool()) .eq(Tool::id, id) .set(Tool::review, Tool.ReviewType.PASS) .set(Tool::publish, LocalDateTime.now(ZoneOffset.UTC).toInstant(ZoneOffset.UTC).toEpochMilli()) @@ -93,7 +93,7 @@ class ManagementServiceImpl( } this.update( - ktUpdate() + KtUpdateWrapper(Tool()) .eq(Tool::id, id) .set(Tool::review, Tool.ReviewType.REJECT) ) @@ -108,7 +108,7 @@ class ManagementServiceImpl( } this.update( - ktUpdate() + KtUpdateWrapper(Tool()) .eq(Tool::id, id) .set(Tool::review, Tool.ReviewType.REJECT) ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt index c077601..237ba10 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/ToolBaseServiceImpl.kt @@ -1,5 +1,6 @@ package top.fatweb.oxygen.api.service.tool.impl +import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import org.springframework.stereotype.Service @@ -44,7 +45,7 @@ class ToolBaseServiceImpl( return ToolBaseConverter.toolBasePageToToolBasePageVo( this.page( basePage, - ktQuery().`in`( + KtQueryWrapper(ToolBase()).`in`( !toolBaseGetParam?.platform.isNullOrBlank(), ToolBase::platform, toolBaseGetParam?.platform?.split(",") From 491e6cf1cd043d49dd2d5838c7f44e0b581ceed2 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 10 May 2024 05:06:52 +0800 Subject: [PATCH 241/258] Refactor(Platform): Move enum class Platform to separate file --- .../oxygen/api/controller/tool/EditController.kt | 6 +++--- .../top/fatweb/oxygen/api/entity/tool/Platform.kt | 14 ++++++++++++++ .../top/fatweb/oxygen/api/entity/tool/Tool.kt | 4 ++-- .../top/fatweb/oxygen/api/entity/tool/ToolBase.kt | 11 ----------- .../fatweb/oxygen/api/entity/tool/ToolTemplate.kt | 4 ++-- .../fatweb/oxygen/api/mapper/tool/EditMapper.kt | 5 +++-- .../oxygen/api/param/tool/ToolBaseAddParam.kt | 6 +++--- .../oxygen/api/param/tool/ToolUpgradeParam.kt | 6 +++--- .../fatweb/oxygen/api/service/tool/IEditService.kt | 10 +++++----- .../api/service/tool/impl/EditServiceImpl.kt | 4 ++-- .../top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt | 6 +++--- .../fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt | 6 +++--- .../kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt | 6 +++--- 13 files changed, 46 insertions(+), 42 deletions(-) create mode 100644 src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Platform.kt diff --git a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt index 86f8d4c..dec2efb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/controller/tool/EditController.kt @@ -7,7 +7,7 @@ import top.fatweb.oxygen.api.annotation.BaseController import top.fatweb.oxygen.api.annotation.Trim import top.fatweb.oxygen.api.entity.common.ResponseCode import top.fatweb.oxygen.api.entity.common.ResponseResult -import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.entity.tool.Platform import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.ToolCreateParam import top.fatweb.oxygen.api.param.tool.ToolUpdateParam @@ -40,7 +40,7 @@ class EditController( */ @Operation(summary = "获取模板") @GetMapping("/template") - fun getTemplate(platform: ToolBase.Platform): ResponseResult> = + fun getTemplate(platform: Platform): ResponseResult> = ResponseResult.databaseSuccess(data = editService.getTemplate(platform)) /** @@ -144,7 +144,7 @@ class EditController( @PathVariable username: String, @PathVariable toolId: String, @PathVariable ver: String, - platform: ToolBase.Platform + platform: Platform ): ResponseResult = ResponseResult.databaseSuccess( ResponseCode.DATABASE_SELECT_SUCCESS, diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Platform.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Platform.kt new file mode 100644 index 0000000..f959266 --- /dev/null +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Platform.kt @@ -0,0 +1,14 @@ +package top.fatweb.oxygen.api.entity.tool + +import com.baomidou.mybatisplus.annotation.EnumValue +import com.fasterxml.jackson.annotation.JsonValue + +/** + * Platform enum + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + */ +enum class Platform(@field:EnumValue @field:JsonValue val code: String) { + WEB("WEB"), DESKTOP("DESKTOP"), ANDROID("ANDROID") +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt index 947f2d0..bef4466 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/Tool.kt @@ -66,10 +66,10 @@ class Tool : Serializable { * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 - * @see ToolBase.Platform + * @see Platform */ @TableField("platform") - var platform: ToolBase.Platform? = null + var platform: Platform? = null /** * Description diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt index 94765cf..a88745b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolBase.kt @@ -1,7 +1,6 @@ package top.fatweb.oxygen.api.entity.tool import com.baomidou.mybatisplus.annotation.* -import com.fasterxml.jackson.annotation.JsonValue import java.io.Serializable import java.time.LocalDateTime @@ -13,16 +12,6 @@ import java.time.LocalDateTime */ @TableName("t_b_tool_base") class ToolBase : Serializable { - /** - * Platform enum - * - * @author FatttSnake, fatttsnake@gmail.com - * @since 1.0.0 - */ - enum class Platform(@field:EnumValue @field:JsonValue val code: String) { - WEB("WEB"), DESKTOP("DESKTOP"), ANDROID("ANDROID") - } - /** * ID * diff --git a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt index d82358b..b2b5007 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/entity/tool/ToolTemplate.kt @@ -53,10 +53,10 @@ class ToolTemplate : Serializable { * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 - * @see ToolBase.Platform + * @see Platform */ @TableField("platform") - var platform: ToolBase.Platform? = null + var platform: Platform? = null /** * Entry point diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt index 7cc0da1..5f6bbcc 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/EditMapper.kt @@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper import com.baomidou.mybatisplus.core.metadata.IPage import org.apache.ibatis.annotations.Mapper import org.apache.ibatis.annotations.Param +import top.fatweb.oxygen.api.entity.tool.Platform import top.fatweb.oxygen.api.entity.tool.Tool -import top.fatweb.oxygen.api.entity.tool.ToolBase import top.fatweb.oxygen.api.entity.tool.ToolTemplate /** @@ -75,13 +75,14 @@ interface EditMapper : BaseMapper { * @return List of tool object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 + * @see Platform * @see Tool */ fun selectDetail( @Param("username") username: String, @Param("toolId") toolId: String, @Param("ver") ver: String, - @Param("platform") platform: ToolBase.Platform, + @Param("platform") platform: Platform, @Param("operator") operator: String? ): Tool? } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt index 9a3bef3..a221097 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolBaseAddParam.kt @@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.NotNull import top.fatweb.oxygen.api.annotation.Trim -import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.entity.tool.Platform /** * Add tool base parameters @@ -30,9 +30,9 @@ data class ToolBaseAddParam( * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 - * @see ToolBase.Platform + * @see Platform */ @Schema(description = "平台") @field:NotNull(message = "Platform can not be null") - val platform: ToolBase.Platform? + val platform: Platform? ) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt index 1863b31..d4d5b61 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolUpgradeParam.kt @@ -5,7 +5,7 @@ import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.NotNull import jakarta.validation.constraints.Pattern import top.fatweb.oxygen.api.annotation.Trim -import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.entity.tool.Platform /** * Upgrade tool parameters @@ -36,11 +36,11 @@ data class ToolUpgradeParam( * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 - * @see ToolBase.Platform + * @see Platform */ @Schema(description = "平台") @field:NotNull(message = "Platform can not be null") - val platform: ToolBase.Platform?, + val platform: Platform?, /** diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt index e9b64bc..32c7f60 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/IEditService.kt @@ -1,8 +1,8 @@ package top.fatweb.oxygen.api.service.tool import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.oxygen.api.entity.tool.Platform import top.fatweb.oxygen.api.entity.tool.Tool -import top.fatweb.oxygen.api.entity.tool.ToolBase import top.fatweb.oxygen.api.param.PageSortParam import top.fatweb.oxygen.api.param.tool.ToolCreateParam import top.fatweb.oxygen.api.param.tool.ToolUpdateParam @@ -27,10 +27,10 @@ interface IEditService : IService { * @return List of ToolTemplateVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 - * @see ToolBase.Platform + * @see Platform * @see ToolTemplateVo */ - fun getTemplate(platform: ToolBase.Platform): List + fun getTemplate(platform: Platform): List /** * Get tool template by ID @@ -122,10 +122,10 @@ interface IEditService : IService { * @return ToolVo object * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 - * @see ToolBase.Platform + * @see Platform * @see ToolVo */ - fun detail(username: String, toolId: String, ver: String, platform: ToolBase.Platform): ToolVo + fun detail(username: String, toolId: String, ver: String, platform: Platform): ToolVo /** * Submit tool review diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt index 74e2208..e1b161b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/EditServiceImpl.kt @@ -41,7 +41,7 @@ class EditServiceImpl( private val toolDataService: IToolDataService, private val rToolCategoryService: IRToolCategoryService ) : ServiceImpl(), IEditService { - override fun getTemplate(platform: ToolBase.Platform): List = + override fun getTemplate(platform: Platform): List = toolTemplateService.list( KtQueryWrapper(ToolTemplate()) .eq(ToolTemplate::platform, platform) @@ -227,7 +227,7 @@ class EditServiceImpl( return ToolConverter.toolPageToToolPageVo(toolPage) } - override fun detail(username: String, toolId: String, ver: String, platform: ToolBase.Platform): ToolVo { + override fun detail(username: String, toolId: String, ver: String, platform: Platform): ToolVo { if (username == "!" && WebUtil.getLoginUserId() == null) { throw NoRecordFoundException() } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt index 25278c1..eee7000 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolBaseVo.kt @@ -3,7 +3,7 @@ package top.fatweb.oxygen.api.vo.tool import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.entity.tool.Platform import java.time.LocalDateTime /** @@ -55,10 +55,10 @@ data class ToolBaseVo( * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 - * @see ToolBase.Platform + * @see Platform */ @Schema(description = "平台") - val platform: ToolBase.Platform?, + val platform: Platform?, /** * Compiled diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt index cad88bb..e5d8e4a 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolTemplateVo.kt @@ -3,7 +3,7 @@ package top.fatweb.oxygen.api.vo.tool import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema -import top.fatweb.oxygen.api.entity.tool.ToolBase +import top.fatweb.oxygen.api.entity.tool.Platform import java.time.LocalDateTime /** @@ -55,10 +55,10 @@ data class ToolTemplateVo( * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 - * @see ToolBase.Platform + * @see Platform */ @Schema(description = "平台") - val platform: ToolBase.Platform?, + val platform: Platform?, /** * Entry point diff --git a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt index 3be8f47..4515dc2 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/vo/tool/ToolVo.kt @@ -3,8 +3,8 @@ package top.fatweb.oxygen.api.vo.tool import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema +import top.fatweb.oxygen.api.entity.tool.Platform import top.fatweb.oxygen.api.entity.tool.Tool -import top.fatweb.oxygen.api.entity.tool.ToolBase import top.fatweb.oxygen.api.vo.permission.UserWithInfoVo import java.time.LocalDateTime @@ -56,10 +56,10 @@ data class ToolVo( * * @author FatttSnake, fatttsnake@gmail.com * @since 1.0.0 - * @see ToolBase.Platform + * @see Platform */ @Schema(description = "平台") - val platform: ToolBase.Platform?, + val platform: Platform?, /** * Description From b7f0222e367ac7a00168fa93bd9f4e5b245a4843 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 10 May 2024 05:13:35 +0800 Subject: [PATCH 242/258] Feat(Store): Support specify platform to search tools --- .../fatweb/oxygen/api/mapper/tool/StoreMapper.kt | 7 ++++++- .../oxygen/api/param/tool/ToolStoreGetParam.kt | 13 ++++++++++++- .../api/service/tool/impl/StoreServiceImpl.kt | 3 ++- src/main/resources/mapper/tool/StoreMapper.xml | 3 +++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt index 7efdf91..c51d574 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper import com.baomidou.mybatisplus.core.metadata.IPage import org.apache.ibatis.annotations.Mapper import org.apache.ibatis.annotations.Param +import top.fatweb.oxygen.api.entity.tool.Platform import top.fatweb.oxygen.api.entity.tool.Tool /** @@ -26,7 +27,11 @@ interface StoreMapper : BaseMapper { * @since 1.0.0 * @see IPage */ - fun selectAuthorToolIdPage(page: IPage, @Param("searchValue") searchValue: String?): IPage + fun selectAuthorToolIdPage( + page: IPage, + @Param("searchValue") searchValue: String?, + @Param("platform") platform: Platform + ): IPage /** * Select author and tool ID by username in page diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt index f127bcb..413a893 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt @@ -2,6 +2,7 @@ package top.fatweb.oxygen.api.param.tool import io.swagger.v3.oas.annotations.media.Schema import top.fatweb.oxygen.api.annotation.Trim +import top.fatweb.oxygen.api.entity.tool.Platform import top.fatweb.oxygen.api.param.PageSortParam /** @@ -21,5 +22,15 @@ data class ToolStoreGetParam( */ @Trim @Schema(description = "查询内容", example = "ToolName") - var searchValue: String? + var searchValue: String?, + + /** + * Platform to search for + * + * @author FatttSnake, fatttsnake@gmail.com + * @since 1.0.0 + * @see Platform + */ + @Schema(description = "指定平台", example = "DESKTOP") + val platform: Platform ) : PageSortParam() diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt index 18fb21a..18db2eb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt @@ -39,7 +39,8 @@ class StoreServiceImpl( val toolIdsPage = Page(toolStoreGetParam.currentPage, 20) toolIdsPage.setOptimizeCountSql(false) - val toolIdsIPage = baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam.searchValue) + val toolIdsIPage = + baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam.searchValue, toolStoreGetParam.platform) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId())) diff --git a/src/main/resources/mapper/tool/StoreMapper.xml b/src/main/resources/mapper/tool/StoreMapper.xml index ca63d96..c526555 100644 --- a/src/main/resources/mapper/tool/StoreMapper.xml +++ b/src/main/resources/mapper/tool/StoreMapper.xml @@ -20,6 +20,9 @@ or tk.keyword like concat('%', #{searchValue}, '%') ) + + and temp1.platform = #{platform} + From 0c9de223fb64a9c0eacd97a66677d5c53a12e5a5 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 10 May 2024 05:33:23 +0800 Subject: [PATCH 243/258] Fix(Store): Fix specify platform to search tools --- .../top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt | 12 ++++++------ .../oxygen/api/service/tool/impl/StoreServiceImpl.kt | 4 ++-- src/main/resources/mapper/tool/StoreMapper.xml | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt index c51d574..8224526 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/mapper/tool/StoreMapper.kt @@ -27,11 +27,7 @@ interface StoreMapper : BaseMapper { * @since 1.0.0 * @see IPage */ - fun selectAuthorToolIdPage( - page: IPage, - @Param("searchValue") searchValue: String?, - @Param("platform") platform: Platform - ): IPage + fun selectAuthorToolIdPage(page: IPage, @Param("searchValue") searchValue: String?): IPage /** * Select author and tool ID by username in page @@ -54,7 +50,11 @@ interface StoreMapper : BaseMapper { * @since 1.0.0 * @see Tool */ - fun selectListByAuthorToolIds(@Param("ids") ids: List, @Param("operator") operator: Long?): List + fun selectListByAuthorToolIds( + @Param("ids") ids: List, + @Param("operator") operator: Long?, + @Param("platform") platform: Platform? = null + ): List /** * Count published tool by username and toolId diff --git a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt index 18db2eb..809fe1d 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/service/tool/impl/StoreServiceImpl.kt @@ -40,10 +40,10 @@ class StoreServiceImpl( toolIdsPage.setOptimizeCountSql(false) val toolIdsIPage = - baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam.searchValue, toolStoreGetParam.platform) + baseMapper.selectAuthorToolIdPage(toolIdsPage, toolStoreGetParam.searchValue) val toolPage = Page(toolIdsIPage.current, toolIdsIPage.size, toolIdsIPage.total) if (toolIdsIPage.total > 0) { - toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId())) + toolPage.setRecords(baseMapper.selectListByAuthorToolIds(toolIdsIPage.records, WebUtil.getLoginUserId(), toolStoreGetParam.platform)) } return ToolConverter.toolPageToToolPageVo(toolPage) diff --git a/src/main/resources/mapper/tool/StoreMapper.xml b/src/main/resources/mapper/tool/StoreMapper.xml index c526555..dc71b72 100644 --- a/src/main/resources/mapper/tool/StoreMapper.xml +++ b/src/main/resources/mapper/tool/StoreMapper.xml @@ -20,9 +20,6 @@ or tk.keyword like concat('%', #{searchValue}, '%') ) - - and temp1.platform = #{platform} - @@ -110,6 +107,9 @@ on tbtf.user_id = #{operator} and tbtf.author_id = tbtm.author_id and tbtf.tool_id = tbtm.tool_id and tbtm.rn = 1 + + and tbtm.platform = #{platform} + #{item} From 565bac9ebca6b18bc8af4c953947597b669efb4c Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 10 May 2024 15:00:05 +0800 Subject: [PATCH 244/258] Fix(ToolStore): Fix the bug that parameter platform is non-null --- .../top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt index 413a893..5e645af 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/param/tool/ToolStoreGetParam.kt @@ -32,5 +32,5 @@ data class ToolStoreGetParam( * @see Platform */ @Schema(description = "指定平台", example = "DESKTOP") - val platform: Platform + val platform: Platform? ) : PageSortParam() From 0af16602152e126b3dee2b09892c4412e59f0e6b Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Sun, 12 May 2024 04:44:24 +0800 Subject: [PATCH 245/258] Fix(ManagementMapper): Fix the bug that query duplicate ID --- src/main/resources/mapper/tool/ManagementMapper.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/mapper/tool/ManagementMapper.xml b/src/main/resources/mapper/tool/ManagementMapper.xml index a5f7b2f..85c7beb 100644 --- a/src/main/resources/mapper/tool/ManagementMapper.xml +++ b/src/main/resources/mapper/tool/ManagementMapper.xml @@ -64,7 +64,7 @@