Optimize role
This commit is contained in:
@@ -6,10 +6,7 @@ import jakarta.validation.Valid
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import top.fatweb.api.entity.common.ResponseCode
|
||||
import top.fatweb.api.entity.common.ResponseResult
|
||||
import top.fatweb.api.param.authentication.RoleAddParam
|
||||
import top.fatweb.api.param.authentication.RoleChangeStatusParam
|
||||
import top.fatweb.api.param.authentication.RoleGetParam
|
||||
import top.fatweb.api.param.authentication.RoleUpdateParam
|
||||
import top.fatweb.api.param.authentication.*
|
||||
import top.fatweb.api.service.permission.IRoleService
|
||||
import top.fatweb.api.vo.PageVo
|
||||
import top.fatweb.api.vo.permission.RoleVo
|
||||
@@ -72,4 +69,18 @@ class RoleController(
|
||||
ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED)
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "删除角色")
|
||||
@DeleteMapping("/{id}")
|
||||
fun delete(@PathVariable id: Long): ResponseResult<Nothing> {
|
||||
roleService.deleteOne(id)
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
}
|
||||
|
||||
@Operation(summary = "批量删除角色")
|
||||
@DeleteMapping
|
||||
fun deleteList(@Valid @RequestBody roleDeleteParam: RoleDeleteParam): ResponseResult<Nothing> {
|
||||
roleService.delete(roleDeleteParam)
|
||||
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,9 @@ object GroupConverter {
|
||||
fun groupToGroupVo(group: Group) = GroupVo(
|
||||
id = group.id,
|
||||
name = group.name,
|
||||
enable = group.enable == 1
|
||||
enable = group.enable == 1,
|
||||
createTime = group.createTime,
|
||||
updateTime = group.updateTime
|
||||
)
|
||||
|
||||
fun groupPageToGroupPageVo(groupPage: IPage<Group>): PageVo<GroupVo> = PageVo(
|
||||
|
||||
@@ -14,13 +14,17 @@ object RoleConverter {
|
||||
fun roleToRoleVo(role: Role) = RoleVo(
|
||||
id = role.id,
|
||||
name = role.name,
|
||||
enable = role.enable == 1
|
||||
enable = role.enable == 1,
|
||||
createTime = role.createTime,
|
||||
updateTime = role.updateTime
|
||||
)
|
||||
|
||||
fun roleToRoleWithPowerVo(role: Role) = RoleWithPowerVo(
|
||||
id = role.id,
|
||||
name = role.name,
|
||||
enable = role.enable == 1,
|
||||
createTime = role.createTime,
|
||||
updateTime = role.updateTime,
|
||||
modules = role.modules?.map { ModuleConverter.moduleToModuleVo(it) },
|
||||
menus = role.menus?.map { MenuConverter.menuToMenuVo(it) },
|
||||
elements = role.elements?.map { ElementConverter.elementToElementVo(it) },
|
||||
|
||||
@@ -2,6 +2,7 @@ package top.fatweb.api.entity.permission
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*
|
||||
import java.io.Serializable
|
||||
import java.time.LocalDateTime
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -29,6 +30,18 @@ class Group : Serializable {
|
||||
@TableField("enable")
|
||||
var enable: Int? = null
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("create_time", fill = FieldFill.INSERT)
|
||||
var createTime: LocalDateTime? = null
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@TableField("update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
var updateTime: LocalDateTime? = null
|
||||
|
||||
@TableField("deleted")
|
||||
@TableLogic
|
||||
var deleted: Long? = null
|
||||
|
||||
@@ -2,6 +2,7 @@ package top.fatweb.api.entity.permission
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*
|
||||
import java.io.Serializable
|
||||
import java.time.LocalDateTime
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -29,6 +30,18 @@ class Role : Serializable {
|
||||
@TableField("enable")
|
||||
var enable: Int? = null
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("create_time", fill = FieldFill.INSERT)
|
||||
var createTime: LocalDateTime? = null
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@TableField("update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
var updateTime: LocalDateTime? = null
|
||||
|
||||
@TableField("deleted")
|
||||
@TableLogic
|
||||
var deleted: Long? = null
|
||||
|
||||
@@ -3,6 +3,7 @@ package top.fatweb.api.param.authentication
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
import top.fatweb.api.param.PageSortParam
|
||||
|
||||
@Schema(description = "用户组查询请求参数")
|
||||
data class GroupGetParam(
|
||||
@Schema(description = "查询用户组名称")
|
||||
val searchName: String? = null,
|
||||
|
||||
@@ -3,6 +3,7 @@ package top.fatweb.api.param.authentication
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
import jakarta.validation.constraints.NotBlank
|
||||
|
||||
@Schema(description = "角色添加请求参数")
|
||||
data class RoleAddParam(
|
||||
@Schema(description = "角色名称")
|
||||
@field:NotBlank(message = "Name can not be blank")
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema
|
||||
import jakarta.validation.constraints.Min
|
||||
import jakarta.validation.constraints.NotNull
|
||||
|
||||
@Schema(description = "角色更改状态请求参数")
|
||||
data class RoleChangeStatusParam(
|
||||
@Schema(description = "角色 ID")
|
||||
@field:Min(0)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package top.fatweb.api.param.authentication
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
|
||||
@Schema(description = "角色删除请求参数")
|
||||
data class RoleDeleteParam(
|
||||
@Schema(description = "角色 ID 列表")
|
||||
val ids: List<Long>
|
||||
)
|
||||
@@ -3,6 +3,7 @@ package top.fatweb.api.param.authentication
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
import top.fatweb.api.param.PageSortParam
|
||||
|
||||
@Schema(description = "角色查询请求参数")
|
||||
data class RoleGetParam(
|
||||
@Schema(description = "查询角色名称")
|
||||
val searchName: String? = null,
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema
|
||||
import jakarta.validation.constraints.Min
|
||||
import jakarta.validation.constraints.NotBlank
|
||||
|
||||
@Schema(description = "角色更新请求参数")
|
||||
data class RoleUpdateParam(
|
||||
@Schema(description = "角色 ID")
|
||||
@field:Min(0)
|
||||
|
||||
@@ -2,10 +2,7 @@ package top.fatweb.api.service.permission
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService
|
||||
import top.fatweb.api.entity.permission.Role
|
||||
import top.fatweb.api.param.authentication.RoleAddParam
|
||||
import top.fatweb.api.param.authentication.RoleChangeStatusParam
|
||||
import top.fatweb.api.param.authentication.RoleGetParam
|
||||
import top.fatweb.api.param.authentication.RoleUpdateParam
|
||||
import top.fatweb.api.param.authentication.*
|
||||
import top.fatweb.api.vo.PageVo
|
||||
import top.fatweb.api.vo.permission.RoleVo
|
||||
import top.fatweb.api.vo.permission.RoleWithPowerVo
|
||||
@@ -28,4 +25,8 @@ interface IRoleService : IService<Role> {
|
||||
fun update(roleUpdateParam: RoleUpdateParam): RoleVo?
|
||||
|
||||
fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean
|
||||
|
||||
fun deleteOne(id: Long)
|
||||
|
||||
fun delete(roleDeleteParam: RoleDeleteParam)
|
||||
}
|
||||
|
||||
@@ -9,10 +9,7 @@ import top.fatweb.api.converter.permission.RoleConverter
|
||||
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.authentication.RoleAddParam
|
||||
import top.fatweb.api.param.authentication.RoleChangeStatusParam
|
||||
import top.fatweb.api.param.authentication.RoleGetParam
|
||||
import top.fatweb.api.param.authentication.RoleUpdateParam
|
||||
import top.fatweb.api.param.authentication.*
|
||||
import top.fatweb.api.service.permission.IPowerRoleService
|
||||
import top.fatweb.api.service.permission.IRoleService
|
||||
import top.fatweb.api.util.PageUtil
|
||||
@@ -124,4 +121,15 @@ class RoleServiceImpl(
|
||||
override fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean {
|
||||
return updateById(RoleConverter.roleChangeStatusParamToRole(roleChangeStatusParam))
|
||||
}
|
||||
|
||||
@Transactional
|
||||
override fun deleteOne(id: Long) {
|
||||
this.delete(RoleDeleteParam(listOf(id)))
|
||||
}
|
||||
|
||||
@Transactional
|
||||
override fun delete(roleDeleteParam: RoleDeleteParam) {
|
||||
baseMapper.deleteBatchIds(roleDeleteParam.ids)
|
||||
powerRoleService.remove(KtQueryWrapper(PowerRole()).`in`(PowerRole::roleId, roleDeleteParam.ids))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package top.fatweb.api.vo.permission
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Schema(description = "用户组返回参数")
|
||||
data class GroupVo(
|
||||
@@ -13,5 +14,11 @@ data class GroupVo(
|
||||
val name: String?,
|
||||
|
||||
@Schema(description = "启用", example = "true")
|
||||
val enable: Boolean?
|
||||
val enable: Boolean?,
|
||||
|
||||
@Schema(description = "创建时间", example = "1900-01-01T00:00:00.000Z")
|
||||
val createTime: LocalDateTime?,
|
||||
|
||||
@Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z")
|
||||
val updateTime: LocalDateTime?
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@ package top.fatweb.api.vo.permission
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Schema(description = "角色返回参数")
|
||||
data class RoleVo(
|
||||
@@ -13,5 +14,11 @@ data class RoleVo(
|
||||
val name: String?,
|
||||
|
||||
@Schema(description = "启用", example = "true")
|
||||
val enable: Boolean?
|
||||
val enable: Boolean?,
|
||||
|
||||
@Schema(description = "创建时间", example = "1900-01-01T00:00:00.000Z")
|
||||
val createTime: LocalDateTime?,
|
||||
|
||||
@Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z")
|
||||
val updateTime: LocalDateTime?
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@ package top.fatweb.api.vo.permission
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Schema(description = "角色返回参数")
|
||||
data class RoleWithPowerVo(
|
||||
@@ -15,6 +16,12 @@ data class RoleWithPowerVo(
|
||||
@Schema(description = "启用", example = "true")
|
||||
val enable: Boolean?,
|
||||
|
||||
@Schema(description = "创建时间", example = "1900-01-01T00:00:00.000Z")
|
||||
val createTime: LocalDateTime?,
|
||||
|
||||
@Schema(description = "修改时间", example = "1900-01-01T00:00:00.000Z")
|
||||
val updateTime: LocalDateTime?,
|
||||
|
||||
@Schema(description = "模块列表")
|
||||
val modules: List<ModuleVo>?,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user