domain.go 1.3 KB
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 companyId != 0 {
		return companyId
	}
	return info.CompanyId
}

func (info OperateInfo) GetOrgId(orgId int64) int64 {
	if orgId != 0 {
		return orgId
	}
	return info.OrgId
}

func (info OperateInfo) GetUserId(userId int64) int64 {
	if 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)
}