domain.go
1.3 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
package domain
import "fmt"
var (
ErrorNotFound = fmt.Errorf("没有此资源")
)
/***** 1.数据权限 *****/
// DataAuthor 数据验证器
type DataAuthor interface {
DataAuth(options OperateInfo, data AuthedData) error
}
// AuthedData 需要认证的数据
type AuthedData interface {
// 数据所属组织
BelongOrg() int64
}
// 验证参数
type OperateInfo struct {
// 当前操作人
UserId int64
// 当前公司
CompanyId int64
// 当前登录的组织
OrgId int64
// 菜单模块
MenuCode string
}
func NewCheckOptions(optUser, org int64) OperateInfo {
return OperateInfo{
UserId: optUser,
OrgId: org,
}
}
func (info OperateInfo) Valid() bool {
if info.UserId == 0 || info.CompanyId == 0 || info.OrgId == 0 {
return false
}
return true
}
func (info OperateInfo) GetCompanyId(companyId int64) int64 {
if info.CompanyId == 0 {
return companyId
}
return info.CompanyId
}
func (info OperateInfo) GetOrgId(orgId int64) int64 {
if info.OrgId == 0 {
return orgId
}
return info.OrgId
}
func (info OperateInfo) GetUserId(userId int64) int64 {
if info.UserId == 0 {
return userId
}
return info.UserId
}
func (info OperateInfo) String() string {
return fmt.Sprintf("UserId: %v OrgId:%v CompanyId:%v", info.UserId, info.OrgId, info.CompanyId)
}