mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
添加获取当前用户资源接口
This commit is contained in:
@@ -5,6 +5,8 @@ import cn.lihongjie.coal.annotation.SysLog;
|
|||||||
import cn.lihongjie.coal.base.controller.BaseController;
|
import cn.lihongjie.coal.base.controller.BaseController;
|
||||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||||
|
import cn.lihongjie.coal.common.Ctx;
|
||||||
|
import cn.lihongjie.coal.resource.dto.ResourceDto;
|
||||||
import cn.lihongjie.coal.user.dto.ChangeUserPwdDto;
|
import cn.lihongjie.coal.user.dto.ChangeUserPwdDto;
|
||||||
import cn.lihongjie.coal.user.dto.CreateUserDto;
|
import cn.lihongjie.coal.user.dto.CreateUserDto;
|
||||||
import cn.lihongjie.coal.user.dto.UpdateUserDto;
|
import cn.lihongjie.coal.user.dto.UpdateUserDto;
|
||||||
@@ -18,6 +20,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RequestMapping("/user")
|
@RequestMapping("/user")
|
||||||
@RestController
|
@RestController
|
||||||
@SysLog(module = "用户管理")
|
@SysLog(module = "用户管理")
|
||||||
@@ -59,4 +63,9 @@ public class UserController extends BaseController {
|
|||||||
public UserDto getById(@RequestBody IdRequest dto) {
|
public UserDto getById(@RequestBody IdRequest dto) {
|
||||||
return this.service.getById(dto.getId());
|
return this.service.getById(dto.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/resources")
|
||||||
|
public List<ResourceDto> resources() {
|
||||||
|
return this.service.resources(Ctx.currentUser().getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import cn.lihongjie.coal.base.service.BaseService;
|
|||||||
import cn.lihongjie.coal.common.Ctx;
|
import cn.lihongjie.coal.common.Ctx;
|
||||||
import cn.lihongjie.coal.exception.BizException;
|
import cn.lihongjie.coal.exception.BizException;
|
||||||
import cn.lihongjie.coal.organization.entity.OrganizationEntity;
|
import cn.lihongjie.coal.organization.entity.OrganizationEntity;
|
||||||
|
import cn.lihongjie.coal.resource.dto.ResourceDto;
|
||||||
|
import cn.lihongjie.coal.resource.mapper.ResourceMapper;
|
||||||
import cn.lihongjie.coal.user.dto.ChangeUserPwdDto;
|
import cn.lihongjie.coal.user.dto.ChangeUserPwdDto;
|
||||||
import cn.lihongjie.coal.user.dto.CreateUserDto;
|
import cn.lihongjie.coal.user.dto.CreateUserDto;
|
||||||
import cn.lihongjie.coal.user.dto.UpdateUserDto;
|
import cn.lihongjie.coal.user.dto.UpdateUserDto;
|
||||||
@@ -22,6 +24,7 @@ import jakarta.persistence.criteria.Root;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
@@ -33,7 +36,10 @@ import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StopWatch;
|
import org.springframework.util.StopWatch;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -172,4 +178,29 @@ public class UserService extends BaseService<UserEntity, UserRepository> {
|
|||||||
|
|
||||||
return adminuser;
|
return adminuser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired ResourceMapper resourceMapper;
|
||||||
|
|
||||||
|
public List<ResourceDto> resources(String id) {
|
||||||
|
|
||||||
|
UserEntity user = get(id);
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(user.getRoles())) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
return io.vavr.collection.Stream.ofAll(user.getRoles())
|
||||||
|
.flatMap(
|
||||||
|
x ->
|
||||||
|
x.getPermissions() == null
|
||||||
|
? io.vavr.collection.Stream.empty()
|
||||||
|
: x.getPermissions())
|
||||||
|
.flatMap(
|
||||||
|
x ->
|
||||||
|
x.getResources() == null
|
||||||
|
? io.vavr.collection.Stream.empty()
|
||||||
|
: x.getResources())
|
||||||
|
.distinctBy(x -> x.getId())
|
||||||
|
.map(x -> resourceMapper.toDto(x))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user