Search in sources :

Example 1 with RoleEntity

use of com.hb0730.boot.admin.project.system.role.model.entity.RoleEntity in project boot-admin by hb0730.

the class RoleServiceImpl method save.

@Override
@Transactional(rollbackFor = Exception.class)
public boolean save(@Nonnull RoleExtDTO dto) {
    RoleEntity entity = dto.convertTo();
    boolean result = super.save(entity);
    Long id = entity.getId();
    List<Long> deptIds = dto.getDeptIds();
    if (!CollectionUtils.isEmpty(deptIds) && Objects.nonNull(id)) {
        roleDeptService.saveRoleDepts(id, deptIds);
    }
    return result;
}
Also used : RoleEntity(com.hb0730.boot.admin.project.system.role.model.entity.RoleEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RoleEntity

use of com.hb0730.boot.admin.project.system.role.model.entity.RoleEntity in project boot-admin by hb0730.

the class RoleServiceImpl method updateById.

@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateById(@Nonnull Long id, @Nonnull RoleExtDTO dto) {
    RoleEntity entity = dto.convertTo();
    entity.setId(id);
    boolean result = this.updateById(entity);
    updateRoleDepts(id, dto.getDeptIds());
    return result;
}
Also used : RoleEntity(com.hb0730.boot.admin.project.system.role.model.entity.RoleEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with RoleEntity

use of com.hb0730.boot.admin.project.system.role.model.entity.RoleEntity in project boot-admin by hb0730.

the class UserInfoServiceImpl method loadUserByUsername.

@Override
public UserDTO loadUserByUsername(String username) {
    UserAccountEntity accountEntity = accountService.findUserAccountByUsername(username);
    if (null == accountEntity) {
        return null;
    }
    Long userId = accountEntity.getUserId();
    UserInfoEntity entity = super.getById(userId);
    UserDTO user = BeanUtil.toBean(entity, UserDTO.class);
    assert user != null;
    user.setUsername(accountEntity.getUsername());
    user.setPassword(accountEntity.getPassword());
    // 用户角色
    Collection<Long> roleIds = userRoleService.findRoleByUserId(userId);
    if (CollectionUtils.isEmpty(roleIds)) {
        return user;
    }
    List<RoleEntity> roles = roleService.findEnabledRoleByIds(roleIds);
    if (CollectionUtils.isEmpty(roles)) {
        return user;
    }
    Map<Long, String> roleMap = roles.parallelStream().collect(Collectors.toMap(RoleEntity::getId, RoleEntity::getCode));
    user.setRoleIds(roleMap.keySet());
    user.setRole(roleMap.values());
    // 权限
    Map<Long, List<Long>> permission = rolePermissionService.findPermissionIdByRoleId(roleIds);
    if (CollectionUtils.isEmpty(permission)) {
        return user;
    }
    Set<Long> permissionIds = permission.values().stream().flatMap(List::stream).collect(Collectors.toSet());
    List<PermissionEntity> permissionEntities = permissionService.findEnabledPermissionByIds(permissionIds);
    if (CollectionUtils.isEmpty(permissionEntities)) {
        return user;
    }
    Map<Long, String> permissionMap = permissionEntities.parallelStream().collect(Collectors.toMap(PermissionEntity::getId, PermissionEntity::getPermission));
    user.setPermission(permissionMap.values());
    user.setPermissionIds(permissionMap.keySet());
    // 岗位
    List<Long> postIds = userPostService.findPostIdByUserIds(Collections.singletonList(userId));
    user.setPostIds(postIds);
    return user;
}
Also used : UserAccountEntity(com.hb0730.boot.admin.project.system.user.model.entity.UserAccountEntity) UserDTO(com.hb0730.boot.admin.project.system.user.model.dto.UserDTO) UserInfoEntity(com.hb0730.boot.admin.project.system.user.model.entity.UserInfoEntity) UserRoleEntity(com.hb0730.boot.admin.project.system.user.model.entity.UserRoleEntity) RoleEntity(com.hb0730.boot.admin.project.system.role.model.entity.RoleEntity) List(java.util.List) PermissionEntity(com.hb0730.boot.admin.project.system.permission.model.entity.PermissionEntity)

Example 4 with RoleEntity

use of com.hb0730.boot.admin.project.system.role.model.entity.RoleEntity in project boot-admin by hb0730.

the class RoleServiceImpl method updateById.

@Override
public boolean updateById(RoleEntity entity) {
    RoleEntity e1 = super.getById(entity);
    BeanUtil.copyProperties(entity, e1);
    return super.updateById(e1);
}
Also used : RoleEntity(com.hb0730.boot.admin.project.system.role.model.entity.RoleEntity)

Aggregations

RoleEntity (com.hb0730.boot.admin.project.system.role.model.entity.RoleEntity)4 Transactional (org.springframework.transaction.annotation.Transactional)2 PermissionEntity (com.hb0730.boot.admin.project.system.permission.model.entity.PermissionEntity)1 UserDTO (com.hb0730.boot.admin.project.system.user.model.dto.UserDTO)1 UserAccountEntity (com.hb0730.boot.admin.project.system.user.model.entity.UserAccountEntity)1 UserInfoEntity (com.hb0730.boot.admin.project.system.user.model.entity.UserInfoEntity)1 UserRoleEntity (com.hb0730.boot.admin.project.system.user.model.entity.UserRoleEntity)1 List (java.util.List)1