Complete core functions #9

Merged
FatttSnake merged 171 commits from FatttSnake into dev 2024-02-23 11:56:35 +08:00
7 changed files with 43 additions and 12 deletions
Showing only changes of commit d4e4ec6cbc - Show all commits

View File

@@ -2,10 +2,7 @@ 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.*
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 {
@@ -30,6 +27,13 @@ object UserConverter {
lastLoginIp = user.lastLoginIp, lastLoginIp = user.lastLoginIp,
createTime = user.createTime, createTime = user.createTime,
updateTime = user.updateTime, updateTime = user.updateTime,
modules = user.modules?.map {
ModuleVo(
id = it.id,
name = it.name,
powerId = it.powerId
)
},
menus = user.menus?.map { menus = user.menus?.map {
MenuVo( MenuVo(
id = it.id, id = it.id,

View File

@@ -110,6 +110,9 @@ class User() : Serializable {
@TableField(exist = false) @TableField(exist = false)
var groups: List<Group>? = null var groups: List<Group>? = null
@TableField(exist = false)
var modules: List<Module>? = null
@TableField(exist = false) @TableField(exist = false)
var menus: List<Menu>? = null var menus: List<Menu>? = null

View File

@@ -57,7 +57,7 @@ class AuthenticationServiceImpl(
val redisKey = "${SecurityConstants.jwtIssuer}_login:" + jwt val redisKey = "${SecurityConstants.jwtIssuer}_login:" + jwt
redisUtil.setObject(redisKey, loginUser, SecurityConstants.redisTtl, SecurityConstants.redisTtlUnit) redisUtil.setObject(redisKey, loginUser, SecurityConstants.redisTtl, SecurityConstants.redisTtlUnit)
return LoginVo(jwt, loginUser.user.lastLoginTime, loginUser.user.lastLoginIp) return LoginVo(jwt, loginUser.user.currentLoginTime, loginUser.user.currentLoginIp)
} }
override fun logout(token: String): Boolean = redisUtil.delObject("${SecurityConstants.jwtIssuer}_login:" + token) override fun logout(token: String): Boolean = redisUtil.delObject("${SecurityConstants.jwtIssuer}_login:" + token)

View File

@@ -4,10 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import top.fatweb.api.entity.permission.User import top.fatweb.api.entity.permission.User
import top.fatweb.api.mapper.permission.UserMapper import top.fatweb.api.mapper.permission.UserMapper
import top.fatweb.api.service.permission.IElementService import top.fatweb.api.service.permission.*
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 import top.fatweb.api.util.WebUtil
/** /**
@@ -20,6 +17,7 @@ import top.fatweb.api.util.WebUtil
*/ */
@Service @Service
class UserServiceImpl( class UserServiceImpl(
private val moduleService: IModuleService,
private val menuService: IMenuService, private val menuService: IMenuService,
private val elementService: IElementService, private val elementService: IElementService,
private val operationService: IOperationService private val operationService: IOperationService
@@ -29,6 +27,7 @@ class UserServiceImpl(
user ?: let { return null } user ?: let { return null }
if (user.id == 0L) { if (user.id == 0L) {
user.modules = moduleService.list()
user.menus = menuService.list() user.menus = menuService.list()
user.elements = elementService.list() user.elements = elementService.list()
user.operations = operationService.list() user.operations = operationService.list()

View File

@@ -0,0 +1,14 @@
package top.fatweb.api.vo.authentication
import io.swagger.v3.oas.annotations.media.Schema
@Schema(description = "模块返回参数")
data class ModuleVo(
val id: Long?,
@Schema(description = "模块名", example = "系统")
val name: String?,
@Schema(description = "权限 ID")
val powerId: Long?
)

View File

@@ -40,6 +40,9 @@ data class UserInfoVo(
@Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z") @Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z")
val updateTime: LocalDateTime?, val updateTime: LocalDateTime?,
@Schema(description = "模块列表")
val modules: List<ModuleVo>?,
@Schema(description = "菜单列表") @Schema(description = "菜单列表")
val menus: List<MenuVo>?, val menus: List<MenuVo>?,

View File

@@ -17,6 +17,9 @@
t_user.update_time as user_update_time, t_user.update_time as user_update_time,
t_user.deleted as user_deleted, t_user.deleted as user_deleted,
t_user.version as user_version, t_user.version as user_version,
tmo.id as module_id,
tmo.name as module_name,
tmo.power_id as module_power_id,
tm.id as menu_id, tm.id as menu_id,
tm.name as menu_name, tm.name as menu_name,
tm.url as menu_url, tm.url as menu_url,
@@ -31,8 +34,7 @@
t.name as operation_name, t.name as operation_name,
t.code as operation_code, t.code as operation_code,
t.power_id as operation_power_id, t.power_id as operation_power_id,
t.element_id as operation_element_id, t.element_id as operation_element_id
t.parent_id as operation_parent_id
from t_user from t_user
left join (select * from t_user_group where deleted = 0) as tug on t_user.id = tug.user_id left join (select * from t_user_group where deleted = 0) as tug on t_user.id = tug.user_id
left join (select * from t_group where deleted = 0 and enable = 1) as tg on tg.id = tug.group_id left join (select * from t_group where deleted = 0 and enable = 1) as tg on tg.id = tug.group_id
@@ -42,6 +44,7 @@
on tr.id = trg.role_id or tr.id = tur.role_id on tr.id = trg.role_id or tr.id = tur.role_id
left join (select * from t_power_role where deleted = 0) as tpr on tr.id = tpr.role_id left join (select * from t_power_role where deleted = 0) as tpr on tr.id = tpr.role_id
left join t_power as tp on tp.id = tpr.power_id left join t_power as tp on tp.id = tpr.power_id
left join t_module as tmo on tp.id = tmo.power_id
left join t_menu as tm on tp.id = tm.power_id left join t_menu as tm on tp.id = tm.power_id
left join t_element as te on tp.id = te.power_id left join t_element as te on tp.id = te.power_id
left join t_operation as t on tp.id = t.power_id left join t_operation as t on tp.id = t.power_id
@@ -68,12 +71,18 @@
<resultMap id="userWithPowerMap" type="user" extends="userBase"> <resultMap id="userWithPowerMap" type="user" extends="userBase">
<result property="password" column="user_password"/> <result property="password" column="user_password"/>
<collection property="modules" ofType="module">
<id property="id" column="module_id"/>
<result property="name" column="module_name"/>
<result property="powerId" column="module_power_id"/>
</collection>
<collection property="menus" ofType="menu"> <collection property="menus" ofType="menu">
<id property="id" column="menu_id"/> <id property="id" column="menu_id"/>
<result property="name" column="menu_name"/> <result property="name" column="menu_name"/>
<result property="url" column="menu_url"/> <result property="url" column="menu_url"/>
<result property="powerId" column="menu_power_id"/> <result property="powerId" column="menu_power_id"/>
<result property="parentId" column="menu_parent_id"/> <result property="parentId" column="menu_parent_id"/>
<result property="moduleId" column="menu_module_id"/>
</collection> </collection>
<collection property="elements" ofType="element"> <collection property="elements" ofType="element">
<id property="id" column="element_id"/> <id property="id" column="element_id"/>
@@ -88,7 +97,6 @@
<result property="code" column="operation_code"/> <result property="code" column="operation_code"/>
<result property="powerId" column="operation_power_id"/> <result property="powerId" column="operation_power_id"/>
<result property="elementId" column="operation_element_id"/> <result property="elementId" column="operation_element_id"/>
<result property="parentId" column="operation_parent_id"/>
</collection> </collection>
</resultMap> </resultMap>
</mapper> </mapper>