Offline user when power change

This commit is contained in:
2023-12-01 17:21:42 +08:00
parent 1ad38bf2a8
commit 95ea00e643
9 changed files with 128 additions and 54 deletions

View File

@@ -18,9 +18,13 @@ interface UserMapper : BaseMapper<User> {
fun selectPage(page: IPage<Long>, searchType: String, searchValue: String?, searchRegex: Boolean): IPage<Long>
fun selectListWithRoleInfoByIds(userIds: List<Long>): List<User>?
fun selectListWithRoleInfoByIds(userIds: List<Long>): List<User>
fun selectOneWithRoleInfoById(id: Long): User?
fun selectListWithInfo(): List<User>
fun selectIdsWithRoleIds(roleIds: List<Long>): List<Long>
fun selectIdsWithGroupIds(groupIds: List<Long>): List<Long>
}

View File

@@ -14,7 +14,7 @@ import jakarta.validation.constraints.NotNull
data class GroupUpdateParam(
@Schema(description = "用户组 ID")
@field:NotNull(message = "ID can not be null")
val id: Long,
val id: Long?,
@Schema(description = "用户组名称")
@field:NotBlank(message = "Name can not be blank")

View File

@@ -13,7 +13,7 @@ import jakarta.validation.constraints.NotNull
data class RoleChangeStatusParam(
@Schema(description = "角色 ID")
@field:NotNull(message = "Role id can not be null")
val id: Long,
val id: Long?,
@Schema(description = "启用", allowableValues = ["true", "false"], defaultValue = "true")
val enable: Boolean = true

View File

@@ -14,7 +14,7 @@ import jakarta.validation.constraints.NotNull
data class RoleUpdateParam(
@Schema(description = "角色 ID")
@field:NotNull(message = "Role id can not be null")
val id: Long,
val id: Long?,
@Schema(description = "角色名称")
@field:NotBlank(message = "Name can not be blank")

View File

@@ -35,4 +35,8 @@ interface IUserService : IService<User> {
fun deleteOne(id: Long)
fun delete(userDeleteParam: UserDeleteParam)
fun selectIdsWithRoleIds(roleIds: List<Long>): List<Long>
fun selectIdsWithGroupIds(groupIds: List<Long>): List<Long>
}

View File

@@ -12,7 +12,10 @@ import top.fatweb.api.mapper.permission.GroupMapper
import top.fatweb.api.param.permission.group.*
import top.fatweb.api.service.permission.IGroupService
import top.fatweb.api.service.permission.IRoleGroupService
import top.fatweb.api.service.permission.IUserService
import top.fatweb.api.util.PageUtil
import top.fatweb.api.util.RedisUtil
import top.fatweb.api.util.WebUtil
import top.fatweb.api.vo.PageVo
import top.fatweb.api.vo.permission.base.GroupVo
import top.fatweb.api.vo.permission.GroupWithRoleVo
@@ -25,7 +28,9 @@ import top.fatweb.api.vo.permission.GroupWithRoleVo
*/
@Service
class GroupServiceImpl(
private val roleGroupService: IRoleGroupService
private val redisUtil: RedisUtil,
private val roleGroupService: IRoleGroupService,
private val userService: IUserService
) : ServiceImpl<GroupMapper, Group>(), IGroupService {
override fun getPage(groupGetParam: GroupGetParam?): PageVo<GroupWithRoleVo> {
val groupIdsPage = Page<Long>(groupGetParam?.currentPage ?: 1, groupGetParam?.pageSize ?: 20)
@@ -107,11 +112,19 @@ class GroupServiceImpl(
})
}
groupUpdateParam.id?.let { offlineUser(it) }
return GroupConverter.groupToGroupVo(group)
}
override fun changeStatus(groupChangeStatusParam: GroupChangeStatusParam): Boolean {
return updateById(GroupConverter.groupChangeStatusParamToGroup(groupChangeStatusParam))
updateById(GroupConverter.groupChangeStatusParamToGroup(groupChangeStatusParam)).let {
if (it && !groupChangeStatusParam.enable) {
groupChangeStatusParam.id?.let { id -> offlineUser(id) }
}
return it
}
}
@Transactional
@@ -123,5 +136,11 @@ class GroupServiceImpl(
override fun delete(groupDeleteParam: GroupDeleteParam) {
baseMapper.deleteBatchIds(groupDeleteParam.ids)
roleGroupService.remove(KtQueryWrapper(RoleGroup()).`in`(RoleGroup::groupId, groupDeleteParam.ids))
offlineUser(*groupDeleteParam.ids.toLongArray())
}
private fun offlineUser(vararg groupIds: Long) {
val userIds = userService.selectIdsWithGroupIds(groupIds.toList())
WebUtil.offlineUser(redisUtil, *userIds.toLongArray())
}
}

View File

@@ -10,11 +10,10 @@ import top.fatweb.api.entity.permission.PowerRole
import top.fatweb.api.entity.permission.Role
import top.fatweb.api.mapper.permission.RoleMapper
import top.fatweb.api.param.permission.role.*
import top.fatweb.api.service.permission.IFuncService
import top.fatweb.api.service.permission.IMenuService
import top.fatweb.api.service.permission.IPowerRoleService
import top.fatweb.api.service.permission.IRoleService
import top.fatweb.api.service.permission.*
import top.fatweb.api.util.PageUtil
import top.fatweb.api.util.RedisUtil
import top.fatweb.api.util.WebUtil
import top.fatweb.api.vo.PageVo
import top.fatweb.api.vo.permission.base.RoleVo
import top.fatweb.api.vo.permission.RoleWithPowerVo
@@ -27,9 +26,11 @@ import top.fatweb.api.vo.permission.RoleWithPowerVo
*/
@Service
class RoleServiceImpl(
private val redisUtil: RedisUtil,
private val powerRoleService: IPowerRoleService,
private val funcService: IFuncService,
private val menuService: IMenuService
private val menuService: IMenuService,
private val userService: IUserService
) : ServiceImpl<RoleMapper, Role>(), IRoleService {
override fun getPage(roleGetParam: RoleGetParam?): PageVo<RoleWithPowerVo> {
val roleIdsPage = Page<Long>(roleGetParam?.currentPage ?: 1, roleGetParam?.pageSize ?: 20)
@@ -118,11 +119,19 @@ class RoleServiceImpl(
})
}
roleUpdateParam.id?.let { offlineUser(it) }
return RoleConverter.roleToRoleVo(role)
}
override fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean {
return updateById(RoleConverter.roleChangeStatusParamToRole(roleChangeStatusParam))
updateById(RoleConverter.roleChangeStatusParamToRole(roleChangeStatusParam)).let {
if (it && !roleChangeStatusParam.enable) {
roleChangeStatusParam.id?.let { id -> offlineUser(id) }
}
return it
}
}
@Transactional
@@ -134,6 +143,7 @@ class RoleServiceImpl(
override fun delete(roleDeleteParam: RoleDeleteParam) {
baseMapper.deleteBatchIds(roleDeleteParam.ids)
powerRoleService.remove(KtQueryWrapper(PowerRole()).`in`(PowerRole::roleId, roleDeleteParam.ids))
offlineUser(*roleDeleteParam.ids.toLongArray())
}
private fun getFullPowerIds(powerIds: List<Long>): Set<Long> {
@@ -161,4 +171,9 @@ class RoleServiceImpl(
getMenuParent(it, parentIds)
}
}
private fun offlineUser(vararg roleIds: Long) {
val userIds = userService.selectIdsWithRoleIds(roleIds.toList())
WebUtil.offlineUser(redisUtil, *userIds.toLongArray())
}
}

View File

@@ -248,4 +248,8 @@ class UserServiceImpl(
WebUtil.offlineUser(redisUtil, *ids.toLongArray())
}
override fun selectIdsWithRoleIds(roleIds: List<Long>) = baseMapper.selectIdsWithRoleIds(roleIds)
override fun selectIdsWithGroupIds(groupIds: List<Long>) = baseMapper.selectIdsWithGroupIds(groupIds)
}