diff --git a/api/src/main/java/com/wansensoft/api/role/SysRoleController.java b/api/src/main/java/com/wansensoft/api/role/SysRoleController.java index c6aa4129..87f02b8a 100644 --- a/api/src/main/java/com/wansensoft/api/role/SysRoleController.java +++ b/api/src/main/java/com/wansensoft/api/role/SysRoleController.java @@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.wansensoft.dto.role.AddOrUpdateRoleDTO; import com.wansensoft.dto.role.RoleListDTO; +import com.wansensoft.dto.role.RolePermissionDTO; import com.wansensoft.service.role.ISysRoleService; import com.wansensoft.service.role.KtSysRoleService; import com.wansensoft.service.system.ISysMenuService; @@ -75,4 +76,9 @@ public Response addOrUpdateRole(@RequestBody AddOrUpdateRoleDTO addOrUpd public Response deleteRole(@RequestParam(value = "id") String id) { return ktSysRoleService.deleteRole(id); } + + @PostMapping("permission") + public Response rolePermission(@RequestBody RolePermissionDTO rolePermissionDTO) { + return ktSysRoleService.rolePermission(rolePermissionDTO); + } } diff --git a/service/src/main/java/com/wansensoft/service/role/KtSysRoleService.kt b/service/src/main/java/com/wansensoft/service/role/KtSysRoleService.kt index 0b4d8dc4..2cc0cb1e 100644 --- a/service/src/main/java/com/wansensoft/service/role/KtSysRoleService.kt +++ b/service/src/main/java/com/wansensoft/service/role/KtSysRoleService.kt @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.IService import com.wansensoft.dto.role.AddOrUpdateRoleDTO import com.wansensoft.dto.role.RoleListDTO +import com.wansensoft.dto.role.RolePermissionDTO import com.wansensoft.entities.role.SysRole import com.wansensoft.utils.response.Response import com.wansensoft.vo.RoleVO @@ -19,4 +20,6 @@ interface KtSysRoleService : IService { fun addOrUpdateRole(addOrUpdateRoleDTO : AddOrUpdateRoleDTO?) : Response fun deleteRole(id: String?): Response + + fun rolePermission(rolePermissionDTO: RolePermissionDTO): Response } \ No newline at end of file diff --git a/service/src/main/java/com/wansensoft/service/role/KtSysRoleServiceImpl.kt b/service/src/main/java/com/wansensoft/service/role/KtSysRoleServiceImpl.kt index cdf27ae0..0488abca 100644 --- a/service/src/main/java/com/wansensoft/service/role/KtSysRoleServiceImpl.kt +++ b/service/src/main/java/com/wansensoft/service/role/KtSysRoleServiceImpl.kt @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl import com.wansensoft.dto.role.AddOrUpdateRoleDTO import com.wansensoft.dto.role.RoleListDTO +import com.wansensoft.dto.role.RolePermissionDTO import com.wansensoft.entities.role.SysRole import com.wansensoft.entities.role.SysRoleMenuRel import com.wansensoft.mappers.role.SysRoleMapper @@ -22,16 +23,17 @@ import java.time.LocalDateTime @Service open class KtSysRoleServiceImpl( - private val roleMapper: SysRoleMapper, - private val roleMenuRelMapper: SysRoleMenuRelMapper + private val roleMapper: SysRoleMapper, + private val roleMenuRelMapper: SysRoleMenuRelMapper, + private val roleMenuRelService: ISysRoleMenuRelService ) : ServiceImpl(), KtSysRoleService { override fun roleList(): Response> { val roles = ArrayList() val sysRoles = lambdaQuery() - .eq(SysRole::getDeleteFlag, CommonConstants.NOT_DELETED) - .list() + .eq(SysRole::getDeleteFlag, CommonConstants.NOT_DELETED) + .list() sysRoles.forEach { item -> val roleVo = RoleVO() BeanUtils.copyProperties(item, roleVo) @@ -66,18 +68,18 @@ open class KtSysRoleServiceImpl( } listVo.forEach { roleVo -> val roleMenuRelList = roleMenuRelMapper.selectList( - LambdaQueryWrapper() - .eq(SysRoleMenuRel::getRoleId, roleVo.id) + LambdaQueryWrapper() + .eq(SysRoleMenuRel::getRoleId, roleVo.id) ) val menuList = ArrayList() - roleMenuRelList.forEach { roleMenuRel -> - val menuId = roleMenuRel.menuId - val regex = "\\d+".toRegex() - val matchResult = regex.findAll(menuId) - matchResult.forEach { match -> - menuList.add(match.value.toInt()) - } + roleMenuRelList.forEach { roleMenuRel -> + val menuId = roleMenuRel.menuId + val regex = "\\d+".toRegex() + val matchResult = regex.findAll(menuId) + matchResult.forEach { match -> + menuList.add(match.value.toInt()) } + } roleVo.menuIds = menuList } Page().apply { @@ -100,9 +102,9 @@ open class KtSysRoleServiceImpl( } val updateResult = lambdaUpdate() - .eq(SysRole::getId, id) - .set(SysRole::getStatus, status) - .update() + .eq(SysRole::getId, id) + .set(SysRole::getStatus, status) + .update() return if (updateResult) { Response.responseMsg(RoleCodeEnum.UPDATE_ROLE_STATUS_SUCCESS) @@ -158,9 +160,9 @@ open class KtSysRoleServiceImpl( return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL) } val deleteResult = lambdaUpdate() - .eq(SysRole::getId, roleId) - .set(SysRole::getDeleteFlag, CommonConstants.DELETED) - .update() + .eq(SysRole::getId, roleId) + .set(SysRole::getDeleteFlag, CommonConstants.DELETED) + .update() return if (deleteResult) { Response.responseMsg(RoleCodeEnum.DELETE_ROLE_SUCCESS) @@ -170,4 +172,26 @@ open class KtSysRoleServiceImpl( } return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL) } + + // 帮我优化rolePermission方法 + + override fun rolePermission(rolePermissionDTO: RolePermissionDTO): Response { + val roleId = rolePermissionDTO.id + val menuIds = rolePermissionDTO.menuIds + if (roleId == null || menuIds.isEmpty()) { + return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL) + } + + val roleMenuRel = SysRoleMenuRel() + val menuIdStr = menuIds.joinToString(separator = "") { "[${it}]" } + roleMenuRel.menuId = menuIdStr + roleMenuRel.roleId = roleId + // 进行saveOrUpdate操作 + val saveBatchResult = roleMenuRelService.saveOrUpdate(roleMenuRel); + return if (saveBatchResult) { + Response.responseMsg(RoleCodeEnum.ROLE_PERMISSION_MENU_SUCCESS) + } else { + Response.responseMsg(RoleCodeEnum.ROLE_PERMISSION_MENU_ERROR) + } + } } \ No newline at end of file diff --git a/utils/src/main/java/com/wansensoft/utils/enums/RoleCodeEnum.java b/utils/src/main/java/com/wansensoft/utils/enums/RoleCodeEnum.java index 2e735b19..88e56d7d 100644 --- a/utils/src/main/java/com/wansensoft/utils/enums/RoleCodeEnum.java +++ b/utils/src/main/java/com/wansensoft/utils/enums/RoleCodeEnum.java @@ -19,7 +19,11 @@ public enum RoleCodeEnum { DELETE_ROLE_SUCCESS("A0007", "删除角色成功"), - DELETE_ROLE_ERROR("A0210", "删除角色失败"); + DELETE_ROLE_ERROR("A0210", "删除角色失败"), + + ROLE_PERMISSION_MENU_SUCCESS("A0008", "赋予角色菜单权限成功"), + + ROLE_PERMISSION_MENU_ERROR("A0211", "赋予角色菜单权限失败"); /** * 响应状态码