2023-08-01 14:54:11 +08:00
|
|
|
|
package memory
|
|
|
|
|
|
2023-08-01 17:08:45 +08:00
|
|
|
|
import (
|
2023-09-20 15:14:40 +08:00
|
|
|
|
"fmt"
|
2023-09-21 14:54:27 +08:00
|
|
|
|
"sort"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
2023-09-22 11:29:56 +08:00
|
|
|
|
"sync"
|
2023-09-21 14:54:27 +08:00
|
|
|
|
|
2023-09-20 15:14:40 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
2023-08-01 17:08:45 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/ats/verify/protos/state"
|
2023-09-21 14:54:27 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/dto"
|
|
|
|
|
"joylink.club/ecs"
|
2023-09-20 15:14:40 +08:00
|
|
|
|
"joylink.club/rtsssimulation/repository"
|
|
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
|
|
|
"joylink.club/rtsssimulation/simulation"
|
2023-09-21 16:28:15 +08:00
|
|
|
|
"joylink.club/rtsssimulation/system"
|
2023-08-01 17:08:45 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-08-01 14:54:11 +08:00
|
|
|
|
// 轨旁仿真定义
|
|
|
|
|
type VerifySimulation struct {
|
|
|
|
|
//地图id
|
2023-09-19 11:02:50 +08:00
|
|
|
|
MapIds []int32
|
2023-08-30 13:25:57 +08:00
|
|
|
|
// 项目ID
|
|
|
|
|
ProjectId int32
|
2023-08-01 14:54:11 +08:00
|
|
|
|
//仿真id
|
|
|
|
|
SimulationId string
|
|
|
|
|
//仿真内存数据
|
|
|
|
|
Memory *WaysideMemory
|
2023-09-20 15:14:40 +08:00
|
|
|
|
//模型仓库
|
|
|
|
|
Repo *repository.Repository
|
|
|
|
|
//Rtss仿真世界的id
|
|
|
|
|
WorldId int
|
2023-09-25 17:05:17 +08:00
|
|
|
|
//设备UID映射
|
|
|
|
|
uidMap map[string]*elementIdStructure
|
2023-08-01 14:54:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 11:29:56 +08:00
|
|
|
|
// 轨旁仿真内存模型
|
|
|
|
|
type WaysideMemory struct {
|
|
|
|
|
//可变状态数据:轨旁仿真模型状态(全量数据)
|
|
|
|
|
Status *VerifyStatus
|
|
|
|
|
// 要变更的状态:用户操作过的状态记录在这里,增量推送次数据
|
|
|
|
|
ChangeStatus *ChangeVerifyStatus
|
|
|
|
|
//状态保护锁
|
|
|
|
|
rwLock *sync.RWMutex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 轨旁仿真模型状态
|
|
|
|
|
type VerifyStatus struct {
|
|
|
|
|
//道岔状态,key为道岔id即索引 state.SwitchState
|
|
|
|
|
SwitchStateMap sync.Map
|
|
|
|
|
//轨道状态,key为轨道id即索引 state.LinkState
|
|
|
|
|
LinkStateMap sync.Map
|
|
|
|
|
//列车状态,key为列车id即索引 state.TrainState
|
|
|
|
|
TrainStateMap sync.Map
|
|
|
|
|
//计轴区段状态,key为计轴区段的id即索引 state.SectionState
|
|
|
|
|
AxleSectionStateMap sync.Map
|
|
|
|
|
//物理区段状态,key为物理区段id即索引 state.SectionState
|
|
|
|
|
PhysicalSectionStateMap sync.Map
|
|
|
|
|
//逻辑区段状态,key为逻辑区段id即索引 state.SectionState
|
|
|
|
|
LogicSectionStateMap sync.Map
|
|
|
|
|
//信号机状态,key为信号机id,即索引 state.SignalState
|
|
|
|
|
SignalStateMap sync.Map
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 轨旁仿真模型状态(变更)
|
|
|
|
|
type ChangeVerifyStatus struct {
|
|
|
|
|
VerifyStatus
|
|
|
|
|
//删除的列车ID列表
|
|
|
|
|
RemoveTrainId []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewWaysideMemory() *WaysideMemory {
|
|
|
|
|
return &WaysideMemory{
|
|
|
|
|
Status: &VerifyStatus{},
|
|
|
|
|
ChangeStatus: &ChangeVerifyStatus{},
|
|
|
|
|
rwLock: &sync.RWMutex{},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-01 14:54:11 +08:00
|
|
|
|
// 创建仿真对象
|
2023-09-20 15:14:40 +08:00
|
|
|
|
func CreateSimulation(projectId int32, mapIds []int32) (*VerifySimulation, error) {
|
|
|
|
|
//构建Repository
|
|
|
|
|
sort.Slice(mapIds, func(i, j int) bool {
|
|
|
|
|
return mapIds[i] < mapIds[j]
|
|
|
|
|
})
|
|
|
|
|
var mapIdStrSlice []string
|
|
|
|
|
for _, id := range mapIds {
|
|
|
|
|
mapIdStrSlice = append(mapIdStrSlice, strconv.Itoa(int(id)))
|
|
|
|
|
}
|
|
|
|
|
repoId := strings.Join(mapIdStrSlice, "|")
|
|
|
|
|
repoVersion := "0.1"
|
|
|
|
|
repo := repository.FindRepository(repoId, repoVersion)
|
|
|
|
|
if repo == nil {
|
2023-09-22 15:13:25 +08:00
|
|
|
|
protoRepo, err := buildProtoRepository(mapIds)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-09-25 11:09:56 +08:00
|
|
|
|
protoRepo.Id, protoRepo.Version = repoId, repoVersion
|
2023-09-20 15:14:40 +08:00
|
|
|
|
newRepo, err := repository.BuildRepository(protoRepo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2023-09-22 15:13:25 +08:00
|
|
|
|
repo = newRepo
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-09-22 11:29:56 +08:00
|
|
|
|
// 目前用本地构建状态
|
|
|
|
|
worldMemory := NewWaysideMemory()
|
|
|
|
|
initWorldDeviceState(worldMemory.Status, repo)
|
2023-09-25 17:05:17 +08:00
|
|
|
|
// 构建所有UID映射关系,
|
|
|
|
|
allUidMap := buildRepositoryAllUidsMap(mapIds, repo)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
//创建仿真
|
2023-09-25 10:34:31 +08:00
|
|
|
|
worldId := simulation.CreateSimulation(repo, system.SWITCH_ZDJ9_2, system.RELAY)
|
2023-08-01 14:54:11 +08:00
|
|
|
|
verifySimulation := &VerifySimulation{
|
2023-09-19 11:02:50 +08:00
|
|
|
|
MapIds: mapIds,
|
|
|
|
|
ProjectId: projectId,
|
2023-09-22 11:29:56 +08:00
|
|
|
|
Memory: worldMemory,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
Repo: repo,
|
|
|
|
|
WorldId: worldId,
|
2023-09-25 17:05:17 +08:00
|
|
|
|
uidMap: allUidMap,
|
2023-09-19 11:02:50 +08:00
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
return verifySimulation, nil
|
2023-08-01 14:54:11 +08:00
|
|
|
|
}
|
2023-08-01 17:08:45 +08:00
|
|
|
|
|
|
|
|
|
// 获取全量状态
|
2023-09-21 16:22:55 +08:00
|
|
|
|
func (s *VerifySimulation) GetAllState(mapId int32) *state.PushedDevicesStatus {
|
2023-09-25 17:05:17 +08:00
|
|
|
|
giType := QueryGiType(mapId)
|
|
|
|
|
if giType != graphicData.PictureType_StationLayout {
|
|
|
|
|
return &state.PushedDevicesStatus{All: true}
|
|
|
|
|
}
|
2023-08-01 17:08:45 +08:00
|
|
|
|
return &state.PushedDevicesStatus{
|
|
|
|
|
All: true,
|
|
|
|
|
AllStatus: &state.AllDevicesStatus{
|
2023-09-22 11:29:56 +08:00
|
|
|
|
SwitchState: GetMapAllTurnoutState(s, mapId),
|
|
|
|
|
TrainState: GetAllTrainState(s),
|
2023-08-01 17:08:45 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
|
2023-09-21 14:54:27 +08:00
|
|
|
|
// 获取仿真世界信息
|
2023-09-21 15:26:47 +08:00
|
|
|
|
func (s *VerifySimulation) GetSimulationWorld() ecs.World {
|
2023-09-21 14:54:27 +08:00
|
|
|
|
ecsSimulation := simulation.FindSimulation(ecs.WorldId(s.WorldId))
|
|
|
|
|
if ecsSimulation == nil {
|
|
|
|
|
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "ecs 仿真不存在"})
|
|
|
|
|
}
|
2023-09-21 15:26:47 +08:00
|
|
|
|
return ecsSimulation.GetWorld()
|
2023-09-21 14:54:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 17:05:17 +08:00
|
|
|
|
// 获取仿真世界信息
|
|
|
|
|
func (s *VerifySimulation) GetComIdByUid(uid string) string {
|
|
|
|
|
es := s.uidMap
|
|
|
|
|
if es == nil {
|
|
|
|
|
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无映射信息"})
|
|
|
|
|
}
|
|
|
|
|
if es[uid] == nil {
|
|
|
|
|
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无【uid】映射信息"})
|
|
|
|
|
}
|
|
|
|
|
return es[uid].CommonId
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 15:13:25 +08:00
|
|
|
|
func buildProtoRepository(mapIds []int32) (*proto.Repository, error) {
|
2023-09-20 15:14:40 +08:00
|
|
|
|
repo := &proto.Repository{}
|
2023-09-22 15:13:25 +08:00
|
|
|
|
var exceptStationGiMapIds []int32
|
|
|
|
|
//创建设备
|
|
|
|
|
for _, mapId := range mapIds {
|
|
|
|
|
giType := QueryGiType(mapId)
|
|
|
|
|
if giType == graphicData.PictureType_StationLayout {
|
|
|
|
|
stationGi := QueryGiData[*graphicData.RtssGraphicStorage](mapId)
|
|
|
|
|
fillProtoRepository(repo, stationGi, mapId)
|
|
|
|
|
} else {
|
|
|
|
|
exceptStationGiMapIds = append(exceptStationGiMapIds, mapId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//将继电器与设备关联
|
|
|
|
|
for _, mapId := range exceptStationGiMapIds {
|
|
|
|
|
giType := QueryGiType(mapId)
|
|
|
|
|
if giType == graphicData.PictureType_RelayCabinetLayout {
|
|
|
|
|
relayGi := QueryGiData[*graphicData.RelayCabinetGraphicStorage](mapId)
|
2023-09-22 15:42:21 +08:00
|
|
|
|
relateRelay(repo, relayGi, mapId)
|
2023-09-22 15:13:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return repo, nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 15:41:10 +08:00
|
|
|
|
func relateRelay(repo *proto.Repository, relayGi *graphicData.RelayCabinetGraphicStorage, mapId int32) {
|
2023-09-25 10:34:31 +08:00
|
|
|
|
uidsMap := queryUidStructure[*relayUidStructure](mapId)
|
2023-09-22 15:13:25 +08:00
|
|
|
|
city := relayGi.UniqueIdPrefix.City
|
|
|
|
|
lineId := relayGi.UniqueIdPrefix.LineId
|
|
|
|
|
station := relayGi.UniqueIdPrefix.BelongsConcentrationStation
|
|
|
|
|
for _, relay := range relayGi.Relays {
|
|
|
|
|
repo.Relays = append(repo.Relays, &proto.Relay{
|
2023-09-22 15:41:10 +08:00
|
|
|
|
Id: uidsMap.RelayIds[relay.Common.Id].Uid,
|
2023-09-22 15:13:25 +08:00
|
|
|
|
Code: relay.Code,
|
2023-09-26 09:34:23 +08:00
|
|
|
|
Model: relay.NewModel.String(),
|
2023-09-22 15:13:25 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
turnoutMap := make(map[string]*proto.Turnout)
|
|
|
|
|
for _, turnout := range repo.Turnouts {
|
|
|
|
|
turnoutMap[turnout.Id] = turnout
|
|
|
|
|
}
|
|
|
|
|
signalMap := make(map[string]*proto.Signal)
|
|
|
|
|
for _, signal := range repo.Signals {
|
|
|
|
|
signalMap[signal.Id] = signal
|
|
|
|
|
}
|
|
|
|
|
for _, relationship := range relayGi.DeviceRelateRelayList {
|
2023-09-26 09:34:23 +08:00
|
|
|
|
switch relationship.DeviceType {
|
|
|
|
|
case graphicData.RelatedRef_Turnout:
|
2023-09-22 15:13:25 +08:00
|
|
|
|
turnout := turnoutMap[GenerateElementUid(city, lineId, []string{station}, relationship.Code)]
|
|
|
|
|
for _, group := range relationship.Combinationtypes {
|
|
|
|
|
turnout.RelayGroups = append(turnout.RelayGroups, &proto.RelayGroup{
|
|
|
|
|
Code: group.Code,
|
|
|
|
|
RelayIds: group.RefRelays,
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-09-26 09:34:23 +08:00
|
|
|
|
case graphicData.RelatedRef_signal:
|
2023-09-22 15:13:25 +08:00
|
|
|
|
signal := signalMap[GenerateElementUid(city, lineId, []string{station}, relationship.Code)]
|
|
|
|
|
for _, group := range relationship.Combinationtypes {
|
|
|
|
|
signal.RelayGroups = append(signal.RelayGroups, &proto.RelayGroup{
|
|
|
|
|
Code: group.Code,
|
|
|
|
|
RelayIds: group.RefRelays,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 14:54:27 +08:00
|
|
|
|
func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphicStorage, mapId int32) {
|
2023-09-20 15:14:40 +08:00
|
|
|
|
axleCountingMap := make(map[string]*graphicData.AxleCounting)
|
2023-09-22 15:15:04 +08:00
|
|
|
|
uidsMap := queryUidStructure[*stationUidStructure](mapId)
|
2023-09-20 15:14:40 +08:00
|
|
|
|
for _, data := range storage.AxleCountings {
|
|
|
|
|
axleCountingMap[data.Common.Id] = data
|
|
|
|
|
cpType := proto.CheckPointType_AxleCounter
|
2023-09-21 14:54:27 +08:00
|
|
|
|
if data.Type == graphicData.AxleCounting_SectionBoundary {
|
2023-09-20 15:14:40 +08:00
|
|
|
|
cpType = proto.CheckPointType_Boundary
|
|
|
|
|
}
|
|
|
|
|
cp := &proto.CheckPoint{
|
2023-09-21 17:57:50 +08:00
|
|
|
|
Id: data.Common.Id,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
Km: convertKm(data.KilometerSystem),
|
|
|
|
|
Type: cpType,
|
|
|
|
|
DevicePorts: convertDevicePorts(data.AxleCountingRef),
|
|
|
|
|
}
|
2023-09-21 17:57:50 +08:00
|
|
|
|
repo.CheckPoints = append(repo.CheckPoints, converCheckPointUid(cp, uidsMap))
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.Section {
|
|
|
|
|
var turnoutIds []string
|
|
|
|
|
if data.SectionType == graphicData.Section_TurnoutPhysical {
|
|
|
|
|
turnoutIds = findTurnoutIds(axleCountingMap, data.AxleCountings)
|
|
|
|
|
}
|
|
|
|
|
physicalSection := &proto.PhysicalSection{
|
2023-09-21 17:57:50 +08:00
|
|
|
|
Id: data.Common.Id,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
ADevicePort: convertDevicePort(data.PaRef),
|
|
|
|
|
BDevicePort: convertDevicePort(data.PbRef),
|
|
|
|
|
TurnoutIds: turnoutIds,
|
|
|
|
|
}
|
2023-09-21 17:57:50 +08:00
|
|
|
|
repo.PhysicalSections = append(repo.PhysicalSections, converSectionUid(physicalSection, uidsMap))
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.Turnouts {
|
|
|
|
|
var km *proto.Kilometer
|
|
|
|
|
for _, ks := range data.KilometerSystem {
|
|
|
|
|
if ks.Kilometer != 0 {
|
|
|
|
|
km = convertKm(ks)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
turnout := &proto.Turnout{
|
2023-09-21 17:57:50 +08:00
|
|
|
|
Id: data.Common.Id,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
Km: km,
|
|
|
|
|
ADevicePort: convertDevicePort(data.PaRef),
|
|
|
|
|
BDevicePort: convertDevicePort(data.PbRef),
|
|
|
|
|
CDevicePort: convertDevicePort(data.PcRef),
|
|
|
|
|
}
|
2023-09-21 17:57:50 +08:00
|
|
|
|
repo.Turnouts = append(repo.Turnouts, converTurnoutUid(turnout, uidsMap))
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.Signals {
|
|
|
|
|
var sectionId string
|
|
|
|
|
var turnoutPort *proto.DevicePort
|
|
|
|
|
switch data.RefDev.DeviceType {
|
|
|
|
|
case graphicData.RelatedRef_Section:
|
|
|
|
|
sectionId = data.RefDev.Id
|
|
|
|
|
case graphicData.RelatedRef_Turnout:
|
|
|
|
|
turnoutPort = convertDevicePort(data.RefDev)
|
|
|
|
|
}
|
|
|
|
|
signal := &proto.Signal{
|
2023-09-21 17:57:50 +08:00
|
|
|
|
Id: data.Common.Id,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
Km: convertKm(data.KilometerSystem),
|
|
|
|
|
SectionId: sectionId,
|
|
|
|
|
TurnoutPort: turnoutPort,
|
|
|
|
|
}
|
2023-09-21 17:57:50 +08:00
|
|
|
|
repo.Signals = append(repo.Signals, converSignalUid(signal, uidsMap))
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.Transponders {
|
|
|
|
|
var sectionId string
|
|
|
|
|
var turnoutPort *proto.DevicePort
|
|
|
|
|
switch data.TransponderRef.DeviceType {
|
|
|
|
|
case graphicData.RelatedRef_Section:
|
|
|
|
|
sectionId = data.TransponderRef.Id
|
|
|
|
|
case graphicData.RelatedRef_Turnout:
|
|
|
|
|
turnoutPort = convertDevicePort(data.TransponderRef)
|
|
|
|
|
}
|
|
|
|
|
responder := &proto.Transponder{
|
2023-09-21 17:57:50 +08:00
|
|
|
|
Id: data.Common.Id,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
Km: convertKm(data.KilometerSystem),
|
|
|
|
|
SectionId: sectionId,
|
|
|
|
|
TurnoutPort: turnoutPort,
|
|
|
|
|
}
|
2023-09-21 17:57:50 +08:00
|
|
|
|
repo.Transponders = append(repo.Transponders, converTransponderUid(responder, uidsMap))
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
slopeKsMap := make(map[string]*graphicData.SlopeKiloMarker)
|
|
|
|
|
for _, data := range storage.SlopeKiloMarker {
|
|
|
|
|
slopeKsMap[data.Common.Id] = data
|
|
|
|
|
}
|
|
|
|
|
curveKsMap := make(map[string]*graphicData.CurvatureKiloMarker)
|
|
|
|
|
for _, data := range storage.CurvatureKiloMarker {
|
|
|
|
|
curveKsMap[data.Common.Id] = data
|
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.Slopes {
|
|
|
|
|
var kms []*proto.Kilometer
|
|
|
|
|
for _, id := range data.RefDeviceId {
|
|
|
|
|
kms = append(kms, convertKm(slopeKsMap[id].KilometerSystem[0]))
|
|
|
|
|
}
|
|
|
|
|
slope := &proto.Slope{
|
2023-09-21 17:57:50 +08:00
|
|
|
|
Id: data.Common.Id,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
Kms: kms,
|
|
|
|
|
Degree: data.SlopeNumber,
|
|
|
|
|
}
|
2023-09-21 17:57:50 +08:00
|
|
|
|
repo.Slopes = append(repo.Slopes, converSlopeUid(slope, uidsMap))
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
for _, data := range storage.Curvatures {
|
|
|
|
|
var kms []*proto.Kilometer
|
|
|
|
|
for _, id := range data.RefDeviceId {
|
|
|
|
|
kms = append(kms, convertKm(curveKsMap[id].KilometerSystem[0]))
|
|
|
|
|
}
|
|
|
|
|
slope := &proto.SectionalCurvature{
|
2023-09-21 17:57:50 +08:00
|
|
|
|
Id: data.Common.Id,
|
2023-09-20 15:14:40 +08:00
|
|
|
|
Kms: kms,
|
|
|
|
|
Radius: data.CurvatureNumber,
|
|
|
|
|
}
|
2023-09-21 17:57:50 +08:00
|
|
|
|
repo.SectionalCurvatures = append(repo.SectionalCurvatures, converCurvatureUid(slope, uidsMap))
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
2023-09-26 09:34:23 +08:00
|
|
|
|
for _, data := range storage.KilometerConvertList {
|
|
|
|
|
repo.KilometerConverts = append(repo.KilometerConverts, &proto.KilometerConvert{
|
|
|
|
|
KmA: convertKm(data.KmA),
|
|
|
|
|
KmB: convertKm(data.KmB),
|
|
|
|
|
SameTrend: data.SameTrend,
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-09-20 15:14:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 15:15:04 +08:00
|
|
|
|
func converCheckPointUid(data *proto.CheckPoint, uidsMap *stationUidStructure) *proto.CheckPoint {
|
2023-09-21 17:57:50 +08:00
|
|
|
|
data.Id = uidsMap.AxlePointIds[data.Id].Uid
|
|
|
|
|
for _, c := range data.DevicePorts {
|
|
|
|
|
c.DeviceId = converRefUid(c.DeviceId, c.DeviceType, uidsMap)
|
|
|
|
|
}
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 15:15:04 +08:00
|
|
|
|
func converSectionUid(data *proto.PhysicalSection, uidsMap *stationUidStructure) *proto.PhysicalSection {
|
2023-09-21 17:57:50 +08:00
|
|
|
|
data.Id = uidsMap.PhysicalSectionIds[data.Id].Uid
|
|
|
|
|
if data.ADevicePort != nil {
|
|
|
|
|
data.ADevicePort.DeviceId = converRefUid(data.ADevicePort.DeviceId, data.ADevicePort.DeviceType, uidsMap)
|
|
|
|
|
}
|
|
|
|
|
if data.BDevicePort != nil {
|
|
|
|
|
data.BDevicePort.DeviceId = converRefUid(data.BDevicePort.DeviceId, data.BDevicePort.DeviceType, uidsMap)
|
|
|
|
|
}
|
|
|
|
|
tids := make([]string, len(data.TurnoutIds))
|
|
|
|
|
for i, tid := range data.TurnoutIds {
|
|
|
|
|
tids[i] = converRefUid(tid, proto.DeviceType_DeviceType_Turnout, uidsMap)
|
|
|
|
|
}
|
|
|
|
|
data.TurnoutIds = tids
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 15:15:04 +08:00
|
|
|
|
func converTurnoutUid(data *proto.Turnout, uidsMap *stationUidStructure) *proto.Turnout {
|
2023-09-21 17:57:50 +08:00
|
|
|
|
data.Id = uidsMap.TurnoutIds[data.Id].Uid
|
|
|
|
|
if data.ADevicePort != nil {
|
|
|
|
|
data.ADevicePort.DeviceId = converRefUid(data.ADevicePort.DeviceId, data.ADevicePort.DeviceType, uidsMap)
|
|
|
|
|
}
|
|
|
|
|
if data.BDevicePort != nil {
|
|
|
|
|
data.BDevicePort.DeviceId = converRefUid(data.BDevicePort.DeviceId, data.BDevicePort.DeviceType, uidsMap)
|
|
|
|
|
}
|
|
|
|
|
if data.CDevicePort != nil {
|
|
|
|
|
data.CDevicePort.DeviceId = converRefUid(data.CDevicePort.DeviceId, data.CDevicePort.DeviceType, uidsMap)
|
|
|
|
|
}
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 15:15:04 +08:00
|
|
|
|
func converSignalUid(data *proto.Signal, uidsMap *stationUidStructure) *proto.Signal {
|
2023-09-21 17:57:50 +08:00
|
|
|
|
data.Id = uidsMap.SignalIds[data.Id].Uid
|
|
|
|
|
if data.SectionId != "" {
|
|
|
|
|
data.SectionId = converRefUid(data.SectionId, proto.DeviceType_DeviceType_PhysicalSection, uidsMap)
|
|
|
|
|
}
|
|
|
|
|
if data.TurnoutPort != nil {
|
|
|
|
|
data.TurnoutPort.DeviceId = converRefUid(data.TurnoutPort.DeviceId, data.TurnoutPort.DeviceType, uidsMap)
|
|
|
|
|
}
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 15:15:04 +08:00
|
|
|
|
func converTransponderUid(data *proto.Transponder, uidsMap *stationUidStructure) *proto.Transponder {
|
2023-09-21 17:57:50 +08:00
|
|
|
|
data.Id = uidsMap.TransponderIds[data.Id].Uid
|
|
|
|
|
if data.SectionId != "" {
|
|
|
|
|
data.SectionId = converRefUid(data.SectionId, proto.DeviceType_DeviceType_PhysicalSection, uidsMap)
|
|
|
|
|
}
|
|
|
|
|
if data.TurnoutPort != nil {
|
|
|
|
|
data.TurnoutPort.DeviceId = converRefUid(data.TurnoutPort.DeviceId, data.TurnoutPort.DeviceType, uidsMap)
|
|
|
|
|
}
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 15:15:04 +08:00
|
|
|
|
func converSlopeUid(data *proto.Slope, uidsMap *stationUidStructure) *proto.Slope {
|
2023-09-21 17:57:50 +08:00
|
|
|
|
data.Id = uidsMap.SlopeIds[data.Id].Uid
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 15:15:04 +08:00
|
|
|
|
func converCurvatureUid(data *proto.SectionalCurvature, uidsMap *stationUidStructure) *proto.SectionalCurvature {
|
2023-09-21 17:57:50 +08:00
|
|
|
|
data.Id = uidsMap.CurvatureIds[data.Id].Uid
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 15:15:04 +08:00
|
|
|
|
func converRefUid(id string, d proto.DeviceType, uidsMap *stationUidStructure) string {
|
|
|
|
|
var elementId *elementIdStructure
|
2023-09-21 17:57:50 +08:00
|
|
|
|
switch d {
|
|
|
|
|
case proto.DeviceType_DeviceType_CheckPoint:
|
|
|
|
|
elementId = uidsMap.AxlePointIds[id]
|
|
|
|
|
case proto.DeviceType_DeviceType_PhysicalSection:
|
|
|
|
|
elementId = uidsMap.PhysicalSectionIds[id]
|
|
|
|
|
case proto.DeviceType_DeviceType_SectionalCurvature:
|
|
|
|
|
elementId = uidsMap.CurvatureIds[id]
|
|
|
|
|
case proto.DeviceType_DeviceType_Signal:
|
|
|
|
|
elementId = uidsMap.SignalIds[id]
|
|
|
|
|
case proto.DeviceType_DeviceType_Slope:
|
|
|
|
|
elementId = uidsMap.SlopeIds[id]
|
|
|
|
|
case proto.DeviceType_DeviceType_Transponder:
|
|
|
|
|
elementId = uidsMap.TransponderIds[id]
|
|
|
|
|
case proto.DeviceType_DeviceType_Turnout:
|
|
|
|
|
elementId = uidsMap.TurnoutIds[id]
|
|
|
|
|
default:
|
|
|
|
|
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "异常的设备类型-" + d.String()})
|
|
|
|
|
}
|
|
|
|
|
return elementId.Uid
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 15:14:40 +08:00
|
|
|
|
func convertKm(ks *graphicData.KilometerSystem) *proto.Kilometer {
|
|
|
|
|
var dir proto.Direction
|
|
|
|
|
switch ks.Direction {
|
|
|
|
|
case graphicData.Direction_LEFT:
|
|
|
|
|
dir = proto.Direction_LEFT
|
|
|
|
|
case graphicData.Direction_RIGHT:
|
|
|
|
|
dir = proto.Direction_RIGHT
|
|
|
|
|
}
|
|
|
|
|
return &proto.Kilometer{
|
|
|
|
|
Value: ks.Kilometer,
|
|
|
|
|
CoordinateSystem: ks.CoordinateSystem,
|
|
|
|
|
Direction: dir,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func convertDevicePort(ref *graphicData.RelatedRef) *proto.DevicePort {
|
|
|
|
|
if ref == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
var deviceType proto.DeviceType
|
|
|
|
|
var port proto.Port
|
|
|
|
|
switch ref.DevicePort {
|
|
|
|
|
case graphicData.RelatedRef_A:
|
|
|
|
|
port = proto.Port_A
|
|
|
|
|
case graphicData.RelatedRef_B:
|
|
|
|
|
port = proto.Port_B
|
|
|
|
|
case graphicData.RelatedRef_C:
|
|
|
|
|
port = proto.Port_C
|
|
|
|
|
}
|
|
|
|
|
switch ref.DeviceType {
|
|
|
|
|
case graphicData.RelatedRef_Section:
|
|
|
|
|
deviceType = proto.DeviceType_DeviceType_PhysicalSection
|
|
|
|
|
case graphicData.RelatedRef_Turnout:
|
|
|
|
|
deviceType = proto.DeviceType_DeviceType_Turnout
|
|
|
|
|
default:
|
|
|
|
|
panic(fmt.Sprintf("异常的设备类型-%s", ref.DeviceType))
|
|
|
|
|
}
|
|
|
|
|
return &proto.DevicePort{
|
|
|
|
|
DeviceId: ref.Id,
|
|
|
|
|
DeviceType: deviceType,
|
|
|
|
|
Port: port,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func convertDevicePorts(refList []*graphicData.RelatedRef) []*proto.DevicePort {
|
|
|
|
|
var dps []*proto.DevicePort
|
|
|
|
|
for _, ref := range refList {
|
|
|
|
|
dps = append(dps, convertDevicePort(ref))
|
|
|
|
|
}
|
|
|
|
|
return dps
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func findTurnoutIds(axleCountingMap map[string]*graphicData.AxleCounting, axleIds []string) []string {
|
|
|
|
|
if len(axleIds) <= 2 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
turnoutMap := make(map[string]bool)
|
|
|
|
|
for _, axleId := range axleIds {
|
|
|
|
|
axle := axleCountingMap[axleId]
|
|
|
|
|
relTurnoutCount := 0
|
|
|
|
|
var turnoutId string
|
|
|
|
|
for _, ref := range axle.AxleCountingRef {
|
|
|
|
|
if ref.DeviceType == graphicData.RelatedRef_Turnout {
|
|
|
|
|
relTurnoutCount++
|
|
|
|
|
turnoutId = ref.Id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if relTurnoutCount == 1 {
|
|
|
|
|
turnoutMap[turnoutId] = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var turnoutIds []string
|
2023-09-21 14:54:27 +08:00
|
|
|
|
for id := range turnoutMap {
|
2023-09-20 15:14:40 +08:00
|
|
|
|
turnoutIds = append(turnoutIds, id)
|
|
|
|
|
}
|
|
|
|
|
return turnoutIds
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 11:29:56 +08:00
|
|
|
|
func initWorldDeviceState(status *VerifyStatus, repo *repository.Repository) {
|
|
|
|
|
initWorldTurnoutState(status, repo)
|
|
|
|
|
initWorldPhysicalSectionState(status, repo)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化道岔状态
|
|
|
|
|
func initWorldTurnoutState(status *VerifyStatus, repo *repository.Repository) {
|
|
|
|
|
for _, turnout := range repo.TurnoutList() {
|
|
|
|
|
id := turnout.Identity.Id()
|
|
|
|
|
status.SwitchStateMap.Store(id, &state.SwitchState{Id: id, Normal: true, Reverse: false})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化物理区段状态
|
|
|
|
|
func initWorldPhysicalSectionState(status *VerifyStatus, repo *repository.Repository) {
|
|
|
|
|
for _, section := range repo.PhysicalSectionList() {
|
|
|
|
|
id := section.Identity.Id()
|
|
|
|
|
status.PhysicalSectionStateMap.Store(id, &state.SectionState{Id: id, Occupied: false, Type: state.SectionType_Physic})
|
|
|
|
|
}
|
|
|
|
|
}
|