数据 输入输出 处理
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

48 lines
1.3 KiB

package adaptors
import (
"encoding/json"
"fmt"
"goInOut/consumers/SinoGnssMySQL"
"strconv"
"time"
)
// 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.Add(8 * time.Hour).UnixMilli(),
//file_mqtt协议里面只解析RV, m=> mm
RawValue: []float64{gnssData.X * 1000, gnssData.Y * 1000, gnssData.H * 1000},
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
}