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 ( 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 (
@ -27,7 +26,6 @@ type Department struct {
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
} }