package common_models import ( "fmt" "time" ) type IotaData struct { UserId string `json:"userId"` ThingId string `json:"thingId"` DimensionId string `json:"dimensionId"` DimCapId string `json:"dimCapId"` CapId string `json:"capId"` DeviceId string `json:"deviceId"` ScheduleId string `json:"scheduleId"` TaskId string `json:"taskId"` JobId int `json:"jobId"` JobRepeatId int `json:"jobRepeatId"` TriggerTime time.Time `json:"triggerTime"` RealTime time.Time `json:"realTime"` FinishTime time.Time `json:"finishTime"` Seq int `json:"seq"` Released bool `json:"released"` Data Data `json:"data"` } // ReadTaskId 支持内部字段定义任务ID (_acq_number) func (the *IotaData) ReadTaskId() (taskId string) { taskId = the.TaskId //可能的覆盖 dtype, ok := the.Data.Data["_data_type"] if ok && dtype == RawTypeVib { taskId = the.TriggerTime.Format("20060102150405") } else { if acq, ok := the.Data.Data["_acq_number"]; ok { taskId = the.TriggerTime.Format("20060102") + fmt.Sprintf("%v", acq) } } return taskId } type Data struct { Type int `json:"type"` Data map[string]any `json:"data"` Result struct { Code int `json:"code"` Msg string `json:"msg"` Detail string `json:"detail"` ErrTimes int `json:"errTimes"` Dropped bool `json:"dropped"` } `json:"result"` } func (the *Data) Success() bool { return the.Result.Code == 0 } func (the *IotaData) T() time.Time { return the.TriggerTime } func (the *IotaData) Q() string { return fmt.Sprintf("iotaData:%s", the.DeviceId) } func (the *IotaData) R() string { return fmt.Sprintf("[ThingId:%s] [DeviceId:%s]", the.ThingId, the.DeviceId) } func (the *IotaData) GetThingId() string { return the.ThingId } func (the *IotaData) GetDeviceId() string { return the.DeviceId }