2023-08-29 14:59:31 +08:00
|
|
|
package repository
|
|
|
|
|
2023-09-06 16:20:36 +08:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
|
|
)
|
2023-08-29 14:59:31 +08:00
|
|
|
|
|
|
|
type Repository struct {
|
2023-09-06 16:20:36 +08:00
|
|
|
id string
|
|
|
|
version string
|
|
|
|
physicalSectionMap map[string]*PhysicalSection
|
|
|
|
//这里不包含区段边界
|
|
|
|
checkPointMap map[string]*CheckPoint
|
|
|
|
turnoutMap map[string]*Turnout
|
|
|
|
signalMap map[string]*Signal
|
|
|
|
responderMap map[string]*Responder
|
|
|
|
slopeMap map[string]*Slope
|
|
|
|
sectionalCurvatureMap map[string]*SectionalCurvature
|
|
|
|
|
|
|
|
kilometerConvertMap map[string]*proto.KilometerConvert
|
2023-08-29 14:59:31 +08:00
|
|
|
}
|
|
|
|
|
2023-08-29 18:01:32 +08:00
|
|
|
func NewRepository(id string, version string) *Repository {
|
|
|
|
return &Repository{
|
2023-09-06 16:20:36 +08:00
|
|
|
id: id,
|
|
|
|
version: version,
|
|
|
|
//modelMap: make(map[string]model.Identity),
|
|
|
|
physicalSectionMap: make(map[string]*PhysicalSection),
|
|
|
|
turnoutMap: make(map[string]*Turnout),
|
|
|
|
signalMap: make(map[string]*Signal),
|
|
|
|
responderMap: make(map[string]*Responder),
|
|
|
|
slopeMap: make(map[string]*Slope),
|
|
|
|
sectionalCurvatureMap: make(map[string]*SectionalCurvature),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *Repository) getModel(deviceId string, deviceType proto.DeviceType) (Identity, error) {
|
|
|
|
switch deviceType {
|
|
|
|
case proto.DeviceType_DeviceType_PhysicalSection:
|
|
|
|
return repo.physicalSectionMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_CheckPoint:
|
|
|
|
return repo.checkPointMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_Turnout:
|
|
|
|
return repo.turnoutMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_Signal:
|
|
|
|
return repo.signalMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_Responder:
|
|
|
|
return repo.responderMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_Slope:
|
|
|
|
return repo.slopeMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_SectionalCurvature:
|
|
|
|
return repo.sectionalCurvatureMap[deviceId], nil
|
|
|
|
default:
|
|
|
|
return nil, errors.New(fmt.Sprintf("仓库中不存在[%s]类型的模型", deviceType))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *Repository) PhysicalSectionList() []*PhysicalSection {
|
|
|
|
list := make([]*PhysicalSection, len(repo.physicalSectionMap))
|
|
|
|
for _, m := range repo.physicalSectionMap {
|
|
|
|
list = append(list, m)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *Repository) TurnoutList() []*Turnout {
|
|
|
|
list := make([]*Turnout, len(repo.turnoutMap))
|
|
|
|
for _, m := range repo.turnoutMap {
|
|
|
|
list = append(list, m)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *Repository) SignalList() []*Signal {
|
|
|
|
list := make([]*Signal, len(repo.signalMap))
|
|
|
|
for _, m := range repo.signalMap {
|
|
|
|
list = append(list, m)
|
2023-08-29 18:01:32 +08:00
|
|
|
}
|
2023-09-06 16:20:36 +08:00
|
|
|
return list
|
2023-08-29 18:01:32 +08:00
|
|
|
}
|
|
|
|
|
2023-09-06 16:20:36 +08:00
|
|
|
func (repo *Repository) ResponderList() []*Responder {
|
|
|
|
list := make([]*Responder, len(repo.responderMap))
|
|
|
|
for _, m := range repo.responderMap {
|
|
|
|
list = append(list, m)
|
|
|
|
}
|
|
|
|
return list
|
2023-08-29 18:01:32 +08:00
|
|
|
}
|
|
|
|
|
2023-09-06 16:20:36 +08:00
|
|
|
func (repo *Repository) SlopeList() []*Slope {
|
|
|
|
list := make([]*Slope, len(repo.slopeMap))
|
|
|
|
for _, m := range repo.slopeMap {
|
|
|
|
list = append(list, m)
|
|
|
|
}
|
|
|
|
return list
|
2023-08-29 18:01:32 +08:00
|
|
|
}
|
|
|
|
|
2023-09-06 16:20:36 +08:00
|
|
|
func (repo *Repository) SectionalCurvatureList() []*SectionalCurvature {
|
|
|
|
list := make([]*SectionalCurvature, len(repo.sectionalCurvatureMap))
|
|
|
|
for _, m := range repo.sectionalCurvatureMap {
|
|
|
|
list = append(list, m)
|
|
|
|
}
|
|
|
|
return list
|
2023-08-29 18:01:32 +08:00
|
|
|
}
|
|
|
|
|
2023-09-06 16:20:36 +08:00
|
|
|
func (repo *Repository) AddPhysicalSection(section *PhysicalSection) {
|
|
|
|
repo.physicalSectionMap[section.Id()] = section
|
|
|
|
//repo.modelMap[section.Id()] = section
|
2023-08-29 14:59:31 +08:00
|
|
|
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
2023-08-29 14:59:31 +08:00
|
|
|
|
2023-09-06 16:20:36 +08:00
|
|
|
func buildKilometerConvertKey(cs1 string, cs2 string, dir1 proto.Direction, dir2 proto.Direction) string {
|
|
|
|
return cs1 + dir1.String() + cs2 + dir2.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *Repository) addKilometerConvert(kc *proto.KilometerConvert) {
|
|
|
|
repo.kilometerConvertMap[buildKilometerConvertKey(kc.KmA.CoordinateSystem, kc.KmB.CoordinateSystem, kc.KmA.Direction, kc.KmB.Direction)] = kc
|
|
|
|
repo.kilometerConvertMap[buildKilometerConvertKey(kc.KmB.CoordinateSystem, kc.KmA.CoordinateSystem, kc.KmB.Direction, kc.KmA.Direction)] = kc
|
|
|
|
}
|
2023-08-29 14:59:31 +08:00
|
|
|
|
2023-09-06 16:20:36 +08:00
|
|
|
func (repo *Repository) getKilometerConvert(cs1, cs2 string, dir1, dir2 proto.Direction) (*proto.KilometerConvert, error) {
|
|
|
|
convert := repo.kilometerConvertMap[buildKilometerConvertKey(cs1, cs2, dir1, dir2)]
|
|
|
|
if convert == nil {
|
|
|
|
return nil, errors.New(fmt.Sprintf("没有[%s-%s]的公里标转换数据", cs1, cs2))
|
|
|
|
}
|
|
|
|
return convert, nil
|
|
|
|
}
|