getdepartment
This commit is contained in:
parent
54821df68a
commit
edc2466eee
|
@ -10,8 +10,10 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
urlQyWeixinHrGetAllField = "https://qyapi.weixin.qq.com/cgi-bin/hr/get_fields"
|
||||
urlQyWeixinHrGetStaffInfo = "https://qyapi.weixin.qq.com/cgi-bin/hr/get_staff_info"
|
||||
urlQyWeixinHrGetAllField = "https://qyapi.weixin.qq.com/cgi-bin/hr/get_fields"
|
||||
urlQyWeixinHrGetStaffInfo = "https://qyapi.weixin.qq.com/cgi-bin/hr/get_staff_info"
|
||||
urlQyWeixinHrGetDepartment = "https://qyapi.weixin.qq.com/cgi-bin/department/list"
|
||||
urlQyWeixinHrGetDepartmentUser = "https://qyapi.weixin.qq.com/cgi-bin/user/list"
|
||||
)
|
||||
|
||||
type AppHr struct {
|
||||
|
@ -19,6 +21,13 @@ type AppHr struct {
|
|||
config *AppConfig
|
||||
}
|
||||
|
||||
type Department struct {
|
||||
Id int64 `json:"id"`
|
||||
Pid int64 `json:"pid"`
|
||||
Name string `json:"name"`
|
||||
Leader []string `json:"leader"`
|
||||
}
|
||||
|
||||
type StaffInfo struct {
|
||||
UserName string
|
||||
RealName string
|
||||
|
@ -85,6 +94,53 @@ func (h *AppHr) GetStaffInfo(userId string) (*StaffInfo, error) {
|
|||
return staff, nil
|
||||
}
|
||||
|
||||
func (h *AppHr) GetDepartment(id int64) ([]*Department, error) {
|
||||
reqUrl := fmt.Sprintf("%s?access_token=%s&id=%d", urlQyWeixinHrGetDepartment, h.GetToken(), id)
|
||||
rspBody, err := util.HttpGet(reqUrl, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := h.GetResult(rspBody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]*Department, 0)
|
||||
|
||||
departments := cast.ToSlice(resp["department"])
|
||||
for _, dd := range departments {
|
||||
d := cast.ToStringMap(dd)
|
||||
r := new(Department)
|
||||
r.Name = cast.ToString(d["name"])
|
||||
r.Leader = cast.ToStringSlice(d["department_leader"])
|
||||
r.Id = cast.ToInt64(d["id"])
|
||||
r.Pid = cast.ToInt64(d["parentid"])
|
||||
result = append(result, r)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (h *AppHr) GetDepartmentUserId(id int64) ([]string, error) {
|
||||
reqUrl := fmt.Sprintf("%s?access_token=%s&department_id=%d", urlQyWeixinHrGetDepartmentUser, h.GetToken(), id)
|
||||
rspBody, err := util.HttpGet(reqUrl, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := h.GetResult(rspBody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]string, 0)
|
||||
|
||||
userlist := cast.ToSlice(resp["userlist"])
|
||||
for _, dd := range userlist {
|
||||
d := cast.ToStringMap(dd)
|
||||
result = append(result, cast.ToString(d["userid"]))
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (h *AppHr) getFieldValue(fieldInfo map[string]interface{}) string {
|
||||
valueType := cast.ToInt(fieldInfo["value_type"])
|
||||
if valueType == 1 {
|
||||
|
|
Loading…
Reference in New Issue