package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"math"
	"net/http"
	"strconv"
	"strings"
	"time"
)

const (
	OnDutyCheckTime    = 120048879
	OnDutyCheckResult  = 120048880
	OffDutyCheckTime   = 120048881
	OffDutyCheckResult = 120048882
	AttendanceApprove  = 120048891
)

type DingTalk struct {
	token   string
	agentId string
}

func (dt *DingTalk) refreshToken() {
	resp, err := http.Get("https://oapi.dingtalk.com/gettoken?appkey=dinglvrfy5p9zq79ojaj&appsecret=7Tcy-xRj8m3jVM9cNZo62XlbFaxfONgRE0LKImUrka4DgEOt16RN9TJh9cZR63Vl")
	if err == nil {
		result := make(map[string]any)
		err := json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) == 0 {
				dt.token = result["access_token"].(string)
				dt.agentId = "1485668405"
			}
		} else {
			panic(any(err))
		}
	}
}

func (dt *DingTalk) getEmployeeIdByUnionId(unionId string) string {
	var param io.Reader = nil
	args := make(map[string]any)
	args["unionid"] = unionId
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/user/getbyunionid?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err = json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) == 0 {
				userResult := result["result"].(map[string]any)
				userId := userResult["userid"].(string)
				return userId
			}
			panic(any("获取员工[" + unionId + "]信息失败"))
		} else {
			panic(any(err))
		}
	} else {
		panic(any(err))
	}
}

func (dt *DingTalk) getEmployeeIdByAuthCode(authCode string) string {
	var param io.Reader = nil
	args := make(map[string]any)
	args["clientId"] = "dinglvrfy5p9zq79ojaj"
	args["clientSecret"] = "7Tcy-xRj8m3jVM9cNZo62XlbFaxfONgRE0LKImUrka4DgEOt16RN9TJh9cZR63Vl"
	args["code"] = authCode
	args["refreshToken"] = authCode
	args["grantType"] = "authorization_code"
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	var token = ""
	resp, err := http.Post("https://api.dingtalk.com/v1.0/oauth2/userAccessToken", "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err = json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if result["accessToken"] != nil {
				token = result["accessToken"].(string)
				req, _ := http.NewRequest("GET", "https://api.dingtalk.com/v1.0/contact/users/me", nil)
				req.Header.Set("x-acs-dingtalk-access-token", token)
				resp, err := (&http.Client{}).Do(req)
				if err != nil {
					panic(any("无法获取员工信息。"))
				} else {
					err = json.Unmarshal(readBody(resp), &result)
					if err == nil {
						if result["unionId"] != nil {
							unionId := result["unionId"].(string)
							id := dt.getEmployeeIdByUnionId(unionId)
							return id
						} else {
							panic(any("无法获取员工信息。"))
						}
					} else {
						panic(any("无法获取员工信息。"))
					}
				}
			} else {
				panic(any("无法获取员工Token。"))
			}
		} else {
			panic(any(err))
		}
	} else {
		panic(any(err))
	}
}

func (dt *DingTalk) getIsLeaderById(id string) bool {
	var param io.Reader = nil
	args := make(map[string]any)
	args["userid"] = id
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/v2/user/get?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err = json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) == 0 {
				userResult := result["result"].(map[string]any)
				leaderInDeps := userResult["leader_in_dept"].([]any)
				for i := 0; i < len(leaderInDeps); i++ {
					leaderInDep := leaderInDeps[i].(map[string]any)
					isLeader := leaderInDep["leader"].(bool)
					if isLeader {
						return true
					}
				}
				return false
			}
			panic(any("获取员工[" + id + "]信息失败"))
		} else {
			panic(any(err))
		}
	} else {
		panic(any(err))
	}
}

func (dt *DingTalk) getEmployeeNameById(id string) string {
	var param io.Reader = nil
	args := make(map[string]any)
	args["userid"] = id
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/v2/user/get?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err = json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) == 0 {
				userResult := result["result"].(map[string]any)
				userName := userResult["name"].(string)
				return userName
			}
			panic(any("获取员工[" + id + "]信息失败"))
		} else {
			panic(any(err))
		}
	} else {
		panic(any(err))
	}
}

func (dt *DingTalk) getEmployeeNameByAuthCode(authCode string) string {
	var param io.Reader = nil
	args := make(map[string]any)
	args["clientId"] = "dinglvrfy5p9zq79ojaj"
	args["clientSecret"] = "7Tcy-xRj8m3jVM9cNZo62XlbFaxfONgRE0LKImUrka4DgEOt16RN9TJh9cZR63Vl"
	args["code"] = authCode
	args["refreshToken"] = authCode
	args["grantType"] = "authorization_code"
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	var token = ""
	resp, err := http.Post("https://api.dingtalk.com/v1.0/oauth2/userAccessToken", "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err = json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if result["accessToken"] != nil {
				token = result["accessToken"].(string)
				req, _ := http.NewRequest("GET", "https://api.dingtalk.com/v1.0/contact/users/me", nil)
				req.Header.Set("x-acs-dingtalk-access-token", token)
				resp, err := (&http.Client{}).Do(req)
				if err != nil {
					panic(any("无法获取员工信息。"))
				} else {
					err = json.Unmarshal(readBody(resp), &result)
					if err == nil {
						if result["unionId"] != nil {
							unionId := result["unionId"].(string)
							id := dt.getEmployeeIdByUnionId(unionId)
							name := dt.getEmployeeNameById(id)
							return name
						} else {
							panic(any("无法获取员工信息。"))
						}
					} else {
						panic(any("无法获取员工信息。"))
					}
				}
			} else {
				panic(any("无法获取员工Token。"))
			}
		} else {
			panic(any(err))
		}
	} else {
		panic(any(err))
	}
}

func (dt *DingTalk) getDepartments(parentId int) []Department {
	departments := make([]Department, 0)
	var param io.Reader = nil
	if parentId != 0 {
		args := make(map[string]any)
		args["dept_id"] = parentId
		json, err := json.Marshal(args)
		if err == nil {
			param = bytes.NewReader(json)
		} else {
			panic(any(err))
		}
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/v2/department/listsub?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		resultData := readBody(resp)
		err := json.Unmarshal(resultData, &result)
		if err == nil {
			if int((result["errcode"]).(float64)) == 0 {
				depList := result["result"].([]any)
				if depList != nil {
					for i := 0; i < len(depList); i++ {
						dep := depList[i].(map[string]any)
						depId := int(dep["dept_id"].(float64))
						depName := dep["name"].(string)
						parentDepId := int(dep["parent_id"].(float64))
						departments = append(departments, Department{depId, depName, parentDepId})
					}
				}
			} else {
				fmt.Println(string(resultData))
			}
		} else {
			fmt.Println(err.Error())
		}
	}
	return departments
}

func (dt *DingTalk) getAttendanceRules(userId string, userName string) AttendanceRules {
	var param io.Reader = nil
	args := make(map[string]any)
	args["userid"] = userId
	data, err := json.Marshal(args)
	if err == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(err))
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/attendance/getusergroup?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err := json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) == 0 {
				groupResult := result["result"].(map[string]any)
				if groupResult != nil {
					if groupResult["name"] == nil {
						return AttendanceRules{"", time.Unix(0, 0), time.Unix(0, 0)}
					}
					groupName := groupResult["name"].(string)
					classes := groupResult["classes"].([]any)
					if len(classes) > 0 {
						sections := classes[0].(map[string]any)["sections"].([]any)
						if len(sections) > 0 {
							times := sections[0].(map[string]any)["times"].([]any)
							start := dateTimeToTime(strToDateTime(times[0].(map[string]any)["check_time"].(string)))
							end := dateTimeToTime(strToDateTime(times[1].(map[string]any)["check_time"].(string)))
							return AttendanceRules{groupName, start, end}
						}
					} else {
						return AttendanceRules{groupName, time.Unix(0, 0), time.Unix(0, 0)}
					}
				}
			}
		}
		panic(any("无法获取员工[" + userName + "]的考勤班次信息。"))
	} else {
		panic(any(err))
	}
}

func (dt *DingTalk) getEmployeeCount() int {
	var param io.Reader = nil
	args := make(map[string]any)
	args["only_active"] = true
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/user/count?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err = json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) == 0 {
				countResult := result["result"].(map[string]any)
				count := int(math.Floor(countResult["count"].(float64)))
				return count
			}
			panic(any("获取员工数量失败。"))
		} else {
			panic(any(err))
		}
	} else {
		panic(any(err))
	}
}

func (dt *DingTalk) getEmployee(userId string, depId int) Employee {
	var param io.Reader = nil
	args := make(map[string]any)
	args["userid"] = userId
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/v2/user/get?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err = json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) == 0 {
				userResult := result["result"].(map[string]any)
				userName := userResult["name"].(string)
				title := ""
				if userResult["title"] != nil {
					title = userResult["title"].(string)
				}
				email := ""
				if userResult["email"] != nil {
					email = userResult["email"].(string)
				}
				attendanceRules := dt.getAttendanceRules(userId, userName)
				isStruggle := false
				return Employee{userId, userName, title, depId, email, attendanceRules, false, isStruggle}
			}
			panic(any("获取员工[" + userId + "]信息失败"))
		} else {
			panic(any(err))
		}
	} else {
		panic(any(err))
	}
}

// 获取部门员工列表
func (dt *DingTalk) getEmployees(depId int) []Employee {
	employees := make([]Employee, 0)
	var param io.Reader = nil
	if depId != 0 {
		args := make(map[string]any)
		args["dept_id"] = depId
		json, err := json.Marshal(args)
		if err == nil {
			param = bytes.NewReader(json)
		} else {
			panic(any(err))
		}
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/user/listid?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err := json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) == 0 {
				resultData := result["result"].(map[string]any)
				if resultData != nil {
					userIdList := resultData["userid_list"].([]any)
					for i := 0; i < len(userIdList); i++ {
						employees = append(employees, dt.getEmployee(userIdList[i].(string), depId))
					}
					return employees
				}
			}
			panic(any("无法获取部门[" + strconv.Itoa(depId) + "]员工列表"))
		} else {
			panic(any(err))
		}
	} else {
		panic(any(err))
	}
}

func (dt *DingTalk) sendTextMessage(userIds []string, content string) {
	var param io.Reader = nil
	args := make(map[string]any)
	args["agent_id"] = dt.agentId
	args["userid_list"] = strings.Join(userIds, ",")

	msg := make(map[string]any)
	msg["msgtype"] = "text"
	text := make(map[string]any)
	text["content"] = content
	msg["text"] = text
	args["msg"] = msg
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err = json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) != 0 {
				panic(any("发送消息失败"))
			}
		} else {
			panic(any(err))
		}
	}
}

func (dt *DingTalk) sendUrlMessage(userIds []string, title string, text string, imageUrl string, contentUrl string) {
	var param io.Reader = nil
	args := make(map[string]any)
	args["agent_id"] = dt.agentId
	args["userid_list"] = strings.Join(userIds, ",")

	msg := make(map[string]any)
	msg["msgtype"] = "link"
	link := make(map[string]any)
	link["messageUrl"] = contentUrl
	link["picUrl"] = imageUrl
	link["title"] = title
	link["text"] = text
	msg["link"] = link
	args["msg"] = msg
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err = json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) != 0 {
				panic(any("发送消息失败"))
			}
		} else {
			panic(any(err))
		}
	}
}

func (dt *DingTalk) sendActionCard(userIds []string, title string, markdown string, singleTitle string, singleUrl string) {
	var param io.Reader = nil
	args := make(map[string]any)
	args["agent_id"] = dt.agentId
	args["userid_list"] = strings.Join(userIds, ",")

	msg := make(map[string]any)
	msg["msgtype"] = "action_card"
	actionCard := make(map[string]any)
	actionCard["title"] = title
	actionCard["markdown"] = markdown
	actionCard["single_title"] = singleTitle
	actionCard["single_url"] = singleUrl
	msg["action_card"] = actionCard
	args["msg"] = msg
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err = json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) != 0 {
				panic(any("发送消息失败"))
			}
		} else {
			panic(any(err))
		}
	}
}

func getOrCreateAttendanceData(list []*AttendanceData, index int, employeeId string, day time.Time) *AttendanceData {
	if list[index] == nil {
		list[index] = new(AttendanceData)
		list[index].EmployeeId = employeeId
		list[index].Day = day
	}
	return list[index]
}

func (dt *DingTalk) getEmployeeAttendanceDataList(employeeId string, start time.Time, end time.Time) []AttendanceData {
	var list []*AttendanceData
	var param io.Reader = nil
	args := make(map[string]any)
	args["column_id_list"] = strconv.Itoa(OnDutyCheckTime) + "," + strconv.Itoa(OnDutyCheckResult) + "," + strconv.Itoa(OffDutyCheckTime) + "," + strconv.Itoa(OffDutyCheckResult) + "," + strconv.Itoa(AttendanceApprove)
	args["from_date"] = start.Format("2006-01-02 15:04:05")
	args["to_date"] = end.Format("2006-01-02 15:04:05")
	args["userid"] = employeeId
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/attendance/getcolumnval?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err = json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) == 0 {
				resultData := result["result"].(map[string]any)
				if resultData != nil {
					columns := resultData["column_vals"].([]any)
					for i := 0; i < len(columns); i++ {
						column := columns[i].(map[string]any)
						columnId := int(column["column_vo"].(map[string]any)["id"].(float64))
						columnsValues := column["column_vals"].([]any)
						if list == nil {
							list = make([]*AttendanceData, len(columnsValues))
						}
						var attendanceData *AttendanceData
						for i := 0; i < len(columnsValues); i++ {
							dayValues := columnsValues[i].(map[string]any)
							switch columnId {
							case OnDutyCheckTime:
								day := dateTimeToDate(strToDateTime(dayValues["date"].(string)))
								attendanceData = getOrCreateAttendanceData(list, i, employeeId, day)
								attendanceData.Start = dayValues["value"].(string)
							case OnDutyCheckResult:
								day := dateTimeToDate(strToDateTime(dayValues["date"].(string)))
								attendanceData = getOrCreateAttendanceData(list, i, employeeId, day)
								attendanceData.StartResult = dayValues["value"].(string)
							case OffDutyCheckTime:
								day := dateTimeToDate(strToDateTime(dayValues["date"].(string)))
								attendanceData = getOrCreateAttendanceData(list, i, employeeId, day)
								attendanceData.End = dayValues["value"].(string)
							case OffDutyCheckResult:
								day := dateTimeToDate(strToDateTime(dayValues["date"].(string)))
								attendanceData = getOrCreateAttendanceData(list, i, employeeId, day)
								attendanceData.EndResult = dayValues["value"].(string)
							case AttendanceApprove:
								day := dateTimeToDate(strToDateTime(dayValues["date"].(string)))
								attendanceData = getOrCreateAttendanceData(list, i, employeeId, day)
								attendanceData.Approve = dayValues["value"].(string)
							}
						}
					}
					for i := 0; i < len(list); i++ {
						attendanceData := list[i]
						attendanceData.State = 出勤
						if attendanceData.Start == "" || attendanceData.End == "" {
							if attendanceData.StartResult == "出差" || attendanceData.EndResult == "出差" {
								attendanceData.State = 出差
							}
							if attendanceData.StartResult == "外出" || attendanceData.EndResult == "外出" {
								attendanceData.State = 外出
							}
							if attendanceData.StartResult == "缺卡" || attendanceData.EndResult == "缺卡" {
								attendanceData.State = 缺卡
							}
							//不管外出还是缺卡，出差还是外出，只要有请假就是请假
							if attendanceData.StartResult == "请假" || attendanceData.EndResult == "请假" {
								attendanceData.State = 请假
							}
							if attendanceData.StartResult == "加班" || attendanceData.EndResult == "加班" {
								attendanceData.State = 加班
							}
							if attendanceData.StartResult == "" && attendanceData.EndResult == "" && attendanceData.Approve == "" {
								attendanceData.State = 休息
							}
						}
						//Check approve
						if strings.Contains(attendanceData.Approve, "出差") {
							attendanceData.State = 出差
						}
						if strings.Contains(attendanceData.Approve, "外出") {
							attendanceData.State = 外出
						}
						if strings.Contains(attendanceData.Approve, "缺卡") {
							attendanceData.State = 缺卡
						}
						if strings.Contains(attendanceData.Approve, "请假") {
							attendanceData.State = 请假
						}
						if strings.Contains(attendanceData.Approve, "加班") {
							attendanceData.State = 加班
						}

						if strings.Contains(attendanceData.Start, "昨日") {
							startTime := dateTimeToTime(strToTime("00:01"))
							attendanceData.StartTime = startTime
						} else {
							startTime := dateTimeToTime(strToTime(attendanceData.Start))
							attendanceData.StartTime = startTime
						}

						if strings.Contains(attendanceData.End, "次日") {
							endTime := dateTimeToTime(strToTime("23:59"))
							attendanceData.EndTime = endTime
						} else {
							endTime := dateTimeToTime(strToTime(attendanceData.End))
							attendanceData.EndTime = endTime
						}
					}
					result := make([]AttendanceData, 0)
					for i := 0; i < len(list); i++ {
						result = append(result, *list[i])
					}
					return result
				}
			}
			panic(any("无法获取员工[" + employeeId + "]的考勤信息。"))
		} else {
			panic(any(err))
		}
	} else {
		panic(any(err))
	}
}

func (dt *DingTalk) getLeaveQuota(lq map[string]any) LeaveQuota {
	leaveQuota := LeaveQuota{}
	leaveQuota.Id = lq["userid"].(string)
	leaveCode := lq["leave_code"].(string)
	if leaveCode == "6a6c631c-65cf-434c-97fa-335c9df7cb81" {
		leaveQuota.Quota = int(lq["quota_num_per_day"].(float64))
		leaveQuota.Used = int(lq["used_num_per_day"].(float64))
		leaveQuota.LeaveType = "年假"
		leaveQuota.Unit = 天
	} else {
		leaveQuota.Quota = int(lq["quota_num_per_hour"].(float64))
		leaveQuota.Used = int(lq["used_num_per_hour"].(float64))
		leaveQuota.LeaveType = "调休"
		leaveQuota.Unit = 小时
	}
	return leaveQuota
}

func (dt *DingTalk) getLeaveQuotas(employeeId string, leaveType int) []LeaveQuota {
	leaveQuotas := make([]LeaveQuota, 0)
	args := make(map[string]any)
	args["offset"] = 0
	args["size"] = 100
	args["userids"] = employeeId
	if leaveType == 年假 {
		args["leave_code"] = "6a6c631c-65cf-434c-97fa-335c9df7cb81"
	} else {
		args["leave_code"] = "12d81490-04e3-4848-920e-7f87e5955451"
	}
	args["op_userid"] = "14033025461181119"
	var param io.Reader = nil
	data, dataErr := json.Marshal(args)
	if dataErr == nil {
		param = bytes.NewReader(data)
	} else {
		panic(any(dataErr))
	}
	resp, err := http.Post("https://oapi.dingtalk.com/topapi/attendance/vacation/quota/list?access_token="+dt.token, "application/json;charset=utf-8", param)
	if err == nil {
		result := make(map[string]any)
		err := json.Unmarshal(readBody(resp), &result)
		if err == nil {
			if int((result["errcode"]).(float64)) == 0 {
				resultData := result["result"].(map[string]any)
				if resultData != nil {
					if resultData["leave_quotas"] != nil {
						lqs := resultData["leave_quotas"].([]any)
						for i := 0; i < len(lqs); i++ {
							lq := lqs[i].(map[string]any)
							leaveQuotas = append(leaveQuotas, dt.getLeaveQuota(lq))
						}
					}
					return leaveQuotas
				} else {
					panic(any("无法获得假期信息"))
				}
			} else {
				panic(any("无法获得假期信息"))
			}
		} else {
			panic(any(err))
		}
	} else {
		panic(any(err))
	}
}
