parent
bf25ec2de9
commit
062963fbc0
11 changed files with 221 additions and 25 deletions
@ -0,0 +1,52 @@ |
||||
package com.daqing.financial.hrauth.controller; |
||||
|
||||
import com.daqing.financial.hrauth.service.RolePermissionService; |
||||
import com.daqing.framework.domain.hrms.PermissionEntity; |
||||
import com.daqing.framework.model.response.ResponseResult; |
||||
import com.daqing.framework.utils.PageUtils; |
||||
import io.swagger.annotations.Api; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* @auther River |
||||
* @date 2020/9/22 15:27 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/hrms/auth/permission") |
||||
@Api(tags = {"角色权限管理"}) |
||||
public class RolePermissionController { |
||||
|
||||
@Autowired |
||||
private RolePermissionService permissionService; |
||||
|
||||
/** |
||||
* 权限菜单树形列表展示 |
||||
* @return |
||||
*/ |
||||
@GetMapping("/tree") |
||||
public ResponseResult tree() { |
||||
List<PermissionEntity> list = permissionService.listWithTree(); |
||||
return new ResponseResult<List<PermissionEntity>>().SUCCESS(list); |
||||
} |
||||
|
||||
/** |
||||
* 角色权限列表展示 |
||||
* @param page |
||||
* @param size |
||||
* @return |
||||
*/ |
||||
@GetMapping("/rolePermissionList") |
||||
public ResponseResult rolePermissionList(@RequestParam("page") Integer page, |
||||
@RequestParam("size") Integer size) { |
||||
PageUtils data = permissionService.queryPage(page, size); |
||||
return new ResponseResult<PageUtils>().SUCCESS(data); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,21 @@ |
||||
package com.daqing.financial.hrauth.dao; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
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 org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* 记录菜单权限 |
||||
* |
||||
* @author gongsj |
||||
* @email gongsj@gmail.com |
||||
* @date 2020-09-07 16:26:04 |
||||
*/ |
||||
@Mapper |
||||
public interface PermissionDao extends BaseMapper<PermissionEntity> { |
||||
IPage<PermissionEntity> pageByCondition(Page page); |
||||
|
||||
} |
@ -0,0 +1,23 @@ |
||||
package com.daqing.financial.hrauth.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import com.daqing.framework.domain.hrms.PermissionEntity; |
||||
import com.daqing.framework.utils.PageUtils; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 记录菜单权限 |
||||
* |
||||
* @author gongsj |
||||
* @email gongsj@gmail.com |
||||
* @date 2020-09-07 16:26:04 |
||||
*/ |
||||
public interface RolePermissionService extends IService<PermissionEntity> { |
||||
|
||||
List<PermissionEntity> listWithTree(); |
||||
|
||||
PageUtils queryPage(Integer page, Integer size); |
||||
|
||||
} |
||||
|
@ -0,0 +1,48 @@ |
||||
package com.daqing.financial.hrauth.service.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 com.daqing.financial.hrauth.dao.PermissionDao; |
||||
import com.daqing.financial.hrauth.service.RolePermissionService; |
||||
import com.daqing.framework.domain.hrms.PermissionEntity; |
||||
import com.daqing.framework.domain.hrms.SystemLog; |
||||
import com.daqing.framework.utils.PageUtils; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
|
||||
@Service("rolePermissionService") |
||||
public class RolePermissionServiceImpl extends ServiceImpl<PermissionDao, PermissionEntity> implements RolePermissionService { |
||||
|
||||
@Override |
||||
public List<PermissionEntity> listWithTree() { |
||||
return getPermissionTreeList(this.list(), 0L); |
||||
} |
||||
|
||||
@Override |
||||
public PageUtils queryPage(Integer page, Integer size) { |
||||
//分页参数
|
||||
if (page <= 0) { |
||||
page = 1; |
||||
} |
||||
if (size <= 0) { |
||||
size = 10; |
||||
} |
||||
IPage<PermissionEntity> systemLogVo = this.getBaseMapper().pageByCondition(new Page(page, size)); |
||||
|
||||
return new PageUtils(systemLogVo); |
||||
} |
||||
|
||||
private List<PermissionEntity> getPermissionTreeList(List<PermissionEntity> list, Long parentId) { |
||||
return list.stream() |
||||
.filter(item -> parentId.equals(item.getParentId())) |
||||
.peek(item -> item.setChildren(getPermissionTreeList(list, item.getId()))) |
||||
.sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) |
||||
.collect(Collectors.toList()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,30 @@ |
||||
<?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"> |
||||
|
||||
<mapper namespace="com.daqing.financial.hrauth.dao.PermissionDao"> |
||||
|
||||
<!-- 可根据自己的需求,是否要使用 --> |
||||
<resultMap type="com.daqing.framework.domain.hrms.PermissionEntity" id="permissionMap"> |
||||
<result property="id" column="id"/> |
||||
<result property="code" column="code"/> |
||||
<result property="name" column="name"/> |
||||
<result property="url" column="url"/> |
||||
<result property="parentId" column="parent_id"/> |
||||
<result property="level" column="level"/> |
||||
<result property="menuOrNot" column="menu_or_not"/> |
||||
<result property="status" column="status"/> |
||||
<result property="sort" column="sort"/> |
||||
<result property="icon" column="icon"/> |
||||
<result property="createTime" column="create_time"/> |
||||
<result property="motifyTime" column="motify_time"/> |
||||
</resultMap> |
||||
<select id="pageByCondition" resultType="com.daqing.framework.domain.hrms.PermissionEntity"> |
||||
select hr.`name`,hr.description,GROUP_CONCAT(hp.`name`separator '/') |
||||
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> |
||||
|
||||
|
||||
</mapper> |
@ -0,0 +1,27 @@ |
||||
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; |
||||
|
||||
/** |
||||
* 记录菜单权限 |
||||
* |
||||
* @author gongsj |
||||
* @email gongsj@gmail.com |
||||
* @date 2020-09-07 17:12:14 |
||||
*/ |
||||
@Data |
||||
@TableName("hrms_permission") |
||||
public class RolePermissionResponse implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue