package models import ( "time" ) // IotCommand 是设备下行命令事实;受理、投递与设备执行状态必须分离。 type IotCommand struct { Entity `gorm:"embedded;comment:设备命令公共实体字段"` // 命令公共实体字段 DeviceIdentity string `gorm:"column:device_identity;type:varchar(36);not null;index" json:"device_identity"` // 平台设备 identity DeviceID string `gorm:"column:device_id;type:varchar(16);not null;index" json:"device_id"` // 厂商 8-byte BCD 标识 IdempotencyKey string `gorm:"column:idempotency_key;type:varchar(128);not null;uniqueIndex;comment:命令幂等键" json:"idempotency_key"` // 命令幂等键 Action string `gorm:"column:action;type:varchar(32);not null;comment:设备控制动作" json:"action"` // 设备控制动作 RequestPayload string `gorm:"column:request_payload;type:text;not null;comment:原始命令请求快照" json:"request_payload"` // 原始请求快照 CommandStatus string `gorm:"column:command_status;type:varchar(32);not null;index;comment:命令受理投递执行状态" json:"command_status"` // 命令处理状态 PacketNumber uint16 `gorm:"column:packet_number;not null;default:0;comment:厂商协议包号" json:"packet_number"` // 厂商协议包号 ErrorCode string `gorm:"column:error_code;type:varchar(64);not null;default:'';comment:稳定错误码" json:"error_code"` // 稳定错误码 ExpiresAt time.Time `gorm:"column:expires_at;type:timestamptz;not null;index;comment:命令失效时间" json:"expires_at"` // 命令失效时间 DispatchedAt *time.Time `gorm:"column:dispatched_at;type:timestamptz;comment:下发到消息代理时间" json:"dispatched_at"` // 下发时间 AcknowledgedAt *time.Time `gorm:"column:acknowledged_at;type:timestamptz;comment:设备回执时间" json:"acknowledged_at"` // 设备回执时间 } func (*IotCommand) TableName() string { return "iot_command" }