2024-12-18 16:25:49 +08:00
|
|
|
|
// Package pool define concurrency call function in ants
|
|
|
|
|
|
package pool
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
|
|
"modelRT/config"
|
2024-12-26 15:03:20 +08:00
|
|
|
|
"modelRT/logger"
|
2024-12-18 16:25:49 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
|
// AnchorFunc defines func that process the real time data of component anchor params
|
|
|
|
|
|
var AnchorFunc = func(anchorChan interface{}) {
|
|
|
|
|
|
var firstStart bool
|
2024-12-26 15:03:20 +08:00
|
|
|
|
logger := logger.GetLoggerInstance()
|
2024-12-18 16:25:49 +08:00
|
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
|
fmt.Println(logger)
|
|
|
|
|
|
fmt.Println(anchorChan)
|
|
|
|
|
|
anchorChanConfig, ok := anchorChan.(config.AnchorChanConfig)
|
2024-12-18 16:25:49 +08:00
|
|
|
|
if !ok {
|
2025-01-21 16:35:44 +08:00
|
|
|
|
logger.Error("conversion component anchor chan type failed")
|
2024-12-18 16:25:49 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2024-12-20 16:06:42 +08:00
|
|
|
|
for {
|
2025-01-21 16:35:44 +08:00
|
|
|
|
select {
|
|
|
|
|
|
case <-anchorChanConfig.Ctx.Done():
|
|
|
|
|
|
return
|
|
|
|
|
|
case anchorParaConfig := <-anchorChanConfig.AnchorChan:
|
|
|
|
|
|
if firstStart {
|
|
|
|
|
|
close(anchorChanConfig.ReadyChan)
|
|
|
|
|
|
firstStart = false
|
2024-12-26 15:03:20 +08:00
|
|
|
|
}
|
2025-01-21 16:35:44 +08:00
|
|
|
|
// TODO 重写anchorParaConfig 处理逻辑
|
|
|
|
|
|
fmt.Println(anchorParaConfig)
|
|
|
|
|
|
default:
|
2024-12-26 15:03:20 +08:00
|
|
|
|
}
|
2025-01-21 16:35:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
// var firstTimePolling bool
|
2024-12-26 15:03:20 +08:00
|
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
|
// paramConfig, ok := anchorConfig.(config.AnchorParamConfig)
|
|
|
|
|
|
// if !ok {
|
|
|
|
|
|
// logger.Error("conversion model anchor param config type failed")
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
2024-12-18 16:25:49 +08:00
|
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
|
// for {
|
|
|
|
|
|
// var beginUnixTime, endUnixTime int64
|
|
|
|
|
|
// if firstTimePolling {
|
|
|
|
|
|
// milliUnixTime := time.Now().UnixMilli()
|
|
|
|
|
|
// endUnixTime = milliUnixTime
|
|
|
|
|
|
// beginUnixTime = milliUnixTime - 1000*60
|
|
|
|
|
|
// firstTimePolling = false
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// // 判断时间差值是否小于10s,如果小于则sleep0.5s后重新获取时间
|
|
|
|
|
|
// endUnixTime = time.Now().UnixMilli()
|
|
|
|
|
|
// if endUnixTime-beginUnixTime < 1000 {
|
|
|
|
|
|
// time.Sleep(time.Duration(500 * time.Millisecond))
|
|
|
|
|
|
// endUnixTime = time.Now().UnixMilli()
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2024-12-26 15:03:20 +08:00
|
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
|
// pollingAPI := network.APIEndpoint{
|
|
|
|
|
|
// URL: paramConfig.APIURL,
|
|
|
|
|
|
// Method: paramConfig.APIMethod,
|
|
|
|
|
|
// QueryParams: map[string]string{
|
|
|
|
|
|
// "station": paramConfig.StationID,
|
|
|
|
|
|
// "component": paramConfig.ComponentID,
|
|
|
|
|
|
// "point": paramConfig.AnchorName,
|
|
|
|
|
|
// "begin": strconv.FormatInt(beginUnixTime, 10),
|
|
|
|
|
|
// "end": strconv.FormatInt(endUnixTime, 10),
|
|
|
|
|
|
// },
|
|
|
|
|
|
// }
|
2024-12-20 16:06:42 +08:00
|
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
|
// if !firstTimePolling {
|
|
|
|
|
|
// beginUnixTime = time.Now().UnixMilli()
|
|
|
|
|
|
// }
|
2024-12-26 15:03:20 +08:00
|
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
|
// valueSlice, err := network.PollAPIEndpoints(pollingAPI)
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
// logger.Error("polling real time data from dataRT service failed", zap.Error(err))
|
|
|
|
|
|
// continue
|
|
|
|
|
|
// }
|
2024-12-26 15:03:20 +08:00
|
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
|
// for _, value := range valueSlice {
|
|
|
|
|
|
// anchorName, err := diagram.GetAnchorValue(paramConfig.UUID)
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
// logger.Error("can not get anchor value from map by uuid", zap.String("uuid", paramConfig.UUID), zap.Error(err))
|
|
|
|
|
|
// continue
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// if anchorName != paramConfig.AnchorName {
|
|
|
|
|
|
// logger.Error("anchor name not equal param config anchor value", zap.String("map_anchor_name", anchorName), zap.String("param_anchor_name", paramConfig.AnchorName))
|
|
|
|
|
|
// continue
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// upperLimitVal := paramConfig.CompareValUpperLimit
|
|
|
|
|
|
// lowerlimitVal := paramConfig.CompareValLowerLimit
|
|
|
|
|
|
// compareValue := paramConfig.CalculateFunc(value, paramConfig.CalculateParams...)
|
|
|
|
|
|
// if compareValue > upperLimitVal || compareValue < lowerlimitVal {
|
|
|
|
|
|
// // TODO 选择报警方式
|
|
|
|
|
|
// fmt.Println("log warning")
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2024-12-18 16:25:49 +08:00
|
|
|
|
}
|