|
|
@ -47,10 +47,20 @@ func (the *consumerHBJCAS) InputInitial() error { |
|
|
|
//数据入口
|
|
|
|
the.InHttp = &dbOperate.HttpHelper{Url: the.Info.IoConfig.In.Http.Url, Token: ""} |
|
|
|
the.monitor = &monitors.CommonMonitor{ |
|
|
|
MonitorHelper: &monitors.MonitorHelper{CronStr: the.Info.IoConfig.In.CronStr}, |
|
|
|
MonitorHelper: &monitors.MonitorHelper{}, |
|
|
|
} |
|
|
|
for taskName, cron := range the.Info.Monitor { |
|
|
|
switch taskName { |
|
|
|
case "cron10min": |
|
|
|
the.monitor.RegisterTask(cron, the.getEs1HourAggData) |
|
|
|
case "cron1hour": |
|
|
|
the.monitor.RegisterTask(cron, the.getEs10minAggData) |
|
|
|
default: |
|
|
|
log.Printf("定时任务[%s],cron=[%s] 无匹配", taskName, cron) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
the.monitor.Start() |
|
|
|
the.monitor.RegisterFun(the.getEsHourAggData) |
|
|
|
return nil |
|
|
|
} |
|
|
|
func (the *consumerHBJCAS) OutputInitial() error { |
|
|
@ -103,21 +113,48 @@ func (the *consumerHBJCAS) getStructIds() []int64 { |
|
|
|
} |
|
|
|
return structIds |
|
|
|
} |
|
|
|
func (the *consumerHBJCAS) getEsHourAggData() { |
|
|
|
func (the *consumerHBJCAS) getEs1HourAggData() { |
|
|
|
start, end := utils.GetTimeRangeByHour(-1) |
|
|
|
log.Printf("查询数据时间范围 %s - %s", start, end) |
|
|
|
hourFactorIds := []int{18, 15, 20} //15, 20 , 28
|
|
|
|
hourFactorIds := []int{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"} |
|
|
|
esAggResult := the.InHttp.HttpGetWithHeader(esQuery, auth) |
|
|
|
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 *consumerHBJCAS) getEs10minAggData() { |
|
|
|
start, end := utils.GetTimeRangeBy10min() |
|
|
|
log.Printf("查询数据时间范围 %s - %s", start, end) |
|
|
|
factorIds := []int{28} |
|
|
|
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, esAggResult) |
|
|
|
needPushes := adaptor.Transform(structId, factorId, esAggResultStr) |
|
|
|
for i := range needPushes { |
|
|
|
needPushes[i].Payload = the.crc16rc4(needPushes[i].Payload) |
|
|
|
} |
|
|
@ -129,6 +166,7 @@ func (the *consumerHBJCAS) getEsHourAggData() { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (the *consumerHBJCAS) crc16rc4(transBytes []byte) []byte { |
|
|
|
resultByCrc16 := utils.NewCRC16CCITT().GetWCRCin(transBytes) |
|
|
|
needRC4 := append(transBytes, resultByCrc16...) |
|
|
@ -187,8 +225,66 @@ func (the *consumerHBJCAS) getESQueryStrByHour(structureId int64, factorId int, |
|
|
|
"groupDate": { |
|
|
|
"date_histogram": { |
|
|
|
"field": "collect_time", |
|
|
|
"interval": "hour", |
|
|
|
"time_zone": "Asia/Shanghai" |
|
|
|
"interval": "1h", |
|
|
|
"time_zone": "Asia/Shanghai", |
|
|
|
"min_doc_count": 1 |
|
|
|
}, |
|
|
|
"aggs": %s |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
`, structureId, factorId, start, end, aggSubSql) |
|
|
|
|
|
|
|
return esQuery |
|
|
|
} |
|
|
|
|
|
|
|
func (the *consumerHBJCAS) 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 |
|
|
|
} |
|
|
@ -240,11 +336,16 @@ func getEsAggSubSqlByFactorId(factorId int) string { |
|
|
|
case 28: |
|
|
|
subAggSQl = ` |
|
|
|
{ |
|
|
|
"trms": { |
|
|
|
"extended_stats": { |
|
|
|
"field": "data.trms" |
|
|
|
} |
|
|
|
} |
|
|
|
"x": { |
|
|
|
"extended_stats": { |
|
|
|
"field": "data.pv" |
|
|
|
} |
|
|
|
}, |
|
|
|
"y": { |
|
|
|
"extended_stats": { |
|
|
|
"field": "data.trms" |
|
|
|
} |
|
|
|
} |
|
|
|
}` |
|
|
|
} |
|
|
|
return subAggSQl |
|
|
|