Add GetUserInfo
This commit is contained in:
@@ -3,7 +3,10 @@ package top.fatweb.api.controller.permission
|
|||||||
import org.springframework.web.bind.annotation.GetMapping
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
import org.springframework.web.bind.annotation.RestController
|
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.service.permission.IUserService
|
||||||
|
import top.fatweb.api.vo.authentication.UserInfoVo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -19,7 +22,10 @@ class UserController(
|
|||||||
private val userService: IUserService
|
private val userService: IUserService
|
||||||
) {
|
) {
|
||||||
@GetMapping("info")
|
@GetMapping("info")
|
||||||
fun getInfo() {
|
fun getInfo(): ResponseResult<UserInfoVo> {
|
||||||
|
userService.getInfo()?.let {
|
||||||
|
return ResponseResult.databaseSuccess(data = UserConverter.userToUserInfoVo(it))
|
||||||
|
} ?: let { return ResponseResult.databaseFail() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import top.fatweb.api.vo.PageVo
|
|||||||
import top.fatweb.api.vo.system.SysLogGetVo
|
import top.fatweb.api.vo.system.SysLogGetVo
|
||||||
|
|
||||||
object SysLogConverter {
|
object SysLogConverter {
|
||||||
fun sysLogPageToSysLogPageVo(syslogPage: IPage<SysLog>): PageVo<SysLogGetVo> = PageVo<SysLogGetVo>(
|
fun sysLogPageToSysLogPageVo(syslogPage: IPage<SysLog>): PageVo<SysLogGetVo> = PageVo(
|
||||||
syslogPage.total,
|
syslogPage.total,
|
||||||
syslogPage.pages,
|
syslogPage.pages,
|
||||||
syslogPage.size,
|
syslogPage.size,
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package top.fatweb.api.converter
|
|||||||
|
|
||||||
import top.fatweb.api.entity.permission.User
|
import top.fatweb.api.entity.permission.User
|
||||||
import top.fatweb.api.param.authentication.LoginParam
|
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 {
|
object UserConverter {
|
||||||
fun loginParamToUser(loginParam: LoginParam): User {
|
fun loginParamToUser(loginParam: LoginParam): User {
|
||||||
@@ -12,4 +16,45 @@ object UserConverter {
|
|||||||
|
|
||||||
return user
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,12 @@ class Element : Serializable {
|
|||||||
@TableField("power_id")
|
@TableField("power_id")
|
||||||
var powerId: Long? = null
|
var powerId: Long? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父ID
|
||||||
|
*/
|
||||||
|
@TableField("parent_id")
|
||||||
|
var parentId: Long? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单ID
|
* 菜单ID
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -14,5 +14,5 @@ import top.fatweb.api.entity.permission.User
|
|||||||
interface IUserService : IService<User> {
|
interface IUserService : IService<User> {
|
||||||
fun getUserWithPower(username: String): User?
|
fun getUserWithPower(username: String): User?
|
||||||
|
|
||||||
fun getInfo(): User
|
fun getInfo(): User?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import top.fatweb.api.service.permission.IElementService
|
|||||||
import top.fatweb.api.service.permission.IMenuService
|
import top.fatweb.api.service.permission.IMenuService
|
||||||
import top.fatweb.api.service.permission.IOperationService
|
import top.fatweb.api.service.permission.IOperationService
|
||||||
import top.fatweb.api.service.permission.IUserService
|
import top.fatweb.api.service.permission.IUserService
|
||||||
|
import top.fatweb.api.util.WebUtil
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -35,4 +36,7 @@ class UserServiceImpl(
|
|||||||
|
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getInfo() = WebUtil.getLoginUsername()?.let { getUserWithPower(it) } ?: let { null }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ object WebUtil {
|
|||||||
|
|
||||||
fun getLoginUserId() = getLoginUser()?.user?.id
|
fun getLoginUserId() = getLoginUser()?.user?.id
|
||||||
|
|
||||||
|
fun getLoginUsername() = getLoginUser()?.user?.username
|
||||||
|
|
||||||
fun getToken(tokenWithPrefix: String) = tokenWithPrefix.removePrefix(SecurityConstants.tokenPrefix)
|
fun getToken(tokenWithPrefix: String) = tokenWithPrefix.removePrefix(SecurityConstants.tokenPrefix)
|
||||||
|
|
||||||
fun getToken(request: HttpServletRequest) = getToken(request.getHeader(SecurityConstants.headerString))
|
fun getToken(request: HttpServletRequest) = getToken(request.getHeader(SecurityConstants.headerString))
|
||||||
|
|||||||
@@ -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?
|
||||||
|
)
|
||||||
20
src/main/kotlin/top/fatweb/api/vo/authentication/MenuVo.kt
Normal file
20
src/main/kotlin/top/fatweb/api/vo/authentication/MenuVo.kt
Normal file
@@ -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?
|
||||||
|
)
|
||||||
@@ -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?
|
||||||
|
)
|
||||||
@@ -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<MenuVo>?,
|
||||||
|
|
||||||
|
@Schema(description = "页面元素列表")
|
||||||
|
val elements: List<ElementVo>?,
|
||||||
|
|
||||||
|
@Schema(description = "功能列表")
|
||||||
|
val operations: List<OperationVo>?
|
||||||
|
)
|
||||||
@@ -2,8 +2,9 @@ drop table if exists t_element;
|
|||||||
|
|
||||||
create table if not exists t_element
|
create table if not exists t_element
|
||||||
(
|
(
|
||||||
id bigint not null primary key,
|
id bigint not null primary key,
|
||||||
name varchar(100) not null comment '元素名',
|
name varchar(100) not null comment '元素名',
|
||||||
power_id bigint not null comment '权限ID',
|
power_id bigint not null comment '权限ID',
|
||||||
menu_id bigint not null comment '菜单ID'
|
parent_id bigint not null comment '父ID',
|
||||||
|
menu_id bigint not null comment '菜单ID'
|
||||||
) comment '页面元素';
|
) comment '页面元素';
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
te.id as element_id,
|
te.id as element_id,
|
||||||
te.name as element_name,
|
te.name as element_name,
|
||||||
te.power_id as element_power_id,
|
te.power_id as element_power_id,
|
||||||
|
te.parent_id as element_parent_id,
|
||||||
te.menu_id as element_menu_id,
|
te.menu_id as element_menu_id,
|
||||||
t.id as operation_id,
|
t.id as operation_id,
|
||||||
t.name as operation_name,
|
t.name as operation_name,
|
||||||
@@ -74,6 +75,7 @@
|
|||||||
<id property="id" column="element_id"/>
|
<id property="id" column="element_id"/>
|
||||||
<result property="name" column="element_name"/>
|
<result property="name" column="element_name"/>
|
||||||
<result property="powerId" column="element_power_id"/>
|
<result property="powerId" column="element_power_id"/>
|
||||||
|
<result property="parentId" column="element_parent_id"/>
|
||||||
<result property="menuId" column="element_menu_id"/>
|
<result property="menuId" column="element_menu_id"/>
|
||||||
</collection>
|
</collection>
|
||||||
<collection property="operations" ofType="operation">
|
<collection property="operations" ofType="operation">
|
||||||
|
|||||||
Reference in New Issue
Block a user