完善部分权限
This commit is contained in:
@ -52,6 +52,9 @@ public class Role implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private Set<Menu> menus;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Set<Dept> depts;
|
||||
|
||||
/** 创建日期 */
|
||||
@TableField(fill= FieldFill.INSERT)
|
||||
private Timestamp createTime;
|
||||
|
@ -261,7 +261,13 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
||||
*/
|
||||
@Override
|
||||
public List<MenuDto> findByRoles(List<RoleSmallDto> roles) {
|
||||
return null;
|
||||
List<Long> roleIds = roles.stream().map(i ->{
|
||||
Long role = i.getId();
|
||||
return role;
|
||||
}).collect(Collectors.toList());
|
||||
List<Menu> list = menuMapper.selectListByRoles(roleIds);
|
||||
|
||||
return generator.convert(list,MenuDto.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,8 +12,12 @@ import co.yixiang.modules.system.domain.Dept;
|
||||
import co.yixiang.modules.system.domain.Menu;
|
||||
import co.yixiang.modules.system.domain.Role;
|
||||
import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||
import co.yixiang.modules.system.service.DeptService;
|
||||
import co.yixiang.modules.system.service.MenuService;
|
||||
import co.yixiang.modules.system.service.dto.RoleSmallDto;
|
||||
import co.yixiang.modules.system.service.dto.UserDto;
|
||||
import co.yixiang.modules.system.service.mapper.DeptMapper;
|
||||
import co.yixiang.modules.system.service.mapper.MenuMapper;
|
||||
import co.yixiang.utils.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.api.R;
|
||||
@ -67,6 +71,8 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
|
||||
|
||||
private final IGenerator generator;
|
||||
private final RoleMapper roleMapper;
|
||||
private final MenuMapper menuMapper;
|
||||
private final DeptMapper deptMapper;
|
||||
|
||||
@Override
|
||||
//@Cacheable
|
||||
@ -111,8 +117,8 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
|
||||
*/
|
||||
@Override
|
||||
public List<RoleSmallDto> findByUsersId(Long id) {
|
||||
|
||||
return null;
|
||||
List<Role> roles = roleMapper.selectListByUserId(id);
|
||||
return generator.convert(roles,RoleSmallDto.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,6 +171,11 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
|
||||
//@Cacheable(key = "'loadPermissionByUser:' + #p0.username")
|
||||
public Collection<GrantedAuthority> mapToGrantedAuthorities(UserDto user) {
|
||||
Set<Role> roles = roleMapper.findByUsers_Id(user.getId());
|
||||
for (Role role : roles) {
|
||||
Set<Menu> menuSet = menuMapper.findMenuByRoleId(role.getId());
|
||||
role.setMenus(menuSet);
|
||||
Set<Dept> deptSet = deptMapper.findDeptByRoleId(role.getId());
|
||||
}
|
||||
Set<String> permissions = roles.stream().filter(role -> StringUtils.isNotBlank(role.getPermission())).map(Role::getPermission).collect(Collectors.toSet());
|
||||
permissions.addAll(
|
||||
roles.stream().flatMap(role -> role.getMenus().stream())
|
||||
|
@ -11,8 +11,13 @@ package co.yixiang.modules.system.service.mapper;
|
||||
import co.yixiang.common.mapper.CoreMapper;
|
||||
import co.yixiang.modules.system.domain.Dept;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-05-14
|
||||
@ -21,4 +26,6 @@ import org.springframework.stereotype.Repository;
|
||||
@Mapper
|
||||
public interface DeptMapper extends CoreMapper<Dept> {
|
||||
|
||||
@Select("select * from dept m LEFT JOIN roles_depts t on m.id= t.dept_id LEFT JOIN role r on r.id = t.role_id where r.id = #{roleId}")
|
||||
Set<Dept> findDeptByRoleId(@Param("roleId") Long roleId);
|
||||
}
|
||||
|
@ -11,9 +11,12 @@ package co.yixiang.modules.system.service.mapper;
|
||||
import co.yixiang.common.mapper.CoreMapper;
|
||||
import co.yixiang.modules.system.domain.Menu;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
@ -29,6 +32,11 @@ public interface MenuMapper extends CoreMapper<Menu> {
|
||||
* @param pid /
|
||||
* @return /
|
||||
*/
|
||||
//todo
|
||||
List<Menu> findByPid(long pid);
|
||||
@Select("SELECT * from menu m where m.pid = #{pid} ")
|
||||
List<Menu> findByPid(@Param("pid") long pid);
|
||||
|
||||
@Select("select m.* from menu m LEFT JOIN roles_menus t on m.id= t.menu_id LEFT JOIN role r on r.id = t.role_id where r.id = #{roleId}")
|
||||
Set<Menu> findMenuByRoleId(@Param("roleId") Long roleId);
|
||||
@Select("<script>select m.* from menu m LEFT JOIN roles_menus t on m.id= t.menu_id LEFT JOIN role r on r.id = t.role_id where r.id in <foreach collection=\"roleIds\" index=\"index\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item}</foreach></script>")
|
||||
List<Menu> selectListByRoles(@Param("roleIds") List<Long> roleIds);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -43,5 +44,6 @@ public interface RoleMapper extends CoreMapper<Role> {
|
||||
*/
|
||||
@Delete("delete from roles_menus where menu_id = #{id}")
|
||||
void untiedMenu(@Param("id") Long id);
|
||||
|
||||
@Select("select m.* from role m LEFT JOIN users_roles t on m.id= t.role_id LEFT JOIN `user` r on r.id = t.user_id where r.id = #{id};")
|
||||
List<Role> selectListByUserId(@Param("id") Long id);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ spring:
|
||||
druid:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||
url: jdbc:log4jdbc:mysql://localhost:3306/yshop?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
url: jdbc:log4jdbc:mysql://localhost:3306/yxshop?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull
|
||||
username: root
|
||||
password: root
|
||||
|
||||
|
Reference in New Issue
Block a user