diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/RoleController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/RoleController.kt index e1b4721..ead0ea6 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/RoleController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/RoleController.kt @@ -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 { + roleService.deleteOne(id) + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + } + + @Operation(summary = "批量删除角色") + @DeleteMapping + fun deleteList(@Valid @RequestBody roleDeleteParam: RoleDeleteParam): ResponseResult { + roleService.delete(roleDeleteParam) + return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS) + } } \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/GroupConverter.kt b/src/main/kotlin/top/fatweb/api/converter/permission/GroupConverter.kt index 571bd07..6d55910 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/GroupConverter.kt +++ b/src/main/kotlin/top/fatweb/api/converter/permission/GroupConverter.kt @@ -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): PageVo = PageVo( diff --git a/src/main/kotlin/top/fatweb/api/converter/permission/RoleConverter.kt b/src/main/kotlin/top/fatweb/api/converter/permission/RoleConverter.kt index c072157..a6bc7c1 100644 --- a/src/main/kotlin/top/fatweb/api/converter/permission/RoleConverter.kt +++ b/src/main/kotlin/top/fatweb/api/converter/permission/RoleConverter.kt @@ -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) }, diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Group.kt b/src/main/kotlin/top/fatweb/api/entity/permission/Group.kt index d3394ac..732feb8 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/Group.kt +++ b/src/main/kotlin/top/fatweb/api/entity/permission/Group.kt @@ -2,6 +2,7 @@ package top.fatweb.api.entity.permission import com.baomidou.mybatisplus.annotation.* import java.io.Serializable +import java.time.LocalDateTime /** *

@@ -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 diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/Role.kt b/src/main/kotlin/top/fatweb/api/entity/permission/Role.kt index 65dcfb1..6f31557 100644 --- a/src/main/kotlin/top/fatweb/api/entity/permission/Role.kt +++ b/src/main/kotlin/top/fatweb/api/entity/permission/Role.kt @@ -2,6 +2,7 @@ package top.fatweb.api.entity.permission import com.baomidou.mybatisplus.annotation.* import java.io.Serializable +import java.time.LocalDateTime /** *

@@ -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 diff --git a/src/main/kotlin/top/fatweb/api/param/authentication/GroupGetParam.kt b/src/main/kotlin/top/fatweb/api/param/authentication/GroupGetParam.kt index e80e28b..373f20d 100644 --- a/src/main/kotlin/top/fatweb/api/param/authentication/GroupGetParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/authentication/GroupGetParam.kt @@ -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, diff --git a/src/main/kotlin/top/fatweb/api/param/authentication/RoleAddParam.kt b/src/main/kotlin/top/fatweb/api/param/authentication/RoleAddParam.kt index eeb168a..8fe1414 100644 --- a/src/main/kotlin/top/fatweb/api/param/authentication/RoleAddParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/authentication/RoleAddParam.kt @@ -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") diff --git a/src/main/kotlin/top/fatweb/api/param/authentication/RoleChangeStatusParam.kt b/src/main/kotlin/top/fatweb/api/param/authentication/RoleChangeStatusParam.kt index 3034009..1f8ba38 100644 --- a/src/main/kotlin/top/fatweb/api/param/authentication/RoleChangeStatusParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/authentication/RoleChangeStatusParam.kt @@ -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) diff --git a/src/main/kotlin/top/fatweb/api/param/authentication/RoleDeleteParam.kt b/src/main/kotlin/top/fatweb/api/param/authentication/RoleDeleteParam.kt new file mode 100644 index 0000000..1fe8669 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/param/authentication/RoleDeleteParam.kt @@ -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 +) diff --git a/src/main/kotlin/top/fatweb/api/param/authentication/RoleGetParam.kt b/src/main/kotlin/top/fatweb/api/param/authentication/RoleGetParam.kt index 4d746e5..2246cd0 100644 --- a/src/main/kotlin/top/fatweb/api/param/authentication/RoleGetParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/authentication/RoleGetParam.kt @@ -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, diff --git a/src/main/kotlin/top/fatweb/api/param/authentication/RoleUpdateParam.kt b/src/main/kotlin/top/fatweb/api/param/authentication/RoleUpdateParam.kt index 6d8548b..6423b48 100644 --- a/src/main/kotlin/top/fatweb/api/param/authentication/RoleUpdateParam.kt +++ b/src/main/kotlin/top/fatweb/api/param/authentication/RoleUpdateParam.kt @@ -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) diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt index c8348cf..fe2c042 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt @@ -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 { fun update(roleUpdateParam: RoleUpdateParam): RoleVo? fun changeStatus(roleChangeStatusParam: RoleChangeStatusParam): Boolean + + fun deleteOne(id: Long) + + fun delete(roleDeleteParam: RoleDeleteParam) } diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleServiceImpl.kt index 1d72988..b5b9a82 100644 --- a/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleServiceImpl.kt +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/RoleServiceImpl.kt @@ -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)) + } } diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/GroupVo.kt b/src/main/kotlin/top/fatweb/api/vo/permission/GroupVo.kt index 9f4b666..1967feb 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/GroupVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/permission/GroupVo.kt @@ -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? ) diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/RoleVo.kt b/src/main/kotlin/top/fatweb/api/vo/permission/RoleVo.kt index 2b89961..3ea3a29 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/RoleVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/permission/RoleVo.kt @@ -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? ) diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/RoleWithPowerVo.kt b/src/main/kotlin/top/fatweb/api/vo/permission/RoleWithPowerVo.kt index 04f5bae..4ff2f07 100644 --- a/src/main/kotlin/top/fatweb/api/vo/permission/RoleWithPowerVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/permission/RoleWithPowerVo.kt @@ -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?, diff --git a/src/main/resources/db/migration/V1_0_0_231028__Add_table_'t_group'.sql b/src/main/resources/db/migration/V1_0_0_231028__Add_table_'t_group'.sql index 322da24..9d0c6fb 100644 --- a/src/main/resources/db/migration/V1_0_0_231028__Add_table_'t_group'.sql +++ b/src/main/resources/db/migration/V1_0_0_231028__Add_table_'t_group'.sql @@ -5,6 +5,8 @@ create table if not exists t_group id bigint not null primary key, name varchar(30) 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, version int not null default 0, constraint t_group_unique unique (name, deleted) diff --git a/src/main/resources/db/migration/V1_0_0_231030__Add_table_'t_role'.sql b/src/main/resources/db/migration/V1_0_0_231030__Add_table_'t_role'.sql index 08cd98b..98d96de 100644 --- a/src/main/resources/db/migration/V1_0_0_231030__Add_table_'t_role'.sql +++ b/src/main/resources/db/migration/V1_0_0_231030__Add_table_'t_role'.sql @@ -5,6 +5,8 @@ create table if not exists t_role id bigint not null primary key, name varchar(20) 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, version int not null default 0, constraint t_role_unique unique (name, deleted) diff --git a/src/main/resources/mapper/permission/GroupMapper.xml b/src/main/resources/mapper/permission/GroupMapper.xml index 5879801..0f08352 100644 --- a/src/main/resources/mapper/permission/GroupMapper.xml +++ b/src/main/resources/mapper/permission/GroupMapper.xml @@ -9,6 +9,8 @@ + + diff --git a/src/main/resources/mapper/permission/RoleMapper.xml b/src/main/resources/mapper/permission/RoleMapper.xml index 6caefa2..4289e01 100644 --- a/src/main/resources/mapper/permission/RoleMapper.xml +++ b/src/main/resources/mapper/permission/RoleMapper.xml @@ -11,6 +11,8 @@ select distinct t_role.id as role_id, t_role.name as role_name, 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.version as role_version, tm.id as module_id, @@ -51,6 +53,8 @@ select distinct t_role.id as role_id, t_role.name as role_name, 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.version as role_version, tm.id as module_id, @@ -93,6 +97,8 @@ + +