355 lines
13 KiB
Go
355 lines
13 KiB
Go
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, protoData.E1, protoData.E2)
|
|
repository.VoltageTransformerMap[m.Id()] = m
|
|
}
|
|
//ISCS电源
|
|
for _, protoData := range source.PowerSources {
|
|
m := NewPowerSource(protoData.Id, protoData.Code, protoData.Voltage, protoData.Sx, protoData.Ac)
|
|
repository.PowerSourceMap[m.Id()] = m
|
|
}
|
|
//ISCS避雷器
|
|
for _, protoData := range source.LightningArresters {
|
|
m := NewLightningArrester(protoData.Id, protoData.Code)
|
|
repository.LightningArresterMap[m.Id()] = m
|
|
}
|
|
//ISCS接地装置
|
|
for _, protoData := range source.EarthingDevices {
|
|
m := NewEarthingDevice(protoData.Id, protoData.Code)
|
|
repository.EarthingDeviceMap[m.Id()] = m
|
|
}
|
|
//ISCS网络交换机
|
|
for _, protoData := range source.NetworkSwitches {
|
|
m := NewNetworkSwitch(protoData.Id, protoData.Code)
|
|
repository.NetworkSwitchMap[m.Id()] = m
|
|
}
|
|
//ISCS线柜
|
|
for _, protoData := range source.WireCabinets {
|
|
m := NewWireCabinet(protoData.Id, protoData.Code)
|
|
repository.WireCabinetMap[m.Id()] = m
|
|
}
|
|
//ISCS风亭
|
|
for _, protoData := range source.AirPavilions {
|
|
m := NewAirPavilion(protoData.Id, protoData.Code, protoData.PavilionType)
|
|
repository.AirPavilionMap[m.Id()] = m
|
|
}
|
|
//ISCS阀门
|
|
for _, protoData := range source.Valves {
|
|
m := NewValve(protoData.Id, protoData.Code, protoData.ValveType)
|
|
repository.ValveMap[m.Id()] = m
|
|
}
|
|
//ISCS 混合室静压箱
|
|
for _, protoData := range source.GasMixingChambers {
|
|
m := NewGasMixingChamber(protoData.Id, protoData.Code)
|
|
repository.GasMixingChamberMap[m.Id()] = m
|
|
}
|
|
//ISCS组合式空调
|
|
for _, protoData := range source.CombinationAirConditioners {
|
|
m := NewCombinationAirConditioner(protoData.Id, protoData.Code)
|
|
repository.CombinationAirConditionerMap[m.Id()] = m
|
|
}
|
|
//ISCS净化装置
|
|
for _, protoData := range source.AirPurificationDevices {
|
|
m := NewAirPurificationDevice(protoData.Id, protoData.Code)
|
|
repository.AirPurificationDeviceMap[m.Id()] = m
|
|
}
|
|
//ISCS空气幕
|
|
for _, protoData := range source.AirCurtains {
|
|
m := NewAirCurtain(protoData.Id, protoData.Code)
|
|
repository.AirCurtainMap[m.Id()] = m
|
|
}
|
|
//ISCS风机
|
|
for _, protoData := range source.Fans {
|
|
m := NewFan(protoData.Id, protoData.Code, protoData.FanType)
|
|
repository.FanMap[m.Id()] = m
|
|
}
|
|
//ISCS环境
|
|
for _, protoData := range source.GasEnvironments {
|
|
m := NewEnvironment(protoData.Id, protoData.Code)
|
|
repository.EnvironmentMap[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_AirPavilion: //管线关联风亭
|
|
{
|
|
airPavilion := relatedDevice.(*AirPavilion)
|
|
pipePortRelatedDevice = &AirPavilionPort{port: portRelatedDevice.Port, device: airPavilion}
|
|
airPavilion.PortA = &PipePort{port: pipePort, pipe: pipeModel}
|
|
}
|
|
case proto.DeviceType_DeviceType_Valve: //管线关联风阀
|
|
{
|
|
valve := relatedDevice.(*Valve)
|
|
pipePortRelatedDevice = &ValvePort{port: portRelatedDevice.Port, device: valve}
|
|
switch portRelatedDevice.Port {
|
|
case proto.Port_A:
|
|
valve.PortA = &PipePort{port: pipePort, pipe: pipeModel}
|
|
case proto.Port_B:
|
|
valve.PortB = &PipePort{port: pipePort, pipe: pipeModel}
|
|
}
|
|
}
|
|
case proto.DeviceType_DeviceType_GasMixingChamber:
|
|
{
|
|
gasMixingChamber := relatedDevice.(*GasMixingChamber)
|
|
pipePortRelatedDevice = &GasMixingChamberPort{port: portRelatedDevice.Port, device: gasMixingChamber}
|
|
switch portRelatedDevice.Port {
|
|
case proto.Port_A:
|
|
gasMixingChamber.PortsA = append(gasMixingChamber.PortsA, &PipePort{port: pipePort, pipe: pipeModel})
|
|
case proto.Port_B:
|
|
gasMixingChamber.PortsB = append(gasMixingChamber.PortsB, &PipePort{port: pipePort, pipe: pipeModel})
|
|
}
|
|
}
|
|
case proto.DeviceType_DeviceType_CombinationAirConditioner:
|
|
{
|
|
combinationAirConditioner := relatedDevice.(*CombinationAirConditioner)
|
|
pipePortRelatedDevice = &CombinationAirConditionerPort{port: portRelatedDevice.Port, device: combinationAirConditioner}
|
|
switch portRelatedDevice.Port {
|
|
case proto.Port_A:
|
|
combinationAirConditioner.PortA = &PipePort{port: pipePort, pipe: pipeModel}
|
|
case proto.Port_B:
|
|
combinationAirConditioner.PortB = &PipePort{port: pipePort, pipe: pipeModel}
|
|
case proto.Port_C:
|
|
combinationAirConditioner.PortC = &PipePort{port: pipePort, pipe: pipeModel}
|
|
case proto.Port_D:
|
|
combinationAirConditioner.PortD = &PipePort{port: pipePort, pipe: pipeModel}
|
|
}
|
|
}
|
|
case proto.DeviceType_DeviceType_AirPurificationDevice:
|
|
{
|
|
airPurificationDevice := relatedDevice.(*AirPurificationDevice)
|
|
pipePortRelatedDevice = &AirPurificationDevicePort{port: portRelatedDevice.Port, device: airPurificationDevice}
|
|
switch portRelatedDevice.Port {
|
|
case proto.Port_A:
|
|
airPurificationDevice.PortA = &PipePort{port: pipePort, pipe: pipeModel}
|
|
case proto.Port_B:
|
|
airPurificationDevice.PortB = &PipePort{port: pipePort, pipe: pipeModel}
|
|
}
|
|
}
|
|
case proto.DeviceType_DeviceType_Fan:
|
|
{
|
|
fan := relatedDevice.(*Fan)
|
|
pipePortRelatedDevice = &FanPort{port: portRelatedDevice.Port, device: fan}
|
|
switch portRelatedDevice.Port {
|
|
case proto.Port_A:
|
|
fan.PortA = &PipePort{port: pipePort, pipe: pipeModel}
|
|
case proto.Port_B:
|
|
fan.PortB = &PipePort{port: pipePort, pipe: pipeModel}
|
|
}
|
|
}
|
|
case proto.DeviceType_DeviceType_Environment:
|
|
{
|
|
gasEnvironment := relatedDevice.(*Environment)
|
|
pipePortRelatedDevice = &EnvironmentPort{port: portRelatedDevice.Port, device: gasEnvironment}
|
|
switch portRelatedDevice.Port {
|
|
case proto.Port_A:
|
|
gasEnvironment.PortsA = append(gasEnvironment.PortsA, &PipePort{port: pipePort, pipe: pipeModel})
|
|
case proto.Port_B:
|
|
gasEnvironment.PortsB = append(gasEnvironment.PortsB, &PipePort{port: pipePort, pipe: pipeModel})
|
|
}
|
|
}
|
|
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_LightningArrester:
|
|
{
|
|
lightningArrester := relatedDevice.(*LightningArrester)
|
|
pipePortRelatedDevice = &LightningArresterPort{port: portRelatedDevice.Port, arrester: lightningArrester}
|
|
switch portRelatedDevice.Port {
|
|
case proto.Port_A:
|
|
lightningArrester.PortA = &PipePort{port: pipePort, pipe: pipeModel}
|
|
case proto.Port_B:
|
|
lightningArrester.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}
|
|
}
|
|
case proto.DeviceType_DeviceType_EarthingDevice:
|
|
{
|
|
ed := relatedDevice.(*EarthingDevice)
|
|
ed.PortA = &PipePort{port: pipePort, pipe: pipeModel}
|
|
pipePortRelatedDevice = &EarthingDevicePort{ed: ed}
|
|
}
|
|
}
|
|
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
|
|
}
|