|
|
@@ -4,16 +4,16 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"gcore/core"
|
|
|
- "gcore/xnet"
|
|
|
"log"
|
|
|
"net/http"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
-type DevConf struct {
|
|
|
+type DingTalkConf struct {
|
|
|
AppKey string
|
|
|
AppSecret string
|
|
|
GetTokenUrl string
|
|
|
+ GetHolidayTypeURL string
|
|
|
GetDeptListUrl string
|
|
|
GetDeptUserListUrl string
|
|
|
GetAttendanceGroupUrl string
|
|
|
@@ -21,27 +21,28 @@ type DevConf struct {
|
|
|
GetAttendanceClockDataUrl string
|
|
|
GetAttendanceGroupDetailsUrl string
|
|
|
ListAttendanceGroupMenberListByIdsUrl string
|
|
|
- Token string
|
|
|
- Params map[string]string
|
|
|
- Headers map[string]string
|
|
|
- Cookie []*http.Cookie
|
|
|
- DeptId int64
|
|
|
- OpUserId int64
|
|
|
- ManageGroupId int64
|
|
|
- EmployeeGroupId int64
|
|
|
+
|
|
|
+ Token string
|
|
|
+ Params map[string]string
|
|
|
+ Headers map[string]string
|
|
|
+ Cookie []*http.Cookie
|
|
|
+ DeptId int64
|
|
|
+ OpUserId string
|
|
|
+ ManageGroupId int64
|
|
|
+ EmployeeGroupId int64
|
|
|
}
|
|
|
|
|
|
// @title GetToken
|
|
|
// @description 获取access token
|
|
|
// @param
|
|
|
// @return
|
|
|
-func (m *DevConf) GetToken() error {
|
|
|
+func (m *DingTalkConf) GetToken() error {
|
|
|
params := map[string]string{"appkey": m.AppKey, "appsecret": m.AppSecret}
|
|
|
- content, err := xnet.GetX(m.GetTokenUrl, params, m.Headers, m.Cookie)
|
|
|
+ content, err := GetX(m.GetTokenUrl, params, m.Headers, m.Cookie)
|
|
|
if err != nil {
|
|
|
log.Printf("GetToken error : %v", err)
|
|
|
}
|
|
|
- //fmt.Printf("%v\n", content)
|
|
|
+ fmt.Printf("%v\n", content)
|
|
|
ret := map[string]interface{}{}
|
|
|
err = json.Unmarshal([]byte(content), &ret)
|
|
|
if err != nil {
|
|
|
@@ -56,15 +57,41 @@ func (m *DevConf) GetToken() error {
|
|
|
|
|
|
}
|
|
|
|
|
|
+func (m *DingTalkConf) GetHolidayType() (err error) {
|
|
|
+ result := map[string]string{}
|
|
|
+ PostData := make(map[string]interface{})
|
|
|
+ PostData["op_userid"] = m.OpUserId
|
|
|
+ PostData["vacation_source"] = "all"
|
|
|
+ fmt.Printf("postdata=======>%v\n", PostData)
|
|
|
+ content, err := PostJson(m.GetHolidayTypeURL, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("GetDeptUserList PostJson error : %v", err)
|
|
|
+ return err
|
|
|
+
|
|
|
+ }
|
|
|
+ ret := map[string]interface{}{}
|
|
|
+ err = json.Unmarshal([]byte(content), &ret)
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("Unmarshal error : %v", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ holidatTypes := ret["result"].([]interface{})
|
|
|
+ for _, holidatType := range holidatTypes {
|
|
|
+ result[holidatType.(map[string]interface{})["leave_name"].(string)] = holidatType.(map[string]interface{})["leave_code"].(string)
|
|
|
+ }
|
|
|
+ fmt.Printf("ret===>%v\n", ret)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// @title GetDeptList
|
|
|
// @description 获取部门列表,只支持查询下一级子部门 https://developers.dingtalk.com/document/app/obtain-the-department-list-v2
|
|
|
// @param
|
|
|
// @return
|
|
|
-func (m *DevConf) GetDeptList(deptId int64) ([]interface{}, error) {
|
|
|
+func (m *DingTalkConf) GetDeptList(deptId int64) ([]interface{}, error) {
|
|
|
result := []interface{}{}
|
|
|
PostData := make(map[string]interface{})
|
|
|
PostData["dept_id"] = deptId
|
|
|
- content, err := xnet.PostJson(m.GetDeptListUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
+ content, err := PostJson(m.GetDeptListUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
if err != nil {
|
|
|
log.Printf("GetDeptUserList PostJson error : %v", err)
|
|
|
return result, err
|
|
|
@@ -109,7 +136,7 @@ func (m *DevConf) GetDeptList(deptId int64) ([]interface{}, error) {
|
|
|
// @description 获取部门成员的姓名和userid https://developers.dingtalk.com/document/app/queries-the-simple-information-of-a-department-user
|
|
|
// @param
|
|
|
// @return
|
|
|
-func (m *DevConf) GetDeptUserList(deptId int64) (map[string]string, error) {
|
|
|
+func (m *DingTalkConf) GetDeptUserList(deptId int64) (map[string]string, error) {
|
|
|
cursor := 0.0
|
|
|
size := 100
|
|
|
PostData := make(map[string]interface{})
|
|
|
@@ -122,7 +149,7 @@ func (m *DevConf) GetDeptUserList(deptId int64) (map[string]string, error) {
|
|
|
|
|
|
//fmt.Printf("%v\n", cursor)
|
|
|
//请求APi
|
|
|
- content, err := xnet.PostJson(m.GetDeptUserListUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
+ content, err := PostJson(m.GetDeptUserListUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
if err != nil {
|
|
|
log.Printf("GetDeptUserList PostJson error : %v", err)
|
|
|
|
|
|
@@ -177,7 +204,7 @@ func (m *DevConf) GetDeptUserList(deptId int64) (map[string]string, error) {
|
|
|
// @description 批量获取考勤组摘要 https://developers.dingtalk.com/document/app/batch-query-of-simple-information-of-the-attendance-group
|
|
|
// @param
|
|
|
// @return
|
|
|
-func (m *DevConf) GetAttendanceGroup() ([]map[string]interface{}, error) {
|
|
|
+func (m *DingTalkConf) GetAttendanceGroup() ([]map[string]interface{}, error) {
|
|
|
groupData := []map[string]interface{}{}
|
|
|
|
|
|
PostData := make(map[string]interface{})
|
|
|
@@ -185,7 +212,7 @@ func (m *DevConf) GetAttendanceGroup() ([]map[string]interface{}, error) {
|
|
|
PostData["op_user_id"] = m.OpUserId
|
|
|
PostData["cursor"] = cursor
|
|
|
|
|
|
- content, err := xnet.PostJson(m.GetAttendanceGroupUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
+ content, err := PostJson(m.GetAttendanceGroupUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
if err != nil {
|
|
|
log.Printf("GetAttendanceClockData PostJson error : %v", err)
|
|
|
return groupData, err
|
|
|
@@ -234,7 +261,7 @@ func (m *DevConf) GetAttendanceGroup() ([]map[string]interface{}, error) {
|
|
|
// @description 获取7天内的指定时间段成员的打卡记录, https://developers.dingtalk.com/document/app/open-attendance-clock-in-data
|
|
|
// @param days获取多少天内的考勤数据
|
|
|
// @return
|
|
|
-func (m *DevConf) GetAttendanceClockData(days int, userIdList []string) (map[string][]int, error) {
|
|
|
+func (m *DingTalkConf) GetAttendanceClockData(days int, userIdList []string) (map[string][]int, error) {
|
|
|
|
|
|
limit := 50 //表示获取考勤数据的条数,最大不能超过50条。
|
|
|
userIdStep := 50 //单次请求传入的userId数量
|
|
|
@@ -292,7 +319,7 @@ func (m *DevConf) GetAttendanceClockData(days int, userIdList []string) (map[str
|
|
|
|
|
|
//fmt.Printf("offset %v\n", offset)
|
|
|
//fmt.Printf("data %v\n", data)
|
|
|
- content, err := xnet.PostJson(m.GetAttendanceClockDataUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
+ content, err := PostJson(m.GetAttendanceClockDataUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
if err != nil {
|
|
|
log.Printf("GetAttendanceClockData PostJson error : %v", err)
|
|
|
|
|
|
@@ -334,12 +361,12 @@ func (m *DevConf) GetAttendanceClockData(days int, userIdList []string) (map[str
|
|
|
// @description 获取考勤组列表, https://developers.dingtalk.com/document/app/queries-attendance-group-list-details
|
|
|
// @param
|
|
|
// @return map[5.5天制管理人员:753150009 5天制:761355305 6天制员工:667040040 合肥1:721640063 合肥6天制:795345194 清洁:854690013 音乐:761855162]
|
|
|
-func (m *DevConf) GetAttendanceGroupDetails() (map[int64]string, error) {
|
|
|
+func (m *DingTalkConf) GetAttendanceGroupDetails() (map[int64]string, error) {
|
|
|
PostData := make(map[string]interface{})
|
|
|
PostData["offset"] = 0
|
|
|
PostData["size"] = 10
|
|
|
|
|
|
- content, err := xnet.PostJson(m.GetAttendanceGroupDetailsUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
+ content, err := PostJson(m.GetAttendanceGroupDetailsUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
if err != nil {
|
|
|
log.Printf("GetAttendanceClockData PostJson error : %v", err)
|
|
|
|
|
|
@@ -364,7 +391,7 @@ func (m *DevConf) GetAttendanceGroupDetails() (map[int64]string, error) {
|
|
|
// @description 考勤组成员校验 , https://developers.dingtalk.com/document/app/query-members-by-id
|
|
|
// @param
|
|
|
// @return
|
|
|
-func (m *DevConf) ListAttendanceGroupMenberListByIds(groupId int64, userIdList []string) ([]string, error) {
|
|
|
+func (m *DingTalkConf) ListAttendanceGroupMenberListByIds(groupId int64, userIdList []string) ([]string, error) {
|
|
|
PostData := make(map[string]interface{})
|
|
|
PostData["op_user_id"] = m.OpUserId
|
|
|
PostData["group_id"] = groupId
|
|
|
@@ -373,7 +400,7 @@ func (m *DevConf) ListAttendanceGroupMenberListByIds(groupId int64, userIdList [
|
|
|
PostData["member_ids"] = userids
|
|
|
PostData["member_type"] = 0
|
|
|
|
|
|
- content, err := xnet.PostJson(m.ListAttendanceGroupMenberListByIdsUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
+ content, err := PostJson(m.ListAttendanceGroupMenberListByIdsUrl, m.Params, m.Headers, PostData, m.Cookie)
|
|
|
if err != nil {
|
|
|
log.Printf("GetAttendanceClockData PostJson error : %v", err)
|
|
|
|