9 changed files with 7870 additions and 6 deletions
@ -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 |
|||
} |
@ -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 |
|||
|
|||
|
File diff suppressed because it is too large
@ -0,0 +1,801 @@ |
|||
/* |
|||
* Version 1.3.1 |
|||
* 创建时间 2023–10-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; |
|||
} |
|||
|
@ -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 |
|||
} |
Loading…
Reference in new issue