Optimize role
This commit is contained in:
@@ -6,10 +6,7 @@ import jakarta.validation.Valid
|
|||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import top.fatweb.api.entity.common.ResponseCode
|
import top.fatweb.api.entity.common.ResponseCode
|
||||||
import top.fatweb.api.entity.common.ResponseResult
|
import top.fatweb.api.entity.common.ResponseResult
|
||||||
import top.fatweb.api.param.authentication.RoleAddParam
|
import top.fatweb.api.param.authentication.*
|
||||||
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.service.permission.IRoleService
|
import top.fatweb.api.service.permission.IRoleService
|
||||||
import top.fatweb.api.vo.PageVo
|
import top.fatweb.api.vo.PageVo
|
||||||
import top.fatweb.api.vo.permission.RoleVo
|
import top.fatweb.api.vo.permission.RoleVo
|
||||||
@@ -72,4 +69,18 @@ class RoleController(
|
|||||||
ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED)
|
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(
|
fun groupToGroupVo(group: Group) = GroupVo(
|
||||||
id = group.id,
|
id = group.id,
|
||||||
name = group.name,
|
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(
|
fun groupPageToGroupPageVo(groupPage: IPage<Group>): PageVo<GroupVo> = PageVo(
|
||||||
|
|||||||
@@ -14,13 +14,17 @@ object RoleConverter {
|
|||||||
fun roleToRoleVo(role: Role) = RoleVo(
|
fun roleToRoleVo(role: Role) = RoleVo(
|
||||||
id = role.id,
|
id = role.id,
|
||||||
name = role.name,
|
name = role.name,
|
||||||
enable = role.enable == 1
|
enable = role.enable == 1,
|
||||||
|
createTime = role.createTime,
|
||||||
|
updateTime = role.updateTime
|
||||||
)
|
)
|
||||||
|
|
||||||
fun roleToRoleWithPowerVo(role: Role) = RoleWithPowerVo(
|
fun roleToRoleWithPowerVo(role: Role) = RoleWithPowerVo(
|
||||||
id = role.id,
|
id = role.id,
|
||||||
name = role.name,
|
name = role.name,
|
||||||
enable = role.enable == 1,
|
enable = role.enable == 1,
|
||||||
|
createTime = role.createTime,
|
||||||
|
updateTime = role.updateTime,
|
||||||
modules = role.modules?.map { ModuleConverter.moduleToModuleVo(it) },
|
modules = role.modules?.map { ModuleConverter.moduleToModuleVo(it) },
|
||||||
menus = role.menus?.map { MenuConverter.menuToMenuVo(it) },
|
menus = role.menus?.map { MenuConverter.menuToMenuVo(it) },
|
||||||
elements = role.elements?.map { ElementConverter.elementToElementVo(it) },
|
elements = role.elements?.map { ElementConverter.elementToElementVo(it) },
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package top.fatweb.api.entity.permission
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*
|
import com.baomidou.mybatisplus.annotation.*
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -29,6 +30,18 @@ class Group : Serializable {
|
|||||||
@TableField("enable")
|
@TableField("enable")
|
||||||
var enable: Int? = null
|
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")
|
@TableField("deleted")
|
||||||
@TableLogic
|
@TableLogic
|
||||||
var deleted: Long? = null
|
var deleted: Long? = null
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package top.fatweb.api.entity.permission
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*
|
import com.baomidou.mybatisplus.annotation.*
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -29,6 +30,18 @@ class Role : Serializable {
|
|||||||
@TableField("enable")
|
@TableField("enable")
|
||||||
var enable: Int? = null
|
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")
|
@TableField("deleted")
|
||||||
@TableLogic
|
@TableLogic
|
||||||
var deleted: Long? = null
|
var deleted: Long? = null
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package top.fatweb.api.param.authentication
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
import top.fatweb.api.param.PageSortParam
|
import top.fatweb.api.param.PageSortParam
|
||||||
|
|
||||||
|
@Schema(description = "用户组查询请求参数")
|
||||||
data class GroupGetParam(
|
data class GroupGetParam(
|
||||||
@Schema(description = "查询用户组名称")
|
@Schema(description = "查询用户组名称")
|
||||||
val searchName: String? = null,
|
val searchName: String? = null,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package top.fatweb.api.param.authentication
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
import jakarta.validation.constraints.NotBlank
|
import jakarta.validation.constraints.NotBlank
|
||||||
|
|
||||||
|
@Schema(description = "角色添加请求参数")
|
||||||
data class RoleAddParam(
|
data class RoleAddParam(
|
||||||
@Schema(description = "角色名称")
|
@Schema(description = "角色名称")
|
||||||
@field:NotBlank(message = "Name can not be blank")
|
@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.Min
|
||||||
import jakarta.validation.constraints.NotNull
|
import jakarta.validation.constraints.NotNull
|
||||||
|
|
||||||
|
@Schema(description = "角色更改状态请求参数")
|
||||||
data class RoleChangeStatusParam(
|
data class RoleChangeStatusParam(
|
||||||
@Schema(description = "角色 ID")
|
@Schema(description = "角色 ID")
|
||||||
@field:Min(0)
|
@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 io.swagger.v3.oas.annotations.media.Schema
|
||||||
import top.fatweb.api.param.PageSortParam
|
import top.fatweb.api.param.PageSortParam
|
||||||
|
|
||||||
|
@Schema(description = "角色查询请求参数")
|
||||||
data class RoleGetParam(
|
data class RoleGetParam(
|
||||||
@Schema(description = "查询角色名称")
|
@Schema(description = "查询角色名称")
|
||||||
val searchName: String? = null,
|
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.Min
|
||||||
import jakarta.validation.constraints.NotBlank
|
import jakarta.validation.constraints.NotBlank
|
||||||
|
|
||||||
|
@Schema(description = "角色更新请求参数")
|
||||||
data class RoleUpdateParam(
|
data class RoleUpdateParam(
|
||||||
@Schema(description = "角色 ID")
|
@Schema(description = "角色 ID")
|
||||||
@field:Min(0)
|
@field:Min(0)
|
||||||
|
|||||||
@@ -2,10 +2,7 @@ package top.fatweb.api.service.permission
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService
|
import com.baomidou.mybatisplus.extension.service.IService
|
||||||
import top.fatweb.api.entity.permission.Role
|
import top.fatweb.api.entity.permission.Role
|
||||||
import top.fatweb.api.param.authentication.RoleAddParam
|
import top.fatweb.api.param.authentication.*
|
||||||
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.vo.PageVo
|
import top.fatweb.api.vo.PageVo
|
||||||
import top.fatweb.api.vo.permission.RoleVo
|
import top.fatweb.api.vo.permission.RoleVo
|
||||||
import top.fatweb.api.vo.permission.RoleWithPowerVo
|
import top.fatweb.api.vo.permission.RoleWithPowerVo
|
||||||
@@ -28,4 +25,8 @@ interface IRoleService : IService<Role> {
|
|||||||
fun update(roleUpdateParam: RoleUpdateParam): RoleVo?
|
fun update(roleUpdateParam: RoleUpdateParam): RoleVo?
|
||||||
|
|
||||||
fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean
|
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.PowerRole
|
||||||
import top.fatweb.api.entity.permission.Role
|
import top.fatweb.api.entity.permission.Role
|
||||||
import top.fatweb.api.mapper.permission.RoleMapper
|
import top.fatweb.api.mapper.permission.RoleMapper
|
||||||
import top.fatweb.api.param.authentication.RoleAddParam
|
import top.fatweb.api.param.authentication.*
|
||||||
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.service.permission.IPowerRoleService
|
import top.fatweb.api.service.permission.IPowerRoleService
|
||||||
import top.fatweb.api.service.permission.IRoleService
|
import top.fatweb.api.service.permission.IRoleService
|
||||||
import top.fatweb.api.util.PageUtil
|
import top.fatweb.api.util.PageUtil
|
||||||
@@ -124,4 +121,15 @@ class RoleServiceImpl(
|
|||||||
override fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean {
|
override fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean {
|
||||||
return updateById(RoleConverter.roleChangeStatusParamToRole(roleChangeStatusParam))
|
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.annotation.JsonSerialize
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
||||||
import io.swagger.v3.oas.annotations.media.Schema
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
@Schema(description = "用户组返回参数")
|
@Schema(description = "用户组返回参数")
|
||||||
data class GroupVo(
|
data class GroupVo(
|
||||||
@@ -13,5 +14,11 @@ data class GroupVo(
|
|||||||
val name: String?,
|
val name: String?,
|
||||||
|
|
||||||
@Schema(description = "启用", example = "true")
|
@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.annotation.JsonSerialize
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
||||||
import io.swagger.v3.oas.annotations.media.Schema
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
@Schema(description = "角色返回参数")
|
@Schema(description = "角色返回参数")
|
||||||
data class RoleVo(
|
data class RoleVo(
|
||||||
@@ -13,5 +14,11 @@ data class RoleVo(
|
|||||||
val name: String?,
|
val name: String?,
|
||||||
|
|
||||||
@Schema(description = "启用", example = "true")
|
@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.annotation.JsonSerialize
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
|
||||||
import io.swagger.v3.oas.annotations.media.Schema
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
@Schema(description = "角色返回参数")
|
@Schema(description = "角色返回参数")
|
||||||
data class RoleWithPowerVo(
|
data class RoleWithPowerVo(
|
||||||
@@ -15,6 +16,12 @@ data class RoleWithPowerVo(
|
|||||||
@Schema(description = "启用", example = "true")
|
@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?,
|
||||||
|
|
||||||
@Schema(description = "模块列表")
|
@Schema(description = "模块列表")
|
||||||
val modules: List<ModuleVo>?,
|
val modules: List<ModuleVo>?,
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ create table if not exists t_group
|
|||||||
id bigint not null primary key,
|
id bigint not null primary key,
|
||||||
name varchar(30) not null comment '用户组名',
|
name varchar(30) not null comment '用户组名',
|
||||||
enable int not null comment '启用',
|
enable int not null comment '启用',
|
||||||
|
create_time datetime not null default (utc_timestamp()) comment '创建时间',
|
||||||
|
update_time datetime not null default (utc_timestamp()) comment '修改时间',
|
||||||
deleted bigint not null default 0,
|
deleted bigint not null default 0,
|
||||||
version int not null default 0,
|
version int not null default 0,
|
||||||
constraint t_group_unique unique (name, deleted)
|
constraint t_group_unique unique (name, deleted)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ create table if not exists t_role
|
|||||||
id bigint not null primary key,
|
id bigint not null primary key,
|
||||||
name varchar(20) not null comment '角色名',
|
name varchar(20) not null comment '角色名',
|
||||||
enable int not null comment '启用',
|
enable int not null comment '启用',
|
||||||
|
create_time datetime not null default (utc_timestamp()) comment '创建时间',
|
||||||
|
update_time datetime not null default (utc_timestamp()) comment '修改时间',
|
||||||
deleted bigint not null default 0,
|
deleted bigint not null default 0,
|
||||||
version int not null default 0,
|
version int not null default 0,
|
||||||
constraint t_role_unique unique (name, deleted)
|
constraint t_role_unique unique (name, deleted)
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
<id property="id" column="group_id"/>
|
<id property="id" column="group_id"/>
|
||||||
<result property="name" column="group_name"/>
|
<result property="name" column="group_name"/>
|
||||||
<result property="enable" column="group_enable"/>
|
<result property="enable" column="group_enable"/>
|
||||||
|
<result property="createTime" column="group_create_time"/>
|
||||||
|
<result property="updateTime" column="group_update_time"/>
|
||||||
<result property="deleted" column="group_deleted"/>
|
<result property="deleted" column="group_deleted"/>
|
||||||
<result property="version" column="group_version"/>
|
<result property="version" column="group_version"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
select distinct t_role.id as role_id,
|
select distinct t_role.id as role_id,
|
||||||
t_role.name as role_name,
|
t_role.name as role_name,
|
||||||
t_role.enable as role_enable,
|
t_role.enable as role_enable,
|
||||||
|
t_role.create_time as role_create_time,
|
||||||
|
t_role.update_time as role_update_time,
|
||||||
t_role.deleted as role_deleted,
|
t_role.deleted as role_deleted,
|
||||||
t_role.version as role_version,
|
t_role.version as role_version,
|
||||||
tm.id as module_id,
|
tm.id as module_id,
|
||||||
@@ -51,6 +53,8 @@
|
|||||||
select distinct t_role.id as role_id,
|
select distinct t_role.id as role_id,
|
||||||
t_role.name as role_name,
|
t_role.name as role_name,
|
||||||
t_role.enable as role_enable,
|
t_role.enable as role_enable,
|
||||||
|
t_role.create_time as role_create_time,
|
||||||
|
t_role.update_time as role_update_time,
|
||||||
t_role.deleted as role_deleted,
|
t_role.deleted as role_deleted,
|
||||||
t_role.version as role_version,
|
t_role.version as role_version,
|
||||||
tm.id as module_id,
|
tm.id as module_id,
|
||||||
@@ -93,6 +97,8 @@
|
|||||||
<id property="id" column="role_id"/>
|
<id property="id" column="role_id"/>
|
||||||
<result property="name" column="role_name"/>
|
<result property="name" column="role_name"/>
|
||||||
<result property="enable" column="role_enable"/>
|
<result property="enable" column="role_enable"/>
|
||||||
|
<result property="createTime" column="role_create_time"/>
|
||||||
|
<result property="updateTime" column="role_update_time"/>
|
||||||
<result property="deleted" column="role_deleted"/>
|
<result property="deleted" column="role_deleted"/>
|
||||||
<result property="version" column="role_version"/>
|
<result property="version" column="role_version"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|||||||
Reference in New Issue
Block a user