record.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. package checkin
  2. import (
  3. "fmt"
  4. "github.com/silenceper/wechat/v2/util"
  5. )
  6. const (
  7. // getCheckinDataURL 获取打卡记录数据
  8. getCheckinDataURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata?access_token=%s"
  9. // getDayDataURL 获取打卡日报数据
  10. getDayDataURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckin_daydata?access_token=%s"
  11. // getMonthDataURL 获取打卡月报数据
  12. getMonthDataURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckin_monthdata?access_token=%s"
  13. )
  14. type (
  15. // GetCheckinDataRequest 获取打卡记录数据请求
  16. GetCheckinDataRequest struct {
  17. OpenCheckinDataType int64 `json:"opencheckindatatype"`
  18. StartTime int64 `json:"starttime"`
  19. EndTime int64 `json:"endtime"`
  20. UserIDList []string `json:"useridlist"`
  21. }
  22. // GetCheckinDataResponse 获取打卡记录数据响应
  23. GetCheckinDataResponse struct {
  24. util.CommonError
  25. CheckinData []*GetCheckinDataItem `json:"checkindata"`
  26. }
  27. // GetCheckinDataItem 打卡记录数据
  28. GetCheckinDataItem struct {
  29. UserID string `json:"userid"`
  30. GroupName string `json:"groupname"`
  31. CheckinType string `json:"checkin_type"`
  32. ExceptionType string `json:"exception_type"`
  33. CheckinTime int64 `json:"checkin_time"`
  34. LocationTitle string `json:"location_title"`
  35. LocationDetail string `json:"location_detail"`
  36. WifiName string `json:"wifiname"`
  37. Notes string `json:"notes"`
  38. WifiMac string `json:"wifimac"`
  39. MediaIDs []string `json:"mediaids"`
  40. SchCheckinTime int64 `json:"sch_checkin_time"`
  41. GroupID int64 `json:"groupid"`
  42. ScheduleID int64 `json:"schedule_id"`
  43. TimelineID int64 `json:"timeline_id"`
  44. Lat int64 `json:"lat,omitempty"`
  45. Lng int64 `json:"lng,omitempty"`
  46. DeviceID string `json:"deviceid,omitempty"`
  47. }
  48. )
  49. // GetCheckinData 获取打卡记录数据
  50. // @see https://developer.work.weixin.qq.com/document/path/90262
  51. func (r *Client) GetCheckinData(req *GetCheckinDataRequest) (*GetCheckinDataResponse, error) {
  52. var (
  53. accessToken string
  54. err error
  55. )
  56. if accessToken, err = r.GetAccessToken(); err != nil {
  57. return nil, err
  58. }
  59. var response []byte
  60. if response, err = util.PostJSON(fmt.Sprintf(getCheckinDataURL, accessToken), req); err != nil {
  61. return nil, err
  62. }
  63. result := &GetCheckinDataResponse{}
  64. err = util.DecodeWithError(response, result, "GetCheckinData")
  65. return result, err
  66. }
  67. type (
  68. // GetDayDataResponse 获取打卡日报数据
  69. GetDayDataResponse struct {
  70. util.CommonError
  71. Datas []DayDataItem `json:"datas"`
  72. }
  73. // DayDataItem 日报
  74. DayDataItem struct {
  75. BaseInfo DayBaseInfo `json:"base_info"`
  76. SummaryInfo DaySummaryInfo `json:"summary_info"`
  77. HolidayInfos []HolidayInfo `json:"holiday_infos"`
  78. ExceptionInfos []ExceptionInfo `json:"exception_infos"`
  79. OtInfo OtInfo `json:"ot_info"`
  80. SpItems []SpItem `json:"sp_items"`
  81. }
  82. // DayBaseInfo 基础信息
  83. DayBaseInfo struct {
  84. Date int64 `json:"date"`
  85. RecordType int64 `json:"record_type"`
  86. Name string `json:"name"`
  87. NameEx string `json:"name_ex"`
  88. DepartsName string `json:"departs_name"`
  89. AcctID string `json:"acctid"`
  90. DayType int64 `json:"day_type"`
  91. RuleInfo DayRuleInfo `json:"rule_info"`
  92. }
  93. // DayCheckInTime 当日打卡时间
  94. DayCheckInTime struct {
  95. WorkSec int64 `json:"work_sec"`
  96. OffWorkSec int64 `json:"off_work_sec"`
  97. }
  98. // DayRuleInfo 打卡人员所属规则信息
  99. DayRuleInfo struct {
  100. GroupID int64 `json:"groupid"`
  101. GroupName string `json:"groupname"`
  102. ScheduleID int64 `json:"scheduleid"`
  103. ScheduleName string `json:"schedulename"`
  104. CheckInTimes []DayCheckInTime `json:"checkintime"`
  105. }
  106. // DaySummaryInfo 汇总信息
  107. DaySummaryInfo struct {
  108. CheckinCount int64 `json:"checkin_count"`
  109. RegularWorkSec int64 `json:"regular_work_sec"`
  110. StandardWorkSec int64 `json:"standard_work_sec"`
  111. EarliestTime int64 `json:"earliest_time"`
  112. LastestTime int64 `json:"lastest_time"`
  113. }
  114. // HolidayInfo 假勤相关信息
  115. HolidayInfo struct {
  116. SpNumber string `json:"sp_number"`
  117. SpTitle SpTitle `json:"sp_title"`
  118. SpDescription SpDescription `json:"sp_description"`
  119. }
  120. // SpTitle 假勤信息摘要-标题信息
  121. SpTitle struct {
  122. Data []SpData `json:"data"`
  123. }
  124. // SpDescription 假勤信息摘要-描述信息
  125. SpDescription struct {
  126. Data []SpData `json:"data"`
  127. }
  128. // SpData 假勤信息(多种语言描述,目前只有中文一种)
  129. SpData struct {
  130. Lang string `json:"lang"`
  131. Text string `json:"text"`
  132. }
  133. // SpItem 假勤统计信息
  134. SpItem struct {
  135. Count int64 `json:"count"`
  136. Duration int64 `json:"duration"`
  137. TimeType int64 `json:"time_type"`
  138. Type int64 `json:"type"`
  139. VacationID int64 `json:"vacation_id"`
  140. Name string `json:"name"`
  141. }
  142. // ExceptionInfo 校准状态信息
  143. ExceptionInfo struct {
  144. Count int64 `json:"count"`
  145. Duration int64 `json:"duration"`
  146. Exception int64 `json:"exception"`
  147. }
  148. // OtInfo 加班信息
  149. OtInfo struct {
  150. OtStatus int64 `json:"ot_status"`
  151. OtDuration int64 `json:"ot_duration"`
  152. ExceptionDuration []uint64 `json:"exception_duration"`
  153. }
  154. )
  155. // GetDayData 获取打卡日报数据
  156. // @see https://developer.work.weixin.qq.com/document/path/96498
  157. func (r *Client) GetDayData(req *GetCheckinDataRequest) (result *GetDayDataResponse, err error) {
  158. var (
  159. response []byte
  160. accessToken string
  161. )
  162. if accessToken, err = r.GetAccessToken(); err != nil {
  163. return
  164. }
  165. if response, err = util.PostJSON(fmt.Sprintf(getDayDataURL, accessToken), req); err != nil {
  166. return
  167. }
  168. result = new(GetDayDataResponse)
  169. err = util.DecodeWithError(response, result, "GetDayData")
  170. return
  171. }
  172. type (
  173. // GetMonthDataResponse 获取打卡月报数据
  174. GetMonthDataResponse struct {
  175. util.CommonError
  176. Datas []MonthDataItem `json:"datas"`
  177. }
  178. // MonthDataItem 月报数据
  179. MonthDataItem struct {
  180. BaseInfo MonthBaseInfo `json:"base_info"`
  181. SummaryInfo MonthSummaryInfo `json:"summary_info"`
  182. ExceptionInfos []ExceptionInfo `json:"exception_infos"`
  183. SpItems []SpItem `json:"sp_items"`
  184. OverWorkInfo OverWorkInfo `json:"overwork_info"`
  185. }
  186. // MonthBaseInfo 基础信息
  187. MonthBaseInfo struct {
  188. RecordType int64 `json:"record_type"`
  189. Name string `json:"name"`
  190. NameEx string `json:"name_ex"`
  191. DepartsName string `json:"departs_name"`
  192. AcctID string `json:"acctid"`
  193. RuleInfo MonthRuleInfo `json:"rule_info"`
  194. }
  195. // MonthRuleInfo 打卡人员所属规则信息
  196. MonthRuleInfo struct {
  197. GroupID int64 `json:"groupid"`
  198. GroupName string `json:"groupname"`
  199. }
  200. // MonthSummaryInfo 汇总信息
  201. MonthSummaryInfo struct {
  202. WorkDays int64 `json:"work_days"`
  203. ExceptDays int64 `json:"except_days"`
  204. RegularDays int64 `json:"regular_days"`
  205. RegularWorkSec int64 `json:"regular_work_sec"`
  206. StandardWorkSec int64 `json:"standard_work_sec"`
  207. }
  208. // OverWorkInfo 加班情况
  209. OverWorkInfo struct {
  210. WorkdayOverSec int64 `json:"workday_over_sec"`
  211. HolidayOverSec int64 `json:"holidays_over_sec"`
  212. RestDayOverSec int64 `json:"restdays_over_sec"`
  213. }
  214. )
  215. // GetMonthData 获取打卡月报数据
  216. // @see https://developer.work.weixin.qq.com/document/path/96499
  217. func (r *Client) GetMonthData(req *GetCheckinDataRequest) (result *GetMonthDataResponse, err error) {
  218. var (
  219. response []byte
  220. accessToken string
  221. )
  222. if accessToken, err = r.GetAccessToken(); err != nil {
  223. return
  224. }
  225. if response, err = util.PostJSON(fmt.Sprintf(getMonthDataURL, accessToken), req); err != nil {
  226. return
  227. }
  228. result = new(GetMonthDataResponse)
  229. err = util.DecodeWithError(response, result, "GetMonthData")
  230. return
  231. }