device_command.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package models
  2. import (
  3. "errors"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // DeviceCommandDatas DeviceCommandData 切片类型
  7. type DeviceCommandDatas []DeviceCommandData
  8. // DeviceCommand 设备指令
  9. type DeviceCommand struct {
  10. gorm.Model
  11. RecordID string `gorm:"primary_key;column:record_id;size:32;index" json:"record_id"`
  12. DeviceType string `gorm:"column:device_type;size:200" json:"device_type"` // 设备类型
  13. DeviceTypeId string `gorm:"column:device_type_id;size:32;index" json:"device_type_id"` // 设备类型id
  14. Name string `gorm:"column:name;size:200" json:"name"` // 名称
  15. Command string `gorm:"column:command;size:200" json:"command"` // 指令
  16. DataType string `gorm:"column:data_type;size:100" json:"data_type"` // 数据类型
  17. Data DeviceCommandDatas `gorm:"foreignkey:CommandId" json:"data"` // 数据
  18. CommandType int `gorm:"column:command_type" json:"command_type"` // 指令类型
  19. }
  20. // TableName 表名
  21. func (DeviceCommand) TableName() string {
  22. return "device_command"
  23. }
  24. // Validate 验证
  25. func (a *DeviceCommand) Validate() error {
  26. if a.Name == "" {
  27. return errors.New("非法参数:[Name]")
  28. }
  29. if a.DeviceTypeId == "" {
  30. return errors.New("非法参数:[DeviceTypeId]")
  31. }
  32. return nil
  33. }
  34. // DeviceCommandData DeviceCommandData对象
  35. type DeviceCommandData struct {
  36. gorm.Model
  37. RecordID string `gorm:"primary_key;column:record_id;size:32;index" json:"record_id"`
  38. CommandId string `gorm:"column:command_id;size:32;index" json:"command_id"` // 指令id
  39. CommandName string `gorm:"column:command_name;size:200" json:"command_name"` // 指令名称
  40. Name string `gorm:"column:name;size:200" json:"name"` // 名称
  41. Params string `gorm:"column:params;type:text" json:"params"` // 参数
  42. }
  43. // TableName 表名
  44. func (DeviceCommandData) TableName() string {
  45. return "device_command_data"
  46. }
  47. // Validate 验证
  48. func (a *DeviceCommandData) Validate() error {
  49. if a.CommandId == "" {
  50. return errors.New("非法参数:[CommandId]")
  51. }
  52. return nil
  53. }