package adaptors import ( "encoding/json" "fmt" "goUpload/consumers/WJHP" "log" "strconv" "time" ) // Adaptor_SJWY_WJHP 飞尚视觉位移 转换 魏家滑坡+实验室 type Adaptor_SJWY_WJHP struct { IdMap WJHP.SensorConfig } func (the Adaptor_SJWY_WJHP) Transform(topic, rawMsg string) []byte { return the.GDRDtoUpload(topic, rawMsg) } func (the Adaptor_SJWY_WJHP) GDRDtoUpload(devModule, rawRecords string) (result []byte) { log.Printf("收到模块号[%s]设备mq数据:%s", devModule, rawRecords) d := WJHP.PosData{} err := json.Unmarshal([]byte(rawRecords), &d) if err != nil { return nil } devId := fmt.Sprintf("%s-%s", devModule, d.Pos) sensorInfo := the.matchStationId(devId) if sensorInfo.StationId == 0 { return nil } rp := devToUpload(d) deviceId := strconv.Itoa(sensorInfo.StationId) upData := WJHP.UploadHistoryData{ DeviceId: deviceId, Apikey: sensorInfo.AppKey, Data: map[string]WJHP.HistoryData{ deviceId: rp, }, } result, _ = json.Marshal(upData) return result } func (the Adaptor_SJWY_WJHP) matchStationId(devId string) (sensorInfo WJHP.SensorInfo) { if v, ok := the.IdMap.SjwySensorInfo[devId]; ok { sensorInfo = v } else { log.Printf("未匹配到设备[%s]的stationId", devId) } return sensorInfo } func devToUpload(deviceData WJHP.PosData) (result WJHP.HistoryData) { k := deviceData.Timestamp.Add(time.Hour * -8).Format("2006-01-02T15:04:05.000Z") d := WJHP.HistoryData{ L1_GP_1: map[string]string{ k: fmt.Sprintf("%0.3f,%0.3f,%0.3f", deviceData.XReal, 0.0, deviceData.YReal), }, } return d }