优化组织结构树查询
This commit is contained in:
parent
099b308c5e
commit
8434098c39
@ -13,12 +13,15 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -42,18 +45,19 @@ public class AppOrganizationController {
|
||||
@Operation(summary = "查询公司结构树")
|
||||
@GetMapping("/getCompanyTree")
|
||||
@OperationLog(type = "06", module = "组织管理", description = "查询公司结构树")
|
||||
public Result<List<AppOrganization>> getCompanyTree() {
|
||||
public Result<List<OrganizationTreeNode>> getCompanyTree(@RequestParam String appId) {
|
||||
QueryWrapper<AppOrganization> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("orgtype", "01");
|
||||
queryWrapper.eq(StrUtil.isNotBlank(appId),"app_id", appId);
|
||||
queryWrapper.eq("isvaild", "1");
|
||||
queryWrapper.orderByAsc("orgcode");
|
||||
List<AppOrganization> children = appOrganizationService.list(queryWrapper);
|
||||
return Result.success(children);
|
||||
List<OrganizationTreeNode> organizationTreeNodes = buildOrganizationTree(children, "0");
|
||||
return Result.success(organizationTreeNodes);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询部门列表")
|
||||
@Operation(summary = "查询公司/部门列表")
|
||||
@GetMapping("/getDepartmentList")
|
||||
@OperationLog(type = "06", module = "组织管理", description = "查询部门列表")
|
||||
@OperationLog(type = "06", module = "组织管理", description = "查询公司/部门列表")
|
||||
public Result<List<AppOrganization>> getDepartmentList(@RequestParam String appId, @RequestParam String orgtype,
|
||||
@RequestParam String parentid, @RequestParam String keystr) {
|
||||
QueryWrapper<AppOrganization> queryWrapper = new QueryWrapper<>();
|
||||
@ -231,5 +235,99 @@ public class AppOrganizationController {
|
||||
// 如果列表不为空,返回第一个记录的orgcode
|
||||
return list.isEmpty() ? null : list.get(0).getOrgcode();
|
||||
}
|
||||
/**
|
||||
* 构建菜单树
|
||||
*/
|
||||
private List<OrganizationTreeNode> buildOrganizationTree(List<AppOrganization> allOrganizations, String parentId) {
|
||||
return allOrganizations.stream()
|
||||
.filter(organization -> parentId.equals(organization.getParentid()))
|
||||
.map(organization -> {
|
||||
OrganizationTreeNode node = new OrganizationTreeNode();
|
||||
node.setId(organization.getId());
|
||||
node.setAppId(organization.getAppId());
|
||||
node.setOrgtype(organization.getOrgtype());
|
||||
node.setOrgcode(organization.getOrgcode());
|
||||
node.setOrgname(organization.getOrgname());
|
||||
node.setParentid(organization.getParentid());
|
||||
node.setManager(organization.getManager());
|
||||
node.setDescription(organization.getDescription());
|
||||
node.setAddress(organization.getAddress());
|
||||
node.setContactPhone(organization.getContactPhone());
|
||||
node.setContactPerson(organization.getContactPerson());
|
||||
node.setIsvaild(organization.getIsvaild());
|
||||
node.setChildren(buildOrganizationTree(allOrganizations, organization.getId()));
|
||||
return node;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 组织树节点
|
||||
*/
|
||||
@Data
|
||||
public static class OrganizationTreeNode {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 应用ID 关联应用系统
|
||||
*/
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 组织类型:01-公司 02-部门
|
||||
*/
|
||||
private String orgtype;
|
||||
|
||||
/**
|
||||
* 组织编号
|
||||
*/
|
||||
private String orgcode;
|
||||
|
||||
/**
|
||||
* 组织名称
|
||||
*/
|
||||
private String orgname;
|
||||
|
||||
/**
|
||||
* 上级ID
|
||||
*/
|
||||
private String parentid;
|
||||
|
||||
/**
|
||||
* 组织负责人
|
||||
*/
|
||||
private String manager;
|
||||
|
||||
/**
|
||||
* 组织详情
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 联系地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
private String contactPhone;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
private String contactPerson;
|
||||
|
||||
/**
|
||||
* 是否有效 1-是 0-否
|
||||
*/
|
||||
private String isvaild;
|
||||
|
||||
private List<OrganizationTreeNode> children = new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user