Finish GroupController
This commit is contained in:
@@ -3,15 +3,23 @@ package top.fatweb.api.controller.permission
|
|||||||
import io.swagger.v3.oas.annotations.Operation
|
import io.swagger.v3.oas.annotations.Operation
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag
|
import io.swagger.v3.oas.annotations.tags.Tag
|
||||||
import jakarta.validation.Valid
|
import jakarta.validation.Valid
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping
|
||||||
import org.springframework.web.bind.annotation.GetMapping
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
|
import org.springframework.web.bind.annotation.PatchMapping
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import top.fatweb.api.converter.permission.GroupConverter
|
import top.fatweb.api.converter.permission.GroupConverter
|
||||||
|
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.GroupGetParam
|
import top.fatweb.api.param.authentication.*
|
||||||
import top.fatweb.api.service.permission.IGroupService
|
import top.fatweb.api.service.permission.IGroupService
|
||||||
import top.fatweb.api.vo.PageVo
|
import top.fatweb.api.vo.PageVo
|
||||||
import top.fatweb.api.vo.permission.GroupVo
|
import top.fatweb.api.vo.permission.GroupVo
|
||||||
|
import top.fatweb.api.vo.permission.GroupWithRoleVo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -27,13 +35,71 @@ import top.fatweb.api.vo.permission.GroupVo
|
|||||||
class GroupController(
|
class GroupController(
|
||||||
val groupService: IGroupService
|
val groupService: IGroupService
|
||||||
) {
|
) {
|
||||||
@Operation(summary = "获取用户组列表")
|
@Operation(summary = "获取用户组")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
fun get(@Valid groupGetParam: GroupGetParam?): ResponseResult<PageVo<GroupVo>> {
|
fun get(@Valid groupGetParam: GroupGetParam?): ResponseResult<PageVo<GroupWithRoleVo>> {
|
||||||
return ResponseResult.databaseSuccess(
|
return ResponseResult.databaseSuccess(
|
||||||
data = GroupConverter.groupPageToGroupPageVo(
|
data = groupService.getPage(groupGetParam)
|
||||||
groupService.getPage(groupGetParam)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取单个用户组")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
fun getOne(@PathVariable id: Long): ResponseResult<GroupWithRoleVo> {
|
||||||
|
return ResponseResult.databaseSuccess(
|
||||||
|
data = groupService.getOne(id)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取用户组列表")
|
||||||
|
@GetMapping("/list")
|
||||||
|
fun list(): ResponseResult<List<GroupVo>> {
|
||||||
|
return ResponseResult.databaseSuccess(
|
||||||
|
data = groupService.listAll()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "添加用户组")
|
||||||
|
@PostMapping
|
||||||
|
fun add(@Valid @RequestBody groupAddParam: GroupAddParam): ResponseResult<GroupVo> {
|
||||||
|
return groupService.add(groupAddParam)?.let {
|
||||||
|
ResponseResult.databaseSuccess(
|
||||||
|
ResponseCode.DATABASE_INSERT_SUCCESS, data = it
|
||||||
|
)
|
||||||
|
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_INSERT_FAILED) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "修改用户组")
|
||||||
|
@PutMapping
|
||||||
|
fun update(@Valid @RequestBody groupUpdateParam: GroupUpdateParam): ResponseResult<GroupVo> {
|
||||||
|
return groupService.update(groupUpdateParam)?.let {
|
||||||
|
ResponseResult.databaseSuccess(
|
||||||
|
ResponseCode.DATABASE_UPDATE_SUCCESS, data = it
|
||||||
|
)
|
||||||
|
} ?: let { ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "修改用户组状态")
|
||||||
|
@PatchMapping
|
||||||
|
fun changStatus(@Valid @RequestBody groupChangeStatusParam: GroupChangeStatusParam): ResponseResult<Nothing> {
|
||||||
|
return if (groupService.changeStatus(groupChangeStatusParam)) {
|
||||||
|
ResponseResult.databaseSuccess(ResponseCode.DATABASE_UPDATE_SUCCESS)
|
||||||
|
} else {
|
||||||
|
ResponseResult.databaseFail(ResponseCode.DATABASE_UPDATE_FILED)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除角色")
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
fun delete(@PathVariable id: Long): ResponseResult<Nothing> {
|
||||||
|
groupService.deleteOne(id)
|
||||||
|
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "批量删除角色")
|
||||||
|
@DeleteMapping
|
||||||
|
fun deleteList(@Valid @RequestBody groupDeleteParam: GroupDeleteParam): ResponseResult<Nothing> {
|
||||||
|
groupService.delete(groupDeleteParam)
|
||||||
|
return ResponseResult.databaseSuccess(ResponseCode.DATABASE_DELETE_SUCCESS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,13 @@ package top.fatweb.api.converter.permission
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage
|
import com.baomidou.mybatisplus.core.metadata.IPage
|
||||||
import top.fatweb.api.entity.permission.Group
|
import top.fatweb.api.entity.permission.Group
|
||||||
|
import top.fatweb.api.entity.permission.Role
|
||||||
|
import top.fatweb.api.param.authentication.GroupAddParam
|
||||||
|
import top.fatweb.api.param.authentication.GroupChangeStatusParam
|
||||||
|
import top.fatweb.api.param.authentication.GroupUpdateParam
|
||||||
import top.fatweb.api.vo.PageVo
|
import top.fatweb.api.vo.PageVo
|
||||||
import top.fatweb.api.vo.permission.GroupVo
|
import top.fatweb.api.vo.permission.GroupVo
|
||||||
|
import top.fatweb.api.vo.permission.GroupWithRoleVo
|
||||||
|
|
||||||
object GroupConverter {
|
object GroupConverter {
|
||||||
fun groupToGroupVo(group: Group) = GroupVo(
|
fun groupToGroupVo(group: Group) = GroupVo(
|
||||||
@@ -14,13 +19,40 @@ object GroupConverter {
|
|||||||
updateTime = group.updateTime
|
updateTime = group.updateTime
|
||||||
)
|
)
|
||||||
|
|
||||||
fun groupPageToGroupPageVo(groupPage: IPage<Group>): PageVo<GroupVo> = PageVo(
|
fun groupToGroupWithRoleVo(group: Group) = GroupWithRoleVo(
|
||||||
|
id = group.id,
|
||||||
|
name = group.name,
|
||||||
|
enable = group.enable == 1,
|
||||||
|
createTime = group.createTime,
|
||||||
|
updateTime = group.updateTime,
|
||||||
|
roles = group.roles?.map { RoleConverter.roleToRoleVo(it) }
|
||||||
|
)
|
||||||
|
|
||||||
|
fun groupPageToGroupWithRolePageVo(groupPage: IPage<Group>): PageVo<GroupWithRoleVo> = PageVo(
|
||||||
total = groupPage.total,
|
total = groupPage.total,
|
||||||
pages = groupPage.pages,
|
pages = groupPage.pages,
|
||||||
size = groupPage.size,
|
size = groupPage.size,
|
||||||
current = groupPage.current,
|
current = groupPage.current,
|
||||||
records = groupPage.records.map {
|
records = groupPage.records.map {
|
||||||
groupToGroupVo(it)
|
groupToGroupWithRoleVo(it)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun groupAddParamToGroup(groupAddParam: GroupAddParam) = Group().apply {
|
||||||
|
name = groupAddParam.name
|
||||||
|
enable = if (groupAddParam.enable == true) 1 else 0
|
||||||
|
roles = groupAddParam.roleIds?.map { Role().apply { id = it } }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun groupUpdateParamToGroup(groupUpdateParam: GroupUpdateParam) = Group().apply {
|
||||||
|
id = groupUpdateParam.id
|
||||||
|
name = groupUpdateParam.name
|
||||||
|
enable = if (groupUpdateParam.enable == true) 1 else 0
|
||||||
|
roles = groupUpdateParam.roleIds?.map { Role().apply { id = it } }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun groupChangeStatusParamToGroup(groupChangeStatusParam: GroupChangeStatusParam) = Group().apply {
|
||||||
|
id = groupChangeStatusParam.id
|
||||||
|
enable = if (groupChangeStatusParam.enable) 1 else 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -15,5 +15,9 @@ import top.fatweb.api.entity.permission.Group
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
interface GroupMapper : BaseMapper<Group> {
|
interface GroupMapper : BaseMapper<Group> {
|
||||||
fun selectPage(page: IPage<Group>): IPage<Group>
|
fun selectPage(page: IPage<Long>, searchName: String?, searchRegex: Boolean): IPage<Long>
|
||||||
|
|
||||||
|
fun getWithRoleByList(groupIds: List<Long>): List<Group>?
|
||||||
|
|
||||||
|
fun selectOne(id: Long): Group?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package top.fatweb.api.param.authentication
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
|
import jakarta.validation.constraints.NotBlank
|
||||||
|
|
||||||
|
@Schema(description = "用户组添加请求参数")
|
||||||
|
data class GroupAddParam(
|
||||||
|
@Schema(description = "用户组名称")
|
||||||
|
@field:NotBlank(message = "Name can not be blank")
|
||||||
|
val name: String?,
|
||||||
|
|
||||||
|
@Schema(description = "启用", allowableValues = ["true", "false"])
|
||||||
|
val enable: Boolean? = true,
|
||||||
|
|
||||||
|
@Schema(description = "角色 ID 列表")
|
||||||
|
val roleIds: List<Long>? = null
|
||||||
|
)
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package top.fatweb.api.param.authentication
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
|
import jakarta.validation.constraints.Min
|
||||||
|
import jakarta.validation.constraints.NotNull
|
||||||
|
|
||||||
|
@Schema(description = "用户组更改状态请求参数")
|
||||||
|
data class GroupChangeStatusParam(
|
||||||
|
@Schema(description = "用户组 ID")
|
||||||
|
@field:Min(0)
|
||||||
|
val id: Long,
|
||||||
|
|
||||||
|
@Schema(description = "启用", allowableValues = ["true", "false"])
|
||||||
|
@field:NotNull
|
||||||
|
val enable: Boolean
|
||||||
|
)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package top.fatweb.api.param.authentication
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
|
|
||||||
|
@Schema(description = "用户组删除请求参数")
|
||||||
|
data class GroupDeleteParam(
|
||||||
|
@Schema(description = "用户组 ID 列表")
|
||||||
|
val ids: List<Long>
|
||||||
|
)
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package top.fatweb.api.param.authentication
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
|
import jakarta.validation.constraints.Min
|
||||||
|
import jakarta.validation.constraints.NotBlank
|
||||||
|
|
||||||
|
@Schema(description = "用户组更新请求参数")
|
||||||
|
data class GroupUpdateParam(
|
||||||
|
@Schema(description = "用户组 ID")
|
||||||
|
@field:Min(0)
|
||||||
|
val id: Long,
|
||||||
|
|
||||||
|
@Schema(description = "用户组名称")
|
||||||
|
@field:NotBlank(message = "Name can not be blank")
|
||||||
|
val name: String?,
|
||||||
|
|
||||||
|
@Schema(description = "启用", allowableValues = ["true", "false"])
|
||||||
|
val enable: Boolean? = true,
|
||||||
|
|
||||||
|
@Schema(description = "角色 ID 列表")
|
||||||
|
val roleIds: List<Long>? = null
|
||||||
|
)
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package top.fatweb.api.service.permission
|
package top.fatweb.api.service.permission
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService
|
import com.baomidou.mybatisplus.extension.service.IService
|
||||||
import top.fatweb.api.entity.permission.Group
|
import top.fatweb.api.entity.permission.Group
|
||||||
import top.fatweb.api.param.authentication.GroupGetParam
|
import top.fatweb.api.param.authentication.*
|
||||||
|
import top.fatweb.api.vo.PageVo
|
||||||
|
import top.fatweb.api.vo.permission.GroupVo
|
||||||
|
import top.fatweb.api.vo.permission.GroupWithRoleVo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -14,5 +16,19 @@ import top.fatweb.api.param.authentication.GroupGetParam
|
|||||||
* @since 2023-10-25
|
* @since 2023-10-25
|
||||||
*/
|
*/
|
||||||
interface IGroupService : IService<Group> {
|
interface IGroupService : IService<Group> {
|
||||||
fun getPage(groupGetParam: GroupGetParam?): IPage<Group>
|
fun getPage(groupGetParam: GroupGetParam?): PageVo<GroupWithRoleVo>
|
||||||
|
|
||||||
|
fun getOne(id: Long): GroupWithRoleVo?
|
||||||
|
|
||||||
|
fun listAll(): List<GroupVo>
|
||||||
|
|
||||||
|
fun add(groupAddParam: GroupAddParam): GroupVo?
|
||||||
|
|
||||||
|
fun update(groupUpdateParam: GroupUpdateParam): GroupVo?
|
||||||
|
|
||||||
|
fun changeStatus(groupChangeStatusParam: GroupChangeStatusParam): Boolean
|
||||||
|
|
||||||
|
fun deleteOne(id: Long)
|
||||||
|
|
||||||
|
fun delete(groupDeleteParam: GroupDeleteParam)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
package top.fatweb.api.service.permission.impl
|
package top.fatweb.api.service.permission.impl
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage
|
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
import org.springframework.transaction.annotation.Transactional
|
||||||
|
import top.fatweb.api.converter.permission.GroupConverter
|
||||||
import top.fatweb.api.entity.permission.Group
|
import top.fatweb.api.entity.permission.Group
|
||||||
|
import top.fatweb.api.entity.permission.RoleGroup
|
||||||
import top.fatweb.api.mapper.permission.GroupMapper
|
import top.fatweb.api.mapper.permission.GroupMapper
|
||||||
import top.fatweb.api.param.authentication.GroupGetParam
|
import top.fatweb.api.param.authentication.*
|
||||||
import top.fatweb.api.service.permission.IGroupService
|
import top.fatweb.api.service.permission.IGroupService
|
||||||
|
import top.fatweb.api.service.permission.IRoleGroupService
|
||||||
import top.fatweb.api.util.PageUtil
|
import top.fatweb.api.util.PageUtil
|
||||||
|
import top.fatweb.api.vo.PageVo
|
||||||
|
import top.fatweb.api.vo.permission.GroupVo
|
||||||
|
import top.fatweb.api.vo.permission.GroupWithRoleVo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -19,12 +26,104 @@ import top.fatweb.api.util.PageUtil
|
|||||||
* @since 2023-10-25
|
* @since 2023-10-25
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
class GroupServiceImpl : ServiceImpl<GroupMapper, Group>(), IGroupService {
|
class GroupServiceImpl(
|
||||||
override fun getPage(groupGetParam: GroupGetParam?): IPage<Group> {
|
private val roleGroupService: IRoleGroupService
|
||||||
val groupPage = Page<Group>(groupGetParam?.currentPage ?: 1, groupGetParam?.pageSize ?: 20)
|
) : ServiceImpl<GroupMapper, Group>(), IGroupService {
|
||||||
|
override fun getPage(groupGetParam: GroupGetParam?): PageVo<GroupWithRoleVo> {
|
||||||
|
val groupIdsPage = Page<Long>(groupGetParam?.currentPage ?: 1, groupGetParam?.pageSize ?: 20)
|
||||||
|
|
||||||
PageUtil.setPageSort(groupGetParam, groupPage)
|
PageUtil.setPageSort(groupGetParam, groupIdsPage)
|
||||||
|
|
||||||
return baseMapper.selectPage(groupPage)
|
val groupIdsIPage =
|
||||||
|
baseMapper.selectPage(groupIdsPage, groupGetParam?.searchName, groupGetParam?.searchRegex ?: false)
|
||||||
|
val groupPage = Page<Group>(groupIdsPage.current, groupIdsIPage.size, groupIdsIPage.total)
|
||||||
|
if (groupIdsIPage.total > 0) {
|
||||||
|
groupPage.setRecords(baseMapper.getWithRoleByList(groupIdsIPage.records))
|
||||||
|
}
|
||||||
|
|
||||||
|
return GroupConverter.groupPageToGroupWithRolePageVo(groupPage)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getOne(id: Long): GroupWithRoleVo? {
|
||||||
|
return baseMapper.selectOne(id)?.let { GroupConverter.groupToGroupWithRoleVo(it) } ?: let { null }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun listAll(): List<GroupVo> {
|
||||||
|
val groups = this.list()
|
||||||
|
|
||||||
|
return groups.map { GroupConverter.groupToGroupVo(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
override fun add(groupAddParam: GroupAddParam): GroupVo? {
|
||||||
|
val group = GroupConverter.groupAddParamToGroup(groupAddParam)
|
||||||
|
if (baseMapper.insert(group) == 1) {
|
||||||
|
if (group.roles.isNullOrEmpty()) {
|
||||||
|
return GroupConverter.groupToGroupVo(group)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (roleGroupService.saveBatch(group.roles!!.map {
|
||||||
|
RoleGroup().apply {
|
||||||
|
groupId = group.id
|
||||||
|
roleId = it.id
|
||||||
|
}
|
||||||
|
})) {
|
||||||
|
return GroupConverter.groupToGroupVo(group)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
override fun update(groupUpdateParam: GroupUpdateParam): GroupVo? {
|
||||||
|
val group = GroupConverter.groupUpdateParamToGroup(groupUpdateParam)
|
||||||
|
val oldRoleList = roleGroupService.list(
|
||||||
|
KtQueryWrapper(RoleGroup()).select(RoleGroup::roleId).eq(RoleGroup::groupId, groupUpdateParam.id)
|
||||||
|
).map { it.roleId }
|
||||||
|
val addRoleIds = HashSet<Long>()
|
||||||
|
val removeRoleIds = HashSet<Long>()
|
||||||
|
groupUpdateParam.roleIds?.forEach { addRoleIds.add(it) }
|
||||||
|
oldRoleList.forEach {
|
||||||
|
if (it != null) {
|
||||||
|
removeRoleIds.add(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
removeRoleIds.removeAll(addRoleIds)
|
||||||
|
oldRoleList.toSet().let { addRoleIds.removeAll(it) }
|
||||||
|
|
||||||
|
baseMapper.updateById(group)
|
||||||
|
|
||||||
|
removeRoleIds.forEach {
|
||||||
|
roleGroupService.remove(
|
||||||
|
KtQueryWrapper(RoleGroup()).eq(
|
||||||
|
RoleGroup::groupId, groupUpdateParam.id
|
||||||
|
).eq(RoleGroup::roleId, it)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
addRoleIds.forEach {
|
||||||
|
roleGroupService.save(RoleGroup().apply {
|
||||||
|
groupId = groupUpdateParam.id
|
||||||
|
roleId = it
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return GroupConverter.groupToGroupVo(group)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun changeStatus(groupChangeStatusParam: GroupChangeStatusParam): Boolean {
|
||||||
|
return updateById(GroupConverter.groupChangeStatusParamToGroup(groupChangeStatusParam))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
override fun deleteOne(id: Long) {
|
||||||
|
this.delete(GroupDeleteParam(listOf(id)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
override fun delete(groupDeleteParam: GroupDeleteParam) {
|
||||||
|
baseMapper.deleteBatchIds(groupDeleteParam.ids)
|
||||||
|
roleGroupService.remove(KtQueryWrapper(RoleGroup()).`in`(RoleGroup::groupId, groupDeleteParam.ids))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
data class GroupWithRoleVo(
|
||||||
|
@JsonSerialize(using = ToStringSerializer::class)
|
||||||
|
val id: Long?,
|
||||||
|
|
||||||
|
@Schema(description = "用户组名", example = "Role")
|
||||||
|
val name: String?,
|
||||||
|
|
||||||
|
@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 roles: List<RoleVo>?
|
||||||
|
)
|
||||||
@@ -1,8 +1,69 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="top.fatweb.api.mapper.permission.GroupMapper">
|
<mapper namespace="top.fatweb.api.mapper.permission.GroupMapper">
|
||||||
<select id="selectPage">
|
<select id="selectPage" resultType="long">
|
||||||
|
select id
|
||||||
|
from t_group
|
||||||
|
<where>
|
||||||
|
deleted = 0
|
||||||
|
<if test="searchName != null">
|
||||||
|
<choose>
|
||||||
|
<when test="searchRegex == true">
|
||||||
|
and t_group.name regexp #{searchName}
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
and t_group.name like concat('%' ,#{searchName}, '%')
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getWithRoleByList" resultMap="groupWithRoleMap">
|
||||||
|
select t_group.id as group_id,
|
||||||
|
t_group.name as group_name,
|
||||||
|
t_group.enable as group_enable,
|
||||||
|
t_group.create_time as group_create_time,
|
||||||
|
t_group.update_time as group_update_time,
|
||||||
|
t_group.deleted as group_deleted,
|
||||||
|
t_group.version as group_version,
|
||||||
|
tr.id as role_id,
|
||||||
|
tr.name as role_name,
|
||||||
|
tr.enable as role_enable,
|
||||||
|
tr.create_time as role_create_time,
|
||||||
|
tr.update_time as role_update_time,
|
||||||
|
tr.deleted as role_deleted,
|
||||||
|
tr.version as role_version
|
||||||
|
from (select * from t_group where deleted = 0) as t_group
|
||||||
|
left join (select * from t_role_group where deleted = 0) as trg on t_group.id = trg.group_id
|
||||||
|
left join (select * from t_role where deleted = 0) as tr on tr.id = trg.role_id
|
||||||
|
<where>
|
||||||
|
<foreach collection="groupIds" item="item" index="index" open="and t_group.id in (" separator="," close=")"
|
||||||
|
nullable="true">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectOne" resultMap="groupWithRoleMap">
|
||||||
|
select t_group.id as group_id,
|
||||||
|
t_group.name as group_name,
|
||||||
|
t_group.enable as group_enable,
|
||||||
|
t_group.create_time as group_create_time,
|
||||||
|
t_group.update_time as group_update_time,
|
||||||
|
t_group.deleted as group_deleted,
|
||||||
|
t_group.version as group_version,
|
||||||
|
tr.id as role_id,
|
||||||
|
tr.name as role_name,
|
||||||
|
tr.enable as role_enable,
|
||||||
|
tr.create_time as role_create_time,
|
||||||
|
tr.update_time as role_update_time,
|
||||||
|
tr.deleted as role_deleted,
|
||||||
|
tr.version as role_version
|
||||||
|
from (select * from t_group where deleted = 0) as t_group
|
||||||
|
left join (select * from t_role_group where deleted = 0) as trg on t_group.id = trg.group_id
|
||||||
|
left join (select * from t_role where deleted = 0) as tr on tr.id = trg.role_id
|
||||||
|
where t_group.id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<resultMap id="groupMap" type="group">
|
<resultMap id="groupMap" type="group">
|
||||||
@@ -14,4 +75,8 @@
|
|||||||
<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>
|
||||||
|
|
||||||
|
<resultMap id="groupWithRoleMap" type="group" extends="groupMap">
|
||||||
|
<collection property="roles" resultMap="top.fatweb.api.mapper.permission.RoleMapper.roleMap"/>
|
||||||
|
</resultMap>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user