增加查询子结构API
This commit is contained in:
parent
02a0a72080
commit
4c51ca55e5
|
|
@ -3,10 +3,13 @@ package org.jetlinks.community.auth.web;
|
|||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.hswebframework.web.api.crud.entity.QueryOperation;
|
||||
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
|
||||
import org.hswebframework.web.api.crud.entity.TreeSupportEntity;
|
||||
import org.hswebframework.web.authorization.Authentication;
|
||||
import org.hswebframework.web.authorization.Dimension;
|
||||
import org.hswebframework.web.authorization.annotation.*;
|
||||
import org.hswebframework.web.system.authorization.api.entity.DimensionEntity;
|
||||
import org.hswebframework.web.system.authorization.defaults.service.DefaultDimensionService;
|
||||
|
|
@ -15,6 +18,9 @@ import org.springframework.web.bind.annotation.*;
|
|||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequestMapping("/organization")
|
||||
@RestController
|
||||
@Resource(id = "organization", name = "机构管理")
|
||||
|
|
@ -37,15 +43,26 @@ public class OrganizationController {
|
|||
@Authorize(merge = false)
|
||||
@Operation(summary = "获取全部机构信息")
|
||||
public Flux<DimensionEntity> getAllOrg() {
|
||||
return dimensionService
|
||||
.createQuery()
|
||||
.where(DimensionEntity::getTypeId, orgDimensionTypeId)
|
||||
.fetch();
|
||||
return Authentication
|
||||
.currentReactive()
|
||||
.flatMapMany(auth -> {
|
||||
List<String> list = auth.getDimensions(orgDimensionTypeId)
|
||||
.stream()
|
||||
.map(Dimension::getId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
return dimensionService.findById(list);
|
||||
}
|
||||
return dimensionService
|
||||
.createQuery()
|
||||
.where(DimensionEntity::getTypeId, orgDimensionTypeId)
|
||||
.fetch();
|
||||
});
|
||||
}
|
||||
|
||||
@GetMapping("/_query")
|
||||
@QueryAction
|
||||
@QueryOperation(summary = "查询结构列表")
|
||||
@QueryOperation(summary = "查询机构列表")
|
||||
public Mono<PagerResult<DimensionEntity>> queryDimension(@Parameter(hidden = true) QueryParamEntity entity) {
|
||||
return entity
|
||||
.toNestQuery(q -> q.where(DimensionEntity::getTypeId, orgDimensionTypeId))
|
||||
|
|
@ -53,6 +70,24 @@ public class OrganizationController {
|
|||
.as(dimensionService::queryPager);
|
||||
}
|
||||
|
||||
@GetMapping("/_query/_children/tree")
|
||||
@QueryAction
|
||||
@QueryOperation(summary = "查询机构列表(包含子机构)树结构")
|
||||
public Mono<List<DimensionEntity>> queryChildrenTree(@Parameter(hidden = true) QueryParamEntity entity) {
|
||||
return entity
|
||||
.toNestQuery(q -> q.where(DimensionEntity::getTypeId, orgDimensionTypeId))
|
||||
.execute(dimensionService::queryIncludeChildrenTree);
|
||||
}
|
||||
|
||||
@GetMapping("/_query/_children")
|
||||
@QueryAction
|
||||
@QueryOperation(summary = "查询机构列表(包含子机构)")
|
||||
public Flux<DimensionEntity> queryChildren(@Parameter(hidden = true) QueryParamEntity entity) {
|
||||
return entity
|
||||
.toNestQuery(q -> q.where(DimensionEntity::getTypeId, orgDimensionTypeId))
|
||||
.execute(dimensionService::queryIncludeChildren);
|
||||
}
|
||||
|
||||
@PatchMapping
|
||||
@SaveAction
|
||||
@Operation(summary = "保存机构信息")
|
||||
|
|
|
|||
Loading…
Reference in New Issue