record.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. // getCorpOptionURL 获取企业所有打卡规则
  14. getCorpOptionURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcorpcheckinoption?access_token=%s"
  15. // getOptionURL 获取员工打卡规则
  16. getOptionURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckinoption?access_token=%s"
  17. // getScheduleListURL 获取打卡人员排班信息
  18. getScheduleListURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckinschedulist?access_token=%s"
  19. // getHardwareDataURL 获取设备打卡数据
  20. getHardwareDataURL = "https://qyapi.weixin.qq.com/cgi-bin/hardware/get_hardware_checkin_data?access_token=%s"
  21. )
  22. type (
  23. // GetCheckinDataRequest 获取打卡记录数据请求
  24. GetCheckinDataRequest struct {
  25. OpenCheckinDataType int64 `json:"opencheckindatatype"`
  26. StartTime int64 `json:"starttime"`
  27. EndTime int64 `json:"endtime"`
  28. UserIDList []string `json:"useridlist"`
  29. }
  30. // GetCheckinDataResponse 获取打卡记录数据响应
  31. GetCheckinDataResponse struct {
  32. util.CommonError
  33. CheckinData []*GetCheckinDataItem `json:"checkindata"`
  34. }
  35. // GetCheckinDataItem 打卡记录数据
  36. GetCheckinDataItem struct {
  37. UserID string `json:"userid"`
  38. GroupName string `json:"groupname"`
  39. CheckinType string `json:"checkin_type"`
  40. ExceptionType string `json:"exception_type"`
  41. CheckinTime int64 `json:"checkin_time"`
  42. LocationTitle string `json:"location_title"`
  43. LocationDetail string `json:"location_detail"`
  44. WifiName string `json:"wifiname"`
  45. Notes string `json:"notes"`
  46. WifiMac string `json:"wifimac"`
  47. MediaIDs []string `json:"mediaids"`
  48. SchCheckinTime int64 `json:"sch_checkin_time"`
  49. GroupID int64 `json:"groupid"`
  50. ScheduleID int64 `json:"schedule_id"`
  51. TimelineID int64 `json:"timeline_id"`
  52. Lat int64 `json:"lat,omitempty"`
  53. Lng int64 `json:"lng,omitempty"`
  54. DeviceID string `json:"deviceid,omitempty"`
  55. }
  56. )
  57. // GetCheckinData 获取打卡记录数据
  58. // @see https://developer.work.weixin.qq.com/document/path/90262
  59. func (r *Client) GetCheckinData(req *GetCheckinDataRequest) (*GetCheckinDataResponse, error) {
  60. var (
  61. accessToken string
  62. err error
  63. )
  64. if accessToken, err = r.GetAccessToken(); err != nil {
  65. return nil, err
  66. }
  67. var response []byte
  68. if response, err = util.PostJSON(fmt.Sprintf(getCheckinDataURL, accessToken), req); err != nil {
  69. return nil, err
  70. }
  71. result := &GetCheckinDataResponse{}
  72. err = util.DecodeWithError(response, result, "GetCheckinData")
  73. return result, err
  74. }
  75. type (
  76. // GetDayDataResponse 获取打卡日报数据
  77. GetDayDataResponse struct {
  78. util.CommonError
  79. Datas []DayDataItem `json:"datas"`
  80. }
  81. // DayDataItem 日报
  82. DayDataItem struct {
  83. BaseInfo DayBaseInfo `json:"base_info"`
  84. SummaryInfo DaySummaryInfo `json:"summary_info"`
  85. HolidayInfos []HolidayInfo `json:"holiday_infos"`
  86. ExceptionInfos []ExceptionInfo `json:"exception_infos"`
  87. OtInfo OtInfo `json:"ot_info"`
  88. SpItems []SpItem `json:"sp_items"`
  89. }
  90. // DayBaseInfo 基础信息
  91. DayBaseInfo struct {
  92. Date int64 `json:"date"`
  93. RecordType int64 `json:"record_type"`
  94. Name string `json:"name"`
  95. NameEx string `json:"name_ex"`
  96. DepartsName string `json:"departs_name"`
  97. AcctID string `json:"acctid"`
  98. DayType int64 `json:"day_type"`
  99. RuleInfo DayRuleInfo `json:"rule_info"`
  100. }
  101. // DayCheckInTime 当日打卡时间
  102. DayCheckInTime struct {
  103. WorkSec int64 `json:"work_sec"`
  104. OffWorkSec int64 `json:"off_work_sec"`
  105. }
  106. // DayRuleInfo 打卡人员所属规则信息
  107. DayRuleInfo struct {
  108. GroupID int64 `json:"groupid"`
  109. GroupName string `json:"groupname"`
  110. ScheduleID int64 `json:"scheduleid"`
  111. ScheduleName string `json:"schedulename"`
  112. CheckInTimes []DayCheckInTime `json:"checkintime"`
  113. }
  114. // DaySummaryInfo 汇总信息
  115. DaySummaryInfo struct {
  116. CheckinCount int64 `json:"checkin_count"`
  117. RegularWorkSec int64 `json:"regular_work_sec"`
  118. StandardWorkSec int64 `json:"standard_work_sec"`
  119. EarliestTime int64 `json:"earliest_time"`
  120. LastestTime int64 `json:"lastest_time"`
  121. }
  122. // HolidayInfo 假勤相关信息
  123. HolidayInfo struct {
  124. SpNumber string `json:"sp_number"`
  125. SpTitle SpTitle `json:"sp_title"`
  126. SpDescription SpDescription `json:"sp_description"`
  127. }
  128. // SpTitle 假勤信息摘要 - 标题信息
  129. SpTitle struct {
  130. Data []SpData `json:"data"`
  131. }
  132. // SpDescription 假勤信息摘要 - 描述信息
  133. SpDescription struct {
  134. Data []SpData `json:"data"`
  135. }
  136. // SpData 假勤信息 (多种语言描述,目前只有中文一种)
  137. SpData struct {
  138. Lang string `json:"lang"`
  139. Text string `json:"text"`
  140. }
  141. // SpItem 假勤统计信息
  142. SpItem struct {
  143. Count int64 `json:"count"`
  144. Duration int64 `json:"duration"`
  145. TimeType int64 `json:"time_type"`
  146. Type int64 `json:"type"`
  147. VacationID int64 `json:"vacation_id"`
  148. Name string `json:"name"`
  149. }
  150. // ExceptionInfo 校准状态信息
  151. ExceptionInfo struct {
  152. Count int64 `json:"count"`
  153. Duration int64 `json:"duration"`
  154. Exception int64 `json:"exception"`
  155. }
  156. // OtInfo 加班信息
  157. OtInfo struct {
  158. OtStatus int64 `json:"ot_status"`
  159. OtDuration int64 `json:"ot_duration"`
  160. ExceptionDuration []uint64 `json:"exception_duration"`
  161. }
  162. )
  163. // GetDayData 获取打卡日报数据
  164. // @see https://developer.work.weixin.qq.com/document/path/96498
  165. func (r *Client) GetDayData(req *GetCheckinDataRequest) (result *GetDayDataResponse, err error) {
  166. var (
  167. response []byte
  168. accessToken string
  169. )
  170. if accessToken, err = r.GetAccessToken(); err != nil {
  171. return
  172. }
  173. if response, err = util.PostJSON(fmt.Sprintf(getDayDataURL, accessToken), req); err != nil {
  174. return
  175. }
  176. result = new(GetDayDataResponse)
  177. err = util.DecodeWithError(response, result, "GetDayData")
  178. return
  179. }
  180. type (
  181. // GetMonthDataResponse 获取打卡月报数据
  182. GetMonthDataResponse struct {
  183. util.CommonError
  184. Datas []MonthDataItem `json:"datas"`
  185. }
  186. // MonthDataItem 月报数据
  187. MonthDataItem struct {
  188. BaseInfo MonthBaseInfo `json:"base_info"`
  189. SummaryInfo MonthSummaryInfo `json:"summary_info"`
  190. ExceptionInfos []ExceptionInfo `json:"exception_infos"`
  191. SpItems []SpItem `json:"sp_items"`
  192. OverWorkInfo OverWorkInfo `json:"overwork_info"`
  193. }
  194. // MonthBaseInfo 基础信息
  195. MonthBaseInfo struct {
  196. RecordType int64 `json:"record_type"`
  197. Name string `json:"name"`
  198. NameEx string `json:"name_ex"`
  199. DepartsName string `json:"departs_name"`
  200. AcctID string `json:"acctid"`
  201. RuleInfo MonthRuleInfo `json:"rule_info"`
  202. }
  203. // MonthRuleInfo 打卡人员所属规则信息
  204. MonthRuleInfo struct {
  205. GroupID int64 `json:"groupid"`
  206. GroupName string `json:"groupname"`
  207. }
  208. // MonthSummaryInfo 汇总信息
  209. MonthSummaryInfo struct {
  210. WorkDays int64 `json:"work_days"`
  211. ExceptDays int64 `json:"except_days"`
  212. RegularDays int64 `json:"regular_days"`
  213. RegularWorkSec int64 `json:"regular_work_sec"`
  214. StandardWorkSec int64 `json:"standard_work_sec"`
  215. }
  216. // OverWorkInfo 加班情况
  217. OverWorkInfo struct {
  218. WorkdayOverSec int64 `json:"workday_over_sec"`
  219. HolidayOverSec int64 `json:"holidays_over_sec"`
  220. RestDayOverSec int64 `json:"restdays_over_sec"`
  221. }
  222. )
  223. // GetMonthData 获取打卡月报数据
  224. // @see https://developer.work.weixin.qq.com/document/path/96499
  225. func (r *Client) GetMonthData(req *GetCheckinDataRequest) (result *GetMonthDataResponse, err error) {
  226. var (
  227. response []byte
  228. accessToken string
  229. )
  230. if accessToken, err = r.GetAccessToken(); err != nil {
  231. return
  232. }
  233. if response, err = util.PostJSON(fmt.Sprintf(getMonthDataURL, accessToken), req); err != nil {
  234. return
  235. }
  236. result = new(GetMonthDataResponse)
  237. err = util.DecodeWithError(response, result, "GetMonthData")
  238. return
  239. }
  240. // GetCorpOptionResponse 获取企业所有打卡规则响应
  241. type GetCorpOptionResponse struct {
  242. util.CommonError
  243. Group []CorpOptionGroup `json:"group"`
  244. }
  245. // CorpOptionGroup 企业规则信息列表
  246. type CorpOptionGroup struct {
  247. GroupType int64 `json:"grouptype"`
  248. GroupID int64 `json:"groupid"`
  249. GroupName string `json:"groupname"`
  250. CheckinDate []GroupCheckinDate `json:"checkindate"`
  251. SpeWorkdays []SpeWorkdays `json:"spe_workdays"`
  252. SpeOffDays []SpeOffDays `json:"spe_offdays"`
  253. SyncHolidays bool `json:"sync_holidays"`
  254. NeedPhoto bool `json:"need_photo"`
  255. NoteCanUseLocalPic bool `json:"note_can_use_local_pic"`
  256. AllowCheckinOffWorkday bool `json:"allow_checkin_offworkday"`
  257. AllowApplyOffWorkday bool `json:"allow_apply_offworkday"`
  258. WifiMacInfos []WifiMacInfos `json:"wifimac_infos"`
  259. LocInfos []LocInfos `json:"loc_infos"`
  260. Range []Range `json:"range"`
  261. CreateTime int64 `json:"create_time"`
  262. WhiteUsers []string `json:"white_users"`
  263. Type int64 `json:"type"`
  264. ReporterInfo ReporterInfo `json:"reporterinfo"`
  265. OtInfo GroupOtInfo `json:"ot_info"`
  266. OtApplyInfo OtApplyInfo `json:"otapplyinfo"`
  267. Uptime int64 `json:"uptime"`
  268. AllowApplyBkCnt int64 `json:"allow_apply_bk_cnt"`
  269. OptionOutRange int64 `json:"option_out_range"`
  270. CreateUserID string `json:"create_userid"`
  271. UseFaceDetect bool `json:"use_face_detect"`
  272. AllowApplyBkDayLimit int64 `json:"allow_apply_bk_day_limit"`
  273. UpdateUserID string `json:"update_userid"`
  274. BukaRestriction int64 `json:"buka_restriction"`
  275. ScheduleList []ScheduleList `json:"schedulelist"`
  276. OffWorkIntervalTime int64 `json:"offwork_interval_time"`
  277. }
  278. // GroupCheckinDate 打卡时间,当规则类型为排班时没有意义
  279. type GroupCheckinDate struct {
  280. Workdays []int64 `json:"workdays"`
  281. CheckinTime []GroupCheckinTime `json:"checkintime"`
  282. NoNeedOffWork bool `json:"noneed_offwork"`
  283. LimitAheadTime int64 `json:"limit_aheadtime"`
  284. FlexOnDutyTime int64 `json:"flex_on_duty_time"`
  285. FlexOffDutyTime int64 `json:"flex_off_duty_time"`
  286. }
  287. // GroupCheckinTime 工作日上下班打卡时间信息
  288. type GroupCheckinTime struct {
  289. WorkSec int64 `json:"work_sec"`
  290. OffWorkSec int64 `json:"off_work_sec"`
  291. RemindWorkSec int64 `json:"remind_work_sec"`
  292. RemindOffWorkSec int64 `json:"remind_off_work_sec"`
  293. }
  294. // SpeWorkdays 特殊日期 - 必须打卡日期信息
  295. type SpeWorkdays struct {
  296. Timestamp int64 `json:"timestamp"`
  297. Notes string `json:"notes"`
  298. CheckinTime []GroupCheckinTime `json:"checkintime"`
  299. }
  300. // SpeOffDays 特殊日期 - 不用打卡日期信息
  301. type SpeOffDays struct {
  302. Timestamp int64 `json:"timestamp"`
  303. Notes string `json:"notes"`
  304. }
  305. // WifiMacInfos 打卡地点-WiFi 打卡信息
  306. type WifiMacInfos struct {
  307. WifiName string `json:"wifiname"`
  308. WifiMac string `json:"wifimac"`
  309. }
  310. // LocInfos 打卡地点 - 位置打卡信息
  311. type LocInfos struct {
  312. Lat int64 `json:"lat"`
  313. Lng int64 `json:"lng"`
  314. LocTitle string `json:"loc_title"`
  315. LocDetail string `json:"loc_detail"`
  316. Distance int64 `json:"distance"`
  317. }
  318. // Range 打卡人员信息
  319. type Range struct {
  320. PartyID []string `json:"partyid"`
  321. UserID []string `json:"userid"`
  322. TagID []int64 `json:"tagid"`
  323. }
  324. // ReporterInfo 汇报对象信息
  325. type ReporterInfo struct {
  326. Reporters []Reporters `json:"reporters"`
  327. UpdateTime int64 `json:"updatetime"`
  328. }
  329. // Reporters 汇报对象,每个汇报人用 userid 表示
  330. type Reporters struct {
  331. UserID string `json:"userid"`
  332. }
  333. // GroupOtInfo 加班信息
  334. type GroupOtInfo struct {
  335. Type int64 `json:"type"`
  336. AllowOtWorkingDay bool `json:"allow_ot_workingday"`
  337. AllowOtNonWorkingDay bool `json:"allow_ot_nonworkingday"`
  338. OtCheckInfo OtCheckInfo `json:"otcheckinfo"`
  339. }
  340. // OtCheckInfo 以打卡时间为准 - 加班时长计算规则信息
  341. type OtCheckInfo struct {
  342. OtWorkingDayTimeStart int64 `json:"ot_workingday_time_start"`
  343. OtWorkingDayTimeMin int64 `json:"ot_workingday_time_min"`
  344. OtWorkingDayTimeMax int64 `json:"ot_workingday_time_max"`
  345. OtNonworkingDayTimeMin int64 `json:"ot_nonworkingday_time_min"`
  346. OtNonworkingDayTimeMax int64 `json:"ot_nonworkingday_time_max"`
  347. OtNonworkingDaySpanDayTime int64 `json:"ot_nonworkingday_spanday_time"`
  348. OtWorkingDayRestInfo OtRestInfo `json:"ot_workingday_restinfo"`
  349. OtNonWorkingDayRestInfo OtRestInfo `json:"ot_nonworkingday_restinfo"`
  350. }
  351. // OtRestInfo 加班 - 休息扣除配置信息
  352. type OtRestInfo struct {
  353. Type int64 `json:"type"`
  354. FixTimeRule FixTimeRule `json:"fix_time_rule"`
  355. CalOtTimeRule CalOtTimeRule `json:"cal_ottime_rule"`
  356. }
  357. // FixTimeRule 工作日加班 - 指定休息时间配置信息
  358. type FixTimeRule struct {
  359. FixTimeBeginSec int64 `json:"fix_time_begin_sec"`
  360. FixTimeEndSec int64 `json:"fix_time_end_sec"`
  361. }
  362. // CalOtTimeRule 工作日加班 - 按加班时长扣除配置信息
  363. type CalOtTimeRule struct {
  364. Items []CalOtTimeRuleItem `json:"items"`
  365. }
  366. // CalOtTimeRuleItem 工作日加班 - 按加班时长扣除条件信息
  367. type CalOtTimeRuleItem struct {
  368. OtTime int64 `json:"ot_time"`
  369. RestTime int64 `json:"rest_time"`
  370. }
  371. // OtApplyInfo 以加班申请核算打卡记录相关信息
  372. type OtApplyInfo struct {
  373. AllowOtWorkingDay bool `json:"allow_ot_workingday"`
  374. AllowOtNonWorkingDay bool `json:"allow_ot_nonworkingday"`
  375. Uiptime int64 `json:"uptime"`
  376. OtNonworkingDaySpanDayTime int64 `json:"ot_nonworkingday_spanday_time"`
  377. OtWorkingDayRestInfo OtRestInfo `json:"ot_workingday_restinfo"`
  378. OtNonWorkingDayRestInfo OtRestInfo `json:"ot_nonworkingday_restinfo"`
  379. }
  380. // ScheduleList 排班信息列表
  381. type ScheduleList struct {
  382. ScheduleID int64 `json:"schedule_id"`
  383. ScheduleName string `json:"schedule_name"`
  384. TimeSection []TimeSection `json:"time_section"`
  385. LimitAheadTime int64 `json:"limit_aheadtime"`
  386. NoNeedOffWork bool `json:"noneed_offwork"`
  387. LimitOffTime int64 `json:"limit_offtime"`
  388. FlexOnDutyTime int64 `json:"flex_on_duty_time"`
  389. FlexOffDutyTime int64 `json:"flex_off_duty_time"`
  390. AllowFlex bool `json:"allow_flex"`
  391. LateRule LateRule `json:"late_rule"`
  392. MaxAllowArriveEarly int64 `json:"max_allow_arrive_early"`
  393. MaxAllowArriveLate int64 `json:"max_allow_arrive_late"`
  394. }
  395. // TimeSection 班次上下班时段信息
  396. type TimeSection struct {
  397. TimeID int64 `json:"time_id"`
  398. WorkSec int64 `json:"work_sec"`
  399. OffWorkSec int64 `json:"off_work_sec"`
  400. RemindWorkSec int64 `json:"remind_work_sec"`
  401. RemindOffWorkSec int64 `json:"remind_off_work_sec"`
  402. RestBeginTime int64 `json:"rest_begin_time"`
  403. RestEndTime int64 `json:"rest_end_time"`
  404. AllowRest bool `json:"allow_rest"`
  405. }
  406. // LateRule 晚走晚到时间规则信息
  407. type LateRule struct {
  408. AllowOffWorkAfterTime bool `json:"allow_offwork_after_time"`
  409. TimeRules []TimeRule `json:"timerules"`
  410. }
  411. // TimeRule 迟到规则时间
  412. type TimeRule struct {
  413. OffWorkAfterTime int64 `json:"offwork_after_time"`
  414. OnWorkFlexTime int64 `json:"onwork_flex_time"`
  415. }
  416. // GetCorpOption 获取企业所有打卡规则
  417. // @see https://developer.work.weixin.qq.com/document/path/93384
  418. func (r *Client) GetCorpOption() (*GetCorpOptionResponse, error) {
  419. var (
  420. accessToken string
  421. err error
  422. )
  423. if accessToken, err = r.GetAccessToken(); err != nil {
  424. return nil, err
  425. }
  426. var response []byte
  427. if response, err = util.HTTPPost(fmt.Sprintf(getCorpOptionURL, accessToken), ""); err != nil {
  428. return nil, err
  429. }
  430. result := &GetCorpOptionResponse{}
  431. err = util.DecodeWithError(response, result, "GetCorpOption")
  432. return result, err
  433. }
  434. // GetOptionRequest 获取员工打卡规则请求
  435. type GetOptionRequest struct {
  436. Datetime int64 `json:"datetime"`
  437. UserIDList []string `json:"useridlist"`
  438. }
  439. // GetOptionResponse 获取员工打卡规则响应
  440. type GetOptionResponse struct {
  441. util.CommonError
  442. Info []OptionInfo `json:"info"`
  443. }
  444. // OptionInfo 打卡规则列表
  445. type OptionInfo struct {
  446. UserID string `json:"userid"`
  447. Group OptionGroup `json:"group"`
  448. }
  449. // OptionGroup 打卡规则相关信息
  450. type OptionGroup struct {
  451. GroupType int64 `json:"grouptype"`
  452. GroupID int64 `json:"groupid"`
  453. GroupName string `json:"groupname"`
  454. CheckinDate []OptionCheckinDate `json:"checkindate"`
  455. SpeWorkdays []SpeWorkdays `json:"spe_workdays"`
  456. SpeOffDays []SpeOffDays `json:"spe_offdays"`
  457. SyncHolidays bool `json:"sync_holidays"`
  458. NeedPhoto bool `json:"need_photo"`
  459. WifiMacInfos []WifiMacInfos `json:"wifimac_infos"`
  460. NoteCanUseLocalPic bool `json:"note_can_use_local_pic"`
  461. AllowCheckinOffWorkday bool `json:"allow_checkin_offworkday"`
  462. AllowApplyOffWorkday bool `json:"allow_apply_offworkday"`
  463. LocInfos []LocInfos `json:"loc_infos"`
  464. ScheduleList []ScheduleList `json:"schedulelist"`
  465. BukaRestriction int64 `json:"buka_restriction"`
  466. }
  467. // OptionCheckinDate 打卡时间配置
  468. type OptionCheckinDate struct {
  469. Workdays []int64 `json:"workdays"`
  470. CheckinTime []GroupCheckinTime `json:"checkintime"`
  471. FlexTime int64 `json:"flex_time"`
  472. NoNeedOffWork bool `json:"noneed_offwork"`
  473. LimitAheadTime int64 `json:"limit_aheadtime"`
  474. FlexOnDutyTime int64 `json:"flex_on_duty_time"`
  475. FlexOffDutyTime int64 `json:"flex_off_duty_time"`
  476. }
  477. // GetOption 获取员工打卡规则
  478. // see https://developer.work.weixin.qq.com/document/path/90263
  479. func (r *Client) GetOption(req *GetOptionRequest) (*GetOptionResponse, error) {
  480. var (
  481. accessToken string
  482. err error
  483. )
  484. if accessToken, err = r.GetAccessToken(); err != nil {
  485. return nil, err
  486. }
  487. var response []byte
  488. if response, err = util.PostJSON(fmt.Sprintf(getOptionURL, accessToken), req); err != nil {
  489. return nil, err
  490. }
  491. result := &GetOptionResponse{}
  492. err = util.DecodeWithError(response, result, "GetOption")
  493. return result, err
  494. }
  495. // GetScheduleListRequest 获取打卡人员排班信息请求
  496. type GetScheduleListRequest struct {
  497. StartTime int64 `json:"starttime"`
  498. EndTime int64 `json:"endtime"`
  499. UserIDList []string `json:"useridlist"`
  500. }
  501. // GetScheduleListResponse 获取打卡人员排班信息响应
  502. type GetScheduleListResponse struct {
  503. util.CommonError
  504. ScheduleList []ScheduleItem `json:"schedule_list"`
  505. }
  506. // ScheduleItem 排班表信息
  507. type ScheduleItem struct {
  508. UserID string `json:"userid"`
  509. YearMonth int64 `json:"yearmonth"`
  510. GroupID int64 `json:"groupid"`
  511. GroupName string `json:"groupname"`
  512. Schedule Schedule `json:"schedule"`
  513. }
  514. // Schedule 个人排班信息
  515. type Schedule struct {
  516. ScheduleList []ScheduleListItem `json:"scheduleList"`
  517. }
  518. // ScheduleListItem 个人排班表信息
  519. type ScheduleListItem struct {
  520. Day int64 `json:"day"`
  521. ScheduleInfo ScheduleInfo `json:"schedule_info"`
  522. }
  523. // ScheduleInfo 个人当日排班信息
  524. type ScheduleInfo struct {
  525. ScheduleID int64 `json:"schedule_id"`
  526. ScheduleName string `json:"schedule_name"`
  527. TimeSection []ScheduleTimeSection `json:"time_section"`
  528. }
  529. // ScheduleTimeSection 班次上下班时段信息
  530. type ScheduleTimeSection struct {
  531. ID int64 `json:"id"`
  532. WorkSec int64 `json:"work_sec"`
  533. OffWorkSec int64 `json:"off_work_sec"`
  534. RemindWorkSec int64 `json:"remind_work_sec"`
  535. RemindOffWorkSec int64 `json:"remind_off_work_sec"`
  536. }
  537. // GetScheduleList 获取打卡人员排班信息
  538. // see https://developer.work.weixin.qq.com/document/path/93380
  539. func (r *Client) GetScheduleList(req *GetScheduleListRequest) (*GetScheduleListResponse, error) {
  540. var (
  541. accessToken string
  542. err error
  543. )
  544. if accessToken, err = r.GetAccessToken(); err != nil {
  545. return nil, err
  546. }
  547. var response []byte
  548. if response, err = util.PostJSON(fmt.Sprintf(getScheduleListURL, accessToken), req); err != nil {
  549. return nil, err
  550. }
  551. result := &GetScheduleListResponse{}
  552. err = util.DecodeWithError(response, result, "GetScheduleList")
  553. return result, err
  554. }
  555. // GetHardwareDataRequest 获取设备打卡数据请求
  556. type GetHardwareDataRequest struct {
  557. FilterType int64 `json:"filter_type"`
  558. StartTime int64 `json:"starttime"`
  559. EndTime int64 `json:"endtime"`
  560. UserIDList []string `json:"useridlist"`
  561. }
  562. // GetHardwareDataResponse 获取设备打卡数据响应
  563. type GetHardwareDataResponse struct {
  564. util.CommonError
  565. CheckinData []HardwareCheckinData `json:"checkindata"`
  566. }
  567. // HardwareCheckinData 设备打卡数据
  568. type HardwareCheckinData struct {
  569. UserID string `json:"userid"`
  570. CheckinTime int64 `json:"checkin_time"`
  571. DeviceSn string `json:"device_sn"`
  572. DeviceName string `json:"device_name"`
  573. }
  574. // GetHardwareData 获取设备打卡数据
  575. // see https://developer.work.weixin.qq.com/document/path/94126
  576. func (r *Client) GetHardwareData(req *GetHardwareDataRequest) (*GetHardwareDataResponse, error) {
  577. var (
  578. accessToken string
  579. err error
  580. )
  581. if accessToken, err = r.GetAccessToken(); err != nil {
  582. return nil, err
  583. }
  584. var response []byte
  585. if response, err = util.PostJSON(fmt.Sprintf(getHardwareDataURL, accessToken), req); err != nil {
  586. return nil, err
  587. }
  588. result := &GetHardwareDataResponse{}
  589. err = util.DecodeWithError(response, result, "GetHardwareData")
  590. return result, err
  591. }