【map属性初始化】
This commit is contained in:
parent
8cf019ae3c
commit
a5906e355b
@ -2,6 +2,7 @@ package memory
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
||||
@ -37,6 +38,13 @@ type relayUidStructure struct {
|
||||
RelayIds map[string]*elementIdStructure
|
||||
}
|
||||
|
||||
// 设备关联的UID前缀
|
||||
type deviceRelateUidPriex struct {
|
||||
deviceCode string
|
||||
typeCode string
|
||||
isStation bool
|
||||
}
|
||||
|
||||
// 获取UID的前缀信息
|
||||
func getUIdPrefix(prefix interface{}) (string, string, string) {
|
||||
switch p := prefix.(type) {
|
||||
@ -56,19 +64,22 @@ func getUIdPrefix(prefix interface{}) (string, string, string) {
|
||||
}
|
||||
|
||||
// 初始化平面布置图 UID
|
||||
func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStructure {
|
||||
func initStationUid(data *graphicData.RtssGraphicStorage) *stationUidStructure {
|
||||
gus := &stationUidStructure{
|
||||
AxlePointIds: make(map[string]*elementIdStructure, len(graphicData.AxleCountings)),
|
||||
TurnoutIds: make(map[string]*elementIdStructure, len(graphicData.Turnouts)),
|
||||
PhysicalSectionIds: make(map[string]*elementIdStructure, len(graphicData.Section)),
|
||||
SignalIds: make(map[string]*elementIdStructure, len(graphicData.Signals)),
|
||||
TransponderIds: make(map[string]*elementIdStructure, len(graphicData.Transponders)),
|
||||
SlopeIds: make(map[string]*elementIdStructure, len(graphicData.Slopes)),
|
||||
CurvatureIds: make(map[string]*elementIdStructure, len(graphicData.Curvatures)),
|
||||
AxlePointIds: make(map[string]*elementIdStructure, len(data.AxleCountings)),
|
||||
TurnoutIds: make(map[string]*elementIdStructure, len(data.Turnouts)),
|
||||
PhysicalSectionIds: make(map[string]*elementIdStructure, len(data.Section)),
|
||||
SignalIds: make(map[string]*elementIdStructure, len(data.Signals)),
|
||||
TransponderIds: make(map[string]*elementIdStructure, len(data.Transponders)),
|
||||
SlopeIds: make(map[string]*elementIdStructure, len(data.Slopes)),
|
||||
CurvatureIds: make(map[string]*elementIdStructure, len(data.Curvatures)),
|
||||
ButtonIds: make(map[string]*elementIdStructure, len(data.EsbButtons)),
|
||||
StationIds: make(map[string]*elementIdStructure, len(data.Stations)),
|
||||
IBPIds: make(map[string]*elementIdStructure, len(data.Stations)),
|
||||
}
|
||||
city, lineId, _ := getUIdPrefix(graphicData.UniqueIdPrefix)
|
||||
city, lineId, _ := getUIdPrefix(data.UniqueIdPrefix)
|
||||
// 初始化计轴信息
|
||||
for _, a := range graphicData.AxleCountings {
|
||||
for _, a := range data.AxleCountings {
|
||||
gus.AxlePointIds[a.Common.Id] = &elementIdStructure{
|
||||
CommonId: a.Common.Id,
|
||||
Index: a.Index,
|
||||
@ -76,7 +87,7 @@ func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStru
|
||||
}
|
||||
}
|
||||
// 初始化道岔信息
|
||||
for _, t := range graphicData.Turnouts {
|
||||
for _, t := range data.Turnouts {
|
||||
gus.TurnoutIds[t.Common.Id] = &elementIdStructure{
|
||||
CommonId: t.Common.Id,
|
||||
Index: t.Index,
|
||||
@ -84,7 +95,7 @@ func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStru
|
||||
}
|
||||
}
|
||||
// 初始化物理区段信息
|
||||
for _, s := range graphicData.Section {
|
||||
for _, s := range data.Section {
|
||||
gus.PhysicalSectionIds[s.Common.Id] = &elementIdStructure{
|
||||
CommonId: s.Common.Id,
|
||||
Index: s.Index,
|
||||
@ -92,7 +103,7 @@ func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStru
|
||||
}
|
||||
}
|
||||
// 初始化信号机信息
|
||||
for _, s := range graphicData.Signals {
|
||||
for _, s := range data.Signals {
|
||||
gus.SignalIds[s.Common.Id] = &elementIdStructure{
|
||||
CommonId: s.Common.Id,
|
||||
Index: s.Index,
|
||||
@ -100,7 +111,7 @@ func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStru
|
||||
}
|
||||
}
|
||||
// 初始化应答器
|
||||
for _, t := range graphicData.Transponders {
|
||||
for _, t := range data.Transponders {
|
||||
gus.TransponderIds[t.Common.Id] = &elementIdStructure{
|
||||
CommonId: t.Common.Id,
|
||||
Index: t.Index,
|
||||
@ -108,33 +119,70 @@ func initStationUid(graphicData *graphicData.RtssGraphicStorage) *stationUidStru
|
||||
}
|
||||
}
|
||||
// 初始化坡度
|
||||
for _, s := range graphicData.Slopes {
|
||||
for _, s := range data.Slopes {
|
||||
gus.SlopeIds[s.Common.Id] = &elementIdStructure{
|
||||
CommonId: s.Common.Id,
|
||||
Uid: GenerateElementUid(city, lineId, nil, s.Common.Id),
|
||||
}
|
||||
}
|
||||
// 初始化曲线
|
||||
for _, c := range graphicData.Curvatures {
|
||||
for _, c := range data.Curvatures {
|
||||
gus.CurvatureIds[c.Common.Id] = &elementIdStructure{
|
||||
CommonId: c.Common.Id,
|
||||
Uid: GenerateElementUid(city, lineId, nil, c.Common.Id),
|
||||
}
|
||||
}
|
||||
// 初始化站场图按钮,先赋值图形ID后根据关联数据处理UID
|
||||
for _, b := range graphicData.EsbButtons {
|
||||
gus.ButtonIds[b.Common.Id] = &elementIdStructure{CommonId: b.Common.Id}
|
||||
//处理车站关联的组合信息
|
||||
refMap := make(map[string]*deviceRelateUidPriex)
|
||||
for _, s := range data.StationRelateDeviceList {
|
||||
for _, c := range s.Combinationtypes {
|
||||
p := &deviceRelateUidPriex{deviceCode: s.Code, typeCode: c.Code}
|
||||
for _, i := range c.RefDevices {
|
||||
refMap[i] = p
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
for _, s := range graphicData.Stations {
|
||||
// 初始化站场图按钮
|
||||
for _, b := range data.EsbButtons {
|
||||
p := refMap[b.Common.Id]
|
||||
code := b.Code
|
||||
if p != nil {
|
||||
code = p.deviceCode + "_" + p.typeCode + "_" + b.Code
|
||||
}
|
||||
gus.ButtonIds[b.Common.Id] = &elementIdStructure{
|
||||
CommonId: b.Common.Id,
|
||||
Uid: GenerateElementUid(city, lineId, nil, code),
|
||||
}
|
||||
}
|
||||
// 处理车站信息
|
||||
for _, s := range data.Stations {
|
||||
gus.StationIds[s.Common.Id] = &elementIdStructure{
|
||||
CommonId: s.Common.Id,
|
||||
Uid: GenerateElementUid(city, lineId, nil, s.Code),
|
||||
}
|
||||
// 处理关联的IBP盘信息
|
||||
if s.RefIbpMapCode == "" {
|
||||
continue
|
||||
}
|
||||
ibpId, _ := strconv.Atoi(s.RefIbpMapCode)
|
||||
ibpMapData, ok := giDataMap.Load(ibpId)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
initIBPUid(gus, city, lineId, s, ibpMapData.(*graphicData.IBPGraphicStorage))
|
||||
}
|
||||
return gus
|
||||
}
|
||||
|
||||
// 处理IBP盘信息
|
||||
func initIBPUid(gus *stationUidStructure, city, lineId string, station *graphicData.Station, data *graphicData.IBPGraphicStorage) {
|
||||
/*for _, d := range data.IbpButtons {
|
||||
|
||||
}
|
||||
|
||||
return gus
|
||||
for _, d := range data.IbpAlarms {
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
// 初始化继电器柜 UID
|
||||
@ -143,18 +191,12 @@ func initRelayCabinetUid(graphicData *graphicData.RelayCabinetGraphicStorage) *r
|
||||
RelayCabinetIds: make(map[string]*elementIdStructure, len(graphicData.RelayCabinets)),
|
||||
RelayIds: make(map[string]*elementIdStructure, len(graphicData.Relays)),
|
||||
}
|
||||
// 获取继电器的关联关系
|
||||
type relayUidPriex struct {
|
||||
deviceCode string
|
||||
typeCode string
|
||||
isStation bool
|
||||
}
|
||||
// 继电器所属设备
|
||||
refMap := make(map[string]*relayUidPriex, len(graphicData.Relays))
|
||||
refMap := make(map[string]*deviceRelateUidPriex, len(graphicData.Relays))
|
||||
for _, r := range graphicData.DeviceRelateRelayList {
|
||||
isStation := r.DeviceType.String() == "station"
|
||||
for _, c := range r.Combinationtypes {
|
||||
p := &relayUidPriex{deviceCode: r.Code, typeCode: c.Code, isStation: isStation}
|
||||
p := &deviceRelateUidPriex{deviceCode: r.Code, typeCode: c.Code, isStation: isStation}
|
||||
for _, i := range c.RefRelays {
|
||||
refMap[i] = p
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user