# Conflicts:
#	ats/verify/simulation/wayside/memory/wayside_memory_map.go
This commit is contained in:
weizhihong 2023-09-22 15:33:40 +08:00
commit 20cd27a54c
3 changed files with 126 additions and 67 deletions

View File

@ -3,6 +3,8 @@ package memory
import ( import (
"fmt" "fmt"
"math" "math"
"sort"
"strings"
"sync" "sync"
"joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository"
@ -85,18 +87,38 @@ func PublishMapVerifyStructure(graphic *model.PublishedGi) {
} }
} }
// 生成Uid, 等加上集中站再做修改
func generateElementUid(ui *graphicData.UniqueIdOfStationLayout, code string, stationName []string) string {
if ui != nil {
return GenerateElementUid(ui.City, ui.LineId, stationName, code)
} else {
return GenerateElementUid("", "", stationName, code)
}
}
func GenerateElementUid(city, lineId string, stationIndexList []string, code string) string {
sort.Strings(stationIndexList)
var idArr []string
idArr = append(idArr, city, lineId)
idArr = append(idArr, stationIndexList...)
idArr = append(idArr, code)
return strings.Join(idArr, "_")
}
// 移除内存中的地图信息 // 移除内存中的地图信息
func DeleteMapVerifyStructure(mapId int32) { func DeleteMapVerifyStructure(mapId int32) {
//graphicDataMap.Delete(mapId) //graphicDataMap.Delete(mapId)
//graphicSourceDataMap.Delete(mapId) //graphicSourceDataMap.Delete(mapId)
} }
func QueryGraphicStorage(mapId int32) *graphicData.RtssGraphicStorage { func QueryGiType(mapId int32) graphicData.PictureType {
value, ok := giDataMap.Load(mapId) value, _ := giTypeMap.Load(mapId)
if ok { return value.(graphicData.PictureType)
return value.(*graphicData.RtssGraphicStorage)
} }
return nil
func QueryGiData[T proto.Message](mapId int32) T {
value, _ := giDataMap.Load(mapId)
return value.(T)
} }
// 获取内存中的地图信息 // 获取内存中的地图信息

View File

@ -2,10 +2,7 @@ package memory
import ( import (
"fmt" "fmt"
"log"
"reflect" "reflect"
"sort"
"strings"
"sync" "sync"
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
@ -35,37 +32,26 @@ type stationUidStructure struct {
type relayUidStructure struct { type relayUidStructure struct {
RelayCabinetIds map[string]*elementIdStructure RelayCabinetIds map[string]*elementIdStructure
RelayIds map[string]*elementIdStructure RelayIds map[string]*elementIdStructure
RelayRefIds map[string]*elementIdStructure
} }
// 获取UID的前缀信息 // 获取UID的前缀信息
func getUIdPrefix(prefix interface{}) string { func getUIdPrefix(prefix interface{}) (string, string, string) {
if prefix == nil { switch p := prefix.(type) {
log.Fatalf("缺少UID前缀设置")
return ""
}
switch prefix.(type) {
case *graphicData.UniqueIdOfStationLayout: case *graphicData.UniqueIdOfStationLayout:
p := prefix.(*graphicData.UniqueIdOfStationLayout) if p == nil {
return p.City + "_" + p.LineId return "", "", ""
}
return p.City, p.LineId, ""
case *graphicData.UniqueIdType: case *graphicData.UniqueIdType:
p := prefix.(*graphicData.UniqueIdType) if p == nil {
return p.City + "_" + p.LineId + "_" + p.BelongsConcentrationStation return "", "", ""
}
return p.City, p.LineId, p.BelongsConcentrationStation
default: default:
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "错误前缀设置"}) panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "错误前缀设置"})
} }
} }
// 生成Uid, 等加上集中站再做修改
func generateElementUid(uidPrefix, code string, stationName []string) string {
sort.Strings(stationName)
var idArr []string
idArr = append(idArr, uidPrefix)
idArr = append(idArr, stationName...)
idArr = append(idArr, code)
return strings.Join(idArr, "_")
}
// 初始化平面布置图 UID // 初始化平面布置图 UID
func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStructure { func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStructure {
gus := &stationUidStructure{ gus := &stationUidStructure{
@ -77,13 +63,13 @@ func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStru
SlopeIds: make(map[string]*elementIdStructure, len(graphicData.Slopes)), SlopeIds: make(map[string]*elementIdStructure, len(graphicData.Slopes)),
CurvatureIds: make(map[string]*elementIdStructure, len(graphicData.Curvatures)), CurvatureIds: make(map[string]*elementIdStructure, len(graphicData.Curvatures)),
} }
uidPrefix := getUIdPrefix(graphicData.UniqueIdPrefix) city, lineId, _ := getUIdPrefix(graphicData.UniqueIdPrefix)
// 初始化计轴信息 // 初始化计轴信息
for _, a := range graphicData.AxleCountings { for _, a := range graphicData.AxleCountings {
gus.AxlePointIds[a.Common.Id] = &elementIdStructure{ gus.AxlePointIds[a.Common.Id] = &elementIdStructure{
CommonId: a.Common.Id, CommonId: a.Common.Id,
Index: a.Index, Index: a.Index,
Uid: generateElementUid(uidPrefix, a.Code, a.CentralizedStations), Uid: GenerateElementUid(city, lineId, a.CentralizedStations, a.Code),
} }
} }
// 初始化道岔信息 // 初始化道岔信息
@ -91,7 +77,7 @@ func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStru
gus.TurnoutIds[t.Common.Id] = &elementIdStructure{ gus.TurnoutIds[t.Common.Id] = &elementIdStructure{
CommonId: t.Common.Id, CommonId: t.Common.Id,
Index: t.Index, Index: t.Index,
Uid: generateElementUid(uidPrefix, t.Code, t.CentralizedStations), Uid: GenerateElementUid(city, lineId, t.CentralizedStations, t.Code),
} }
} }
// 初始化物理区段信息 // 初始化物理区段信息
@ -99,7 +85,7 @@ func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStru
gus.PhysicalSectionIds[s.Common.Id] = &elementIdStructure{ gus.PhysicalSectionIds[s.Common.Id] = &elementIdStructure{
CommonId: s.Common.Id, CommonId: s.Common.Id,
Index: s.Index, Index: s.Index,
Uid: generateElementUid(uidPrefix, s.Code, s.CentralizedStations), Uid: GenerateElementUid(city, lineId, s.CentralizedStations, s.Code),
} }
} }
// 初始化信号机信息 // 初始化信号机信息
@ -107,7 +93,7 @@ func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStru
gus.SignalIds[s.Common.Id] = &elementIdStructure{ gus.SignalIds[s.Common.Id] = &elementIdStructure{
CommonId: s.Common.Id, CommonId: s.Common.Id,
Index: s.Index, Index: s.Index,
Uid: generateElementUid(uidPrefix, s.Code, s.CentralizedStations), Uid: GenerateElementUid(city, lineId, s.CentralizedStations, s.Code),
} }
} }
// 初始化应答器 // 初始化应答器
@ -115,21 +101,21 @@ func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStru
gus.TransponderIds[t.Common.Id] = &elementIdStructure{ gus.TransponderIds[t.Common.Id] = &elementIdStructure{
CommonId: t.Common.Id, CommonId: t.Common.Id,
Index: t.Index, Index: t.Index,
Uid: generateElementUid(uidPrefix, t.Code, t.CentralizedStations), Uid: GenerateElementUid(city, lineId, t.CentralizedStations, t.Code),
} }
} }
// 初始化坡度 // 初始化坡度
for _, s := range graphicData.Slopes { for _, s := range graphicData.Slopes {
gus.SlopeIds[s.Common.Id] = &elementIdStructure{ gus.SlopeIds[s.Common.Id] = &elementIdStructure{
CommonId: s.Common.Id, CommonId: s.Common.Id,
Uid: generateElementUid(uidPrefix, s.Common.Id, nil), Uid: GenerateElementUid(city, lineId, nil, s.Common.Id),
} }
} }
// 初始化曲线 // 初始化曲线
for _, c := range graphicData.Curvatures { for _, c := range graphicData.Curvatures {
gus.CurvatureIds[c.Common.Id] = &elementIdStructure{ gus.CurvatureIds[c.Common.Id] = &elementIdStructure{
CommonId: c.Common.Id, CommonId: c.Common.Id,
Uid: generateElementUid(uidPrefix, c.Common.Id, nil), Uid: GenerateElementUid(city, lineId, nil, c.Common.Id),
} }
} }
return gus return gus
@ -140,27 +126,20 @@ func initRelayCabinetUid(graphicData *graphicData.RelayCabinetGraphicStorage) *r
rus := &relayUidStructure{ rus := &relayUidStructure{
RelayCabinetIds: make(map[string]*elementIdStructure, len(graphicData.RelayCabinets)), RelayCabinetIds: make(map[string]*elementIdStructure, len(graphicData.RelayCabinets)),
RelayIds: make(map[string]*elementIdStructure, len(graphicData.Relays)), RelayIds: make(map[string]*elementIdStructure, len(graphicData.Relays)),
RelayRefIds: make(map[string]*elementIdStructure, len(graphicData.DeviceRelateRelayList)),
} }
uidPrefix := getUIdPrefix(graphicData.UniqueIdPrefix) city, lineId, station := getUIdPrefix(graphicData.UniqueIdPrefix)
for _, r := range graphicData.RelayCabinets { for _, r := range graphicData.RelayCabinets {
rus.RelayCabinetIds[r.Common.Id] = &elementIdStructure{ rus.RelayCabinetIds[r.Common.Id] = &elementIdStructure{
CommonId: r.Common.Id, CommonId: r.Common.Id,
Code: r.Code, Code: r.Code,
Uid: generateElementUid(uidPrefix, r.Code, nil), Uid: GenerateElementUid(city, lineId, []string{station}, r.Code),
} }
} }
for _, r := range graphicData.Relays { for _, r := range graphicData.Relays {
rus.RelayIds[r.Common.Id] = &elementIdStructure{ rus.RelayIds[r.Common.Id] = &elementIdStructure{
CommonId: r.Common.Id, CommonId: r.Common.Id,
Code: r.Code, Code: r.Code,
Uid: generateElementUid(uidPrefix, r.Code, nil), Uid: GenerateElementUid(city, lineId, []string{station}, r.Code),
}
}
for _, r := range graphicData.DeviceRelateRelayList {
rus.RelayRefIds[r.Code] = &elementIdStructure{
Code: r.Code,
Uid: generateElementUid(uidPrefix, r.Code, nil),
} }
} }
return rus return rus
@ -196,8 +175,6 @@ func getFieldNameByType(m interface{}) string {
return "RelayCabinetIds" return "RelayCabinetIds"
case *graphicData.Relay: case *graphicData.Relay:
return "RelayIds" return "RelayIds"
case *graphicData.DeviceRelateRelay:
return "RelayRefIds"
default: default:
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "类型未映射字段"}) panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "类型未映射字段"})
} }

View File

@ -90,22 +90,25 @@ func CreateSimulation(projectId int32, mapIds []int32) (*VerifySimulation, error
repoVersion := "0.1" repoVersion := "0.1"
repo := repository.FindRepository(repoId, repoVersion) repo := repository.FindRepository(repoId, repoVersion)
if repo == nil { if repo == nil {
var storages []*graphicData.RtssGraphicStorage //var storages []*graphicData.RtssGraphicStorage
var rmapIds []int32 //var rmapIds []int32
for _, mapId := range mapIds { //for _, mapId := range mapIds {
storage := QueryGraphicStorage(mapId) // storage := QueryGraphicStorage(mapId)
if storage == nil { // if storage == nil {
continue // continue
} // }
storages = append(storages, storage) // storages = append(storages, storage)
rmapIds = append(rmapIds, mapId) // rmapIds = append(rmapIds, mapId)
} //}
protoRepo := buildProtoRepository(storages, rmapIds) protoRepo, err := buildProtoRepository(mapIds)
newRepo, err := repository.BuildRepository(protoRepo)
repo = newRepo
if err != nil { if err != nil {
return nil, err return nil, err
} }
newRepo, err := repository.BuildRepository(protoRepo)
if err != nil {
return nil, err
}
repo = newRepo
} }
// 目前用本地构建状态 // 目前用本地构建状态
worldMemory := NewWaysideMemory() worldMemory := NewWaysideMemory()
@ -142,12 +145,69 @@ func (s *VerifySimulation) GetSimulationWorld() ecs.World {
return ecsSimulation.GetWorld() return ecsSimulation.GetWorld()
} }
func buildProtoRepository(storages []*graphicData.RtssGraphicStorage, mapIds []int32) *proto.Repository { func buildProtoRepository(mapIds []int32) (*proto.Repository, error) {
repo := &proto.Repository{} repo := &proto.Repository{}
for i, storage := range storages { var exceptStationGiMapIds []int32
fillProtoRepository(repo, storage, mapIds[i]) //创建设备
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)
relateRelay(repo, relayGi)
}
}
return repo, nil
}
func relateRelay(repo *proto.Repository, relayGi *graphicData.RelayCabinetGraphicStorage) {
city := relayGi.UniqueIdPrefix.City
lineId := relayGi.UniqueIdPrefix.LineId
station := relayGi.UniqueIdPrefix.BelongsConcentrationStation
for _, relay := range relayGi.Relays {
repo.Relays = append(repo.Relays, &proto.Relay{
Id: relay.Common.Id,
Code: relay.Code,
Model: relay.Model,
})
}
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 {
switch relationship.Type {
case "Turnout":
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,
})
}
case "Signal":
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,
})
}
}
} }
return repo
} }
func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphicStorage, mapId int32) { func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphicStorage, mapId int32) {