【修改获取UID映射集合】

This commit is contained in:
weizhihong 2023-09-25 18:14:00 +08:00
parent 95599bfae3
commit ea29848a74

View File

@ -2,7 +2,6 @@ package memory
import ( import (
"fmt" "fmt"
"reflect"
"sync" "sync"
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
@ -208,26 +207,26 @@ func queryUidStructure[T *stationUidStructure | *relayUidStructure](mapId int32)
} }
// 获取设备类型获取对应字段 // 获取设备类型获取对应字段
func getFieldNameByType(m interface{}) string { func getUidMapByType(uidData any, m interface{}) map[string]*elementIdStructure {
switch m.(type) { switch m.(type) {
case *graphicData.AxleCounting: case *graphicData.AxleCounting:
return "AxlePointIds" return (uidData.(*stationUidStructure)).AxlePointIds
case *graphicData.Turnout: case *graphicData.Turnout:
return "TurnoutIds" return (uidData.(*stationUidStructure)).TurnoutIds
case *graphicData.Section: case *graphicData.Section:
return "PhysicalSectionIds" return (uidData.(*stationUidStructure)).PhysicalSectionIds
case *graphicData.Signal: case *graphicData.Signal:
return "SignalIds" return (uidData.(*stationUidStructure)).SignalIds
case *graphicData.Transponder: case *graphicData.Transponder:
return "TransponderIds" return (uidData.(*stationUidStructure)).TransponderIds
case *graphicData.Slope: case *graphicData.Slope:
return "SlopeIds" return (uidData.(*stationUidStructure)).SlopeIds
case *graphicData.Curvature: case *graphicData.Curvature:
return "CurvatureIds" return (uidData.(*stationUidStructure)).CurvatureIds
case *graphicData.RelayCabinet: case *graphicData.RelayCabinet:
return "RelayCabinetIds" return (uidData.(*relayUidStructure)).RelayCabinetIds
case *graphicData.Relay: case *graphicData.Relay:
return "RelayIds" return (uidData.(*relayUidStructure)).RelayIds
default: default:
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "类型未映射字段"}) panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "类型未映射字段"})
} }
@ -239,18 +238,7 @@ func QueryMapUidMapByType(mapId int32, m interface{}) map[string]*elementIdStruc
if !ok { if !ok {
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("地图【id:%d】不存在uid缓存", mapId)}) panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("地图【id:%d】不存在uid缓存", mapId)})
} }
// 字段名称 return getUidMapByType(uidData, m)
fieldName := getFieldNameByType(m)
reflectUidMap := reflect.ValueOf(&uidData).Elem()
um := reflectUidMap.Elem().Elem().FieldByName(fieldName)
if !um.CanAddr() {
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "类型不匹配"})
}
uidMap, ok := um.Interface().(map[string]*elementIdStructure)
if !ok {
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "类型不匹配"})
}
return uidMap
} }
// 根据地图的comId获取UID // 根据地图的comId获取UID