department flat

This commit is contained in:
jiangyong 2026-03-10 16:26:33 +08:00
parent 010cacb4b1
commit b456c3da06
1 changed files with 3 additions and 18 deletions

View File

@ -111,7 +111,6 @@ func (h *AppHr) GetDepartment(id int64) ([]*Department, error) {
departments := cast.ToSlice(resp["department"])
mapDepartment := make(map[int64]*Department)
for _, dd := range departments {
d := cast.ToStringMap(dd)
r := new(Department)
@ -119,24 +118,10 @@ 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
}