Merge branch 'master' of https://git.code.tencent.com/beijing-rtss-test/bj-rtsts-server-go
# Conflicts: # ats/verify/simulation/wayside/memory/wayside_memory_map.go
This commit is contained in:
commit
20cd27a54c
@ -3,6 +3,8 @@ package memory
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"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) {
|
||||
//graphicDataMap.Delete(mapId)
|
||||
//graphicSourceDataMap.Delete(mapId)
|
||||
}
|
||||
|
||||
func QueryGraphicStorage(mapId int32) *graphicData.RtssGraphicStorage {
|
||||
value, ok := giDataMap.Load(mapId)
|
||||
if ok {
|
||||
return value.(*graphicData.RtssGraphicStorage)
|
||||
}
|
||||
return nil
|
||||
func QueryGiType(mapId int32) graphicData.PictureType {
|
||||
value, _ := giTypeMap.Load(mapId)
|
||||
return value.(graphicData.PictureType)
|
||||
}
|
||||
|
||||
func QueryGiData[T proto.Message](mapId int32) T {
|
||||
value, _ := giDataMap.Load(mapId)
|
||||
return value.(T)
|
||||
}
|
||||
|
||||
// 获取内存中的地图信息
|
||||
|
@ -2,10 +2,7 @@ package memory
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
||||
@ -35,37 +32,26 @@ type stationUidStructure struct {
|
||||
type relayUidStructure struct {
|
||||
RelayCabinetIds map[string]*elementIdStructure
|
||||
RelayIds map[string]*elementIdStructure
|
||||
RelayRefIds map[string]*elementIdStructure
|
||||
}
|
||||
|
||||
// 获取UID的前缀信息
|
||||
func getUIdPrefix(prefix interface{}) string {
|
||||
if prefix == nil {
|
||||
log.Fatalf("缺少UID前缀设置")
|
||||
return ""
|
||||
}
|
||||
switch prefix.(type) {
|
||||
func getUIdPrefix(prefix interface{}) (string, string, string) {
|
||||
switch p := prefix.(type) {
|
||||
case *graphicData.UniqueIdOfStationLayout:
|
||||
p := prefix.(*graphicData.UniqueIdOfStationLayout)
|
||||
return p.City + "_" + p.LineId
|
||||
if p == nil {
|
||||
return "", "", ""
|
||||
}
|
||||
return p.City, p.LineId, ""
|
||||
case *graphicData.UniqueIdType:
|
||||
p := prefix.(*graphicData.UniqueIdType)
|
||||
return p.City + "_" + p.LineId + "_" + p.BelongsConcentrationStation
|
||||
if p == nil {
|
||||
return "", "", ""
|
||||
}
|
||||
return p.City, p.LineId, p.BelongsConcentrationStation
|
||||
default:
|
||||
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
|
||||
func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStructure {
|
||||
gus := &stationUidStructure{
|
||||
@ -77,13 +63,13 @@ func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStru
|
||||
SlopeIds: make(map[string]*elementIdStructure, len(graphicData.Slopes)),
|
||||
CurvatureIds: make(map[string]*elementIdStructure, len(graphicData.Curvatures)),
|
||||
}
|
||||
uidPrefix := getUIdPrefix(graphicData.UniqueIdPrefix)
|
||||
city, lineId, _ := getUIdPrefix(graphicData.UniqueIdPrefix)
|
||||
// 初始化计轴信息
|
||||
for _, a := range graphicData.AxleCountings {
|
||||
gus.AxlePointIds[a.Common.Id] = &elementIdStructure{
|
||||
CommonId: a.Common.Id,
|
||||
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{
|
||||
CommonId: t.Common.Id,
|
||||
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{
|
||||
CommonId: s.Common.Id,
|
||||
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{
|
||||
CommonId: s.Common.Id,
|
||||
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{
|
||||
CommonId: t.Common.Id,
|
||||
Index: t.Index,
|
||||
Uid: generateElementUid(uidPrefix, t.Code, t.CentralizedStations),
|
||||
Uid: GenerateElementUid(city, lineId, t.CentralizedStations, t.Code),
|
||||
}
|
||||
}
|
||||
// 初始化坡度
|
||||
for _, s := range graphicData.Slopes {
|
||||
gus.SlopeIds[s.Common.Id] = &elementIdStructure{
|
||||
CommonId: s.Common.Id,
|
||||
Uid: generateElementUid(uidPrefix, s.Common.Id, nil),
|
||||
Uid: GenerateElementUid(city, lineId, nil, s.Common.Id),
|
||||
}
|
||||
}
|
||||
// 初始化曲线
|
||||
for _, c := range graphicData.Curvatures {
|
||||
gus.CurvatureIds[c.Common.Id] = &elementIdStructure{
|
||||
CommonId: c.Common.Id,
|
||||
Uid: generateElementUid(uidPrefix, c.Common.Id, nil),
|
||||
Uid: GenerateElementUid(city, lineId, nil, c.Common.Id),
|
||||
}
|
||||
}
|
||||
return gus
|
||||
@ -140,27 +126,20 @@ func initRelayCabinetUid(graphicData *graphicData.RelayCabinetGraphicStorage) *r
|
||||
rus := &relayUidStructure{
|
||||
RelayCabinetIds: make(map[string]*elementIdStructure, len(graphicData.RelayCabinets)),
|
||||
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 {
|
||||
rus.RelayCabinetIds[r.Common.Id] = &elementIdStructure{
|
||||
CommonId: r.Common.Id,
|
||||
Code: r.Code,
|
||||
Uid: generateElementUid(uidPrefix, r.Code, nil),
|
||||
Uid: GenerateElementUid(city, lineId, []string{station}, r.Code),
|
||||
}
|
||||
}
|
||||
for _, r := range graphicData.Relays {
|
||||
rus.RelayIds[r.Common.Id] = &elementIdStructure{
|
||||
CommonId: r.Common.Id,
|
||||
Code: r.Code,
|
||||
Uid: generateElementUid(uidPrefix, r.Code, nil),
|
||||
}
|
||||
}
|
||||
for _, r := range graphicData.DeviceRelateRelayList {
|
||||
rus.RelayRefIds[r.Code] = &elementIdStructure{
|
||||
Code: r.Code,
|
||||
Uid: generateElementUid(uidPrefix, r.Code, nil),
|
||||
Uid: GenerateElementUid(city, lineId, []string{station}, r.Code),
|
||||
}
|
||||
}
|
||||
return rus
|
||||
@ -196,8 +175,6 @@ func getFieldNameByType(m interface{}) string {
|
||||
return "RelayCabinetIds"
|
||||
case *graphicData.Relay:
|
||||
return "RelayIds"
|
||||
case *graphicData.DeviceRelateRelay:
|
||||
return "RelayRefIds"
|
||||
default:
|
||||
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "类型未映射字段"})
|
||||
}
|
||||
|
@ -90,22 +90,25 @@ func CreateSimulation(projectId int32, mapIds []int32) (*VerifySimulation, error
|
||||
repoVersion := "0.1"
|
||||
repo := repository.FindRepository(repoId, repoVersion)
|
||||
if repo == nil {
|
||||
var storages []*graphicData.RtssGraphicStorage
|
||||
var rmapIds []int32
|
||||
for _, mapId := range mapIds {
|
||||
storage := QueryGraphicStorage(mapId)
|
||||
if storage == nil {
|
||||
continue
|
||||
}
|
||||
storages = append(storages, storage)
|
||||
rmapIds = append(rmapIds, mapId)
|
||||
}
|
||||
protoRepo := buildProtoRepository(storages, rmapIds)
|
||||
newRepo, err := repository.BuildRepository(protoRepo)
|
||||
repo = newRepo
|
||||
//var storages []*graphicData.RtssGraphicStorage
|
||||
//var rmapIds []int32
|
||||
//for _, mapId := range mapIds {
|
||||
// storage := QueryGraphicStorage(mapId)
|
||||
// if storage == nil {
|
||||
// continue
|
||||
// }
|
||||
// storages = append(storages, storage)
|
||||
// rmapIds = append(rmapIds, mapId)
|
||||
//}
|
||||
protoRepo, err := buildProtoRepository(mapIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newRepo, err := repository.BuildRepository(protoRepo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repo = newRepo
|
||||
}
|
||||
// 目前用本地构建状态
|
||||
worldMemory := NewWaysideMemory()
|
||||
@ -142,12 +145,69 @@ func (s *VerifySimulation) GetSimulationWorld() ecs.World {
|
||||
return ecsSimulation.GetWorld()
|
||||
}
|
||||
|
||||
func buildProtoRepository(storages []*graphicData.RtssGraphicStorage, mapIds []int32) *proto.Repository {
|
||||
func buildProtoRepository(mapIds []int32) (*proto.Repository, error) {
|
||||
repo := &proto.Repository{}
|
||||
for i, storage := range storages {
|
||||
fillProtoRepository(repo, storage, mapIds[i])
|
||||
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)
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user