2023-08-29 14:59:31 +08:00
|
|
|
package repository
|
|
|
|
|
2023-09-06 16:20:36 +08:00
|
|
|
import (
|
|
|
|
"fmt"
|
2023-10-19 16:38:46 +08:00
|
|
|
"math"
|
2023-09-28 09:20:28 +08:00
|
|
|
|
2023-09-06 16:20:36 +08:00
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
|
|
)
|
2023-08-29 14:59:31 +08:00
|
|
|
|
|
|
|
type Repository struct {
|
2023-12-25 14:09:29 +08:00
|
|
|
id string
|
|
|
|
version string
|
|
|
|
coordinate *MapCoordinate // 基准坐标系类型,在列车画图时统一坐标系
|
|
|
|
physicalSectionMap map[string]*PhysicalSection
|
|
|
|
checkPointMap map[string]*CheckPoint
|
|
|
|
turnoutMap map[string]*Turnout
|
|
|
|
signalMap map[string]*Signal
|
2024-01-10 11:12:19 +08:00
|
|
|
responderMap map[string]*Transponder
|
2023-12-25 14:09:29 +08:00
|
|
|
slopeMap map[string]*Slope
|
|
|
|
sectionalCurvatureMap map[string]*SectionalCurvature
|
|
|
|
kilometerConvertMap map[string]*proto.KilometerConvert
|
|
|
|
relayMap map[string]*Relay
|
|
|
|
phaseFailureProtectorMap map[string]*PhaseFailureProtector
|
|
|
|
buttonMap map[string]*Button
|
|
|
|
psdMap map[string]*Psd
|
|
|
|
lightMap map[string]*Light
|
|
|
|
alarmMap map[string]*Alarm
|
|
|
|
stationMap map[string]*Station
|
|
|
|
mkxMap map[string]*Mkx
|
|
|
|
keyMap map[string]*Key
|
|
|
|
linkMap map[string]*Link
|
|
|
|
platformMap map[string]*Platform
|
|
|
|
centralizedMap map[string]*proto.CentralizedStationRef
|
2024-03-07 17:40:51 +08:00
|
|
|
ckmMap map[string]*Ckm
|
|
|
|
xcjMap map[string]*Xcj
|
2023-12-25 14:09:29 +08:00
|
|
|
PipeMap map[string]*Pipe //ISCS 管线
|
|
|
|
PipeFittingMap map[string]*PipeFitting //ISCS 管件
|
|
|
|
CircuitBreakerMap map[string]*CircuitBreaker //ISCS 断路器
|
|
|
|
ThreePositionSwitchMap map[string]*ThreePositionSwitch //ISCS 三工位开关
|
|
|
|
HandcartSwitchMap map[string]*HandcartSwitch //ISCS 手车
|
|
|
|
RectifierMap map[string]*Rectifier //ISCS 整流器
|
|
|
|
DisconnectorMap map[string]*Disconnector //ISCS 隔离开关
|
|
|
|
VoltageTransformerMap map[string]*VoltageTransformer //ISCS 变压器
|
|
|
|
PowerSourceMap map[string]*PowerSource //ISCS 电源
|
|
|
|
LightningArresterMap map[string]*LightningArrester //ISCS 避雷器
|
|
|
|
EarthingDeviceMap map[string]*EarthingDevice //ISCS 接地装置
|
|
|
|
NetworkSwitchMap map[string]*NetworkSwitch //ISCS 网络交换机
|
|
|
|
WireCabinetMap map[string]*WireCabinet //ISCS 线柜
|
|
|
|
AirPavilionMap map[string]*AirPavilion //ISCS 风亭
|
|
|
|
ValveMap map[string]*Valve //ISCS 阀门
|
|
|
|
GasMixingChamberMap map[string]*GasMixingChamber //ISCS 混合室静压箱
|
|
|
|
CombinationAirConditionerMap map[string]*CombinationAirConditioner //ISCS组合式空调
|
|
|
|
AirPurificationDeviceMap map[string]*AirPurificationDevice //ISCS净化装置
|
|
|
|
AirCurtainMap map[string]*AirCurtain //ISCS空气幕
|
|
|
|
FanMap map[string]*Fan //ISCS风机
|
2023-12-29 17:00:26 +08:00
|
|
|
EnvironmentMap map[string]*Environment //ISCS气体环境
|
2023-08-29 14:59:31 +08:00
|
|
|
}
|
|
|
|
|
2023-09-20 15:14:38 +08:00
|
|
|
func newRepository(id string, version string) *Repository {
|
2023-08-29 18:01:32 +08:00
|
|
|
return &Repository{
|
2023-12-25 14:09:29 +08:00
|
|
|
id: id,
|
|
|
|
version: version,
|
|
|
|
physicalSectionMap: make(map[string]*PhysicalSection),
|
|
|
|
checkPointMap: make(map[string]*CheckPoint),
|
|
|
|
turnoutMap: make(map[string]*Turnout),
|
|
|
|
signalMap: make(map[string]*Signal),
|
2024-01-10 11:12:19 +08:00
|
|
|
responderMap: make(map[string]*Transponder),
|
2023-12-25 14:09:29 +08:00
|
|
|
slopeMap: make(map[string]*Slope),
|
|
|
|
sectionalCurvatureMap: make(map[string]*SectionalCurvature),
|
|
|
|
kilometerConvertMap: make(map[string]*proto.KilometerConvert),
|
|
|
|
relayMap: make(map[string]*Relay),
|
|
|
|
phaseFailureProtectorMap: make(map[string]*PhaseFailureProtector),
|
|
|
|
linkMap: make(map[string]*Link),
|
|
|
|
buttonMap: make(map[string]*Button),
|
|
|
|
psdMap: make(map[string]*Psd),
|
|
|
|
lightMap: make(map[string]*Light),
|
|
|
|
alarmMap: make(map[string]*Alarm),
|
|
|
|
stationMap: make(map[string]*Station),
|
|
|
|
mkxMap: make(map[string]*Mkx),
|
|
|
|
keyMap: make(map[string]*Key),
|
|
|
|
platformMap: make(map[string]*Platform),
|
|
|
|
centralizedMap: make(map[string]*proto.CentralizedStationRef),
|
|
|
|
PipeMap: make(map[string]*Pipe), //ISCS 管线
|
|
|
|
PipeFittingMap: make(map[string]*PipeFitting), //ISCS 管件
|
|
|
|
CircuitBreakerMap: make(map[string]*CircuitBreaker), //ISCS 断路器
|
|
|
|
ThreePositionSwitchMap: make(map[string]*ThreePositionSwitch), //ISCS 三工位开关
|
|
|
|
HandcartSwitchMap: make(map[string]*HandcartSwitch), //ISCS 手车
|
|
|
|
RectifierMap: make(map[string]*Rectifier), //ISCS 整流器
|
|
|
|
DisconnectorMap: make(map[string]*Disconnector), //ISCS 隔离开关
|
|
|
|
VoltageTransformerMap: make(map[string]*VoltageTransformer), //ISCS 变压器
|
|
|
|
PowerSourceMap: make(map[string]*PowerSource), //ISCS 电源
|
|
|
|
LightningArresterMap: make(map[string]*LightningArrester), //ISCS 避雷器
|
|
|
|
EarthingDeviceMap: make(map[string]*EarthingDevice), //ISCS 接地装置
|
|
|
|
NetworkSwitchMap: make(map[string]*NetworkSwitch), //ISCS网络交换机
|
|
|
|
WireCabinetMap: make(map[string]*WireCabinet), //ISCS线柜
|
|
|
|
AirPavilionMap: make(map[string]*AirPavilion), //ISCS 风亭
|
|
|
|
ValveMap: make(map[string]*Valve), //ISCS 阀门
|
|
|
|
GasMixingChamberMap: make(map[string]*GasMixingChamber), //ISCS 混合室静压箱
|
|
|
|
CombinationAirConditionerMap: make(map[string]*CombinationAirConditioner), //ISCS组合式空调
|
|
|
|
AirPurificationDeviceMap: make(map[string]*AirPurificationDevice), //ISCS净化装置
|
|
|
|
AirCurtainMap: make(map[string]*AirCurtain), //ISCS空气幕
|
|
|
|
FanMap: make(map[string]*Fan), //ISCS风机
|
2023-12-29 17:00:26 +08:00
|
|
|
EnvironmentMap: make(map[string]*Environment), //ISCS气体环境
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-25 15:39:03 +08:00
|
|
|
// FindById 根据模型的复合id获取模型数据
|
|
|
|
func (repo *Repository) FindById(id string) Identity {
|
|
|
|
if md, ok := repo.turnoutMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.signalMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.relayMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
2023-11-09 14:18:02 +08:00
|
|
|
if md, ok := repo.physicalSectionMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.checkPointMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
2024-01-10 11:12:19 +08:00
|
|
|
if md, ok := repo.responderMap[id]; ok {
|
2023-11-09 14:18:02 +08:00
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.stationMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.platformMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
2023-12-20 10:53:12 +08:00
|
|
|
//ISCS-begin
|
2023-12-20 15:22:36 +08:00
|
|
|
if md, ok := repo.PipeMap[id]; ok {
|
2023-12-20 10:53:12 +08:00
|
|
|
return md
|
|
|
|
}
|
2023-12-20 15:22:36 +08:00
|
|
|
if md, ok := repo.PipeFittingMap[id]; ok {
|
2023-12-20 10:53:12 +08:00
|
|
|
return md
|
|
|
|
}
|
2023-12-20 15:22:36 +08:00
|
|
|
if md, ok := repo.CircuitBreakerMap[id]; ok {
|
2023-12-20 10:53:12 +08:00
|
|
|
return md
|
|
|
|
}
|
2023-12-20 15:22:36 +08:00
|
|
|
if md, ok := repo.ThreePositionSwitchMap[id]; ok {
|
2023-12-20 10:53:12 +08:00
|
|
|
return md
|
|
|
|
}
|
2023-12-20 15:22:36 +08:00
|
|
|
if md, ok := repo.HandcartSwitchMap[id]; ok {
|
2023-12-20 10:53:12 +08:00
|
|
|
return md
|
|
|
|
}
|
2023-12-20 15:22:36 +08:00
|
|
|
if md, ok := repo.RectifierMap[id]; ok {
|
2023-12-20 10:53:12 +08:00
|
|
|
return md
|
|
|
|
}
|
2023-12-20 15:22:36 +08:00
|
|
|
if md, ok := repo.DisconnectorMap[id]; ok {
|
2023-12-20 10:53:12 +08:00
|
|
|
return md
|
|
|
|
}
|
2023-12-20 15:22:36 +08:00
|
|
|
if md, ok := repo.VoltageTransformerMap[id]; ok {
|
2023-12-20 10:53:12 +08:00
|
|
|
return md
|
|
|
|
}
|
2023-12-20 15:22:36 +08:00
|
|
|
if md, ok := repo.PowerSourceMap[id]; ok {
|
2023-12-20 10:53:12 +08:00
|
|
|
return md
|
|
|
|
}
|
2023-12-22 10:57:43 +08:00
|
|
|
if md, ok := repo.LightningArresterMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
2023-12-22 13:20:06 +08:00
|
|
|
if md, ok := repo.EarthingDeviceMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
2023-12-22 15:29:57 +08:00
|
|
|
if md, ok := repo.NetworkSwitchMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.WireCabinetMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
2023-12-25 14:09:29 +08:00
|
|
|
if md, ok := repo.AirPavilionMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.ValveMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.GasMixingChamberMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.CombinationAirConditionerMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.AirPurificationDeviceMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.AirCurtainMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
if md, ok := repo.FanMap[id]; ok {
|
|
|
|
return md
|
|
|
|
}
|
2023-12-29 17:00:26 +08:00
|
|
|
if md, ok := repo.EnvironmentMap[id]; ok {
|
2023-12-25 14:09:29 +08:00
|
|
|
return md
|
|
|
|
}
|
2023-12-20 10:53:12 +08:00
|
|
|
//ISCS-end
|
|
|
|
|
2023-09-25 15:39:03 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-09-20 15:14:38 +08:00
|
|
|
func (repo *Repository) PhysicalSectionList() []*PhysicalSection {
|
|
|
|
var list []*PhysicalSection
|
|
|
|
for _, model := range repo.physicalSectionMap {
|
|
|
|
list = append(list, model)
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
2023-09-20 15:14:38 +08:00
|
|
|
return list
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
2023-09-20 15:14:38 +08:00
|
|
|
func (repo *Repository) CheckPointList() []*CheckPoint {
|
|
|
|
var list []*CheckPoint
|
|
|
|
for _, model := range repo.checkPointMap {
|
|
|
|
list = append(list, model)
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
func (repo *Repository) TurnoutList() []*Turnout {
|
2023-09-20 15:14:38 +08:00
|
|
|
var list []*Turnout
|
|
|
|
for _, model := range repo.turnoutMap {
|
|
|
|
list = append(list, model)
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
func (repo *Repository) SignalList() []*Signal {
|
2023-09-20 15:14:38 +08:00
|
|
|
var list []*Signal
|
|
|
|
for _, model := range repo.signalMap {
|
|
|
|
list = append(list, model)
|
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
|
|
|
}
|
2024-01-10 11:12:19 +08:00
|
|
|
func (repo *Repository) ResponderList() []*Transponder {
|
2023-09-20 15:14:38 +08:00
|
|
|
var list []*Transponder
|
2024-01-10 11:12:19 +08:00
|
|
|
for _, model := range repo.responderMap {
|
2023-09-20 15:14:38 +08:00
|
|
|
list = append(list, model)
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
|
|
|
return list
|
2023-08-29 18:01:32 +08:00
|
|
|
}
|
2023-11-27 15:09:09 +08:00
|
|
|
func (repo *Repository) ResponderListByLink(linkId string) []*Transponder {
|
|
|
|
var list []*Transponder
|
2024-01-10 11:12:19 +08:00
|
|
|
for _, model := range repo.responderMap {
|
2023-11-27 15:09:09 +08:00
|
|
|
if model.linkPosition.link.Id() == linkId {
|
|
|
|
list = append(list, model)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
2023-09-06 16:20:36 +08:00
|
|
|
func (repo *Repository) SlopeList() []*Slope {
|
2023-09-20 15:14:38 +08:00
|
|
|
var list []*Slope
|
|
|
|
for _, model := range repo.slopeMap {
|
|
|
|
list = append(list, model)
|
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) SectionalCurvatureList() []*SectionalCurvature {
|
2023-09-20 15:14:38 +08:00
|
|
|
var list []*SectionalCurvature
|
|
|
|
for _, model := range repo.sectionalCurvatureMap {
|
|
|
|
list = append(list, model)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
func (repo *Repository) LinkList() []*Link {
|
|
|
|
var list []*Link
|
|
|
|
for _, model := range repo.linkMap {
|
|
|
|
list = append(list, model)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
func (repo *Repository) KilometerConvertList() []*proto.KilometerConvert {
|
|
|
|
var list []*proto.KilometerConvert
|
|
|
|
for _, model := range repo.kilometerConvertMap {
|
|
|
|
list = append(list, model)
|
2023-09-22 15:13:24 +08:00
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
func (repo *Repository) RelayList() []*Relay {
|
|
|
|
var list []*Relay
|
|
|
|
for _, model := range repo.relayMap {
|
|
|
|
list = append(list, model)
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
|
|
|
return list
|
2023-08-29 18:01:32 +08:00
|
|
|
}
|
|
|
|
|
2023-10-10 11:05:26 +08:00
|
|
|
func (repo *Repository) ButtonList() []*Button {
|
|
|
|
var list []*Button
|
|
|
|
for _, model := range repo.buttonMap {
|
|
|
|
list = append(list, model)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
2023-10-12 17:55:40 +08:00
|
|
|
func (repo *Repository) PsdList() []*Psd {
|
|
|
|
var list []*Psd
|
|
|
|
for _, model := range repo.psdMap {
|
|
|
|
list = append(list, model)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
2023-10-17 10:26:31 +08:00
|
|
|
func (repo *Repository) MkxList() []*Mkx {
|
|
|
|
var list []*Mkx
|
|
|
|
for _, model := range repo.mkxMap {
|
|
|
|
list = append(list, model)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
2023-10-10 11:05:26 +08:00
|
|
|
|
2023-10-17 15:05:13 +08:00
|
|
|
func (repo *Repository) StationList() []*Station {
|
|
|
|
var list []*Station
|
|
|
|
for _, model := range repo.stationMap {
|
|
|
|
list = append(list, model)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
2023-10-20 13:13:44 +08:00
|
|
|
func (repo *Repository) KeyList() []*Key {
|
|
|
|
var list []*Key
|
|
|
|
for _, model := range repo.keyMap {
|
|
|
|
list = append(list, model)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
2023-11-03 17:26:32 +08:00
|
|
|
func (repo *Repository) CiQcList() []*proto.CentralizedStationRef {
|
2023-10-31 09:24:39 +08:00
|
|
|
var list []*proto.CentralizedStationRef
|
|
|
|
for _, model := range repo.centralizedMap {
|
|
|
|
list = append(list, model)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
2024-03-07 17:40:51 +08:00
|
|
|
func (repo *Repository) CkmList() []*Ckm {
|
|
|
|
var list []*Ckm
|
|
|
|
for _, model := range repo.ckmMap {
|
|
|
|
list = append(list, model)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *Repository) XcjList() []*Xcj {
|
|
|
|
var list []*Xcj
|
|
|
|
for _, model := range repo.xcjMap {
|
|
|
|
list = append(list, model)
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
2023-11-07 17:47:41 +08:00
|
|
|
func (repo *Repository) GetCentralizedStationRef(centralizedStationId string) *proto.CentralizedStationRef {
|
|
|
|
return repo.centralizedMap[centralizedStationId]
|
|
|
|
}
|
2023-09-26 10:25:00 +08:00
|
|
|
func (repo *Repository) FindModel(deviceId string, deviceType proto.DeviceType) (Identity, error) {
|
2023-09-20 15:14:38 +08:00
|
|
|
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_Transponder:
|
2024-01-10 11:12:19 +08:00
|
|
|
return repo.responderMap[deviceId], nil
|
2023-09-20 15:14:38 +08:00
|
|
|
case proto.DeviceType_DeviceType_Slope:
|
|
|
|
return repo.slopeMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_SectionalCurvature:
|
|
|
|
return repo.sectionalCurvatureMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_Link:
|
|
|
|
return repo.linkMap[deviceId], nil
|
2023-11-01 16:52:03 +08:00
|
|
|
case proto.DeviceType_DeviceType_Psd:
|
|
|
|
return repo.psdMap[deviceId], nil
|
2023-12-20 10:53:12 +08:00
|
|
|
case proto.DeviceType_DeviceType_Pipe: //ISCS
|
2023-12-20 15:22:36 +08:00
|
|
|
return repo.PipeMap[deviceId], nil
|
2023-12-20 10:53:12 +08:00
|
|
|
case proto.DeviceType_DeviceType_PipeFitting:
|
2023-12-20 15:22:36 +08:00
|
|
|
return repo.PipeFittingMap[deviceId], nil
|
2023-12-20 10:53:12 +08:00
|
|
|
case proto.DeviceType_DeviceType_CircuitBreaker:
|
2023-12-20 15:22:36 +08:00
|
|
|
return repo.CircuitBreakerMap[deviceId], nil
|
2023-12-20 10:53:12 +08:00
|
|
|
case proto.DeviceType_DeviceType_ThreePositionSwitch:
|
2023-12-20 15:22:36 +08:00
|
|
|
return repo.ThreePositionSwitchMap[deviceId], nil
|
2023-12-20 10:53:12 +08:00
|
|
|
case proto.DeviceType_DeviceType_HandcartSwitch:
|
2023-12-20 15:22:36 +08:00
|
|
|
return repo.HandcartSwitchMap[deviceId], nil
|
2023-12-20 10:53:12 +08:00
|
|
|
case proto.DeviceType_DeviceType_Rectifier:
|
2023-12-20 15:22:36 +08:00
|
|
|
return repo.RectifierMap[deviceId], nil
|
2023-12-20 10:53:12 +08:00
|
|
|
case proto.DeviceType_DeviceType_Disconnector:
|
2023-12-20 15:22:36 +08:00
|
|
|
return repo.DisconnectorMap[deviceId], nil
|
2023-12-20 10:53:12 +08:00
|
|
|
case proto.DeviceType_DeviceType_VoltageTransformer:
|
2023-12-20 15:22:36 +08:00
|
|
|
return repo.VoltageTransformerMap[deviceId], nil
|
2023-12-20 10:53:12 +08:00
|
|
|
case proto.DeviceType_DeviceType_PowerSource:
|
2023-12-20 15:22:36 +08:00
|
|
|
return repo.PowerSourceMap[deviceId], nil
|
2023-12-22 10:57:43 +08:00
|
|
|
case proto.DeviceType_DeviceType_LightningArrester:
|
|
|
|
return repo.LightningArresterMap[deviceId], nil
|
2023-12-22 13:20:06 +08:00
|
|
|
case proto.DeviceType_DeviceType_EarthingDevice:
|
|
|
|
return repo.EarthingDeviceMap[deviceId], nil
|
2023-12-22 15:29:57 +08:00
|
|
|
case proto.DeviceType_DeviceType_NetworkSwitch:
|
|
|
|
return repo.NetworkSwitchMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_WireCabinet:
|
|
|
|
return repo.WireCabinetMap[deviceId], nil
|
2023-12-25 14:09:29 +08:00
|
|
|
case proto.DeviceType_DeviceType_AirPavilion:
|
|
|
|
return repo.AirPavilionMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_Valve:
|
|
|
|
return repo.ValveMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_GasMixingChamber:
|
|
|
|
return repo.GasMixingChamberMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_CombinationAirConditioner:
|
|
|
|
return repo.CombinationAirConditionerMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_AirPurificationDevice:
|
|
|
|
return repo.AirPurificationDeviceMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_AirCurtain:
|
|
|
|
return repo.AirCurtainMap[deviceId], nil
|
|
|
|
case proto.DeviceType_DeviceType_Fan:
|
|
|
|
return repo.FanMap[deviceId], nil
|
2023-12-29 17:00:26 +08:00
|
|
|
case proto.DeviceType_DeviceType_Environment:
|
|
|
|
return repo.EnvironmentMap[deviceId], nil
|
2023-09-20 15:14:38 +08:00
|
|
|
default:
|
2023-10-17 15:05:13 +08:00
|
|
|
return nil, fmt.Errorf("仓库中不存在[%s]类型的模型", deviceType)
|
2023-09-20 15:14:38 +08:00
|
|
|
}
|
|
|
|
}
|
2023-08-29 14:59:31 +08:00
|
|
|
|
2023-09-20 15:14:38 +08:00
|
|
|
func (repo *Repository) FindLink(id string) *Link {
|
|
|
|
return repo.linkMap[id]
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
2023-11-23 13:55:43 +08:00
|
|
|
func (repo *Repository) FindTransponder(id string) *Transponder {
|
2024-01-10 11:12:19 +08:00
|
|
|
return repo.responderMap[id]
|
2023-11-23 13:55:43 +08:00
|
|
|
}
|
2023-09-26 10:25:00 +08:00
|
|
|
func (repo *Repository) FindTurnout(id string) *Turnout {
|
|
|
|
return repo.turnoutMap[id]
|
|
|
|
}
|
|
|
|
|
2023-09-28 09:20:28 +08:00
|
|
|
func (repo *Repository) FindPhysicalSection(id string) *PhysicalSection {
|
|
|
|
return repo.physicalSectionMap[id]
|
|
|
|
}
|
|
|
|
|
2023-12-13 11:21:13 +08:00
|
|
|
func (repo *Repository) FindStationByStationName(name string) *Station {
|
|
|
|
for _, s := range repo.StationList() {
|
|
|
|
if s.code == name {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-11-01 16:52:03 +08:00
|
|
|
func (repo *Repository) FindPsd(id string) *Psd {
|
|
|
|
return repo.psdMap[id]
|
|
|
|
}
|
|
|
|
|
2024-01-10 11:12:19 +08:00
|
|
|
func (repo *Repository) FindPlatfrom(id string) *Platform {
|
2023-11-01 16:52:03 +08:00
|
|
|
return repo.platformMap[id]
|
|
|
|
}
|
|
|
|
|
2023-09-20 15:14:38 +08:00
|
|
|
func (repo *Repository) AddPhysicalSection(section *PhysicalSection) {
|
|
|
|
repo.physicalSectionMap[section.Id()] = section
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
|
|
|
|
2023-10-20 15:05:56 +08:00
|
|
|
func (repo *Repository) ConvertKilometer(km *proto.Kilometer, cs string) (*proto.Kilometer, error) {
|
2023-09-28 14:22:21 +08:00
|
|
|
if km.CoordinateSystem == cs {
|
2023-10-20 15:05:56 +08:00
|
|
|
return km, nil
|
2023-09-28 14:22:21 +08:00
|
|
|
}
|
|
|
|
kc, err := repo.getKilometerConvert(km.CoordinateSystem, cs)
|
|
|
|
if err != nil {
|
2023-10-20 15:05:56 +08:00
|
|
|
return nil, err
|
|
|
|
// panic(err)
|
2023-09-28 14:22:21 +08:00
|
|
|
}
|
|
|
|
var sourceCsKm *proto.Kilometer
|
|
|
|
var targetCsKm *proto.Kilometer
|
|
|
|
if kc.KmA.CoordinateSystem == km.CoordinateSystem {
|
|
|
|
sourceCsKm = kc.KmA
|
|
|
|
targetCsKm = kc.KmB
|
|
|
|
} else {
|
|
|
|
sourceCsKm = kc.KmB
|
|
|
|
targetCsKm = kc.KmA
|
|
|
|
}
|
2023-09-28 14:57:51 +08:00
|
|
|
value := targetCsKm.Value + (km.Value - sourceCsKm.Value)
|
2023-12-05 13:54:49 +08:00
|
|
|
// 20231205 注释
|
|
|
|
// if value < 0 {
|
|
|
|
// panic(fmt.Sprintf("公里标[%v]转换为坐标系[%s]的公里标的值[%d]小于0", km, cs, value))
|
|
|
|
// }
|
2023-10-20 15:05:56 +08:00
|
|
|
return &proto.Kilometer{Value: value, CoordinateSystem: cs}, nil
|
2023-09-28 14:22:21 +08:00
|
|
|
}
|
|
|
|
|
2023-09-06 16:20:36 +08:00
|
|
|
func (repo *Repository) addKilometerConvert(kc *proto.KilometerConvert) {
|
2023-09-25 14:38:13 +08:00
|
|
|
repo.kilometerConvertMap[buildKilometerConvertKey(kc.KmA.CoordinateSystem, kc.KmB.CoordinateSystem)] = kc
|
|
|
|
repo.kilometerConvertMap[buildKilometerConvertKey(kc.KmB.CoordinateSystem, kc.KmA.CoordinateSystem)] = kc
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
2023-08-29 14:59:31 +08:00
|
|
|
|
2023-09-25 14:38:13 +08:00
|
|
|
func (repo *Repository) getKilometerConvert(cs1, cs2 string) (*proto.KilometerConvert, error) {
|
|
|
|
convert := repo.kilometerConvertMap[buildKilometerConvertKey(cs1, cs2)]
|
2023-09-06 16:20:36 +08:00
|
|
|
if convert == nil {
|
2023-10-17 15:05:13 +08:00
|
|
|
return nil, fmt.Errorf("没有[%s-%s]的公里标转换数据", cs1, cs2)
|
2023-09-06 16:20:36 +08:00
|
|
|
}
|
|
|
|
return convert, nil
|
|
|
|
}
|
2023-09-20 15:14:38 +08:00
|
|
|
|
2023-10-19 16:38:46 +08:00
|
|
|
// 获取地图坐标信息
|
2023-10-20 15:05:56 +08:00
|
|
|
func (repo *Repository) generateCoordinateInfo(coordinateSystem string) error {
|
2023-10-19 16:38:46 +08:00
|
|
|
coordinate := &MapCoordinate{
|
2023-10-19 17:36:39 +08:00
|
|
|
Coordinate: "MAIN_LINE",
|
2023-10-19 16:38:46 +08:00
|
|
|
MinCoordinate: int64(math.MaxInt64),
|
|
|
|
MaxCoordinate: int64(math.MinInt64),
|
|
|
|
}
|
2023-10-19 17:36:39 +08:00
|
|
|
if coordinateSystem != "" {
|
|
|
|
coordinate.Coordinate = coordinateSystem
|
|
|
|
}
|
2023-10-19 16:38:46 +08:00
|
|
|
for _, data := range repo.checkPointMap {
|
|
|
|
if data.km == nil || data.km.CoordinateSystem == "" {
|
|
|
|
continue
|
|
|
|
}
|
2023-10-20 15:05:56 +08:00
|
|
|
km, err := repo.ConvertKilometer(data.km, coordinate.Coordinate)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-10-19 16:38:46 +08:00
|
|
|
if km.Value < coordinate.MinCoordinate {
|
|
|
|
coordinate.MinCoordinate = km.Value
|
|
|
|
}
|
|
|
|
if km.Value > coordinate.MaxCoordinate {
|
|
|
|
coordinate.MaxCoordinate = km.Value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if coordinate.Coordinate == "" {
|
2023-10-20 15:05:56 +08:00
|
|
|
return fmt.Errorf("无计轴公里标信息")
|
|
|
|
// panic("无计轴公里标信息")
|
2023-10-19 16:38:46 +08:00
|
|
|
}
|
|
|
|
repo.coordinate = coordinate
|
2023-10-20 15:05:56 +08:00
|
|
|
return nil
|
2023-10-19 16:38:46 +08:00
|
|
|
}
|
|
|
|
|
2024-01-10 11:12:19 +08:00
|
|
|
func (repo Repository) GetCoordinateInfo() *MapCoordinate {
|
2023-10-19 16:38:46 +08:00
|
|
|
return repo.coordinate
|
|
|
|
}
|
|
|
|
|
2023-09-25 14:38:13 +08:00
|
|
|
func buildKilometerConvertKey(cs1 string, cs2 string) string {
|
|
|
|
return cs1 + cs2
|
2023-09-20 15:14:38 +08:00
|
|
|
}
|