Compare commits
No commits in common. "010cacb4b1e75611ae91f47916fe8b56d6ebb589" and "9c46469b6794367612fdfeef56ab754e597ba263" have entirely different histories.
010cacb4b1
...
9c46469b67
|
|
@ -2,12 +2,11 @@ package qyweixin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.u8t.cn/open/gosdk/util"
|
"git.u8t.cn/open/gosdk/util"
|
||||||
"git.u8t.cn/open/goutil"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"git.u8t.cn/open/goutil"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -23,11 +22,10 @@ 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 {
|
||||||
|
|
@ -110,8 +108,6 @@ 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)
|
||||||
|
|
@ -119,23 +115,7 @@ 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"])
|
||||||
mapDepartment[r.Id] = r
|
result = append(result, 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