-
Notifications
You must be signed in to change notification settings - Fork 0
/
dimissionlist.go
69 lines (59 loc) · 2.03 KB
/
dimissionlist.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
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/1/31 0031
* Time: 23:33
*/
package employee
import (
"regexp"
"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 dimissionList struct {
dingtalk.BaseCorp
corpId string
agentTag string
atType string
userList []string // 员工列表
}
func (dl *dimissionList) SetUserList(userList []string) {
if len(userList) == 0 {
panic(mperr.NewDingTalkCorp(errorcode.DingTalkCorpParam, "员工列表不能为空", nil))
} else if len(userList) > 50 {
panic(mperr.NewDingTalkCorp(errorcode.DingTalkCorpParam, "员工不能超过50个", nil))
}
dl.userList = make([]string, 0)
for _, v := range userList {
match, _ := regexp.MatchString(project.RegexDigitAlpha, v)
if match {
dl.userList = append(dl.userList, v)
}
}
}
func (dl *dimissionList) CheckData() (*fasthttp.Client, *fasthttp.Request) {
if len(dl.userList) == 0 {
panic(mperr.NewDingTalkCorp(errorcode.DingTalkCorpParam, "员工列表不能为空", nil))
}
dl.ExtendData["userid_list"] = strings.Join(dl.userList, ",")
dl.ReqURI = dingtalk.UrlService + "/topapi/smartwork/hrm/employee/listdimission?access_token=" + dingtalk.NewUtil().GetAccessToken(dl.corpId, dl.agentTag, dl.atType)
reqBody := mpf.JSONMarshal(dl.ExtendData)
dlient, req := dl.GetRequest()
req.SetBody([]byte(reqBody))
return dlient, req
}
func NewDimissionList(corpId, agentTag, atType string) *dimissionList {
dl := &dimissionList{dingtalk.NewCorp(), "", "", "", make([]string, 0)}
dl.corpId = corpId
dl.agentTag = agentTag
dl.atType = atType
dl.ReqContentType = project.HTTPContentTypeJSON
dl.ReqMethod = fasthttp.MethodPost
return dl
}