【修改获取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 (
"fmt"
"reflect"
"sync"
"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) {
case *graphicData.AxleCounting:
return "AxlePointIds"
return (uidData.(*stationUidStructure)).AxlePointIds
case *graphicData.Turnout:
return "TurnoutIds"
return (uidData.(*stationUidStructure)).TurnoutIds
case *graphicData.Section:
return "PhysicalSectionIds"
return (uidData.(*stationUidStructure)).PhysicalSectionIds
case *graphicData.Signal:
return "SignalIds"
return (uidData.(*stationUidStructure)).SignalIds
case *graphicData.Transponder:
return "TransponderIds"
return (uidData.(*stationUidStructure)).TransponderIds
case *graphicData.Slope:
return "SlopeIds"
return (uidData.(*stationUidStructure)).SlopeIds
case *graphicData.Curvature:
return "CurvatureIds"
return (uidData.(*stationUidStructure)).CurvatureIds
case *graphicData.RelayCabinet:
return "RelayCabinetIds"
return (uidData.(*relayUidStructure)).RelayCabinetIds
case *graphicData.Relay:
return "RelayIds"
return (uidData.(*relayUidStructure)).RelayIds
default:
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "类型未映射字段"})
}
@ -239,18 +238,7 @@ func QueryMapUidMapByType(mapId int32, m interface{}) map[string]*elementIdStruc
if !ok {
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("地图【id:%d】不存在uid缓存", mapId)})
}
// 字段名称
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
return getUidMapByType(uidData, m)
}
// 根据地图的comId获取UID