【修改公里标绑定逻辑】

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

View File

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