From 175e2388526d68c115e70020664f3d9c8f36f022 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Fri, 27 Sep 2024 08:55:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=96=B0=E5=A2=9E):=20=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/service/context/BaseContext.kt | 2 +- .../dao/pojo/constant/RedisUserConstant.kt | 20 ++++--------------- .../cn/bunny/dao/pojo/enums/OperationTypes.kt | 8 -------- .../bunny/dao/pojo/result/ResultCodeEnum.kt | 2 +- .../services/controller/RouterController.java | 2 +- .../services/controller/UserController.kt | 7 +++++++ .../bunny/services/service/UserService.java | 5 +++++ .../services/service/impl/UserServiceImpl.kt | 9 +++++++++ 8 files changed, 28 insertions(+), 27 deletions(-) delete mode 100644 dao/src/main/kotlin/cn/bunny/dao/pojo/enums/OperationTypes.kt diff --git a/common/common-service/src/main/kotlin/cn/bunny/common/service/context/BaseContext.kt b/common/common-service/src/main/kotlin/cn/bunny/common/service/context/BaseContext.kt index b9a4045..cd9eaf3 100644 --- a/common/common-service/src/main/kotlin/cn/bunny/common/service/context/BaseContext.kt +++ b/common/common-service/src/main/kotlin/cn/bunny/common/service/context/BaseContext.kt @@ -30,7 +30,7 @@ open class BaseContext { } @JvmStatic - fun getLoginVo(): LoginVo { + fun getLoginVo(): LoginVo? { return loginVo.get() } diff --git a/dao/src/main/kotlin/cn/bunny/dao/pojo/constant/RedisUserConstant.kt b/dao/src/main/kotlin/cn/bunny/dao/pojo/constant/RedisUserConstant.kt index ad08558..56ae7b9 100644 --- a/dao/src/main/kotlin/cn/bunny/dao/pojo/constant/RedisUserConstant.kt +++ b/dao/src/main/kotlin/cn/bunny/dao/pojo/constant/RedisUserConstant.kt @@ -9,13 +9,12 @@ import lombok.Data class RedisUserConstant { companion object { // 管理员用户 - private const val ADMIN_LOGIN_INFO_PREFIX: String = "ADMIN::LOGIN_INFO::" - private const val ADMIN_EMAIL_CODE_PREFIX: String = "ADMIN::EMAIL_CODE::" + private const val ADMIN_LOGIN_INFO_PREFIX: String = "admin::login_info::" + private const val ADMIN_EMAIL_CODE_PREFIX: String = "admin::email_code::" // 普通用户 - private const val USER_LOGIN_INFO_PREFIX: String = "USER::LOGIN_INFO::" - private const val USER_EMAIL_CODE_PREFIX: String = "USER::EMAIL_CODE::" - private const val USER_DO_LIKE_PREFIX: String = "USER::doLike::" + private const val USER_LOGIN_INFO_PREFIX: String = "user::login_info::" + private const val USER_EMAIL_CODE_PREFIX: String = "user::email_code::" /** * * 管理员用户登录信息 @@ -60,16 +59,5 @@ class RedisUserConstant { fun getUserEmailCodePrefix(user: String): String { return USER_EMAIL_CODE_PREFIX + user } - - /** - * * 用户点赞操作 - * - * @param user 用户名 - * @return 用户点赞key - */ - @JvmStatic - fun getUserDoLikePrefix(user: String): String { - return USER_DO_LIKE_PREFIX + user - } } } diff --git a/dao/src/main/kotlin/cn/bunny/dao/pojo/enums/OperationTypes.kt b/dao/src/main/kotlin/cn/bunny/dao/pojo/enums/OperationTypes.kt deleted file mode 100644 index 16f5854..0000000 --- a/dao/src/main/kotlin/cn/bunny/dao/pojo/enums/OperationTypes.kt +++ /dev/null @@ -1,8 +0,0 @@ -package cn.bunny.dao.pojo.enums - -/** - * 数据库操作类型 - */ -enum class OperationTypes { - UPDATE, INSERT -} diff --git a/dao/src/main/kotlin/cn/bunny/dao/pojo/result/ResultCodeEnum.kt b/dao/src/main/kotlin/cn/bunny/dao/pojo/result/ResultCodeEnum.kt index 8e95e84..56106bd 100644 --- a/dao/src/main/kotlin/cn/bunny/dao/pojo/result/ResultCodeEnum.kt +++ b/dao/src/main/kotlin/cn/bunny/dao/pojo/result/ResultCodeEnum.kt @@ -9,7 +9,7 @@ import lombok.Getter enum class ResultCodeEnum(val code: Int, val message: String) { // 成功操作 200 SUCCESS(200, "操作成功"), - SUCCESS_LOGOUT(200, "退出成功"), + LOGOUT_SUCCESS(200, "退出成功"), EMAIL_CODE_SEND_SUCCESS(200, "邮箱验证码已发送"), // 验证错误 201 diff --git a/services/src/main/kotlin/cn/bunny/services/controller/RouterController.java b/services/src/main/kotlin/cn/bunny/services/controller/RouterController.java index 11849c5..4d13fcf 100644 --- a/services/src/main/kotlin/cn/bunny/services/controller/RouterController.java +++ b/services/src/main/kotlin/cn/bunny/services/controller/RouterController.java @@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RestController; */ @Tag(name = "系统路由", description = "系统路由相关接口") @RestController -@RequestMapping("/router") +@RequestMapping("admin/router") public class RouterController { } diff --git a/services/src/main/kotlin/cn/bunny/services/controller/UserController.kt b/services/src/main/kotlin/cn/bunny/services/controller/UserController.kt index 38fb033..9835c09 100644 --- a/services/src/main/kotlin/cn/bunny/services/controller/UserController.kt +++ b/services/src/main/kotlin/cn/bunny/services/controller/UserController.kt @@ -43,4 +43,11 @@ class UserController { val vo: RefreshTokenVo = userService.refreshToken(dto) return Result.success(vo) } + + @Operation(summary = "退出登录", description = "退出登录") + @PostMapping("logOut") + fun logOut(): Result { + userService.logOut() + return Result.success(ResultCodeEnum.LOGOUT_SUCCESS) + } } diff --git a/services/src/main/kotlin/cn/bunny/services/service/UserService.java b/services/src/main/kotlin/cn/bunny/services/service/UserService.java index 06e47c1..3a4ffa5 100644 --- a/services/src/main/kotlin/cn/bunny/services/service/UserService.java +++ b/services/src/main/kotlin/cn/bunny/services/service/UserService.java @@ -31,4 +31,9 @@ public interface UserService extends IService { */ @NotNull RefreshTokenVo refreshToken(@NotNull RefreshTokenDto dto); + + /** + * * 退出登录 + */ + void logOut(); } diff --git a/services/src/main/kotlin/cn/bunny/services/service/impl/UserServiceImpl.kt b/services/src/main/kotlin/cn/bunny/services/service/impl/UserServiceImpl.kt index c9c8047..664e388 100644 --- a/services/src/main/kotlin/cn/bunny/services/service/impl/UserServiceImpl.kt +++ b/services/src/main/kotlin/cn/bunny/services/service/impl/UserServiceImpl.kt @@ -1,5 +1,6 @@ package cn.bunny.services.service.impl +import cn.bunny.common.service.context.BaseContext import cn.bunny.common.service.exception.BunnyException import cn.bunny.common.service.utils.JwtHelper import cn.bunny.dao.dto.system.RefreshTokenDto @@ -89,5 +90,13 @@ internal class UserServiceImpl : ServiceImpl(), UserSer return refreshTokenVo } + + /** + * * 退出登录 + */ + override fun logOut() { + val loginVo = BaseContext.getLoginVo() ?: throw BunnyException(ResultCodeEnum.FAIL_REQUEST_NOT_AUTH) + redisTemplate.delete(RedisUserConstant.getAdminLoginInfoPrefix(loginVo.username!!)) + } }