|
@@ -4,6 +4,7 @@ import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"eta_gn/eta_api/models"
|
|
"eta_gn/eta_api/models"
|
|
"eta_gn/eta_api/models/system"
|
|
"eta_gn/eta_api/models/system"
|
|
|
|
+ "eta_gn/eta_api/services"
|
|
"eta_gn/eta_api/utils"
|
|
"eta_gn/eta_api/utils"
|
|
"fmt"
|
|
"fmt"
|
|
"strings"
|
|
"strings"
|
|
@@ -208,7 +209,7 @@ func (this *SysDepartmentController) ListDepartment() {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
departmentGroup := make(map[int][]*system.SysGroupList)
|
|
departmentGroup := make(map[int][]*system.SysGroupList)
|
|
- groupTeam := make(map[int][]*system.SysTeamList)
|
|
|
|
|
|
+ groupTeam := make(map[int][]*system.SysGroupList)
|
|
for _, v := range groups {
|
|
for _, v := range groups {
|
|
if departmentGroup[v.DepartmentId] == nil {
|
|
if departmentGroup[v.DepartmentId] == nil {
|
|
departmentGroup[v.DepartmentId] = make([]*system.SysGroupList, 0)
|
|
departmentGroup[v.DepartmentId] = make([]*system.SysGroupList, 0)
|
|
@@ -218,28 +219,33 @@ func (this *SysDepartmentController) ListDepartment() {
|
|
}
|
|
}
|
|
if v.ParentId > 0 {
|
|
if v.ParentId > 0 {
|
|
if groupTeam[v.ParentId] == nil {
|
|
if groupTeam[v.ParentId] == nil {
|
|
- groupTeam[v.ParentId] = make([]*system.SysTeamList, 0)
|
|
|
|
|
|
+ groupTeam[v.ParentId] = make([]*system.SysGroupList, 0)
|
|
}
|
|
}
|
|
- groupTeam[v.ParentId] = append(groupTeam[v.ParentId], &system.SysTeamList{
|
|
|
|
- GroupId: v.GroupId,
|
|
|
|
- ParentId: v.ParentId,
|
|
|
|
- GroupName: v.GroupName,
|
|
|
|
- CreateTime: v.CreateTime,
|
|
|
|
|
|
+ groupTeam[v.ParentId] = append(groupTeam[v.ParentId], &system.SysGroupList{
|
|
|
|
+ GroupId: v.GroupId,
|
|
|
|
+ DepartmentId: v.DepartmentId,
|
|
|
|
+ ParentId: v.ParentId,
|
|
|
|
+ GroupName: v.GroupName,
|
|
|
|
+ CreateTime: v.CreateTime,
|
|
|
|
+ IsGroup: true,
|
|
|
|
+ Child: make([]*system.SysGroupList, 0),
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// 数据重组
|
|
// 数据重组
|
|
- for _, groups := range departmentGroup {
|
|
|
|
- for _, g := range groups {
|
|
|
|
- g.IsGroup = true
|
|
|
|
- if groupTeam[g.GroupId] != nil {
|
|
|
|
- g.Child = groupTeam[g.GroupId]
|
|
|
|
- } else {
|
|
|
|
- g.Child = make([]*system.SysTeamList, 0)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ for departmentId, groups := range departmentGroup {
|
|
|
|
+ //for _, g := range groups {
|
|
|
|
+ // g.IsGroup = true
|
|
|
|
+ // if groupTeam[g.GroupId] != nil {
|
|
|
|
+ // g.Child = groupTeam[g.GroupId]
|
|
|
|
+ // } else {
|
|
|
|
+ // g.Child = make([]*system.SysTeamList, 0)
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ departmentGroup[departmentId] = buildTree(groups, groupTeam)
|
|
}
|
|
}
|
|
|
|
+
|
|
for _, v := range departments {
|
|
for _, v := range departments {
|
|
v.IsDepartment = true
|
|
v.IsDepartment = true
|
|
if departmentGroup[v.DepartmentId] != nil {
|
|
if departmentGroup[v.DepartmentId] != nil {
|
|
@@ -280,6 +286,18 @@ func (this *SysDepartmentController) ListDepartment() {
|
|
br.Data = resp
|
|
br.Data = resp
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func buildTree(groups []*system.SysGroupList, groupTeam map[int][]*system.SysGroupList) []*system.SysGroupList {
|
|
|
|
+ for _, g := range groups {
|
|
|
|
+ g.IsGroup = true
|
|
|
|
+ if children, ok := groupTeam[g.GroupId]; ok {
|
|
|
|
+ g.Child = buildTree(children, groupTeam)
|
|
|
|
+ } else {
|
|
|
|
+ g.Child = make([]*system.SysGroupList, 0)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return groups
|
|
|
|
+}
|
|
|
|
+
|
|
// DepartmentUserTree
|
|
// DepartmentUserTree
|
|
// @Title 获取部门及分组用户树
|
|
// @Title 获取部门及分组用户树
|
|
// @Description 获取部门列表接口
|
|
// @Description 获取部门列表接口
|
|
@@ -353,60 +371,14 @@ func (this *SysDepartmentController) DepartmentUserTree() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // 小组
|
|
|
|
- groupTeams := make(map[int][]*system.DepartmentUserTree, 0)
|
|
|
|
- for _, v := range groups {
|
|
|
|
- if v.ParentId == 0 {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- // 关键词查询时不显示空组
|
|
|
|
- if keywords != "" && groupAdmins[v.GroupId] == nil {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- t := new(system.DepartmentUserTree)
|
|
|
|
- t.NodeId = v.GroupId
|
|
|
|
- t.NodeName = v.GroupName
|
|
|
|
- t.NodeType = 2
|
|
|
|
- t.Children = make([]*system.DepartmentUserTree, 0)
|
|
|
|
- t.Children = groupAdmins[v.GroupId]
|
|
|
|
- if groupTeams[v.ParentId] == nil {
|
|
|
|
- groupTeams[v.ParentId] = make([]*system.DepartmentUserTree, 0)
|
|
|
|
- }
|
|
|
|
- groupTeams[v.ParentId] = append(groupTeams[v.ParentId], t)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 大组
|
|
|
|
- departmentGroups := make(map[int][]*system.DepartmentUserTree, 0)
|
|
|
|
- for _, v := range groups {
|
|
|
|
- if v.ParentId > 0 {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- // 关键词查询时不显示空组
|
|
|
|
- if keywords != "" && groupAdmins[v.GroupId] == nil && groupTeams[v.GroupId] == nil {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- t := new(system.DepartmentUserTree)
|
|
|
|
- t.NodeId = v.GroupId
|
|
|
|
- t.NodeName = v.GroupName
|
|
|
|
- t.NodeType = 2
|
|
|
|
- t.Children = make([]*system.DepartmentUserTree, 0)
|
|
|
|
- if groupTeams[v.GroupId] != nil {
|
|
|
|
- t.Children = append(t.Children, groupTeams[v.GroupId]...)
|
|
|
|
- }
|
|
|
|
- if groupAdmins[v.GroupId] != nil {
|
|
|
|
- t.Children = append(t.Children, groupAdmins[v.GroupId]...)
|
|
|
|
- }
|
|
|
|
- if departmentGroups[v.DepartmentId] == nil {
|
|
|
|
- departmentGroups[v.DepartmentId] = make([]*system.DepartmentUserTree, 0)
|
|
|
|
- }
|
|
|
|
- departmentGroups[v.DepartmentId] = append(departmentGroups[v.DepartmentId], t)
|
|
|
|
- }
|
|
|
|
|
|
+ // 构建分组树(以前这里还有个keyword匹配,不知道用作干嘛的,先去掉吧)
|
|
|
|
+ groupTree := services.BuildGroupTreeV2(groups, groupAdmins)
|
|
|
|
|
|
// 部门
|
|
// 部门
|
|
list := make([]*system.DepartmentUserTree, 0)
|
|
list := make([]*system.DepartmentUserTree, 0)
|
|
for _, v := range departments {
|
|
for _, v := range departments {
|
|
// 关键词查询时不显示空部门
|
|
// 关键词查询时不显示空部门
|
|
- if keywords != "" && departmentGroups[v.DepartmentId] == nil && departmentAdmins[v.DepartmentId] == nil {
|
|
|
|
|
|
+ if keywords != "" && groupTree[v.DepartmentId] == nil && departmentAdmins[v.DepartmentId] == nil {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
t := new(system.DepartmentUserTree)
|
|
t := new(system.DepartmentUserTree)
|
|
@@ -414,8 +386,8 @@ func (this *SysDepartmentController) DepartmentUserTree() {
|
|
t.NodeType = 1
|
|
t.NodeType = 1
|
|
t.NodeName = v.DepartmentName
|
|
t.NodeName = v.DepartmentName
|
|
t.Children = make([]*system.DepartmentUserTree, 0)
|
|
t.Children = make([]*system.DepartmentUserTree, 0)
|
|
- if departmentGroups[v.DepartmentId] != nil {
|
|
|
|
- t.Children = append(t.Children, departmentGroups[v.DepartmentId]...)
|
|
|
|
|
|
+ if groupTree[v.DepartmentId] != nil {
|
|
|
|
+ t.Children = append(t.Children, groupTree[v.DepartmentId]...)
|
|
}
|
|
}
|
|
if departmentAdmins[v.DepartmentId] != nil {
|
|
if departmentAdmins[v.DepartmentId] != nil {
|
|
t.Children = append(t.Children, departmentAdmins[v.DepartmentId]...)
|
|
t.Children = append(t.Children, departmentAdmins[v.DepartmentId]...)
|