Optimize RoleController
This commit is contained in:
@@ -24,7 +24,7 @@ import top.fatweb.api.vo.permission.RoleWithPowerVo
|
|||||||
class RoleController(
|
class RoleController(
|
||||||
private val roleService: IRoleService
|
private val roleService: IRoleService
|
||||||
) {
|
) {
|
||||||
@Operation(summary = "获取角色列表")
|
@Operation(summary = "获取角色")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> {
|
fun get(roleGetParam: RoleGetParam?): ResponseResult<PageVo<RoleWithPowerVo>> {
|
||||||
return ResponseResult.databaseSuccess(
|
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 = "添加角色")
|
@Operation(summary = "添加角色")
|
||||||
@PostMapping
|
@PostMapping
|
||||||
fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> {
|
fun add(@Valid @RequestBody roleAddParam: RoleAddParam): ResponseResult<RoleVo> {
|
||||||
|
|||||||
@@ -20,6 +20,4 @@ interface RoleMapper : BaseMapper<Role> {
|
|||||||
fun getWithPowerByList(roleIds: List<Long>): List<Role>?
|
fun getWithPowerByList(roleIds: List<Long>): List<Role>?
|
||||||
|
|
||||||
fun selectOne(id: Long): Role?
|
fun selectOne(id: Long): Role?
|
||||||
|
|
||||||
fun getPowerList(id: Long): List<Long?>
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import jakarta.validation.constraints.NotNull
|
|||||||
data class RoleChangeStatusParam(
|
data class RoleChangeStatusParam(
|
||||||
@Schema(description = "角色 ID")
|
@Schema(description = "角色 ID")
|
||||||
@field:Min(0)
|
@field:Min(0)
|
||||||
@JsonSerialize(using = ToStringSerializer::class)
|
|
||||||
val id: Long,
|
val id: Long,
|
||||||
|
|
||||||
@Schema(description = "启用", allowableValues = ["true", "false"])
|
@Schema(description = "启用", allowableValues = ["true", "false"])
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ interface IRoleService : IService<Role> {
|
|||||||
|
|
||||||
fun getOne(id: Long): RoleWithPowerVo?
|
fun getOne(id: Long): RoleWithPowerVo?
|
||||||
|
|
||||||
|
fun listAll(): List<RoleVo>
|
||||||
|
|
||||||
fun add(roleAddParam: RoleAddParam): RoleVo?
|
fun add(roleAddParam: RoleAddParam): RoleVo?
|
||||||
|
|
||||||
fun update(roleUpdateParam: RoleUpdateParam): RoleVo?
|
fun update(roleUpdateParam: RoleUpdateParam): RoleVo?
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ class RoleServiceImpl(
|
|||||||
return baseMapper.selectOne(id)?.let { RoleConverter.roleToRoleWithPowerVo(it) } ?: let { null }
|
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
|
@Transactional
|
||||||
override fun add(roleAddParam: RoleAddParam): RoleVo? {
|
override fun add(roleAddParam: RoleAddParam): RoleVo? {
|
||||||
@@ -83,7 +89,9 @@ class RoleServiceImpl(
|
|||||||
val fullPowerIds = roleUpdateParam.powerIds?.let { getFullPowerIds(it) }
|
val fullPowerIds = roleUpdateParam.powerIds?.let { getFullPowerIds(it) }
|
||||||
|
|
||||||
val role = RoleConverter.roleUpdateParamToRole(roleUpdateParam)
|
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 addPowerIds = HashSet<Long>()
|
||||||
val removePowerIds = HashSet<Long>()
|
val removePowerIds = HashSet<Long>()
|
||||||
fullPowerIds?.forEach { addPowerIds.add(it) }
|
fullPowerIds?.forEach { addPowerIds.add(it) }
|
||||||
|
|||||||
@@ -90,13 +90,6 @@
|
|||||||
where t_role.id = #{id}
|
where t_role.id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getPowerList" resultType="long">
|
|
||||||
select tpr.power_id
|
|
||||||
from t_role
|
|
||||||
left join (select * from t_power_role where deleted = 0) as tpr on t_role.id = tpr.role_id
|
|
||||||
where t_role.id = #{id}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<resultMap id="roleMap" type="role">
|
<resultMap id="roleMap" type="role">
|
||||||
<id property="id" column="role_id"/>
|
<id property="id" column="role_id"/>
|
||||||
<result property="name" column="role_name"/>
|
<result property="name" column="role_name"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user