Add get user list controller

This commit is contained in:
2023-11-01 18:26:49 +08:00
parent a94bf94bc7
commit e5c71c8a51
18 changed files with 237 additions and 23 deletions

View File

@@ -43,7 +43,7 @@ class InitConfig(
}
val userInfo = UserInfo().apply {
userId = 0
nickName = AdminProperties.nickName
nickname = AdminProperties.nickname
email = AdminProperties.email
}

View File

@@ -6,7 +6,8 @@ import org.springframework.web.bind.annotation.RestController
import top.fatweb.api.converter.permission.UserConverter
import top.fatweb.api.entity.common.ResponseResult
import top.fatweb.api.service.permission.IUserService
import top.fatweb.api.vo.permission.UserWithInfoVo
import top.fatweb.api.vo.permission.UserWithPowerInfoVo
import top.fatweb.api.vo.permission.UserWithRoleInfoVo
/**
* <p>
@@ -22,10 +23,16 @@ class UserController(
private val userService: IUserService
) {
@GetMapping("info")
fun getInfo(): ResponseResult<UserWithInfoVo> {
fun getInfo(): ResponseResult<UserWithPowerInfoVo> {
userService.getInfo()?.let {
return ResponseResult.databaseSuccess(data = UserConverter.userToUserInfoVo(it))
return ResponseResult.databaseSuccess(data = UserConverter.userToUserWithPowerInfoVo(it))
} ?: let { return ResponseResult.databaseFail() }
}
@GetMapping
fun get(): ResponseResult<List<UserWithRoleInfoVo>> {
return ResponseResult.databaseSuccess(
data = userService.getList().map { UserConverter.userToUserWithRoleInfoVo(it) })
}
}

View File

@@ -14,7 +14,7 @@ object UserConverter {
return user
}
fun userToUserInfoVo(user: User) = UserWithInfoVo(
fun userToUserWithPowerInfoVo(user: User) = UserWithPowerInfoVo(
id = user.id,
username = user.username,
locking = user.locking?.let { it == 1 },
@@ -30,7 +30,7 @@ object UserConverter {
userInfo = user.userInfo?.let { UserInfoVo(
id = it.id,
userId = it.userId,
nickName = it.nickName,
nickname = it.nickname,
avatar = it.avatar,
email = it.email,
createTime = it.createTime,
@@ -71,4 +71,42 @@ object UserConverter {
)
}
)
fun userToUserWithRoleInfoVo(user: User) = UserWithRoleInfoVo(
id = user.id,
username = user.username,
locking = user.locking?.let { it == 1 },
expiration = user.expiration,
credentialsExpiration = user.credentialsExpiration,
enable = user.enable?.let { it == 1 },
currentLoginTime = user.currentLoginTime,
currentLoginIp = user.currentLoginIp,
lastLoginTime = user.lastLoginTime,
lastLoginIp = user.lastLoginIp,
createTime = user.createTime,
updateTime = user.updateTime,
userInfo = user.userInfo?.let { UserInfoVo(
id = it.id,
userId = it.userId,
nickname = it.nickname,
avatar = it.avatar,
email = it.email,
createTime = it.createTime,
updateTime = it.updateTime
) },
roles = user.roles?.map {
RoleVo(
id = it.id,
name = it.name,
enable = it.enable == 1
)
},
groups = user.groups?.map {
GroupVo(
id = it.id,
name = it.name,
enable = it.enable == 1
)
}
)
}

View File

@@ -24,8 +24,8 @@ class UserInfo : Serializable {
/**
* 昵称
*/
@TableField("nick_name")
var nickName: String? = null
@TableField("nickname")
var nickname: String? = null
/**
* 头像
@@ -60,6 +60,6 @@ class UserInfo : Serializable {
var version: Int? = null
override fun toString(): String {
return "UserInfo(id=$id, userId=$userId, nickName=$nickName, avatar=$avatar, email=$email, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)"
return "UserInfo(id=$id, userId=$userId, nickname=$nickname, avatar=$avatar, email=$email, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)"
}
}

View File

@@ -15,5 +15,7 @@ import top.fatweb.api.entity.permission.User
*/
@Mapper
interface UserMapper : BaseMapper<User> {
fun getOneWithPowerByUsername(@Param("username")username: String): User?
fun getOneWithPowerInfoByUsername(@Param("username")username: String): User?
fun getListWithRoleInfo(): List<User>
}

View File

@@ -8,6 +8,6 @@ import org.springframework.stereotype.Component
object AdminProperties {
var username = "admin"
var password: String? = null
var nickName = "Administrator"
var nickname = "Administrator"
var email = "admin@fatweb.top"
}

View File

@@ -15,4 +15,6 @@ interface IUserService : IService<User> {
fun getUserWithPower(username: String): User?
fun getInfo(): User?
fun getList(): List<User>
}

View File

@@ -23,7 +23,7 @@ class UserServiceImpl(
private val operationService: IOperationService
) : ServiceImpl<UserMapper, User>(), IUserService {
override fun getUserWithPower(username: String): User? {
val user = baseMapper.getOneWithPowerByUsername(username)
val user = baseMapper.getOneWithPowerInfoByUsername(username)
user ?: let { return null }
if (user.id == 0L) {
@@ -38,4 +38,5 @@ class UserServiceImpl(
override fun getInfo() = WebUtil.getLoginUsername()?.let { getUserWithPower(it) } ?: let { null }
override fun getList() = baseMapper.getListWithRoleInfo()
}

View File

@@ -0,0 +1,17 @@
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
@Schema(description = "用户组返回参数")
data class GroupVo(
@JsonSerialize(using = ToStringSerializer::class)
val id: Long?,
@Schema(description = "用户组名", example = "Group")
val name: String?,
@Schema(description = "启用", example = "true")
val enable: Boolean?
)

View File

@@ -0,0 +1,17 @@
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
@Schema(description = "角色返回参数")
data class RoleVo(
@JsonSerialize(using = ToStringSerializer::class)
val id: Long?,
@Schema(description = "角色名", example = "Role")
val name: String?,
@Schema(description = "启用", example = "true")
val enable: Boolean?
)

View File

@@ -2,7 +2,7 @@ package top.fatweb.api.vo.permission
import io.swagger.v3.oas.annotations.media.Schema
@Schema(description = "Token")
@Schema(description = "Token 返回参数")
data class TokenVo(
@Schema(
description = "Token",

View File

@@ -15,7 +15,7 @@ data class UserInfoVo(
val userId: Long?,
@Schema(description = "昵称", example = "User")
val nickName: String?,
val nickname: String?,
@Schema(description = "头像")
val avatar: String?,

View File

@@ -5,8 +5,8 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
import io.swagger.v3.oas.annotations.media.Schema
import java.time.LocalDateTime
@Schema(description = "获取用户信息返回参数")
data class UserWithInfoVo(
@Schema(description = "用户权限信息返回参数")
data class UserWithPowerInfoVo(
@JsonSerialize(using = ToStringSerializer::class)
val id: Long?,

View File

@@ -0,0 +1,54 @@
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
@Schema(description = "用户角色信息返回参数")
data class UserWithRoleInfoVo(
@JsonSerialize(using = ToStringSerializer::class)
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 currentLoginTime: LocalDateTime?,
@Schema(description = "当前登录 IP", example = "1.1.1.1")
val currentLoginIp: String?,
@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 userInfo: UserInfoVo?,
@Schema(description = "角色列表")
val roles: List<RoleVo>?,
@Schema(description = "用户组列表")
val groups: List<GroupVo>?
)