Browse Source

update 添加 果子沟 推送 中交华联 部分代码

dev
lucas 2 months ago
parent
commit
d9073ace75
  1. 192
      adaptors/知物云es主题特征to中交华联.go
  2. 32
      configFiles/config_知物云果子沟_中交华联_特征数据.yaml
  3. 8
      configFiles/弃用备份/config_河北省公路基础设施监测_承德_轻量化特征数据.yaml
  4. 3
      configFiles/弃用备份/config_河北省公路基础设施监测_秦皇岛_轻量化特征数据.yaml
  5. 6502
      consumers/GZG2ZJHL/protoFiles_zjhl/MonitorDataProtocol-V1.3.1.pb.go
  6. 801
      consumers/GZG2ZJHL/protoFiles_zjhl/MonitorDataProtocol-V1.3.1.proto
  7. 324
      consumers/consumerGZG2ZJHL.go
  8. 10
      consumers/consumerHBJCAS.go
  9. 4
      consumers/consumerManage.go

192
adaptors/知物云es主题特征to中交华联.go

@ -0,0 +1,192 @@
package adaptors
import (
"encoding/json"
"fmt"
"goInOut/consumers/GZG2ZJHL/protoFiles_zjhl"
//"goInOut/consumers/GZG2ZJHL/protoFiles_zjhl"
"goInOut/consumers/HBJCAS"
"goInOut/dbOperate"
"goInOut/models"
"google.golang.org/protobuf/proto"
"log"
"math"
"strconv"
"strings"
"time"
)
// Adaptor_ZWYES_ZJHL 知物云果子沟es 特征数据 to 中交华联平台
type Adaptor_ZWYES_ZJHL struct {
//传感器code转换信息
PointInfo map[int64]map[int64]int64
StructInfo map[int64]int64
//一些必要信息
Info map[string]string
Redis *dbOperate.RedisHelper
}
func (the Adaptor_ZWYES_ZJHL) Transform(structId int64, factorId int, rawMsg string) []NeedPush {
esAggDateHistogram := HBJCAS.EsThemeAggDateHistogram{}
var needPush []NeedPush
err := json.Unmarshal([]byte(rawMsg), &esAggDateHistogram)
if err != nil {
return nil
}
Payload := the.EsAggTopToHBJCAS(structId, factorId, esAggDateHistogram)
if len(Payload) == 0 {
return needPush
}
needPush = append(needPush, NeedPush{
Payload: Payload,
})
return needPush
}
func (the Adaptor_ZWYES_ZJHL) EsAggTopToHBJCAS(structId int64, factorId int, esAggs HBJCAS.EsThemeAggDateHistogram) (result []byte) {
buckets := esAggs.Aggregations.GroupSensor.Buckets
if len(buckets) == 0 {
log.Printf("[s=%d,f=%d] ,es agg数据数量==0", structId, factorId)
return
}
//设施唯一编码(省平台)
uniqueCode := the.getUniqueCode(structId)
if uniqueCode == 0 {
log.Printf("structId=%d,无匹配省平台uniqueCode", structId)
return
}
//数据汇总
complexData := &protoFiles_zjhl.ComplexData{}
for _, sensorBucket := range buckets {
sensorId := sensorBucket.Key
for _, dateBucket := range sensorBucket.GroupDate.Buckets {
//优先redis获取
station := models.Station{}
k1 := fmt.Sprintf("station:%d", sensorId)
errRedis := the.Redis.GetObj(k1, &station)
if errRedis != nil {
log.Printf("redis 获取[s:%d,f:%d]测点[%d]标签异常", structId, factorId, sensorId)
continue
}
monitorCode := the.getPointCodeFromLabel(station.Labels)
if monitorCode == 0 {
log.Printf("redis 获取[s:%d,f:%d]测点[%d]标签,信息转换int64异常,跳过", structId, factorId, sensorId)
continue
}
dataDefinition := &protoFiles_zjhl.DataDefinition{
DataType: protoFiles_zjhl.DataType_STATISTICS,
//BridgeCode: fmt.Sprintf("%d", uniqueCode), //提示 不传该字段
DataBody: the.EsAgg2StatisticData(factorId, monitorCode, dateBucket),
}
complexData.SensorData = append(complexData.SensorData, dataDefinition)
}
}
v, _ := json.Marshal(complexData)
log.Printf("[s:%d,f:%d] 特征数据=> %s", structId, factorId, v)
result, _ = proto.Marshal(complexData)
return result
}
func (the Adaptor_ZWYES_ZJHL) getMonitorTypeByFactorId(factorId int) protoFiles_zjhl.MonitoryType {
//桥墩倾斜 15 裂缝18 支座位移20 桥面振动28 加速度三项监测592
switch factorId {
case 15:
return protoFiles_zjhl.MonitoryType_INC
case 18:
return protoFiles_zjhl.MonitoryType_CRK
case 20:
return protoFiles_zjhl.MonitoryType_DIS
case 28:
return protoFiles_zjhl.MonitoryType_VIB
case 592:
return protoFiles_zjhl.MonitoryType_VIB
default:
log.Printf("factorId=%d,无匹配的MonitorType", factorId)
return protoFiles_zjhl.MonitoryType_CMM
}
}
func (the Adaptor_ZWYES_ZJHL) EsAgg2StatisticData(factorId int, monitorCode int64, dateBucket HBJCAS.BucketsXY) *protoFiles_zjhl.DataDefinition_StatisticData {
Atime := dateBucket.KeyAsString.Add(-8 * time.Hour).UnixMilli()
maxAbsoluteValueX := max(math.Abs(dateBucket.X.Max), math.Abs(dateBucket.X.Min))
avgValueX := dateBucket.X.Avg
rootMeanSquareX := math.Sqrt(dateBucket.X.SumOfSquares / float64(dateBucket.X.Count))
maxAbsoluteValueY := max(math.Abs(dateBucket.Y.Max), math.Abs(dateBucket.Y.Min))
avgValueY := dateBucket.Y.Avg
rootMeanSquareY := math.Sqrt(dateBucket.Y.SumOfSquares / float64(dateBucket.Y.Count))
monitoryType := the.getMonitorTypeByFactorId(factorId)
dataDefinitionStatisticData := &protoFiles_zjhl.DataDefinition_StatisticData{
StatisticData: &protoFiles_zjhl.StatisticData{
MonitorType: monitoryType,
MonitorCode: monitorCode, //测点唯一编码
EventTime: Atime,
Interval: 60 * 1000,
},
}
switch factorId {
case 15: //倾角
dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_zjhl.StatisticData_Inc{Inc: &protoFiles_zjhl.INCStatistic{
MaxAbsoluteValueX: float32(maxAbsoluteValueX),
AvgValueX: float32(avgValueX),
RootMeanSquareX: float32(rootMeanSquareX),
MaxAbsoluteValueY: float32(maxAbsoluteValueY),
AvgValueY: float32(avgValueY),
RootMeanSquareY: float32(rootMeanSquareY),
}}
case 18: //裂缝监测
dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_zjhl.StatisticData_Crk{Crk: &protoFiles_zjhl.CRKStatistic{
MaxAbsoluteValue: float32(maxAbsoluteValueX),
AvgValue: float32(avgValueX),
RootMeanSquare: float32(rootMeanSquareX),
TotalAbsoluteValue: float32(dateBucket.X.Max - dateBucket.X.Min),
}}
case 20: //支座位移
dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_zjhl.StatisticData_Dis{Dis: &protoFiles_zjhl.DISStatistic{
MaxAbsoluteValue: float32(maxAbsoluteValueX),
AvgValue: float32(avgValueX),
RootMeanSquare: float32(rootMeanSquareX),
TotalAbsoluteValue: float32(dateBucket.X.Max - dateBucket.X.Min),
}}
case 28: //振动
dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_zjhl.StatisticData_Vib{Vib: &protoFiles_zjhl.VIBStatistic{
MaxAbsoluteValue: float32(maxAbsoluteValueX),
RootMeanSquare: float32(rootMeanSquareY),
}}
case 592: //加速度三项监测
dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_zjhl.StatisticData_Vib{Vib: &protoFiles_zjhl.VIBStatistic{
MaxAbsoluteValue: float32(maxAbsoluteValueX),
RootMeanSquare: float32(rootMeanSquareX),
}}
}
return dataDefinitionStatisticData
}
func (the Adaptor_ZWYES_ZJHL) getUniqueCode(structId int64) (uniqueCode int64) {
if v, ok := the.StructInfo[structId]; ok {
uniqueCode = v
}
return uniqueCode
}
func (the Adaptor_ZWYES_ZJHL) getPointCodeFromLabel(label string) int64 {
//解析label {13010600001}
pointUniqueCode := int64(0)
if len(label) > 2 {
newLabel := strings.TrimLeft(label, "{")
str := strings.TrimRight(newLabel, "}")
codeInt64, err := strconv.ParseInt(str, 10, 64)
if err != nil {
log.Printf("测点标签转换异常[%s]", label)
}
pointUniqueCode = codeInt64
}
return pointUniqueCode
}

32
configFiles/config_知物云果子沟_中交华联_特征数据.yaml

@ -0,0 +1,32 @@
consumer: consumerGZG2ZJHL
ioConfig:
in:
http:
url: https://esproxy.anxinyun.cn/savoir_themes/_search
out:
mqtt:
host: 124.205.140.18
port: 1883
userName: bridge
password: bridge123456
clientId: bridge_goinout
topics:
- t/gzgyy0219
monitor:
#振动是触发式,数据迟缓 cron10min也改成1小时一次 最多上报6条,不进行10min实时上报
cron10min: 29 0/1 * * * #6/10 * * * *
#普通类型 特征数据
cron1hour: 06 0/1 * * *
info:
rc4key: t/gzgyy0219
queryComponent:
redis:
address: 10.8.30.160:30379
#结构物id对应
structInfo:
#果子沟5296 -> 映射对方平台id
5296: 136004
#点位id对应信息
pointInfo: #测点类型支持 桥墩倾斜 15 裂缝18 支座位移20 桥面振动28

8
configFiles/config_河北省公路基础设施监测_承德_轻量化特征数据.yaml → configFiles/弃用备份/config_河北省公路基础设施监测_承德_轻量化特征数据.yaml

@ -14,13 +14,11 @@ ioConfig:
- t/province/1307 - t/province/1307
monitor: monitor:
#振动是触发式,数据迟缓 cron10min也改成1小时一次 最多上报6条,不进行10min实时上报 #振动是触发式,数据迟缓 cron10min也改成1小时一次 最多上报6条,不进行10min实时上报
cron10min: 40 0/1 * * * #6/10 * * * * cron10min: 22 0/1 * * * #6/10 * * * *
#普通类型 特征数据 #普通类型 特征数据
cron1hour: 20 0/1 * * * cron1hour: 20 0/1 * * *
info: info:
rc4key: sK3kJttzZyf7aZI94zSYgytBYCrfZRt6yil2 rc4key: sK3kJttzZyf7aZI94zSYgytBYCrfZRt6yil2
queryComponent: queryComponent:
redis: redis:
address: 10.8.30.160:30379 address: 10.8.30.160:30379
@ -28,8 +26,8 @@ queryComponent:
structInfo: structInfo:
5011: 130110 5011: 130110
5016: 130109 5016: 130109
5017: 130112
#点位id对应信息 #点位id对应信息
pointInfo: #测点类型支持 桥墩倾斜 15 裂缝18 支座位移20 桥面振动28 pointInfo: #测点类型支持 桥墩倾斜 15 裂缝18 支座位移20 桥面振动28 加速度三项监测592(承德隧道专用)

3
configFiles/config_河北省公路基础设施监测_秦皇岛_轻量化特征数据.yaml → configFiles/弃用备份/config_河北省公路基础设施监测_秦皇岛_轻量化特征数据.yaml

@ -14,7 +14,7 @@ ioConfig:
- t/province/1308 - t/province/1308
monitor: monitor:
#振动是触发式,数据迟缓 cron10min也改成1小时一次 最多上报6条,不进行10min实时上报 #振动是触发式,数据迟缓 cron10min也改成1小时一次 最多上报6条,不进行10min实时上报
cron10min: 35 0/1 * * * #6/10 * * * * cron10min: 29 0/1 * * * #6/10 * * * *
#普通类型 特征数据 #普通类型 特征数据
cron1hour: 45 0/1 * * * cron1hour: 45 0/1 * * *
info: info:
@ -24,6 +24,7 @@ queryComponent:
address: 10.8.30.160:30379 address: 10.8.30.160:30379
#结构物id对应 #结构物id对应
structInfo: structInfo:
5222: 136004
4993: 130140 4993: 130140
#点位id对应信息 #点位id对应信息
pointInfo: #测点类型支持 桥墩倾斜 15 裂缝18 支座位移20 桥面振动28 pointInfo: #测点类型支持 桥墩倾斜 15 裂缝18 支座位移20 桥面振动28

6502
consumers/GZG2ZJHL/protoFiles_zjhl/MonitorDataProtocol-V1.3.1.pb.go

File diff suppressed because it is too large

801
consumers/GZG2ZJHL/protoFiles_zjhl/MonitorDataProtocol-V1.3.1.proto

@ -0,0 +1,801 @@
/*
* Version 1.3.1
* 202310-11
*/
// protobuf的版本proto3是最新的语法版本
syntax = "proto3";
option go_package = "../protoFiles_zjhl";
package protoFiles_zjhl;
enum DataType {REALTIME = 0;STATISTICS = 1; EMERGENCY = 2; INSPECTION = 3;}
enum MonitoryType {
//
UAN = 0;
//湿
RHS = 1;
//
GNSS = 2;
//
VIC = 3;
//
DIC = 4 ;
//
DIS = 5;
//
HPT = 6;
//
RSG = 7;
//
INC = 8;
//
VIB = 9;
//
VIE = 10;
//TMD监测
TMD = 11;
//
HSD = 12;
//
TMP = 13;
//
PWS = 14;
//
FRZ = 15;
//
LMZ = 16;
//
STF = 17;
//
SCO = 18;
//
CRK = 19;
//
COR = 20;
//
VIS = 21;
//
STR = 22;
//
BRK = 23;
//
BTF = 24;
//
CSP = 25;
//
VSB = 26;
//
ACN = 27;
//
WLV = 28;
//
CMM = 99;
}
//
message ComplexData{
//CRC后进行加密
repeated DataDefinition sensorData = 1;
}
//
message DataDefinition{
DataType dataType = 1;
//
string bridgeCode = 14;
oneof dataBody{
//
RealTimeData realTimeData = 2;
//
StatisticData statisticData = 3;
}
}
message RealTimeData{
//
MonitoryType monitorType = 1;
//
int64 monitorCode = 2;
//
int64 eventTime = 3;
//
int32 interval = 100;
oneof dataBody{
//
//
UANRealTime uan = 4;
//湿
RHSRealTime rhs = 5;
//
TMPRealTime tmp = 6;
//
GNSSRealTime gnss = 7;
//
VICRealTime vic = 8;
DICRealTime dic = 9;
//
DISRealTime dis = 10;
//
HPTRealTime hpt = 11;
//
RSGRealTime rsg = 12;
//
INCRealTime inc = 13;
//
VIERealTime vie = 14;
//TMD
TMDRealTime tmd = 15;
//
VIBRealTime vib = 16;
//
HSDRealTime hsd = 17;
//
PWSRealTime pws = 18;
//
FRZRealTime frz = 19;
//
LMZRealTime lmz = 20;
//
STFRealTime stf = 21;
//
SCORealTime sco = 22;
//
CRKRealTime crk = 23;
//
CORRealTime cor = 25;
//
VISRealTime vis = 26;
//
STRRealTime str = 27;
//
BRKRealTime brk = 28;
//
BTFRealTime btf = 29;
//
CSPRealTime csp = 30;
//
VSBRealTime vsb = 31;
//
ACNRealTime acn = 32;
//
WLVRealTime wlv =33;
}
}
/*
*/
//hsd
message UANRealTime{
//
float windVelocity = 1;
//
float windDirection = 2;
//
optional float windAttackAngle = 3;
}
//湿
message RHSRealTime{
//
float temperature = 1;
//湿
float humidity = 2;
}
//
message TMPRealTime{
//
float temperature = 1;
}
//
message GNSSRealTime{
//
float x = 1;
//
float y = 2;
//
float z = 3;
}
//
message VICRealTime{
//
float cableForce = 1;
//
optional float fundamentalFrequency = 2;
}
//
message DISRealTime{
//
float displacement = 1;
//
optional float temperature = 2;
}
//
message CRKRealTime{
//
float crackWidth = 1;
//
optional float temperature = 2;
}
//
message HPTRealTime{
//
float deflection = 1;
//
optional float temperature = 2;
}
//
message RSGRealTime{
//
float strain = 1;
//
optional float temperature = 2;
}
//
message INCRealTime{
// X
float x = 1;
//Y
float y = 2;
//
repeated float temperature = 3 [packed = true];
}
//
message VIBRealTime{
repeated float monitorValues = 1 [packed = true];
}
//
message VIERealTime{
//
repeated float monitorValues = 1 [packed = true];
}
//TMD
message TMDRealTime{
repeated float monitorValues = 1 [packed = true];
}
// --
message HSDRealTime{
//
int32 laneId = 1;
//
int32 operDirec = 2;
//
int32 axleNum = 3;
//
int32 axleGrpNum = 4;
//
int32 grossLoad = 5;
//
int32 vehType = 6;
//1
int32 leftWheelWeight1 = 7;
//2
int32 leftWheelWeight2 = 8;
//3
int32 leftWheelWeight3 = 9;
//4
int32 leftWheelWeight4 = 10;
//5
int32 leftWheelWeight5 = 11;
//6
int32 leftWheelWeight6 = 12;
//7
int32 leftWheelWeight7 = 13;
//8
int32 leftWheelWeight8 = 14;
//1
int32 rightWheelWeight1 = 15;
//2
int32 rightWheelWeight2 = 16;
//3
int32 rightWheelWeight3 = 17;
//4
int32 rightWheelWeight4 = 18;
//5
int32 rightWheelWeight5 = 19;
//6
int32 rightWheelWeight6 = 20;
//7
int32 rightWheelWeight7 = 21;
//8
int32 rightWheelWeight8 = 22;
//1-2
int32 axleDis1 = 23;
//2-3
int32 axleDis2 = 24;
//3-4
int32 axleDis3 = 25;
//4-5
int32 axleDis4 = 26;
//5-6
int32 axleDis5 = 27;
//6-7
int32 axleDis6 = 28;
//7-8
int32 axleDis7 = 29;
//
optional int32 violationId = 30;
//
optional int32 overloadSign = 31;
//
int32 speed = 32;
//
optional float acceleration = 33;
//
int32 vehLength = 34;
//
optional float qat = 35;
//
optional string licencePlate = 36;
//
optional string licencePlateColor = 37;
//id
optional int32 picId = 38;
//
optional float roadTemperature = 39;
}
//
message PWSRealTime{
//
float rainfall = 1;
}
//
message FRZRealTime{
//
float iceThickness = 1 ;
//
float temperature = 2 ;
}
//
message LMZRealTime{
//
float roadCondition = 1;
//
float temperature = 2;
}
//
message DICRealTime{
//
float cableForce = 1;
//
float temperature = 2 ;
}
//
message STFRealTime{
//
float supportAction = 1 ;
//
float temperature = 2 ;
}
//
message SCORealTime{
//
float depth = 1;
}
//
message CORRealTime{
//
float chlorideConcentration = 1 ;
//
float corrosionDepth = 2 ;
}
//
message VISRealTime{
//
repeated float monitorValues = 1 [packed = true];
}
//
message STRRealTime{
//
float stress = 1 ;
//
optional float temperature = 2 ;
}
//
message BRKRealTime{
//
bool state = 1;
}
//
message BTFRealTime{
//
float boltTightForce = 1;
//
optional float temperature = 2;
}
//
message CSPRealTime{
//
float displacement = 1 ;
//
optional float temperature = 2;
}
//
message VSBRealTime{
//
float value = 1;
}
//
message ACNRealTime{
//
float value = 1;
}
//
message WLVRealTime{
//
float value = 1;
}
/*
*/
//
message StatisticData{
//
MonitoryType monitorType = 1;
//
int64 monitorCode = 2;
//
int64 eventTime = 3;
//
int32 interval = 100;
oneof dataBody{
//
UANStatistic uan = 4;
//湿
RHSStatistic rhs = 5;
//
TMPStatistic tmp = 6;
//
GNSSStatistic gnss = 7;
//
VICStatistic vic = 8;
//
DISStatistic dis = 9;
//
HPTStatistic hpt = 10;
//
RSGStatistic rsg = 11;
//
INCStatistic inc = 12;
//
VIEStatistic vie = 13;
//TMD
TMDStatistic tmd = 14;
//
VIBStatistic vib = 15;
//
HSDStatistic hsd = 16;
//
ANDStatistic and = 17;
//
CRKStatistic crk = 18;
//
FRZStatistic frz = 19;
//
PWSStatistic pws = 20;
//
VSBStatistic vsb = 21;
//
ACNStatistic acn = 22;
//
WLVStatistic wlv = 23;
//
BTFStatistic btf = 24;
//
CSPStatistic csp = 25;
}
}
// 10min
message UANStatistic{
//
float avgVelocity = 1;
//
float avgDirection = 2;
//
optional float avgAttackAngle = 3;
}
//湿 1h
message RHSStatistic{
//
float maxTemperature = 1;
//
float minTemperature = 2;
//
float avgTemperature = 3;
//
float maxTemperatureDifference = 4;
//湿
float maxHumidity = 5;
//湿
float minHumidity = 6;
//湿
float avgHumidity = 7;
//湿,
int32 humidityExceedDuration = 8;
}
// 1h
message TMPStatistic{
//
float maxTemperature = 1;
//
float minTemperature = 2;
//
float avgTemperature = 3;
//
float maxDifference = 4;
}
// 1h
message GNSSStatistic{
//X绝对最大值
float maxAbsoluteValueX = 1;
//X平均值
float avgValueX = 2;
//X均方根
float rootMeanSquareX = 3;
//Y绝对最大值
float maxAbsoluteValueY = 4;
//Y平均值
float avgValueY = 5;
//Y均方根
float rootMeanSquareY = 6;
//Z绝对最大值
float maxAbsoluteValueZ = 7;
//Z平均值
float avgValueZ = 8;
//Z均方根
float rootMeanSquareZ = 9;
}
// 24h
message ANDStatistic{
//X绝对最大值
float maxAbsoluteValueX = 1;
//X平均值
float avgValueX = 2;
//X均方根
float rootMeanSquareX = 3;
//Y绝对最大值
float maxAbsoluteValueY = 4;
//Y平均值
float avgValueY = 5;
//Y均方根
float rootMeanSquareY = 6;
//Z绝对最大值
float maxAbsoluteValueZ = 7;
//Z平均值
float avgValueZ = 8;
//Z均方根
float rootMeanSquareZ = 9;
}
// 1h
message DISStatistic{
//
float maxAbsoluteValue = 1;
//
float avgValue = 2;
//
float rootMeanSquare = 3;
//
float totalAbsoluteValue = 4;
}
// 1h
message HPTStatistic{
//
float maxAbsoluteValue = 1;
//
float avgValue = 2;
//
float rootMeanSquare = 3;
}
// 1h
message INCStatistic{
//
float maxAbsoluteValueX = 1;
//
float avgValueX = 2;
//
float rootMeanSquareX = 3;
//
float maxAbsoluteValueY = 4;
//
float avgValueY = 5;
//
float rootMeanSquareY = 6;
}
// 1h
message RSGStatistic{
///
float maxAbsoluteValue = 1;
///
float avgValue = 2;
//
optional float avgTemperature = 3;
}
// 1h
message VICStatistic{
//
float maxValue = 1;
//
float minValue = 2;
//
float avgValue = 3;
//
float rootMeanSquare = 4;
}
// 10min
message VIBStatistic{
//
float maxAbsoluteValue = 1;
//
float rootMeanSquare = 2;
}
// 10min
message VIEStatistic{
//
float maxAbsoluteValue = 1;
//
float rootMeanSquare = 2;
}
//TMD监测特征值 10min
message TMDStatistic{
//
float maxAbsoluteValue = 1;
//
float rootMeanSquare = 2;
}
// - 1h
message HSDStatistic{
//
int32 trafficFlow = 1;
//
int32 maxTotalLoad = 2;
//
int32 maxAxleLoad = 3;
//
int32 overLoadCount = 4;
}
// 1h)
message CRKStatistic{
//
float maxAbsoluteValue = 1;
//
float avgValue = 2;
//
float rootMeanSquare = 3;
//
float totalAbsoluteValue = 4;
}
//( 1h)
message FRZStatistic{
//
float maxValue = 1;
//
float minValue = 2;
//
float avgValue = 3;
}
//( 10min)
message PWSStatistic{
//
float avgValue = 1;
}
//( 10min)
message VSBStatistic{
//
float avgValue = 1;
}
//( 1h)
message ACNStatistic{
//
float maxValue = 1;
//
float minValue = 2;
//
float avgValue = 3;
}
//( 1h)
message WLVStatistic{
//
float maxValue = 1;
//
float minValue = 2;
//
float avgValue = 3;
}
//( 1h)
message BTFStatistic{
//
float avgValue = 1;
//
float maxAbsoluteValue = 2;
//
float rootMeanSquare = 3;
}
//( 1h)
message CSPStatistic{
//
float avgValue = 1;
//
float maxAbsoluteValue = 2;
//
float rootMeanSquare = 3;
}

324
consumers/consumerGZG2ZJHL.go

@ -0,0 +1,324 @@
package consumers
import (
"crypto/rc4"
"encoding/hex"
"fmt"
"goInOut/adaptors"
"goInOut/consumers/HBJCAS"
"goInOut/dbOperate"
"goInOut/monitors"
"goInOut/utils"
"gopkg.in/yaml.v3"
"log"
"time"
)
type consumerGZG2ZJHL struct {
//数据缓存管道
ch chan []adaptors.NeedPush
//具体配置
Info HBJCAS.ConfigFile
InHttp *dbOperate.HttpHelper
outMqtt *dbOperate.MqttHelper
monitor *monitors.CommonMonitor
infoRedis *dbOperate.RedisHelper
}
func (the *consumerGZG2ZJHL) LoadConfigJson(cfgStr string) {
// 将 yaml 格式的数据解析到结构体中
err := yaml.Unmarshal([]byte(cfgStr), &the.Info)
if err != nil {
log.Printf("读取配置文件[%s]异常 err=%v", cfgStr, err.Error())
panic(err)
}
}
func (the *consumerGZG2ZJHL) Initial(cfg string) error {
the.LoadConfigJson(cfg)
err := the.InputInitial()
if err != nil {
return err
}
err = the.OutputInitial()
if err != nil {
return err
}
err = the.infoComponentInitial()
return err
}
func (the *consumerGZG2ZJHL) InputInitial() error {
the.ch = make(chan []adaptors.NeedPush, 200)
//数据入口
the.InHttp = &dbOperate.HttpHelper{Url: the.Info.IoConfig.In.Http.Url, Token: ""}
the.monitor = &monitors.CommonMonitor{
MonitorHelper: &monitors.MonitorHelper{},
}
the.monitor.Start()
for taskName, cron := range the.Info.Monitor {
switch taskName {
case "cron10min":
//the.monitor.RegisterTask(cron, the.getEs10minAggData)
case "cron1hour":
the.monitor.RegisterTask(cron, the.getEs1HourAggData)
default:
log.Printf("定时任务[%s],cron=[%s] 无匹配", taskName, cron)
}
}
return nil
}
func (the *consumerGZG2ZJHL) OutputInitial() error {
//数据出口
the.outMqtt = dbOperate.MqttInitial(
the.Info.IoConfig.Out.Mqtt.Host,
the.Info.IoConfig.Out.Mqtt.Port,
the.Info.IoConfig.Out.Mqtt.ClientId,
the.Info.IoConfig.Out.Mqtt.UserName,
the.Info.IoConfig.Out.Mqtt.Password,
true, //按照具体项目来
"consumers/HBJCAS/ssl/cacert.pem",
"consumers/HBJCAS/ssl/client-cert.pem",
"consumers/HBJCAS/ssl/client-key.pem")
return nil
}
func (the *consumerGZG2ZJHL) infoComponentInitial() error {
//数据出口
addr := the.Info.QueryComponent.Redis.Address
the.infoRedis = dbOperate.NewRedisHelper("", addr)
return nil
}
func (the *consumerGZG2ZJHL) Work() {
go func() {
for {
needPushList := <-the.ch
if len(the.ch) > 0 {
log.Printf("取出ch数据,剩余[%d] ", len(the.ch))
}
for _, push := range needPushList {
if push.Topic != "" {
the.outMqtt.Publish(push.Topic, push.Payload)
continue
}
//没有标记topic 的 按照配置文件里面的推送
for _, topic := range the.Info.IoConfig.Out.Mqtt.Topics {
the.outMqtt.Publish(topic, push.Payload)
}
}
time.Sleep(100 * time.Millisecond)
}
}()
}
func (the *consumerGZG2ZJHL) getAdaptor() (adaptor adaptors.Adaptor_ZWYES_ZJHL) {
return adaptors.Adaptor_ZWYES_ZJHL{
Redis: the.infoRedis,
}
}
func (the *consumerGZG2ZJHL) getStructIds() []int64 {
var structIds []int64
for strutId, _ := range the.Info.StructInfo {
structIds = append(structIds, strutId)
}
return structIds
}
func (the *consumerGZG2ZJHL) getEs1HourAggData() {
start, end := utils.GetTimeRangeByHour(-1)
log.Printf("查询数据时间范围 %s - %s", start, end)
hourFactorIds := []int{4} // 15, 18, 20
structIds := the.getStructIds()
for _, structId := range structIds {
for _, factorId := range hourFactorIds {
esQuery := the.getESQueryStrByHour(structId, factorId, start, end)
auth := map[string]string{"Authorization": "Bear 85a441d4-022b-4613-abba-aaa8e2693bf7"}
esAggResultStr := the.InHttp.HttpGetWithHeader(esQuery, auth)
adaptor := the.getAdaptor()
adaptor.PointInfo = the.Info.PointInfo
adaptor.StructInfo = the.Info.StructInfo
needPushes := adaptor.Transform(structId, factorId, esAggResultStr)
for i := range needPushes {
needPushes[i].Payload = the.crc16rc4(needPushes[i].Payload)
}
if len(needPushes) > 0 {
the.ch <- needPushes
}
}
}
}
func (the *consumerGZG2ZJHL) getEs10minAggData() {
//utils.GetTimeRangeBy10min() 由于振动数据实时性问题 改用一小时统一上报
start, end := utils.GetTimeRangeByHour(-1)
log.Printf("查询10min数据时间范围 %s - %s", start, end)
factorIds := []int{28, 592} //监测因素 592 -> 结构物[5222]隧道河北承德广仁岭隧道(上行) 的加速度三项监测
structIds := the.getStructIds()
for _, structId := range structIds {
for _, factorId := range factorIds {
esQuery := the.getESQueryStrBy10min(structId, factorId, start, end)
auth := map[string]string{"Authorization": "Bear 85a441d4-022b-4613-abba-aaa8e2693bf7"}
esAggResultStr := the.InHttp.HttpGetWithHeader(esQuery, auth)
adaptor := the.getAdaptor()
adaptor.PointInfo = the.Info.PointInfo
adaptor.StructInfo = the.Info.StructInfo
needPushes := adaptor.Transform(structId, factorId, esAggResultStr)
for i := range needPushes {
needPushes[i].Payload = the.crc16rc4(needPushes[i].Payload)
log.Printf("topic[%s],Payload=> %s", needPushes[i].Topic, hex.EncodeToString(needPushes[i].Payload))
}
if len(needPushes) > 0 {
the.ch <- needPushes
}
}
}
}
func (the *consumerGZG2ZJHL) crc16rc4(transBytes []byte) []byte {
resultByCrc16 := utils.NewCRC16CCITT().GetWCRCin(transBytes)
needRC4 := append(transBytes, resultByCrc16...)
rc4KeyStr, ok := the.Info.OtherInfo["rc4key"]
if !ok {
log.Panicf("未配置 rc4key")
}
rc4Key := []byte(rc4KeyStr) //the.RC4Key
// 加密操作
dest1 := make([]byte, len(needRC4))
rc4.NewCipher(rc4Key)
cipher1, _ := rc4.NewCipher(rc4Key)
cipher1.XORKeyStream(dest1, needRC4)
return dest1
}
func (the *consumerGZG2ZJHL) getESQueryStrByHour(structureId int64, factorId int, start, end string) string {
aggSubSql := getEsAggSubSqlByFactorId(factorId)
esQuery := fmt.Sprintf(`
{
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"structure": {
"value": %d
}
}
},
{
"term": {
"factor": {
"value": %d
}
}
},
{
"range": {
"collect_time": {
"gte": "%s",
"lt": "%s"
}
}
}
]
}
},
"aggs": {
"groupSensor": {
"terms": {
"field": "sensor"
},
"aggs": {
"groupDate": {
"date_histogram": {
"field": "collect_time",
"interval": "1h",
"time_zone": "Asia/Shanghai",
"min_doc_count": 1
},
"aggs": %s
}
}
}
}
}
`, structureId, factorId, start, end, aggSubSql)
return esQuery
}
func (the *consumerGZG2ZJHL) getESQueryStrBy10min(structureId int64, factorId int, start, end string) string {
aggSubSql := getEsAggSubSqlByFactorId(factorId)
esQuery := fmt.Sprintf(`
{
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"structure": {
"value": %d
}
}
},
{
"term": {
"factor": {
"value": %d
}
}
},
{
"range": {
"collect_time": {
"gte": "%s",
"lte": "%s"
}
}
}
]
}
},
"aggs": {
"groupSensor": {
"terms": {
"field": "sensor"
},
"aggs": {
"groupDate": {
"date_histogram": {
"field": "collect_time",
"interval": "10m",
"time_zone": "Asia/Shanghai",
"min_doc_count": 1
},
"aggs": %s
}
}
}
}
}
`, structureId, factorId, start, end, aggSubSql)
return esQuery
}
func (the *consumerGZG2ZJHL) getStructureId() string {
structureId, ok := the.Info.OtherInfo["structureId"]
if !ok {
log.Panicf("无法识别有效的structureId")
}
return structureId
}

10
consumers/consumerHBJCAS.go

@ -317,8 +317,18 @@ func (the *consumerHBJCAS) getESQueryStrBy10min(structureId int64, factorId int,
func getEsAggSubSqlByFactorId(factorId int) string { func getEsAggSubSqlByFactorId(factorId int) string {
//桥墩倾斜 15 裂缝 18 支座位移20 桥面振动28 加速度三项监测592(承德隧道专用) //桥墩倾斜 15 裂缝 18 支座位移20 桥面振动28 加速度三项监测592(承德隧道专用)
//温度4 果子沟上报
subAggSQl := "" subAggSQl := ""
switch factorId { switch factorId {
case 4:
subAggSQl = `
{
"x": {
"extended_stats": {
"field": "data.temperature"
}
}
}`
case 15: case 15:
subAggSQl = ` subAggSQl = `
{ {

4
consumers/consumerManage.go

@ -34,6 +34,10 @@ func GetConsumer(name string) (consumer IConsumer) {
case "consumerHBJCAS": case "consumerHBJCAS":
consumer = new(consumerHBJCAS) consumer = new(consumerHBJCAS)
case "consumerGZG2ZJHL":
consumer = new(consumerGZG2ZJHL)
default: default:
consumer = nil consumer = nil
} }

Loading…
Cancel
Save