|
|
|
package adaptors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"goInOut/consumers/SinoGnssMySQL"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Adaptor_SINOMYSQL_AXYMQTT 数据 转换 江苏农村公路桥梁监测系统
|
|
|
|
type Adaptor_SINOMYSQL_AXYMQTT struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (the Adaptor_SINOMYSQL_AXYMQTT) Transform(gnssDataList []SinoGnssMySQL.GnssData) []NeedPush {
|
|
|
|
var needPush []NeedPush
|
|
|
|
allDxFiles := make(map[string][]SinoGnssMySQL.DxFile)
|
|
|
|
for _, gnssData := range gnssDataList {
|
|
|
|
OnceDxFiles := allDxFiles[gnssData.GroupName]
|
|
|
|
OnceDxFiles = append(OnceDxFiles, SinoGnssMySQL.DxFile{
|
|
|
|
Module: gnssData.StationName,
|
|
|
|
Channel: 1,
|
|
|
|
Timespan: gnssData.Time.UnixMilli(),
|
|
|
|
RawValue: []float64{gnssData.X, gnssData.Y, gnssData.H}, //file_mqtt协议里面只解析RV
|
|
|
|
LimitValue: []float64{},
|
|
|
|
PhyValue: []float64{},
|
|
|
|
ThemeValue: []float64{},
|
|
|
|
})
|
|
|
|
allDxFiles[gnssData.GroupName] = OnceDxFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
for groupName, groupFileList := range allDxFiles {
|
|
|
|
contentMap := make(map[string]string)
|
|
|
|
for i, file := range groupFileList {
|
|
|
|
bs, _ := json.Marshal(file)
|
|
|
|
contentMap[strconv.Itoa(i)] = string(bs)
|
|
|
|
}
|
|
|
|
gpContent, _ := json.Marshal(contentMap)
|
|
|
|
topic := fmt.Sprintf("SinoGnss/%s/", groupName)
|
|
|
|
needPush = append(needPush, NeedPush{
|
|
|
|
Topic: topic,
|
|
|
|
Payload: gpContent,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return needPush
|
|
|
|
}
|