-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.go
53 lines (47 loc) · 1.26 KB
/
User.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
package feishu
import (
"github.com/ncuhome/GeniusAuthoritarian/internal/db/dao"
"github.com/ncuhome/GeniusAuthoritarian/pkg/feishuApi"
)
func NewUser(data *feishuApi.User) *User {
return &User{
Data: data,
}
}
type User struct {
ID uint // 辅助字段,初始为空
Data *feishuApi.User
}
// Model 注意需要同时修改下方的 IsModelEmpty
func (u User) Model() dao.User {
return dao.User{
Name: u.Data.Name,
Phone: u.Data.Mobile,
AvatarUrl: u.Data.Avatar.AvatarOrigin,
}
}
func (u User) IsModelEmpty() bool {
return u.Data.Name == "" &&
u.Data.Mobile == "" &&
u.Data.Avatar.AvatarOrigin == ""
}
func (u User) IsInvalid() bool {
return !u.Data.Status.IsActivated || u.Data.Status.IsFrozen || u.Data.Status.IsResigned || u.Data.Mobile == "" || // 账号未异常
u.Data.EmployeeType != 1 // 仅允许正式员工状态账号
}
func (u User) Departments(groupMap map[string]uint) UserDepartment {
var departments = make([]uint, len(u.Data.DepartmentIds))
var validLength int
for _, groupOpenID := range u.Data.DepartmentIds {
id, ok := groupMap[groupOpenID]
if !ok {
continue
}
departments[validLength] = id
validLength++
}
return UserDepartment{
GidList: departments[:validLength],
OpenIdList: u.Data.DepartmentIds,
}
}