From 038037b89dfc8d871566aacfb6ce9b34176cce4e Mon Sep 17 00:00:00 2001 From: Thinker Date: Wed, 11 Oct 2023 11:10:10 +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=E4=B8=8E=E6=9C=88?= =?UTF-8?q?=E6=8A=A5=E6=95=B0=E6=8D=AE=20(#733)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 企业微信-打卡-日报数据 * feat: 企业微信-打卡-月报数据 * refactor:重命名checkin为record(该文件内所有方法均为获取记录) * refactor:修改字段名称以符合golint标准 * fix: ineffectual assignment to err --- doc/api/work.md | 9 ++ work/checkin/checkin.go | 67 ----------- work/checkin/record.go | 259 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 268 insertions(+), 67 deletions(-) delete mode 100644 work/checkin/checkin.go create mode 100644 work/checkin/record.go diff --git a/doc/api/work.md b/doc/api/work.md index 117c20b..3be65c7 100644 --- a/doc/api/work.md +++ b/doc/api/work.md @@ -116,5 +116,14 @@ 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 | +| 获取打卡月报数据 | POST | /cgi-bin/checkin/getcheckin_monthdata | YES | (r *Client) GetMonthData | Thinker | + ## 应用管理 TODO diff --git a/work/checkin/checkin.go b/work/checkin/checkin.go deleted file mode 100644 index cf99ec0..0000000 --- a/work/checkin/checkin.go +++ /dev/null @@ -1,67 +0,0 @@ -package checkin - -import ( - "fmt" - - "github.com/silenceper/wechat/v2/util" -) - -const ( - // getCheckinDataURL 获取打卡记录数据 - getCheckinDataURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata?access_token=%s" -) - -type ( - // GetCheckinDataRequest 获取打卡记录数据请求 - GetCheckinDataRequest struct { - OpenCheckinDataType int64 `json:"opencheckindatatype"` - StartTime int64 `json:"starttime"` - EndTime int64 `json:"endtime"` - UserIDList []string `json:"useridlist"` - } - // GetCheckinDataResponse 获取打卡记录数据响应 - GetCheckinDataResponse struct { - util.CommonError - CheckinData []*GetCheckinDataItem `json:"checkindata"` - } - // GetCheckinDataItem 打卡记录数据 - GetCheckinDataItem struct { - UserID string `json:"userid"` - GroupName string `json:"groupname"` - CheckinType string `json:"checkin_type"` - ExceptionType string `json:"exception_type"` - CheckinTime int64 `json:"checkin_time"` - LocationTitle string `json:"location_title"` - LocationDetail string `json:"location_detail"` - WifiName string `json:"wifiname"` - Notes string `json:"notes"` - WifiMac string `json:"wifimac"` - MediaIDs []string `json:"mediaids"` - SchCheckinTime int64 `json:"sch_checkin_time"` - GroupID int64 `json:"groupid"` - ScheduleID int64 `json:"schedule_id"` - TimelineID int64 `json:"timeline_id"` - Lat int64 `json:"lat,omitempty"` - Lng int64 `json:"lng,omitempty"` - DeviceID string `json:"deviceid,omitempty"` - } -) - -// GetCheckinData 获取打卡记录数据 -// @see https://developer.work.weixin.qq.com/document/path/90262 -func (r *Client) GetCheckinData(req *GetCheckinDataRequest) (*GetCheckinDataResponse, error) { - var ( - accessToken string - err error - ) - if accessToken, err = r.GetAccessToken(); err != nil { - return nil, err - } - var response []byte - if response, err = util.PostJSON(fmt.Sprintf(getCheckinDataURL, accessToken), req); err != nil { - return nil, err - } - result := &GetCheckinDataResponse{} - err = util.DecodeWithError(response, result, "GetCheckinData") - return result, err -} diff --git a/work/checkin/record.go b/work/checkin/record.go new file mode 100644 index 0000000..8136ce0 --- /dev/null +++ b/work/checkin/record.go @@ -0,0 +1,259 @@ +package checkin + +import ( + "fmt" + + "github.com/silenceper/wechat/v2/util" +) + +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" + // getMonthDataURL 获取打卡月报数据 + getMonthDataURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckin_monthdata?access_token=%s" +) + +type ( + // GetCheckinDataRequest 获取打卡记录数据请求 + GetCheckinDataRequest struct { + OpenCheckinDataType int64 `json:"opencheckindatatype"` + StartTime int64 `json:"starttime"` + EndTime int64 `json:"endtime"` + UserIDList []string `json:"useridlist"` + } + // GetCheckinDataResponse 获取打卡记录数据响应 + GetCheckinDataResponse struct { + util.CommonError + CheckinData []*GetCheckinDataItem `json:"checkindata"` + } + // GetCheckinDataItem 打卡记录数据 + GetCheckinDataItem struct { + UserID string `json:"userid"` + GroupName string `json:"groupname"` + CheckinType string `json:"checkin_type"` + ExceptionType string `json:"exception_type"` + CheckinTime int64 `json:"checkin_time"` + LocationTitle string `json:"location_title"` + LocationDetail string `json:"location_detail"` + WifiName string `json:"wifiname"` + Notes string `json:"notes"` + WifiMac string `json:"wifimac"` + MediaIDs []string `json:"mediaids"` + SchCheckinTime int64 `json:"sch_checkin_time"` + GroupID int64 `json:"groupid"` + ScheduleID int64 `json:"schedule_id"` + TimelineID int64 `json:"timeline_id"` + Lat int64 `json:"lat,omitempty"` + Lng int64 `json:"lng,omitempty"` + DeviceID string `json:"deviceid,omitempty"` + } +) + +// GetCheckinData 获取打卡记录数据 +// @see https://developer.work.weixin.qq.com/document/path/90262 +func (r *Client) GetCheckinData(req *GetCheckinDataRequest) (*GetCheckinDataResponse, error) { + var ( + accessToken string + err error + ) + if accessToken, err = r.GetAccessToken(); err != nil { + return nil, err + } + var response []byte + if response, err = util.PostJSON(fmt.Sprintf(getCheckinDataURL, accessToken), req); err != nil { + return nil, err + } + result := &GetCheckinDataResponse{} + err = util.DecodeWithError(response, result, "GetCheckinData") + return result, err +} + +type ( + // GetDayDataResponse 获取打卡日报数据 + GetDayDataResponse struct { + util.CommonError + Datas []DayDataItem `json:"datas"` + } + + // DayDataItem 日报 + 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"` + } + + // DayCheckInTime 当日打卡时间 + DayCheckInTime 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 []DayCheckInTime `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) + err = util.DecodeWithError(response, result, "GetDayData") + return +} + +type ( + // GetMonthDataResponse 获取打卡月报数据 + GetMonthDataResponse struct { + util.CommonError + Datas []MonthDataItem `json:"datas"` + } + + // MonthDataItem 月报数据 + MonthDataItem struct { + BaseInfo MonthBaseInfo `json:"base_info"` + SummaryInfo MonthSummaryInfo `json:"summary_info"` + ExceptionInfos []ExceptionInfo `json:"exception_infos"` + SpItems []SpItem `json:"sp_items"` + OverWorkInfo OverWorkInfo `json:"overwork_info"` + } + + // MonthBaseInfo 基础信息 + MonthBaseInfo struct { + RecordType int64 `json:"record_type"` + Name string `json:"name"` + NameEx string `json:"name_ex"` + DepartsName string `json:"departs_name"` + AcctID string `json:"acctid"` + RuleInfo MonthRuleInfo `json:"rule_info"` + } + + // MonthRuleInfo 打卡人员所属规则信息 + MonthRuleInfo struct { + GroupID int64 `json:"groupid"` + GroupName string `json:"groupname"` + } + + // MonthSummaryInfo 汇总信息 + MonthSummaryInfo struct { + WorkDays int64 `json:"work_days"` + ExceptDays int64 `json:"except_days"` + RegularDays int64 `json:"regular_days"` + RegularWorkSec int64 `json:"regular_work_sec"` + StandardWorkSec int64 `json:"standard_work_sec"` + } + + // OverWorkInfo 加班情况 + OverWorkInfo struct { + WorkdayOverSec int64 `json:"workday_over_sec"` + HolidayOverSec int64 `json:"holidays_over_sec"` + RestDayOverSec int64 `json:"restdays_over_sec"` + } +) + +// GetMonthData 获取打卡月报数据 +// @see https://developer.work.weixin.qq.com/document/path/96499 +func (r *Client) GetMonthData(req *GetCheckinDataRequest) (result *GetMonthDataResponse, err error) { + var ( + response []byte + accessToken string + ) + if accessToken, err = r.GetAccessToken(); err != nil { + return + } + if response, err = util.PostJSON(fmt.Sprintf(getMonthDataURL, accessToken), req); err != nil { + return + } + + result = new(GetMonthDataResponse) + err = util.DecodeWithError(response, result, "GetMonthData") + return +}