Complete core functions #9

Merged
FatttSnake merged 171 commits from FatttSnake into dev 2024-02-23 11:56:35 +08:00
9 changed files with 128 additions and 54 deletions
Showing only changes of commit 95ea00e643 - Show all commits

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)
}

View File

@@ -39,7 +39,7 @@
t.id as operation_id,
t.name as operation_name,
t.code as operation_code,
t.func_id as operation_func_id
t.func_id as operation_func_id
from t_user
left join (select * from t_user_info where deleted = 0) as tui on t_user.id = tui.user_id
left join (select * from t_user_group where deleted = 0) as tug on t_user.id = tug.user_id
@@ -124,48 +124,48 @@
</select>
<select id="selectListWithRoleInfoByIds" resultMap="userWithRoleInfoMap">
select t_user.id as user_id,
t_user.username as user_username,
t_user.password as user_password,
t_user.locking as user_locking,
t_user.expiration as user_expiration,
t_user.credentials_expiration as user_credentials_expiration,
t_user.enable as user_enable,
t_user.current_login_time as user_current_login_time,
t_user.current_login_ip as user_current_login_ip,
t_user.last_login_time as user_last_login_time,
t_user.last_login_ip as user_last_login_ip,
t_user.create_time as user_create_time,
t_user.update_time as user_update_time,
t_user.deleted as user_deleted,
t_user.version as user_version,
tui.id as user_info_id,
tui.user_id as user_info_user_id,
tui.nickname as user_info_nickname,
tui.avatar as user_info_avatar,
tui.email as user_info_email,
tui.create_time as user_info_create_time,
tui.update_time as user_info_update_time,
tui.deleted as user_info_deleted,
tui.version as user_info_version,
tr.id as role_id,
tr.name as role_name,
tr.enable as role_enable,
tr.deleted as role_deleted,
tr.version as role_version,
tg.id as group_id,
tg.name as group_name,
tg.enable as group_enable,
tg.deleted as group_deleted,
tg.version as group_version
select t_user.id as user_id,
t_user.username as user_username,
t_user.password as user_password,
t_user.locking as user_locking,
t_user.expiration as user_expiration,
t_user.credentials_expiration as user_credentials_expiration,
t_user.enable as user_enable,
t_user.current_login_time as user_current_login_time,
t_user.current_login_ip as user_current_login_ip,
t_user.last_login_time as user_last_login_time,
t_user.last_login_ip as user_last_login_ip,
t_user.create_time as user_create_time,
t_user.update_time as user_update_time,
t_user.deleted as user_deleted,
t_user.version as user_version,
tui.id as user_info_id,
tui.user_id as user_info_user_id,
tui.nickname as user_info_nickname,
tui.avatar as user_info_avatar,
tui.email as user_info_email,
tui.create_time as user_info_create_time,
tui.update_time as user_info_update_time,
tui.deleted as user_info_deleted,
tui.version as user_info_version,
tr.id as role_id,
tr.name as role_name,
tr.enable as role_enable,
tr.deleted as role_deleted,
tr.version as role_version,
tg.id as group_id,
tg.name as group_name,
tg.enable as group_enable,
tg.deleted as group_deleted,
tg.version as group_version
from t_user
left join (select * from t_user_info where deleted = 0) as tui on t_user.id = tui.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) as tg on tg.id = tug.group_id
left join (select * from t_role_group where deleted = 0) as trg on tg.id = trg.group_id
left join (select * from t_user_role where deleted = 0) as tur on t_user.id = tur.user_id
left join (select * from t_role where deleted = 0) as tr
on tr.id = trg.role_id or tr.id = tur.role_id
left join (select * from t_user_info where deleted = 0) as tui on t_user.id = tui.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) as tg on tg.id = tug.group_id
left join (select * from t_role_group where deleted = 0) as trg on tg.id = trg.group_id
left join (select * from t_user_role where deleted = 0) as tur on t_user.id = tur.user_id
left join (select * from t_role where deleted = 0) as tr
on tr.id = trg.role_id or tr.id = tur.role_id
<where>
<foreach collection="userIds" item="item" index="index" open="and t_user.id in (" separator="," close=")"
nullable="true">
@@ -251,6 +251,34 @@
where t_user.deleted = 0
</select>
<select id="selectIdsWithRoleIds" resultType="long">
select t_user.id
from t_user
left join (select * from t_user_role where deleted = 0) as tur on t_user.id = tur.user_id
left join (select * from t_role where deleted = 0) as tr on tr.id = tur.role_id
<where>
t_user.deleted = 0
<foreach collection="roleIds" item="item" index="index" open="and tr.id in (" separator="," close=")"
nullable="true">
#{item}
</foreach>
</where>
</select>
<select id="selectIdsWithGroupIds" resultType="long">
select t_user.id
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_group where deleted = 0) as tg on tg.id = tug.group_id
<where>
t_user.deleted = 0
<foreach collection="groupIds" item="item" index="index" open="and tg.id in (" separator="," close=")"
nullable="true">
#{item}
</foreach>
</where>
</select>
<resultMap id="userBaseMap" type="user">
<id property="id" column="user_id"/>
<result property="username" column="user_username"/>