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 @@ +