refactor(optimize storage struct): optimize topologic storage struct
1.optimize uuid start and end node of uuid nil node str
2.optimize topologic query sql of init topologic in memory
This commit is contained in:
parent
daf30766ba
commit
237c7ecf69
|
|
@ -14,9 +14,9 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// SpecialUUIDStr 拓扑信息中开始节点与结束节点字符串形式
|
// UUIDNilStr 拓扑信息中开始节点与结束节点字符串形式
|
||||||
SpecialUUIDStr = "00000000-0000-0000-0000-000000000000"
|
UUIDNilStr = "00000000-0000-0000-0000-000000000000"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SpecialUUID 拓扑信息中开始节点与结束节点 UUID 格式
|
// UUIDNil 拓扑信息中开始节点与结束节点 UUID 格式
|
||||||
var SpecialUUID = uuid.FromStringOrNil(SpecialUUIDStr)
|
var UUIDNil = uuid.FromStringOrNil(UUIDNilStr)
|
||||||
|
|
|
||||||
|
|
@ -24,16 +24,14 @@ func QueryTopologic(ctx context.Context, tx *gorm.DB, logger *zap.Logger) ([]orm
|
||||||
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
result := tx.WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Raw(sql.RecursiveSQL, constant.SpecialUUIDStr).Scan(&topologics)
|
result := tx.WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Raw(sql.RecursiveSQL, constant.UUIDNilStr).Scan(&topologics)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
logger.Error("query circuit diagram topologic info by start node uuid failed", zap.String("start_node_uuid", constant.SpecialUUIDStr), zap.Error(result.Error))
|
logger.Error("query circuit diagram topologic info by start node uuid failed", zap.String("start_node_uuid", constant.UUIDNilStr), zap.Error(result.Error))
|
||||||
return nil, result.Error
|
return nil, result.Error
|
||||||
}
|
}
|
||||||
return topologics, nil
|
return topologics, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 电流互感器不单独划分间隔
|
|
||||||
// TODO 以母线、浇筑母线、变压器为间隔原件
|
|
||||||
// QueryTopologicFromDB return the result of query topologic info from DB
|
// QueryTopologicFromDB return the result of query topologic info from DB
|
||||||
func QueryTopologicFromDB(ctx context.Context, tx *gorm.DB, logger *zap.Logger, componentTypeMap map[uuid.UUID]int) error {
|
func QueryTopologicFromDB(ctx context.Context, tx *gorm.DB, logger *zap.Logger, componentTypeMap map[uuid.UUID]int) error {
|
||||||
topologicInfos, err := QueryTopologic(ctx, tx, logger)
|
topologicInfos, err := QueryTopologic(ctx, tx, logger)
|
||||||
|
|
@ -60,7 +58,7 @@ func QueryTopologicFromDB(ctx context.Context, tx *gorm.DB, logger *zap.Logger,
|
||||||
func InitCircuitDiagramTopologic(topologicNodes []orm.Topologic, componentTypeMap map[uuid.UUID]int) error {
|
func InitCircuitDiagramTopologic(topologicNodes []orm.Topologic, componentTypeMap map[uuid.UUID]int) error {
|
||||||
var rootVertex *diagram.MultiBranchTreeNode
|
var rootVertex *diagram.MultiBranchTreeNode
|
||||||
for _, node := range topologicNodes {
|
for _, node := range topologicNodes {
|
||||||
if node.UUIDFrom == constant.SpecialUUID {
|
if node.UUIDFrom == constant.UUIDNil {
|
||||||
// rootVertex = node.UUIDTo
|
// rootVertex = node.UUIDTo
|
||||||
var componentType int
|
var componentType int
|
||||||
componentType, ok := componentTypeMap[node.UUIDFrom]
|
componentType, ok := componentTypeMap[node.UUIDFrom]
|
||||||
|
|
@ -77,7 +75,7 @@ func InitCircuitDiagramTopologic(topologicNodes []orm.Topologic, componentTypeMa
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, node := range topologicNodes {
|
for _, node := range topologicNodes {
|
||||||
if node.UUIDFrom == constant.SpecialUUID {
|
if node.UUIDFrom == constant.UUIDNil {
|
||||||
var componentType int
|
var componentType int
|
||||||
componentType, ok := componentTypeMap[node.UUIDTo]
|
componentType, ok := componentTypeMap[node.UUIDTo]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -97,11 +95,18 @@ func InitCircuitDiagramTopologic(topologicNodes []orm.Topologic, componentTypeMa
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO 电流互感器不单独划分间隔
|
||||||
|
// TODO 以母线、浇筑母线、变压器为间隔原件
|
||||||
func IntervalBoundaryDetermine(uuid uuid.UUID) bool {
|
func IntervalBoundaryDetermine(uuid uuid.UUID) bool {
|
||||||
// TODO 从diagramsOverview中根据 uuid 获取 component 信息
|
// TODO 从diagramsOverview中根据 uuid 获取 component 信息
|
||||||
var componentID int64
|
var componentID int64
|
||||||
diagram.GetComponentMap(componentID)
|
diagram.GetComponentMap(componentID)
|
||||||
// TODO 判断 component 的类型是否为间隔
|
// TODO 判断 component 的类型是否为间隔
|
||||||
|
// TODO 0x1111A1B2C3D4,高四位表示可以成为间隔的compoent类型的值为FFFF,普通 component 类型的值为 0000。低四位中前二位表示component的一级类型,例如母线 PT、母联/母分、进线等,低四位中后二位表示一级类型中包含的具体类型,例如母线 PT中包含的电压互感器、隔离开关、接地开关、避雷器、带电显示器等。
|
||||||
|
num := uint32(0xA1B2C3D4) // 八位16进制数
|
||||||
|
high16 := uint16(num >> 16)
|
||||||
|
fmt.Printf("原始值: 0x%X\n", num) // 输出: 0xA1B2C3D4
|
||||||
|
fmt.Printf("高十六位: 0x%X\n", high16) // 输出: 0xA1B2
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,9 +116,11 @@ func BuildMultiBranchTree(topologics []orm.Topologic, componentTypeMap map[uuid.
|
||||||
|
|
||||||
for _, topo := range topologics {
|
for _, topo := range topologics {
|
||||||
// skip special uuid
|
// skip special uuid
|
||||||
if topo.UUIDFrom != constant.SpecialUUID {
|
if _, exists := nodeMap[topo.UUIDFrom]; !exists {
|
||||||
if _, exists := nodeMap[topo.UUIDFrom]; !exists {
|
var componentType int
|
||||||
componentType, ok := componentTypeMap[topo.UUIDFrom]
|
if topo.UUIDTo != constant.UUIDNil {
|
||||||
|
var ok bool
|
||||||
|
componentType, ok = componentTypeMap[topo.UUIDFrom]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("can not get component type by uuid: %s", topo.UUIDFrom)
|
return nil, fmt.Errorf("can not get component type by uuid: %s", topo.UUIDFrom)
|
||||||
}
|
}
|
||||||
|
|
@ -126,9 +133,13 @@ func BuildMultiBranchTree(topologics []orm.Topologic, componentTypeMap map[uuid.
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, exists := nodeMap[topo.UUIDTo]; !exists {
|
if _, exists := nodeMap[topo.UUIDTo]; !exists {
|
||||||
componentType, ok := componentTypeMap[topo.UUIDTo]
|
var componentType int
|
||||||
if !ok {
|
if topo.UUIDTo != constant.UUIDNil {
|
||||||
return nil, fmt.Errorf("can not get component type by uuid: %s", topo.UUIDTo)
|
var ok bool
|
||||||
|
componentType, ok = componentTypeMap[topo.UUIDTo]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("can not get component type by uuid: %s", topo.UUIDTo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeMap[topo.UUIDTo] = &diagram.MultiBranchTreeNode{
|
nodeMap[topo.UUIDTo] = &diagram.MultiBranchTreeNode{
|
||||||
|
|
@ -140,17 +151,13 @@ func BuildMultiBranchTree(topologics []orm.Topologic, componentTypeMap map[uuid.
|
||||||
|
|
||||||
for _, topo := range topologics {
|
for _, topo := range topologics {
|
||||||
var parent *diagram.MultiBranchTreeNode
|
var parent *diagram.MultiBranchTreeNode
|
||||||
if topo.UUIDFrom == constant.SpecialUUID {
|
if topo.UUIDFrom == constant.UUIDNil {
|
||||||
componentType, ok := componentTypeMap[topo.UUIDTo]
|
var componentType int
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("can not get component type by uuid: %s", topo.UUIDTo)
|
|
||||||
}
|
|
||||||
|
|
||||||
parent = &diagram.MultiBranchTreeNode{
|
parent = &diagram.MultiBranchTreeNode{
|
||||||
ID: constant.SpecialUUID,
|
ID: constant.UUIDNil,
|
||||||
NodeComponentType: componentType,
|
NodeComponentType: componentType,
|
||||||
}
|
}
|
||||||
nodeMap[constant.SpecialUUID] = parent
|
nodeMap[constant.UUIDNil] = parent
|
||||||
} else {
|
} else {
|
||||||
parent = nodeMap[topo.UUIDFrom]
|
parent = nodeMap[topo.UUIDFrom]
|
||||||
}
|
}
|
||||||
|
|
@ -161,7 +168,7 @@ func BuildMultiBranchTree(topologics []orm.Topologic, componentTypeMap map[uuid.
|
||||||
}
|
}
|
||||||
|
|
||||||
// return root vertex
|
// return root vertex
|
||||||
root, exists := nodeMap[constant.SpecialUUID]
|
root, exists := nodeMap[constant.UUIDNil]
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, fmt.Errorf("root node not found")
|
return nil, fmt.Errorf("root node not found")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue