device.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package models
  2. import (
  3. "errors"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // Device device model
  7. // device is a product instance, which is managed by our platform
  8. type Device struct {
  9. gorm.Model
  10. RecordId string `gorm:"column:record_id;size:32;index"`
  11. // which product the device belongs to
  12. ProductID string `gorm:"column:product_id;size:32;index"`
  13. // universal device identifier, generated from vendorid-productid-deviceserial
  14. DeviceIdentifier string `sql:"type:varchar(200);not null;unique;key"`
  15. // device secret which is auto generated by the platform
  16. DeviceSecret string `sql:"type:varchar(200);not null;"`
  17. // device key is used to auth a device
  18. DeviceKey string `sql:"type:varchar(200);not null;key;"`
  19. // device name
  20. DeviceName string `sql:"type:varchar(200);not null;"`
  21. // device desc
  22. DeviceDescription string `sql:"type:text;not null;"`
  23. // device version(the agent version)
  24. DeviceVersion string `sql:"type:text;not null;"`
  25. // vendor id
  26. VendorID string `gorm:"column:vendor_id;size:32;index"`
  27. //通讯模组名称
  28. ModuleName string
  29. }
  30. // DeviceQuery device query
  31. type DeviceQuery struct {
  32. Device
  33. ProductName string
  34. }
  35. // Devices
  36. type Devices struct {
  37. Device
  38. Status int
  39. }
  40. // DeviceChartData 设备数据图表
  41. type DeviceChartData struct {
  42. Dt string
  43. Count int
  44. }
  45. type UpgradeParams struct {
  46. VendorID string `json:"vendor_id"`
  47. DeviceID string `json:"device_id"`
  48. File []byte `json:"file"`
  49. FileName string `json:"file_name"`
  50. FileSize int64 `json:"file_size"`
  51. }
  52. // Validate 验证
  53. func (a *UpgradeParams) Validate() error {
  54. if a.DeviceID == "" {
  55. return errors.New("非法参数[Name, Label]")
  56. }
  57. return nil
  58. }