|
@ -2,6 +2,9 @@ package common_utils |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
|
|
|
"gitea.anxinyun.cn/container/common_models/constant/settlementParam" |
|
|
|
|
|
"strings" |
|
|
|
|
|
|
|
|
//"encoding/json"
|
|
|
//"encoding/json"
|
|
|
"errors" |
|
|
"errors" |
|
|
"fmt" |
|
|
"fmt" |
|
@ -24,6 +27,7 @@ var IotaDeviceCache map[string]common_models.IotaDevice |
|
|
var ThingStructCache map[string]common_models.ThingStruct |
|
|
var ThingStructCache map[string]common_models.ThingStruct |
|
|
var DeviceNodeCache map[string]common_models.IotaInstances |
|
|
var DeviceNodeCache map[string]common_models.IotaInstances |
|
|
var AlarmCodeCache map[string]common_models.AlarmCode |
|
|
var AlarmCodeCache map[string]common_models.AlarmCode |
|
|
|
|
|
var StructureCache map[int]common_models.Structure |
|
|
|
|
|
|
|
|
// var stationThreshold map[int]common_models.Threshold
|
|
|
// var stationThreshold map[int]common_models.Threshold
|
|
|
// var aggThreshold map[string]common_models.AggThreshold
|
|
|
// var aggThreshold map[string]common_models.AggThreshold
|
|
@ -85,6 +89,9 @@ func initDeviceInfoMapCache() { |
|
|
if AlarmCodeCache == nil { |
|
|
if AlarmCodeCache == nil { |
|
|
AlarmCodeCache = make(map[string]common_models.AlarmCode) |
|
|
AlarmCodeCache = make(map[string]common_models.AlarmCode) |
|
|
} |
|
|
} |
|
|
|
|
|
if StructureCache == nil { |
|
|
|
|
|
StructureCache = make(map[int]common_models.Structure) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// GetDeviceInfo 通过
|
|
|
// GetDeviceInfo 通过
|
|
@ -318,23 +325,75 @@ func (the *ConfigHelper) SetStationGroup(groupId int, group common_models.Statio |
|
|
k := fmt.Sprintf("%s:%d", redisKey.Group, groupId) |
|
|
k := fmt.Sprintf("%s:%d", redisKey.Group, groupId) |
|
|
return the.chainedCache.LoadableChinCache.Set(the.ctx, k, &group) |
|
|
return the.chainedCache.LoadableChinCache.Set(the.ctx, k, &group) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 最大级联层级
|
|
|
|
|
|
const max_corr_depth int = 15 |
|
|
|
|
|
|
|
|
|
|
|
// 关联分组(e.g 沉降级联)
|
|
|
|
|
|
// depth: 递归查询深度(防止错误配置导致基点互相参考;亦限制级联的最大层级)
|
|
|
|
|
|
func (the *ConfigHelper) corrGroups(gp common_models.StationGroup, depth int) { |
|
|
|
|
|
if gp.GroupType == "202" && gp.Params != nil && len(gp.Params) == 2 { |
|
|
|
|
|
ref_base_stationId, ok := gp.Params[settlementParam.Ref_base].(float64) |
|
|
|
|
|
if !ok { |
|
|
|
|
|
log.Println("ref_base 转换异常。", gp.Params[settlementParam.Ref_base]) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
ref_point_stationId, ok := gp.Params[settlementParam.Ref_point].(float64) |
|
|
|
|
|
if !ok { |
|
|
|
|
|
log.Println("ref_base 转换异常。", gp.Params[settlementParam.Ref_point]) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
basePtr := gp.GetSettlementBaseItem() |
|
|
|
|
|
if basePtr == nil { |
|
|
|
|
|
log.Println("无基点。", gp.R()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sg, err := the.GetStationGroupInfo(int(ref_base_stationId)) |
|
|
|
|
|
subBase := common_models.GroupItem{ |
|
|
|
|
|
StationId: int(ref_base_stationId), |
|
|
|
|
|
ParamsValue: map[string]interface{}{"base": true}, |
|
|
|
|
|
SubItems: nil, |
|
|
|
|
|
} |
|
|
|
|
|
if err == nil { |
|
|
|
|
|
refGroup, err := the.GetStationGroup(sg.GroupId) |
|
|
|
|
|
if err == nil { |
|
|
|
|
|
if depth+1 <= max_corr_depth { |
|
|
|
|
|
the.corrGroups(refGroup, depth+1) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
subBase = *refGroup.GetItem(int(ref_base_stationId)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
subPoint := common_models.GroupItem{ |
|
|
|
|
|
StationId: int(ref_point_stationId), |
|
|
|
|
|
ParamsValue: map[string]interface{}{"base": false}, |
|
|
|
|
|
SubItems: nil, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
basePtr.SubItems = map[string]common_models.GroupItem{ |
|
|
|
|
|
settlementParam.Ref_base: subBase, |
|
|
|
|
|
settlementParam.Ref_point: subPoint, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//log.Println(basePtr)
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (the *ConfigHelper) GetStationGroup(groupId int) (common_models.StationGroup, error) { |
|
|
func (the *ConfigHelper) GetStationGroup(groupId int) (common_models.StationGroup, error) { |
|
|
var result common_models.StationGroup |
|
|
var group common_models.StationGroup |
|
|
// group:35
|
|
|
// group:35
|
|
|
k := fmt.Sprintf("%s:%d", redisKey.Group, groupId) |
|
|
k := fmt.Sprintf("%s:%d", redisKey.Group, groupId) |
|
|
value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, k) |
|
|
value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, k) |
|
|
if v, ok := value.(string); ok { |
|
|
if v, ok := value.(string); ok { |
|
|
if v == "" { |
|
|
err = json.Unmarshal([]byte(v), &group) |
|
|
err = errors.New("无测点group 数据") |
|
|
|
|
|
return result, err |
|
|
|
|
|
} |
|
|
|
|
|
err = json.Unmarshal([]byte(v), &result) |
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Printf("json unmarshal error:%s \n", err.Error()) |
|
|
log.Printf("json unmarshal error:%s \n", err.Error()) |
|
|
log.Printf("err => v=%s", v) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return result, err |
|
|
|
|
|
|
|
|
the.corrGroups(group, 0) |
|
|
|
|
|
return group, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// RedisKey.station_group
|
|
|
// RedisKey.station_group
|
|
@ -342,6 +401,7 @@ func (the *ConfigHelper) SetStationGroupInfo(stationId int, info common_models.S |
|
|
k := fmt.Sprintf("%s:%d", redisKey.Station_group, stationId) |
|
|
k := fmt.Sprintf("%s:%d", redisKey.Station_group, stationId) |
|
|
return the.chainedCache.LoadableChinCache.Set(the.ctx, k, &info) |
|
|
return the.chainedCache.LoadableChinCache.Set(the.ctx, k, &info) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (the *ConfigHelper) GetStationGroupInfo(stationId int) (common_models.StationGroupInfo, error) { |
|
|
func (the *ConfigHelper) GetStationGroupInfo(stationId int) (common_models.StationGroupInfo, error) { |
|
|
// sg:193
|
|
|
// sg:193
|
|
|
k := fmt.Sprintf("%s:%d", redisKey.Station_group, stationId) |
|
|
k := fmt.Sprintf("%s:%d", redisKey.Station_group, stationId) |
|
@ -522,7 +582,8 @@ func (the *ConfigHelper) GetIotaScheme(dimensionId string) (common_models.IotaSc |
|
|
var scheme common_models.IotaScheme |
|
|
var scheme common_models.IotaScheme |
|
|
value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, k) |
|
|
value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, k) |
|
|
if v, ok := value.(string); ok { |
|
|
if v, ok := value.(string); ok { |
|
|
err = json.Unmarshal([]byte(v), &scheme) |
|
|
formattedStr := strings.Replace(v, "+0800", "+08:00", -1) |
|
|
|
|
|
err = json.Unmarshal([]byte(formattedStr), &scheme) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Printf("json unmarshal error:%s \n", err.Error()) |
|
|
log.Printf("json unmarshal error:%s \n", err.Error()) |
|
|
} |
|
|
} |
|
@ -603,3 +664,17 @@ func (the *ConfigHelper) mapToTree(source map[string]common_models.IotaInstance, |
|
|
} |
|
|
} |
|
|
return deviceNode |
|
|
return deviceNode |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (the *ConfigHelper) GetStructure(structId int) (common_models.Structure, error) { |
|
|
|
|
|
var result common_models.Structure |
|
|
|
|
|
// structure:1
|
|
|
|
|
|
k := fmt.Sprintf("%s:%d", redisKey.Structure, structId) |
|
|
|
|
|
value, err := the.chainedCache.LoadableChinCache.Get(the.ctx, k) |
|
|
|
|
|
if v, ok := value.(string); ok { |
|
|
|
|
|
err = json.Unmarshal([]byte(v), &result) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Printf("json unmarshal error:%s \n", err.Error()) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return result, err |
|
|
|
|
|
} |
|
|