msgThing

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package repo 本文件是提供设备模型数据存储的信息

Index

Constants

View Source
const (
	TypeProperty = "property" //事件-操作类型:属性或信息上报(Topic:$thing/up/property/{ProductID}/{DeviceName})
	TypeEvent    = "event"    //事件-操作类型:事件上报(Topic:$thing/up/event/{ProductID}/{DeviceName})
	TypeAction   = "action"   //事件-操作类型:行为上报(Topic:$thing/up/action/{ProductID}/{DeviceName})
	TypeService  = "service"  // 联犀应用相关服务

	EventReport = "report" //设备上报的信息
	EventInfo   = "info"   //信息
	EventAlert  = "alert"  //告警
	EventFault  = "fault"  //故障
)

Variables

This section is empty.

Functions

func GetVal

func GetVal(d *schema.Define, val any) (any, error)

从设备参数中获取值

func IsParamValEq

func IsParamValEq(d *schema.Define, v1 any, v2 any) bool

func ToParamValues

func ToParamValues(tp map[string]Param) (map[string]any, error)

func ToVal

func ToVal(tp map[string]Param) (map[string]any, error)

Types

type DeviceBasicInfo

type DeviceBasicInfo struct {
	devices.Core
	DeviceAlias    string            `json:"deviceAlias,omitempty"` //设备名称
	Imei           string            `json:"imei,omitempty"`        //设备的 IMEI 号信息,非必填项
	Mac            string            `json:"mac,omitempty"`         //设备的 MAC 信息,非必填项
	Version        string            `json:"version,omitempty"`     //固件版本
	Address        *string           `json:"address,omitempty"`     //所在地址
	Adcode         *string           `json:"adcode,omitempty"`      //地区编码
	Module         string            `json:"module,omitempty"`
	HardInfo       string            `json:"hardInfo,omitempty"`       //模组具体硬件型号
	SoftInfo       string            `json:"softInfo,omitempty"`       //模组软件版本
	Position       *def.Point        `json:"position,omitempty"`       //设备基础信息-坐标信息
	Tags           map[string]string `json:"tags,omitempty"`           //设备标签信息
	MobileOperator int64             `json:"mobileOperator,omitempty"` //移动运营商:1)移动 2)联通 3)电信 4)广电
	Rssi           *int64            `json:"rssi,omitempty"`
	Iccid          *string           `json:"iccid"`
}

设备基础信息

type EventData

type EventData struct {
	Identifier string         `gorm:"column:identifier;type:varchar(50);NOT NULL" json:"identifier"` //标识符
	Type       string         `gorm:"column:type;type:varchar(20);NOT NULL" json:"type" `            //事件类型: 信息:info  告警alert  故障:fault
	Params     map[string]any `gorm:"column:param;type:varchar(256);NOT NULL" json:"params" `        //事件参数
	TimeStamp  time.Time      `gorm:"column:ts;NOT NULL;" json:"timeStamp"`                          //时间戳
}

EventData 事件数据

type FilterOpt

type FilterOpt struct {
	Page       def.PageInfo2
	ProductID  string
	ProductIDs []string
	//DeviceName  string
	DeviceNames  []string
	DataID       string
	Types        []string     //事件类型: 信息:info  告警alert  故障:fault
	Order        stores.Order //0:aes(默认,从久到近排序) 1:desc(时间从近到久排序)
	Interval     int64        //间隔(单位毫秒) 如果这个值不为零值 则时间的开始和结束必须有效及聚合函数不应该为空
	IntervalUnit def.TimeUnit //间隔单位 a (毫秒,默认), d (天), h (小时), m (分钟), n (月), s (秒), u (微秒), w (周), y (年)
	Fill         string       //指定窗口区间数据缺失的情况下的填充模式
	ArgFunc      string       //聚合函数 avg:平均值 first:第一个参数 last:最后一个参数 count:总数 twa: 时间加权平均函数 参考:https://docs.taosdata.com/taos-sql/function
	PartitionBy  string       //切分数据,可以填写deviceName
}

FILL 语句指定某一窗口区间数据缺失的情况下的填充模式。填充模式包括以下几种: 不进行填充:NONE(默认填充模式)。 VALUE 填充:固定值填充,此时需要指定填充的数值。例如:FILL(VALUE, 1.23)。这里需要注意,最终填充的值受由相应列的类型决定,如 FILL(VALUE, 1.23),相应列为 INT 类型,则填充值为 1。 PREV 填充:使用前一个非 NULL 值填充数据。例如:FILL(PREV)。 NULL 填充:使用 NULL 填充数据。例如:FILL(NULL)。 LINEAR 填充:根据前后距离最近的非 NULL 值做线性插值填充。例如:FILL(LINEAR)。 NEXT 填充:使用下一个非 NULL 值填充数据。例如:FILL(NEXT)。

func (FilterOpt) Check

func (f FilterOpt) Check() error

type LatestFilter

type LatestFilter struct {
	ProductID  string
	DeviceName string
	DataID     string
}

type Optional

type Optional struct {
	Sync      bool //同步执行
	OnlyCache bool //只记录到缓存中
}

type PackReport

type PackReport struct {
	*deviceMsg.CommonMsg
}

type Param

type Param struct {
	Identifier string              `json:"identifier"` //标识符
	Name       string              `json:"name"`       //功能名称
	Desc       string              `json:"gesc"`       //描述
	Mode       schema.PropertyMode `json:"mode"`       //读写乐行:rw(可读可写) r(只读)
	Required   bool                `json:"required"`   //是否必须
	Type       schema.EventType    `json:"type"`       //事件类型: 信息:info  告警alert  故障:fault
	Define     *schema.Define
	Value      any `json:"value"` //数据定义
}

func (*Param) SetByDefine

func (tp *Param) SetByDefine(d *schema.Define, val any) (err error)

func (*Param) ToVal

func (tp *Param) ToVal() (any, error)

type PropertyData

type PropertyData struct {
	DeviceName string    `gorm:"column:device_name;type:varchar(50);NOT NULL" json:"deviceName"`
	Identifier string    `gorm:"column:identifier;type:varchar(50);NOT NULL" json:"identifier"` //标识符
	Param      any       `gorm:"column:param;type:varchar(256);NOT NULL" json:"param" `         //一个属性的参数
	TimeStamp  time.Time `gorm:"column:ts;NOT NULL;" json:"timeStamp"`                          //时间戳
}

PropertyData 属性数据

func (*PropertyData) Fmt

func (p *PropertyData) Fmt() *PropertyData

func (*PropertyData) String

func (p *PropertyData) String() string

type Req

type Req struct {
	deviceMsg.CommonMsg
	Params      map[string]any `json:"params,omitempty"`      //参数列表
	Identifiers []string       `json:"identifiers,omitempty"` //内为希望设备上报的属性列表,不填为获取全部
	Version     string         `json:"version,omitempty"`     //协议版本,默认为1.0。
	EventID     string         `json:"eventID,omitempty"`     //事件的 Id,在数据模板事件中定义。
	ActionID    string         `json:"actionID,omitempty"`    //数据模板中的行为标识符,由开发者自行根据设备的应用场景定义
	Type        string         `json:"type,omitempty"`        //表示获取什么类型的信息(report:表示设备上报的信息 info:信息 alert:告警 fault:故障)
	ProductID   string         `json:"productID,omitempty"`   //产品ID
	//批量上报用到
	Properties []*deviceMsg.TimeParams `json:"properties,omitempty"`
	Events     []*deviceMsg.TimeParams `json:"events,omitempty"`
	SubDevices []*SubDevice            `json:"subDevices,omitempty"`
	Schema     *schema.ModelSimple     `json:"schema,omitempty"` //物模型
}

func (Req) AddStatus

func (d Req) AddStatus(err error) Req

func (*Req) FmtReqParam

func (d *Req) FmtReqParam(t *schema.Model, tt schema.ParamType) error

func (*Req) GetTimeStamp

func (d *Req) GetTimeStamp(defaultTime int64) time.Time

func (*Req) VerifyReqParam

func (d *Req) VerifyReqParam(t *schema.Model, tt schema.ParamType) (map[string]Param, error)

校验设备上报的参数合法性

type Resp

type Resp struct {
	deviceMsg.CommonMsg
	Version string `json:"version,omitempty"` //协议版本,默认为1.0。
	Type    string `json:"type,omitempty"`    //	表示什么类型的信息。report:表示设备上报的信息
	//Response map[string]any `json:"response,omitempty"` //设备行为中定义的返回参数,设备行为执行成功后,向云端返回执行结果
	ActionID string `json:"actionID,omitempty"` //数据模板中的行为标识符,由开发者自行根据设备的应用场景定义
}

func (*Resp) FmtRespParam

func (d *Resp) FmtRespParam(t *schema.Model, id string, tt schema.ParamType) error

func (*Resp) GetTimeStamp

func (d *Resp) GetTimeStamp(defaultTime time.Time) time.Time

func (*Resp) VerifyRespParam

func (d *Resp) VerifyRespParam(t *schema.Model, id string,
	tt schema.ParamType) (map[string]Param, error)

type SchemaDataRepo

type SchemaDataRepo interface {
	Init(ctx context.Context) error
	// InsertEventData 插入事件数据
	InsertEventData(ctx context.Context, productID string, deviceName string, event *EventData) error
	// InsertPropertyData 插入一条属性数据
	InsertPropertyData(ctx context.Context, t *schema.Property, productID string, deviceName string, property *Param, timestamp time.Time, optional Optional) error
	// InsertPropertiesData 插入多条属性数据 params key为属性的id,val为属性的值
	InsertPropertiesData(ctx context.Context, t *schema.Model, productID string, deviceName string, params map[string]Param, timestamp time.Time, optional Optional) error
	// GetEventDataWithID 根据事件id获取事件信息
	GetEventDataByFilter(ctx context.Context, filter FilterOpt) ([]*EventData, error)
	GetEventCountByFilter(ctx context.Context, filter FilterOpt) (int64, error)
	// GetPropertyDataByID 根据属性id获取属性信息
	GetPropertyDataByID(ctx context.Context, p *schema.Property, filter FilterOpt) ([]*PropertyData, error)
	GetLatestPropertyDataByID(ctx context.Context, p *schema.Property, filter LatestFilter) (*PropertyData, error)
	GetPropertyCountByID(ctx context.Context, p *schema.Property, filter FilterOpt) (int64, error)
	// InitProduct 初始化产品的物模型相关表及日志记录表
	InitProduct(ctx context.Context, t *schema.Model, productID string) error
	// DeleteProduct 删除产品时需要删除产品下的所有表
	DeleteProduct(ctx context.Context, t *schema.Model, productID string) error
	// InitDevice 创建设备时为设备创建单独的表
	InitDevice(ctx context.Context, t *schema.Model, productID string, deviceName string) error
	// DeleteDevice 删除设备时需要删除设备的所有表
	DeleteDevice(ctx context.Context, t *schema.Model, productID string, deviceName string) error
	DeleteDeviceProperty(ctx context.Context, productID string, deviceName string, s []schema.Property) error
	// UpdateProduct 修改产品物模型 只支持新增和删除,不支持修改数据类型
	//UpdateProduct(ctx context.Context, oldT *schema.Model, newt *schema.Model, productID string) error
	CreateProperty(ctx context.Context, p *schema.Property, productID string) error
	DeleteProperty(ctx context.Context, p *schema.Property, productID string, identifier string) error
	UpdateProperty(ctx context.Context, oldP *schema.Property, newP *schema.Property, productID string) error
}

type SubDevice

type SubDevice struct {
	ProductID  string                  `json:"productID"`  //产品id
	DeviceName string                  `json:"deviceName"` //设备名称
	Properties []*deviceMsg.TimeParams `json:"properties"`
	Events     []*deviceMsg.TimeParams `json:"events"`
}

type TimeParam

type TimeParam struct {
	Timestamp int64            `json:"timestamp,omitempty"` //毫秒时间戳
	EventID   string           `json:"eventID,omitempty"`   //事件的 Id,在数据模板事件中定义。
	Type      schema.EventType `json:"type,omitempty"`      //事件类型: 信息:info  告警alert  故障:fault
	Params    map[string]Param `json:"params"`
}

func VerifyEvents

func VerifyEvents(t *schema.Model, events []*deviceMsg.TimeParams) ([]*TimeParam, error)

func VerifyProperties

func VerifyProperties(t *schema.Model, properties []*deviceMsg.TimeParams) ([]*TimeParam, map[string]any, error)

Jump to

Keyboard shortcuts

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