Optimize RoleController
This commit is contained in:
@@ -24,7 +24,7 @@ import top.fatweb.api.vo.permission.RoleWithPowerVo
|
||||
class RoleController(
|
||||
private val roleService: IRoleService
|
||||
) {
|
||||
@Operation(summary = "获取角色列表")
|
||||
@Operation(summary = "获取角色")
|
||||
@GetMapping
|
||||
fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> {
|
||||
return ResponseResult.databaseSuccess(
|
||||
@@ -40,6 +40,14 @@ class RoleController(
|
||||
)
|
||||
}
|
||||
|
||||
@Operation(summary = "获取角色列表")
|
||||
@GetMapping("/list")
|
||||
fun list(): ResponseResult<List<RoleVo>> {
|
||||
return ResponseResult.databaseSuccess(
|
||||
data = roleService.listAll()
|
||||
)
|
||||
}
|
||||
|
||||
@Operation(summary = "添加角色")
|
||||
@PostMapping
|
||||
fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> {
|
||||
|
||||
@@ -20,6 +20,4 @@ interface RoleMapper : BaseMapper<Role> {
|
||||
fun getWithPowerByList(roleIds: List<Long>): List<Role>?
|
||||
|
||||
fun selectOne(id: Long): Role?
|
||||
|
||||
fun getPowerList(id: Long): List<Long?>
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import jakarta.validation.constraints.NotNull
|
||||
data class RoleChangeStatusParam(
|
||||
@Schema(description = "角色 ID")
|
||||
@field:Min(0)
|
||||
@JsonSerialize(using = ToStringSerializer::class)
|
||||
val id: Long,
|
||||
|
||||
@Schema(description = "启用", allowableValues = ["true", "false"])
|
||||
|
||||
@@ -20,6 +20,8 @@ interface IRoleService : IService<Role> {
|
||||
|
||||
fun getOne(id: Long): RoleWithPowerVo?
|
||||
|
||||
fun listAll(): List<RoleVo>
|
||||
|
||||
fun add(roleAddParam: RoleAddParam): RoleVo?
|
||||
|
||||
fun update(roleUpdateParam: RoleUpdateParam): RoleVo?
|
||||
|
||||
@@ -54,6 +54,12 @@ class RoleServiceImpl(
|
||||
return baseMapper.selectOne(id)?.let { RoleConverter.roleToRoleWithPowerVo(it) } ?: let { null }
|
||||
}
|
||||
|
||||
override fun listAll(): List<RoleVo> {
|
||||
val roles = this.list()
|
||||
|
||||
return roles.map { RoleConverter.roleToRoleVo(it) }
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
override fun add(roleAddParam: RoleAddParam): RoleVo? {
|
||||
@@ -83,7 +89,9 @@ class RoleServiceImpl(
|
||||
val fullPowerIds = roleUpdateParam.powerIds?.let { getFullPowerIds(it) }
|
||||
|
||||
val role = RoleConverter.roleUpdateParamToRole(roleUpdateParam)
|
||||
val oldPowerList = baseMapper.getPowerList(roleUpdateParam.id)
|
||||
val oldPowerList = powerRoleService.list(
|
||||
KtQueryWrapper(PowerRole()).select(PowerRole::powerId).eq(PowerRole::roleId, roleUpdateParam.id)
|
||||
).map { it.powerId }
|
||||
val addPowerIds = HashSet<Long>()
|
||||
val removePowerIds = HashSet<Long>()
|
||||
fullPowerIds?.forEach { addPowerIds.add(it) }
|
||||
|
||||
Reference in New Issue
Block a user