package models import ( "errors" "github.com/jinzhu/gorm" ) // DeviceCommandDatas DeviceCommandData 切片类型 type DeviceCommandDatas []DeviceCommandData // DeviceCommand 设备指令 type DeviceCommand struct { gorm.Model RecordID string `gorm:"primary_key;column:record_id;size:32;index" json:"record_id"` DeviceType string `gorm:"column:device_type;size:200" json:"device_type"` // 设备类型 DeviceTypeId string `gorm:"column:device_type_id;size:32;index" json:"device_type_id"` // 设备类型id Name string `gorm:"column:name;size:200" json:"name"` // 名称 Command string `gorm:"column:command;size:200" json:"command"` // 指令 DataType string `gorm:"column:data_type;size:100" json:"data_type"` // 数据类型 Data DeviceCommandDatas `gorm:"foreignkey:CommandId" json:"data"` // 数据 CommandType int `gorm:"column:command_type" json:"command_type"` // 指令类型 } // TableName 表名 func (DeviceCommand) TableName() string { return "device_command" } // Validate 验证 func (a *DeviceCommand) Validate() error { if a.Name == "" { return errors.New("非法参数:[Name]") } if a.DeviceTypeId == "" { return errors.New("非法参数:[DeviceTypeId]") } return nil } // DeviceCommandData DeviceCommandData对象 type DeviceCommandData struct { gorm.Model RecordID string `gorm:"primary_key;column:record_id;size:32;index" json:"record_id"` CommandId string `gorm:"column:command_id;size:32;index" json:"command_id"` // 指令id CommandName string `gorm:"column:command_name;size:200" json:"command_name"` // 指令名称 Name string `gorm:"column:name;size:200" json:"name"` // 名称 Params string `gorm:"column:params;type:text" json:"params"` // 参数 } // TableName 表名 func (DeviceCommandData) TableName() string { return "device_command_data" } // Validate 验证 func (a *DeviceCommandData) Validate() error { if a.CommandId == "" { return errors.New("非法参数:[CommandId]") } return nil }