entity

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2021 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package entity 数据库表定义,与数据库无关的基础数据结构请定义在 types

Index

Constants

View Source
const (
	// StatusInstallFail 添加插件失败
	StatusInstallFail = -1

	// StatusInstallSuccess 添加插件成功
	StatusInstallSuccess = 1
)
View Source
const (
	SourceTypeDefault     = "default"     // 默认插件
	SourceTypeDevelopment = "development" // 开发者插件
)
View Source
const (
	OwnerRoleID = -1 // 拥有者角色的roleID
	Owner       = "拥有者"
)
View Source
const (
	MatchAllCondition = 1 // 全部满足
	MatchAnyCondition = 2 // 任一满足
)
View Source
const (
	AreaIDFieldName = "AreaID"
)
View Source
const (
	UserCredentialFoundType = "user_credential_found"
)

配置类型

Variables

View Source
var Tables []interface{} = []interface{}{
	Device{}, Location{}, Area{}, Role{}, RolePermission{},
	User{}, UserRole{}, Scene{}, SceneCondition{},
	SceneTask{}, TaskLog{}, GlobalSetting{}, PluginInfo{},
}

Functions

func AddDevice

func AddDevice(device *Device, tx *gorm.DB) (err error)

func CheckIllegalRepeatDate

func CheckIllegalRepeatDate(repeatDate string) bool

CheckIllegalRepeatDate 判断生效时间格式是否合法

func CheckSceneExitById

func CheckSceneExitById(sceneId int) (err error)

func CreateLocation

func CreateLocation(location *Location) error

func CreateScene

func CreateScene(scene *Scene) (err error)

func CreateSceneTask

func CreateSceneTask(sceneTask []SceneTask) (err error)

func CreateUser

func CreateUser(user *User, tx *gorm.DB) (err error)

func CreateUserRole

func CreateUserRole(uRoles []UserRole) (err error)

func DelAreaByID

func DelAreaByID(id uint64) (err error)

func DelDeviceByID

func DelDeviceByID(id int) (err error)

func DelDevicesByPlgID

func DelDevicesByPlgID(plgID string) (err error)

func DelLocation

func DelLocation(id int) (err error)

func DelPlugin

func DelPlugin(pluginID string, areaID uint64) (err error)

DelPlugin 删除插件

func DelUser

func DelUser(id int) (err error)

func DelUserRoleByUid

func DelUserRoleByUid(userId int, db *gorm.DB) (err error)

func DeleteRole

func DeleteRole(roleID int) error

func DeleteScene

func DeleteScene(sceneId int) (err error)

func DeviceControlPermit

func DeviceControlPermit(userID, deviceID int) bool

DeviceControlPermit 判断用户是否有设备的任一控制权限

func EditLocationSort

func EditLocationSort(id int, sort int) (err error)

func EditUser

func EditUser(id int, updateUser User) (err error)

func FromArea

func FromArea(areaID uint64) func(db *gorm.DB) *gorm.DB

FromArea 查找家庭对应的数据

func GetAreaCount

func GetAreaCount() (count int64, err error)

func GetDB

func GetDB() *gorm.DB

func GetDBWithAreaScope

func GetDBWithAreaScope(areaID uint64) *gorm.DB

func GetLocationCount

func GetLocationCount(areaID uint64) (count int64, err error)

func GetRoleIdsByUid

func GetRoleIdsByUid(userId int) (roleIds []int, err error)

func GetSetting

func GetSetting(settingType string, setting interface{}, areaID uint64) (err error)

GetSetting 获取全局设置

func GetUIds

func GetUIds(areaID uint64) (ids []int, err error)

func InitRole

func InitRole(db *gorm.DB, areaId uint64) (err error)

func IsAccountNameExist

func IsAccountNameExist(accountName string) bool

func IsAreaOwner

func IsAreaOwner(userID int) bool

IsAreaOwner 是否是area拥有者

func IsDeviceActionPermit

func IsDeviceActionPermit(roleID int, action string) bool

func IsDeviceControlPermit

func IsDeviceControlPermit(userID, deviceID int, attr Attribute) bool

IsDeviceControlPermit 判断用户是否有该设备的某个控制权限

func IsDeviceControlPermitByAttr

func IsDeviceControlPermitByAttr(userID, deviceID, instanceID int, attr string) bool

IsDeviceControlPermitByAttr 判断用户是否有该设备的某个控制权限

func IsDeviceExist

func IsDeviceExist(device *Device, tx *gorm.DB) (err error)

IsDeviceExist 设备是否已存在

func IsLocationExist

func IsLocationExist(areaID uint64, locationID int) bool

func IsPermit

func IsPermit(roleID int, action, target, attribute string) bool

func IsPluginAdd

func IsPluginAdd(pluginID string, areaID uint64) bool

func IsRoleNameExist

func IsRoleNameExist(name string, roleID int, areaID uint64) bool

func IsSceneNameExist

func IsSceneNameExist(name string, sceneId int) (err error)

func JudgePermit

func JudgePermit(userID int, p types.Permission) bool

func LocationNameExist

func LocationNameExist(areaID uint64, name string) bool

func NewTaskLog

func NewTaskLog(target interface{}, taskID string, parentTaskID *string) error

func PluginDeviceAttr

func PluginDeviceAttr(instanceID int, attr string) string

func SavePluginInfo

func SavePluginInfo(pi PluginInfo) (err error)

func SetAreaOwnerID

func SetAreaOwnerID(id uint64, ownerID int, tx *gorm.DB) (err error)

func SwitchAutoScene

func SwitchAutoScene(scene *Scene, isExecute bool) error

SwitchAutoScene 切换自动场景开关

func SwitchAutoSceneByID

func SwitchAutoSceneByID(sceneID int, isExecute bool) error

SwitchAutoSceneByID 切换自动场景开关

func UnBindLocationDevice

func UnBindLocationDevice(deviceID int) (err error)

func UnBindLocationDevices

func UnBindLocationDevices(locationID int) (err error)

func UnScopedDelURoleByUid

func UnScopedDelURoleByUid(userID int) (err error)

func UpdateArea

func UpdateArea(id uint64, name string) (err error)

UpdateArea 修改Area名称后,同时需要修改location中旧名称

func UpdateDevice

func UpdateDevice(id int, updateDevice Device) (err error)

func UpdateLocation

func UpdateLocation(id int, updateLocation Location) (err error)

func UpdateParentLog

func UpdateParentLog(parentTaskID string) error

UpdateParentLog 更新父任务的日志

func UpdatePluginStatus

func UpdatePluginStatus(pluginID string, status int) (err error)

UpdatePluginStatus 更新插件状态

func UpdateSetting

func UpdateSetting(settingType string, setting interface{}, areaID uint64) (err error)

UpdateSetting 添加全局设置

func UpdateTaskLog

func UpdateTaskLog(taskID string, taskErr error) error

UpdateTaskLog 更新任务日志

Types

type ActionType

type ActionType string

type Area

type Area struct {
	ID        uint64    `json:"id" gorm:"type:bigint"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"created_at"`
	OwnerID   int       `json:"owner_id"`
	Deleted   gorm.DeletedAt
}

Area 家庭

func CreateArea

func CreateArea(name string) (area Area, err error)

func GetAreaByID

func GetAreaByID(id uint64) (area Area, err error)

func GetAreaResultById

func GetAreaResultById(id uint64) (area Area, err error)

func GetAreas

func GetAreas() (areas []Area, err error)

func (*Area) AfterDelete

func (d *Area) AfterDelete(tx *gorm.DB) (err error)

func (*Area) BeforeCreate

func (d *Area) BeforeCreate(tx *gorm.DB) (err error)

func (Area) TableName

func (d Area) TableName() string

type Attr

type Attr struct {
	DeviceID   int
	InstanceID int
	Attribute  string
}

type AttrMetadata

type AttrMetadata struct {
	Timestamp int64 `json:"timestamp"`
}

type Attribute

type Attribute struct {
	server.Attribute
	InstanceID int `json:"instance_id"`
}

type ConditionInfo

type ConditionInfo struct {
	SceneCondition
	Timing int64 `json:"timing"`
}

func (ConditionInfo) CheckCondition

func (c ConditionInfo) CheckCondition(userId int) (err error)

CheckCondition 触发条件校验

type ConditionType

type ConditionType int
const (
	ConditionTypeTiming ConditionType = iota + 1
	ConditionTypeDeviceStatus
)

type Device

type Device struct {
	ID           int       `json:"id"`
	Name         string    `json:"name"`
	Address      string    `json:"address"`                                                    // 地址
	Identity     string    `json:"identity" gorm:"uniqueIndex:area_id_mau_model_identity"`     // 设备唯一值
	Model        string    `json:"model" gorm:"uniqueIndex:area_id_mau_model_identity"`        // 型号
	SwVersion    string    `json:"sw_version"`                                                 // 软件版本
	Manufacturer string    `json:"manufacturer" gorm:"uniqueIndex:area_id_mau_model_identity"` // 制造商
	Type         string    `json:"type"`                                                       // 设备类型,如:light,switch...
	PluginID     string    `json:"plugin_id"`
	CreatedAt    time.Time `json:"created_at"`
	LocationID   int       `json:"location_id"`
	Deleted      gorm.DeletedAt

	AreaID uint64 `json:"area_id" gorm:"type:bigint;uniqueIndex:area_id_mau_model_identity"`
	Area   Area   `gorm:"constraint:OnDelete:CASCADE;"`

	Shadow     datatypes.JSON `json:"-"`
	ThingModel datatypes.JSON `json:"-"`
}

Device 识别的设备

func GetDeviceByID

func GetDeviceByID(id int) (device Device, err error)

func GetDeviceByIDWithUnscoped

func GetDeviceByIDWithUnscoped(id int) (device Device, err error)

GetDeviceByIDWithUnscoped 获取设备,包括已删除

func GetDevices

func GetDevices(areaID uint64) (devices []Device, err error)

func GetDevicesByLocationID

func GetDevicesByLocationID(locationId int) (devices []Device, err error)

func GetDevicesByPluginID

func GetDevicesByPluginID(pluginID string) (devices []Device, err error)

func GetManufacturerDevice

func GetManufacturerDevice(areaID uint64, manufacturer, identity string) (device Device, err error)

GetManufacturerDevice 获取厂商的设备

func GetPluginDevice

func GetPluginDevice(areaID uint64, pluginID, identity string) (device Device, err error)

GetPluginDevice 获取插件的设备

func GetSaDevice

func GetSaDevice() (device Device, err error)

func GetZhitingDevices

func GetZhitingDevices() (devices []Device, err error)

GetZhitingDevices 获取所有智汀设备

func (*Device) AfterDelete

func (d *Device) AfterDelete(tx *gorm.DB) (err error)

func (Device) IsBelongsToUserArea

func (d Device) IsBelongsToUserArea(user User) bool

IsBelongsToUserArea 是否属于用户的家庭

func (Device) TableName

func (d Device) TableName() string

type GlobalSetting

type GlobalSetting struct {
	ID      int
	Type    string `gorm:"uniqueIndex:area_id_type"`
	Value   datatypes.JSON
	AreaID  uint64 `gorm:"type:bigint;uniqueIndex:area_id_type"`
	Area    Area   `gorm:"constraint:OnDelete:CASCADE;"`
	Deleted gorm.DeletedAt
}

GlobalSetting SA全局设置

func (GlobalSetting) TableName

func (g GlobalSetting) TableName() string

type Location

type Location struct {
	ID   int    `json:"id"`
	Name string `json:"name" gorm:"uniqueIndex:area_id_name" `
	Sort int    `json:"sort" `

	CreatedAt time.Time `json:"created_at"`

	AreaID uint64 `gorm:"type:bigint;uniqueIndex:area_id_name"`
	Area   Area   `gorm:"constraint:OnDelete:CASCADE;"`

	Deleted gorm.DeletedAt
}

Location 房间

func GetLocationByID

func GetLocationByID(id int) (location Location, err error)

func GetLocations

func GetLocations(areaID uint64) (locations []Location, err error)

func (*Location) BeforeCreate

func (d *Location) BeforeCreate(tx *gorm.DB) (err error)

func (Location) IsBelongsToUserArea

func (d Location) IsBelongsToUserArea(user User) bool

IsBelongsToUserArea 是否属于用户的家庭

func (Location) TableName

func (d Location) TableName() string

type Metadata

type Metadata struct {
	Desired  map[int]map[string]AttrMetadata `json:"desired"`
	Reported map[int]map[string]AttrMetadata `json:"reported"`
}

type OperatorType

type OperatorType string
const (
	OperatorGT OperatorType = ">"
	OperatorLT OperatorType = "<"
	OperatorEQ OperatorType = "="
)

type PluginInfo

type PluginInfo struct {
	ID       int
	AreaID   uint64 `gorm:"uniqueIndex:area_plugin"`
	Area     Area   `gorm:"constraint:OnDelete:CASCADE;"`
	PluginID string `gorm:"uniqueIndex:area_plugin"`
	Info     datatypes.JSON
	Status   int
	Version  string
	Source   string
	Brand    string
}

PluginInfo 开发者插件信息

func GetDevelopPlugins

func GetDevelopPlugins(areaID uint64) (pis []PluginInfo, err error)

GetDevelopPlugins 获取所有开发者插件

func GetPlugin

func GetPlugin(pluginID string, areaID uint64) (plugin PluginInfo, err error)

func (PluginInfo) TableName

func (p PluginInfo) TableName() string

type RepeatType

type RepeatType int
const (
	RepeatTypeAllDay RepeatType = iota + 1
	RepeatTypeWorkDay
	RepeatTypeCustom
)

type Role

type Role struct {
	ID        int
	Name      string
	IsManager bool // 管理员角色不允许修改和删除

	AreaID  uint64 `gorm:"type:bigint;index"`
	Area    Area   `gorm:"constraint:OnDelete:CASCADE;"`
	Deleted gorm.DeletedAt
}

func AddManagerRoleWithDB

func AddManagerRoleWithDB(db *gorm.DB, roleName string, areaID uint64) (Role, error)

func AddRole

func AddRole(roleName string, areaID uint64) (Role, error)

func AddRoleWithDB

func AddRoleWithDB(db *gorm.DB, roleName string, areaID uint64) (Role, error)

func GetManagerRoleWithDB

func GetManagerRoleWithDB(db *gorm.DB) (roleInfo Role, err error)

func GetRoleByID

func GetRoleByID(id int) (role Role, err error)

func GetRoles

func GetRoles(areaID uint64) (roles []Role, err error)

func GetRolesByIds

func GetRolesByIds(roleIds []int) (roles []Role, err error)

func GetRolesByUid

func GetRolesByUid(userId int) (roles []Role, err error)

func UpdateRole

func UpdateRole(roleID int, roleName string) (Role, error)

func (*Role) AddPermissionForRole

func (r *Role) AddPermissionForRole(name, action, target, attr string) error

func (*Role) AddPermissions

func (r *Role) AddPermissions(ps ...types.Permission)

func (*Role) AddPermissionsWithDB

func (r *Role) AddPermissionsWithDB(db *gorm.DB, ps ...types.Permission)

func (*Role) AfterDelete

func (r *Role) AfterDelete(tx *gorm.DB) (err error)

func (*Role) BeforeCreate

func (r *Role) BeforeCreate(tx *gorm.DB) (err error)

func (*Role) BeforeDelete

func (r *Role) BeforeDelete(tx *gorm.DB) (err error)

func (*Role) BeforeUpdate

func (r *Role) BeforeUpdate(tx *gorm.DB) (err error)

func (*Role) DelPermission

func (r *Role) DelPermission(p types.Permission) error

func (Role) IsBelongsToUserArea

func (r Role) IsBelongsToUserArea(user User) bool

IsBelongsToUserArea 是否属于用户的家庭

func (Role) TableName

func (r Role) TableName() string

type RoleInfo

type RoleInfo struct {
	ID   int    `json:"id,omitempty" uri:"id"`
	Name string `json:"name,omitempty"`
}

type RolePermission

type RolePermission struct {
	ID        int
	RoleID    int  `gorm:"index:permission,unique"` // 角色
	Role      Role `gorm:"constraint:OnDelete:CASCADE;"`
	Name      string
	Action    string `gorm:"index:permission,unique"` // 动作
	Target    string `gorm:"index:permission,unique"` // 对象
	Attribute string `gorm:"index:permission,unique"` // 属性
}

RolePermission

func (RolePermission) TableName

func (p RolePermission) TableName() string

type Scene

type Scene struct {
	ID             int    `json:"id"`
	Name           string `json:"name"`
	ConditionLogic int    `json:"condition_logic"` // 1 为 全部满足,2为满足任一

	// 生效时间的配置
	TimePeriodType TimePeriodType `json:"time_period"` // 全天1、时间段2
	EffectStart    time.Time      `json:"-"`
	EffectEnd      time.Time      `json:"-"`

	// 重复执行的配置
	RepeatType RepeatType `json:"repeat_type"` // 每天1,工作日2,自定义3
	RepeatDate string     `json:"repeat_date"` // 自定义的情况下:1234567

	// 设置为手动:false,则不能再设置其他两种
	AutoRun bool `json:"auto_run"` // true 就需要设置scene_condition,false 只需表示手动
	// 场景会自动执行: true
	IsOn bool `json:"is_on"`

	CreatorID       int              `json:"creator_id"`
	CreatedAt       time.Time        `json:"-"`
	SceneConditions []SceneCondition `json:"-" gorm:"constraint:OnDelete:CASCADE;"`
	SceneTasks      []SceneTask      `json:"scene_tasks" gorm:"constraint:OnDelete:CASCADE;"`
	Deleted         gorm.DeletedAt   `json:"-"`

	AreaID uint64 `gorm:"type:bigint;index"`
	Area   Area   `gorm:"constraint:OnDelete:CASCADE;"`
}

Scene 场景

func GetPendingScenesByTime

func GetPendingScenesByTime(t time.Time) (scenes []Scene, err error)

GetPendingScenesByTime 根据时间获取待执行的场景

func GetSceneByIDWithUnscoped

func GetSceneByIDWithUnscoped(id int) (scene Scene, err error)

GetSceneByIDWithUnscoped 获取场景,包括已删除

func GetSceneById

func GetSceneById(id int) (scene Scene, err error)

func GetSceneInfoById

func GetSceneInfoById(id int) (scene Scene, err error)

GetSceneInfoById 获取场景所有信息

func GetScenes

func GetScenes(areaID uint64) (scenes []Scene, err error)

func GetScenesByCondition

func GetScenesByCondition(deviceID int, attr Attribute) (scenes []Scene, err error)

GetScenesByCondition 根据条件获取场景

func (*Scene) BeforeSave

func (s *Scene) BeforeSave(tx *gorm.DB) (err error)

func (Scene) CheckConditionLogic

func (s Scene) CheckConditionLogic() bool

CheckConditionLogic 校验满足条件

func (Scene) CheckPeriodType

func (s Scene) CheckPeriodType() (err error)

CheckPeriodType 生效时间类型校验

func (Scene) CheckRepeatConfig

func (s Scene) CheckRepeatConfig() (err error)

CheckRepeatConfig 校验重复执行的配置

func (Scene) CheckSceneNameLength

func (s Scene) CheckSceneNameLength() (err error)

func (Scene) IsMatchAllCondition

func (s Scene) IsMatchAllCondition() bool

func (Scene) TableName

func (s Scene) TableName() string

type SceneCondition

type SceneCondition struct {
	ID            int           `json:"id"`
	SceneID       int           `json:"scene_id"`
	ConditionType ConditionType `json:"condition_type"`
	TimingAt      time.Time     `json:"-"` // 定时在某个时间

	// 设备有关配置
	DeviceID      int            `json:"device_id"`      // 或某个设备状态变化时
	Operator      OperatorType   `json:"operator"`       // 操作符,大于、小于、等于
	ConditionAttr datatypes.JSON `json:"condition_attr"` // refer to Attribute
}

SceneCondition 场景条件

func GetConditions

func GetConditions(deviceID int, attr Attribute) (conds []SceneCondition, err error)

GetConditions 获取符合设备属性的条件

func GetConditionsBySceneID

func GetConditionsBySceneID(sceneID int) (conditions []SceneCondition, err error)

func (SceneCondition) CheckConditionItem

func (d SceneCondition) CheckConditionItem(userId, deviceId int) (err error)

CheckConditionItem 触发条件为设备状态变化时,校验对应参数

func (SceneCondition) TableName

func (d SceneCondition) TableName() string

type SceneTask

type SceneTask struct {
	ID             int      `json:"id"`
	SceneID        int      `json:"scene_id"`
	ControlSceneID int      `json:"control_scene_id"` // ControlSceneID 控制场景id
	DelaySeconds   int      `json:"delay_seconds"`    // 延迟的秒数
	Type           TaskType `json:"type"`             // 任务目标:智能设备device或者是场景scene

	DeviceID   int            `json:"device_id"`
	Attributes datatypes.JSON `json:"attributes"` // refer to Attribute
}

SceneTask 场景任务

func GetSceneTasksBySceneID

func GetSceneTasksBySceneID(sceneID int) (sceneTasks []SceneTask, err error)

func (SceneTask) CheckTaskDevice

func (task SceneTask) CheckTaskDevice(userId int) (err error)

checkTaskDevice 校验设备任务类型

func (SceneTask) CheckTaskType

func (task SceneTask) CheckTaskType() (err error)

checkTaskType 执行任务类型校验

func (SceneTask) TableName

func (d SceneTask) TableName() string

type Shadow

type Shadow struct {
	State     State    `json:"state"`
	Metadata  Metadata `json:"metadata"`
	Timestamp int      `json:"timestamp"`
	Version   int      `json:"version"`
}

Shadow shadow of device

func NewShadow

func NewShadow() Shadow

func (Shadow) Get

func (s Shadow) Get(instanceID int, attribute string) (val interface{}, err error)

func (*Shadow) UpdateReported

func (s *Shadow) UpdateReported(instanceID int, attr server.Attribute)

type State

type State struct {
	// Desired 期望值
	Desired map[int]map[string]interface{} `json:"desired"`
	// Reported 报告值
	Reported map[int]map[string]interface{} `json:"reported"`
}

type TaskLog

type TaskLog struct {
	ID   int
	Name string   // 设备名称/场景名称
	Type TaskType // 任务类型

	Finish bool           // 是否完成
	Result TaskResultType // 执行结果
	Error  string

	DeviceLocation string // 设备区域

	TaskID        string    `gorm:"unique"` // 任务ID
	ParentTaskID  *string   // 父任务id
	ChildTaskLogs []TaskLog `gorm:"foreignkey:parent_task_id;references:task_id"` // 子任务日志

	FinishedAt time.Time
	CreatedAt  time.Time

	AreaID  uint64 `gorm:"type:bigint;index"`
	Area    Area   `gorm:"constraint:OnDelete:CASCADE;"`
	Deleted gorm.DeletedAt
}

TaskLog 任务日志

func (TaskLog) TableName

func (tl TaskLog) TableName() string

type TaskResultType

type TaskResultType int

TaskResultType 任务执行结果

const (
	TaskSuccess TaskResultType = iota + 1
	TaskPartSuccess
	TaskFail
	TaskTimeout
	TaskDeviceAlreadyDeleted
	TaskDeviceDisConnect
	TaskSceneAlreadyDeleted
)

type TaskType

type TaskType int
const (
	TaskTypeSmartDevice TaskType = iota + 1
	TaskTypeManualRun
	TaskTypeEnableAutoRun
	TaskTypeDisableAutoRun
)

type TimePeriodType

type TimePeriodType int
const (
	TimePeriodTypeAllDay TimePeriodType = iota + 1
	TimePeriodTypeCustom
)

type User

type User struct {
	ID          int       `json:"id"`
	AccountName string    `json:"account_name"`
	Nickname    string    `json:"nickname"`
	Phone       string    `json:"phone"`
	Password    string    `json:"password"`
	Salt        string    `json:"salt"`
	Token       string    `json:"token" gorm:"uniqueIndex"`
	CreatedAt   time.Time `json:"created_at"`

	AreaID  uint64 `gorm:"type:bigint;index"`
	Area    Area   `gorm:"constraint:OnDelete:CASCADE;"`
	Deleted gorm.DeletedAt
}

func GetAreaUsers

func GetAreaUsers(areaID uint64) (users []User, err error)

func GetUserByAccountName

func GetUserByAccountName(accountName string) (userInfo User, err error)

func GetUserByID

func GetUserByID(id int) (user User, err error)

func GetUserByToken

func GetUserByToken(token string) (user User, err error)

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

func (User) BeforeDelete

func (u User) BeforeDelete(tx *gorm.DB) (err error)

func (User) BelongsToArea

func (u User) BelongsToArea(areaID uint64) bool

func (User) TableName

func (u User) TableName() string

type UserCredentialFoundSetting

type UserCredentialFoundSetting struct {
	UserCredentialFound bool `json:"user_credential_found"`
}

用户凭证配置

func GetDefaultUserCredentialFoundSetting

func GetDefaultUserCredentialFoundSetting() UserCredentialFoundSetting

GetDefaultUserCredentialFoundSetting 获取找回用户凭证默认配置

type UserInfo

type UserInfo struct {
	UserId        int        `json:"user_id"`
	RoleInfos     []RoleInfo `json:"role_infos"`
	AccountName   string     `json:"account_name"`
	Nickname      string     `json:"nickname"`
	Token         string     `json:"token"`
	Phone         string     `json:"phone"`
	IsSetPassword bool       `json:"is_set_password"`
}

type UserPermissions

type UserPermissions struct {
	// contains filtered or unexported fields
}

func GetUserPermissions

func GetUserPermissions(userID int) (up UserPermissions, err error)

GetUserPermissions 获取用户的所有权限

func (UserPermissions) IsDeviceAttrPermit

func (up UserPermissions) IsDeviceAttrPermit(deviceID int, attr Attribute) bool

func (UserPermissions) IsDeviceControlPermit

func (up UserPermissions) IsDeviceControlPermit(deviceID, instanceID int, attr string) bool

type UserRole

type UserRole struct {
	ID     int
	UserID int  `gorm:"uniqueIndex:uid_rid"`
	User   User `gorm:"constraint:OnDelete:CASCADE;"`
	RoleID int  `gorm:"uniqueIndex:uid_rid"`
	Role   Role `gorm:"constraint:OnDelete:CASCADE;"`
}

func (UserRole) TableName

func (ur UserRole) TableName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL