login_access.go
2.4 KB
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
83
84
package domain
import "time"
//登录的平台
const (
LoginPlatformApp string = "app"
LoginPlatformWeb string = "web"
)
// 登录凭证存储
type LoginAccess struct {
LoginAccessId int64 `json:"loginAccessId"`
UserBaseId int64 `json:"userBaseId"`
UserId int64 `json:"userId"`
// 账号
Account string `json:"account"`
// 对应平台
Platform string `json:"platform"`
// 公司id
CompanyId int64 `json:"companyId"`
// 组织id
OrganizationId int64 `json:"organizationId"`
// 登录凭证存储
AccessToken string `json:"accessToken"`
// 刷新登录凭证
RefreshToken string `json:"refreshToken"`
// 登录凭证到期时间,时间戳精度秒
AccessExpired int64 `json:"accessExpired"`
// 刷新登录凭证到期时间,时间戳精度秒
RefreshExpired int64 `json:"refreshExpired"`
// 创建时间
CreatedTime time.Time `json:"createdTime"`
// 更新时间
UpdatedTime time.Time `json:"updatedTime"`
}
type LoginAccessRepository interface {
Save(loginAccess *LoginAccess) (*LoginAccess, error)
Remove(loginAccess *LoginAccess) (*LoginAccess, error)
FindOne(queryOptions map[string]interface{}) (*LoginAccess, error)
Find(queryOptions map[string]interface{}) (int64, []*LoginAccess, error)
}
func (loginAccess *LoginAccess) Identify() interface{} {
if loginAccess.LoginAccessId == 0 {
return nil
}
return loginAccess.LoginAccessId
}
func (loginAccess *LoginAccess) Update(data map[string]interface{}) error {
if account, ok := data["account"]; ok {
loginAccess.Account = account.(string)
}
if platform, ok := data["platform"]; ok {
loginAccess.Platform = platform.(string)
}
if companyId, ok := data["companyId"]; ok {
loginAccess.CompanyId = companyId.(int64)
}
if organizationId, ok := data["organizationId"]; ok {
loginAccess.OrganizationId = organizationId.(int64)
}
if accessToken, ok := data["accessToken"]; ok {
loginAccess.AccessToken = accessToken.(string)
}
if refreshToken, ok := data["refreshToken"]; ok {
loginAccess.RefreshToken = refreshToken.(string)
}
if accessExpired, ok := data["accessExpired"]; ok {
loginAccess.AccessExpired = accessExpired.(int64)
}
if refreshExpired, ok := data["refreshExpired"]; ok {
loginAccess.RefreshExpired = refreshExpired.(int64)
}
if createdTime, ok := data["createdTime"]; ok {
loginAccess.CreatedTime = createdTime.(time.Time)
}
if updatedTime, ok := data["updatedTime"]; ok {
loginAccess.UpdatedTime = updatedTime.(time.Time)
}
return nil
}