From e8c430e0a3df20c8836f7f9bac4997605f12dada Mon Sep 17 00:00:00 2001 From: Thinker Date: Mon, 9 Oct 2023 14:49:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1-?= =?UTF-8?q?=E6=89=93=E5=8D=A1-=E6=97=A5=E6=8A=A5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/api/work.md | 8 +++ work/checkin/checkin.go | 123 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/doc/api/work.md b/doc/api/work.md index 117c20b4..2c3be66c 100644 --- a/doc/api/work.md +++ b/doc/api/work.md @@ -116,5 +116,13 @@ host: https://qyapi.weixin.qq.com/ | ---------------- | -------- | --------------------- | ---------- | -------------------------- | -------- | | 群机器人发送消息 | POST | /cgi-bin/webhook/send | YES | (r *Client) RobotBroadcast | chcthink | +## 打卡 + +[官方文档](https://developer.work.weixin.qq.com/document/path/96497) + +| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 | +| ---------------- | -------- | --------------------- | ---------- | -------------------------- |---------| +| 获取打卡日报数据 | POST | /cgi-bin/checkin/getcheckin_daydata | YES | (r *Client) GetDayData | Thinker | + ## 应用管理 TODO diff --git a/work/checkin/checkin.go b/work/checkin/checkin.go index 7dbd0a38..1416cce9 100644 --- a/work/checkin/checkin.go +++ b/work/checkin/checkin.go @@ -9,6 +9,8 @@ import ( const ( // getCheckinDataURL 获取打卡记录数据 getCheckinDataURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata?access_token=%s" + // getDayDataURL 获取打卡日报数据 + getDayDataURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckin_daydata?access_token=%s" ) type ( @@ -67,3 +69,124 @@ func (r *Client) GetCheckinData(req *GetCheckinDataRequest) (*GetCheckinDataResp } return result, nil } + +type ( + // GetDayDataResponse 获取打卡日报数据 + GetDayDataResponse struct { + util.CommonError + Datas []DayDataItem `json:"datas"` + } + + DayDataItem struct { + BaseInfo DayBaseInfo `json:"base_info"` + SummaryInfo DaySummaryInfo `json:"summary_info"` + HolidayInfos []HolidayInfo `json:"holiday_infos"` + ExceptionInfos []ExceptionInfo `json:"exception_infos"` + OtInfo OtInfo `json:"ot_info"` + SpItems []SpItem `json:"sp_items"` + } + + // DayBaseInfo 基础信息 + DayBaseInfo struct { + Date int64 `json:"date"` + RecordType int64 `json:"record_type"` + Name string `json:"name"` + NameEx string `json:"name_ex"` + DepartsName string `json:"departs_name"` + AcctId string `json:"acctid"` + DayType int64 `json:"day_type"` + RuleInfo DayRuleInfo `json:"rule_info"` + } + + // CheckInTime 当日打卡时间 + CheckInTime struct { + WorkSec int64 `json:"work_sec"` + OffWorkSec int64 `json:"off_work_sec"` + } + + // DayRuleInfo 打卡人员所属规则信息 + DayRuleInfo struct { + GroupId int64 `json:"groupid"` + GroupName string `json:"groupname"` + ScheduleId int64 `json:"scheduleid"` + ScheduleName string `json:"schedulename"` + CheckInTimes []CheckInTime `json:"checkintime"` + } + + // DaySummaryInfo 汇总信息 + DaySummaryInfo struct { + CheckinCount int64 `json:"checkin_count"` + RegularWorkSec int64 `json:"regular_work_sec"` + StandardWorkSec int64 `json:"standard_work_sec"` + EarliestTime int64 `json:"earliest_time"` + LastestTime int64 `json:"lastest_time"` + } + + // HolidayInfo 假勤相关信息 + HolidayInfo struct { + SpNumber string `json:"sp_number"` + SpTitle SpTitle `json:"sp_title"` + SpDescription SpDescription `json:"sp_description"` + } + + // SpTitle 假勤信息摘要-标题信息 + SpTitle struct { + Data []SpData `json:"data"` + } + + // SpDescription 假勤信息摘要-描述信息 + SpDescription struct { + Data []SpData `json:"data"` + } + + // SpData 假勤信息(多种语言描述,目前只有中文一种) + SpData struct { + Lang string `json:"lang"` + Text string `json:"text"` + } + + // SpItem 假勤统计信息 + SpItem struct { + Count int64 `json:"count"` + Duration int64 `json:"duration"` + TimeType int64 `json:"time_type"` + Type int64 `json:"type"` + VacationId int64 `json:"vacation_id"` + Name string `json:"name"` + } + + // ExceptionInfo 校准状态信息 + ExceptionInfo struct { + Count int64 `json:"count"` + Duration int64 `json:"duration"` + Exception int64 `json:"exception"` + } + + // OtInfo 加班信息 + OtInfo struct { + OtStatus int64 `json:"ot_status"` + OtDuration int64 `json:"ot_duration"` + ExceptionDuration []uint64 `json:"exception_duration"` + } +) + +// GetDayData 获取打卡日报数据 +// @see https://developer.work.weixin.qq.com/document/path/96498 +func (r *Client) GetDayData(req *GetCheckinDataRequest) (result *GetDayDataResponse, err error) { + var ( + response []byte + accessToken string + ) + if accessToken, err = r.GetAccessToken(); err != nil { + return + } + if response, err = util.PostJSON(fmt.Sprintf(getDayDataURL, accessToken), req); err != nil { + return + } + + result = new(GetDayDataResponse) + if err = util.DecodeWithError(response, result, "GetDayData"); err != nil { + return + } + return +}