From c2a4d1250b9bf6bd16b889ba9809e6cd8d2ad2cb Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Mon, 12 Oct 2020 17:43:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=92=E8=89=B2=E6=9D=83=E9=99=90=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2,=E6=9F=A5=E7=9C=8B=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RolePermissionController.java | 12 ++++++ .../hrauth/dao/RolePermissionMapper.java | 8 +++- .../hrauth/service/RolePermissionService.java | 3 ++ .../impl/RolePermissionServiceImpl.java | 19 +++++++++- .../mapper/hrmsauth/RolePermissionMapper.xml | 10 ++++- .../hrms/response/RolePermissionResponse.java | 38 +++++++++++++++++-- 6 files changed, 83 insertions(+), 7 deletions(-) diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java index a01d419f..4b4708d6 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java @@ -2,6 +2,7 @@ package com.daqing.financial.hrauth.controller; import com.daqing.financial.hrauth.service.RolePermissionService; import com.daqing.framework.domain.hrms.PermissionEntity; +import com.daqing.framework.domain.hrms.response.RolePermissionResponse; import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.utils.PageUtils; import io.swagger.annotations.Api; @@ -49,4 +50,15 @@ public class RolePermissionController { return new ResponseResult().SUCCESS(data); } + /** + * 查看权限 + * @param roleId + * @return + */ + @GetMapping("/queryPermissionByRoleId") + public ResponseResult queryPermissionByRoleId(@RequestParam("roleId") Long roleId) { + List list = permissionService.listWithPermissionTree(roleId); + return new ResponseResult>().SUCCESS(list); + } + } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/RolePermissionMapper.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/RolePermissionMapper.java index 1eb2828c..b21801c3 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/RolePermissionMapper.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/RolePermissionMapper.java @@ -5,8 +5,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.daqing.framework.domain.hrms.PermissionEntity; import com.daqing.framework.domain.hrms.SystemLog; +import com.daqing.framework.domain.hrms.response.RolePermissionResponse; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 记录菜单权限 * @@ -16,6 +19,7 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface RolePermissionMapper extends BaseMapper { - IPage pageByCondition(Page page); - + IPage pageByCondition(Page page); + + List queryPermissionByRoleId(Long roleId); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java index 1daecfdc..3e7b152c 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java @@ -2,6 +2,7 @@ package com.daqing.financial.hrauth.service; import com.baomidou.mybatisplus.extension.service.IService; import com.daqing.framework.domain.hrms.PermissionEntity; +import com.daqing.framework.domain.hrms.response.RolePermissionResponse; import com.daqing.framework.utils.PageUtils; import java.util.List; @@ -17,6 +18,8 @@ public interface RolePermissionService extends IService { List listWithTree(); + List listWithPermissionTree(Long roleId); + PageUtils queryPage(Integer page, Integer size); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java index 424401b1..6032ce61 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.daqing.financial.hrauth.dao.RolePermissionMapper; import com.daqing.financial.hrauth.service.RolePermissionService; import com.daqing.framework.domain.hrms.PermissionEntity; +import com.daqing.framework.domain.hrms.response.RolePermissionResponse; import com.daqing.framework.utils.PageUtils; import org.springframework.stereotype.Service; @@ -19,6 +20,7 @@ public class RolePermissionServiceImpl extends ServiceImpl listWithTree() { + System.out.println("this.list()=================="+this.list()); return getPermissionTreeList(this.list(), 0L); } @@ -31,7 +33,7 @@ public class RolePermissionServiceImpl extends ServiceImpl systemLogVo = this.getBaseMapper().pageByCondition(new Page(page, size)); + IPage systemLogVo = this.getBaseMapper().pageByCondition(new Page(page, size)); return new PageUtils(systemLogVo); } @@ -44,4 +46,19 @@ public class RolePermissionServiceImpl extends ServiceImpl listWithPermissionTree(Long roleId) { + //根据角色id查询单个角色对应的所有权限 + Listlist = this.getBaseMapper().queryPermissionByRoleId(roleId); + return getRolePermissionTreeList(list, 0L); + } + + private List getRolePermissionTreeList(List list, Long parentId) { + return list.stream() + .filter(item -> parentId.equals(item.getParentId())) + .peek(item -> item.setChildren(getRolePermissionTreeList(list, item.getPermissionId()))) + .sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) + .collect(Collectors.toList()); + } + } \ No newline at end of file diff --git a/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/RolePermissionMapper.xml b/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/RolePermissionMapper.xml index 3ead99c3..fbb230f3 100644 --- a/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/RolePermissionMapper.xml +++ b/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/RolePermissionMapper.xml @@ -19,12 +19,20 @@ + + + \ No newline at end of file diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/RolePermissionResponse.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/RolePermissionResponse.java index 47bca555..3c2af371 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/RolePermissionResponse.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/RolePermissionResponse.java @@ -1,14 +1,11 @@ package com.daqing.framework.domain.hrms.response; -import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; import java.io.Serializable; -import java.util.Date; import java.util.List; /** @@ -23,10 +20,45 @@ import java.util.List; public class RolePermissionResponse implements Serializable { private static final long serialVersionUID = 1L; + /** + * 角色id + */ + private Long roleId; + /** + * 角色名称 + */ private String name; + /** + * 角色描述 + */ private String description; + /** + * 权限id + */ + private Long permissionId; + + /** + * 拥有权限名称 + */ private String permissionName; + /** + * 父级id + */ + private Long parentId; + + /** + * 子权限 + */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @TableField(exist = false) + private List children; + + /** + * 排序 + */ + private Integer sort; + }