fix(multi-branch-tree-of-topologic): add global tree variable and fix topologic info processing bug
This commit is contained in:
parent
237c7ecf69
commit
d2196701ec
|
|
@ -33,25 +33,19 @@ func QueryTopologic(ctx context.Context, tx *gorm.DB, logger *zap.Logger) ([]orm
|
|||
}
|
||||
|
||||
// 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) (*diagram.MultiBranchTreeNode, error) {
|
||||
topologicInfos, err := QueryTopologic(ctx, tx, logger)
|
||||
if err != nil {
|
||||
logger.Error("query topologic info failed", zap.Error(err))
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// err = InitCircuitDiagramTopologic(topologicInfos, componentTypeMap)
|
||||
// if err != nil {
|
||||
// logger.Error("init topologic failed", zap.Error(err))
|
||||
// return err
|
||||
// }
|
||||
|
||||
_, err = BuildMultiBranchTree(topologicInfos, componentTypeMap)
|
||||
tree, err := BuildMultiBranchTree(topologicInfos, componentTypeMap)
|
||||
if err != nil {
|
||||
logger.Error("init topologic failed", zap.Error(err))
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return tree, nil
|
||||
}
|
||||
|
||||
// InitCircuitDiagramTopologic return circuit diagram topologic info from postgres
|
||||
|
|
@ -95,14 +89,13 @@ func InitCircuitDiagramTopologic(topologicNodes []orm.Topologic, componentTypeMa
|
|||
return nil
|
||||
}
|
||||
|
||||
// TODO 电流互感器不单独划分间隔
|
||||
// TODO 以母线、浇筑母线、变压器为间隔原件
|
||||
// TODO 电流互感器不单独划分间隔,以母线、浇筑母线、变压器为间隔原件
|
||||
func IntervalBoundaryDetermine(uuid uuid.UUID) bool {
|
||||
// TODO 从diagramsOverview中根据 uuid 获取 component 信息
|
||||
fmt.Println(uuid)
|
||||
var componentID int64
|
||||
diagram.GetComponentMap(componentID)
|
||||
// TODO 判断 component 的类型是否为间隔
|
||||
// TODO 0x1111A1B2C3D4,高四位表示可以成为间隔的compoent类型的值为FFFF,普通 component 类型的值为 0000。低四位中前二位表示component的一级类型,例如母线 PT、母联/母分、进线等,低四位中后二位表示一级类型中包含的具体类型,例如母线 PT中包含的电压互感器、隔离开关、接地开关、避雷器、带电显示器等。
|
||||
// TODO 0xA1B2C3D4,高四位表示可以成为间隔的compoent类型的值为FFFF,普通 component 类型的值为 0000。低四位中前二位表示component的一级类型,例如母线 PT、母联/母分、进线等,低四位中后二位表示一级类型中包含的具体类型,例如母线 PT中包含的电压互感器、隔离开关、接地开关、避雷器、带电显示器等。
|
||||
num := uint32(0xA1B2C3D4) // 八位16进制数
|
||||
high16 := uint16(num >> 16)
|
||||
fmt.Printf("原始值: 0x%X\n", num) // 输出: 0xA1B2C3D4
|
||||
|
|
@ -112,15 +105,14 @@ func IntervalBoundaryDetermine(uuid uuid.UUID) bool {
|
|||
|
||||
// BuildMultiBranchTree return the multi branch tree by topologic info and component type map
|
||||
func BuildMultiBranchTree(topologics []orm.Topologic, componentTypeMap map[uuid.UUID]int) (*diagram.MultiBranchTreeNode, error) {
|
||||
nodeMap := make(map[uuid.UUID]*diagram.MultiBranchTreeNode, len(topologics))
|
||||
nodeMap := make(map[uuid.UUID]*diagram.MultiBranchTreeNode, len(topologics)*2)
|
||||
|
||||
for _, topo := range topologics {
|
||||
// skip special uuid
|
||||
if _, exists := nodeMap[topo.UUIDFrom]; !exists {
|
||||
var componentType int
|
||||
// skip special uuid
|
||||
if topo.UUIDTo != constant.UUIDNil {
|
||||
var ok bool
|
||||
componentType, ok = componentTypeMap[topo.UUIDFrom]
|
||||
componentType, ok := componentTypeMap[topo.UUIDFrom]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("can not get component type by uuid: %s", topo.UUIDFrom)
|
||||
}
|
||||
|
|
@ -128,23 +120,25 @@ func BuildMultiBranchTree(topologics []orm.Topologic, componentTypeMap map[uuid.
|
|||
nodeMap[topo.UUIDFrom] = &diagram.MultiBranchTreeNode{
|
||||
ID: topo.UUIDFrom,
|
||||
NodeComponentType: componentType,
|
||||
Children: make([]*diagram.MultiBranchTreeNode, 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _, exists := nodeMap[topo.UUIDTo]; !exists {
|
||||
var componentType int
|
||||
// skip special uuid
|
||||
if topo.UUIDTo != constant.UUIDNil {
|
||||
var ok bool
|
||||
componentType, ok = componentTypeMap[topo.UUIDTo]
|
||||
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{
|
||||
ID: topo.UUIDTo,
|
||||
NodeComponentType: componentType,
|
||||
nodeMap[topo.UUIDTo] = &diagram.MultiBranchTreeNode{
|
||||
ID: topo.UUIDTo,
|
||||
NodeComponentType: componentType,
|
||||
Children: make([]*diagram.MultiBranchTreeNode, 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -162,7 +156,16 @@ func BuildMultiBranchTree(topologics []orm.Topologic, componentTypeMap map[uuid.
|
|||
parent = nodeMap[topo.UUIDFrom]
|
||||
}
|
||||
|
||||
child := nodeMap[topo.UUIDTo]
|
||||
var child *diagram.MultiBranchTreeNode
|
||||
if topo.UUIDTo == constant.UUIDNil {
|
||||
var componentType int
|
||||
child = &diagram.MultiBranchTreeNode{
|
||||
ID: topo.UUIDTo,
|
||||
NodeComponentType: componentType,
|
||||
}
|
||||
} else {
|
||||
child = nodeMap[topo.UUIDTo]
|
||||
}
|
||||
child.Parent = parent
|
||||
parent.Children = append(parent.Children, child)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"github.com/gofrs/uuid"
|
||||
)
|
||||
|
||||
var GlobalTree *MultiBranchTreeNode
|
||||
|
||||
// MultiBranchTreeNode represents a topological structure using an multi branch tree
|
||||
type MultiBranchTreeNode struct {
|
||||
ID uuid.UUID // 节点唯一标识
|
||||
|
|
|
|||
3
main.go
3
main.go
|
|
@ -108,11 +108,12 @@ func main() {
|
|||
}
|
||||
|
||||
// TODO 暂时屏蔽完成 swagger 启动测试
|
||||
err = database.QueryTopologicFromDB(ctx, tx, zapLogger, componentTypeMap)
|
||||
tree, err := database.QueryTopologicFromDB(ctx, tx, zapLogger, componentTypeMap)
|
||||
if err != nil {
|
||||
zapLogger.Error("load topologic info from postgres failed", zap.Error(err))
|
||||
panic(err)
|
||||
}
|
||||
diagram.GlobalTree = tree
|
||||
return nil
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue