| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package models
- import (
- "errors"
- "github.com/jinzhu/gorm"
- )
- // DeviceStatusDatas DeviceStatusData 切片类型
- type DeviceStatusDatas []DeviceStatusData
- // DeviceStatusInfo DeviceStatus对象
- type DeviceStatus struct {
- gorm.Model
- RecordID string `gorm:"primary_key;column:record_id;size:32;index" json:"record_id"`
- DeviceTypeId string `gorm:"column:device_type_id;size:32;index" json:"device_type_id"` // 设备类型id
- DeviceTypeCode string `gorm:"column:device_type_code;size:100" json:"device_type_code"` // 设备类型code
- Desc string `gorm:"column:desc;size:500" json:"desc"` // 描述
- Name string `gorm:"column:name;size:200" json:"name"` // 状态字段名称
- Label string `gorm:"column:label;size:200" json:"label"` // 状态字段标签
- Type string `gorm:"column:type;size:100" json:"type"` // 状态字段类型
- Unit string `gorm:"column:unit;size:50" json:"unit"` // 单位
- FieldType int `gorm:"column:field_type" json:"field_type"` // 数据类型
- Data DeviceStatusDatas `gorm:"foreignkey:status_id" json:"data"` // 状态数据
- }
- // TableName 表名
- func (DeviceStatus) TableName() string {
- return "device_status"
- }
- // Validate 验证
- func (a *DeviceStatus) Validate() error {
- if a.Name == "" {
- return errors.New("非法参数:[Name]")
- }
- if a.DeviceTypeId == "" {
- return errors.New("非法参数:[DeviceTypeId]")
- }
- return nil
- }
- // DeviceStatusData DeviceStatusData对象
- type DeviceStatusData struct {
- gorm.Model
- RecordID string `gorm:"primary_key;column:record_id;size:32;index" json:"record_id"`
- StatusID string `gorm:"column:status_id;size:32;index" json:"status_id"` // 状态id
- Name string `gorm:"column:name;size:200" json:"name"` // 名称
- Value string `gorm:"column:value;size:500" json:"value"` // 值
- }
- // TableName 表名
- func (DeviceStatusData) TableName() string {
- return "device_status_data"
- }
- // Validate 验证
- func (a *DeviceStatusData) Validate() error {
- if a.StatusID == "" {
- return errors.New("非法参数:[StatusID]")
- }
- return nil
- }
|