记录任务下发历史和接收是否成功

This commit is contained in:
2025-09-25 00:17:01 +08:00
parent 6b931648dc
commit e2e21601f4
7 changed files with 161 additions and 29 deletions

View File

@@ -4,11 +4,11 @@ import (
"time"
)
// DownlinkTaskRecord 记录下行任务的下发情况和设备确认状态
type DownlinkTaskRecord struct {
// DeviceCommandLog 记录下行任务的下发情况和设备确认状态
type DeviceCommandLog struct {
// MessageID 是下行消息的唯一标识符。
// 可以是 ChirpStack 的 DeduplicationID 或其他系统生成的ID。
MessageID string `gorm:"uniqueIndex;not null" json:"message_id"`
MessageID string `gorm:"primaryKey" json:"message_id"`
// DeviceID 是接收此下行任务的设备的ID。
// 对于 LoRaWAN这通常是区域主控设备的ID。
@@ -20,9 +20,13 @@ type DownlinkTaskRecord struct {
// AcknowledgedAt 记录设备确认收到下行消息的时间。
// 如果设备未确认,则为零值或 NULL。使用指针类型 *time.Time 允许 NULL 值。
AcknowledgedAt *time.Time `json:"acknowledged_at"`
// ReceivedSuccess 表示设备是否成功接收到下行消息。
// true 表示设备已确认收到false 表示设备未确认收到或下发失败。
ReceivedSuccess bool `gorm:"not null" json:"received_success"`
}
// TableName 自定义 GORM 使用的数据库表名
func (DownlinkTaskRecord) TableName() string {
return "downlink_task_records"
func (DeviceCommandLog) TableName() string {
return "device_command_log"
}

View File

@@ -13,6 +13,6 @@ func GetAllModels() []interface{} {
&TaskExecutionLog{},
&PendingTask{},
&SensorData{},
&DownlinkTaskRecord{},
&DeviceCommandLog{},
}
}