From 772403c7d9925c86e32f1f5497d0f3448770f1ee Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Wed, 20 Dec 2023 14:44:27 +0800 Subject: [PATCH] =?UTF-8?q?iscs=20=20pscada=20=E4=B8=80=E6=AC=A1=E5=9B=BE?= =?UTF-8?q?=20repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- repository/repository.go | 8 +- repository/repository_iscs.go | 201 ++++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+), 4 deletions(-) create mode 100644 repository/repository_iscs.go diff --git a/repository/repository.go b/repository/repository.go index dbc3380..e3a74b3 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -39,7 +39,7 @@ type Repository struct { rectifierMap map[string]*Rectifier //ISCS 整流器 disconnectorMap map[string]*Disconnector //ISCS 隔离开关 voltageTransformerMap map[string]*VoltageTransformer //ISCS 变压器 - powerSource map[string]*PowerSource //ISCS 电源 + powerSourceMap map[string]*PowerSource //ISCS 电源 } func newRepository(id string, version string) *Repository { @@ -74,7 +74,7 @@ func newRepository(id string, version string) *Repository { rectifierMap: make(map[string]*Rectifier), //ISCS 整流器 disconnectorMap: make(map[string]*Disconnector), //ISCS 隔离开关 voltageTransformerMap: make(map[string]*VoltageTransformer), //ISCS 变压器 - powerSource: make(map[string]*PowerSource), //ISCS 电源 + powerSourceMap: make(map[string]*PowerSource), //ISCS 电源 } } @@ -129,7 +129,7 @@ func (repo *Repository) FindById(id string) Identity { if md, ok := repo.voltageTransformerMap[id]; ok { return md } - if md, ok := repo.powerSource[id]; ok { + if md, ok := repo.powerSourceMap[id]; ok { return md } //ISCS-end @@ -302,7 +302,7 @@ func (repo *Repository) FindModel(deviceId string, deviceType proto.DeviceType) case proto.DeviceType_DeviceType_VoltageTransformer: return repo.voltageTransformerMap[deviceId], nil case proto.DeviceType_DeviceType_PowerSource: - return repo.powerSource[deviceId], nil + return repo.powerSourceMap[deviceId], nil default: return nil, fmt.Errorf("仓库中不存在[%s]类型的模型", deviceType) } diff --git a/repository/repository_iscs.go b/repository/repository_iscs.go new file mode 100644 index 0000000..fdfa0a0 --- /dev/null +++ b/repository/repository_iscs.go @@ -0,0 +1,201 @@ +package repository + +import "joylink.club/rtsssimulation/repository/model/proto" + +// ISCS模型仓库构建 +func buildIscsModels(source *proto.Repository, repository *Repository) error { + //ISCS管线 + for _, protoData := range source.Pipes { + m := NewPipe(protoData.Id, protoData.Code) + repository.pipeMap[m.Id()] = m + } + //ISCS管件 + for _, protoData := range source.PipeFittings { + m := NewPipeFitting(protoData.Id, protoData.Code, int8(protoData.Sum)) + repository.pipeFittingMap[m.Id()] = m + } + //ISCS断路器 + for _, protoData := range source.CircuitBreakers { + m := NewCircuitBreaker(protoData.Id, protoData.Code) + repository.circuitBreakerMap[m.Id()] = m + } + //ISCS三工位开关 + for _, protoData := range source.ThreePositionSwitches { + m := NewThreePositionSwitch(protoData.Id, protoData.Code) + repository.threePositionSwitchMap[m.Id()] = m + } + //ISCS手车 + for _, protoData := range source.HandcartSwitches { + m := NewHandcartSwitch(protoData.Id, protoData.Code) + repository.handcartSwitchMap[m.Id()] = m + } + //ISCS整流器 + for _, protoData := range source.Rectifiers { + m := NewRectifier(protoData.Id, protoData.Code) + repository.rectifierMap[m.Id()] = m + } + //ISCS隔离开关 + for _, protoData := range source.Disconnectors { + m := NewDisconnector(protoData.Id, protoData.Code) + repository.disconnectorMap[m.Id()] = m + } + //ISCS变压器 + for _, protoData := range source.VoltageTransformers { + m := NewVoltageTransformer(protoData.Id, protoData.Code) + repository.voltageTransformerMap[m.Id()] = m + } + //ISCS电源 + for _, protoData := range source.PowerSources { + m := NewPowerSource(protoData.Id, protoData.Code) + repository.powerSourceMap[m.Id()] = m + } + // + return nil +} + +// ISCS模型关系构建 +func buildIscsModelRelationship(source *proto.Repository, repository *Repository) error { + if e := buildIscsPipeModelRelationship(source, repository); e != nil { + return e + } + // + return nil +} + +// ISCS模型关系构建---构建与管线Pipe相关的关系 +func buildIscsPipeModelRelationship(source *proto.Repository, repository *Repository) error { + //PSCADA一次图关系数据都在proto管线中 + for _, protoPipe := range source.Pipes { + pipeA := protoPipe.PortA + pipeB := protoPipe.PortB + pipeModel := (repository.FindById(source.Id)).(*Pipe) + //pipeModel的端口pipePort连接设备的端口portRelatedDevice + buildRelationship := func(pipePort proto.Port, portRelatedDevice *proto.DevicePort) error { + relatedDevice, e := repository.FindModel(portRelatedDevice.DeviceId, portRelatedDevice.DeviceType) + if e != nil { + return e + } + var pipePortRelatedDevice DevicePort + switch portRelatedDevice.DeviceType { + case proto.DeviceType_DeviceType_PipeFitting: + { + pipeFitting := relatedDevice.(*PipeFitting) + pipePortRelatedDevice = &PipeFittingPort{port: portRelatedDevice.Port, pipeFitting: pipeFitting} + //构建管件pipeFitting与管线的关系 + switch portRelatedDevice.Port { + case proto.Port_A: + pipeFitting.PortA = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_B: + pipeFitting.PortB = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_C: + pipeFitting.PortC = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_D: + pipeFitting.PortD = &PipePort{port: pipePort, pipe: pipeModel} + } + } + case proto.DeviceType_DeviceType_CircuitBreaker: + { + circuitBreaker := relatedDevice.(*CircuitBreaker) + pipePortRelatedDevice = &CircuitBreakerPort{port: portRelatedDevice.Port, breaker: circuitBreaker} + switch portRelatedDevice.Port { + case proto.Port_A: + circuitBreaker.PortA = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_B: + circuitBreaker.PortB = &PipePort{port: pipePort, pipe: pipeModel} + } + } + case proto.DeviceType_DeviceType_ThreePositionSwitch: + { + tps := relatedDevice.(*ThreePositionSwitch) + pipePortRelatedDevice = &ThreePositionSwitchPort{port: portRelatedDevice.Port, breaker: tps} + switch portRelatedDevice.Port { + case proto.Port_A: + tps.PortA = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_B: + tps.PortB = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_C: + tps.PortC = &PipePort{port: pipePort, pipe: pipeModel} + } + } + case proto.DeviceType_DeviceType_HandcartSwitch: + { + hs := relatedDevice.(*HandcartSwitch) + pipePortRelatedDevice = &HandcartSwitchPort{port: portRelatedDevice.Port, breaker: hs} + switch portRelatedDevice.Port { + case proto.Port_A: + hs.PortA = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_B: + hs.PortB = &PipePort{port: pipePort, pipe: pipeModel} + } + } + case proto.DeviceType_DeviceType_Rectifier: + { + rectifier := relatedDevice.(*Rectifier) + pipePortRelatedDevice = &RectifierPort{port: portRelatedDevice.Port, rectifier: rectifier} + switch portRelatedDevice.Port { + case proto.Port_A: + rectifier.PortA = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_B: + rectifier.PortB = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_C: + rectifier.PortC = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_D: + rectifier.PortD = &PipePort{port: pipePort, pipe: pipeModel} + } + } + case proto.DeviceType_DeviceType_Disconnector: + { + disconnecter := relatedDevice.(*Disconnector) + pipePortRelatedDevice = &DisconnectorPort{port: portRelatedDevice.Port, breaker: disconnecter} + switch portRelatedDevice.Port { + case proto.Port_A: + disconnecter.PortA = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_B: + disconnecter.PortB = &PipePort{port: pipePort, pipe: pipeModel} + } + } + case proto.DeviceType_DeviceType_VoltageTransformer: + { + vt := relatedDevice.(*VoltageTransformer) + pipePortRelatedDevice = &VoltageTransformerPort{port: portRelatedDevice.Port, vt: vt} + switch portRelatedDevice.Port { + case proto.Port_A: + vt.PortA = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_B: + vt.PortB = &PipePort{port: pipePort, pipe: pipeModel} + case proto.Port_C: + vt.PortC = &PipePort{port: pipePort, pipe: pipeModel} + } + } + case proto.DeviceType_DeviceType_PowerSource: + { + ps := relatedDevice.(*PowerSource) + pipePortRelatedDevice = &PowerSourcePort{ps: ps} + ps.PortA = &PipePort{port: pipePort, pipe: pipeModel} + } + } + if pipePortRelatedDevice != nil { + if pipePort == proto.Port_A { + pipeModel.PortA = pipePortRelatedDevice + } else { + pipeModel.PortB = pipePortRelatedDevice + } + } + // + return nil + } + // + if pipeA != nil { + if e := buildRelationship(proto.Port_A, pipeA); e != nil { + return e + } + } + if pipeB != nil { + if e := buildRelationship(proto.Port_B, pipeB); e != nil { + return e + } + } + } + // + return nil +}