角色权限列表查询,查看权限

master
shijie 4 years ago
parent 9c5987aa7b
commit c2a4d1250b
  1. 12
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/RolePermissionController.java
  2. 8
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/RolePermissionMapper.java
  3. 3
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/RolePermissionService.java
  4. 19
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/RolePermissionServiceImpl.java
  5. 10
      dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/RolePermissionMapper.xml
  6. 38
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/RolePermissionResponse.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<PageUtils>().SUCCESS(data);
}
/**
* 查看权限
* @param roleId
* @return
*/
@GetMapping("/queryPermissionByRoleId")
public ResponseResult queryPermissionByRoleId(@RequestParam("roleId") Long roleId) {
List<RolePermissionResponse> list = permissionService.listWithPermissionTree(roleId);
return new ResponseResult<List<RolePermissionResponse>>().SUCCESS(list);
}
}

@ -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<PermissionEntity> {
IPage<PermissionEntity> pageByCondition(Page page);
IPage<RolePermissionResponse> pageByCondition(Page page);
List<RolePermissionResponse> queryPermissionByRoleId(Long roleId);
}

@ -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<PermissionEntity> {
List<PermissionEntity> listWithTree();
List<RolePermissionResponse> listWithPermissionTree(Long roleId);
PageUtils queryPage(Integer page, Integer size);
}

@ -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<RolePermissionMapper,
@Override
public List<PermissionEntity> listWithTree() {
System.out.println("this.list()=================="+this.list());
return getPermissionTreeList(this.list(), 0L);
}
@ -31,7 +33,7 @@ public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper,
if (size <= 0) {
size = 10;
}
IPage<PermissionEntity> systemLogVo = this.getBaseMapper().pageByCondition(new Page(page, size));
IPage<RolePermissionResponse> systemLogVo = this.getBaseMapper().pageByCondition(new Page(page, size));
return new PageUtils(systemLogVo);
}
@ -44,4 +46,19 @@ public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper,
.collect(Collectors.toList());
}
@Override
public List<RolePermissionResponse> listWithPermissionTree(Long roleId) {
//根据角色id查询单个角色对应的所有权限
List<RolePermissionResponse>list = this.getBaseMapper().queryPermissionByRoleId(roleId);
return getRolePermissionTreeList(list, 0L);
}
private List<RolePermissionResponse> getRolePermissionTreeList(List<RolePermissionResponse> 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());
}
}

@ -19,12 +19,20 @@
<result property="motifyTime" column="motify_time"/>
</resultMap>
<select id="pageByCondition" resultType="com.daqing.framework.domain.hrms.response.RolePermissionResponse">
select hr.`name`,hr.description,GROUP_CONCAT(hp.`name`separator '/') as permissionName
select hr.id as roleId, hr.`name`,hr.description,GROUP_CONCAT(hp.`name`separator '/') as permissionName
FROM hrms_role_permission rp
LEFT JOIN hrms_role hr on hr.id = rp.role_id
LEFT JOIN hrms_permission hp on hp.id= rp.permission_id
GROUP BY rp.role_id
</select>
<select id="queryPermissionByRoleId" parameterType="long"
resultType="com.daqing.framework.domain.hrms.response.RolePermissionResponse">
select rp.permission_id, hp.`name`as permissionName, hp.parent_id, hp.sort from hrms_role_permission rp
LEFT JOIN hrms_permission hp on hp.id=rp.permission_id
WHERE rp.role_id=#{roleId}
</select>
</mapper>

@ -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<RolePermissionResponse> children;
/**
* 排序
*/
private Integer sort;
}

Loading…
Cancel
Save