|
|
|
package et_Info
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gitea.anxinyun.cn/container/common_models"
|
|
|
|
"gitea.anxinyun.cn/container/common_utils"
|
|
|
|
"gitea.anxinyun.cn/container/common_utils/configLoad"
|
|
|
|
"log"
|
|
|
|
"node/stages"
|
|
|
|
)
|
|
|
|
|
|
|
|
type InfoHandler struct {
|
|
|
|
configHelper *common_utils.ConfigHelper
|
|
|
|
stage *stages.Stage
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewInfoHandler() *InfoHandler {
|
|
|
|
redisAddr := configLoad.LoadConfig().GetString("redis.address")
|
|
|
|
the := &InfoHandler{
|
|
|
|
configHelper: common_utils.NewConfigHelper(redisAddr),
|
|
|
|
stage: stages.NewStage("测点信息获取"),
|
|
|
|
}
|
|
|
|
the.stage.AddProcess(the.getStationInfo)
|
|
|
|
return the
|
|
|
|
}
|
|
|
|
|
|
|
|
func (the *InfoHandler) GetStage() stages.Stage {
|
|
|
|
return *the.stage
|
|
|
|
}
|
|
|
|
|
|
|
|
func (the *InfoHandler) getStationInfo(p *common_models.ProcessData) *common_models.ProcessData {
|
|
|
|
|
|
|
|
// TODO 测试 DeviceId = 22c76344-1eb2-4508-8aa6-4550c010e8f7 ,sensorId=18
|
|
|
|
//if p.DeviceData.DeviceId != "22c76344-1eb2-4508-8aa6-4550c010e8f7" {
|
|
|
|
// return &common_models.ProcessData{}
|
|
|
|
//}
|
|
|
|
|
|
|
|
s, err := the.configHelper.GetDeviceStationObjs(p.DeviceData.DeviceId)
|
|
|
|
if err == nil && s != nil {
|
|
|
|
p.Stations = s
|
|
|
|
} else {
|
|
|
|
//无法查询到完整的 重新获取
|
|
|
|
log.Printf("重获取设备[%s]的 DeviceStationObj", p.DeviceData.DeviceId)
|
|
|
|
stationIds, err := the.configHelper.GetDeviceStationIds(p.DeviceData.DeviceId)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("err !!! GetDeviceStationIds =>%s", err.Error())
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
p.Stations, err = the.configHelper.GetStations(stationIds...)
|
|
|
|
the.getFormulaInfo(p)
|
|
|
|
//补全 设备数据输入单位
|
|
|
|
p.DeviceData.RawUnit = p.DeviceData.DeviceInfo.DeviceMeta.GetOutputUnit()
|
|
|
|
//存储测点obj
|
|
|
|
if len(p.Stations) > 0 {
|
|
|
|
go func() {
|
|
|
|
errSet := the.configHelper.SetDeviceStationObjs(p.DeviceData.DeviceId, p.Stations)
|
|
|
|
if errSet != nil {
|
|
|
|
log.Printf("SetDeviceStationObjs 缓存异常 err=%s", errSet.Error())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
func (the *InfoHandler) getFormulaInfo(p *common_models.ProcessData) {
|
|
|
|
for i, _ := range p.Stations {
|
|
|
|
deviceFactorProto, err := the.configHelper.GetDeviceFactorProto(p.Stations[i].Info.ProtoCode, p.DeviceData.DeviceInfo.DeviceMeta.Id)
|
|
|
|
p.Stations[i].Info.Proto, err = the.configHelper.GetProto(p.Stations[i].Info.ProtoCode)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
//for i2, device := range p.Stations[i].Info.Devices {
|
|
|
|
// formulaInfo, err := the.configHelper.GetFormulaInfo(device.FormulaId)
|
|
|
|
// if err == nil {
|
|
|
|
// p.Stations[i].Info.Devices[i2].FormulaInfo = formulaInfo
|
|
|
|
// p.Stations[i].Info.Devices[i2].DeviceFactorProto = deviceFactorProto
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
// TODO #TEST BEGIN 2024-10-01 测点设备没有公式信息,测试时先从设备监测原型中获取
|
|
|
|
for i2, _ := range p.Stations[i].Info.Devices {
|
|
|
|
p.Stations[i].Info.Devices[i2].FormulaId = deviceFactorProto.Formula
|
|
|
|
formulaInfo, err := the.configHelper.GetFormulaInfo(deviceFactorProto.Formula)
|
|
|
|
if err == nil {
|
|
|
|
p.Stations[i].Info.Devices[i2].FormulaInfo = formulaInfo
|
|
|
|
p.Stations[i].Info.Devices[i2].DeviceFactorProto = deviceFactorProto
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// #TEST END
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//func (the *InfoHandler) getThresholdInfo(p *common_models.ProcessData) {
|
|
|
|
// for _, stationInfo := range p.Stations {
|
|
|
|
// the.configHelper.GetStationThreshold(stationInfo.Info.Id)
|
|
|
|
// }
|
|
|
|
//}
|