-
Notifications
You must be signed in to change notification settings - Fork 0
/
onjobquery.go
82 lines (70 loc) · 2.35 KB
/
onjobquery.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/1/31 0031
* Time: 22:33
*/
package employee
import (
"strconv"
"strings"
"github.com/a07061625/gompf/mpf"
"github.com/a07061625/gompf/mpf/api/dingtalk"
"github.com/a07061625/gompf/mpf/mpconstant/errorcode"
"github.com/a07061625/gompf/mpf/mpconstant/project"
"github.com/a07061625/gompf/mpf/mperr"
"github.com/valyala/fasthttp"
)
// 查询企业在职员工列表
type onJobQuery struct {
dingtalk.BaseCorp
corpId string
agentTag string
atType string
statusList []string // 状态列表
}
func (ojq *onJobQuery) SetStatusList(statusList []int) {
if len(statusList) == 0 {
panic(mperr.NewDingTalkCorp(errorcode.DingTalkCorpParam, "状态列表不能为空", nil))
}
ojq.statusList = make([]string, 0)
for _, v := range statusList {
ojq.statusList = append(ojq.statusList, strconv.Itoa(v))
}
}
func (ojq *onJobQuery) SetOffset(offset int) {
if offset >= 0 {
ojq.ExtendData["offset"] = offset
} else {
panic(mperr.NewDingTalkCorp(errorcode.DingTalkCorpParam, "偏移量不合法", nil))
}
}
func (ojq *onJobQuery) SetSize(size int) {
if (size > 0) && (size <= 20) {
ojq.ExtendData["size"] = size
} else {
panic(mperr.NewDingTalkCorp(errorcode.DingTalkCorpParam, "分页大小不合法", nil))
}
}
func (ojq *onJobQuery) CheckData() (*fasthttp.Client, *fasthttp.Request) {
if len(ojq.statusList) == 0 {
panic(mperr.NewDingTalkCorp(errorcode.DingTalkCorpParam, "状态列表不能为空", nil))
}
ojq.ExtendData["status_list"] = strings.Join(ojq.statusList, ",")
ojq.ReqURI = dingtalk.UrlService + "/topapi/smartwork/hrm/employee/queryonjob?access_token=" + dingtalk.NewUtil().GetAccessToken(ojq.corpId, ojq.agentTag, ojq.atType)
reqBody := mpf.JSONMarshal(ojq.ExtendData)
client, req := ojq.GetRequest()
req.SetBody([]byte(reqBody))
return client, req
}
func NewOnJobQuery(corpId, agentTag, atType string) *onJobQuery {
ojq := &onJobQuery{dingtalk.NewCorp(), "", "", "", make([]string, 0)}
ojq.corpId = corpId
ojq.agentTag = agentTag
ojq.atType = atType
ojq.ExtendData["offset"] = 0
ojq.ExtendData["size"] = 10
ojq.ReqContentType = project.HTTPContentTypeJSON
ojq.ReqMethod = fasthttp.MethodPost
return ojq
}