Documentation ¶
Overview ¶
Package entity 数据库表定义,与数据库无关的基础数据结构请定义在 types
Index ¶
- Constants
- Variables
- func AddDevice(d *Device, tx *gorm.DB) (err error)
- func AddSADevice(device *Device, tx *gorm.DB) (err error)
- func BatchAddChildDevice(childDevices []*Device, tx *gorm.DB) error
- func CheckIllegalRepeatDate(repeatDate string) bool
- func CheckSAExist(device Device, tx *gorm.DB) (err error)
- func CheckSceneExitById(sceneId int) (err error)
- func CopyTable(src *gorm.DB, dst *gorm.DB, table interface{}, delete bool) (err error)
- func CreateDepartment(department *Department) error
- func CreateDepartmentUser(departmentUsers []DepartmentUser) (err error)
- func CreateHistory(areaID uint64, deviceID, userID int, context []byte) (err error)
- func CreateLocation(location *Location) error
- func CreateScene(scene *Scene) (err error)
- func CreateSceneTask(sceneTask []SceneTask) (err error)
- func CreateUser(user *User, tx *gorm.DB) (err error)
- func CreateUserRole(uRoles []UserRole) (err error)
- func DelAreaByID(id uint64) (err error)
- func DelDepartment(id int) (err error)
- func DelDepartmentUserByDepID(departmentID int, db *gorm.DB) (err error)
- func DelDepartmentUserByUId(userID int, db *gorm.DB) (err error)
- func DelDeviceByID(id int) (err error)
- func DelDeviceByPID(pid int, tx *gorm.DB) error
- func DelDevicesByPlgID(plgID string) (err error)
- func DelLocation(id int) (err error)
- func DelPlugin(pluginID string, areaID uint64) (err error)
- func DelUser(id int) (err error)
- func DelUserRoleByUid(userId int, db *gorm.DB) (err error)
- func DeleteRole(roleID int) error
- func DeleteScene(sceneId int) (err error)
- func DepartmentNameExist(areaID uint64, name string) bool
- func EditLocationSort(id int, sort int) (err error)
- func EditUser(id int, updateUser User) (err error)
- func FromArea(areaID uint64) func(db *gorm.DB) *gorm.DB
- func GetAreaCount() (count int64, err error)
- func GetDB() *gorm.DB
- func GetDBWithAreaScope(areaID uint64) *gorm.DB
- func GetDBWithAreaScopeTx(tx *gorm.DB, areaID uint64) *gorm.DB
- func GetDefaultScope() (scope string)
- func GetDepartmentCount(areaID uint64) (count int64, err error)
- func GetDepartmentCountByIds(departmentIds []int) (count int64, err error)
- func GetLocationCount(areaID uint64) (count int64, err error)
- func GetRoleIdsByUid(userId int) (roleIds []int, err error)
- func GetSetting(settingType string, setting interface{}, areaID uint64) (err error)
- func GetUIds(areaID uint64) (ids []int, err error)
- func InitClient() (err error)
- func InitRole(db *gorm.DB, areaId uint64) (err error)
- func IsAccountNameExist(accountName string) bool
- func IsAreaType(areaType AreaType) bool
- func IsCompany(areaType AreaType) bool
- func IsDepartmentExist(areaID uint64, departmentID int) bool
- func IsDepartmentManager(areaID uint64, departmentID, userID int) (isManager bool, err error)
- func IsDeviceActionPermit(roleID int, action string, tx *gorm.DB) bool
- func IsDeviceControlPermit(userID, deviceID int, attr Attribute) bool
- func IsDeviceControlPermitByAttr(userID, deviceID, instanceID int, attr string) bool
- func IsHome(areaType AreaType) bool
- func IsLocationExist(areaID uint64, locationID int) bool
- func IsMeiHuiZhiJuBrand(pluginID string) bool
- func IsOwner(userID int) bool
- func IsOwnerOfArea(userID int, areaID uint64) bool
- func IsPermit(roleID int, action, target, attribute string, tx *gorm.DB) bool
- func IsPluginAdd(pluginID string, areaID uint64) bool
- func IsPluginDevelop(pluginID string, areaID uint64) bool
- func IsRoleNameExist(name string, roleID int, areaID uint64) bool
- func IsSceneNameExist(name string, sceneId int, areaId uint64) (err error)
- func JudgePermit(userID int, p types.Permission) bool
- func LocationNameExist(areaID uint64, name string) bool
- func NewTaskLog(target interface{}, taskID string, parentTaskID *string) error
- func Open(dsn string) gorm.Dialector
- func OpenSqlite(path string, enableForeign bool) (*gorm.DB, error)
- func PluginDeviceAttr(instanceID int, attr string) string
- func ResetDepartmentManager(areaID uint64, departmentID ...int) (err error)
- func SavePluginInfo(pi PluginInfo) (err error)
- func SetAreaOwnerID(id uint64, ownerID int, tx *gorm.DB) (err error)
- func SwitchAutoScene(scene *Scene, isExecute bool) error
- func SwitchAutoSceneByID(sceneID int, isExecute bool) error
- func UnBindDepartmentDevice(deviceID int) (err error)
- func UnBindDepartmentDevices(departmentID int, tx *gorm.DB) (err error)
- func UnBindLocationDevice(deviceID int) (err error)
- func UnBindLocationDevices(locationID int) (err error)
- func UnScopedDelDepartmentUsers(departmentID int) (err error)
- func UnScopedDelURoleByUid(userID int) (err error)
- func UnScopedDelUserDepartments(userID int) (err error)
- func UnbindDepartmentManager(managerID int, areaID uint64, tx *gorm.DB) (err error)
- func UpdateArea(id uint64, updates map[string]interface{}) (err error)
- func UpdateDepartment(id int, updateDepartment Department) (err error)
- func UpdateDepartmentSort(id int, sort int) (err error)
- func UpdateDevice(id int, updateDevice Device) (err error)
- func UpdateDeviceById(id int, values interface{}, tx *gorm.DB) error
- func UpdateLocation(id int, updateLocation Location) (err error)
- func UpdateParentLog(parentTaskID string) error
- func UpdatePluginInfo(pluginID string, pluginInfo PluginInfo) (err error)
- func UpdateSceneByIDWithTx(sceneID int, update *Scene, tx *gorm.DB) (err error)
- func UpdateSetting(settingType string, setting interface{}, areaID uint64) (err error)
- func UpdateTaskLog(taskID string, taskErr error) error
- func UserRolePermissionsScope(userID int) func(db *gorm.DB) *gorm.DB
- type ActionType
- type Area
- type AreaType
- type Attr
- type AttrMetadata
- type Attribute
- type Client
- type ConditionInfo
- type ConditionType
- type Department
- func GetAllDepartments(parentDepartment []Department) (allDepartment []Department)
- func GetDepartmentByID(id int) (department Department, err error)
- func GetDepartments(areaID uint64) (departments []Department, err error)
- func GetManagerDepartments(areaID uint64, managerID int) (departments []Department, err error)
- func GetUserDepartments(userID int) (departments []Department, err error)
- type DepartmentInfo
- type DepartmentUser
- type Device
- func GetDeviceByID(id int) (device Device, err error)
- func GetDeviceByIDWithUnscoped(id int) (device Device, err error)
- func GetDeviceByIdentity(identity string) (*Device, error)
- func GetDevices(areaID uint64) (devices []Device, err error)
- func GetDevicesByDepartmentID(departmentId int) (devices []Device, err error)
- func GetDevicesByLocationID(locationId int) (devices []Device, err error)
- func GetDevicesByPluginID(pluginID string) (devices []Device, err error)
- func GetManufacturerDevice(areaID uint64, manufacturer, identity string) (device Device, err error)
- func GetPluginDevice(areaID uint64, pluginID, identity string) (device Device, err error)
- func GetSaDevice() (device Device, err error)
- func GetZhitingDevices() (devices []Device, err error)
- type DeviceStatusHistory
- type Dialector
- type GetCloudDiskCredentialSetting
- type GlobalSetting
- type Location
- type LogSwitchSetting
- type Metadata
- type Migrator
- type OperatorType
- type PluginInfo
- type RepeatType
- type Role
- func AddManagerRoleWithDB(db *gorm.DB, roleName string, areaID uint64) (Role, error)
- func AddRole(roleName string, areaID uint64) (Role, error)
- func AddRoleWithDB(db *gorm.DB, roleName string, areaID uint64) (Role, error)
- func GetManagerRoleWithDB(db *gorm.DB) (roleInfo Role, err error)
- func GetRoleByID(id int) (role Role, err error)
- func GetRoles(areaID uint64) (roles []Role, err error)
- func GetRolesByIds(roleIds []int) (roles []Role, err error)
- func GetRolesByUid(userId int) (roles []Role, err error)
- func GetRolesWithTx(tx *gorm.DB, areaID uint64) (roles []Role, err error)
- func UpdateRole(roleID int, roleName string) (Role, error)
- func (r *Role) AddPermissionForRole(name, action, target, attr string) error
- func (r *Role) AddPermissions(ps ...types.Permission)
- func (r *Role) AddPermissionsWithDB(db *gorm.DB, ps ...types.Permission)
- func (r *Role) AfterDelete(tx *gorm.DB) (err error)
- func (r *Role) BeforeCreate(tx *gorm.DB) (err error)
- func (r *Role) BeforeDelete(tx *gorm.DB) (err error)
- func (r *Role) BeforeUpdate(tx *gorm.DB) (err error)
- func (r *Role) DelPermission(p types.Permission) error
- func (r Role) IsBelongsToUserArea(user User) bool
- func (r Role) TableName() string
- type RoleInfo
- type RolePermission
- type Scene
- func GetPendingScenesByTime(t time.Time) (scenes []Scene, err error)
- func GetSceneByIDWithUnscoped(id int) (scene Scene, err error)
- func GetSceneById(id int) (scene Scene, err error)
- func GetSceneInfoById(id int) (scene Scene, err error)
- func GetScenes(areaID uint64) (scenes []Scene, err error)
- func GetScenesByCondition(deviceID int, attr Attribute) (scenes []Scene, err error)
- func (s *Scene) BeforeSave(tx *gorm.DB) (err error)
- func (s Scene) CheckConditionLogic() bool
- func (s Scene) CheckPeriodType() (err error)
- func (s Scene) CheckRepeatConfig() (err error)
- func (s Scene) CheckSceneNameLength() (err error)
- func (s Scene) HaveTimeCondition() bool
- func (s Scene) IsMatchAllCondition() bool
- func (s Scene) TableName() string
- type SceneCondition
- type SceneTask
- type Shadow
- type State
- type TaskLog
- type TaskResultType
- type TaskType
- type TimePeriodType
- type User
- func GetAreaOwner(areaID uint64) (user User, err error)
- func GetDepartmentUsers(departmentID int) (users []User, err error)
- func GetUserByAccountName(accountName string) (userInfo User, err error)
- func GetUserByID(id int) (user User, err error)
- func GetUserByIDAndAreaID(uID int, areaID uint64) (user User, err error)
- func GetUserByToken(token string) (user User, err error)
- func GetUsers(areaID uint64) (users []User, err error)
- type UserCredentialFoundSetting
- type UserInfo
- type UserPermissions
- func (up UserPermissions) IsDeviceAttrControlPermit(deviceID, instanceID int, attr string) bool
- func (up UserPermissions) IsDeviceAttrPermit(deviceID int, attr Attribute) bool
- func (up UserPermissions) IsDeviceControlPermit(deviceID int) bool
- func (up UserPermissions) IsOwner() bool
- func (up UserPermissions) IsPermit(tp types.Permission) bool
- type UserRole
Constants ¶
const ( // StatusInstallFail 添加插件失败 StatusInstallFail = -1 StatusInstalling = 0 // StatusInstallSuccess 添加插件成功 StatusInstallSuccess = 1 )
const ( SourceTypeDefault = "default" // 默认插件 SourceTypeDevelopment = "development" // 开发者插件 )
const ( OwnerRoleID = -1 // 拥有者角色的roleID Owner = "拥有者" )
const ( MatchAllCondition = 1 // 全部满足 MatchAnyCondition = 2 // 任一满足 )
const ( UserCredentialFoundType = "user_credential_found" LogSwitch = "log_switch" GetCloudDiskCredential = "get_cloud_disk_credential" )
配置类型
const (
AreaIDFieldName = "AreaID"
)
Variables ¶
var Tables []interface{} = []interface{}{ Device{}, Location{}, Area{}, Role{}, RolePermission{}, User{}, UserRole{}, Scene{}, SceneCondition{}, SceneTask{}, TaskLog{}, GlobalSetting{}, PluginInfo{}, Client{}, Department{}, DepartmentUser{}, }
Functions ¶
func AddSADevice ¶ added in v1.5.0
AddSADevice 添加SA设备
func BatchAddChildDevice ¶ added in v1.9.1
BatchAddChildDevice 批量添加子设备
func CheckIllegalRepeatDate ¶
CheckIllegalRepeatDate 判断生效时间格式是否合法
func CheckSAExist ¶ added in v1.9.1
CheckSAExist SA是否已存在
func CheckSceneExitById ¶
func CreateDepartment ¶ added in v1.9.1
func CreateDepartment(department *Department) error
func CreateDepartmentUser ¶ added in v1.9.1
func CreateDepartmentUser(departmentUsers []DepartmentUser) (err error)
func CreateHistory ¶ added in v1.5.0
func CreateLocation ¶
func CreateScene ¶
func CreateSceneTask ¶
func CreateUserRole ¶
func DelAreaByID ¶
func DelDepartmentUserByDepID ¶ added in v1.9.1
func DelDepartmentUserByUId ¶ added in v1.9.1
func DelDeviceByID ¶
func DelDeviceByPID ¶ added in v1.9.1
DelDeviceByPID 根据PID删除对应的子设备,子设备使用硬删除
func DelDevicesByPlgID ¶
func DelLocation ¶
func DeleteRole ¶
func DeleteScene ¶
func DepartmentNameExist ¶ added in v1.9.1
DepartmentNameExist 部门名字是否存在
func EditLocationSort ¶
func GetAreaCount ¶
func GetDBWithAreaScope ¶
func GetDBWithAreaScopeTx ¶ added in v1.5.0
func GetDefaultScope ¶ added in v1.5.0
func GetDefaultScope() (scope string)
func GetDepartmentCount ¶ added in v1.9.1
GetDepartmentCount 该公司部门数量
func GetDepartmentCountByIds ¶ added in v1.9.1
GetDepartmentCountByIds 获取通过部门id获取已有的部门数量
func GetLocationCount ¶
func GetRoleIdsByUid ¶
func GetSetting ¶
GetSetting 获取全局设置
func IsAccountNameExist ¶
func IsAreaType ¶ added in v1.9.1
func IsDepartmentExist ¶ added in v1.9.1
IsDepartmentExist 是否存在该部门
func IsDepartmentManager ¶ added in v1.9.1
IsDepartmentManager 该用户是否是该部门主管
func IsDeviceControlPermit ¶
IsDeviceControlPermit 判断用户是否有该设备的某个控制权限
func IsDeviceControlPermitByAttr ¶
IsDeviceControlPermitByAttr 判断用户是否有该设备的某个控制权限
func IsLocationExist ¶
func IsMeiHuiZhiJuBrand ¶ added in v1.9.1
func IsOwnerOfArea ¶ added in v1.5.0
IsOwnerOfArea 是否是area拥有者
func IsPluginAdd ¶
func IsPluginDevelop ¶ added in v1.5.0
IsPluginDevelop 是否是开发插件
func JudgePermit ¶
func JudgePermit(userID int, p types.Permission) bool
func LocationNameExist ¶
func NewTaskLog ¶
func OpenSqlite ¶ added in v1.5.0
func PluginDeviceAttr ¶
func ResetDepartmentManager ¶ added in v1.9.1
ResetDepartmentManager 重置部门的主管
func SavePluginInfo ¶
func SavePluginInfo(pi PluginInfo) (err error)
func SwitchAutoScene ¶
SwitchAutoScene 切换自动场景开关
func SwitchAutoSceneByID ¶
SwitchAutoSceneByID 切换自动场景开关
func UnBindDepartmentDevice ¶ added in v1.9.1
UnBindDepartmentDevice 解绑该设备与部门的绑定
func UnBindDepartmentDevices ¶ added in v1.9.1
UnBindDepartmentDevices 解绑部门下的设备
func UnBindLocationDevice ¶
func UnBindLocationDevices ¶
func UnScopedDelDepartmentUsers ¶ added in v1.9.1
UnScopedDelDepartmentUsers 通过部门ID删除部门与用户的关联
func UnScopedDelURoleByUid ¶
func UnScopedDelUserDepartments ¶ added in v1.9.1
UnScopedDelUserDepartments 通过用户ID删除用户与部门的关联
func UnbindDepartmentManager ¶ added in v1.9.1
UnbindDepartmentManager 解除部门与主管关联
func UpdateArea ¶
UpdateArea 修改Area名称后,同时需要修改location中旧名称
func UpdateDepartment ¶ added in v1.9.1
func UpdateDepartment(id int, updateDepartment Department) (err error)
UpdateDepartment 更新部门数据
func UpdateDepartmentSort ¶ added in v1.9.1
UpdateDepartmentSort 更新部门排序
func UpdateDevice ¶
func UpdateDeviceById ¶ added in v1.9.1
UpdateDeviceById 根据主键修改设备的值
func UpdateLocation ¶
func UpdatePluginInfo ¶ added in v1.5.0
func UpdatePluginInfo(pluginID string, pluginInfo PluginInfo) (err error)
UpdatePluginInfo 更新插件
func UpdateSceneByIDWithTx ¶ added in v1.9.1
UpdateSceneByIDWithTx 根据SceneID更新场景
func UpdateSetting ¶
UpdateSetting 添加全局设置
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 AreaType AreaType `json:"area_type" gorm:"default:1"` IsSendAuthToSC bool `json:"-"` IsBindCloud bool `json:"is_bind_cloud"` }
Area 家庭
func GetAreaByID ¶
func GetAreaResultById ¶
type AttrMetadata ¶
type AttrMetadata struct {
Timestamp int64 `json:"timestamp"`
}
type Attribute ¶
func (*Attribute) Operate ¶ added in v1.9.1
func (attr *Attribute) Operate(operatorType OperatorType, val interface{}) bool
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
CreateClient 创建应用
func GetClientByClientID ¶ added in v1.5.0
GetClientByClientID 根据ClientID获取Client信息
func GetSAClient ¶ added in v1.5.0
GetSAClient 获取SAClient
func GetSCClient ¶ added in v1.5.0
GetSCClient 获取SCClient
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 Department ¶ added in v1.9.1
type Department struct { ID int `json:"id"` Name string `json:"name" gorm:"uniqueIndex:dep_area_id_name" ` Sort int `json:"sort" ` CreatedAt time.Time `json:"created_at"` AreaID uint64 `gorm:"type:bigint;uniqueIndex:dep_area_id_name"` Area Area `gorm:"constraint:OnDelete:CASCADE;"` ParentDepartmentID *int ChildDepartments []Department `gorm:"foreignkey:parent_department_id"` ManagerID *int `gorm:"index"` // 主管 Deleted gorm.DeletedAt }
func GetAllDepartments ¶ added in v1.9.1
func GetAllDepartments(parentDepartment []Department) (allDepartment []Department)
GetAllDepartments 获取父部门下所有子部门
func GetDepartmentByID ¶ added in v1.9.1
func GetDepartmentByID(id int) (department Department, err error)
GetDepartmentByID 通过id获取部门
func GetDepartments ¶ added in v1.9.1
func GetDepartments(areaID uint64) (departments []Department, err error)
GetDepartments 获取对应公司下的所有部门
func GetManagerDepartments ¶ added in v1.9.1
func GetManagerDepartments(areaID uint64, managerID int) (departments []Department, err error)
GetManagerDepartments 获取主管的部门
func GetUserDepartments ¶ added in v1.9.1
func GetUserDepartments(userID int) (departments []Department, err error)
GetUserDepartments 根据userID获取用户所在部门
func (*Department) BeforeCreate ¶ added in v1.9.1
func (d *Department) BeforeCreate(tx *gorm.DB) (err error)
func (Department) BeforeDelete ¶ added in v1.9.1
func (d Department) BeforeDelete(tx *gorm.DB) (err error)
func (Department) TableName ¶ added in v1.9.1
func (d Department) TableName() string
type DepartmentInfo ¶ added in v1.9.1
type DepartmentInfo struct { ID int `json:"id,omitempty" uri:"id"` Name string `json:"name,omitempty"` IsManager bool `json:"is_manager,omitempty"` PId *int `json:"pid,omitempty"` }
func GetDepartmentsByUser ¶ added in v1.9.1
func GetDepartmentsByUser(user User) (departmentInfos []DepartmentInfo, err error)
GetDepartmentsByUser 获取用户所在部门信息
type DepartmentUser ¶ added in v1.9.1
type DepartmentUser struct { ID int `json:"id" gorm:"primary_key"` DepartmentID int `gorm:"uniqueIndex:department_user_id"` Department Department `gorm:"constraint:OnDelete:CASCADE;"` UserID int `gorm:"uniqueIndex:department_user_id"` User User `gorm:"constraint:OnDelete:CASCADE;"` }
func WrapDepUsersOfDepID ¶ added in v1.9.1
func WrapDepUsersOfDepID(departmentId int, userIds []int) (departmentUsers []DepartmentUser)
WrapDepUsersOfDepID 包装部门对应用户的实体关系
func WrapDepUsersOfUId ¶ added in v1.9.1
func WrapDepUsersOfUId(userID int, departmentIds []int) (departmentUsers []DepartmentUser)
WrapDepUsersOfUId 包装部门对应用户的实体关系
func (DepartmentUser) TableName ¶ added in v1.9.1
func (du DepartmentUser) TableName() string
type Device ¶
type Device struct { ID int `json:"id"` PID int `json:"pid"` // 子设备有值,所属父设备 Name string `json:"name"` // Identity 设备在插件中的唯一标识符 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"` DepartmentID int `json:"department_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 GetDeviceByIDWithUnscoped ¶
GetDeviceByIDWithUnscoped 获取设备,包括已删除
func GetDeviceByIdentity ¶ added in v1.5.0
func GetDevices ¶
func GetDevicesByDepartmentID ¶ added in v1.9.1
func GetDevicesByLocationID ¶
func GetDevicesByPluginID ¶
func GetManufacturerDevice ¶
GetManufacturerDevice 获取厂商的设备
func GetPluginDevice ¶
GetPluginDevice 获取插件的设备
func GetSaDevice ¶
func GetZhitingDevices ¶
GetZhitingDevices 获取所有智汀设备
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 Dialector ¶ added in v1.9.1
func (Dialector) DataTypeOf ¶ added in v1.9.1
type GetCloudDiskCredentialSetting ¶ added in v1.9.1
type GetCloudDiskCredentialSetting struct {
GetCloudDiskCredentialSetting bool `json:"get_cloud_disk_credential_setting"`
}
func GetDefaultCloudDiskCredentialSetting ¶ added in v1.9.1
func GetDefaultCloudDiskCredentialSetting() GetCloudDiskCredentialSetting
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 GetAllSetting ¶ added in v1.9.1
func GetAllSetting(areaID uint64) (gsList []GlobalSetting, err error)
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 GetLocations ¶
func (Location) IsBelongsToUserArea ¶
IsBelongsToUserArea 是否属于用户的家庭
type LogSwitchSetting ¶ added in v1.9.1
type LogSwitchSetting struct {
LogSwitch bool `json:"log_switch"`
}
日志开关
func GetDefaultLogSetting ¶ added in v1.9.1
func GetDefaultLogSetting() LogSwitchSetting
GetDefaultLogSetting 获取日志开关默认配置
type Metadata ¶
type Metadata struct { Desired map[int]map[string]AttrMetadata `json:"desired"` Reported map[int]map[string]AttrMetadata `json:"reported"` }
type Migrator ¶ added in v1.9.1
func (Migrator) CreateTable ¶ added in v1.9.1
CreateTable
gorm Migrator包的CreateTable() 方法拼接建表语句时,默认会将dataType中不含"PRIMARY KEY"的主键字段加上primary Key 如果使用gorm的自定义type标签,当sqlite类型为INTEGER PRIMARY KEY AUTOINCREMENT 时gorm无法正常建表,且会导致云端sa使用的pg数据库失去bigserial特性, 所以兼容两个数据库,重写CreateTable方法,且加入strings.Contains(strings.ToUpper(field.TagSettings["SQLITETYPE"]), "PRIMARY KEY")判断,保证 数据库运行正常
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 (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 GetRoleByID ¶
func GetRolesByIds ¶
func GetRolesByUid ¶
func GetRolesWithTx ¶ added in v1.5.0
func (*Role) AddPermissionForRole ¶
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) DelPermission ¶
func (r *Role) DelPermission(p types.Permission) error
func (Role) IsBelongsToUserArea ¶
IsBelongsToUserArea 是否属于用户的家庭
type RoleInfo ¶
func GetRoleInfos ¶ added in v1.9.1
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 角色权限role_tmpl
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;"` Version int `json:"-" gorm:"column:version;default:1;NOT NULL"` }
Scene 场景
func GetPendingScenesByTime ¶
GetPendingScenesByTime 根据时间获取待执行的场景
func GetSceneByIDWithUnscoped ¶
GetSceneByIDWithUnscoped 获取场景,包括已删除
func GetSceneById ¶
func GetSceneInfoById ¶
GetSceneInfoById 获取场景所有信息
func GetScenesByCondition ¶
GetScenesByCondition 根据条件获取场景
func (Scene) CheckConditionLogic ¶
CheckConditionLogic 校验满足条件
func (Scene) CheckPeriodType ¶
CheckPeriodType 生效时间类型校验
func (Scene) CheckRepeatConfig ¶
CheckRepeatConfig 校验重复执行的配置
func (Scene) CheckSceneNameLength ¶
func (Scene) HaveTimeCondition ¶ added in v1.9.1
HaveTimeCondition 场景是否有定时条件
func (Scene) IsMatchAllCondition ¶
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 (SceneTask) CheckTaskDevice ¶
CheckTaskDevice 校验设备任务类型
func (SceneTask) CheckTaskType ¶
CheckTaskType 执行任务类型校验
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
type TaskLog ¶
type TaskLog struct { ID int Name string // 设备名称/场景名称 Type TaskType // 任务类型 Finish bool // 是否完成 Result TaskResultType // 执行结果 Error string DeviceLocation string // 设备区域 DeviceDepartment 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 任务日志
type TaskResultType ¶
type TaskResultType int
TaskResultType 任务执行结果
const ( TaskSuccess TaskResultType = iota + 1 TaskPartSuccess TaskFail TaskTimeout TaskDeviceAlreadyDeleted TaskDeviceDisConnect TaskSceneAlreadyDeleted )
type TimePeriodType ¶
type TimePeriodType int
const ( TimePeriodTypeAllDay TimePeriodType = iota + 1 TimePeriodTypeCustom )
type User ¶
type User struct { // 使用自定义tag 配合 ./sqlite.go下的DataTypeOf() 和CreateTable()确保能给字段加上autoIncrement标签 ID int `json:"id" gorm:"sqliteType:integer PRIMARY KEY AUTOINCREMENT"` 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;"` PasswordUpdateTime time.Time Deleted gorm.DeletedAt }
func GetAreaOwner ¶ added in v1.5.0
GetAreaOwner 获取家庭的拥有者
func GetDepartmentUsers ¶ added in v1.9.1
GetDepartmentUsers 根据departmentID获取部门下用户
func GetUserByAccountName ¶
func GetUserByID ¶
func GetUserByIDAndAreaID ¶ added in v1.5.0
func GetUserByToken ¶
func (User) BelongsToArea ¶
type UserCredentialFoundSetting ¶
type UserCredentialFoundSetting struct {
UserCredentialFound bool `json:"user_credential_found"`
}
用户凭证配置
func GetDefaultUserCredentialFoundSetting ¶
func GetDefaultUserCredentialFoundSetting() UserCredentialFoundSetting
GetDefaultUserCredentialFoundSetting 获取找回用户凭证默认配置
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
IsDeviceAttrControlPermit 判断设备的属性是否有权限
func (UserPermissions) IsDeviceAttrPermit ¶
func (up UserPermissions) IsDeviceAttrPermit(deviceID int, attr Attribute) bool
IsDeviceAttrPermit 判断设备的属性是否有权限
func (UserPermissions) IsDeviceControlPermit ¶
func (up UserPermissions) IsDeviceControlPermit(deviceID int) bool
IsDeviceControlPermit 判断设备是否可控制
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