? = null
+)
diff --git a/src/main/kotlin/top/fatweb/api/param/authentication/RoleGetParam.kt b/src/main/kotlin/top/fatweb/api/param/authentication/RoleGetParam.kt
new file mode 100644
index 0000000..99e44e3
--- /dev/null
+++ b/src/main/kotlin/top/fatweb/api/param/authentication/RoleGetParam.kt
@@ -0,0 +1,12 @@
+package top.fatweb.api.param.authentication
+
+import io.swagger.v3.oas.annotations.media.Schema
+import top.fatweb.api.param.PageSortParam
+
+data class RoleGetParam(
+ @Schema(description = "查询角色名称")
+ val searchName: String? = null,
+
+ @Schema(description = "查询使用正则表达式")
+ val searchRegex: Boolean = false,
+) : PageSortParam()
diff --git a/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt b/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt
index 929f2ae..c605079 100644
--- a/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt
+++ b/src/main/kotlin/top/fatweb/api/param/system/SysLogGetParam.kt
@@ -2,17 +2,11 @@ package top.fatweb.api.param.system
import io.swagger.v3.oas.annotations.media.Schema
import org.springframework.format.annotation.DateTimeFormat
-import top.fatweb.api.param.PageParam
+import top.fatweb.api.param.PageSortParam
import java.time.LocalDateTime
@Schema(description = "获取系统日志请求参数")
data class SysLogGetParam(
- @Schema(description = "排序字段", example = "id")
- val sortField: String? = null,
-
- @Schema(description = "排序方式", example = "desc", allowableValues = ["desc", "asc"])
- val sortOrder: String? = null,
-
@Schema(description = "类型过滤(多个使用逗号分隔)", example = "INFO", allowableValues = ["INFO", "ERROR"])
val logType: String? = null,
@@ -36,4 +30,4 @@ data class SysLogGetParam(
@Schema(description = "查询结束时间")
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
val searchEndTime: LocalDateTime? = null
-) : PageParam()
\ No newline at end of file
+) : PageSortParam()
\ No newline at end of file
diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IGroupService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IGroupService.kt
index 7361f63..73c88b3 100644
--- a/src/main/kotlin/top/fatweb/api/service/permission/IGroupService.kt
+++ b/src/main/kotlin/top/fatweb/api/service/permission/IGroupService.kt
@@ -1,7 +1,9 @@
package top.fatweb.api.service.permission
+import com.baomidou.mybatisplus.core.metadata.IPage
import com.baomidou.mybatisplus.extension.service.IService
import top.fatweb.api.entity.permission.Group
+import top.fatweb.api.param.authentication.GroupGetParam
/**
*
@@ -11,4 +13,6 @@ import top.fatweb.api.entity.permission.Group
* @author FatttSnake
* @since 2023-10-25
*/
-interface IGroupService : IService
+interface IGroupService : IService {
+ fun getPage(groupGetParam: GroupGetParam?): IPage
+}
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 afe7289..a019bc6 100644
--- a/src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt
+++ b/src/main/kotlin/top/fatweb/api/service/permission/IRoleService.kt
@@ -1,7 +1,11 @@
package top.fatweb.api.service.permission
+import com.baomidou.mybatisplus.core.metadata.IPage
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.RoleGetParam
+import top.fatweb.api.vo.permission.RoleVo
/**
*
@@ -11,4 +15,8 @@ import top.fatweb.api.entity.permission.Role
* @author FatttSnake
* @since 2023-10-25
*/
-interface IRoleService : IService
+interface IRoleService : IService {
+ fun getPage(roleGetParam: RoleGetParam?): IPage
+
+ fun add(roleAddParam: RoleAddParam): RoleVo?
+}
diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/GroupServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/GroupServiceImpl.kt
index f7f5694..811464d 100644
--- a/src/main/kotlin/top/fatweb/api/service/permission/impl/GroupServiceImpl.kt
+++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/GroupServiceImpl.kt
@@ -1,10 +1,14 @@
package top.fatweb.api.service.permission.impl
+import com.baomidou.mybatisplus.core.metadata.IPage
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import org.springframework.stereotype.Service
import top.fatweb.api.entity.permission.Group
import top.fatweb.api.mapper.permission.GroupMapper
+import top.fatweb.api.param.authentication.GroupGetParam
import top.fatweb.api.service.permission.IGroupService
+import top.fatweb.api.util.PageUtil
/**
*
@@ -15,4 +19,12 @@ import top.fatweb.api.service.permission.IGroupService
* @since 2023-10-25
*/
@Service
-class GroupServiceImpl : ServiceImpl(), IGroupService
+class GroupServiceImpl : ServiceImpl(), IGroupService {
+ override fun getPage(groupGetParam: GroupGetParam?): IPage {
+ val groupPage = Page(groupGetParam?.currentPage ?: 1, groupGetParam?.pageSize ?: 20)
+
+ PageUtil.setPageSort(groupGetParam, groupPage)
+
+ return baseMapper.selectPage(groupPage)
+ }
+}
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 34ab16a..931d6d9 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
@@ -1,10 +1,20 @@
package top.fatweb.api.service.permission.impl
+import com.baomidou.mybatisplus.core.metadata.IPage
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import org.springframework.stereotype.Service
+import org.springframework.transaction.annotation.Transactional
+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.RoleGetParam
+import top.fatweb.api.service.permission.IPowerRoleService
import top.fatweb.api.service.permission.IRoleService
+import top.fatweb.api.util.PageUtil
+import top.fatweb.api.vo.permission.RoleVo
/**
*
@@ -15,4 +25,35 @@ import top.fatweb.api.service.permission.IRoleService
* @since 2023-10-25
*/
@Service
-class RoleServiceImpl : ServiceImpl(), IRoleService
+class RoleServiceImpl(
+ private val powerRoleService: IPowerRoleService
+) : ServiceImpl(), IRoleService {
+ override fun getPage(roleGetParam: RoleGetParam?): IPage {
+ val rolePage = Page(roleGetParam?.currentPage ?: 1, roleGetParam?.pageSize ?: 20)
+
+ PageUtil.setPageSort(roleGetParam, rolePage)
+
+ return baseMapper.selectPage(rolePage)
+ }
+
+
+ @Transactional
+ override fun add(roleAddParam: RoleAddParam): RoleVo? {
+ val role = RoleConverter.roleAddParamToRole(roleAddParam)
+ if (baseMapper.insert(role) == 1) {
+ if (powerRoleService.saveBatch(
+ roleAddParam.powerIds?.map {
+ PowerRole().apply {
+ roleId = role.id
+ powerId = it
+ }
+ }
+ )
+ ) {
+ return RoleConverter.roleToRoleVo(role)
+ }
+ }
+
+ return null
+ }
+}
diff --git a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt
index 403b6a5..518983d 100644
--- a/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt
+++ b/src/main/kotlin/top/fatweb/api/service/system/impl/SysLogServiceImpl.kt
@@ -9,7 +9,7 @@ import top.fatweb.api.entity.system.SysLog
import top.fatweb.api.mapper.system.SysLogMapper
import top.fatweb.api.param.system.SysLogGetParam
import top.fatweb.api.service.system.ISysLogService
-import top.fatweb.api.util.StrUtil
+import top.fatweb.api.util.PageUtil
/**
*
@@ -24,20 +24,7 @@ class SysLogServiceImpl : ServiceImpl(), ISysLogService {
override fun getPage(sysLogGetParam: SysLogGetParam?): IPage {
val sysLogPage = Page(sysLogGetParam?.currentPage ?: 1, sysLogGetParam?.pageSize ?: 20)
- if (sysLogGetParam?.sortField == null && sysLogGetParam?.sortOrder == null) {
- sysLogPage.addOrder(OrderItem.desc("start_time"))
- } else {
- sysLogPage.addOrder(
- if (sysLogGetParam.sortOrder?.startsWith(
- "desc", true
- ) == true
- ) OrderItem.desc(StrUtil.upperToUnderLetter(sysLogGetParam.sortField)) else OrderItem.asc(
- StrUtil.upperToUnderLetter(
- sysLogGetParam.sortField
- )
- )
- )
- }
+ PageUtil.setPageSort(sysLogGetParam, sysLogPage, OrderItem.desc("start_time"))
return baseMapper.selectPage(
sysLogPage,
diff --git a/src/main/kotlin/top/fatweb/api/util/PageUtil.kt b/src/main/kotlin/top/fatweb/api/util/PageUtil.kt
new file mode 100644
index 0000000..2d5c11a
--- /dev/null
+++ b/src/main/kotlin/top/fatweb/api/util/PageUtil.kt
@@ -0,0 +1,24 @@
+package top.fatweb.api.util
+
+import com.baomidou.mybatisplus.core.metadata.OrderItem
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page
+import top.fatweb.api.param.PageSortParam
+
+object PageUtil {
+ fun > setPageSort(pageSortParam: PageSortParam?, page: T, defaultOrder: OrderItem? = null) {
+ if (pageSortParam?.sortField != null || pageSortParam?.sortOrder != null) {
+ page.addOrder(
+ if (pageSortParam.sortOrder?.startsWith(
+ "desc", true
+ ) == true
+ ) OrderItem.desc(StrUtil.upperToUnderLetter(pageSortParam.sortField)) else OrderItem.asc(
+ StrUtil.upperToUnderLetter(
+ pageSortParam.sortField
+ )
+ )
+ )
+ } else {
+ defaultOrder?.let { page.addOrder(defaultOrder) }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/top/fatweb/api/vo/permission/RoleWithPowerVo.kt b/src/main/kotlin/top/fatweb/api/vo/permission/RoleWithPowerVo.kt
new file mode 100644
index 0000000..da12b43
--- /dev/null
+++ b/src/main/kotlin/top/fatweb/api/vo/permission/RoleWithPowerVo.kt
@@ -0,0 +1,17 @@
+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
+
+@Schema(description = "角色返回参数")
+data class RoleWithPowerVo(
+ @JsonSerialize(using = ToStringSerializer::class)
+ val id: Long?,
+
+ @Schema(description = "角色名", example = "Role")
+ val name: String?,
+
+ @Schema(description = "启用", example = "true")
+ val enable: Boolean?
+)
diff --git a/src/main/resources/db/migration/R__Basic_data.sql b/src/main/resources/db/migration/R__Basic_data.sql
index 61c4500..4a12727 100644
--- a/src/main/resources/db/migration/R__Basic_data.sql
+++ b/src/main/resources/db/migration/R__Basic_data.sql
@@ -6,7 +6,35 @@ insert into t_power_type (id, name)
on duplicate key update name = new_value.name;
insert into t_power (id, type_id)
- values (1000000, 1) as new_value
+ values (1000000, 1),
+ (1990000, 2),
+ (1010000, 2),
+ (1020000, 2),
+ (1030000, 2),
+ (1010100, 3),
+ (1010200, 3),
+ (1010300, 3),
+ (1020100, 3),
+ (1020200, 3),
+ (1020300, 3),
+ (1020400, 3),
+ (1030100, 3),
+ (1030200, 3),
+ (1030300, 3),
+ (1030400, 3),
+ (1010101, 4),
+ (1010102, 4),
+ (1010201, 4),
+ (1010301, 4),
+ (1020101, 4),
+ (1020201, 4),
+ (1020301, 4),
+ (1020401, 4),
+ (1030101, 4),
+ (1030201, 4),
+ (1030301, 4),
+ (1030401, 4)
+ as new_value
on duplicate key update type_id = new_value.type_id;
insert into t_module (id, name, power_id)
diff --git a/src/main/resources/mapper/permission/ElementMapper.xml b/src/main/resources/mapper/permission/ElementMapper.xml
index f29cb9f..f0ee1c0 100644
--- a/src/main/resources/mapper/permission/ElementMapper.xml
+++ b/src/main/resources/mapper/permission/ElementMapper.xml
@@ -1,5 +1,11 @@
-
+
+
+
+
+
+
+
diff --git a/src/main/resources/mapper/permission/GroupMapper.xml b/src/main/resources/mapper/permission/GroupMapper.xml
index 861ee18..5879801 100644
--- a/src/main/resources/mapper/permission/GroupMapper.xml
+++ b/src/main/resources/mapper/permission/GroupMapper.xml
@@ -1,5 +1,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/mapper/permission/MenuMapper.xml b/src/main/resources/mapper/permission/MenuMapper.xml
index aaf1664..22b998f 100644
--- a/src/main/resources/mapper/permission/MenuMapper.xml
+++ b/src/main/resources/mapper/permission/MenuMapper.xml
@@ -1,5 +1,12 @@
-
+
diff --git a/src/main/resources/mapper/permission/ModuleMapper.xml b/src/main/resources/mapper/permission/ModuleMapper.xml
index 4e9b314..36764b2 100644
--- a/src/main/resources/mapper/permission/ModuleMapper.xml
+++ b/src/main/resources/mapper/permission/ModuleMapper.xml
@@ -1,5 +1,9 @@
-
+
+
+
+
+
diff --git a/src/main/resources/mapper/permission/OperationMapper.xml b/src/main/resources/mapper/permission/OperationMapper.xml
index 174b17b..50e1e15 100644
--- a/src/main/resources/mapper/permission/OperationMapper.xml
+++ b/src/main/resources/mapper/permission/OperationMapper.xml
@@ -1,5 +1,11 @@
-
+
+
+
+
+
+
+
diff --git a/src/main/resources/mapper/permission/PowerMapper.xml b/src/main/resources/mapper/permission/PowerMapper.xml
index c9854f0..dde3f8c 100644
--- a/src/main/resources/mapper/permission/PowerMapper.xml
+++ b/src/main/resources/mapper/permission/PowerMapper.xml
@@ -1,5 +1,8 @@
-
+
+
+
+
diff --git a/src/main/resources/mapper/permission/RoleMapper.xml b/src/main/resources/mapper/permission/RoleMapper.xml
index b84d046..2f9b5ac 100644
--- a/src/main/resources/mapper/permission/RoleMapper.xml
+++ b/src/main/resources/mapper/permission/RoleMapper.xml
@@ -1,5 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/mapper/permission/UserInfoMapper.xml b/src/main/resources/mapper/permission/UserInfoMapper.xml
index 6ad303b..bdaf75a 100644
--- a/src/main/resources/mapper/permission/UserInfoMapper.xml
+++ b/src/main/resources/mapper/permission/UserInfoMapper.xml
@@ -1,5 +1,15 @@
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/mapper/permission/UserMapper.xml b/src/main/resources/mapper/permission/UserMapper.xml
index 1102e10..248568e 100644
--- a/src/main/resources/mapper/permission/UserMapper.xml
+++ b/src/main/resources/mapper/permission/UserMapper.xml
@@ -125,65 +125,18 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+