【修改公里标绑定逻辑】

This commit is contained in:
weizhihong 2023-12-05 15:01:34 +08:00
parent 582a291abf
commit cec59a573e
2 changed files with 13 additions and 8 deletions

View File

@ -1,8 +1,8 @@
package repository package repository
import ( import (
"errors"
"fmt" "fmt"
"joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/repository/model/proto"
"joylink.club/rtsssimulation/util/number" "joylink.club/rtsssimulation/util/number"
) )
@ -106,7 +106,7 @@ func (s *PhysicalSection) bindDevicePort(port proto.Port, devicePort DevicePort)
_, isSectionPort := devicePort.(*PhysicalSectionPort) _, isSectionPort := devicePort.(*PhysicalSectionPort)
_, isTurnoutPort := devicePort.(*TurnoutPort) _, isTurnoutPort := devicePort.(*TurnoutPort)
if !isSectionPort && !isTurnoutPort { if !isSectionPort && !isTurnoutPort {
return errors.New(fmt.Sprintf("物理区段不能与[%s]类型的设备端口关联", devicePort.Device().Type())) return fmt.Errorf("物理区段不能与[%s]类型的设备端口关联", devicePort.Device().Type())
} }
switch port { switch port {
case proto.Port_A: case proto.Port_A:
@ -114,20 +114,23 @@ func (s *PhysicalSection) bindDevicePort(port proto.Port, devicePort DevicePort)
case proto.Port_B: case proto.Port_B:
s.bRelation = devicePort s.bRelation = devicePort
default: default:
return errors.New(fmt.Sprintf("物理区段无端口[%s]", port)) return fmt.Errorf("物理区段无端口[%s]", port)
} }
return nil return nil
} }
// 绑定区段边界公里标。(仅限非道岔物理区段调用) // 绑定区段边界公里标。(仅限非道岔物理区段调用)
func (s *PhysicalSection) bindBoundaryKm(km *proto.Kilometer, port proto.Port) error { func (s *PhysicalSection) bindBoundaryKm(km *proto.Kilometer, port proto.Port) error {
if km == nil {
return nil
}
switch port { switch port {
case proto.Port_A: case proto.Port_A:
s.aKm = km s.aKm = km
case proto.Port_B: case proto.Port_B:
s.bKm = km s.bKm = km
default: default:
return errors.New(fmt.Sprintf("区段无端口[%s]", port)) return fmt.Errorf("区段无端口[%s]", port)
} }
return nil return nil
} }

View File

@ -1,7 +1,6 @@
package repository package repository
import ( import (
"errors"
"fmt" "fmt"
"joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/repository/model/proto"
@ -110,7 +109,7 @@ func (t *Turnout) bindDevicePort(port proto.Port, devicePort DevicePort) error {
_, isSectionPort := devicePort.(*PhysicalSectionPort) _, isSectionPort := devicePort.(*PhysicalSectionPort)
_, isTurnoutPort := devicePort.(*TurnoutPort) _, isTurnoutPort := devicePort.(*TurnoutPort)
if !isSectionPort && !isTurnoutPort { if !isSectionPort && !isTurnoutPort {
return errors.New(fmt.Sprintf("道岔不能与[%s]类型的设备端口关联", devicePort.Device().Type())) return fmt.Errorf("道岔不能与[%s]类型的设备端口关联", devicePort.Device().Type())
} }
switch port { switch port {
case proto.Port_A: case proto.Port_A:
@ -120,7 +119,7 @@ func (t *Turnout) bindDevicePort(port proto.Port, devicePort DevicePort) error {
case proto.Port_C: case proto.Port_C:
t.cDevicePort = devicePort t.cDevicePort = devicePort
default: default:
return errors.New(fmt.Sprintf("道岔无端口[%s]", port)) return fmt.Errorf("道岔无端口[%s]", port)
} }
return nil return nil
} }
@ -137,6 +136,9 @@ func (t *Turnout) bindLinkPort(port proto.Port, linkPort *LinkPort) {
} }
func (t *Turnout) bindBoundaryKm(km *proto.Kilometer, port proto.Port) error { func (t *Turnout) bindBoundaryKm(km *proto.Kilometer, port proto.Port) error {
if km == nil {
return nil
}
switch port { switch port {
case proto.Port_A: case proto.Port_A:
t.aKm = km t.aKm = km
@ -145,7 +147,7 @@ func (t *Turnout) bindBoundaryKm(km *proto.Kilometer, port proto.Port) error {
case proto.Port_C: case proto.Port_C:
t.cKm = km t.cKm = km
default: default:
return errors.New(fmt.Sprintf("道岔无端口[%s]", port)) return fmt.Errorf("道岔无端口[%s]", port)
} }
return nil return nil
} }