permission.go 1.3 KB
package domain

// 权限
type Permission struct {
	// 权限id
	PermissionId int `json:"permissionId"`
	// 公司名称
	Name string `json:"name"`
	// 权限编码
	Code string `json:"code"`
	// 父级id
	ParentId int `json:"parentId"`
	// 排序
	Sort int `json:"sort"`
	// 图标
	Icon string `json:"icon"`
}

type PermissionRepository interface {
	Save(permission *Permission) (*Permission, error)
	Remove(permission *Permission) (*Permission, error)
	FindOne(queryOptions map[string]interface{}) (*Permission, error)
	Find(queryOptions map[string]interface{}) (int64, []*Permission, error)
}

func (permission *Permission) Identify() interface{} {
	if permission.PermissionId == 0 {
		return nil
	}
	return permission.PermissionId
}

func (permission *Permission) Update(data map[string]interface{}) error {
	if permissionId, ok := data["permissionId"]; ok {
		permission.PermissionId = permissionId.(int)
	}
	if name, ok := data["name"]; ok {
		permission.Name = name.(string)
	}
	if code, ok := data["code"]; ok {
		permission.Code = code.(string)
	}
	if parentId, ok := data["parentId"]; ok {
		permission.ParentId = parentId.(int)
	}
	if sort, ok := data["sort"]; ok {
		permission.Sort = sort.(int)
	}
	if icon, ok := data["icon"]; ok {
		permission.Icon = icon.(string)
	}
	return nil
}