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.
79 lines
2.3 KiB
79 lines
2.3 KiB
2 weeks ago
|
package adaptors
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"goUpload/models"
|
||
|
"goUpload/utils"
|
||
|
"log"
|
||
|
"strings"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// Adaptor_ZD_MYX 振动DAAS数据 转换 湘潭健康监测平台
|
||
|
type Adaptor_ZD_MYX struct {
|
||
|
IdMap map[string]string
|
||
|
}
|
||
|
|
||
|
func (the Adaptor_ZD_MYX) Transform(rawMsg string) []byte {
|
||
|
zd := models.ZD{}
|
||
|
json.Unmarshal([]byte(rawMsg), &zd)
|
||
|
return the.ZDtoMYCInflux(zd)
|
||
|
}
|
||
|
|
||
|
func (the Adaptor_ZD_MYX) ZDtoMYCInflux(zd models.ZD) (result []byte) {
|
||
|
Atime := time.UnixMilli(zd.Ticks)
|
||
|
|
||
|
var sensorAccDataList = zd.AccValues
|
||
|
|
||
|
sensorCode := the.getSensorId(zd.Module)
|
||
|
|
||
|
if sensorCode == "" || len(sensorAccDataList) < 5 {
|
||
|
log.Printf("振动DAAS 设备[%s] 无匹配的明月峡id,请检查配置文件", zd.Module)
|
||
|
return
|
||
|
}
|
||
|
//振动DAAS数据 分为3种 :
|
||
|
// 1. 用来计算索力 2.用来计算梁体振动 3.用来船撞振动
|
||
|
//由于 船撞/地震振动监测 和 主梁振动监测 都是共用DAAS 无法区分监测类型,通过测点来获取表名
|
||
|
//测点如 CZDZJC001 表=CZDZJC, 测点ZLZDJC001 表=ZLZDJC
|
||
|
tableName := sensorCode[:6]
|
||
|
var sqlBuilder strings.Builder
|
||
|
|
||
|
sensorType := sensorCode[:2]
|
||
|
switch sensorType {
|
||
|
case "SL":
|
||
|
tableName = "XLSSLJC"
|
||
|
slTimeNanosecond := Atime.Add(-8 * time.Hour).UnixNano()
|
||
|
sqlBuilder.WriteString(fmt.Sprintf("%s,sensor_id=%s value=%f %d", tableName, sensorCode, zd.ThemeValue[0], slTimeNanosecond))
|
||
|
default:
|
||
|
switch sensorType {
|
||
|
case "CZ":
|
||
|
tableName = "CZDZJC"
|
||
|
case "ZD":
|
||
|
tableName = "ZLZDJC"
|
||
|
default:
|
||
|
log.Printf("无法识别的 sensorType=%s", sensorType)
|
||
|
}
|
||
|
for i, sensorData := range sensorAccDataList {
|
||
|
timeSpan := i * 1000000000 / zd.Frequency
|
||
|
dataTimeNanosecond := Atime.Add(-8 * time.Hour).Add(time.Nanosecond * time.Duration(timeSpan)).UnixNano()
|
||
|
sqlBuilder.WriteString(fmt.Sprintf("%s,sensor_id=%s value=%f %d", tableName, sensorCode, sensorData, dataTimeNanosecond))
|
||
|
sqlBuilder.WriteString("\n")
|
||
|
}
|
||
|
}
|
||
|
sqlBuilder.WriteString("\n")
|
||
|
sqlStr := sqlBuilder.String()
|
||
|
|
||
|
log.Printf("ZD [%s]-[%s]报文=\n %s... 设备时间%v", zd.Module, sensorCode, utils.LimitStringLength(sqlStr, 200), Atime)
|
||
|
result = []byte(sqlStr)
|
||
|
return result
|
||
|
}
|
||
|
func (the Adaptor_ZD_MYX) getSensorId(rawSensorName string) string {
|
||
|
v, isValid := the.IdMap[rawSensorName]
|
||
|
if !isValid {
|
||
|
v = ""
|
||
|
}
|
||
|
|
||
|
return v
|
||
|
}
|