device_status.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package models
  2. import (
  3. "errors"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // DeviceStatusDatas DeviceStatusData 切片类型
  7. type DeviceStatusDatas []DeviceStatusData
  8. // DeviceStatusInfo DeviceStatus对象
  9. type DeviceStatus struct {
  10. gorm.Model
  11. RecordID string `gorm:"primary_key;column:record_id;size:32;index" json:"record_id"`
  12. DeviceTypeId string `gorm:"column:device_type_id;size:32;index" json:"device_type_id"` // 设备类型id
  13. DeviceTypeCode string `gorm:"column:device_type_code;size:100" json:"device_type_code"` // 设备类型code
  14. Desc string `gorm:"column:desc;size:500" json:"desc"` // 描述
  15. Name string `gorm:"column:name;size:200" json:"name"` // 状态字段名称
  16. Label string `gorm:"column:label;size:200" json:"label"` // 状态字段标签
  17. Type string `gorm:"column:type;size:100" json:"type"` // 状态字段类型
  18. Unit string `gorm:"column:unit;size:50" json:"unit"` // 单位
  19. FieldType int `gorm:"column:field_type" json:"field_type"` // 数据类型
  20. Data DeviceStatusDatas `gorm:"foreignkey:status_id" json:"data"` // 状态数据
  21. }
  22. // TableName 表名
  23. func (DeviceStatus) TableName() string {
  24. return "device_status"
  25. }
  26. // Validate 验证
  27. func (a *DeviceStatus) Validate() error {
  28. if a.Name == "" {
  29. return errors.New("非法参数:[Name]")
  30. }
  31. if a.DeviceTypeId == "" {
  32. return errors.New("非法参数:[DeviceTypeId]")
  33. }
  34. return nil
  35. }
  36. // DeviceStatusData DeviceStatusData对象
  37. type DeviceStatusData struct {
  38. gorm.Model
  39. RecordID string `gorm:"primary_key;column:record_id;size:32;index" json:"record_id"`
  40. StatusID string `gorm:"column:status_id;size:32;index" json:"status_id"` // 状态id
  41. Name string `gorm:"column:name;size:200" json:"name"` // 名称
  42. Value string `gorm:"column:value;size:500" json:"value"` // 值
  43. }
  44. // TableName 表名
  45. func (DeviceStatusData) TableName() string {
  46. return "device_status_data"
  47. }
  48. // Validate 验证
  49. func (a *DeviceStatusData) Validate() error {
  50. if a.StatusID == "" {
  51. return errors.New("非法参数:[StatusID]")
  52. }
  53. return nil
  54. }