作者 tangxuhui
... ... @@ -185,7 +185,7 @@ func (orgService *OrgService) GetOrgSubDepartment(getOrgSubDepartmentQuery *quer
treeNodes[i] = orgs[i]
}
tree := domain.NewTrees(treeNodes)
nodes := tree.AllChildNodes(org)
nodes := tree.AllSubDepartment(org)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -111,6 +111,35 @@ func traverse(tree *Tree, node TreeNode) bool {
return match
}
// 返回tree下的所有子部门 (如果节点是组织,跳过)
func (tree *Tree) AllSubDepartment(node TreeNode) []TreeNode {
treeNode := tree.find(node)
if treeNode == nil {
return []TreeNode{}
}
var stack []*Tree
stack = append(stack, treeNode)
var res []TreeNode
rootId := treeNode.Node.(*Org).OrgId
for {
if len(stack) == 0 {
break
}
pop := stack[0]
stack = stack[1:]
/***特殊处理***/
if org, ok := pop.Node.(*Org); ok && org.OrgId != int64(rootId) {
if org.IsOrg == IsOrgFlag {
continue
}
}
/***特殊处理***/
stack = append(stack, pop.Nodes...)
res = append(res, pop.Node)
}
return res
}
// Int64String 1 -> "1" 1->1
type Int64String int64
... ...