46 lines
3.7 KiB
Go
46 lines
3.7 KiB
Go
|
|
// 功能:家庭成员邀请、接受状态和设备共享授权;版本:1.0.0。
|
|||
|
|
package models
|
|||
|
|
|
|||
|
|
import "time"
|
|||
|
|
|
|||
|
|
// UserFamilyMember 保存房主发出的成员邀请,成员确认后才建立家庭关系。
|
|||
|
|
type UserFamilyMember struct {
|
|||
|
|
Entity
|
|||
|
|
OwnerUserAccountID uint64 `gorm:"column:owner_user_account_id;not null;index" json:"-"` // 房主用户内部主键
|
|||
|
|
MemberUserAccountID uint64 `gorm:"column:member_user_account_id;not null;default:0;index" json:"-"` // 接受邀请的成员用户内部主键,0表示尚未接受
|
|||
|
|
Name string `gorm:"column:name;type:varchar(64);not null" json:"name"` // 邀请时填写的成员称呼
|
|||
|
|
Phone string `gorm:"column:phone;type:varchar(32);not null;index" json:"-"` // 受邀手机号,仅向房主或本人脱敏返回
|
|||
|
|
Relationship string `gorm:"column:relationship;type:varchar(32);not null;default:''" json:"relationship"` // 与房主关系
|
|||
|
|
InviteStatus int `gorm:"column:invite_status;not null;default:10;index" json:"invite_status"` // 邀请状态:10=待确认,20=已接受,30=已拒绝,40=已撤销
|
|||
|
|
RequestNo string `gorm:"column:request_no;type:varchar(36);not null" json:"-"` // 邀请幂等请求号
|
|||
|
|
ExpiresAt time.Time `gorm:"column:expires_at;type:timestamptz;not null" json:"expires_at"` // 邀请失效时间
|
|||
|
|
AcceptedAt *time.Time `gorm:"column:accepted_at;type:timestamptz" json:"accepted_at"` // 成员接受时间
|
|||
|
|
RevokedAt *time.Time `gorm:"column:revoked_at;type:timestamptz" json:"revoked_at"` // 房主撤销时间
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (*UserFamilyMember) TableName() string { return "user_family_member" }
|
|||
|
|
|
|||
|
|
// UserDeviceShare 保存单个家庭成员对单个设备的最小授权范围。
|
|||
|
|
type UserDeviceShare struct {
|
|||
|
|
Entity
|
|||
|
|
FamilyMemberID uint64 `gorm:"column:family_member_id;not null;index;uniqueIndex:ux_family_device_share" json:"-"` // 家庭成员关系内部主键
|
|||
|
|
ProductInfoID uint64 `gorm:"column:product_info_id;not null;index;uniqueIndex:ux_family_device_share" json:"-"` // 房主名下设备内部主键
|
|||
|
|
CanView bool `gorm:"column:can_view;not null;default:false" json:"can_view"` // 是否允许查看设备资料和状态
|
|||
|
|
CanAlert bool `gorm:"column:can_alert;not null;default:false" json:"can_alert"` // 是否允许接收该设备危险告警
|
|||
|
|
CanControl bool `gorm:"column:can_control;not null;default:false" json:"can_control"` // 是否允许发起远程控制,控制仍需二次确认
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (*UserDeviceShare) TableName() string { return "user_device_share" }
|
|||
|
|
|
|||
|
|
// UserFamilyAudit 保存邀请和授权变化,供安全追溯。
|
|||
|
|
type UserFamilyAudit struct {
|
|||
|
|
Entity
|
|||
|
|
OwnerUserAccountID uint64 `gorm:"column:owner_user_account_id;not null;index" json:"-"` // 房主用户内部主键
|
|||
|
|
FamilyMemberID uint64 `gorm:"column:family_member_id;not null;default:0;index" json:"-"` // 关联成员内部主键
|
|||
|
|
ActorUserAccountID uint64 `gorm:"column:actor_user_account_id;not null;index" json:"-"` // 执行操作的用户内部主键
|
|||
|
|
Action string `gorm:"column:action;type:varchar(32);not null;index" json:"action"` // 操作类型:invite/accept/reject/update_permissions/revoke
|
|||
|
|
Summary string `gorm:"column:summary;type:varchar(512);not null;default:''" json:"summary"` // 不含手机号的变更摘要
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (*UserFamilyAudit) TableName() string { return "user_family_audit" }
|