package serializer import ( "vamicro/iotData-service/model" ) // type Warning struct { // gorm.Model // SN string `json:"device_sn"` // Lng float64 `json:"lng"` // Lat float64 `json:"lat"` // Battery float64 `json:"battery"` // High float64 `json:"high"` // GpsType string `json:"gps_type"` // IsLowBattery int `json:"isLowBattery" gorm:"default 0"` //0不是 1是 // // } type WarnRsp struct { Id uint `json:"id"` SN string `json:"device_sn"` Lng float64 `json:"lng"` Lat float64 `json:"lat"` Battery float64 `json:"battery"` High float64 `json:"high"` GpsType string `json:"gps_type"` IsLowBattery int `json:"isLowBattery" gorm:"default 0"` //0不是 1是 IsOutBound int `json:"isOutBound" gorm:"default 0"` //0不是 1是 Status int `json:"status" gorm:"default 0"` //0未处理 1已处理 CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` SnapShot string `json:"snap_shot"` } func BuildWarnRsp(item model.Warning) WarnRsp { return WarnRsp{ Id: item.ID, SN: item.SN, Lng: item.Lng, Lat: item.Lat, Battery: item.Battery, High: item.High, GpsType: item.GpsType, IsLowBattery: item.IsLowBattery, IsOutBound: item.IsOutBound, Status: item.Status, CreatedAt: item.CreatedAt.Local().Format("2006-01-02 15:04:05"), UpdatedAt: item.UpdatedAt.Local().Format("2006-01-02 15:04:05"), SnapShot: item.SnapShot, } } func BuildWarnsRsp(items []model.Warning) (dvs []WarnRsp) { for _, item := range items { dv := BuildWarnRsp(item) dvs = append(dvs, dv) } return }