This commit is contained in:
parent
79dd16de58
commit
0d82e7521f
|
|
@ -2,11 +2,12 @@ package qyweixin
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"git.u8t.cn/open/gosdk/util"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"git.u8t.cn/open/goutil"
|
||||
"github.com/spf13/cast"
|
||||
"time"
|
||||
|
||||
"git.u8t.cn/open/gosdk/util"
|
||||
"git.u8t.cn/open/goutil"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -26,6 +27,7 @@ type Department struct {
|
|||
Pid int64 `json:"pid"`
|
||||
Name string `json:"name"`
|
||||
Leader []string `json:"leader"`
|
||||
Childchren []*Department `json:"childchren"`
|
||||
}
|
||||
|
||||
type StaffInfo struct {
|
||||
|
|
@ -108,6 +110,8 @@ func (h *AppHr) GetDepartment(id int64) ([]*Department, error) {
|
|||
result := make([]*Department, 0)
|
||||
|
||||
departments := cast.ToSlice(resp["department"])
|
||||
|
||||
mapDepartment := make(map[int64]*Department)
|
||||
for _, dd := range departments {
|
||||
d := cast.ToStringMap(dd)
|
||||
r := new(Department)
|
||||
|
|
@ -115,7 +119,23 @@ func (h *AppHr) GetDepartment(id int64) ([]*Department, error) {
|
|||
r.Leader = cast.ToStringSlice(d["department_leader"])
|
||||
r.Id = cast.ToInt64(d["id"])
|
||||
r.Pid = cast.ToInt64(d["parentid"])
|
||||
result = append(result, r)
|
||||
mapDepartment[r.Id] = r
|
||||
}
|
||||
for _, v := range mapDepartment {
|
||||
parent := mapDepartment[v.Pid]
|
||||
if parent == nil {
|
||||
continue
|
||||
}
|
||||
if parent.Childchren == nil {
|
||||
parent.Childchren = make([]*Department, 0)
|
||||
}
|
||||
parent.Childchren = append(parent.Childchren, v)
|
||||
}
|
||||
for _, v := range mapDepartment {
|
||||
if v.Pid != id {
|
||||
continue
|
||||
}
|
||||
result = append(result, v)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue