数据 输入输出 处理
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.

78 lines
2.2 KiB

package adaptors
import (
"encoding/json"
"github.com/labstack/gommon/log"
"goInOut/consumers/HBJCAS/protoFiles_hb"
"goInOut/models"
"google.golang.org/protobuf/proto"
"time"
)
// Adaptor_AXYES_HBGL 统一采集软件数据 转换 湘潭健康监测平台
type Adaptor_AXYES_HBGL struct {
//传感器code转换信息
GnssMap map[string]string
RainMap map[string]string
NBWYMap map[string]string
DXSWMap map[string]string
//一些必要信息
Info map[string]string
}
func (the Adaptor_AXYES_HBGL) Transform(rawMsg string) []NeedPush {
esAggDateHistogram := models.EsThemeAggDateHistogram{}
var needPush []NeedPush
err := json.Unmarshal([]byte(rawMsg), &esAggDateHistogram)
if err != nil {
return nil
}
needPush = append(needPush, NeedPush{
Payload: the.EsAggTopToHBJCAS(esAggDateHistogram),
})
return needPush
}
func (the Adaptor_AXYES_HBGL) EsAggTopToHBJCAS(esAggs models.EsThemeAggDateHistogram) (result []byte) {
buckets := esAggs.Aggregations.GroupSensor.Buckets
if len(buckets) == 0 {
log.Info("es agg数据数量==0")
return
}
//数据汇总
complexData := &protoFiles_hb.ComplexData{}
for _, sensorBucket := range buckets {
//sensorId := sensorBucket.Key
for _, dateBucket := range sensorBucket.GroupDate.Buckets {
Atime := dateBucket.KeyAsString
dataDefinitionStatisticData := &protoFiles_hb.DataDefinition_StatisticData{
StatisticData: &protoFiles_hb.StatisticData{
MonitorType: protoFiles_hb.MonitoryType_INC,
MonitorCode: 13000100001, //测点唯一编码
EventTime: Atime.Add(-8 * time.Hour).UnixMilli(),
Interval: 60 * 1000,
DataBody: &protoFiles_hb.StatisticData_Inc{Inc: &protoFiles_hb.INCStatistic{
MaxAbsoluteValueX: 0,
AvgValueX: 0,
RootMeanSquareX: 0,
MaxAbsoluteValueY: 0,
AvgValueY: 0,
RootMeanSquareY: 0,
}},
},
}
dataDefinition := &protoFiles_hb.DataDefinition{
DataType: protoFiles_hb.DataType_STATISTICS,
UniqueCode: "130109", //乃积沟大桥
DataBody: dataDefinitionStatisticData,
}
complexData.SensorData = append(complexData.SensorData, dataDefinition)
}
}
result, _ = proto.Marshal(complexData)
return result
}