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