Compare commits

..

No commits in common. "010cacb4b1e75611ae91f47916fe8b56d6ebb589" and "9c46469b6794367612fdfeef56ab754e597ba263" have entirely different histories.

1 changed files with 7 additions and 27 deletions

View File

@ -2,12 +2,11 @@ package qyweixin
import (
"fmt"
"time"
"git.u8t.cn/open/gosdk/util"
"git.u8t.cn/open/goutil"
log "github.com/sirupsen/logrus"
"git.u8t.cn/open/goutil"
"github.com/spf13/cast"
"time"
)
var (
@ -23,11 +22,10 @@ type AppHr struct {
}
type Department struct {
Id int64 `json:"id"`
Pid int64 `json:"pid"`
Name string `json:"name"`
Leader []string `json:"leader"`
Childchren []*Department `json:"childchren"`
Id int64 `json:"id"`
Pid int64 `json:"pid"`
Name string `json:"name"`
Leader []string `json:"leader"`
}
type StaffInfo struct {
@ -110,8 +108,6 @@ 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)
@ -119,23 +115,7 @@ 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"])
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)
result = append(result, r)
}
return result, nil
}