entity

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

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

Index

Constants

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

	StatusInstalling = 0

	// 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{}, Client{},
}

Functions

func AddDevice

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

func AddSADevice added in v1.5.0

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

AddSADevice 添加SA设备

func CheckDeviceExist added in v1.5.0

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

CheckDeviceExist 设备是否已存在

func CheckIllegalRepeatDate

func CheckIllegalRepeatDate(repeatDate string) bool

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

func CheckSceneExitById

func CheckSceneExitById(sceneId int) (err error)

func CreateHistory added in v1.5.0

func CreateHistory(areaID uint64, deviceID, userID int, context []byte) (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 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 GetDBWithAreaScopeTx added in v1.5.0

func GetDBWithAreaScopeTx(tx *gorm.DB, areaID uint64) *gorm.DB

func GetDefaultScope added in v1.5.0

func GetDefaultScope() (scope string)

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 InitClient added in v1.5.0

func InitClient() (err error)

InitClient 初始化Client

func InitRole

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

func IsAccountNameExist

func IsAccountNameExist(accountName string) bool

func IsDeviceActionPermit

func IsDeviceActionPermit(roleID int, action string, tx *gorm.DB) 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 IsLocationExist

func IsLocationExist(areaID uint64, locationID int) bool

func IsOwner added in v1.5.0

func IsOwner(userID int) bool

IsOwner 是否是area拥有者

func IsOwnerOfArea added in v1.5.0

func IsOwnerOfArea(userID int, areaID uint64) bool

IsOwnerOfArea 是否是area拥有者

func IsPermit

func IsPermit(roleID int, action, target, attribute string, tx *gorm.DB) bool

func IsPluginAdd

func IsPluginAdd(pluginID string, areaID uint64) bool

func IsPluginDevelop added in v1.5.0

func IsPluginDevelop(pluginID string, areaID uint64) bool

IsPluginDevelop 是否是开发插件

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 OpenSqlite added in v1.5.0

func OpenSqlite(path string, enableForeign bool) (*gorm.DB, 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 UpdatePluginInfo added in v1.5.0

func UpdatePluginInfo(pluginID string, pluginInfo PluginInfo) (err error)

UpdatePluginInfo 更新插件

func UpdateSetting

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

UpdateSetting 添加全局设置

func UpdateTaskLog

func UpdateTaskLog(taskID string, taskErr error) error

UpdateTaskLog 更新任务日志

func UserRolePermissionsScope added in v1.5.0

func UserRolePermissionsScope(userID int) func(db *gorm.DB) *gorm.DB

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 Client added in v1.5.0

type Client struct {
	ID           int
	Name         string `gorm:"UniqueIndex"`
	ClientID     string `gorm:"UniqueIndex"`
	ClientSecret string `gorm:"UniqueIndex"`
	GrantType    string
	AllowScope   string // 允许客户端申请的权限
}

func CreateClient added in v1.5.0

func CreateClient(grantType, allowScope, name string) (client Client, err error)

CreateClient 创建应用

func GetClientByClientID added in v1.5.0

func GetClientByClientID(clientID string) (client Client, err error)

GetClientByClientID 根据ClientID获取Client信息

func GetSAClient added in v1.5.0

func GetSAClient() (client Client, err error)

GetSAClient 获取SAClient

func GetSCClient added in v1.5.0

func GetSCClient() (client Client, err error)

GetSCClient 获取SCClient

func (*Client) BeforeCreate added in v1.5.0

func (c *Client) BeforeCreate(tx *gorm.DB) error

func (Client) TableName added in v1.5.0

func (c Client) TableName() string

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_identity_plugin_id"` // 设备唯一值
	Model        string    `json:"model"`                                                  // 型号
	Manufacturer string    `json:"manufacturer"`                                           // 制造商
	Type         string    `json:"type"`                                                   // 设备类型,如:light,switch...
	PluginID     string    `json:"plugin_id" gorm:"uniqueIndex:area_id_identity_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_identity_plugin_id"`
	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 GetDeviceByIdentity added in v1.5.0

func GetDeviceByIdentity(identity string) (*Device, error)

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) TableName

func (d Device) TableName() string

type DeviceStatusHistory added in v1.5.0

type DeviceStatusHistory struct {
	ID       int            `json:"id"`
	DeviceID int            `json:"device_id" gorm:"uniqueIndex:area_id_mau_device"`
	Context  datatypes.JSON `json:"context"`
	UserID   int            `json:"user_id"`
	AreaID   uint64         `json:"area_id" gorm:"type:bigint;uniqueIndex:area_id_mau_device"`
	CreateAt time.Time      `json:"create_at"`
}

func GetDeviceHistoryByCondition added in v1.5.0

func GetDeviceHistoryByCondition(deviceID int, areaID uint64) (histories []DeviceStatusHistory, err error)

func (DeviceStatusHistory) TableName added in v1.5.0

func (d DeviceStatusHistory) 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"`
	Image     string
	Info      string
	ConfigMsg datatypes.JSON
	Status    int
	Version   string
	Source    string
	Brand     string
	ErrorInfo string
}

PluginInfo 开发者插件信息

func GetDevelopPlugins

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

GetDevelopPlugins 获取所有开发插件

func GetInstalledPlugins added in v1.5.0

func GetInstalledPlugins() (pis []PluginInfo, err error)

GetInstalledPlugins 获取所有已安装插件

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 GetRolesWithTx added in v1.5.0

func GetRolesWithTx(tx *gorm.DB, areaID uint64) (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"`
	Key         string    `json:"key" gorm:"uniqueIndex"`
	CreatedAt   time.Time `json:"created_at"`

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

func GetAreaOwner added in v1.5.0

func GetAreaOwner(areaID uint64) (user User, err error)

GetAreaOwner 获取家庭的拥有者

func GetUserByAccountName

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

func GetUserByID

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

func GetUserByIDAndAreaID added in v1.5.0

func GetUserByIDAndAreaID(uID int, areaID uint64) (user User, err error)

func GetUserByToken

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

func GetUsers added in v1.5.0

func GetUsers(areaID uint64) (users []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,omitempty"`
	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) IsDeviceAttrControlPermit added in v1.5.0

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

func (UserPermissions) IsDeviceAttrPermit

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

func (UserPermissions) IsDeviceControlPermit

func (up UserPermissions) IsDeviceControlPermit(deviceID int) bool

func (UserPermissions) IsOwner added in v1.5.0

func (up UserPermissions) IsOwner() bool

func (UserPermissions) IsPermit added in v1.5.0

func (up UserPermissions) IsPermit(tp types.Permission) 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 GetUserRoles added in v1.5.0

func GetUserRoles(areaID uint64) (userRoles []UserRole, err error)

GetUserRoles 获取家庭下所有用户的角色

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